%@ 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 ? "" : "
") + "
" + l.substring(tab);
if ( 40 > len ) // break after short heading
l += " ";
isli = true;
break;
case '\t': // indented
isli = inli; // continue list item, if any
if ( 1 == len )
l = "\t ";
break;
case '>': // link
isli = inli; // dont't break lists on links
int t = l.indexOf('\t',tab);
String ref, name;
if ( 0 > t )
ref = name = l.substring(tab).trim();
else {
ref = l.substring(tab,t).trim();
name = l.substring(t+1).trim();
}
l = ""+name+"";
break;
case '.':
if ( l.startsWith("...") ) { // continued
notes = l.substring(3).trim();
continue;
}
break;
case '!': // pre
br = true;
case ';': // comment
continue;
}
if ( inli && !isli )
o.write( "
" );
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 ) { %>