Apache Nutch is an extensible and scalable web crawler
removed log flooding, removed unneycessaru code from PreferencesController, integrated displaying information of index-more plugin
Sami Sirenbe4eba3dfa9d
diff --git a/contrib/web2/README.txt b/contrib/web2/README.txtindex a4b62327d..50bb4cf1c 100644--- a/contrib/web2/README.txt+++ b/contrib/web2/README.txt@@ -9,9 +9,9 @@ to represent blocks of functinality and layout on a search(and related) pages. Layout is constructed by using followingtag libraries:-struts-logic+jstl-c+jstl-fmtstruts-tiles-struts-beanThese tiles blocks can be extended or overridden by pluginsimplementing org.apache.nutch.webapp.UIExtensionPoint. A@@ -36,8 +36,10 @@ the configuration parameter you need to edit is namedTodo:--Provide some samples of ui plugins-+-provide some samples of ui plugins+-move "more" functionality to plugin+-remove table structures from html to allow more flexible css layouts+-add mechanism for adding binary items (ie. images)Directory contentsdiff --git a/contrib/web2/build.xml b/contrib/web2/build.xmlindex 2548b449d..a3bbc3d35 100644--- a/contrib/web2/build.xml+++ b/contrib/web2/build.xml@@ -287,6 +287,7 @@ webappincludes="**/*.html"/><replace dir="${docs.dir}" token="help.html" value="help.do" includes="**/*.html"/>+ <replace dir="${docs.dir}" token="about.html" value="about.do" includes="**/*.html"/><replace dir="${docs.dir}" token="search.jsp" value="search.do" includes="**/*.html"/><replace dir="${docs.dir}" token="../" value="" includes="**/*.html"/>diff --git a/contrib/web2/src/main/java/org/apache/nutch/webapp/common/NavigationHelper.java b/contrib/web2/src/main/java/org/apache/nutch/webapp/common/NavigationHelper.javaindex c6d155ea8..5b80f4467 100644--- a/contrib/web2/src/main/java/org/apache/nutch/webapp/common/NavigationHelper.java+++ b/contrib/web2/src/main/java/org/apache/nutch/webapp/common/NavigationHelper.java@@ -62,9 +62,6 @@ public class NavigationHelper {* @return*/protected boolean hasNext() {- System.out.println("totalIsExact" + totalIsExact);- System.out.println("end" + end);- System.out.println("totalHits" + totalHits);return end < totalHits && (!getShowAllHits());}diff --git a/contrib/web2/src/main/java/org/apache/nutch/webapp/common/Search.java b/contrib/web2/src/main/java/org/apache/nutch/webapp/common/Search.javaindex 1ed3c7983..b3e94f61a 100644--- a/contrib/web2/src/main/java/org/apache/nutch/webapp/common/Search.java+++ b/contrib/web2/src/main/java/org/apache/nutch/webapp/common/Search.java@@ -89,18 +89,12 @@ public class Search {hits = new Hits(0, new Hit[0]);}- LOG.info("form:");- LOG.info(locator.getSearchForm().toString());- LOG.info("performing search");-int realEnd = (int) Math.min(hits.getLength(), getStartOffset()+ getMaxHits());int endOffset=hits.getLength();show = hits.getHits(getStartOffset(), realEnd - getStartOffset());--navigationHelper = new NavigationHelper(startOffset, endOffset, hitsPerPage, hits.getTotal(), hits.totalIsExact());diff --git a/contrib/web2/src/main/java/org/apache/nutch/webapp/controller/MoreController.java b/contrib/web2/src/main/java/org/apache/nutch/webapp/controller/MoreController.javanew file mode 100644index 000000000..9133359f0--- /dev/null+++ b/contrib/web2/src/main/java/org/apache/nutch/webapp/controller/MoreController.java@@ -0,0 +1,72 @@+/*+ * Copyright 2006 The Apache Software Foundation+ *+ * Licensed 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.+ */+package org.apache.nutch.webapp.controller;++import java.io.IOException;+import java.util.Date;++import javax.servlet.ServletContext;+import javax.servlet.ServletException;+import javax.servlet.http.HttpServletRequest;+import javax.servlet.http.HttpServletResponse;++import org.apache.nutch.webapp.common.SearchResultBean;+import org.apache.struts.tiles.ComponentContext;++/**+ * This is the controller used when rendering a hit. Basically what+ * happens here is that we get some meta data values from HitDetails+ * and stick them into request object so the jsp can display them.+ *+ */+public class MoreController extends NutchController {++ public void nutchPerform(ComponentContext tileContext,+ HttpServletRequest request, HttpServletResponse response,+ ServletContext servletContext) throws ServletException, IOException {++ SearchResultBean hit = (SearchResultBean) request.getAttribute("hit");++ if (hit != null) {++ // Content-Type+ String primaryType = hit.getDetails().getValue("primaryType");+ String subType = hit.getDetails().getValue("subType");++ String contentType = subType;+ if (contentType == null)+ contentType = primaryType;+ if (contentType != null) {+ request.setAttribute("contentType", contentType);+ }+ // Content-Length+ String contentLength = hit.getDetails().getValue("contentLength");+ if (contentLength != null) {+ request.setAttribute("contentLength", contentLength);+ }++ // Last-Modified+ String lastModified = hit.getDetails().getValue("lastModified");+ if (lastModified != null) {+ long millis = new Long(lastModified).longValue();+ Date date = new Date(millis);+ request.setAttribute("lastModified", date);+ }+ } else {+ LOG.info("hit was null?");+ }+ }+}diff --git a/contrib/web2/src/main/java/org/apache/nutch/webapp/controller/NutchController.java b/contrib/web2/src/main/java/org/apache/nutch/webapp/controller/NutchController.javaindex 92b99c9d6..f39709fdc 100644--- a/contrib/web2/src/main/java/org/apache/nutch/webapp/controller/NutchController.java+++ b/contrib/web2/src/main/java/org/apache/nutch/webapp/controller/NutchController.java@@ -55,8 +55,9 @@ public abstract class NutchController implements Controller {LOG.info("Exception occured while executing nutch controller:");e.printStackTrace(System.err);}- LOG.info("request processing time: " + (System.currentTimeMillis() - t)+/* LOG.info("Controller processing time: " + (System.currentTimeMillis() - t)+ "ms");+ */}/**diff --git a/contrib/web2/src/main/java/org/apache/nutch/webapp/controller/PreferencesController.java b/contrib/web2/src/main/java/org/apache/nutch/webapp/controller/PreferencesController.javaindex 3fa711995..cd199d5e1 100644--- a/contrib/web2/src/main/java/org/apache/nutch/webapp/controller/PreferencesController.java+++ b/contrib/web2/src/main/java/org/apache/nutch/webapp/controller/PreferencesController.java@@ -48,12 +48,5 @@ public class PreferencesController extends NutchController {LOG.info("view");request.setAttribute("preferences", locator.getPreferences());}-- // add List languages (defined in tles-defs)- request.setAttribute("languages", tileContext.getAttribute("languages"));-- // add List hitsPerPages (defined in tles-defs)- request.setAttribute("hitsPerPage", tileContext.getAttribute("hitsPerPage"));-}}diff --git a/contrib/web2/src/main/webapp/WEB-INF/jsp/more.jsp b/contrib/web2/src/main/webapp/WEB-INF/jsp/more.jspindex 3cfe2c055..b73ea3de0 100644--- a/contrib/web2/src/main/webapp/WEB-INF/jsp/more.jsp+++ b/contrib/web2/src/main/webapp/WEB-INF/jsp/more.jsp@@ -1,54 +1,14 @@-<%@ include file="common.jsp" %>-<jsp:useBean id="hit" scope="request" type="org.apache.nutch.webapp.SearchResultBean"/>-<%- // @author John Xing- // show meta info (currently type, size, date of last-modified)- // for each hit. These info are indexed by ./src/plugin/index-more.-- // do not show unless we have something- boolean showMore = false;-- // Content-Type- String primaryType = hit.getDetails().getValue("primaryType");- String subType = hit.getDetails().getValue("subType");-- String contentType = subType;- if (contentType == null)- contentType = primaryType;- if (contentType != null) {- contentType = "[<span class=\"contentType\">" + contentType + "</span>]";- showMore = true;- } else {- contentType = "";- }-- // Content-Length- String contentLength = hit.getDetails().getValue("contentLength");- if (contentLength != null) {- contentLength = "(" + contentLength + " bytes)";- showMore = true;- } else {- contentLength = "";- }-- // Last-Modified- String lastModified = hit.getDetails().getValue("lastModified");- if (lastModified != null) {- java.util.Calendar cal = new java.util.GregorianCalendar();- cal.setTimeInMillis(new Long(lastModified).longValue());- lastModified = cal.get(java.util.Calendar.YEAR)- + "." + (1+cal.get(java.util.Calendar.MONTH)) // it is 0-based- + "." + cal.get(java.util.Calendar.DAY_OF_MONTH);- showMore = true;- } else {- lastModified = "";- }-%>--<% if (showMore) {- if ("text".equalsIgnoreCase(primaryType)) { %>- <br><font size=-1><nobr><%=contentType%> <%=contentLength%> <%=lastModified%></nobr></font>-<% } else { %>- <br><font size=-1><nobr><%=contentType%> <%=contentLength%> <%=lastModified%> - <a href="../text.jsp?<jsp:getProperty name="hit" property="id"/>"><i18n:message key="viewAsText"/></a></nobr></font>-<% }- } %>+<%@ include file="common.jsp"%>+<c:if+ test="${contentType!=null || contentLength!=null ||lastModified!=null }">+ <fmt:message key="search.contentType">+ <fmt:param value="${contentType}" />+ </fmt:message>+ <fmt:message key="search.contentLength">+ <fmt:param value="${contentLength}" />+ </fmt:message>+ <fmt:message key="search.lastModified">+ <fmt:param><fmt:formatDate value="${lastModified}" /></fmt:param>+ </fmt:message>+ <br />+</c:if>diff --git a/contrib/web2/src/main/webapp/WEB-INF/jsp/preferences.jsp b/contrib/web2/src/main/webapp/WEB-INF/jsp/preferences.jspindex b80638e10..2ebc6e3ef 100644--- a/contrib/web2/src/main/webapp/WEB-INF/jsp/preferences.jsp+++ b/contrib/web2/src/main/webapp/WEB-INF/jsp/preferences.jsp@@ -1,4 +1,5 @@<%@ include file="common.jsp"%>+<tiles:importAttribute/><form action="preferencesSave.do"><fmt:messagekey="preferences.ui.language" /> <select name="L"><c:forEach var="language" items="${languages}">diff --git a/contrib/web2/src/main/webapp/WEB-INF/jsp/results.jsp b/contrib/web2/src/main/webapp/WEB-INF/jsp/results.jspindex 1723b24f2..336db541d 100644--- a/contrib/web2/src/main/webapp/WEB-INF/jsp/results.jsp+++ b/contrib/web2/src/main/webapp/WEB-INF/jsp/results.jsp@@ -1,7 +1,8 @@<%@ include file="common.jsp" %><c:forEach var="hit" items="${nutchSearch.results}">+ <c:set var="hit" scope="request" value="${hit}"/><b><a href="<c:out value="${hit.url}"/>"><c:out value="${hit.title}"/></a></b><br/>- <tiles:insert name="more" flush="false" beanName="hit"/>+ <tiles:insert name="more" /><c:out value="${hit.summary}" escapeXml="false"/><br><span class="url"><c:out value="${hit.encodedUrl}"/></span>diff --git a/contrib/web2/src/main/webapp/WEB-INF/jsp/search.jsp b/contrib/web2/src/main/webapp/WEB-INF/jsp/search.jspindex e7dea5f88..e71754256 100644--- a/contrib/web2/src/main/webapp/WEB-INF/jsp/search.jsp+++ b/contrib/web2/src/main/webapp/WEB-INF/jsp/search.jsp@@ -15,7 +15,7 @@<fmt:param value="${resultInfo[3]}" /></fmt:message><br />- <tiles:insert name="results" />+ <tiles:insert name="results" flush="true"/><tiles:insert name="cluster" /><tiles:insert name="navigate" /></c:when>diff --git a/contrib/web2/src/main/webapp/WEB-INF/jsp/template.jsp b/contrib/web2/src/main/webapp/WEB-INF/jsp/template.jspindex 8ddbd5315..6da490460 100644--- a/contrib/web2/src/main/webapp/WEB-INF/jsp/template.jsp+++ b/contrib/web2/src/main/webapp/WEB-INF/jsp/template.jsp@@ -2,15 +2,13 @@<%@ include file="common.jsp"%><html lang="<fmt:message key="lang"/>"><head>-<tiles:insert name="header">+<tiles:insert name="header" flush="true"><tiles:put name="title" beanName="title" />- <tiles:put name="basePage" content="/include/header.html" />- <tiles:put name="attrName" content="headerContent" /></tiles:insert></head><body onLoad="queryfocus();"><c:out default="" value="${headerContent}" escapeXml="false"/>-<tiles:insert name="pageBody" />+<tiles:insert name="pageBody" flush="true"/><tiles:insert name="footer" /></body></html>diff --git a/contrib/web2/src/main/webapp/WEB-INF/tiles-defs.xml b/contrib/web2/src/main/webapp/WEB-INF/tiles-defs.xmlindex 8f6df0714..4aef28aee 100644--- a/contrib/web2/src/main/webapp/WEB-INF/tiles-defs.xml+++ b/contrib/web2/src/main/webapp/WEB-INF/tiles-defs.xml@@ -1,73 +1,111 @@<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE tiles-definitions PUBLIC "-//Apache Software Foundation//DTD Tiles Configuration 1.1//EN" "dtd/tiles-config_1_1.dtd"><tiles-definitions>- <definition name=".configurable">+ <definition name="stylable"><put name="style" value="/include/style.html" /></definition>- <definition name=".layout" extends=".configurable"++ <definition name="masterlayout" extends="stylable"path="/WEB-INF/jsp/template.jsp">+ </definition>++ <definition name="template" extends="masterlayout"><put name="title" value="title" /><put name="header" value=".header" />- <put name="footer" value="/WEB-INF/jsp/footer.jsp" />+ <put name="footer" value="footer" /></definition>- <!-- Search page -->- <definition name="searchPage" extends=".layout"++ <!-- Footer -->+ <definition name="footer" path="/WEB-INF/jsp/footer.jsp"/>++ <!-- Search -->+ <definition name="searchPage" extends="template"controllerClass="org.apache.nutch.webapp.controller.SearchController"><put name="title" value="search.title" />- <put name="pageBody" value="/WEB-INF/jsp/search.jsp" />+ <put name="pageBody" value="search" /></definition>+ <definition name="search" path="/WEB-INF/jsp/search.jsp"/>+<!-- Cached --><definition name="cachedPage" path="/WEB-INF/jsp/cached.jsp"controllerClass="org.apache.nutch.webapp.controller.CachedController"><put name="title" value="cached.title" /></definition>+<!-- Explain -->- <definition name="explainPage" extends=".layout"+ <definition name="explainPage" extends="template"controllerClass="org.apache.nutch.webapp.controller.ExplainController">- <put name="pageBody" value="/WEB-INF/jsp/explain.jsp" />+ <put name="pageBody" value="explain" /><put name="title" value="explain.title" /></definition>+ <definition name="explain" path="/WEB-INF/jsp/explain.jsp"/>+<!-- Anchors -->- <definition name="anchorsPage" extends=".layout"+ <definition name="anchorsPage" extends="template"controllerClass="org.apache.nutch.webapp.controller.AnchorsController">- <put name="pageBody" value="/WEB-INF/jsp/anchors.jsp" />+ <put name="pageBody" value="anchors" /><put name="title" value="anchors.title" /></definition>- <!-- Tile that displays the search results -->+ <definition name="anchors" path="/WEB-INF/jsp/anchors.jsp"/>++ <!-- Search results --><definition name="results" path="/WEB-INF/jsp/results.jsp"></definition>- <definition name="more" path="/WEB-INF/jsp/more.jsp" />- <!-- Tile that displays the search result navigation -->++ <!-- Index more ui extension, should really be in own plugin -->+ <definition name="more" path="/WEB-INF/jsp/more.jsp" controllerClass="org.apache.nutch.webapp.controller.MoreController">+ <putList name="moreNames" id="moreNames">+ <add value="primaryType" type="string"/>+ <add value="subType" type="string"/>+ <add value="contentLength" type="string"/>+ <add value="lastModified" type="string"/>+ </putList>+ </definition>+ <!-- Search result navigation --><definition name="navigate" path="/WEB-INF/jsp/navigate.jsp" />- <definition name=".header" extends=".configurable"++ <definition name=".header" extends="stylable"path="/WEB-INF/jsp/header.jsp"- controllerClass="org.apache.nutch.webapp.controller.I18NPageController" />- <definition name="localizedPage" extends=".layout"+ controllerClass="org.apache.nutch.webapp.controller.I18NPageController" >+ <put name="basePage" content="/include/header.html" />+ <put name="attrName" content="headerContent" />+ </definition>++ <!-- Localized pages (help, about,...) -->+ <definition name="localizedPage" extends="template"controllerClass="org.apache.nutch.webapp.controller.I18NPageController">- <put name="pageBody" value="/WEB-INF/jsp/i18ncontent.jsp" />+ <put name="pageBody" value="localized" /></definition>+ <definition name="localized" path="/WEB-INF/jsp/i18ncontent.jsp"/>+<!-- Help --><definition name="helpPage" extends="localizedPage"><put name="basePage" value="/help.html" /><put name="title" value="help.title" /></definition>+<!-- About --><definition name="aboutPage" extends="localizedPage"><put name="basePage" value="/about.html" /></definition>+<!-- No Results --><definition name="noResults" path="/WEB-INF/jsp/noResults.jsp" />- <!-- i18n component -->++ <!-- Loclaized component --><definition name="i18nComponent" path="/WEB-INF/jsp/i18ncontent.jsp"controllerClass="org.apache.nutch.webapp.controller.I18NPageController"></definition><!-- Preferences -->- <definition name="preferencesPage" extends=".layout"+ <definition name="preferencesPage" extends="template"controllerClass="org.apache.nutch.webapp.controller.PreferencesController"><put name="title" value="preferences.title" /><put name="action" value="edit" />- <put name="pageBody" value="/WEB-INF/jsp/preferences.jsp" />+ <put name="pageBody" value="preferences" />+ </definition>++ <definition name="preferences" page="/WEB-INF/jsp/preferences.jsp"><putList name="languages"><add value="ca"/><add value="de"/>@@ -91,7 +129,7 @@<add value="20"/><add value="50"/></putList>- </definition>+ </definition><definition name="preferencesSavePage" extends="preferencesPage"><put name="action" value="save" />