Author: jerome Date: Mon Mar 27 06:52:14 2006 New Revision: 389160 URL: http://svn.apache.org/viewcvs?rev=389160&view=rev Log: NUTCH-210, Add an xsl that generates a basic ServletContext XML file for the nutch webapp and make use of the ServletContext init parameters to override the properties in nutch-default and nutch-site properties. Contributed by Chris Mattmann.
Added: lucene/nutch/trunk/conf/context.xsl (with props) Modified: lucene/nutch/trunk/src/java/org/apache/nutch/util/NutchConfiguration.java lucene/nutch/trunk/src/web/jsp/anchors.jsp lucene/nutch/trunk/src/web/jsp/cached.jsp lucene/nutch/trunk/src/web/jsp/explain.jsp lucene/nutch/trunk/src/web/jsp/refine-query-init.jsp lucene/nutch/trunk/src/web/jsp/search.jsp lucene/nutch/trunk/src/web/jsp/text.jsp Added: lucene/nutch/trunk/conf/context.xsl URL: http://svn.apache.org/viewcvs/lucene/nutch/trunk/conf/context.xsl?rev=389160&view=auto ============================================================================== --- lucene/nutch/trunk/conf/context.xsl (added) +++ lucene/nutch/trunk/conf/context.xsl Mon Mar 27 06:52:14 2006 @@ -0,0 +1,87 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + 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. + + Author : Chris Mattmann + Auhtor : Jérôme Charron + Description: This xsl file is used to transform dynamic properties out of the + nutch-default.xml file into a deployable Context.xml file for configuring + the Nutch war file in a servlet container. +--> + +<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> + +<xsl:template match="/"> +<Context path="/nutch" docBase="nutch-0.8-dev.war" + debug="5" reloadable="true" crossContext="true"> + +<xsl:for-each select="configuration/property"> + +<!-- "searcher." properties --> +<xsl:call-template name="parameter"> + <xsl:with-param name="property" select="current()"/> + <xsl:with-param name="filter" select="'searcher.'"/> +</xsl:call-template> + +<!-- "plugin." properties --> +<xsl:call-template name="parameter"> + <xsl:with-param name="property" select="current()"/> + <xsl:with-param name="filter" select="'plugin.'"/> +</xsl:call-template> + +<!-- "extension.clustering." properties --> +<xsl:call-template name="parameter"> + <xsl:with-param name="property" select="current()"/> + <xsl:with-param name="filter" select="'extension.clustering.'"/> +</xsl:call-template> + +<!-- "extension.ontology." properties --> +<xsl:call-template name="parameter"> + <xsl:with-param name="property" select="current()"/> + <xsl:with-param name="filter" select="'extension.ontology.'"/> +</xsl:call-template> + +<!-- "query." properties --> +<xsl:call-template name="parameter"> + <xsl:with-param name="property" select="current()"/> + <xsl:with-param name="filter" select="'query.'"/> +</xsl:call-template> + +</xsl:for-each> + +</Context> +</xsl:template> + + +<!-- + ! Template used to write out a parameter if the property's + ! name contains the specified filter string. + !--> +<xsl:template name="parameter"> + <xsl:param name="property"/> + <xsl:param name="filter"/> + <xsl:if test="contains(name, $filter)"> + <Parameter override="false"> + <xsl:attribute name="name"> + <xsl:value-of select="name"/> + </xsl:attribute> + <xsl:attribute name="value"> + <xsl:value-of select="value"/> + </xsl:attribute> + </Parameter> + </xsl:if> +</xsl:template> + +</xsl:stylesheet> Propchange: lucene/nutch/trunk/conf/context.xsl ------------------------------------------------------------------------------ svn:eol-style = native Modified: lucene/nutch/trunk/src/java/org/apache/nutch/util/NutchConfiguration.java URL: http://svn.apache.org/viewcvs/lucene/nutch/trunk/src/java/org/apache/nutch/util/NutchConfiguration.java?rev=389160&r1=389159&r2=389160&view=diff ============================================================================== --- lucene/nutch/trunk/src/java/org/apache/nutch/util/NutchConfiguration.java (original) +++ lucene/nutch/trunk/src/java/org/apache/nutch/util/NutchConfiguration.java Mon Mar 27 06:52:14 2006 @@ -16,12 +16,23 @@ package org.apache.nutch.util; +// JDK imports +import java.util.Enumeration; + +// Servlet imports +import javax.servlet.ServletContext; + +// Hadoop imports import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.io.WritableName; + /** Utility to create Hadoop [EMAIL PROTECTED] Configuration}s that include Nutch-specific * resources. */ public class NutchConfiguration { + + private final static String KEY = NutchConfiguration.class.getName(); + private NutchConfiguration() {} // singleton // for back-compatibility, add old aliases for these Writable classes @@ -41,11 +52,40 @@ return conf; } + /** + * Create a [EMAIL PROTECTED] Configuration} for Nutch front-end. + * + * If a [EMAIL PROTECTED] Configuration} is found in the + * [EMAIL PROTECTED] javax.servlet.ServletContext} it is simply returned, otherwise, + * a new [EMAIL PROTECTED] Configuration} is created using the [EMAIL PROTECTED] #create()} method, + * and then all the init parameters found in the + * [EMAIL PROTECTED] javax.servlet.ServletContext} are added to the [EMAIL PROTECTED] Configuration} + * (the created [EMAIL PROTECTED] Configuration} is then saved into the + * [EMAIL PROTECTED] javax.servlet.ServletContext}). + * + * @param application is the ServletContext whose init parameters + * must override those of Nutch. + */ + public static Configuration get(ServletContext application) { + Configuration conf = (Configuration) application.getAttribute(KEY); + if (conf == null) { + conf = create(); + Enumeration e = application.getInitParameterNames(); + while (e.hasMoreElements()) { + String name = (String) e.nextElement(); + conf.set(name, application.getInitParameter(name)); + } + application.setAttribute(KEY, conf); + } + return conf; + } + /** Add the standard Nutch resources to [EMAIL PROTECTED] Configuration}. */ public static Configuration addNutchResources(Configuration conf) { conf.addDefaultResource("nutch-default.xml"); conf.addFinalResource("nutch-site.xml"); return conf; } + } Modified: lucene/nutch/trunk/src/web/jsp/anchors.jsp URL: http://svn.apache.org/viewcvs/lucene/nutch/trunk/src/web/jsp/anchors.jsp?rev=389160&r1=389159&r2=389160&view=diff ============================================================================== --- lucene/nutch/trunk/src/web/jsp/anchors.jsp (original) +++ lucene/nutch/trunk/src/web/jsp/anchors.jsp Mon Mar 27 06:52:14 2006 @@ -11,11 +11,7 @@ import="org.apache.hadoop.conf.Configuration" import="org.apache.nutch.util.NutchConfiguration" %><% - Configuration nutchConf = (Configuration) application.getAttribute(Configuration.class.getName()); - if (nutchConf == null) { - nutchConf = NutchConfiguration.create(); - application.setAttribute(Configuration.class.getName(), nutchConf); - } + Configuration nutchConf = NutchConfiguration.get(application); NutchBean bean = NutchBean.get(application, nutchConf); // set the character encoding to use when interpreting request values request.setCharacterEncoding("UTF-8"); Modified: lucene/nutch/trunk/src/web/jsp/cached.jsp URL: http://svn.apache.org/viewcvs/lucene/nutch/trunk/src/web/jsp/cached.jsp?rev=389160&r1=389159&r2=389160&view=diff ============================================================================== --- lucene/nutch/trunk/src/web/jsp/cached.jsp (original) +++ lucene/nutch/trunk/src/web/jsp/cached.jsp Mon Mar 27 06:52:14 2006 @@ -10,11 +10,7 @@ import="org.apache.hadoop.conf.Configuration" import="org.apache.nutch.util.NutchConfiguration" %><% - Configuration nutchConf = (Configuration) application.getAttribute(Configuration.class.getName()); - if (nutchConf == null) { - nutchConf = NutchConfiguration.create(); - application.setAttribute(Configuration.class.getName(), nutchConf); - } + Configuration nutchConf = NutchConfiguration.get(application); NutchBean bean = NutchBean.get(application, nutchConf); bean.LOG.info("cache request from " + request.getRemoteAddr()); Hit hit = new Hit(Integer.parseInt(request.getParameter("idx")), Modified: lucene/nutch/trunk/src/web/jsp/explain.jsp URL: http://svn.apache.org/viewcvs/lucene/nutch/trunk/src/web/jsp/explain.jsp?rev=389160&r1=389159&r2=389160&view=diff ============================================================================== --- lucene/nutch/trunk/src/web/jsp/explain.jsp (original) +++ lucene/nutch/trunk/src/web/jsp/explain.jsp Mon Mar 27 06:52:14 2006 @@ -9,11 +9,7 @@ import="org.apache.hadoop.conf.Configuration" import="org.apache.nutch.util.NutchConfiguration" %><% - Configuration nutchConf = (Configuration) application.getAttribute(Configuration.class.getName()); - if (nutchConf == null) { - nutchConf = NutchConfiguration.create(); - application.setAttribute(Configuration.class.getName(), nutchConf); - } + Configuration nutchConf = NutchConfiguration.get(application); NutchBean bean = NutchBean.get(application, nutchConf); // set the character encoding to use when interpreting request values request.setCharacterEncoding("UTF-8"); Modified: lucene/nutch/trunk/src/web/jsp/refine-query-init.jsp URL: http://svn.apache.org/viewcvs/lucene/nutch/trunk/src/web/jsp/refine-query-init.jsp?rev=389160&r1=389159&r2=389160&view=diff ============================================================================== --- lucene/nutch/trunk/src/web/jsp/refine-query-init.jsp (original) +++ lucene/nutch/trunk/src/web/jsp/refine-query-init.jsp Mon Mar 27 06:52:14 2006 @@ -13,11 +13,7 @@ // being loaded into the JVM. Need improvement in future. try { - Configuration nutchConf = (Configuration) application.getAttribute(Configuration.class.getName()); - if (nutchConf == null) { - nutchConf = NutchConfiguration.create(); - application.setAttribute(Configuration.class.getName(), nutchConf); - } + Configuration nutchConf = NutchConfiguration.get(application); String urls = nutchConf.get("extension.ontology.urls"); ontology = new org.apache.nutch.ontology.OntologyFactory(nutchConf).getOntology(); if (urls==null || urls.trim().equals("")) { Modified: lucene/nutch/trunk/src/web/jsp/search.jsp URL: http://svn.apache.org/viewcvs/lucene/nutch/trunk/src/web/jsp/search.jsp?rev=389160&r1=389159&r2=389160&view=diff ============================================================================== --- lucene/nutch/trunk/src/web/jsp/search.jsp (original) +++ lucene/nutch/trunk/src/web/jsp/search.jsp Mon Mar 27 06:52:14 2006 @@ -15,11 +15,8 @@ import="org.apache.nutch.util.NutchConfiguration" %><% - Configuration nutchConf = (Configuration) application.getAttribute(Configuration.class.getName()); - if (nutchConf == null) { - nutchConf = NutchConfiguration.create(); - application.setAttribute(Configuration.class.getName(), nutchConf); - } + Configuration nutchConf = NutchConfiguration.get(application); + /** * Number of hits to retrieve and cluster if clustering extension is available * and clustering is on. By default, 100. Configurable via nutch-conf.xml. Modified: lucene/nutch/trunk/src/web/jsp/text.jsp URL: http://svn.apache.org/viewcvs/lucene/nutch/trunk/src/web/jsp/text.jsp?rev=389160&r1=389159&r2=389160&view=diff ============================================================================== --- lucene/nutch/trunk/src/web/jsp/text.jsp (original) +++ lucene/nutch/trunk/src/web/jsp/text.jsp Mon Mar 27 06:52:14 2006 @@ -12,11 +12,7 @@ %><% // show the content of a hit as plain text - Configuration nutchConf = (Configuration) application.getAttribute(Configuration.class.getName()); - if (nutchConf == null) { - nutchConf = NutchConfiguration.create(); - application.setAttribute(Configuration.class.getName(), nutchConf); - } + Configuration nutchConf = NutchConfiguration.get(application); NutchBean bean = NutchBean.get(application, nutchConf); bean.LOG.info("text request from " + request.getRemoteAddr());