2009-01-29 02:16:18 +00:00
|
|
|
package net.i2p.router.web;
|
|
|
|
|
|
|
|
import java.io.Writer;
|
|
|
|
|
|
|
|
import net.i2p.router.RouterContext;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Base helper
|
|
|
|
*/
|
|
|
|
public abstract class HelperBase {
|
|
|
|
protected RouterContext _context;
|
|
|
|
protected Writer _out;
|
|
|
|
|
2013-10-04 19:06:39 +00:00
|
|
|
static final String PROP_ADVANCED = "routerconsole.advanced";
|
2015-12-18 14:43:31 +00:00
|
|
|
static final String CHECKED = " checked=\"checked\" ";
|
2013-10-04 19:06:39 +00:00
|
|
|
|
2009-01-29 02:16:18 +00:00
|
|
|
/**
|
|
|
|
* Configure this bean to query a particular router context
|
|
|
|
*
|
2009-08-14 01:52:47 +00:00
|
|
|
* @param contextId beginning few characters of the routerHash, or null to pick
|
2009-01-29 02:16:18 +00:00
|
|
|
* the first one we come across.
|
|
|
|
*/
|
|
|
|
public void setContextId(String contextId) {
|
|
|
|
try {
|
|
|
|
_context = ContextHelper.getContext(contextId);
|
|
|
|
} catch (Throwable t) {
|
|
|
|
t.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-04 19:06:39 +00:00
|
|
|
/** @since 0.9.9 */
|
|
|
|
public boolean isAdvanced() {
|
|
|
|
return _context.getBooleanProperty(PROP_ADVANCED);
|
|
|
|
}
|
|
|
|
|
2009-08-14 01:52:47 +00:00
|
|
|
/** might be useful in the jsp's */
|
|
|
|
//public RouterContext getContext() { return _context; }
|
|
|
|
|
2010-11-21 20:46:48 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Renamed from setWriter, we realy don't want setFoo(non-String)
|
|
|
|
* Prevent jsp.error.beans.property.conversion 500 error for ?writer=foo
|
|
|
|
* @since 0.8.2
|
|
|
|
*/
|
|
|
|
public void storeWriter(Writer out) { _out = out; }
|
2009-10-18 14:06:07 +00:00
|
|
|
|
2015-12-18 14:43:31 +00:00
|
|
|
/**
|
|
|
|
* Is a boolean property set to true?
|
|
|
|
*
|
|
|
|
* @param prop must default to false
|
|
|
|
* @return non-null, either "" or " checked=\"checked\" "
|
|
|
|
* @since 0.9.24 consolidated from various helpers
|
|
|
|
*/
|
|
|
|
protected String getChecked(String prop) {
|
|
|
|
if (_context.getBooleanProperty(prop))
|
|
|
|
return CHECKED;
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2009-10-18 14:06:07 +00:00
|
|
|
/** translate a string */
|
2015-09-25 19:55:36 +00:00
|
|
|
public String _t(String s) {
|
2009-10-18 14:06:07 +00:00
|
|
|
return Messages.getString(s, _context);
|
|
|
|
}
|
2009-10-22 22:25:53 +00:00
|
|
|
|
2009-10-26 14:24:25 +00:00
|
|
|
/**
|
|
|
|
* translate a string with a parameter
|
2015-09-25 19:55:36 +00:00
|
|
|
* This is a lot more expensive than _t(s), so use sparingly.
|
2009-10-26 14:24:25 +00:00
|
|
|
*
|
|
|
|
* @param s string to be translated containing {0}
|
|
|
|
* The {0} will be replaced by the parameter.
|
|
|
|
* Single quotes must be doubled, i.e. ' -> '' in the string.
|
|
|
|
* @param o parameter, not translated.
|
2015-11-16 19:32:00 +00:00
|
|
|
* To translate parameter also, use _t("foo {0} bar", _t("baz"))
|
2009-10-26 14:24:25 +00:00
|
|
|
* Do not double the single quotes in the parameter.
|
|
|
|
* Use autoboxing to call with ints, longs, floats, etc.
|
|
|
|
*/
|
2015-09-25 19:55:36 +00:00
|
|
|
public String _t(String s, Object o) {
|
2009-10-26 14:24:25 +00:00
|
|
|
return Messages.getString(s, o, _context);
|
|
|
|
}
|
|
|
|
|
2010-06-02 18:16:43 +00:00
|
|
|
/** two params @since 0.7.14 */
|
2015-09-25 19:55:36 +00:00
|
|
|
public String _t(String s, Object o, Object o2) {
|
2010-06-02 18:16:43 +00:00
|
|
|
return Messages.getString(s, o, o2, _context);
|
|
|
|
}
|
|
|
|
|
2010-05-27 00:38:32 +00:00
|
|
|
/** translate (ngettext) @since 0.7.14 */
|
2011-03-12 21:32:29 +00:00
|
|
|
public String ngettext(String s, String p, int n) {
|
2010-05-27 00:38:32 +00:00
|
|
|
return Messages.getString(n, s, p, _context);
|
|
|
|
}
|
|
|
|
|
2009-10-22 22:25:53 +00:00
|
|
|
/**
|
|
|
|
* Mark a string for extraction by xgettext and translation.
|
|
|
|
* Use this only in static initializers.
|
|
|
|
* It does not translate!
|
|
|
|
* @return s
|
|
|
|
*/
|
|
|
|
public static String _x(String s) {
|
|
|
|
return s;
|
|
|
|
}
|
2009-01-29 02:16:18 +00:00
|
|
|
}
|