Esempio n. 1
0
 private static int print_XBEL(final Iterator<String> bit, int count) {
   BookmarksDB.Bookmark bookmark = null;
   Date date;
   while (bit.hasNext()) {
     bookmark = sb.bookmarksDB.getBookmark(bit.next());
     date = new Date(bookmark.getTimeStamp());
     prop.put(
         "display_xbel_" + count + "_elements",
         "<bookmark id=\""
             + bookmark.getUrlHash()
             + "\" href=\""
             + CharacterCoding.unicode2xml(bookmark.getUrl(), true)
             + "\" added=\""
             + CharacterCoding.unicode2xml(ISO8601Formatter.FORMATTER.format(date), true)
             + "\">");
     count++;
     prop.put("display_xbel_" + count + "_elements", "<title>");
     count++;
     prop.putXML("display_xbel_" + count + "_elements", bookmark.getTitle());
     count++;
     prop.put("display_xbel_" + count + "_elements", "</title>");
     count++;
     prop.put("display_xbel_" + count + "_elements", "<info>");
     count++;
     prop.put(
         "display_xbel_" + count + "_elements",
         "<metadata owner=\"Mozilla\" ShortcutURL=\""
             + CharacterCoding.unicode2xml(
                 bookmark.getTagsString().replaceAll("/.*,", "").toLowerCase(), true)
             + "\"/>");
     count++;
     prop.put(
         "display_xbel_" + count + "_elements",
         "<metadata owner=\"YaCy\" public=\"" + Boolean.toString(bookmark.getPublic()) + "\"/>");
     count++;
     prop.put("display_xbel_" + count + "_elements", "</info>");
     count++;
     prop.put("display_xbel_" + count + "_elements", "<desc>");
     count++;
     prop.putXML("display_xbel_" + count + "_elements", bookmark.getDescription());
     count++;
     prop.put("display_xbel_" + count + "_elements", "</desc>");
     count++;
     prop.put("display_xbel_" + count + "_elements", "</bookmark>");
     count++;
   }
   return count;
 }
Esempio n. 2
0
  private static int recurseFolders(
      final Iterator<String> it, String root, int count, final boolean next, final String prev) {
    String fn = "";

    if (next) fn = it.next();
    else fn = prev;

    if ("\uffff".equals(fn)) {
      int i = prev.replaceAll("[^/]", "").length() - R;
      while (i > 0) {
        prop.put("display_xbel_" + count + "_elements", "</folder>");
        count++;
        i--;
      }
      return count;
    }

    if (fn.startsWith(("/".equals(root) ? root : root + "/"))) {
      prop.put(
          "display_xbel_" + count + "_elements",
          "<folder id=\"" + BookmarkHelper.tagHash(fn) + "\">");
      count++;

      final String title = fn; // just to make sure fn stays untouched
      prop.put(
          "display_xbel_" + count + "_elements",
          "<title>"
              + CharacterCoding.unicode2xml(title.replaceAll("(/.[^/]*)*/", ""), true)
              + "</title>");
      count++;
      final Iterator<String> bit = sb.bookmarksDB.getBookmarksIterator(fn, isAdmin);
      count = print_XBEL(bit, count);
      if (it.hasNext()) {
        count = recurseFolders(it, fn, count, true, fn);
      }
    } else {
      if (count > 0) {
        prop.put("display_xbel_" + count + "_elements", "</folder>");
        count++;
      }
      root = root.replaceAll("(/.[^/]*$)", "");
      if ("".equals(root)) {
        root = "/";
      }
      count = recurseFolders(it, root, count, false, fn);
    }
    return count;
  }
Esempio n. 3
0
  public static serverObjects respond(
      final RequestHeader header, serverObjects post, final serverSwitch env) {
    final serverObjects prop = new serverObjects();
    final Switchboard sb = (Switchboard) env;

    prop.put("refresh", 0);
    prop.put("import", 0);
    prop.put("source", 0);

    if (post != null && post.containsKey("source")) {
      final Set<String> oaiRoots = OAIListFriendsLoader.getListFriends(sb.loader).keySet();

      boolean dark = false;
      int count = 0;
      for (final String root : oaiRoots) {
        prop.put("source_table_" + count + "_dark", (dark) ? "1" : "0");
        prop.put("source_table_" + count + "_count", count);
        prop.put("source_table_" + count + "_source", CharacterCoding.unicode2html(root, true));
        prop.put(
            "source_table_" + count + "_loadurl",
            "<a href=\"/IndexImportOAIPMH_p.html?urlstart="
                + CharacterCoding.unicode2html(root, true)
                + "\" target=\"_top\">"
                + CharacterCoding.unicode2html(root, true)
                + "</a>");
        dark = !dark;
        count++;
      }
      prop.put("source_table", count);
      prop.put("source_num", count);
      prop.put("source", 1);
    }

    if (post != null && post.containsKey("import")) {
      final List<OAIPMHImporter> jobs = new ArrayList<OAIPMHImporter>();
      for (OAIPMHImporter job : OAIPMHImporter.runningJobs.keySet()) jobs.add(job);
      for (OAIPMHImporter job : OAIPMHImporter.startedJobs.keySet()) jobs.add(job);
      for (OAIPMHImporter job : OAIPMHImporter.finishedJobs.keySet()) jobs.add(job);

      boolean dark = false;
      int count = 0;
      for (final OAIPMHImporter job : jobs) {
        prop.put("import_table_" + count + "_dark", (dark) ? "1" : "0");
        prop.put(
            "import_table_" + count + "_thread",
            (job.isAlive())
                ? "<img src=\"/env/grafics/loading.gif\" alt=\"running\" />"
                : "finished");
        prop.putXML("import_table_" + count + "_source", job.source());
        prop.put("import_table_" + count + "_chunkCount", job.chunkCount());
        prop.put("import_table_" + count + "_recordsCount", job.count());
        prop.put("import_table_" + count + "_completeListSize", job.getCompleteListSize());
        prop.put("import_table_" + count + "_speed", job.speed());
        dark = !dark;
        count++;
      }
      prop.put("import_table", count);
      prop.put("import", 1);
      prop.put("refresh", 1);
    }
    return prop;
  }