Revision 237 (by dpavlin, 2004/03/08 17:43:12) initial import of openisis 0.9.0 vendor drop
<%@page import="org.openisis.*,java.io.IOException,java.util.Date"%>
<%!
	static final String EMPTY = "";
	static Db[] dbs = new Db[2];
	static String dberr = EMPTY;
	static {
		try {
			String[] args = new String[] { "-v", "error", "-encoding", "Cp850" };
			dbs[0] = Db.open( "/var/db/cds/cds", args );
			args = new String[] { "-v", "error", "-format", "aligned" };
			dbs[1] = Db.open( "/var/db/unesb/unesb", args );
		} catch (IOException e) {
			e.printStackTrace();
			dberr = e.toString();
		}
	};
	static String NV ( String x ) { return null==x ? EMPTY : x; }
	static int ROWS = 5; // number of rows to show at once
%>
<%
	String search = NV( request.getParameter( "search" ) );
	int off = 0;
	int rows = ROWS;
	int dbnum = -1;
	try {
		off = Integer.parseInt( request.getParameter( "off" ) );
	} catch ( Exception e ) {}
	try {
		dbnum = Integer.parseInt( request.getParameter( "db" ) );
		if ( dbs.length <= dbnum )
			dbnum = -1;
	} catch ( Exception e ) { }
	if ( 0 > dbnum )
		try {
			dbnum = Integer.parseInt( (String)session.getAttribute( "db" ) );
		} catch ( Exception e ) { dbnum = 0; }
	else
		session.setAttribute( "db", ""+dbnum );
	Db db = dbs[dbnum];
	try {
		rows = Integer.parseInt( request.getParameter( "rows" ) );
	} catch ( Exception e ) {}
	int[] set = (int[])session.getAttribute( "set" );
%>
<html>
<head>
  <title>OpenIsis JSP demo</title>
</head>
<body>
	<%= dberr %>
	<form action="Demo.jsp">
		<input type="text" name="search" value="<%=search%>"/>
		<input type="checkbox" name="narrow" value="1"/> narrow previous search
		<input type="submit" name="action" value="search"/>
		<input type="text" name="rows" size="2" value="<%=rows%>"/> rows at once
		in
		<select name="db">
		<option value="0"<%= 0==dbnum ? " selected" : ""%>>cds</option>
		<option value="1"<%= 1==dbnum ? " selected" : ""%>>unesb</option>
		</select>
	</form>
	<b>
	Note: $,"",*,+,^,(F),(G),..,$$,/(tag) are supported.
	Queries are processed straight left to right.
	</b>
<p>
<%
	if ( EMPTY != search ) {
		long then = (new Date()).getTime();
		int[] nset = db.search( search, Db.QRY_SIMPLE );
		long now = (new Date()).getTime();
		if ( null == nset ) {
%>
	sorry, no results for <%=search%>
<%
			session.removeAttribute( "set" );
			return;
		} else {
%>
	got <%=nset.length%> rows for <%=search%>
	in <%=(now - then)/1000.%> seconds.<br>
<%
			if ( null == set || null == request.getParameter("narrow") )
				set = nset;
			else { // and sets
				set = Db.AND( set, nset );
%>
	<%=set.length%> rows remaining after combine with previous search<br>
<%
			}
			session.setAttribute( "set", set );
		}
	} // EMPTY != search
	if ( null == set )
		return;
	if ( 0 < off ) {
		int boff = off-rows;
		if ( boff < 0 ) boff = 0;
%>
		<a href="Demo.jsp?off=<%=boff%>&rows=<%=rows%>">&lt;&lt;rows <%=boff+1%> to <%=boff+rows%></a>
<%
	}
	int end = off + rows;
	if ( end >= set.length )
		end = set.length;
	else {
%>
		<a href="Demo.jsp?off=<%=end%>&rows=<%=rows%>">rows <%=end+1%> to <%=end+rows%>&gt;&gt;</a>
<%
	}
%>
	<h4> rows <%=off+1%> to <%=end%> </h4>
<%-- start output --%>
<%
	if ( 0 == dbnum ) {
		for ( int i=off; i<end; i++ ) {
			Rec r = db.readRow( set[i] );
			if ( null == r ) continue;
			int m = Db.MDL | Db.PS | Db.HTA;
			String r13 = "<br>&nbsp;", s = "<br>";
%>
<p>
MFN        : <%= r.getRowId() %><br>
<%= r.v("CONFERENCE : ",null,12,m,0,0,r13,s) %>
<%= r.v("TITLE      : ",null,24,m,0,0,r13,s) %>
<%= r.v("AUTHOR(S)  : ",null,14,m,0,0,"; "+r13+" ",s) %>
<%= r.v("EDITION    : ",null,25,m,0,0,r13,s) %>
<%= r.v("IMPRINT    : ",null,26,m,0,0,r13,s) %>
<%= r.v("COLLATION  : ",null,30,m,0,0,r13,s) %>
<%= r.v("SERIES     : ",null,44,m,0,0,r13,s) %>
<%= r.v("NOTES      : ",null,50,m,0,0,r13,s) %>
<%= r.v("CORP. BODY : ",null,71,m,0,0,r13,s) %>
<%= r.v("ADDED CONF : ",null,72,m,0,0,r13,s) %>
<%= r.v("OTHER TITLE: ",null,74,m,0,0,r13,s) %>
<%= r.v("OTHER LANG : ",null,76,m|'*',0,0,r13,s) %>
<%= r.v("KEYWORDS   : ",null,69,m,0,0,r13,s) %>
<%
		}
	} else {
%>
	<table cols="4" width="100%">
	<tr>
		<td width="20">&nbsp;</td>
		<td width="20">&nbsp;</td>
		<td width="20">&nbsp;</td>
		<td>&nbsp;</td>
	</tr>
<%
	for ( int i=off; i<end; i++ ) {
		Rec r = db.readRow( set[i] );
		if ( null == r ) {
%>
	<tr>
		<td colspan="4">
			skip bad row <%=set[i]%> as <%=i+1%> of <%=set.length%>
		</td>
	</tr>
<%
			continue;
		}
		int id = r.getRowId();
		int l = r.getLen();
%>
	<tr>
		<td colspan="4">
			row <%=id%> with <%=l%> fields as <%=i+1%> of <%=set.length%>
		</td>
	</tr>
<%
		for ( int j=0; j<l; j++ ) {
			Field f = r.getField(j);
%>
	<tr>
		<td> <%=id%> </td>
		<td> <%=f.tag%> </td>
		<td>&nbsp;</td>
		<td> <%=f.html()%> </td>
	</tr>
<%
			if ( '^' == f.val.charAt(0) ) {
				Field[] s = f.split();
				if ( null == s )
					continue;
				for ( int k=0; k<s.length; k++ ) {
					if ( null == s[k] )
						continue;
%>
	<tr>
		<td> <%=id%> </td>
		<td> <%=f.tag%> </td>
		<td> <%=(char)s[k].tag%> </td>
		<td> <%=s[k].html()%> </td>
	</tr>
<%
				} // for subfields
			} // if subfields
		} // for fields
	} // for rows
%>
	</table>
<% } %>
</body>