2004-08-26 08:00:16 +00:00
|
|
|
package net.i2p.router.web;
|
|
|
|
|
|
|
|
import net.i2p.router.RouterContext;
|
2004-09-29 19:34:02 +00:00
|
|
|
import net.i2p.util.FileUtil;
|
2004-08-26 08:00:16 +00:00
|
|
|
|
|
|
|
public class ContentHelper {
|
|
|
|
private String _page;
|
|
|
|
private int _maxLines;
|
2004-11-25 21:57:19 +00:00
|
|
|
private boolean _startAtBeginning;
|
2004-08-26 08:00:16 +00:00
|
|
|
private RouterContext _context;
|
|
|
|
/**
|
|
|
|
* Configure this bean to query a particular router context
|
|
|
|
*
|
|
|
|
* @param contextId begging few characters of the routerHash, or null to pick
|
|
|
|
* the first one we come across.
|
|
|
|
*/
|
|
|
|
public void setContextId(String contextId) {
|
|
|
|
try {
|
|
|
|
_context = ContextHelper.getContext(contextId);
|
|
|
|
} catch (Throwable t) {
|
|
|
|
t.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public ContentHelper() {}
|
|
|
|
|
|
|
|
public void setPage(String page) { _page = page; }
|
2004-11-25 21:57:19 +00:00
|
|
|
public void setStartAtBeginning(String moo) {
|
|
|
|
_startAtBeginning = Boolean.valueOf(""+moo).booleanValue();
|
|
|
|
}
|
|
|
|
|
2004-08-26 08:00:16 +00:00
|
|
|
public void setMaxLines(String lines) {
|
|
|
|
if (lines != null) {
|
|
|
|
try {
|
|
|
|
_maxLines = Integer.parseInt(lines);
|
|
|
|
} catch (NumberFormatException nfe) {
|
|
|
|
_maxLines = -1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
_maxLines = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public String getContent() {
|
2004-11-25 21:57:19 +00:00
|
|
|
String str = FileUtil.readTextFile(_page, _maxLines, _startAtBeginning);
|
2004-08-26 08:00:16 +00:00
|
|
|
if (str == null)
|
|
|
|
return "";
|
|
|
|
else
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
public String getTextContent() {
|
2004-11-25 21:57:19 +00:00
|
|
|
String str = FileUtil.readTextFile(_page, _maxLines, _startAtBeginning);
|
2004-08-26 08:00:16 +00:00
|
|
|
if (str == null)
|
|
|
|
return "";
|
|
|
|
else
|
|
|
|
return "<pre>" + str + "</pre>";
|
|
|
|
}
|
|
|
|
}
|