<%@ page import="java.io.*, java.util.*, org.openisis.*" session="false" %><%! // need at least Field.html static File _dir ; // have no reliable ServletConfig before init static long timestamp; static String[] files; static synchronized void refresh ( ServletContext a ) throws IOException { if ( null == _dir ) _dir = new File( a.getRealPath("doc") ); files = _dir.list( new FilenameFilter() { public boolean accept( File _dir, String name ) { return name.endsWith( ".txt" ); } } ); Arrays.sort( files ); timestamp = _dir.lastModified(); } // mini wiki-style doc static String mikidoc ( Writer o, BufferedReader in ) throws IOException { String notes = null; String l; boolean inli = false; boolean br = false; // break on any line boolean code = false; // code mode while ( null != (l = in.readLine()) ) { int len = l.length(); boolean isli = false; char c = 0 == len ? 0 : l.charAt(0); int tab = 1 < len && '\t' == l.charAt(1) ? 2 : 1; if ( code && '$' != c ) l = Field.html( l ); else switch( c ) { case 0: l = "
"; break; case '$': // toggle code l = (code = !code) ? "
" : "
"; break; case '*': // head String bg = "#CCCCCC"; String anchor = ""; if ( 1==tab && 2 < len && ' ' != l.charAt(1) ) { /* make anchor */ int i = l.indexOf( '\t' ); if ( 1 < i ) { tab = i+1; anchor = " "; } } l = "" +anchor+l.substring(tab) +""; break; case '-': if ( l.startsWith("---") ) { // rule l = "
"; break; // rule :) } // new list item l = (inli ? "" : "" ); o.write( l ); if ( br && ! l.endsWith( "
" ) ) o.write( "
\n" ); else o.write( '\n' ); inli = isli; } return notes; } static String mikidoc ( Writer o, String file ) throws IOException { file = _dir+File.separator+file; try { return mikidoc( o, new BufferedReader( new InputStreamReader( new FileInputStream( file ) ) ) ); } catch (IOException e) { o.write( "" ); } return null; } %><% if ( null == _dir || timestamp != _dir.lastModified() ) refresh( application ); String right = null; String file = request.getParameter("file")+".txt"; boolean sides = null == request.getParameter("print"); String name = ""; int f = files.length; while ( 0 < f-- && !files[f].equals(file) ) ; file = 0 > f ? "OverView.txt" : files[f]; name = file.substring( 0, file.length()-4 ); %> OpenIsis - <%=name%> <% if ( sides ) { %> <%-- left: the index --%> <%-- middle: the content --%>
<% mikidoc( out, ".index" ); %>
print
plaintext
<% } // sides %>
<%= name %>
<% right = mikidoc( out, file ); %>
<% if ( sides ) { %> <% if ( null != right ) { %> <%-- right: notes --%>
<%= right %>
<% mikidoc( out, right+".txt" ); %>
<% } %>
<% } // sides %>