001: // /xml/bookmarks/posts/all.java
002: // -------------------------------
003: // (C) 2006 Alexander Schier
004: // part of yacy
005: //
006: // This program is free software; you can redistribute it and/or modify
007: // it under the terms of the GNU General Public License as published by
008: // the Free Software Foundation; either version 2 of the License, or
009: // (at your option) any later version.
010: //
011: // This program is distributed in the hope that it will be useful,
012: // but WITHOUT ANY WARRANTY; without even the implied warranty of
013: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: // GNU General Public License for more details.
015: //
016: // You should have received a copy of the GNU General Public License
017: // along with this program; if not, write to the Free Software
018: // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
019:
020: package xml.bookmarks.posts;
021:
022: import java.text.ParseException;
023: import java.util.ArrayList;
024: import java.util.Date;
025: import java.util.Iterator;
026:
027: import de.anomic.data.bookmarksDB;
028: import de.anomic.http.httpHeader;
029: import de.anomic.plasma.plasmaSwitchboard;
030: import de.anomic.server.serverCodings;
031: import de.anomic.server.serverDate;
032: import de.anomic.server.serverObjects;
033: import de.anomic.server.serverSwitch;
034:
035: public class get {
036: public static serverObjects respond(httpHeader header,
037: serverObjects post, serverSwitch env) {
038: // return variable that accumulates replacements
039: plasmaSwitchboard switchboard = (plasmaSwitchboard) env;
040: boolean isAdmin = switchboard
041: .verifyAuthentication(header, true);
042: serverObjects prop = new serverObjects();
043: String tag = null;
044: String date;
045: //String url=""; //urlfilter not yet implemented
046:
047: if (post != null && post.containsKey("tag")) {
048: tag = (String) post.get("tag");
049: }
050: if (post != null && post.containsKey("date")) {
051: date = (String) post.get("date");
052: } else {
053: date = serverDate.formatISO8601(new Date(System
054: .currentTimeMillis()));
055: }
056:
057: // if an extended xml should be used
058: boolean extendedXML = (post != null && post
059: .containsKey("extendedXML"));
060:
061: int count = 0;
062:
063: Date parsedDate = null;
064: try {
065: parsedDate = serverDate.parseISO8601(date);
066: } catch (ParseException e) {
067: parsedDate = new Date();
068: }
069:
070: ArrayList<String> bookmark_hashes = switchboard.bookmarksDB
071: .getDate(Long.toString(parsedDate.getTime()))
072: .getBookmarkList();
073: Iterator<String> it = bookmark_hashes.iterator();
074: bookmarksDB.Bookmark bookmark = null;
075: while (it.hasNext()) {
076: bookmark = switchboard.bookmarksDB.getBookmark(it.next());
077: if (serverDate.formatISO8601(new Date(bookmark
078: .getTimeStamp())) == date
079: && tag == null
080: || bookmark.getTags().contains(tag)
081: && isAdmin || bookmark.getPublic()) {
082: prop.put("posts_" + count + "_url", bookmark.getUrl());
083: prop.put("posts_" + count + "_title", bookmark
084: .getTitle());
085: prop.put("posts_" + count + "_description", bookmark
086: .getDescription());
087: prop.put("posts_" + count + "_md5", serverCodings
088: .encodeMD5Hex(bookmark.getUrl()));
089: prop.put("posts_" + count + "_time", date);
090: prop.putHTML("posts_" + count + "_tags", bookmark
091: .getTagsString().replaceAll(",", " "));
092:
093: // additional XML tags
094: prop.put("posts_" + count + "_isExtended",
095: extendedXML ? "1" : "0");
096: if (extendedXML) {
097: prop.put("posts_" + count + "_isExtended_private",
098: Boolean.toString(!bookmark.getPublic()));
099: }
100: count++;
101: }
102: }
103: prop.put("posts", count);
104:
105: // return rewrite properties
106: return prop;
107: }
108:
109: }
|