From: <mi...@us...> - 2008-07-26 15:42:17
|
Revision: 2502 http://archive-access.svn.sourceforge.net/archive-access/?rev=2502&view=rev Author: miklosh Date: 2008-07-26 15:42:26 +0000 (Sat, 26 Jul 2008) Log Message: ----------- Added basic JSP-based user interface. Modified Paths: -------------- trunk/archive-access/projects/nutchwax/imagesearch/build.xml Added Paths: ----------- trunk/archive-access/projects/nutchwax/imagesearch/src/web/ trunk/archive-access/projects/nutchwax/imagesearch/src/web/jsp/ trunk/archive-access/projects/nutchwax/imagesearch/src/web/jsp/images/ trunk/archive-access/projects/nutchwax/imagesearch/src/web/jsp/images/logo.jpg trunk/archive-access/projects/nutchwax/imagesearch/src/web/jsp/results.jsp trunk/archive-access/projects/nutchwax/imagesearch/src/web/jsp/thumb.jsp trunk/archive-access/projects/nutchwax/imagesearch/src/web/locale/ trunk/archive-access/projects/nutchwax/imagesearch/src/web/locale/org/ trunk/archive-access/projects/nutchwax/imagesearch/src/web/locale/org/archive/ trunk/archive-access/projects/nutchwax/imagesearch/src/web/locale/org/archive/jsp/ trunk/archive-access/projects/nutchwax/imagesearch/src/web/locale/org/archive/jsp/imagesearch.properties trunk/archive-access/projects/nutchwax/imagesearch/src/web/locale/org/archive/jsp/imagesearch_en.properties trunk/archive-access/projects/nutchwax/imagesearch/src/web/web.xml Modified: trunk/archive-access/projects/nutchwax/imagesearch/build.xml =================================================================== --- trunk/archive-access/projects/nutchwax/imagesearch/build.xml 2008-07-26 15:37:14 UTC (rev 2501) +++ trunk/archive-access/projects/nutchwax/imagesearch/build.xml 2008-07-26 15:42:26 UTC (rev 2502) @@ -22,6 +22,7 @@ <property name="src.dir" value="src" /> <property name="lib.dir" value="lib" /> <property name="build.dir" value="${nutch.dir}/build" /> + <property name="build.plugins" value="${nutch.dir}/build/plugins" /> <!-- HACK: Need to import default.properties like Nutch does --> <property name="dist.dir" value="${build.dir}/nutch-1.0-dev" /> @@ -135,4 +136,56 @@ </target> + <!-- + generate the servlet context file (nutch.xml) + --> + <target name="generate-context"> + <!-- xmlcatalog definition for xslt task --> + <xmlcatalog id="docDTDs"> + <dtd publicId="-//W3C//DTD XHTML 1.0 Transitional//EN" + location="${xmlcatalog.dir}/xhtml1-transitional.dtd"/> + </xmlcatalog> + <xslt in="${nutch.dir}/conf/nutch-default.xml" + out="${build.dir}/nutch.xml" + style="${nutch.dir}/conf/context.xsl"> + <xmlcatalog refid="docDTDs"/> + <outputproperty name="indent" value="yes"/> + </xslt> + </target> + + <target name="imagesearch-war" depends="generate-context, jar"> + <war destfile="${build.dir}/imagesearch.war" + webxml="${src.dir}/web/web.xml"> + <fileset dir="${src.dir}/web/jsp"/> + <lib dir="${nutch.dir}/lib"> + <include name="lucene*.jar"/> + <include name="taglibs-*.jar"/> + <include name="hadoop-*.jar"/> + <include name="dom4j-*.jar"/> + <include name="xerces-*.jar"/> + <include name="tika-*.jar"/> + <include name="commons-cli-*.jar"/> + <include name="commons-lang-*.jar"/> + <include name="commons-logging-*.jar"/> + <include name="log4j-*.jar"/> + </lib> + <lib dir="${build.dir}"> + <include name="nutch-*.jar"/> + </lib> + + <zipfileset prefix="WEB-INF/classes" dir="${build.dir}/classes"/> + <classes dir="${nutch.dir}/conf" excludes="**/*.template"/> + <classes dir="${src.dir}/web/locale"/> + <zipfileset prefix="WEB-INF/classes/plugins" dir="${build.plugins}"> + <exclude name="parse-*/**"/> + <exclude name="protocol-*/**"/> + <exclude name="urlfilter-*/**"/> + </zipfileset> + + <webinf dir="${nutch.dir}/lib"> + <include name="taglibs-*.tld"/> + </webinf> + </war> + </target> + </project> Property changes on: trunk/archive-access/projects/nutchwax/imagesearch/src/web/jsp/images/logo.jpg ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: trunk/archive-access/projects/nutchwax/imagesearch/src/web/jsp/results.jsp =================================================================== --- trunk/archive-access/projects/nutchwax/imagesearch/src/web/jsp/results.jsp (rev 0) +++ trunk/archive-access/projects/nutchwax/imagesearch/src/web/jsp/results.jsp 2008-07-26 15:42:26 UTC (rev 2502) @@ -0,0 +1,226 @@ +<%@ page +session="false" +contentType="text/html; charset=UTF-8" +pageEncoding="UTF-8" + +import="java.io.*" +import="java.util.*" +import="java.net.*" + +import="org.archive.nutchwax.imagesearch.*" +import="org.apache.hadoop.conf.*" +import="org.apache.nutch.html.Entities" +import="org.apache.nutch.searcher.*" +import="org.apache.nutch.metadata.*" +import="org.apache.nutch.util.NutchConfiguration" +import="org.apache.nutch.plugin.*" +import="org.apache.hadoop.fs.Path" +import="org.apache.lucene.index.*" +import="org.apache.lucene.document.*" + +%> +<% +Configuration nutchConf = NutchConfiguration.get(application); + +// Get query from request +boolean haveQuery = true; +request.setCharacterEncoding("UTF-8"); +String queryString = request.getParameter("query"); +String mainTitle = "Internet Archive Image Search"; +if (queryString == null) { + queryString = ""; + haveQuery = false; +} else { + mainTitle = queryString + " - " + mainTitle; +} +String htmlQueryString = Entities.encode(queryString); + +int start = 0; +String startString = request.getParameter("start"); +if (startString != null) { + start = Integer.parseInt(startString); +} + +int hitsPerPage = 20; // number of hits to display per page +int rowLength = 5; // number of images to display per row + +int end = start+hitsPerPage; + +%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><% +// To prevent the character encoding declared with 'contentType' page +// directive from being overriden by JSTL (apache i18n), we freeze it +// by flushing the output buffer. +// see http://java.sun.com/developer/technicalArticles/Intl/MultilingualJSP/ +out.flush(); + +String language = ResourceBundle.getBundle("org.archive.jsp.imagesearch", request.getLocale()) + .getLocale().getLanguage(); +%> +<%@ taglib uri="http://jakarta.apache.org/taglibs/i18n" prefix="i18n" %> +<i18n:bundle baseName="org.archive.jsp.imagesearch"/> +<html> +<head> +<title><%=mainTitle%></title> + +<style type="text/css"><!-- +.xs {font-family:verdana,arial,helvetica,sans-serif;font-size: x-small} +body,div,span,th,td,input,.s {font-family: arial, helvetica, sans-serif; font-size: small} +.m {font-size: medium} +.lbl,a.lbl:link,a.lbl:visited,a.lbl:active,a.lbl:hover{color:#444;font-weight:bold;font-family:verdana,arial,helvetica,sans-serif;;text-decoration:none} + +.resItem {font-family: arial, helvetica, sans-serif; font-size: small} + +.site{color:#55AA55} +a:link,a:active{color:#2249cc} a:visited{color:#573875} a{text-decoration:underline} +a.res{color:#2249cc; font-size:1.3em } + +#res_pages {text-align: center; font-size:medium; font-weight:bold;} +.nav_curr {font-size:1.3em;} +#results {margin-right: 240px; text-align: justify;} +.ellipsis {font-weight: bold;} +.highlight{font-weight: bold;} + +form{margin-bottom:0px} + +--> +</style> + +</head> +<body> + +<table width="100%" border=0 cellspacing=0 cellpadding=0> +<tr><td class=xs> </td></tr> +<tr><td width=50><img src="images/logo.jpg"></td> +<td><table border=0 cellspacing=0 cellpadding=1> + <tr><td width=10><form action="results.jsp"> </td><td> + <input type=text name=query size=20 maxlength=500 value="<%=queryString%>" style='width:230px' /> + </td> + <td> <input type=submit value="<i18n:message key="search"/>" class=btn /></td> + <td> </form> + </td></tr></table> +</td></tr> +<tr><td class=xs> </td></tr> +</table> + +<% +ImageHits hitList = null; +ImageSearcherBean bean = new ImageSearcherBean(nutchConf); + +if (haveQuery) { + hitList = bean.search(queryString, end); + + long numHits = hitList.getTotal(); + if (end >= numHits) { + end = (int)numHits; + } + + // Output info about the results + if (numHits > 0) { + %><hr size=1 /> + <div align=left class=lbl style="padding: 0px 0px 0px"> + <i18n:message key="showingHits"> + <i18n:messageArg value="<%=new Long(start+1)%>"/> + <i18n:messageArg value="<%=new Long(end)%>"/> + <i18n:messageArg value="<%=numHits%>"/> + </i18n:message> + </div> + + <table border=0 cellpadding=20 cellspacing=0 align=center width=700> + <% + } + // Get hits + ImageHit[] hits = null; + System.out.println(numHits); + if (numHits > 0) { + hits = hitList.getHits(start, (end-start) >= hitsPerPage ? hitsPerPage : + (end-start)); + } else { + hits = new ImageHit[0]; + } + + // Output results + for (int i = 0; i < hits.length; i++) { + ImageHit hit = hits[i]; + String url = hit.url; + String fileName = null; + int slashIndex = url.lastIndexOf("/"); + if (slashIndex > 0) { + fileName = url.substring(slashIndex + 1); + } else { + fileName = url; + } + String parentUrl = hit.parentUrl; + String host = null; + String thumbnailUrl = "thumb.jsp?id=" + hit.imageId; + try { + URL u; + u = new URL(url); + host = u.getHost(); + } catch (MalformedURLException e) { + host = ""; + } + + // Load metadata + String size = null; + String dimensions = null; + String imgWidth = null; + ImageWritable image = bean.getImage(hit.imageId); + if (image != null) { + Metadata meta = image.getMetadata(); + int sizeInt = Integer.parseInt(meta.get(ImageSearch.SIZE_KEY)); + size = Integer.toString((int)Math.round(sizeInt / 1024.0)) + "k"; + dimensions = meta.get("width") + "x" + meta.get("height"); + imgWidth = ""; + } else { + size = "??k"; + dimensions = "??x??"; + // Have the downscaled original image displayed by the browser + thumbnailUrl = url; + int maxSize = nutchConf.getInt("imagesearcher.thumbnail.maxSize", 150); + imgWidth = "width=" + maxSize; + } + + if (i % rowLength == 0) { + if (i > 0) { + %></tr><% + } +%> <tr class=resultGroup><% + } +%> <td class=resItem width=200 valign=top align=center> + <br/><a href="<%=parentUrl%>"><img src="<%=thumbnailUrl%>" border=0 <%=imgWidth%>/></a> + <br/><%=fileName%><br/> + <span class=resMeta><%=dimensions%> - <%=size%><br/></span> + <span class=site><%=host%></span> + </td><% + } + if (hits.length == 0) { + %><i18n:message key="noMatch"><i18n:messageArg value="<%=queryString%>"/></i18n:message><% + } else { // Draw paging information + %> + </table> + <div id=res_pages> + <br/><% + int currentPage = (start - (start % hitsPerPage)) / hitsPerPage; + int currentLoc = currentPage*hitsPerPage; + int pageCounter = 0; + String encodedQuery = URLEncoder.encode(queryString, "UTF-8"); + + // Prev + if (currentPage > 0) { + int prevPageLoc = (currentPage-1)*hitsPerPage; + String prevUrl = "./results.jsp?query=" + encodedQuery + "&start=" + + prevPageLoc; + %><a class=res href="<%=prevUrl%>"><< <i18n:message key="prev"/></a> <% + } + // Next + if (currentPage*hitsPerPage + hitsPerPage < numHits) { + int nextPageLoc = (currentPage+1)*hitsPerPage; + String nextUrl = "./results.jsp?query=" + encodedQuery + "&start=" + + nextPageLoc; + %> <a class=res href="<%=nextUrl%>"><i18n:message key="next"/> >></a><% + } + } + bean.close(); +}%> + </div> +</body> \ No newline at end of file Added: trunk/archive-access/projects/nutchwax/imagesearch/src/web/jsp/thumb.jsp =================================================================== --- trunk/archive-access/projects/nutchwax/imagesearch/src/web/jsp/thumb.jsp (rev 0) +++ trunk/archive-access/projects/nutchwax/imagesearch/src/web/jsp/thumb.jsp 2008-07-26 15:42:26 UTC (rev 2502) @@ -0,0 +1,33 @@ +<%@ page +import="java.io.*" +import="java.util.*" + +import="org.archive.nutchwax.imagesearch.*" +import="org.apache.hadoop.conf.*" +import="org.apache.nutch.util.NutchConfiguration" +import="org.apache.hadoop.fs.Path" + +%><% +Configuration nutchConf = NutchConfiguration.get(application); + +// Get id from request +request.setCharacterEncoding("UTF-8"); +String idString = request.getParameter("id"); +if (idString == null) { + response.sendRedirect("./results.jsp"); + return; +} + +ImageSearcherBean bean = new ImageSearcherBean(nutchConf); +ImageWritable imageData = bean.getImage(idString); +if (imageData != null) { + StoredImage thumb = imageData.getThumbnail(); + response.setContentType("image/jpg"); + OutputStream os = response.getOutputStream(); + os.write(thumb.getData()); + os.close(); +} else { + response.sendRedirect("./results.jsp"); +} +bean.close(); +%> \ No newline at end of file Added: trunk/archive-access/projects/nutchwax/imagesearch/src/web/locale/org/archive/jsp/imagesearch.properties =================================================================== --- trunk/archive-access/projects/nutchwax/imagesearch/src/web/locale/org/archive/jsp/imagesearch.properties (rev 0) +++ trunk/archive-access/projects/nutchwax/imagesearch/src/web/locale/org/archive/jsp/imagesearch.properties 2008-07-26 15:42:26 UTC (rev 2502) @@ -0,0 +1,5 @@ +search = Search Images +showingHits = Results <b>{0}-{1}</b> out of about <b>{2}</b>. +next = Next +prev = Previous +noMatch = Your query (<b>{0}</b>) did not match any documents.<br/>Please try different keywords. Added: trunk/archive-access/projects/nutchwax/imagesearch/src/web/locale/org/archive/jsp/imagesearch_en.properties =================================================================== --- trunk/archive-access/projects/nutchwax/imagesearch/src/web/locale/org/archive/jsp/imagesearch_en.properties (rev 0) +++ trunk/archive-access/projects/nutchwax/imagesearch/src/web/locale/org/archive/jsp/imagesearch_en.properties 2008-07-26 15:42:26 UTC (rev 2502) @@ -0,0 +1,5 @@ +search = Search Images +showingHits = Results <b>{0}-{1}</b> out of about <b>{2}</b>. +next = Next +prev = Previous +noMatch = Your query (<b>{0}</b>) did not match any documents.<br/>Please try different keywords. Added: trunk/archive-access/projects/nutchwax/imagesearch/src/web/web.xml =================================================================== --- trunk/archive-access/projects/nutchwax/imagesearch/src/web/web.xml (rev 0) +++ trunk/archive-access/projects/nutchwax/imagesearch/src/web/web.xml 2008-07-26 15:42:26 UTC (rev 2502) @@ -0,0 +1,36 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!DOCTYPE web-app + PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" + "http://java.sun.com/dtd/web-app_2_3.dtd"> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> +<web-app> + +<!-- order is very important here --> + +<welcome-file-list> + <welcome-file>results.jsp</welcome-file> + <welcome-file>index.html</welcome-file> + <welcome-file>index.jsp</welcome-file> +</welcome-file-list> + +<taglib> + <taglib-uri>http://jakarta.apache.org/taglibs/i18n</taglib-uri> + <taglib-location>/WEB-INF/taglibs-i18n.tld</taglib-location> + </taglib> + +</web-app> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |