/[webpac]/trunk/openisis/Demo.jsp
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /trunk/openisis/Demo.jsp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 239 - (show annotations)
Mon Mar 8 17:49:13 2004 UTC (20 years ago) by dpavlin
File size: 5083 byte(s)
including openisis 0.9.0 into webpac tree

1 <%@page import="org.openisis.*,java.io.IOException,java.util.Date"%>
2 <%!
3 static final String EMPTY = "";
4 static Db[] dbs = new Db[2];
5 static String dberr = EMPTY;
6 static {
7 try {
8 String[] args = new String[] { "-v", "error", "-encoding", "Cp850" };
9 dbs[0] = Db.open( "/var/db/cds/cds", args );
10 args = new String[] { "-v", "error", "-format", "aligned" };
11 dbs[1] = Db.open( "/var/db/unesb/unesb", args );
12 } catch (IOException e) {
13 e.printStackTrace();
14 dberr = e.toString();
15 }
16 };
17 static String NV ( String x ) { return null==x ? EMPTY : x; }
18 static int ROWS = 5; // number of rows to show at once
19 %>
20 <%
21 String search = NV( request.getParameter( "search" ) );
22 int off = 0;
23 int rows = ROWS;
24 int dbnum = -1;
25 try {
26 off = Integer.parseInt( request.getParameter( "off" ) );
27 } catch ( Exception e ) {}
28 try {
29 dbnum = Integer.parseInt( request.getParameter( "db" ) );
30 if ( dbs.length <= dbnum )
31 dbnum = -1;
32 } catch ( Exception e ) { }
33 if ( 0 > dbnum )
34 try {
35 dbnum = Integer.parseInt( (String)session.getAttribute( "db" ) );
36 } catch ( Exception e ) { dbnum = 0; }
37 else
38 session.setAttribute( "db", ""+dbnum );
39 Db db = dbs[dbnum];
40 try {
41 rows = Integer.parseInt( request.getParameter( "rows" ) );
42 } catch ( Exception e ) {}
43 int[] set = (int[])session.getAttribute( "set" );
44 %>
45 <html>
46 <head>
47 <title>OpenIsis JSP demo</title>
48 </head>
49 <body>
50 <%= dberr %>
51 <form action="Demo.jsp">
52 <input type="text" name="search" value="<%=search%>"/>
53 <input type="checkbox" name="narrow" value="1"/> narrow previous search
54 <input type="submit" name="action" value="search"/>
55 <input type="text" name="rows" size="2" value="<%=rows%>"/> rows at once
56 in
57 <select name="db">
58 <option value="0"<%= 0==dbnum ? " selected" : ""%>>cds</option>
59 <option value="1"<%= 1==dbnum ? " selected" : ""%>>unesb</option>
60 </select>
61 </form>
62 <b>
63 Note: $,"",*,+,^,(F),(G),..,$$,/(tag) are supported.
64 Queries are processed straight left to right.
65 </b>
66 <p>
67 <%
68 if ( EMPTY != search ) {
69 long then = (new Date()).getTime();
70 int[] nset = db.search( search, Db.QRY_SIMPLE );
71 long now = (new Date()).getTime();
72 if ( null == nset ) {
73 %>
74 sorry, no results for <%=search%>
75 <%
76 session.removeAttribute( "set" );
77 return;
78 } else {
79 %>
80 got <%=nset.length%> rows for <%=search%>
81 in <%=(now - then)/1000.%> seconds.<br>
82 <%
83 if ( null == set || null == request.getParameter("narrow") )
84 set = nset;
85 else { // and sets
86 set = Db.AND( set, nset );
87 %>
88 <%=set.length%> rows remaining after combine with previous search<br>
89 <%
90 }
91 session.setAttribute( "set", set );
92 }
93 } // EMPTY != search
94 if ( null == set )
95 return;
96 if ( 0 < off ) {
97 int boff = off-rows;
98 if ( boff < 0 ) boff = 0;
99 %>
100 <a href="Demo.jsp?off=<%=boff%>&rows=<%=rows%>">&lt;&lt;rows <%=boff+1%> to <%=boff+rows%></a>
101 <%
102 }
103 int end = off + rows;
104 if ( end >= set.length )
105 end = set.length;
106 else {
107 %>
108 <a href="Demo.jsp?off=<%=end%>&rows=<%=rows%>">rows <%=end+1%> to <%=end+rows%>&gt;&gt;</a>
109 <%
110 }
111 %>
112 <h4> rows <%=off+1%> to <%=end%> </h4>
113 <%-- start output --%>
114 <%
115 if ( 0 == dbnum ) {
116 for ( int i=off; i<end; i++ ) {
117 Rec r = db.readRow( set[i] );
118 if ( null == r ) continue;
119 int m = Db.MDL | Db.PS | Db.HTA;
120 String r13 = "<br>&nbsp;", s = "<br>";
121 %>
122 <p>
123 MFN : <%= r.getRowId() %><br>
124 <%= r.v("CONFERENCE : ",null,12,m,0,0,r13,s) %>
125 <%= r.v("TITLE : ",null,24,m,0,0,r13,s) %>
126 <%= r.v("AUTHOR(S) : ",null,14,m,0,0,"; "+r13+" ",s) %>
127 <%= r.v("EDITION : ",null,25,m,0,0,r13,s) %>
128 <%= r.v("IMPRINT : ",null,26,m,0,0,r13,s) %>
129 <%= r.v("COLLATION : ",null,30,m,0,0,r13,s) %>
130 <%= r.v("SERIES : ",null,44,m,0,0,r13,s) %>
131 <%= r.v("NOTES : ",null,50,m,0,0,r13,s) %>
132 <%= r.v("CORP. BODY : ",null,71,m,0,0,r13,s) %>
133 <%= r.v("ADDED CONF : ",null,72,m,0,0,r13,s) %>
134 <%= r.v("OTHER TITLE: ",null,74,m,0,0,r13,s) %>
135 <%= r.v("OTHER LANG : ",null,76,m|'*',0,0,r13,s) %>
136 <%= r.v("KEYWORDS : ",null,69,m,0,0,r13,s) %>
137 <%
138 }
139 } else {
140 %>
141 <table cols="4" width="100%">
142 <tr>
143 <td width="20">&nbsp;</td>
144 <td width="20">&nbsp;</td>
145 <td width="20">&nbsp;</td>
146 <td>&nbsp;</td>
147 </tr>
148 <%
149 for ( int i=off; i<end; i++ ) {
150 Rec r = db.readRow( set[i] );
151 if ( null == r ) {
152 %>
153 <tr>
154 <td colspan="4">
155 skip bad row <%=set[i]%> as <%=i+1%> of <%=set.length%>
156 </td>
157 </tr>
158 <%
159 continue;
160 }
161 int id = r.getRowId();
162 int l = r.getLen();
163 %>
164 <tr>
165 <td colspan="4">
166 row <%=id%> with <%=l%> fields as <%=i+1%> of <%=set.length%>
167 </td>
168 </tr>
169 <%
170 for ( int j=0; j<l; j++ ) {
171 Field f = r.getField(j);
172 %>
173 <tr>
174 <td> <%=id%> </td>
175 <td> <%=f.tag%> </td>
176 <td>&nbsp;</td>
177 <td> <%=f.html()%> </td>
178 </tr>
179 <%
180 if ( '^' == f.val.charAt(0) ) {
181 Field[] s = f.split();
182 if ( null == s )
183 continue;
184 for ( int k=0; k<s.length; k++ ) {
185 if ( null == s[k] )
186 continue;
187 %>
188 <tr>
189 <td> <%=id%> </td>
190 <td> <%=f.tag%> </td>
191 <td> <%=(char)s[k].tag%> </td>
192 <td> <%=s[k].html()%> </td>
193 </tr>
194 <%
195 } // for subfields
196 } // if subfields
197 } // for fields
198 } // for rows
199 %>
200 </table>
201 <% } %>
202 </body>

  ViewVC Help
Powered by ViewVC 1.1.26