<config> tags (which use values from all2xml.conf) are now properly handled
[webpac] / openisis / doc.jsp
1 <%@     page import="java.io.*, java.util.*, org.openisis.*"
2         session="false"
3 %><%!
4         // need at least Field.html
5         static File _dir ; // have no reliable ServletConfig before init
6         static long timestamp;
7         static String[] files;
8         static synchronized void refresh ( ServletContext a ) throws IOException {
9                 if ( null == _dir )
10                         _dir = new File( a.getRealPath("doc") );
11                 files = _dir.list( new FilenameFilter() {
12                         public boolean accept( File _dir, String name ) {
13                                 return name.endsWith( ".txt" );
14                         }
15                 } );
16                 Arrays.sort( files );
17                 timestamp = _dir.lastModified();
18         }
19
20         // mini wiki-style doc
21         static String mikidoc ( Writer o, BufferedReader in )
22                 throws IOException
23         {
24                 String notes = null;
25                 String l;
26                 boolean inli = false;
27                 boolean br = false; // break on any line
28                 boolean code = false; // code mode
29                 while ( null != (l = in.readLine()) ) {
30                         int len = l.length();
31                         boolean isli = false;
32                         char c = 0 == len ? 0 : l.charAt(0);
33                         int tab = 1 < len && '\t' == l.charAt(1) ? 2 : 1;
34                         if ( code && '$' != c )
35                                 l = Field.html( l );
36                         else switch( c ) {
37                         case 0:
38                                 l = "<br>";
39                                 break;
40                         case '$': // toggle code
41                                 l = (code = !code) ? "<pre>" : "</pre>";
42                                 break;
43                         case '*': // head
44                                 String bg = "#CCCCCC";
45                                 String anchor = "";
46                                 if ( 1==tab && 2 < len && ' ' != l.charAt(1) ) { /* make anchor */
47                                         int i = l.indexOf( '\t' );
48                                         if ( 1 < i ) {
49                                                 tab = i+1;
50                                                 anchor = "<a name=\""+l.substring(1,i)+"\">&nbsp;</a>";
51                                         }
52                                 }
53                                 l = "</td></tr><tr><td bgcolor=\""+bg+"\"><b>"
54                                         +anchor+l.substring(tab)
55                                         +"</b></td></tr><tr><td align=\"justify\">";
56                                 break;
57                         case '-':
58                                 if ( l.startsWith("---") ) { // rule
59                                         l = "<hr>";
60                                         break; // rule :)
61                                 }
62                                 // new list item
63                                 l = (inli ? "</li>" : "<ul>") + "<li>" + l.substring(tab);
64                                 if ( 40 > len ) // break after short heading
65                                         l += "<br>";
66                                 isli = true;
67                                 break;
68                         case '\t': // indented
69                                 isli = inli; // continue list item, if any
70                                 if ( 1 == len )
71                                         l = "\t<br>";
72                                 break;
73                         case '>': // link
74                                 isli = inli; // dont't break lists on links
75                                 int t = l.indexOf('\t',tab);
76                                 String ref, name;
77                                 if ( 0 > t )
78                                         ref = name = l.substring(tab).trim();
79                                 else {
80                                         ref = l.substring(tab,t).trim();
81                                         name = l.substring(t+1).trim();
82                                 }
83                                 l = "<a href=\""+ref+"\">"+name+"</a>";
84                                 break;
85                         case '.':
86                                 if ( l.startsWith("...") ) { // continued
87                                         notes = l.substring(3).trim();
88                                         continue;
89                                 }
90                                 break;
91                         case '!': // pre
92                                 br = true;
93                         case ';': // comment
94                                 continue;
95                         }
96                         if ( inli && !isli )
97                                 o.write( "</ul>" );
98                         o.write( l );
99                         if ( br && ! l.endsWith( "<br>" ) )
100                                 o.write( "<br>\n" );
101                         else
102                                 o.write( '\n' );
103                         inli = isli;
104                 }
105                 return notes;
106         }
107
108         static String mikidoc ( Writer o, String file )
109                 throws IOException
110         {
111                 file = _dir+File.separator+file;
112                 try {
113                         return mikidoc( o, new BufferedReader( new InputStreamReader(
114                                 new FileInputStream( file ) ) ) );
115                 } catch (IOException e) {
116                         o.write( "<!-- schnurps -->" );
117                 }
118                 return null;
119         }
120
121 %><%
122         if ( null == _dir || timestamp != _dir.lastModified() )
123                 refresh( application );
124
125         String right = null;
126         String file  = request.getParameter("file")+".txt";
127         boolean sides = null == request.getParameter("print");
128         String name = "";
129         int f = files.length;
130         while ( 0 < f-- && !files[f].equals(file) )
131                 ;
132         file = 0 > f ? "OverView.txt" : files[f];
133         name = file.substring( 0, file.length()-4 );
134 %><html>
135 <head>
136   <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
137   <title>OpenIsis - <%=name%></title>
138         <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
139 </head>
140 <body bgcolor="#FFFFFF"
141         marginwidth="0" marginheight="0" topmargin="0" leftmargin="0">
142 <% if ( sides ) { %>
143 <table width="100%" cellpadding="0" cellspacing="0"
144         marginwidth="0" marginheight="0" topmargin="0" leftmargin="0" border="0">
145 <tr>
146         <%-- left: the index --%>
147         <td valign="top" width="160">
148   <table border="0" cellspacing="5" width="100%" cols="1">
149         <tr>
150                 <td valign="top">
151 <% mikidoc( out, ".index" ); %>
152                 <hr>
153                 <a href="<%=name%>?print=">print</a><br>
154                 <a href="/doc/<%=file%>">plaintext</a>
155                 </td>
156         </tr>
157         </table>
158         </td>
159         <%-- middle: the content --%>
160         <td valign="top">
161 <% } // sides %>
162   <table border="0" cellspacing="5" width="100%" cols="1">
163         <tr>
164                 <td valign="top" bgcolor="#000000"><font color="#FFFFFF"><b>
165         <%= name %>
166                 </b></font></td>
167         </tr>
168         <tr>
169                 <td align="justify">
170 <% right = mikidoc( out, file ); %>
171                 </td>
172         </tr>
173         </table>
174 <% if ( sides ) { %>
175 <%
176         if ( null != right ) {
177 %>
178         <%-- right: notes --%>
179         </td>
180         <td valign="top" width="25%">
181   <table border="0" cellspacing="5" width="100%" cols="1">
182         <tr>
183                 <td valign="top" bgcolor="#000000"><font color="#FFFFFF"><b>
184         <%= right %>
185                 </b></font></td>
186         </tr>
187         <tr>
188                 <td align="justify">
189 <% mikidoc( out, right+".txt" ); %>
190                 </td>
191         </tr>
192         </table>
193 <%
194         }
195 %>
196         </td>
197 </tr>
198 </table>
199 <% } // sides %>
200 <!--
201 $Revision: 1.6 $ last changed $Date: 2003/01/06 19:54:29 $ by $Author: kripke $
202 -->
203 </body>
204 </html>