java.lang.Object
net.i2p.router.web.HelperBase
net.i2p.router.web.ContentHelper
Direct Known Subclasses:
NewsHelper

public class ContentHelperextends HelperBase
Helper for including static content files in router console pages.
  • Field Details

    • _page

      protected String _page
      Absolute path of the content file to include, empty until set.
    • _maxLines

      private int _maxLines
      Most lines shown on the page.
    • _startAtBeginning

      private boolean _startAtBeginning
      True to show the start of the log, not the end.
    • _lang

      private String _lang
      Language of the page being rendered.
  • Constructor Details

    • ContentHelper

      public ContentHelper()
      Constructor, used by the console to build the bean before the setters below populate it. Nothing is selected until setPage(String) supplies a file, and getContent() has nothing to read before that.
  • Method Details

    • setPage

      public void setPage(String page)
      Caution, use absolute paths only, do not assume files are in CWD.
      Parameters:
      page - the absolute path of the content file to include, resolved by filename() to a localized variant such as file_lang.ext when one exists
    • setStartAtBeginning

      public void setStartAtBeginning(String moo)
      Chooses which end of the file to keep when trimming to maxLines.
      Parameters:
      moo - parsed as a boolean: true keeps the first lines of the file, false (the default) keeps the last
    • setLang

      public void setLang(String l)
      Bean property setter, intentionally a no-op. An earlier version persisted the language here for the desktopgui, but that bypassed the CSRF nonce check; language is now handled by CSSHelper.
      Parameters:
      l - the requested language, accepted so the bean property keeps working but discarded
    • setMaxLines

      public void setMaxLines(String lines)
      Limits how many lines of the file are read in.
      Parameters:
      lines - the maximum number of lines to keep, parsed as an integer; null or any non-numeric value means unlimited
    • getContent

      public String getContent()
      Return the raw text of the resolved page file.
      Returns:
      the file text, or an empty string if it cannot be read
    • getTextContent

      public String getTextContent()
      Return the page text escaped for HTML and wrapped in a "pre" element.
      Returns:
      the text content
    • filename

      private String filename()
      Convert file.ext to file_lang.ext if it exists. Get lang from the cgi lang param, then properties, then from the default locale. _context must be set to check the property.
      Returns:
      the localized page filename, or the original page if no localized file exists