java.lang.Object
net.i2p.router.web.HelperBase
net.i2p.router.web.ContentHelper
- Direct Known Subclasses:
NewsHelper
Helper for including static content files in router console pages.
Field Summary
FieldsFields inherited from class HelperBase
_context, _log, _out, CHECKED, PROP_ADVANCED, SELECTEDModifier and TypeFieldDescriptionprotected RouterContextThe router context.protected LogThe log instance.protected WriterThe writer for output.static final StringChecked attribute for HTML checkboxes.static final StringProperty key for advanced mode.static final StringSelected attribute for HTML select options.Constructor Summary
ConstructorsConstructorDescriptionConstructor, used by the console to build the bean before the setters below populate it.Method Summary
Modifier and TypeMethodDescriptionprivate Stringfilename()Convert file.ext to file_lang.ext if it exists.Return the raw text of the resolved page file.Return the page text escaped for HTML and wrapped in a "pre" element.voidBean property setter, intentionally a no-op.voidsetMaxLines(String lines) Limits how many lines of the file are read in.voidCaution, use absolute paths only, do not assume files are in CWD.voidChooses which end of the file to keep when trimming to maxLines.Methods inherited from class HelperBase
_t, _t, _t, _x, getChecked, isAdvanced, ngettext, setContextId, storeWriterModifier and TypeMethodDescriptionTranslate a string.Translate a string with a parameter.Translate a string with two parameters.static StringMark a string for extraction by xgettext and translation.protected StringgetChecked(String prop) Get the checked attribute for a boolean property.booleanCheck if advanced mode is enabled.Translate a string with plural forms (ngettext).voidsetContextId(String contextId) Configure this bean to query a particular router context.voidstoreWriter(Writer out) Store the writer for output.
Field Details
_page
Absolute path of the content file to include, empty until set._maxLines
private int _maxLinesMost lines shown on the page._startAtBeginning
private boolean _startAtBeginningTrue to show the start of the log, not the end._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 untilsetPage(String)supplies a file, andgetContent()has nothing to read before that.
Method Details
setPage
Caution, use absolute paths only, do not assume files are in CWD.- Parameters:
page- the absolute path of the content file to include, resolved byfilename()to a localized variant such as file_lang.ext when one exists
setStartAtBeginning
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
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 byCSSHelper.- Parameters:
l- the requested language, accepted so the bean property keeps working but discarded
setMaxLines
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
Return the raw text of the resolved page file.- Returns:
- the file text, or an empty string if it cannot be read
getTextContent
Return the page text escaped for HTML and wrapped in a "pre" element.- Returns:
- the text content
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