package net.i2p.router.web;

import net.i2p.router.RouterContext;
import net.i2p.util.FileUtil;

public class ContentHelper {
    private String _page;
    private int _maxLines;
    private boolean _startAtBeginning;
    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; }
    public void setStartAtBeginning(String moo) { 
        _startAtBeginning = Boolean.valueOf(""+moo).booleanValue(); 
    }
    
    public void setMaxLines(String lines) {
        if (lines != null) {
            try {
                _maxLines = Integer.parseInt(lines);
            } catch (NumberFormatException nfe) {
                _maxLines = -1;
            }
        } else {
            _maxLines = -1;
        }
    } 
    public String getContent() {
        String str = FileUtil.readTextFile(_page, _maxLines, _startAtBeginning);
        if (str == null) 
            return "";
        else 
            return str;
    } 
    public String getTextContent() {
        String str = FileUtil.readTextFile(_page, _maxLines, _startAtBeginning);
        if (str == null) 
            return "";
        else 
            return "<pre>" + str + "</pre>";
    }
}

@@ -1582,32 +1582,33 @@
 %22;%0A        else 
+%7B
 %0A            ret
@@ -1608,40 +1608,529 @@
     
-return %22%3Cpre%3E%22 + str + %22%3C/pre%3E%22;
+StringBuffer sb = new StringBuffer(str.length()+11);%0A            sb.append(%22%3Cpre%3E%22);%0A            for (int i=0; i %3C str.length(); i++) %7B%0A                char c = str.charAt(i);%0A                switch (str.charAt(i)) %7B%0A                    case '%3C': sb.append(%22&lt;%22); break;%0A                    case '%3E': sb.append(%22&gt;%22); break;%0A                    case '&': sb.append(%22&amp;%22); break;%0A                    default: sb.append(c); break;%0A                %7D%0A            %7D%0A            return sb.append(%22%3C/pre%3E%22).toString();%0A%09%7D
 %0A   

fix ugliness in release history of help.jsp