Package freenet.support

Examples of freenet.support.HTMLNode


                    new String[]{name, Long.toString(key.getSuggestedEdition())});
        }

        @Override
    public HTMLNode getHTMLText() {
            HTMLNode n = new HTMLNode("div");
            NodeL10n.getBase().addL10nSubstitution(n, "BookmarkItem.bookmarkUpdatedWithLink", new String[]{"link", "name", "edition"},
                new HTMLNode[] { HTMLNode.link("/"+key), HTMLNode.text(name), HTMLNode.text(key.getSuggestedEdition()) });
            return n;
        }
View Full Code Here


                    redirectToRoot(ctx);
                    return;
                }
                // Tell the user that the node is shutting down
                PageNode page = ctx.getPageMaker().getPageNode("Node Shutdown", ctx, new RenderParameters().renderNavigationLinks(false));
                HTMLNode pageNode = page.outer;
                HTMLNode contentNode = page.content;
                ctx.getPageMaker().getInfobox("infobox-information", l10n("shutdownDone"), contentNode, "shutdown-progressing", true).
                  addChild("#", l10n("thanks"));

                WelcomeToadlet.maybeDisplayWrapperLogfile(ctx, contentNode);

                this.writeHTMLReply(ctx, 200, "OK", pageNode.generate());
                return;
            } else if (request.isParameterSet("restarted")) {
                if ((!request.isParameterSet("formPassword")) || !request.getParam("formPassword").equals(ctx.getFormPassword())) {
                    redirectToRoot(ctx);
                    return;
                }
                sendRestartingPage(ctx);
                return;
            } else if (request.getParam("newbookmark").length() > 0) {
              PageNode page = ctx.getPageMaker().getPageNode(l10n("confirmAddBookmarkTitle"), ctx);
                HTMLNode pageNode = page.outer;
                HTMLNode contentNode = page.content;
                HTMLNode infoboxContent = ctx.getPageMaker().getInfobox("#", l10n("confirmAddBookmarkSubTitle"), contentNode, "add-bookmark-confirm", true);
                HTMLNode addForm = ctx.addFormChild(infoboxContent, "/bookmarkEditor/", "editBookmarkForm");
                addForm.addChild("#", l10n("confirmAddBookmarkWithKey", "key", request.getParam("newbookmark")));
                addForm.addChild("br");
                String key = request.getParam("newbookmark");
                if (key.startsWith("freenet:")) {
                    key = key.substring(8);
                }
                addForm.addChild("input", new String[]{"type", "name", "value"}, new String[]{"hidden", "key", key});
                if(request.isParameterSet("hasAnActivelink")) {
                  addForm.addChild("input", new String[]{"type", "name", "value"}, new String[]{"hidden","hasAnActivelink",request.getParam("hasAnActivelink")});
                }
        addForm.addChild("label", "for", "name", NodeL10n.getBase().getString("BookmarkEditorToadlet.nameLabel") + ' ');
                addForm.addChild("input", new String[]{"type", "name", "value"}, new String[]{"text", "name", request.getParam("desc")});
                addForm.addChild("br");
                addForm.addChild("input", new String[]{"type", "name", "value"}, new String[]{"hidden", "bookmark", "/"});
                addForm.addChild("input", new String[]{"type", "name", "value"}, new String[]{"hidden", "action", "addItem"});
                addForm.addChild("label", "for", "descB", NodeL10n.getBase().getString("BookmarkEditorToadlet.descLabel") + ' ');
                addForm.addChild("br");
                addForm.addChild("textarea", new String[]{"id", "name", "row", "cols"}, new String[]{"descB", "descB", "3", "70"});
                if(node.getDarknetConnections().length > 0) {
                  addForm.addChild("br");
                  addForm.addChild("br");

                  HTMLNode peerTable = addForm.addChild("table", "class", "darknet_connections");
                  peerTable.addChild("th", "colspan", "2", NodeL10n.getBase().getString("BookmarkEditorToadlet.recommendToFriends"));
                  for(DarknetPeerNode peer : node.getDarknetConnections()) {
                    HTMLNode peerRow = peerTable.addChild("tr", "class", "darknet_connections_normal");
                    peerRow.addChild("td", "class", "peer-marker").addChild("input", new String[] { "type", "name" }, new String[] { "checkbox", "node_" + peer.hashCode() });
                    peerRow.addChild("td", "class", "peer-name").addChild("#", peer.getName());
                  }

                  addForm.addChild("label", "for", "descB", (NodeL10n.getBase().getString("BookmarkEditorToadlet.publicDescLabel") + ' '));
                  addForm.addChild("br");
                  addForm.addChild("textarea", new String[]{"id", "name", "row", "cols"}, new String[]{"descB", "publicDescB", "3", "70"}, "");
                }
                addForm.addChild("br");

                addForm.addChild("input", new String[]{"type", "name", "value"}, new String[]{"submit", "addbookmark", NodeL10n.getBase().getString("BookmarkEditorToadlet.addBookmark")});

                this.writeHTMLReply(ctx, 200, "OK", pageNode.generate());
                return;
        } else if (uri.getQuery() != null && uri.getQuery().startsWith("_CHECKED_HTTP_=")) {
    //Redirect requests for escaped URLs using the old destination to ExternalLinkToadlet.
    super.writeTemporaryRedirect(ctx, "Depreciated", ExternalLinkToadlet.PATH+'?'+uri.getQuery());
    return;
        }
        }

        PageNode page = ctx.getPageMaker().getPageNode(l10n("homepageFullTitle"), ctx);
        HTMLNode pageNode = page.outer;
        HTMLNode contentNode = page.content;

        String useragent = ctx.getHeaders().get("user-agent");

        if (useragent != null) {
            useragent = useragent.toLowerCase();
            if ((useragent.indexOf("msie") > -1) && (useragent.indexOf("opera") == -1)) {
              ctx.getPageMaker().getInfobox("infobox-alert", l10n("ieWarningTitle"), contentNode, "internet-explorer-used", true).
                  addChild("#", l10n("ieWarning"));
            }
        }

        // Alerts
        if (ctx.isAllowedFullAccess()) {
      contentNode.addChild(ctx.getAlertManager().createSummary());
        }
   
        if (ctx.getPageMaker().getTheme().fetchKeyBoxAboveBookmarks) {
            this.putFetchKeyBox(ctx, contentNode);
        }
       
        // Bookmarks
        HTMLNode bookmarkBox = contentNode.addChild("div", "class", "infobox infobox-normal bookmarks-box");
        HTMLNode bookmarkBoxHeader = bookmarkBox.addChild("div", "class", "infobox-header");
        bookmarkBoxHeader.addChild("a", new String[]{"class", "title"}, new String[]{"bookmarks-header-text", NodeL10n.getBase().getString("BookmarkEditorToadlet.myBookmarksExplanation")}, NodeL10n.getBase().getString("BookmarkEditorToadlet.myBookmarksTitle"));
        if (ctx.isAllowedFullAccess()) {
            bookmarkBoxHeader.addChild("span", "class", "edit-bracket", "[");
            bookmarkBoxHeader.addChild("span", "id", "bookmarkedit").addChild("a", new String[]{"href", "class"}, new String[]{"/bookmarkEditor/", "interfacelink"}, NodeL10n.getBase().getString("BookmarkEditorToadlet.edit"));
            bookmarkBoxHeader.addChild("span", "class", "edit-bracket", "]");
        }

        HTMLNode bookmarkBoxContent = bookmarkBox.addChild("div", "class", "infobox-content");
       
       
        HTMLNode bookmarksList = bookmarkBoxContent.addChild("ul", "id", "bookmarks");
    if (ctx.isAllowedFullAccess() || !ctx.getContainer().publicGatewayMode()) {
      addCategoryToList(BookmarkManager.MAIN_CATEGORY, bookmarksList, (!container.enableActivelinks()) || (useragent != null && useragent.contains("khtml") && !useragent.contains("chrome")), ctx);
    }
    else {
      addCategoryToList(BookmarkManager.DEFAULT_CATEGORY, bookmarksList, (!container.enableActivelinks()) || (useragent != null && useragent.contains("khtml") && !useragent.contains("chrome")), ctx);
    }

    // Search Box
        // FIXME search box is BELOW bookmarks for now, until we get search fixed properly.
    HTMLNode searchBox = contentNode.addChild("div", "class", "infobox infobox-normal");
    searchBox.addAttribute("id", "search-freenet");
        searchBox.addChild("div", "class", "infobox-header").addChild("span", "class", "search-title-label", NodeL10n.getBase().getString("WelcomeToadlet.searchBoxLabel"));
    HTMLNode searchBoxContent = searchBox.addChild("div", "class", "infobox-content");
    // Search form
    if(node.pluginManager != null &&
        node.pluginManager.isPluginLoaded("plugins.Library.Main")) {
          // FIXME: Remove this once we have a non-broken index.
          searchBoxContent.addChild("span", "class", "search-warning-text", l10n("searchBoxWarningSlow"));
      HTMLNode searchForm = container.addFormChild(searchBoxContent, "/library/", "searchform");
          searchForm.addChild("input", new String[] { "type", "size", "name" }, new String[] { "text", "80", "search" });
          searchForm.addChild("input", new String[] { "type", "name", "value" }, new String[] { "submit", "find", l10n("searchFreenet") });
          // Search must be in a new window so that the user is able to browse the bookmarks.
          searchForm.addAttribute("target", "_blank");
        } else if(node.pluginManager == null ||
            node.pluginManager.isPluginLoadedOrLoadingOrWantLoad("Library")) {
      // Warn that search plugin is not loaded.
      HTMLNode textSpan = searchBoxContent.addChild("span", "class", "search-not-availible-warning");
      NodeL10n.getBase().addL10nSubstitution(textSpan, "WelcomeToadlet.searchPluginLoading", new String[] { "link" }, new HTMLNode[] { HTMLNode.link("/plugins/") });
        } else {
      // Warn that search plugin is not loaded.
      HTMLNode textSpan = searchBoxContent.addChild("span", "class", "search-not-availible-warning");
      NodeL10n.getBase().addL10nSubstitution(textSpan, "WelcomeToadlet.searchPluginNotLoaded", new String[] { "link" }, new HTMLNode[] { HTMLNode.link("/plugins/") });
    }
   
        if (!ctx.getPageMaker().getTheme().fetchKeyBoxAboveBookmarks) {
            this.putFetchKeyBox(ctx, contentNode);
        }

        // Version info and Quit Form
        HTMLNode versionContent = ctx.getPageMaker().getInfobox("infobox-information", l10n("versionHeader"), contentNode, "freenet-version", true);
        versionContent.addChild("span", "class", "freenet-full-version",
                NodeL10n.getBase().getString("WelcomeToadlet.version", new String[]{"fullVersion", "build", "rev"},
                new String[]{Version.publicVersion(), Integer.toString(Version.buildNumber()), Version.cvsRevision()}));
        versionContent.addChild("br");
        versionContent.addChild("span", "class", "freenet-ext-version",
            NodeL10n.getBase().getString("WelcomeToadlet.extVersion", new String[]{"build", "rev"},
                new String[]{Integer.toString(NodeStarter.extBuildNumber), NodeStarter.extRevisionNumber}));
        versionContent.addChild("br");
        if (ctx.isAllowedFullAccess()) {
          HTMLNode shutdownForm = ctx.addFormChild(versionContent, ".", "shutdownForm");
            shutdownForm.addChild("input", new String[]{"type", "name"}, new String[]{"hidden", "exit"});
           
            shutdownForm.addChild("input", new String[]{"type", "value"}, new String[]{"submit", l10n("shutdownNode")});
            if (node.isUsingWrapper()) {
                HTMLNode restartForm = ctx.addFormChild(versionContent, ".", "restartForm");
                restartForm.addChild("input", new String[]{"type", "name"}, new String[]{"hidden", "restart"});
                restartForm.addChild("input", new String[]{"type", "name", "value"}, new String[]{"submit", "restart2", l10n("restartNode")});
            }
        }

        this.writeHTMLReply(ctx, 200, "OK", pageNode.generate());
    }
View Full Code Here

        this.writeHTMLReply(ctx, 200, "OK", pageNode.generate());
    }

  private void putFetchKeyBox(ToadletContext ctx, HTMLNode contentNode) {
    // Fetch-a-key box
    HTMLNode fetchKeyContent = ctx.getPageMaker().getInfobox("infobox-normal", l10n("fetchKeyLabel"), contentNode, "fetch-key", true);
    fetchKeyContent.addAttribute("id", "keyfetchbox");
    HTMLNode fetchKeyForm = fetchKeyContent.addChild("form", new String[]{"action", "method"}, new String[]{"/", "get"}).addChild("div");
    fetchKeyForm.addChild("span", "class", "fetch-key-label", l10n("keyRequestLabel") + ' ');
    fetchKeyForm.addChild("input", new String[]{"type", "size", "name"}, new String[]{"text", "80", "key"});
    fetchKeyForm.addChild("input", new String[]{"type", "value"}, new String[]{"submit", l10n("fetch")});
  }
View Full Code Here

  }
   
    static HTMLNode sendRestartingPageInner(ToadletContext ctx) {
        // Tell the user that the node is restarting
        PageNode page = ctx.getPageMaker().getPageNode("Node Restart", ctx, new RenderParameters().renderNavigationLinks(false));
        HTMLNode pageNode = page.outer;
        HTMLNode headNode = page.headNode;
        headNode.addChild("meta", new String[]{"http-equiv", "content"}, new String[]{"refresh", "20; url="});
        HTMLNode contentNode = page.content;
        ctx.getPageMaker().getInfobox("infobox-information", l10n("restartingTitle"), contentNode, "shutdown-progressing", true).
          addChild("#", l10n("restarting"));
        Logger.normal(WelcomeToadlet.class, "Node is restarting");
        return pageNode;
    }
View Full Code Here

    public static void maybeDisplayWrapperLogfile(ToadletContext ctx, HTMLNode contentNode) {
        final File logs = new File("wrapper.log");
        long logSize = logs.length();
        if(logs.exists() && logs.isFile() && logs.canRead() && (logSize > 0)) {
            HTMLNode logInfoboxContent = ctx.getPageMaker().getInfobox("infobox-info", "Current status", contentNode, "start-progress", true);
            LineReadingInputStream logreader = null;
            try {
                logreader = FileUtil.getLogTailReader(logs, 2000);
              String line;
              while ((line = logreader.readLine(100000, 200, true)) != null) {
                  logInfoboxContent.addChild("#", line);
                  logInfoboxContent.addChild("br");
              }
            } catch(IOException e) {}
            finally {
                Closer.close(logreader);
            }
View Full Code Here

  }

  private void drawJVMStatsBox(HTMLNode jvmStatsInfobox, boolean advancedModeEnabled) {
   
    jvmStatsInfobox.addChild("div", "class", "infobox-header", l10n("jvmInfoTitle"));
    HTMLNode jvmStatsInfoboxContent = jvmStatsInfobox.addChild("div", "class", "infobox-content");
    HTMLNode jvmStatsList = jvmStatsInfoboxContent.addChild("ul");

    Runtime rt = Runtime.getRuntime();
    long freeMemory = rt.freeMemory();
    long totalMemory = rt.totalMemory();
    long maxMemory = rt.maxMemory();

    long usedJavaMem = totalMemory - freeMemory;
    long allocatedJavaMem = totalMemory;
    long maxJavaMem = maxMemory;
    int availableCpus = rt.availableProcessors();

    int threadCount = stats.getActiveThreadCount();

    jvmStatsList.addChild("li", l10n("usedMemory", "memory", SizeUtil.formatSize(usedJavaMem, true)));
    jvmStatsList.addChild("li", l10n("allocMemory", "memory", SizeUtil.formatSize(allocatedJavaMem, true)));
    jvmStatsList.addChild("li", l10n("maxMemory", "memory", SizeUtil.formatSize(maxJavaMem, true)));
    jvmStatsList.addChild("li", l10n("threads", new String[] { "running", "max" },
        new String[] { thousandPoint.format(threadCount), Integer.toString(stats.getThreadLimit()) }));
    jvmStatsList.addChild("li", l10n("cpus", "count", Integer.toString(availableCpus)));
    jvmStatsList.addChild("li", l10n("javaVersion", "version", System.getProperty("java.version")));
    jvmStatsList.addChild("li", l10n("jvmVendor", "vendor", System.getProperty("java.vendor")));
    jvmStatsList.addChild("li", l10n("jvmName", "name", System.getProperty("java.vm.name")));
    jvmStatsList.addChild("li", l10n("jvmVersion", "version", System.getProperty("java.vm.version")));
    jvmStatsList.addChild("li", l10n("osName", "name", System.getProperty("os.name")));
    jvmStatsList.addChild("li", l10n("osVersion", "version", System.getProperty("os.version")));
    jvmStatsList.addChild("li", l10n("osArch", "arch", System.getProperty("os.arch")));
    if(advancedModeEnabled) {
      if(Rijndael.AesCtrProvider == null)
        jvmStatsList.addChild("li", l10n("cryptoUsingBuiltin"));
      else
        jvmStatsList.addChild("li", l10n("cryptoUsingJCA", "provider", Rijndael.getProviderName()));
    }
  }
View Full Code Here

  }
 
  private void drawThreadPriorityStatsBox(HTMLNode node) {
   
    node.addChild("div", "class", "infobox-header", l10n("threadsByPriority"));
    HTMLNode threadsInfoboxContent = node.addChild("div", "class", "infobox-content");
    int[] activeThreadsByPriority = stats.getActiveThreadsByPriority();
    int[] waitingThreadsByPriority = stats.getWaitingThreadsByPriority();
   
    HTMLNode threadsByPriorityTable = threadsInfoboxContent.addChild("table", "border", "0");
    HTMLNode row = threadsByPriorityTable.addChild("tr");

    row.addChild("th", l10n("priority"));
    row.addChild("th", l10n("running"));
    row.addChild("th", l10n("waiting"));
   
    for(int i=0; i<activeThreadsByPriority.length; i++) {
      row = threadsByPriorityTable.addChild("tr");
      row.addChild("td", String.valueOf(i+1));
      row.addChild("td", String.valueOf(activeThreadsByPriority[i]));
      row.addChild("td", String.valueOf(waitingThreadsByPriority[i]));
    }
  }
View Full Code Here

    }
  }

  private void drawOpennetStatsBox(HTMLNode box, OpennetManager om) {
    box.addChild("div", "class", "infobox-header", l10n("opennetStats"));
    HTMLNode opennetStatsContent = box.addChild("div", "class", "infobox-content");
    om.drawOpennetStatsBox(opennetStatsContent);
  }
View Full Code Here

    om.drawOpennetStatsBox(opennetStatsContent);
  }
 
  private void drawSeedStatsBox(HTMLNode box, OpennetManager om) {
    box.addChild("div", "class", "infobox-header", l10n("seedStats"));
    HTMLNode opennetStatsContent = box.addChild("div", "class", "infobox-content");
    om.drawSeedStatsBox(opennetStatsContent);
  }
View Full Code Here

    om.drawSeedStatsBox(opennetStatsContent);
  }

  private void drawClientRequestersBox(HTMLNode box) {
    box.addChild("div", "class", "infobox-header", l10n("clientRequesterObjects"));
    HTMLNode masterContent = box.addChild("div", "class", "infobox-content");
    HTMLNode table = masterContent.addChild("table");
    HTMLNode row = table.addChild("tr");
    row.addChild("th", "RequestClient");
    row.addChild("th", l10n("clientRequesters.class"));
    row.addChild("th", l10n("clientRequesters.age"));
    row.addChild("th", l10n("clientRequesters.priorityClass"));
    row.addChild("th", l10n("clientRequesters.realtimeFlag"));
    row.addChild("th", l10n("clientRequesters.uri"));
    NumberFormat nf = NumberFormat.getInstance();
    nf.setMaximumFractionDigits(0);
    nf.setMinimumIntegerDigits(2);
    ClientRequester[] requests = ClientRequester.getAll();
    Arrays.sort(requests, new Comparator<ClientRequester>() {
        @Override
        public int compare(ClientRequester a, ClientRequester b) {
          return -Long.signum(a.creationTime - b.creationTime);
        }
      });
    long now = System.currentTimeMillis();
    for(ClientRequester request : requests) {
      if(request.isFinished() || request.isCancelled())
        continue;
      row = table.addChild("tr");
      RequestClient client = request.getClient();
      row.addChild("td", client.toString());
      try {
        String s = request.toString();
        if(s.indexOf(':') > s.indexOf('@')) {
          s = s.substring(0, s.indexOf(':'));
        }
        row.addChild("td", s);
      } catch (Throwable t) {
        // FIXME shouldn't happen...
        row.addChild("td", "ERROR: "+request.getClass().toString());
      }
      long diff = now - request.creationTime;
      StringBuilder sb = new StringBuilder();
      sb.append(TimeUtil.formatTime(diff, 2));
      row.addChild("td", sb.toString());
      row.addChild("td", Short.toString(request.getPriorityClass()));
      row.addChild("td", client==null ? "?" : Boolean.toString(client.realTimeFlag()));
      FreenetURI uri = request.getURI(); // getURI() sometimes returns null, eg for ClientPutters
      row.addChild("td", uri == null ? "null" : uri.toString());
    }
  }
View Full Code Here

TOP

Related Classes of freenet.support.HTMLNode

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.