Package de.anomic.server

Examples of de.anomic.server.serverObjects


import de.anomic.server.serverSwitch;

public class ConfigLiveSearch {

    public static serverObjects respond(final RequestHeader header, final serverObjects post, final serverSwitch env) {
        final serverObjects prop = new serverObjects();
        final Switchboard sb = (Switchboard) env;
       
        prop.putHTML("ip", sb.peers.mySeed().getIP());
        prop.putHTML("port", sb.getConfig("port", "8090"));
        return prop;
    }
View Full Code Here


public final class Settings_p {
   
    public static serverObjects respond(final RequestHeader header, final serverObjects post, final serverSwitch env) {
        // return variable that accumulates replacements
        final serverObjects prop = new serverObjects();
        final Switchboard sb = (Switchboard) env;
       
        //if (post == null) System.out.println("POST: NULL"); else System.out.println("POST: " + post.toString());
       
        final String page = (post == null) ? "general" : post.get("page", "general");
       
        if (page.equals("ProxyAccess")) {
            prop.put("settingsTables", "Settings_ProxyAccess.inc");
        }
        else if (page.equals("http")) {
            prop.put("settingsTables", "Settings_Http.inc");
        }
        else if (page.equals("proxy")) {
            prop.put("settingsTables", "Settings_Proxy.inc");
        }
        else if (page.equals("ServerAccess")) { 
            prop.put("settingsTables", "Settings_ServerAccess.inc");
        }
        else if (page.equals("SystemBehaviour")) {
            prop.put("settingsTables", "Settings_SystemBehaviour.inc");
        }
        else if (page.equals("seed")) {
            prop.put("settingsTables", "Settings_Seed.inc");
        }
        else if (page.equals("messageForwarding")) {
            prop.put("settingsTables", "Settings_MessageForwarding.inc");
        }
        else if (page.equals("parser")) {
            prop.put("settingsTables", "Settings_Parser.inc");
        }
        else if (page.equals("crawler")) {
            prop.put("settingsTables", "Settings_Crawler.inc");
        } else {
            prop.put("settingsTables", "");
        }

        prop.put("port", env.getConfig("port", "8090"));              
       
        prop.putHTML("peerName", sb.peers.mySeed().getName());
        prop.putHTML("staticIP", env.getConfig("staticIP", ""));
        String peerLang = env.getConfig("locale.language", "default");
        if (peerLang.equals("default")) peerLang = "en";
        prop.putHTML("peerLang", peerLang);
       
        // http networking settings
        prop.put("isTransparentProxy", env.getConfigBool("isTransparentProxy", false) ? "1" : "0");
        prop.put("connectionKeepAliveSupport", env.getConfigBool("connectionKeepAliveSupport", false) ? "1" : "0");
        prop.put("proxy.sendViaHeader", env.getConfigBool("proxy.sendViaHeader", false) ? "1" : "0");
        prop.put("proxy.sendXForwardedForHeader", env.getConfigBool("proxy.sendXForwardedForHeader", true) ? "1" : "0");

        // admin password
        prop.put("adminuser","admin");
       
        // remote proxy
        prop.put("remoteProxyUseChecked", env.getConfigBool("remoteProxyUse", false) ? 1 : 0);
        prop.put("remoteProxyUse4Yacy", env.getConfigBool("remoteProxyUse4Yacy", true) ? 1 : 0);
        prop.put("remoteProxyUse4SSL", env.getConfigBool("remoteProxyUse4SSL", true) ? 1 : 0);
       
        prop.putHTML("remoteProxyHost", env.getConfig("remoteProxyHost", ""));
        prop.putHTML("remoteProxyPort", env.getConfig("remoteProxyPort", ""));
       
        prop.putHTML("remoteProxyUser", env.getConfig("remoteProxyUser", ""));
        prop.putHTML("remoteProxyPwd", env.getConfig("remoteProxyPwd", ""));
       
        prop.putHTML("remoteProxyNoProxy", env.getConfig("remoteProxyNoProxy", ""));
       
        // proxy access filter
        prop.putHTML("proxyfilter", env.getConfig("proxyClient", "*"));
       
        // proxy password
        if (!env.getConfigBool("use_proxyAccounts", false)) {
            // no password has been specified
            prop.put("use_proxyAccounts", "0"); //unchecked
        } else {
            prop.put("use_proxyAccounts", "1"); //checked
            /*s = env.getConfig("proxyAccount", "proxy:void");
            pos = s.indexOf(":");
            if (pos < 0) {
                prop.put("proxyuser","proxy");
            } else {
                prop.put("proxyuser",s.substring(0, pos));
            }*/
        }
       
        // server access filter
        prop.putHTML("serverfilter", env.getConfig("serverClient", "*"));
       
        // server password
        prop.put("serveruser","server");
       
        // clientIP
        prop.putXML("clientIP", header.get(HeaderFramework.CONNECTION_PROP_CLIENTIP, "<unknown>")); // read an artificial header addendum
       
        /*
         * seed upload settings
         */
        // available methods
        String enabledUploader = env.getConfig("seedUploadMethod", "none");
       
        // for backward compatiblity ....
        if ((enabledUploader.equalsIgnoreCase("Ftp")) ||
                ((enabledUploader.equals("")) &&
                        (env.getConfig("seedFTPPassword","").length() > 0) &&
                        (env.getConfig("seedFilePath", "").length() > 0))) {
            enabledUploader = "Ftp";
            env.setConfig("seedUploadMethod",enabledUploader);
        }                 
       
        final HashMap<String, String> uploaders = yacyCore.getSeedUploadMethods();
        prop.put("seedUploadMethods", uploaders.size() + 1);
        prop.put("seedUploadMethods_0_name", "none");
        prop.put("seedUploadMethods_0_selected", enabledUploader.equals("none") ? "1" : "0");
        prop.put("seedUploadMethods_0_file", "");
       
        int count = 0;
        final Iterator<String> uploaderKeys = uploaders.keySet().iterator();
        while (uploaderKeys.hasNext()) {
            count++;
            final String uploaderName = uploaderKeys.next();
            prop.put("seedUploadMethods_" +count+ "_name", uploaderName);
            prop.put("seedUploadMethods_" +count+ "_selected", uploaderName.equals(enabledUploader) ? "1" : "0");           
            prop.put("seedUploadMethods_" +count+ "_file", "Settings_Seed_Upload" + uploaderName + ".inc");
           
            final yacySeedUploader theUploader = yacyCore.getSeedUploader(uploaderName);
            final String[] configOptions = theUploader.getConfigurationOptions();
            if (configOptions != null) {
                for (int i=0; i<configOptions.length; i++) {
                    prop.put("seedUploadMethods_" +count+ "_" + configOptions[i], env.getConfig(configOptions[i], ""));
                    // prop.put("seedUpload" + uploaderName,1);
                }
            }
        }
       
        // general settings
        prop.put("seedURL", sb.peers.mySeed().get(yacySeed.SEEDLISTURL, ""));
       
        /*
         * Message forwarding configuration
         */
        prop.put("msgForwardingEnabled",env.getConfigBool("msgForwardingEnabled",false) ? "1" : "0");
        prop.putHTML("msgForwardingCmd",env.getConfig("msgForwardingCmd", ""));
        prop.putHTML("msgForwardingTo",env.getConfig("msgForwardingTo", ""));

        // Crawler settings
        prop.putHTML("crawler.clientTimeout",sb.getConfig("crawler.clientTimeout", "10000"));
        prop.putHTML("crawler.http.maxFileSize",sb.getConfig("crawler.http.maxFileSize", "-1"));
        prop.putHTML("crawler.ftp.maxFileSize",sb.getConfig("crawler.ftp.maxFileSize", "-1"));
        prop.putHTML("crawler.smb.maxFileSize",sb.getConfig("crawler.smb.maxFileSize", "-1"));
        prop.putHTML("crawler.file.maxFileSize",sb.getConfig("crawler.file.maxFileSize", "-1"));
       
        // return rewrite properties
        return prop;
    }
View Full Code Here

public class import_ymark {
 
  public static serverObjects respond(final RequestHeader header, final serverObjects post, final serverSwitch env) {
        final Switchboard sb = (Switchboard) env;
        final serverObjects prop = new serverObjects();
        final UserDB.Entry user = sb.userDB.getUser(header);
        final boolean isAdmin = (sb.verifyAuthentication(header, true));
        final boolean isAuthUser = user!= null && user.hasRight(UserDB.AccessRight.BOOKMARK_RIGHT);
        final int queueSize = 20;
       
        Thread t;
        YMarkEntry bmk;
        String root = YMarkEntry.FOLDERS_IMPORTED;
        ByteArrayInputStream stream = null;
   
        if(isAdmin || isAuthUser) {
          String bmk_user = (isAuthUser ? user.getUserName() : YMarkTables.USER_ADMIN);         
          final ArrayBlockingQueue<String> autoTaggingQueue = new ArrayBlockingQueue<String>(2*queueSize);
            boolean autotag = false;
          boolean merge = false;
          boolean empty = false;
           
          if(post.containsKey("autotag") && !post.get("autotag", "off").equals("off")) {                                       
            autotag = true;
            if(post.get("autotag").equals("merge")) {                 
                  merge = true;
                }
                if(post.get("autotag").equals("empty")) {
                  empty = true;
                }
                t = new Thread(new YMarkAutoTagger(autoTaggingQueue, sb.loader, sb.tables.bookmarks, bmk_user, merge),"YMarks - autoTagger");
                t.start();
          }
         
          if(isAdmin && post.containsKey("table") && post.get("table").length() > 0) {
            bmk_user = post.get("table").substring(0, post.get("table").indexOf('_'));
          }
            if(post.containsKey("redirect") && post.get("redirect").length() > 0) {
                prop.put("redirect_url", post.get("redirect"));
                prop.put("redirect", "1");
            }
            if(post.containsKey("root") && post.get("root").length() > 0) {
                root = post.get("root");
            }
          if(post.containsKey("bmkfile") && post.containsKey("importer")){
            stream = new ByteArrayInputStream(UTF8.getBytes(post.get("bmkfile$file")));
            if(post.get("importer").equals("surro") && stream != null) {
                    SurrogateReader surrogateReader;
                    try {
                        surrogateReader = new SurrogateReader(stream, queueSize);
                    } catch (IOException e) {
                        //TODO: display an error message
                        Log.logException(e);
                        prop.put("result", "0");
                        return prop;  
                    }
                    t = new Thread(surrogateReader, "YMarks - Surrogate Reader");
                    t.start();
                    while ((bmk = new YMarkEntry(surrogateReader.take())) != YMarkEntry.POISON) {
                        putBookmark(sb.tables.bookmarks, bmk_user, bmk, autoTaggingQueue, autotag, empty);
                    }
                    prop.put("result", "1");
                } else {
                    InputStreamReader reader = null;
                    try {
                        reader = new InputStreamReader(stream,"UTF-8");
                    } catch (UnsupportedEncodingException e1) {
                        //TODO: display an error message
                        Log.logException(e1);
                        prop.put("result", "0");
                        return prop;
                    }
                    if(post.get("importer").equals("html") && reader != null) {
                        final YMarkHTMLImporter htmlImporter = new YMarkHTMLImporter(reader, queueSize, root);
                        t = new Thread(htmlImporter, "YMarks - HTML Importer");
                        t.start();
                        while ((bmk = htmlImporter.take()) != YMarkEntry.POISON) {
                            putBookmark(sb.tables.bookmarks, bmk_user, bmk, autoTaggingQueue, autotag, empty);
                        }
                        prop.put("result", "1");                   
                    } else if(post.get("importer").equals("xbel") && reader != null) {
                        final YMarkXBELImporter xbelImporter;  
                        try {
                            //TODO: make RootFold
                            xbelImporter = new YMarkXBELImporter(reader, queueSize, root);
                        } catch (SAXException e) {
                            //TODO: display an error message
                            Log.logException(e);
                            prop.put("result", "0");
                            return prop;
                        }
                        t = new Thread(xbelImporter, "YMarks - XBEL Importer");
                        t.start();
                        while ((bmk = xbelImporter.take()) != YMarkEntry.POISON) {
                            putBookmark(sb.tables.bookmarks, bmk_user, bmk, autoTaggingQueue, autotag, empty);
                        }
                        prop.put("result", "1");
                    } else if(post.get("importer").equals("json") && reader != null) {
                        YMarkJSONImporter jsonImporter;
                        jsonImporter = new YMarkJSONImporter(reader, queueSize, root);
                        t = new Thread(jsonImporter, "YMarks - JSON Importer");
                        t.start();
                        while ((bmk = jsonImporter.take()) != YMarkEntry.POISON) {
                          putBookmark(sb.tables.bookmarks, bmk_user, bmk, autoTaggingQueue, autotag, empty);
                        }
                        prop.put("result", "1");
                    }
                }           
          }
          if(post.containsKey("autotag") && !post.get("autotag", "off").equals("off")) {
              try {
            autoTaggingQueue.put(YMarkAutoTagger.POISON);
            Log.logInfo(YMarkTables.BOOKMARKS_LOG, "Importer inserted poison pill in autoTagging queue");
          } catch (InterruptedException e) {
            Log.logException(e);
          }  
          }        
        }  else {
          prop.put(YMarkTables.USER_AUTHENTICATE,YMarkTables.USER_AUTHENTICATE_MSG);
        }               
        // return rewrite properties
        return prop;
  }
View Full Code Here

public class get {
    public static serverObjects respond(final RequestHeader header, final serverObjects post, final serverSwitch env) {
        // return variable that accumulates replacements
        final Switchboard switchboard = (Switchboard) env;
        final boolean isAdmin=switchboard.verifyAuthentication(header, true);
        final serverObjects prop = new serverObjects();
        String tag = null;
        final String date;
        //String url=""; //urlfilter not yet implemented
       
        if (post != null && post.containsKey("tag")) {
            tag = post.get("tag");
        }
        if (post != null && post.containsKey("date")) {
            date = post.get("date");
        } else {
            date = ISO8601Formatter.FORMATTER.format();
        }
       
        // if an extended xml should be used
        final boolean extendedXML = (post != null && post.containsKey("extendedXML"));
       
        int count=0;
       
        Date parsedDate = null;
        try {
            parsedDate = ISO8601Formatter.FORMATTER.parse(date);
        } catch (final ParseException e) {
            parsedDate = new Date();
        }
       
        final List<String> bookmark_hashes = switchboard.bookmarksDB.getDate(Long.toString(parsedDate.getTime())).getBookmarkList();
        BookmarksDB.Bookmark bookmark = null;
        for (final String bookmark_hash : bookmark_hashes){
            bookmark=switchboard.bookmarksDB.getBookmark(bookmark_hash);
            if (ISO8601Formatter.FORMATTER.format(new Date(bookmark.getTimeStamp())).equals(date) &&
                    tag==null || bookmark.getTags().contains(tag) &&
                    isAdmin || bookmark.getPublic()){
                prop.putHTML("posts_"+count+"_url", bookmark.getUrl());
                prop.putHTML("posts_"+count+"_title", bookmark.getTitle());
                prop.putHTML("posts_"+count+"_description", bookmark.getDescription());
                prop.put("posts_"+count+"_md5", Digest.encodeMD5Hex(bookmark.getUrl()));
                prop.put("posts_"+count+"_time", date);
                prop.putHTML("posts_"+count+"_tags", bookmark.getTagsString().replaceAll(","," "));
               
                // additional XML tags
                prop.put("posts_"+count+"_isExtended",extendedXML ? "1" : "0");
                if (extendedXML) {
                  prop.put("posts_"+count+"_isExtended_private", Boolean.toString(!bookmark.getPublic()));
                }
                count++;
            }
        }
        prop.put("posts", count);

        // return rewrite properties
        return prop;
    }
View Full Code Here

    public static serverObjects respond(final RequestHeader header, final serverObjects post, final serverSwitch env) {
        // return variable that accumulates replacements
        final Switchboard sb = (Switchboard) env;
       
        final serverObjects prop = new serverObjects();
        if ((post == null) || (env == null)) return prop;
        final boolean authenticated = sb.adminAuthenticated(header) >= 2;
       
        Segment segment = null;
        if (post.containsKey("segment") && authenticated) {
            segment = sb.indexSegments.segment(post.get("segment"));
        } else {
            segment = sb.indexSegments.segment(Segments.Process.PUBLIC);
        }
       
        final String  querystring = post.get("query", "")// a string of word hashes that shall be searched and combined
        final int     count  = Math.min((authenticated) ? 1000 : 10, post.getInt("maximumRecords", 1000)); // SRU syntax
        final int     maxdist= post.getInt("maxdist", Integer.MAX_VALUE);
        String  language = post.get("language", "");
        if (!ISO639.exists(language)) {
            // take language from the user agent
            String agent = header.get("User-Agent");
            if (agent == null) agent = System.getProperty("user.language");
            language = (agent == null) ? "en" : ISO639.userAgentLanguageDetection(agent);
            if (language == null) language = "en";
        }
        final TreeSet<String>[] query = QueryParams.cleanQuery(querystring); // converts also umlaute
        HandleSet q = Word.words2hashesHandles(query[0]);
       
        // tell all threads to do nothing for a specific time
        sb.intermissionAllThreads(3000);

        // prepare search
        final long timestamp = System.currentTimeMillis();
       
        // prepare an abstract result
        int indexabstractContainercount = 0;
        int joincount = 0;

        // retrieve index containers
        //yacyCore.log.logInfo("INIT TIMELINE SEARCH: " + plasmaSearchQuery.anonymizedQueryHashes(query[0]) + " - " + count + " links");
       
        // get the index container with the result vector
        TermSearch<WordReference> search = null;
        try {
            search = segment.termIndex().query(q, Word.words2hashesHandles(query[1]), null, Segment.wordReferenceFactory, maxdist);
        } catch (RowSpaceExceededException e) {
            Log.logException(e);
        }
        ReferenceContainer<WordReference> index = search.joined();
       
        Iterator<WordReference> i = index.entries();
        WordReference entry;
        int c = 0;
        Date lm;
        String lms;
        while (i.hasNext() && c < count) {
            entry = i.next();
            lm = new Date(entry.lastModified());
            lms = GenericFormatter.ANSIC_FORMATTER.format(lm);
            prop.put("event_" + c + "_start", lms); // like "Wed May 01 1963 00:00:00 GMT-0600"
            prop.put("event_" + c + "_end", lms); // like "Sat Jun 01 1963 00:00:00 GMT-0600"
            prop.put("event_" + c + "_isDuration", 0); // 0 (only a point) or 1 (period of time)
            prop.putHTML("event_" + c + "_title", "test"); // short title of the event
            prop.putHTML("event_" + c + "_description", ""); // long description of the event
            c++;
        }
        prop.put("event", c);
       
        // log
        yacyCore.log.logInfo("EXIT TIMELINE SEARCH: " +
                QueryParams.anonymizedQueryHashes(q) + " - " + joincount + " links found, " +
                prop.get("linkcount", "?") + " links selected, " +
                indexabstractContainercount + " index abstracts, " +
                (System.currentTimeMillis() - timestamp) + " milliseconds");
        return prop;
    }
View Full Code Here

public class delete_p {
    public static serverObjects respond(final RequestHeader header, final serverObjects post, final serverSwitch env) {
        // return variable that accumulates replacements
        final Switchboard switchboard = (Switchboard) env;
        final serverObjects prop = new serverObjects();
        final boolean isAdmin=switchboard.verifyAuthentication(header, true);       
        if(post!= null){
        if(!isAdmin){
          // force authentication if desired
              if(post.containsKey("login")){
                prop.put("AUTHENTICATE","admin log-in");
              }
              return prop;
        }
          try {
                if (post.containsKey("url") && switchboard.bookmarksDB.removeBookmark(ASCII.String((new DigestURI(post.get("url", "nourl"))).hash()))) {
                  prop.put("result", "1");
                } else if (post.containsKey("urlhash") && switchboard.bookmarksDB.removeBookmark(post.get("urlhash", "nohash"))) {
                  prop.put("result", "1");
                } else {
                  prop.put("result", "0");
                }
            } catch (final MalformedURLException e) {
                prop.put("result", "0");
            }
        }else{
          prop.put("result", "0");
        }       
        // return rewrite properties
        return prop;
    }   
View Full Code Here

public class add_ymark {
 
  public static serverObjects respond(final RequestHeader header, final serverObjects post, final serverSwitch env) {
    final Switchboard sb = (Switchboard) env;
        final serverObjects prop = new serverObjects();
       
        final UserDB.Entry user = sb.userDB.getUser(header);
        final boolean isAdmin = (sb.verifyAuthentication(header, true));
        final boolean isAuthUser = user!= null && user.hasRight(UserDB.AccessRight.BOOKMARK_RIGHT);
       
        if(isAdmin || isAuthUser) {
          final String bmk_user = (isAuthUser ? user.getUserName() : YMarkTables.USER_ADMIN);

            String url = post.get(YMarkEntry.BOOKMARK.URL.key(),YMarkEntry.BOOKMARK.URL.deflt());
      boolean hasProtocol = false;
      for (YMarkTables.PROTOCOLS p : YMarkTables.PROTOCOLS.values()) {
        hasProtocol = url.toLowerCase().startsWith(p.protocol());
      }
      if (!hasProtocol) {
          url=YMarkTables.PROTOCOLS.HTTP.protocol(url);
      }
       
          final YMarkEntry bmk = new YMarkEntry();       
           
          bmk.put(YMarkEntry.BOOKMARK.URL.key(), url);
          bmk.put(YMarkEntry.BOOKMARK.TITLE.key(), post.get(YMarkEntry.BOOKMARK.TITLE.key(),YMarkEntry.BOOKMARK.TITLE.deflt()));
          bmk.put(YMarkEntry.BOOKMARK.DESC.key(), post.get(YMarkEntry.BOOKMARK.DESC.key(),YMarkEntry.BOOKMARK.DESC.deflt()));
          bmk.put(YMarkEntry.BOOKMARK.PUBLIC.key(), post.get(YMarkEntry.BOOKMARK.PUBLIC.key(),YMarkEntry.BOOKMARK.PUBLIC.deflt()));
          bmk.put(YMarkEntry.BOOKMARK.TAGS.key(), YMarkUtil.cleanTagsString(post.get(YMarkEntry.BOOKMARK.TAGS.key(),YMarkEntry.BOOKMARK.TAGS.deflt())));
          bmk.put(YMarkEntry.BOOKMARK.FOLDERS.key(), YMarkUtil.cleanFoldersString(post.get(YMarkEntry.BOOKMARK.FOLDERS.key(),YMarkEntry.FOLDERS_UNSORTED)));
           
            try {
        sb.tables.bookmarks.addBookmark(bmk_user, bmk, false, false);
        } catch (IOException e) {
            Log.logException(e);
        } catch (RowSpaceExceededException e) {
      }
            prop.put("result", "1");
        } else {
          prop.put(YMarkTables.USER_AUTHENTICATE,YMarkTables.USER_AUTHENTICATE_MSG);
        }
        // return rewrite properties
        return prop;
    }
View Full Code Here

public class all {
    public static serverObjects respond(final RequestHeader header, final serverObjects post, final serverSwitch env) {
        // return variable that accumulates replacements
        final Switchboard switchboard = (Switchboard) env;
        final boolean isAdmin=switchboard.verifyAuthentication(header, true);
        final serverObjects prop = new serverObjects();
       
        Iterator<String> it;
        if(post != null && post.containsKey("tag")){
            it=switchboard.bookmarksDB.getBookmarksIterator(post.get("tag"), isAdmin);
        }else{
            it=switchboard.bookmarksDB.getBookmarksIterator(isAdmin);
        }
       
        // if an extended xml should be used
        final boolean extendedXML = (post != null && post.containsKey("extendedXML"));
       
        int count=0;
        BookmarksDB.Bookmark bookmark;
        Date date;
        while(it.hasNext()){
            bookmark=switchboard.bookmarksDB.getBookmark(it.next());
            prop.putXML("posts_"+count+"_url", bookmark.getUrl());
            prop.putXML("posts_"+count+"_title", bookmark.getTitle());
            prop.putXML("posts_"+count+"_description", bookmark.getDescription());
            prop.putXML("posts_"+count+"_md5", Digest.encodeMD5Hex(bookmark.getUrl()));
            date = new Date(bookmark.getTimeStamp());
            prop.putXML("posts_"+count+"_time", ISO8601Formatter.FORMATTER.format(date));
            prop.putXML("posts_"+count+"_tags", bookmark.getTagsString().replaceAll(","," "));
           
            // additional XML tags
            prop.put("posts_"+count+"_isExtended",extendedXML ? "1" : "0");
            if (extendedXML) {
              prop.put("posts_"+count+"_isExtended_private", Boolean.toString(!bookmark.getPublic()));
            }
            count++;
        }
        prop.put("posts", count);

        // return rewrite properties
        return prop;
    }
View Full Code Here

  public static final String ROOT = "root";
  public static final String SOURCE = "source";

  public static serverObjects respond(final RequestHeader header, final serverObjects post, final serverSwitch env) {
    final Switchboard sb = (Switchboard) env;
    final serverObjects prop = new serverObjects();       
    final HashSet<String> alias = new HashSet<String>();
    final StringBuilder buffer = new StringBuilder(250);
    final UserDB.Entry user = sb.userDB.getUser(header);
        final boolean isAdmin = (sb.verifyAuthentication(header, true));
        final boolean isAuthUser = user!= null && user.hasRight(UserDB.AccessRight.BOOKMARK_RIGHT);
    final String bmk_user;
       
        if(isAdmin || isAuthUser) {
          bmk_user = (isAuthUser ? user.getUserName() : YMarkTables.USER_ADMIN);
         
          String root = YMarkTables.FOLDERS_ROOT;   
          String[] foldername = null;
         
          // TODO: better handling of query
          if (post != null){
            if (post.containsKey(ROOT)) {
                if (post.get(ROOT).equals(SOURCE) || post.get(ROOT).equals(YMarkTables.FOLDERS_ROOT)) {
                  root = "";
                } else if (post.get(ROOT).startsWith(YMarkTables.FOLDERS_ROOT)) {
                  root = post.get(ROOT);
                } else {
                  root = "";                 
                }
            }
          } else {
            root = "";
          }
         
          final int root_depth = root.split(YMarkUtil.FOLDERS_SEPARATOR).length;
        Iterator<String> fit = null;
          Iterator<Tables.Row> bit = null;
          int count = 0;       
          int n = root_depth;
         
          try {
        // fit = sb.tables.bookmarks.folders.getFolders(bmk_user, root);
            fit = sb.tables.bookmarks.getFolders(bmk_user, root).iterator();
      } catch (IOException e) {
        Log.logException(e);
      }
     
      while (fit.hasNext()) {              
            String folder = fit.next();
            foldername = folder.split(YMarkUtil.FOLDERS_SEPARATOR);
            if (n != root_depth && foldername.length <= n) {
          prop.put("xbel_"+count+"_elements", "</folder>");
                count++;
            }
            if (foldername.length >= n) {
              n = foldername.length;
              if(n != root_depth) {
                    prop.put("xbel_"+count+"_elements", "<folder id=\"f:"+UTF8.String(YMarkUtil.getKeyId(foldername[n-1]))+"\">");
                    count++;
                    prop.put("xbel_"+count+"_elements", "<title>" + CharacterCoding.unicode2xml(foldername[n-1], true) + "</title>");      
                    count++; 
              }
                // bit = sb.tables.bookmarks.folders.getBookmarkIds(bmk_user, folder).iterator();
          try {
            bit = sb.tables.bookmarks.getBookmarksByFolder(bmk_user, folder);
          } catch (IOException e) {
            // TODO: better error handling (avoid NPE)
            bit = null;
          }
          Tables.Row bmk_row = null;
          String urlHash;
          final YMarkDate date = new YMarkDate();
          while(bit.hasNext()){     
            // urlHash = bit.next();
            bmk_row = bit.next();
            urlHash = new String(bmk_row.getPK());
           
            if(alias.contains(urlHash)) {
              buffer.setLength(0);
              buffer.append(YMarkXBELImporter.XBEL.ALIAS.startTag(true));
              buffer.append(" ref=\"b:");
              buffer.append(urlHash);
              buffer.append("\"/>");                       
              prop.put("xbel_"+count+"_elements", buffer.toString());    
              count++;   
            } else {
              alias.add(urlHash);
              // bmk_row = sb.tables.select(YMarkTables.TABLES.BOOKMARKS.tablename(bmk_user), urlHash.getBytes());
                if(bmk_row != null) {
                  buffer.setLength(0);
                 
                  buffer.append(YMarkXBELImporter.XBEL.BOOKMARK.startTag(true));
                  buffer.append(" id=\"b:");
                  buffer.append(urlHash);
                 
                  buffer.append(YMarkEntry.BOOKMARK.URL.xbel());
                  buffer.append(CharacterCoding.unicode2xml(bmk_row.get(YMarkEntry.BOOKMARK.URL.key(), YMarkEntry.BOOKMARK.URL.deflt()), true));
                 
                  buffer.append(YMarkEntry.BOOKMARK.DATE_ADDED.xbel());
                  date.set(bmk_row.get(YMarkEntry.BOOKMARK.DATE_ADDED.key()));
                  buffer.append(CharacterCoding.unicode2xml(date.toISO8601(), true));
                 
                  buffer.append(YMarkEntry.BOOKMARK.DATE_MODIFIED.xbel());
                  date.set(bmk_row.get(YMarkEntry.BOOKMARK.DATE_MODIFIED.key()));
                  buffer.append(CharacterCoding.unicode2xml(date.toISO8601(), true));
                 
                  buffer.append(YMarkEntry.BOOKMARK.DATE_VISITED.xbel());
                  date.set(bmk_row.get(YMarkEntry.BOOKMARK.DATE_VISITED.key()));
                  buffer.append(CharacterCoding.unicode2xml(date.toISO8601(), true));
                 
                  buffer.append(YMarkEntry.BOOKMARK.TAGS.xbel());
                  buffer.append(bmk_row.get(YMarkEntry.BOOKMARK.TAGS.key(), YMarkEntry.BOOKMARK.TAGS.deflt()));
                 
                  buffer.append(YMarkEntry.BOOKMARK.PUBLIC.xbel());
                  buffer.append(bmk_row.get(YMarkEntry.BOOKMARK.PUBLIC.key(), YMarkEntry.BOOKMARK.PUBLIC.deflt()));
                 
                  buffer.append(YMarkEntry.BOOKMARK.VISITS.xbel());
                  buffer.append(bmk_row.get(YMarkEntry.BOOKMARK.VISITS.key(), YMarkEntry.BOOKMARK.VISITS.deflt()));
                 
                  buffer.append("\"\n>");
                  prop.put("xbel_"+count+"_elements", buffer.toString());
                  count++;
                 
                  buffer.setLength(0);
                  buffer.append(YMarkXBELImporter.XBEL.TITLE.startTag(false));
                  buffer.append(CharacterCoding.unicode2xml(bmk_row.get(YMarkEntry.BOOKMARK.TITLE.key(), YMarkEntry.BOOKMARK.TITLE.deflt()), true));
                  buffer.append(YMarkXBELImporter.XBEL.TITLE.endTag(false));
                  prop.put("xbel_"+count+"_elements", buffer.toString());
                  count++;

                  buffer.setLength(0);
                  buffer.append(YMarkXBELImporter.XBEL.DESC.startTag(false));
                  buffer.append(CharacterCoding.unicode2xml(bmk_row.get(YMarkEntry.BOOKMARK.DESC.key(), YMarkEntry.BOOKMARK.DESC.deflt()), true));
                  buffer.append(YMarkXBELImporter.XBEL.DESC.endTag(false));
                  prop.put("xbel_"+count+"_elements", buffer.toString());
                  count++;
                 
                  prop.put("xbel_"+count+"_elements", YMarkXBELImporter.XBEL.BOOKMARK.endTag(false));      
                  count++;   
                }
            }
          }
            }
          }
      while(n > root_depth) {
        prop.put("xbel_"+count+"_elements", YMarkXBELImporter.XBEL.FOLDER.endTag(false));
          count++;
          n--;
      }
      prop.put("root", root);
        prop.put("user", bmk_user.substring(0,1).toUpperCase() + bmk_user.substring(1));
        prop.put("xbel", count);
       
        else {
          prop.put(YMarkTables.USER_AUTHENTICATE,YMarkTables.USER_AUTHENTICATE_MSG);
       
        // return rewrite properties
        return prop;
  }
View Full Code Here

  private static serverObjects prop = null;
  final static String FOLDER_IMG = "<img src=\"/yacy/ui/img/treeview/folder-closed.gif\" />";
 
  public static serverObjects respond(final RequestHeader header, final serverObjects post, final serverSwitch env) {
        sb = (Switchboard) env;
        prop = new serverObjects();
       
        int rp;         // items per page
        int page;                 // page
        int total;
        String sortorder;
View Full Code Here

TOP

Related Classes of de.anomic.server.serverObjects

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.