%@ page import="java.util.*, java.sql.*, com.oroinc.text.perl.Perl5Util, com.oroinc.text.perl.MalformedPerl5PatternException, com.oroinc.text.regex.PatternMatcherInput" errorPage="error.jsp" %> <%! String channel = "etcon"; String db_driver = "org.postgresql.Driver"; String db_url = "jdbc:postgresql://localhost/irclog"; String db_user = "dav"; String db_pass = ""; int defaultLimit = 40; Connection db = null; //static constructor { try{ Class.forName(db_driver); db = DriverManager.getConnection(db_url, db_user, db_pass); } catch(ClassNotFoundException e){ //out.println("No such class:" + db_driver+"
"); } catch(SQLException e){ //out.println((e.getMessage())+"
"); } } %> <% // set defaults int limit = defaultLimit; int startRow = Integer.MAX_VALUE; // sometime need to ensure this is > rowid max value int endRow = Integer.MAX_VALUE; // sometime need to ensure this is > rowid max value boolean prevOrder = true; boolean urlsOnly = false; String lines = request.getParameter("lines"); String start = request.getParameter("start"); String order = request.getParameter("order"); String urlsonly = request.getParameter("urlsonly"); if (order!=null) { if (order.equalsIgnoreCase("next")) { prevOrder = false; } } if (lines!=null) { try { limit = Integer.valueOf(lines).intValue(); if (limit > 500 || limit <1) { limit = defaultLimit; } } catch (NumberFormatException nfe) { } } if (start!=null) { try { startRow = Integer.valueOf(start).intValue(); if (startRow<=0) { startRow = Integer.MAX_VALUE; } } catch (NumberFormatException nfe) { } } if (urlsonly!=null && urlsonly.equalsIgnoreCase("true")) { urlsOnly = true; } %>
Log for #<%=channel%><% int stop = startRow-limit; if (stop<0 || lines==null) { stop = 0; } String sql = null; if (prevOrder) { sql = "SELECT rowid, stamp, name, msg, type " +"FROM Log"+channel+" " +"WHERE (type"+(urlsOnly?" = ":" <> ")+"7 AND rowid <= "+startRow+" ) " +"ORDER BY rowid DESC LIMIT "+limit; } else { sql = "SELECT rowid, stamp, name, msg, type " +"FROM Log"+channel+" " +"WHERE (type"+(urlsOnly?" = ":" <> ")+"7 AND rowid >= "+startRow+" ) " +"ORDER BY rowid ASC LIMIT "+limit; } Vector lineVector = new Vector(limit); try { //System.out.println(sql); java.sql.Statement st = db.createStatement(); ResultSet rs = st.executeQuery(sql); while(rs.next()) { long id = rs.getLong(1); Timestamp stamp = rs.getTimestamp(2); String nick = rs.getString(3); String msg = rs.getString(4); long type = rs.getLong(5); lineVector.add( new Line( rs.getLong(1), rs.getTimestamp(2), rs.getString(3), rs.getString(4), rs.getLong(5) ) ); } } catch(SQLException e){ System.out.println("ShowLog.jsp: "+e.getMessage()); out.println("ShowLog.jsp: "+e.getMessage()); } Object[] lineArray = lineVector.toArray(); if (lineArray!=null && lineArray.length>0) { long firstRow; long lastRow; if (prevOrder) { firstRow = ((Line)lineArray[lineArray.length-1]).getId(); lastRow = ((Line)lineArray[0]).getId(); } else { firstRow = ((Line)lineArray[0]).getId(); lastRow = ((Line)lineArray[lineArray.length-1]).getId(); } urlsonly=urlsOnly?"true":"false"; out.println("[Prev] "); out.println("[Next] "); out.println("[Latest Text] "); out.println("[Latest URLs] "); out.println("