You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by fe...@apache.org on 2007/07/07 20:08:57 UTC

svn commit: r554234 [1/2] - in /cocoon/trunk/blocks/cocoon-lucene/cocoon-lucene-impl/src: changes/ main/java/org/apache/cocoon/components/search/ main/java/org/apache/cocoon/generation/ main/java/org/apache/cocoon/samples/ main/resources/META-INF/cocoo...

Author: felixk
Date: Sat Jul  7 11:08:56 2007
New Revision: 554234

URL: http://svn.apache.org/viewvc?view=rev&rev=554234
Log:
Springify lucene block.

Added:
    cocoon/trunk/blocks/cocoon-lucene/cocoon-lucene-impl/src/main/java/org/apache/cocoon/samples/LuceneCocoonCrawler.java   (with props)
    cocoon/trunk/blocks/cocoon-lucene/cocoon-lucene-impl/src/main/resources/META-INF/cocoon/spring/
    cocoon/trunk/blocks/cocoon-lucene/cocoon-lucene-impl/src/main/resources/META-INF/cocoon/spring/cocoon-lucene.xml   (with props)
Removed:
    cocoon/trunk/blocks/cocoon-lucene/cocoon-lucene-impl/src/main/resources/META-INF/cocoon/avalon/
    cocoon/trunk/blocks/cocoon-lucene/cocoon-lucene-impl/src/main/resources/org/
Modified:
    cocoon/trunk/blocks/cocoon-lucene/cocoon-lucene-impl/src/changes/changes.xml
    cocoon/trunk/blocks/cocoon-lucene/cocoon-lucene-impl/src/main/java/org/apache/cocoon/components/search/SimpleLuceneCocoonIndexerImpl.java
    cocoon/trunk/blocks/cocoon-lucene/cocoon-lucene-impl/src/main/java/org/apache/cocoon/components/search/SimpleLuceneCocoonSearcherImpl.java
    cocoon/trunk/blocks/cocoon-lucene/cocoon-lucene-impl/src/main/java/org/apache/cocoon/components/search/SimpleLuceneXMLIndexerImpl.java
    cocoon/trunk/blocks/cocoon-lucene/cocoon-lucene-impl/src/main/java/org/apache/cocoon/generation/SearchGenerator.java
    cocoon/trunk/blocks/cocoon-lucene/cocoon-lucene-impl/src/main/java/org/apache/cocoon/samples/LuceneUtil.java

Modified: cocoon/trunk/blocks/cocoon-lucene/cocoon-lucene-impl/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-lucene/cocoon-lucene-impl/src/changes/changes.xml?view=diff&rev=554234&r1=554233&r2=554234
==============================================================================
--- cocoon/trunk/blocks/cocoon-lucene/cocoon-lucene-impl/src/changes/changes.xml (original)
+++ cocoon/trunk/blocks/cocoon-lucene/cocoon-lucene-impl/src/changes/changes.xml Sat Jul  7 11:08:56 2007
@@ -7,9 +7,9 @@
   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
-
+  
+  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
@@ -18,17 +18,21 @@
   under the License.
 -->
 <!--+
-    | Find usage details at http://maven.apache.org/plugins/maven-changes-plugin/usage.html
-    |
-    | @version $Id$
-    +-->
-    <document>
-      <body>
-        <release version="1.0.0-M1" date="2007-??-??" description="unreleased">    
-          <action dev="reinhard" type="add">
-            Initial creation.
-          </action>      
-        </release>
-      </body>
-    </document>
-    
+  | Find usage details at http://maven.apache.org/plugins/maven-changes-plugin/usage.html
+  |
+  | @version $Id$
+  +-->
+<document>
+  <body>
+    <release version="1.0.0-M1" date="2007-??-??" description="unreleased">
+      <action dev="reinhard" type="add">Initial creation.</action>
+    </release>
+    <release version="2.2.0-M2" date="2007-??-??" description="pending">
+      <action dev="felixk" type="update">
+        Cocoon-Lucene-Block becomes a normal Spring application which means that it is 
+        initialized by Spring and not the other way around.
+      </action>
+    </release>
+  </body>
+</document>
+

Modified: cocoon/trunk/blocks/cocoon-lucene/cocoon-lucene-impl/src/main/java/org/apache/cocoon/components/search/SimpleLuceneCocoonIndexerImpl.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-lucene/cocoon-lucene-impl/src/main/java/org/apache/cocoon/components/search/SimpleLuceneCocoonIndexerImpl.java?view=diff&rev=554234&r1=554233&r2=554234
==============================================================================
--- cocoon/trunk/blocks/cocoon-lucene/cocoon-lucene-impl/src/main/java/org/apache/cocoon/components/search/SimpleLuceneCocoonIndexerImpl.java (original)
+++ cocoon/trunk/blocks/cocoon-lucene/cocoon-lucene-impl/src/main/java/org/apache/cocoon/components/search/SimpleLuceneCocoonIndexerImpl.java Sat Jul  7 11:08:56 2007
@@ -16,17 +16,15 @@
  */
 package org.apache.cocoon.components.search;
 
-import org.apache.avalon.framework.activity.Disposable;
-import org.apache.avalon.framework.configuration.Configurable;
-import org.apache.avalon.framework.configuration.Configuration;
-import org.apache.avalon.framework.configuration.ConfigurationException;
-import org.apache.avalon.framework.logger.AbstractLogEnabled;
-import org.apache.avalon.framework.service.ServiceException;
-import org.apache.avalon.framework.service.ServiceManager;
-import org.apache.avalon.framework.service.Serviceable;
+import java.io.IOException;
+import java.net.URL;
+import java.util.Iterator;
+
 import org.apache.cocoon.ProcessingException;
 import org.apache.cocoon.components.crawler.CocoonCrawler;
+import org.apache.cocoon.util.AbstractLogEnabled;
 import org.apache.lucene.analysis.Analyzer;
+import org.apache.lucene.analysis.standard.StandardAnalyzer;
 import org.apache.lucene.document.Document;
 import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.IndexWriter;
@@ -34,170 +32,96 @@
 import org.apache.lucene.index.TermEnum;
 import org.apache.lucene.store.Directory;
 
-import java.io.IOException;
-import java.net.URL;
-import java.util.Iterator;
-
 /**
  * A lucene indexer.
- *
+ * 
  * <p>
- *  XML documents are indexed using lucene.
- *  Links to XML documents are supplied by
- *  a crawler, requesting links of documents by specifying a cocoon-view, and
- *  HTTP protocol.
+ * XML documents are indexed using lucene. Links to XML documents are supplied
+ * by a crawler, requesting links of documents by specifying a cocoon-view, and
+ * HTTP protocol.
  * </p>
- *
- * @version $Id$
+ * 
+ * @version $Id: SimpleLuceneCocoonIndexerImpl.java 449162 2006-09-23 05:14:05Z
+ *          crossley $
  */
-public class SimpleLuceneCocoonIndexerImpl extends AbstractLogEnabled
-         implements LuceneCocoonIndexer, Configurable, Serviceable, Disposable
-{
-
-    /**
-     * configuration tagname for specifying the analyzer class
-     */
-    public final static String ANALYZER_CLASSNAME_CONFIG = "analyzer-classname";
-    
-    /**
-     * configuration default analyzer class
-     */
-    public final static String ANALYZER_CLASSNAME_DEFAULT = "org.apache.lucene.analysis.standard.StandardAnalyzer";
-
-    /**
-     * configuration tagname for specifying lucene's index directory
-     */
-    public final static String DIRECTORY_CONFIG = "directory";
-    
-    /**
-     * configuration default directory, ie. no default.
-     */
-    public final static String DIRECTORY_DEFAULT = null;
-
-    /**
-     * configuration tagname for specifying lucene's merge factor.
-     */
-    public final static String MERGE_FACTOR_CONFIG = "merge-factor";
+public class SimpleLuceneCocoonIndexerImpl extends AbstractLogEnabled implements LuceneCocoonIndexer {
 
     /**
-     * configuration default value for
-     * <a href="http://www.mail-archive.com/lucene-user@jakarta.apache.org/msg00373.html">lucene's merge factor</a>.
+     * configuration default value for <a
+     * href="http://www.mail-archive.com/lucene-user@jakarta.apache.org/msg00373.html">lucene's
+     * merge factor</a>.
      */
     public final static int MERGE_FACTOR_DEFAULT = 10;
 
-    /**
-     * The service manager for looking up components used.
-     */
-    protected ServiceManager manager = null;
+    /** The used lucene analyzer */
+    protected Analyzer analyzer = new StandardAnalyzer();
+
+    // private String analyzerClassnameDefault = ANALYZER_CLASSNAME_DEFAULT;
 
-    protected Analyzer analyzer;
-//    private String analyzerClassnameDefault = ANALYZER_CLASSNAME_DEFAULT;
+    /** The Lucene Merge Factor */
     private int mergeFactor = MERGE_FACTOR_DEFAULT;
 
+    /** The Lucene XML Indexer */
+    private LuceneXMLIndexer luceneXMLIndexer;
+
+    /** The crawler */
+    private CocoonCrawler cocoonCrawler;
 
     /**
-     *Sets the analyzer attribute of the SimpleLuceneCocoonIndexerImpl object
-     *
-     * @param  analyzer  The new analyzer value
+     * Sets the analyzer attribute of the SimpleLuceneCocoonIndexerImpl object
+     * 
+     * @param analyzer
+     *            The new analyzer value
      */
     public void setAnalyzer(Analyzer analyzer) {
         this.analyzer = analyzer;
     }
 
-
-    /**
-     * Configure this component.
-     *
-     * @param  conf                        is the configuration
-     * @exception  ConfigurationException  is thrown if configuring fails
-     */
-    public void configure(Configuration conf) throws ConfigurationException {
-        Configuration child;
-
-/*        child = conf.getChild(ANALYZER_CLASSNAME_CONFIG, false);
-        if (child != null) {
-            // fix Bugzilla Bug 25277, use child.getValue
-            // and in all following blocks
-            String value = child.getValue(ANALYZER_CLASSNAME_DEFAULT);
-            if (value != null) {
-                analyzerClassnameDefault = value;
-            }
-        }
-*/
-        child = conf.getChild(MERGE_FACTOR_CONFIG, false);
-        if (child != null) {
-            // fix Bugzilla Bug 25277, use child instead of conf
-            int int_value = child.getValueAsInteger(MERGE_FACTOR_DEFAULT);
-            mergeFactor = int_value;
-        }
-    }
-
-
-    /**
-     * Set the current <code>ServiceManager</code> instance used by this
-     * <code>Serviceable</code>.
-     *
-     * @param  manager                 used by this component
-     * @exception  ServiceException  is never thrown
-     */
-    public void service(ServiceManager manager) throws ServiceException {
-        this.manager = manager;
-    }
-
-
-    /**
-     * Dispose this component.
-     */
-    public void dispose() { }
-
-
     /**
      * index content of base_url, index content of links from base_url.
-     *
-     * @param  index                    the lucene store to write the index to
-     * @param  create                   if true create, or overwrite existing index, else
-     *   update existing index.
-     * @param  base_url                 index content of base_url, and crawl through all its
-     *   links recursivly.
-     * @exception  ProcessingException  is thrown if indexing fails
+     * 
+     * @param index
+     *            the lucene store to write the index to
+     * @param create
+     *            if true create, or overwrite existing index, else update
+     *            existing index.
+     * @param base_url
+     *            index content of base_url, and crawl through all its links
+     *            recursivly.
+     * @exception ProcessingException
+     *                is thrown if indexing fails
      */
-    public void index(Directory index, boolean create, URL base_url)
-             throws ProcessingException {
+    public void index(Directory index, boolean create, URL base_url) throws ProcessingException {
 
         IndexWriter writer = null;
-        LuceneXMLIndexer lxi = null;
-        CocoonCrawler cocoonCrawler = null;
 
         try {
-            lxi = (LuceneXMLIndexer) manager.lookup(LuceneXMLIndexer.ROLE);
-
             writer = new IndexWriter(index, analyzer, create);
             writer.mergeFactor = this.mergeFactor;
 
-            cocoonCrawler = (CocoonCrawler) manager.lookup(CocoonCrawler.ROLE);
-            cocoonCrawler.crawl(base_url);
+            getCocoonCrawler().crawl(base_url);
 
-            Iterator cocoonCrawlerIterator = cocoonCrawler.iterator();
+            Iterator cocoonCrawlerIterator = getCocoonCrawler().iterator();
             while (cocoonCrawlerIterator.hasNext()) {
                 URL crawl_url = (URL) cocoonCrawlerIterator.next();
                 // result of fix Bugzilla Bug 25270, in SimpleCocoonCrawlerImpl
                 // check if crawl_url is null
                 if (crawl_url == null) {
                     continue;
-                } else if (!crawl_url.getHost().equals(base_url.getHost()) ||
-                        crawl_url.getPort() != base_url.getPort()) {
+                } else if (!crawl_url.getHost().equals(base_url.getHost()) || crawl_url.getPort() != base_url.getPort()) {
 
                     // skip urls using different host, or port than host,
                     // or port of base url
                     if (getLogger().isDebugEnabled()) {
-                        getLogger().debug("Skipping crawling URL " + crawl_url.toString() +
-                            " as base_url is " + base_url.toString());
+                        getLogger().debug(
+                                "Skipping crawling URL " + crawl_url.toString() + " as base_url is "
+                                        + base_url.toString());
                     }
                     continue;
                 }
 
                 // build lucene documents from the content of the crawl_url
-                Iterator i = lxi.build(crawl_url).iterator();
+                Iterator i = getLuceneXMLIndexer().build(crawl_url).iterator();
 
                 // add all built lucene documents
                 while (i.hasNext()) {
@@ -208,8 +132,6 @@
             writer.optimize();
         } catch (IOException ioe) {
             throw new ProcessingException("IOException in index()", ioe);
-        } catch (ServiceException se) {
-            throw new ProcessingException("Could not lookup service in index()", se);
         } finally {
             if (writer != null) {
                 try {
@@ -218,19 +140,9 @@
                 }
                 writer = null;
             }
-
-            if (lxi != null) {
-                manager.release(lxi);
-                lxi = null;
-            }
-            if (cocoonCrawler != null) {
-                manager.release(cocoonCrawler);
-                cocoonCrawler = null;
-            }
         }
     }
 
-
     /**
      * A document iterator deleting "old" documents form the index.
      * 
@@ -243,12 +155,13 @@
 
         // document id iterator
 
-
         /**
-         *Constructor for the DocumentDeletableIterator object
-         *
-         * @param  directory        Description of Parameter
-         * @exception  IOException  Description of Exception
+         * Constructor for the DocumentDeletableIterator object
+         * 
+         * @param directory
+         *            Description of Parameter
+         * @exception IOException
+         *                Description of Exception
          */
         public DocumentDeletableIterator(Directory directory) throws IOException {
             reader = IndexReader.open(directory);
@@ -257,11 +170,11 @@
             // init uid iterator
         }
 
-
         /**
-         *Description of the Method
-         *
-         * @exception  IOException  Description of Exception
+         * Description of the Method
+         * 
+         * @exception IOException
+         *                Description of Exception
          */
         public void deleteAllStaleDocuments() throws IOException {
             while (uidIter.term() != null && uidIter.term().field() == "uid") {
@@ -270,12 +183,13 @@
             }
         }
 
-
         /**
-         *Description of the Method
-         *
-         * @param  uid              Description of Parameter
-         * @exception  IOException  Description of Exception
+         * Description of the Method
+         * 
+         * @param uid
+         *            Description of Parameter
+         * @exception IOException
+         *                Description of Exception
          */
         public void deleteModifiedDocuments(String uid) throws IOException {
             while (documentHasBeenModified(uidIter.term(), uid)) {
@@ -287,11 +201,11 @@
             }
         }
 
-
         /**
-         *Description of the Method
-         *
-         * @exception  Throwable  Description of Exception
+         * Description of the Method
+         * 
+         * @exception Throwable
+         *                Description of Exception
          */
         protected void finalize() throws Throwable {
             super.finalize();
@@ -307,42 +221,86 @@
             }
         }
 
-
         /**
-         *Description of the Method
-         *
-         * @param  term  Description of Parameter
-         * @return       Description of the Returned Value
+         * Description of the Method
+         * 
+         * @param term
+         *            Description of Parameter
+         * @return Description of the Returned Value
          */
         boolean documentIsDeletable(Term term) {
             return term != null && term.field() == "uid";
         }
 
-
         /**
-         *Description of the Method
-         *
-         * @param  term  Description of Parameter
-         * @param  uid   Description of Parameter
-         * @return       Description of the Returned Value
+         * Description of the Method
+         * 
+         * @param term
+         *            Description of Parameter
+         * @param uid
+         *            Description of Parameter
+         * @return Description of the Returned Value
          */
         boolean documentHasBeenModified(Term term, String uid) {
-            return documentIsDeletable(term) &&
-                    term.text().compareTo(uid) < 0;
+            return documentIsDeletable(term) && term.text().compareTo(uid) < 0;
         }
 
-
         /**
-         *Description of the Method
-         *
-         * @param  term  Description of Parameter
-         * @param  uid   Description of Parameter
-         * @return       Description of the Returned Value
+         * Description of the Method
+         * 
+         * @param term
+         *            Description of Parameter
+         * @param uid
+         *            Description of Parameter
+         * @return Description of the Returned Value
          */
         boolean documentHasNotBeenModified(Term term, String uid) {
-            return documentIsDeletable(term) &&
-                    term.text().compareTo(uid) == 0;
+            return documentIsDeletable(term) && term.text().compareTo(uid) == 0;
         }
     }
-}
 
+    /**
+     * @return the mergeFactor
+     */
+    public int getMergeFactor() {
+        return mergeFactor;
+    }
+
+    /**
+     * @param mergeFactor
+     *            the mergeFactor to set
+     */
+    public void setMergeFactor(int mergeFactor) {
+        this.mergeFactor = mergeFactor;
+    }
+
+    /**
+     * @return the luceneXMLIndexer
+     */
+    public LuceneXMLIndexer getLuceneXMLIndexer() {
+        return luceneXMLIndexer;
+    }
+
+    /**
+     * @param luceneXMLIndexer
+     *            the luceneXMLIndexer to set
+     */
+    public void setLuceneXMLIndexer(LuceneXMLIndexer luceneXMLIndexer) {
+        this.luceneXMLIndexer = luceneXMLIndexer;
+    }
+
+    /**
+     * @return the cocoonCrawler
+     */
+    public CocoonCrawler getCocoonCrawler() {
+        return cocoonCrawler;
+    }
+
+    /**
+     * @param cocoonCrawler
+     *            the cocoonCrawler to set
+     */
+    public void setCocoonCrawler(CocoonCrawler cocoonCrawler) {
+        this.cocoonCrawler = cocoonCrawler;
+    }
+}

Modified: cocoon/trunk/blocks/cocoon-lucene/cocoon-lucene-impl/src/main/java/org/apache/cocoon/components/search/SimpleLuceneCocoonSearcherImpl.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-lucene/cocoon-lucene-impl/src/main/java/org/apache/cocoon/components/search/SimpleLuceneCocoonSearcherImpl.java?view=diff&rev=554234&r1=554233&r2=554234
==============================================================================
--- cocoon/trunk/blocks/cocoon-lucene/cocoon-lucene-impl/src/main/java/org/apache/cocoon/components/search/SimpleLuceneCocoonSearcherImpl.java (original)
+++ cocoon/trunk/blocks/cocoon-lucene/cocoon-lucene-impl/src/main/java/org/apache/cocoon/components/search/SimpleLuceneCocoonSearcherImpl.java Sat Jul  7 11:08:56 2007
@@ -15,18 +15,14 @@
  * limitations under the License.
  */
 package org.apache.cocoon.components.search;
-import org.apache.avalon.excalibur.pool.Recyclable;
-import org.apache.avalon.framework.activity.Disposable;
-import org.apache.avalon.framework.configuration.Configurable;
-import org.apache.avalon.framework.configuration.Configuration;
-import org.apache.avalon.framework.configuration.ConfigurationException;
-import org.apache.avalon.framework.logger.AbstractLogEnabled;
-import org.apache.avalon.framework.service.ServiceException;
-import org.apache.avalon.framework.service.ServiceManager;
-import org.apache.avalon.framework.service.Serviceable;
+
+import java.io.File;
+import java.io.IOException;
+
 import org.apache.cocoon.ProcessingException;
-import org.apache.cocoon.util.ClassUtils;
+import org.apache.cocoon.util.AbstractLogEnabled;
 import org.apache.lucene.analysis.Analyzer;
+import org.apache.lucene.analysis.standard.StandardAnalyzer;
 import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.queryParser.ParseException;
 import org.apache.lucene.queryParser.QueryParser;
@@ -35,178 +31,96 @@
 import org.apache.lucene.search.Query;
 import org.apache.lucene.store.Directory;
 import org.apache.lucene.store.FSDirectory;
-
-import java.io.File;
-import java.io.IOException;
+import org.springframework.beans.factory.InitializingBean;
 
 /**
  * This class provides searching via lucene.
- *
+ * 
  * <p>
- *   In order to do searching you need a lucene Directory where the lucene generated
- *   index resides.
- *   Moreover you must know the lucene Analyzer which has been used for
- *   indexing, and which will be used for searching.
+ * In order to do searching you need a lucene Directory where the lucene
+ * generated index resides. Moreover you must know the lucene Analyzer which has
+ * been used for indexing, and which will be used for searching.
  * </p>
  * <p>
- *   Knowing this you can may start searching having a query which is parsable
- *   by an QueryParser, and having the name of the default field to use in
- *   searching.
+ * Knowing this you can may start searching having a query which is parsable by
+ * an QueryParser, and having the name of the default field to use in searching.
  * </p>
  * <p>
- *   This class returns an Hit object as its search result.
+ * This class returns an Hit object as its search result.
  * </p>
- *
- * @version $Id$
+ * 
+ * @version $Id: SimpleLuceneCocoonSearcherImpl.java 449162 2006-09-23 05:14:05Z
+ *          crossley $
  */
-public class SimpleLuceneCocoonSearcherImpl extends AbstractLogEnabled
-         implements LuceneCocoonSearcher, Configurable, Serviceable, Disposable, Recyclable
-{
-
-    /**
-     * Configuration element name of lucene's Analyzer class.
-     * <p>
-     *   Its value is
-     *   <code>analyzer-classname</code>.
-     * </p>
-     *
-     */
-    protected final static String ANALYZER_CLASSNAME_CONFIG = "analyzer-classname";
-    /**
-     * Configuration element default value of lucene's Analyzer class.
-     * <p>
-     *   Its value is,
-     *   <code>org.apache.lucene.analysis.standard.StandardAnalyzer</code>.
-     * </p>
-     *
-     */
-    protected final static String ANALYZER_CLASSNAME_DEFAULT = "org.apache.lucene.analysis.standard.StandardAnalyzer";
+public class SimpleLuceneCocoonSearcherImpl extends AbstractLogEnabled implements InitializingBean,
+        LuceneCocoonSearcher {
 
     /**
-     * Configuration element name of default search field.
-     * <p>
-     *   Its value is
-     *   <code>default-seach-field</code>.
-     * </p>
-     *
-     */
-    protected final static String DEFAULT_SEARCH_FIELD_CONFIG = "default-search-field";
-    /**
      * Configuration element default value of lucene's default search field.
      * <p>
-     *   Its value is <code>body</code>.
+     * Its value is <code>body</code>.
      * </p>
-     *
+     * 
      */
     protected final static String DEFAULT_SEARCH_FIELD_DEFAULT = "body";
 
     /**
-     * Configuration element name of default-query.
-     * <p>
-     *   Its value is
-     *   <code>default-query</code>.
-     * </p>
-     *
-     */
-    protected final static String DEFAULT_QUERY_CONFIG = "default-query";
-    /**
      * Configuration element default value of default-query.
      * <p>
-     *   Its value is <code>null</code>.
+     * Its value is <code>null</code>.
      * </p>
-     *
+     * 
      */
     protected final static String DEFAULT_QUERY_DEFAULT = null;
 
     /**
-     * Configuration element name of query parser class name.
-     * <p>
-     *   Its value is
-     *   <code>queryparser-classname</code>.
-     * </p>
-     *
-     */
-    protected final static String QUERYPARSER_CLASSNAME_CONFIG = "queryparser-classname";
-    /**
      * Configuration element default value of queryparser-classname.
      * <p>
-     *   Its value is
-     *   <code>org.apache.lucene.queryParser.QueryParser</code>.
+     * Its value is <code>org.apache.lucene.queryParser.QueryParser</code>.
      * </p>
-     *
+     * 
      */
     protected final static String QUERYPARSER_CLASSNAME_DEFAULT = "org.apache.lucene.queryParser.QueryParser";
 
     /**
-     * Configuration element name of lucene's default filesystem default
-     * directory.
-     * <p>
-     *   Its value is <code>directory</code>.
-     * </p>
-     *
-     */
-    protected final static String DIRECTORY_CONFIG = "directory";
-    /**
      * Configuration element default value of filesystem default directory.
      * <p>
-     *   Its value is <code>null</code>.
+     * Its value is <code>null</code>.
      * </p>
-     *
+     * 
      */
     protected final static String DIRECTORY_DEFAULT = null;
 
     /**
-     * The service manager instance
-     *
+     * The lucene analyzer used for searching
      */
-    protected ServiceManager manager = null;
+    private Analyzer analyzer = new StandardAnalyzer();
 
-    private String analyzerClassnameDefault = ANALYZER_CLASSNAME_DEFAULT;
     private String defaultSearchFieldDefault = DEFAULT_SEARCH_FIELD_DEFAULT;
     private String defaultQueryDefault = DEFAULT_QUERY_DEFAULT;
-//    private String queryparserClassnameDefault = QUERYPARSER_CLASSNAME_DEFAULT;
-    private String directoryDefault = DIRECTORY_DEFAULT;
+    private String defaultQueryparser = QUERYPARSER_CLASSNAME_DEFAULT;
+    private String defaultDirectory = DIRECTORY_DEFAULT;
 
     /**
-     * The lucene analyzer used for searching
-     */
-    private Analyzer analyzer;
-    /**
      * The lucene directory used for searching
      */
     private Directory directory;
+
     /**
      * The lucene index searcher used for searching
      */
     private IndexSearcher indexSearcher;
 
     /**
-     * A lucene index reader cache to maximize sharing of
-     * lucene index readers
+     * A lucene index reader cache to maximize sharing of lucene index readers
      */
     private IndexReaderCache indexReaderCache;
 
     /**
-     * set an analyzer, overriding the analyzerClassnameDefault.
-     *
-     * @param  analyzer  The new analyzer value
-     */
-    public void setAnalyzer(Analyzer analyzer) {
-        this.analyzer = analyzer;
-    }
-
-    /**
-     * get the analyzer.
-     *
-     */
-    public Analyzer getAnalyzer() {
-        return this.analyzer;
-    }
-
-    /**
-     *Sets the directory attribute of the SimpleLuceneCocoonSearcherImpl object
-     *
-     * @param  directory  The new directory value
+     * Sets the directory attribute of the SimpleLuceneCocoonSearcherImpl object
+     * 
+     * @param directory
+     *            The new directory value
      */
     public void setDirectory(Directory directory) {
         this.directory = directory;
@@ -216,17 +130,16 @@
         }
     }
 
-
     /**
      * Get an IndexReader.
      * <p>
-     *   As an IndexReader might be cached, it is check if the indexReader is
-     *   still valid.
+     * As an IndexReader might be cached, it is check if the indexReader is
+     * still valid.
      * </p>
-     *
-     * @return                  IndexReader an up to date indexReader
-     * @exception  IOException  is thrown iff it's impossible to create 
-     * an IndexReader
+     * 
+     * @return IndexReader an up to date indexReader
+     * @exception IOException
+     *                is thrown iff it's impossible to create an IndexReader
      */
     public IndexReader getReader() throws IOException {
         if (indexReaderCache == null) {
@@ -235,85 +148,22 @@
         return indexReaderCache.getIndexReader(directory);
     }
 
-
     /**
      * configure this component
-     *
-     * @param  conf                        of this component
-     * @exception  ConfigurationException  is thrown iff configuration of 
-     *   this component fails
-     */
-    public void configure(Configuration conf) throws ConfigurationException {
-        Configuration child;
-        String value;
-
-        child = conf.getChild(ANALYZER_CLASSNAME_CONFIG, false);
-        if (child != null) {
-            // fix Bugzilla Bug 25277, use child.getValue
-            // and in all following blocks
-            value = child.getValue(ANALYZER_CLASSNAME_DEFAULT);
-            if (value != null) {
-                analyzerClassnameDefault = value;
-                try {
-                    analyzer = (Analyzer) ClassUtils.newInstance(analyzerClassnameDefault);
-                } catch (Exception e) {
-                    throw new ConfigurationException("Cannot create analyzer of class " +
-                            analyzerClassnameDefault, e);
-                }
-            }
-        }
-
-        child = conf.getChild(DEFAULT_SEARCH_FIELD_CONFIG, false);
-        if (child != null) {
-            value = child.getValue(DEFAULT_SEARCH_FIELD_DEFAULT);
-            if (value != null) {
-                defaultSearchFieldDefault = value;
-            }
-        }
-
-        child = conf.getChild(DEFAULT_QUERY_CONFIG, false);
-        if (child != null) {
-            value = child.getValue(DEFAULT_QUERY_DEFAULT);
-            if (value != null) {
-                defaultQueryDefault = value;
-            }
-        }
-/*
-        child = conf.getChild(QUERYPARSER_CLASSNAME_CONFIG, false);
-        if (child != null) {
-            value = child.getValue(QUERYPARSER_CLASSNAME_DEFAULT);
-            if (value != null) {
-                queryparserClassnameDefault = value;
-            }
-        }
-*/
-        child = conf.getChild(DIRECTORY_CONFIG, false);
-        if (child != null) {
-            value = child.getValue(DIRECTORY_DEFAULT);
-            if (value != null) {
-                directoryDefault = value;
-                try {
-                    setDirectory(FSDirectory.getDirectory(new File(directoryDefault), false));
-                } catch (IOException ioe) {
-                    throw new ConfigurationException("Cannot set index directory " + directoryDefault, ioe);
-                }
-            }
-        }
-    }
-
-
-    /**
-     * Set the current <code>ServiceManager</code> instance used by this
-     * <code>Serviceable</code>.
-     *
-     * @param manager  manager of this component
-     * @exception  ServiceException  is never thrown
+     * 
+     * @param conf
+     *            of this component
+     * @exception IllegalArgumentException
+     *                is thrown iff configuration of this bean fails
      */
-    public void service(ServiceManager manager) throws ServiceException {
-        this.manager = manager;
+    public void afterPropertiesSet() throws IllegalArgumentException {
+        try {
+            setDirectory(FSDirectory.getDirectory(new File(getDefaultDirectory()), false));
+        } catch (IOException ioe) {
+            throw new IllegalArgumentException("Cannot set index directory " + getDefaultDirectory(), ioe);
+        }
     }
 
-
     /**
      * Dispose this component, releasing IndexSearcher, and IndexReaderCache.
      */
@@ -322,23 +172,16 @@
         releaseIndexReaderCache();
     }
 
-
-    /**
-     * Recycle this component, releasing IndexSearcher, and IndexReaderCache.
-     */
-    public void recycle() {
-        releaseIndexSearcher();
-        releaseIndexReaderCache();
-    }
-
-
     /**
      * Search lucene index.
-     *
-     * @param  query_string             is lucene's query string
-     * @param  default_field            the lucene field to run the query
-     * @return                          lucene Hits
-     * @exception  ProcessingException  iff its not possible do run the query
+     * 
+     * @param query_string
+     *            is lucene's query string
+     * @param default_field
+     *            the lucene field to run the query
+     * @return lucene Hits
+     * @exception ProcessingException
+     *                iff its not possible do run the query
      */
     public Hits search(String query_string, String default_field) throws ProcessingException {
         Hits hits = null;
@@ -369,12 +212,14 @@
     }
 
     /**
-     * Search lucene index.
-     * This method is designed to be used by other components, or Flowscripts
-     *
-     * @param  query                    the lucene Query
-     * @return                          lucene Hits
-     * @exception  ProcessingException  if its not possible do run the query
+     * Search lucene index. This method is designed to be used by other
+     * components, or Flowscripts
+     * 
+     * @param query
+     *            the lucene Query
+     * @return lucene Hits
+     * @exception ProcessingException
+     *                if its not possible do run the query
      */
     public Hits search(Query query) throws ProcessingException {
         Hits hits = null;
@@ -394,7 +239,7 @@
 
     /**
      * Release the index searcher.
-     *
+     * 
      */
     private void releaseIndexSearcher() {
         if (indexSearcher != null) {
@@ -407,10 +252,9 @@
         }
     }
 
-
     /**
      * Release the IndexReaderCache
-     *
+     * 
      */
     private void releaseIndexReaderCache() {
         if (indexReaderCache != null) {
@@ -418,29 +262,27 @@
         }
     }
 
-
     /**
      * This class should help to minimise usage of IndexReaders.
-     *
+     * 
      */
-    static class IndexReaderCache 
-    {
+    static class IndexReaderCache {
         private IndexReader indexReader;
         private long lastModified;
 
-
         /**
          * Create an IndexReaderCache.
-         *
+         * 
          */
-        IndexReaderCache() { }
-
+        IndexReaderCache() {
+        }
 
         /**
          * return cached IndexReader object.
-         *
-         * @param  directory  lucene index directory
-         * @return            The indexReader value
+         * 
+         * @param directory
+         *            lucene index directory
+         * @return The indexReader value
          */
         public IndexReader getIndexReader(Directory directory) throws IOException {
             if (indexReader == null) {
@@ -453,10 +295,9 @@
             return indexReader;
         }
 
-
         /**
          * Close an opened lucene IndexReader
-         *
+         * 
          */
         public void close() {
             if (indexReader != null) {
@@ -469,37 +310,38 @@
             }
         }
 
-
         /**
          * Check if cached IndexReader is up to date.
-         *
-         * @param  directory        lucene index directory
-         * @return                  boolean  return true if there is a cached IndexReader object,
-         *   and its lastModified date is greater equal than the lastModified date
-         *   of its lucene Directory.
-         * @exception  IOException  Description of Exception
+         * 
+         * @param directory
+         *            lucene index directory
+         * @return boolean return true if there is a cached IndexReader object,
+         *         and its lastModified date is greater equal than the
+         *         lastModified date of its lucene Directory.
+         * @exception IOException
+         *                Description of Exception
          */
         public boolean indexReaderIsValid(Directory directory) throws IOException {
-            return indexReader != null &&
-            IndexReader.getCurrentVersion(directory) == lastModified;
+            return indexReader != null && IndexReader.getCurrentVersion(directory) == lastModified;
         }
 
-
         /**
-         *  Release all resources, most notably the lucene IndexReader.
-         *
-         * @exception  Throwable  Description of Exception
+         * Release all resources, most notably the lucene IndexReader.
+         * 
+         * @exception Throwable
+         *                Description of Exception
          */
         protected void finalize() throws Throwable {
             close();
         }
 
-
         /**
          * Create unconditionally a lucene IndexReader.
-         *
-         * @param  directory        lucene index directory
-         * @exception  IOException  Description of Exception
+         * 
+         * @param directory
+         *            lucene index directory
+         * @exception IOException
+         *                Description of Exception
          */
         private void createIndexReader(Directory directory) throws IOException {
             close();
@@ -507,5 +349,80 @@
             lastModified = IndexReader.getCurrentVersion(directory);
         }
     }
-}
 
+    /**
+     * @return the defaultSearchFieldDefault
+     */
+    public String getDefaultSearchFieldDefault() {
+        return defaultSearchFieldDefault;
+    }
+
+    /**
+     * @param defaultSearchFieldDefault
+     *            the defaultSearchFieldDefault to set
+     */
+    public void setDefaultSearchFieldDefault(String defaultSearchFieldDefault) {
+        this.defaultSearchFieldDefault = defaultSearchFieldDefault;
+    }
+
+    /**
+     * @return the defaultQueryDefault
+     */
+    public String getDefaultQueryDefault() {
+        return defaultQueryDefault;
+    }
+
+    /**
+     * @param defaultQueryDefault
+     *            the defaultQueryDefault to set
+     */
+    public void setDefaultQueryDefault(String defaultQueryDefault) {
+        this.defaultQueryDefault = defaultQueryDefault;
+    }
+
+    /**
+     * @return the defaultQueryparser
+     */
+    public String getDefaultQueryparser() {
+        return defaultQueryparser;
+    }
+
+    /**
+     * @param defaultQueryparser
+     *            the defaultQueryparser to set
+     */
+    public void setDefaultQueryparser(String defaultQueryparser) {
+        this.defaultQueryparser = defaultQueryparser;
+    }
+
+    /**
+     * @return the defaultDirectory
+     */
+    public String getDefaultDirectory() {
+        return defaultDirectory;
+    }
+
+    /**
+     * @param defaultDirectory
+     *            the defaultDirectory to set
+     */
+    public void setDefaultDirectory(String defaultDirectory) {
+        this.defaultDirectory = defaultDirectory;
+    }
+
+    /**
+     * @return the analyzer
+     */
+    public Analyzer getAnalyzer() {
+        return analyzer;
+    }
+
+    /**
+     * @param analyzer
+     *            the analyzer to set
+     */
+    public void setAnalyzer(Analyzer analyzer) {
+        this.analyzer = analyzer;
+    }
+
+}

Modified: cocoon/trunk/blocks/cocoon-lucene/cocoon-lucene-impl/src/main/java/org/apache/cocoon/components/search/SimpleLuceneXMLIndexerImpl.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-lucene/cocoon-lucene-impl/src/main/java/org/apache/cocoon/components/search/SimpleLuceneXMLIndexerImpl.java?view=diff&rev=554234&r1=554233&r2=554234
==============================================================================
--- cocoon/trunk/blocks/cocoon-lucene/cocoon-lucene-impl/src/main/java/org/apache/cocoon/components/search/SimpleLuceneXMLIndexerImpl.java (original)
+++ cocoon/trunk/blocks/cocoon-lucene/cocoon-lucene-impl/src/main/java/org/apache/cocoon/components/search/SimpleLuceneXMLIndexerImpl.java Sat Jul  7 11:08:56 2007
@@ -16,23 +16,6 @@
  */
 package org.apache.cocoon.components.search;
 
-import org.apache.avalon.framework.configuration.Configurable;
-import org.apache.avalon.framework.configuration.Configuration;
-import org.apache.avalon.framework.configuration.ConfigurationException;
-import org.apache.avalon.framework.logger.AbstractLogEnabled;
-import org.apache.avalon.framework.service.ServiceException;
-import org.apache.avalon.framework.service.ServiceManager;
-import org.apache.avalon.framework.service.Serviceable;
-import org.apache.avalon.framework.thread.ThreadSafe;
-import org.apache.cocoon.ProcessingException;
-import org.apache.commons.lang.StringUtils;
-import org.apache.excalibur.xml.sax.SAXParser;
-import org.apache.lucene.document.DateField;
-import org.apache.lucene.document.Document;
-import org.apache.lucene.document.Field;
-import org.xml.sax.InputSource;
-import org.xml.sax.SAXException;
-
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.URL;
@@ -42,76 +25,76 @@
 import java.util.Iterator;
 import java.util.List;
 
+import org.apache.cocoon.ProcessingException;
+import org.apache.cocoon.core.xml.SAXParser;
+import org.apache.cocoon.util.AbstractLogEnabled;
+import org.apache.lucene.document.DateField;
+import org.apache.lucene.document.Document;
+import org.apache.lucene.document.Field;
+import org.springframework.beans.factory.InitializingBean;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
 
 /**
  * A simple class building lucene documents from xml content.
- *
- * <p>It has two parameters that effect the way it works:</p>
+ * 
+ * <p>
+ * It has two parameters that effect the way it works:
+ * </p>
  * <p>
- *   <tt>&lt;store-fields/&gt;</tt> 
- *   Sets which tags in your content are stored in Lucene as fields, 
- *   during the indexing process. Allows them to be output with search hits.
- * </p><p>
- *   <tt>&lt;content-view-query/&gt;</tt>
- *   Sets the view the indexer will request for indexing content.
- * </p><p>
- *   Example configuration (goes in cocoon.xconf)
- *   <pre><tt>
- *     &lt;lucene-xml-indexer logger="core.search.lucene"&gt;
- *       &lt;store-fields&gt;title, summary&lt;/store-fields&gt;
- *       &lt;content-view-query&gt;cocoon-view=search&lt;/content-view-query&gt;
- *     &lt;/lucene-xml-indexer&gt;
- *   </tt></pre></p>
- *
- * @version $Id$
+ * <tt>&lt;storeFields/&gt;</tt> Sets which tags in your content are stored
+ * in Lucene as fields, during the indexing process. Allows them to be output
+ * with search hits.
+ * </p>
+ * <p>
+ * <tt>&lt;contentViewQuery/&gt;</tt> Sets the view the indexer will request
+ * for indexing content.
+ * </p>
+ * <p>
+ * Example configuration (goes in cocoon-lucene.xml)
+ * 
+ * <pre><tt>
+ * &lt;bean name=&quot;org.apache.cocoon.components.search.LuceneXMLIndexer&quot; class=&quot;org.apache.cocoon.components.search.SimpleLuceneXMLIndexerImpl&quot;&gt;
+ *   &lt;property name=&quot;parser&quot; ref=&quot;org.apache.cocoon.core.xml.SAXParser&quot; /&gt;
+ *   &lt;!-- Config element name specifying query-string appendend for requesting links of an URL. --&gt;
+ *   &lt;property name="contentViewQuery&quot; value=&quot;cocoon-view=content&quot; /&gt;
+ *   &lt;!-- Optional config element name specifying the tags to be added as Stored, Untokenised, Unindexed Fields. --&gt;
+ *   &lt;property name=&quot;storeFields&quot;&gt;
+ *      &lt;storeFields&gt;
+ *        &lt;set&gt;
+ *          &lt;value&gt;title&lt;/value&gt;
+ *          &lt;value&gt;summary&lt;/value&gt;
+ *        &lt;/set&gt;
+ *       &lt;/storeFields&gt;
+ *   &lt;/property&gt;
+ * &lt;/bean&gt;
+ * 
+ * </tt></pre>
+ * 
+ * </p>
+ * 
+ * @version $Id: SimpleLuceneXMLIndexerImpl.java 449162 2006-09-23 05:14:05Z
+ *          crossley $
  */
-public class SimpleLuceneXMLIndexerImpl extends AbstractLogEnabled
-         implements LuceneXMLIndexer, Configurable, Serviceable, ThreadSafe {
-
-    /**
-     * The service manager instance
-     *
-     * @since
-     */
-    protected ServiceManager manager = null;
+public class SimpleLuceneXMLIndexerImpl extends AbstractLogEnabled implements LuceneXMLIndexer, InitializingBean {
 
     /**
-     * Config element name specifying query-string appendend for requesting links
-     * of an URL.
-     * <p>
-     *  Its value is <code>link-view-query</code>.
-     * </p>
-     *
+     * append this string to the url in order to get the content view of the url
+     * 
      * @since
      */
-    public final static String CONTENT_VIEW_QUERY_CONFIG = "content-view-query";
-
-    /**
-     * append this string to the url in order to get the
-     * content view of the url
-     *
-     * @since
-     */
-    
     final String CONTENT_VIEW_QUERY_DEFAULT = "cocoon-view=content";
 
     /**
-     * Config element name specifying the tags to be added as Stored, Untokenised, Unindexed Fields.
-     * <p>
-     *  Its value is <code>field-tags</code>.
-     * </p>
-     *
-     * @since
-     */
-    public final static String FIELDTAGS_CONFIG = "store-fields";
-
-    /**
      * set of allowed content types
-     *
+     * 
      * @since
      */
     final HashSet allowedContentType;
 
+    private String contentViewQuery = CONTENT_VIEW_QUERY_DEFAULT;
+    private HashSet storeFields;
+    private SAXParser parser;
 
     /**
      * @since
@@ -120,83 +103,48 @@
         allowedContentType = new HashSet();
         allowedContentType.add("text/xml");
         allowedContentType.add("text/xhtml");
-        fieldTags = new HashSet();
+        storeFields = new HashSet();
     }
-    
-    
-    private String contentViewQuery = CONTENT_VIEW_QUERY_DEFAULT;
-    private HashSet fieldTags;
-
 
     /**
-     * configure
-     *
-     * @param  configuration
-     * @exception  ConfigurationException
-     * @since
-     */
-    public void configure(Configuration configuration) throws ConfigurationException { 
-    
-        Configuration[] children;
-        children = configuration.getChildren(FIELDTAGS_CONFIG);
-        if (children != null && children.length > 0) {
-            fieldTags = new HashSet();
-            for (int i = 0; i < children.length; i++) {
-                String pattern = children[i].getValue();
-                String params[] = StringUtils.split(pattern, ", ");
-                for (int index = 0; index < params.length; index++) {
-                    String tokenized_pattern = params[index];
-					if (!tokenized_pattern.equals("")) {
-						this.fieldTags.add(tokenized_pattern);
-						if (getLogger().isDebugEnabled()) {
-								getLogger().debug("add field: " + tokenized_pattern);
-						}
-					}
-    			}
-            }
-        } else {
-            if (getLogger().isDebugEnabled()) {
+     * afterPropertiesSet
+     * 
+     * @exception IllegalArgumentException
+     */
+    public void afterPropertiesSet() throws IllegalArgumentException {
+        if (getLogger().isDebugEnabled()) {
+            if (getStoreFields() != null) {
+                final Iterator iter = getStoreFields().iterator();
+                while (iter.hasNext()) {
+                    getLogger().debug("add field: " + (String) iter.next());
+                }
+            } else {
                 getLogger().debug("Do not add any fields");
             }
+            getLogger().debug("content view: " + this.getContentViewQuery());
+        }
+        if (parser == null) {
+            throw new IllegalArgumentException("Cannot lookup xml parser!");
         }
-        this.contentViewQuery = configuration.getChild(CONTENT_VIEW_QUERY_CONFIG, true).getValue(CONTENT_VIEW_QUERY_DEFAULT);
-				if (getLogger().isDebugEnabled()) {
-						getLogger().debug("content view: " + this.contentViewQuery);
-				}
-    }
-
-
-    /**
-     * Set the current <code>ServiceManager</code> instance used by this
-     * <code>Serviceable</code>.
-     *
-     * @param  manager                 Description of Parameter
-     * @exception  ServiceException  Description of Exception
-     * @since
-     */
-    public void service(ServiceManager manager) throws ServiceException {
-        this.manager = manager;
     }
 
-
     /**
      * Build lucenen documents from a URL
-     *
-     * @param  url                      the content of this url gets indexed.
-     * @exception  ProcessingException  Description of Exception
+     * 
+     * @param url
+     *            the content of this url gets indexed.
+     * @exception ProcessingException
+     *                Description of Exception
      * @since
      */
-    public List build(URL url)
-             throws ProcessingException {
+    public List build(URL url) throws ProcessingException {
 
         try {
-            URL contentURL = new URL(url, url.getFile()
-                + ((url.getFile().indexOf("?") == -1) ? "?" : "&")
-                + contentViewQuery);
+            URL contentURL = new URL(url, url.getFile() + ((url.getFile().indexOf("?") == -1) ? "?" : "&")
+                    + contentViewQuery);
             URLConnection contentURLConnection = contentURL.openConnection();
             if (contentURLConnection == null) {
-                throw new ProcessingException("Can not open connection to URL "
-                        + contentURL + " (null connection)");
+                throw new ProcessingException("Can not open connection to URL " + contentURL + " (null connection)");
             }
 
             String contentType = contentURLConnection.getContentType();
@@ -219,7 +167,7 @@
                 }
 
                 LuceneIndexContentHandler luceneIndexContentHandler = new LuceneIndexContentHandler();
-                luceneIndexContentHandler.setFieldTags(fieldTags);
+                luceneIndexContentHandler.setFieldTags(storeFields);
                 indexDocument(contentURLConnection, luceneIndexContentHandler);
                 //
                 // document is parsed
@@ -245,31 +193,29 @@
         }
     }
 
-
     /**
      * index input stream producing lucene Documents
-     *
-     * @param  contentURLConnection       the xml content which should get indexed.
-     * @param  luceneIndexContentHandler  ContentHandler for generating
-     *   a lucene Document from XML content.
-     * @exception  ProcessingException    Description of Exception
+     * 
+     * @param contentURLConnection
+     *            the xml content which should get indexed.
+     * @param luceneIndexContentHandler
+     *            ContentHandler for generating a lucene Document from XML
+     *            content.
+     * @exception ProcessingException
+     *                Description of Exception
      * @since
      */
-    private void indexDocument(URLConnection contentURLConnection,
-            LuceneIndexContentHandler luceneIndexContentHandler)
-             throws ProcessingException {
+    private void indexDocument(URLConnection contentURLConnection, LuceneIndexContentHandler luceneIndexContentHandler)
+            throws ProcessingException {
 
         InputStream is = null;
         InputSource in = null;
-        SAXParser parser = null;
 
         try {
             is = contentURLConnection.getInputStream();
             in = new InputSource(is);
 
-            // get an XML parser
-            parser = (SAXParser) this.manager.lookup(SAXParser.ROLE);
-            //reader.setErrorHandler(new CocoonErrorHandler());
+            // reader.setErrorHandler(new CocoonErrorHandler());
             parser.parse(in, luceneIndexContentHandler);
             //
             // document is parsed
@@ -278,31 +224,68 @@
             throw new ProcessingException("Cannot read!", ioe);
         } catch (SAXException saxe) {
             throw new ProcessingException("Cannot parse!", saxe);
-        } catch (ServiceException se) {
-            throw new ProcessingException("Cannot lookup xml parser!", se);
-        } finally {
-            if (parser != null) {
-                this.manager.release(parser);
-            }
         }
     }
 
-
     /**
      * return a unique uid of a url connection
-     *
-     * @param  urlConnection  Description of Parameter
-     * @return                String unique uid of a urlConnection
+     * 
+     * @param urlConnection
+     *            Description of Parameter
+     * @return String unique uid of a urlConnection
      * @since
      */
     private String uid(URLConnection urlConnection) {
         // Append path and date into a string in such a way that lexicographic
-        // sorting gives the same results as a walk of the file hierarchy.  Thus
+        // sorting gives the same results as a walk of the file hierarchy. Thus
         // null (\u0000) is used both to separate directory components and to
         // separate the path from the date.
-        return urlConnection.toString().replace('/', '\u0000') +
-                "\u0000" +
-                DateField.timeToString(urlConnection.getLastModified());
+        return urlConnection.toString().replace('/', '\u0000') + "\u0000"
+                + DateField.timeToString(urlConnection.getLastModified());
+    }
+
+    /**
+     * @return the contentViewQuery
+     */
+    public String getContentViewQuery() {
+        return contentViewQuery;
+    }
+
+    /**
+     * @param contentViewQuery
+     *            the contentViewQuery to set
+     */
+    public void setContentViewQuery(String contentViewQuery) {
+        this.contentViewQuery = contentViewQuery;
+    }
+
+    /**
+     * @return the storeFields
+     */
+    public HashSet getStoreFields() {
+        return storeFields;
+    }
+
+    /**
+     * @param storeFields
+     *            the dtoreFields to set
+     */
+    public void setStoreFields(HashSet storeFields) {
+        this.storeFields = storeFields;
+    }
+
+    /**
+     * @return the parser
+     */
+    public SAXParser getParser() {
+        return parser;
     }
-}
 
+    /**
+     * @param parser
+     *            the parser to set
+     */
+    public void setParser(SAXParser parser) {
+        this.parser = parser;
+    }
+}

Modified: cocoon/trunk/blocks/cocoon-lucene/cocoon-lucene-impl/src/main/java/org/apache/cocoon/generation/SearchGenerator.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-lucene/cocoon-lucene-impl/src/main/java/org/apache/cocoon/generation/SearchGenerator.java?view=diff&rev=554234&r1=554233&r2=554234
==============================================================================
--- cocoon/trunk/blocks/cocoon-lucene/cocoon-lucene-impl/src/main/java/org/apache/cocoon/generation/SearchGenerator.java (original)
+++ cocoon/trunk/blocks/cocoon-lucene/cocoon-lucene-impl/src/main/java/org/apache/cocoon/generation/SearchGenerator.java Sat Jul  7 11:08:56 2007
@@ -16,54 +16,56 @@
  */
 package org.apache.cocoon.generation;
 
-import org.apache.avalon.framework.parameters.Parameters;
-import org.apache.avalon.framework.service.ServiceException;
-import org.apache.avalon.framework.service.ServiceManager;
+import java.io.File;
+import java.io.IOException;
+import java.util.Enumeration;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
 
+import org.apache.avalon.framework.parameters.Parameters;
 import org.apache.cocoon.ProcessingException;
 import org.apache.cocoon.components.search.LuceneCocoonHelper;
 import org.apache.cocoon.components.search.LuceneCocoonPager;
 import org.apache.cocoon.components.search.LuceneCocoonSearcher;
 import org.apache.cocoon.components.search.LuceneXMLIndexer;
+import org.apache.cocoon.components.source.util.SourceUtil;
 import org.apache.cocoon.configuration.Settings;
 import org.apache.cocoon.environment.ObjectModelHelper;
 import org.apache.cocoon.environment.Request;
 import org.apache.cocoon.environment.SourceResolver;
-
+import org.apache.cocoon.sitemap.DisposableSitemapComponent;
+import org.apache.cocoon.spring.configurator.WebAppContextUtils;
+import org.apache.cocoon.util.AbstractLogEnabled;
+import org.apache.cocoon.xml.XMLConsumer;
+import org.apache.excalibur.source.Source;
+import org.apache.excalibur.source.SourceException;
 import org.apache.lucene.analysis.Analyzer;
 import org.apache.lucene.document.Document;
 import org.apache.lucene.document.Field;
 import org.apache.lucene.search.Hits;
 import org.apache.lucene.store.Directory;
-
+import org.springframework.beans.factory.InitializingBean;
 import org.xml.sax.SAXException;
 import org.xml.sax.helpers.AttributesImpl;
 
-import java.io.File;
-import java.io.IOException;
-import java.util.Enumeration;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
 /**
  * Generates an XML representation of a search result.
- *
+ * 
  * <p>
- *  This generator generates xml content representening an XML search.
- *  The generated xml content contains the search result,
- *  the search query information, and navigation information about the
- *  search results.
- *  The query is sent to the generator, either via the 'queryString' request parameter
- *  or the 'query' SiteMap parameter. The sitemap overides the request.
+ * This generator generates xml content representening an XML search. The
+ * generated xml content contains the search result, the search query
+ * information, and navigation information about the search results. The query
+ * is sent to the generator, either via the 'queryString' request parameter or
+ * the 'query' SiteMap parameter. The sitemap overides the request.
  * </p>
- *
+ * 
  * <p>
- *  Search xml sample generated by this generator:
+ * Search xml sample generated by this generator:
  * </p>
+ * 
  * <pre><tt>
  * &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
- *
  * &lt;search:results date=&quot;1008437081064&quot; query-string=&quot;cocoon&quot;
  *     start-index=&quot;0&quot; page-length=&quot;10&quot;
  *     xmlns:search=&quot;http://apache.org/cocoon/search/1.0&quot;
@@ -71,11 +73,10 @@
  *   &lt;search:hits total-count=&quot;125&quot; count-of-pages=&quot;13&quot;&gt;
  *     &lt;search:hit rank=&quot;0&quot; score=&quot;1.0&quot;
  *         uri=&quot;http://localhost:8080/cocoon/documents/hosting.html&quot;&gt;
- *       &lt;search:field name="title"&gt;Document Title&lt;search:field/&gt;
+ *       &lt;search:field name=&quot;title&quot;&gt;Document Title&lt;search:field/&gt;
  *     &lt;search:hit/&gt;
  *     ...
  *   &lt;/search:hits&gt;
- *
  *   &lt;search:navigation total-count=&quot;125&quot; count-of-pages=&quot;13&quot;
  *       has-next=&quot;true&quot; has-previous=&quot;false&quot; next-index=&quot;10&quot; previous-index=&quot;0&quot;&gt;
  *     &lt;search:navigation-page start-index=&quot;0&quot;/&gt;
@@ -85,10 +86,11 @@
  *   &lt;/search:navigation&gt;
  * &lt;/search:results&gt;
  * </tt></pre>
- *
+ * 
  * @version $Id$
  */
-public class SearchGenerator extends ServiceableGenerator {
+public class SearchGenerator extends AbstractLogEnabled implements Generator, InitializingBean,
+        DisposableSitemapComponent {
 
     /**
      * The XML namespace for the output document.
@@ -116,14 +118,15 @@
     protected final static String RESULTS_ELEMENT = "results";
 
     /**
-     * Qualified name of root element of generated xml content, ie <code>search:results</code>.
+     * Qualified name of root element of generated xml content, ie
+     * <code>search:results</code>.
      */
     protected final static String Q_RESULTS_ELEMENT = PREFIX + ":" + RESULTS_ELEMENT;
 
     /**
-     * Attribute <code>date</code> of <code>results</code> element.
-     * It contains the date a long value, indicating when a search
-     * generated this xml content.
+     * Attribute <code>date</code> of <code>results</code> element. It
+     * contains the date a long value, indicating when a search generated this
+     * xml content.
      */
     protected final static String DATE_ATTRIBUTE = "date";
 
@@ -151,20 +154,20 @@
     protected final static String NAME_ATTRIBUTE = "name";
 
     /**
-     * Child element of generated xml content, ie <code>hits</code>.
-     * This element describes all hits.
+     * Child element of generated xml content, ie <code>hits</code>. This
+     * element describes all hits.
      */
     protected final static String HITS_ELEMENT = "hits";
 
     /**
-     * QName of child element of generated xml content, ie <code>search:hits</code>.
-     * This element describes all hits.
+     * QName of child element of generated xml content, ie
+     * <code>search:hits</code>. This element describes all hits.
      */
     protected final static String Q_HITS_ELEMENT = PREFIX + ":" + HITS_ELEMENT;
 
     /**
-     * Attribute <code>total-count</code> of <code>hits</code> element.
-     * The value describes total number of hits found by the search engine.
+     * Attribute <code>total-count</code> of <code>hits</code> element. The
+     * value describes total number of hits found by the search engine.
      */
     protected final static String TOTAL_COUNT_ATTRIBUTE = "total-count";
 
@@ -175,33 +178,33 @@
     protected final static String COUNT_OF_PAGES_ATTRIBUTE = "count-of-pages";
 
     /**
-     * Child element of generated xml content, ie <code>hit</code>.
-     * This element describes a single hit.
+     * Child element of generated xml content, ie <code>hit</code>. This
+     * element describes a single hit.
      */
     protected final static String HIT_ELEMENT = "hit";
 
     /**
-     * QName of child element of generated xml content, ie <code>search:hit</code>.
-     * This element describes a single hit.
+     * QName of child element of generated xml content, ie
+     * <code>search:hit</code>. This element describes a single hit.
      */
     protected final static String Q_HIT_ELEMENT = PREFIX + ":" + HIT_ELEMENT;
 
     /**
-     * Attribute <code>rank</code> of <code>hit</code> element.
-     * The value describes the count index of this hits, ranging between 0, and
+     * Attribute <code>rank</code> of <code>hit</code> element. The value
+     * describes the count index of this hits, ranging between 0, and
      * total-count minus 1.
      */
     protected final static String RANK_ATTRIBUTE = "rank";
 
     /**
-     * Attribute <code>score</code> of <code>hit</code> element.
-     * The value describes the score of this hits, ranging between 0, and 1.0.
+     * Attribute <code>score</code> of <code>hit</code> element. The value
+     * describes the score of this hits, ranging between 0, and 1.0.
      */
     protected final static String SCORE_ATTRIBUTE = "score";
 
     /**
-     * Attribute <code>uri</code> of <code>hit</code> element.
-     * The value describes the uri of a document matching the search query.
+     * Attribute <code>uri</code> of <code>hit</code> element. The value
+     * describes the uri of a document matching the search query.
      */
     protected final static String URI_ATTRIBUTE = "uri";
 
@@ -212,7 +215,8 @@
     protected final static String FIELD_ELEMENT = "field";
 
     /**
-     * QName of child element <code>search:field</code> of the <code>hit</code> element.
+     * QName of child element <code>search:field</code> of the
+     * <code>hit</code> element.
      */
     protected final static String Q_FIELD_ELEMENT = PREFIX + ":" + FIELD_ELEMENT;
 
@@ -223,7 +227,8 @@
     protected final static String NAVIGATION_ELEMENT = "navigation";
 
     /**
-     * QName of child element of generated xml content, ie <code>search:navigation</code>.
+     * QName of child element of generated xml content, ie
+     * <code>search:navigation</code>.
      */
     protected final static String Q_NAVIGATION_ELEMENT = PREFIX + ":" + NAVIGATION_ELEMENT;
 
@@ -234,32 +239,37 @@
     protected final static String NAVIGATION_PAGE_ELEMENT = "navigation-page";
 
     /**
-     * QName of child element of generated xml content, ie <code>search:navigation-page</code>.
-     * This element describes the start-index of page containing hits.
+     * QName of child element of generated xml content, ie
+     * <code>search:navigation-page</code>. This element describes the
+     * start-index of page containing hits.
      */
     protected final static String Q_NAVIGATION_PAGE_ELEMENT = PREFIX + ":" + NAVIGATION_PAGE_ELEMENT;
 
     /**
-     * Attribute <code>has-next</code> of <code>navigation-page</code> element.
-     * The value is true if a next navigation control should be presented.
+     * Attribute <code>has-next</code> of <code>navigation-page</code>
+     * element. The value is true if a next navigation control should be
+     * presented.
      */
     protected final static String HAS_NEXT_ATTRIBUTE = "has-next";
 
     /**
-     * Attribute <code>has-next</code> of <code>navigation-page</code> element.
-     * The value is true if a previous navigation control should be presented.
+     * Attribute <code>has-next</code> of <code>navigation-page</code>
+     * element. The value is true if a previous navigation control should be
+     * presented.
      */
     protected final static String HAS_PREVIOUS_ATTRIBUTE = "has-previous";
 
     /**
-     * Attribute <code>next-index</code> of <code>navigation-page</code> element.
-     * The value describes the start-index of the next-to-be-presented page.
+     * Attribute <code>next-index</code> of <code>navigation-page</code>
+     * element. The value describes the start-index of the next-to-be-presented
+     * page.
      */
     protected final static String NEXT_INDEX_ATTRIBUTE = "next-index";
 
     /**
-     * Attribute <code>previous-index</code> of <code>navigation-page</code> element.
-     * The value describes the start-index of the previous-to-be-presented page.
+     * Attribute <code>previous-index</code> of <code>navigation-page</code>
+     * element. The value describes the start-index of the
+     * previous-to-be-presented page.
      */
     protected final static String PREVIOUS_INDEX_ATTRIBUTE = "previous-index";
 
@@ -269,7 +279,8 @@
     protected final static String INDEX_PARAM = "index";
 
     /**
-     * Default value of setup parameter <code>index</code>, ie <code>index</code>.
+     * Default value of setup parameter <code>index</code>, ie
+     * <code>index</code>.
      */
     protected final static String INDEX_PARAM_DEFAULT = "index";
 
@@ -279,13 +290,13 @@
     protected final static String ANALYZER_PARAM = "analyzer";
 
     /**
-     * Default value of analyzer parameter <code>analyzer</code>, ie <code>org.apache.lucene.analysis.standard.StandardAnalyzer</code>.
+     * Default value of analyzer parameter <code>analyzer</code>, ie
+     * <code>org.apache.lucene.analysis.standard.StandardAnalyzer</code>.
      */
     protected final static String ANALYZER_PARAM_DEFAULT = "org.apache.lucene.analysis.standard.StandardAnalyzer";
-    
+
     /**
-     * Setup the actual query from generator parameter,
-     * ie <code>query</code>.
+     * Setup the actual query from generator parameter, ie <code>query</code>.
      */
     protected final static String QUERY_PARAM = "query";
 
@@ -296,7 +307,8 @@
     protected final static String QUERY_STRING_PARAM = "query-string";
 
     /**
-     * Default value of setup parameter <code>query-string</code>, ie <code>queryString</code>.
+     * Default value of setup parameter <code>query-string</code>, ie
+     * <code>queryString</code>.
      */
     protected final static String QUERY_STRING_PARAM_DEFAULT = "queryString";
 
@@ -307,29 +319,32 @@
     protected final static String START_INDEX_PARAM = "start-index";
 
     /**
-     * Default value of setup parameter <code>start-index</code>, ie <code>startIndex</code>.
+     * Default value of setup parameter <code>start-index</code>, ie
+     * <code>startIndex</code>.
      */
     protected final static String START_INDEX_PARAM_DEFAULT = "startIndex";
 
     /**
-     * Setup parameter name specifying the name of start-next-index query parameter,
-     * ie <code>start-next-index</code>.
+     * Setup parameter name specifying the name of start-next-index query
+     * parameter, ie <code>start-next-index</code>.
      */
     protected final static String START_INDEX_NEXT_PARAM = "start-next-index";
 
     /**
-     * Default value of setup parameter <code>start-next-index</code>, ie <code>startNextIndex</code>.
+     * Default value of setup parameter <code>start-next-index</code>, ie
+     * <code>startNextIndex</code>.
      */
     protected final static String START_INDEX_NEXT_PARAM_DEFAULT = "startNextIndex";
 
     /**
-     * Setup parameter name specifying the name of start-previous-index query parameter,
-     * ie <code>start-previous-index</code>.
+     * Setup parameter name specifying the name of start-previous-index query
+     * parameter, ie <code>start-previous-index</code>.
      */
     protected final static String START_INDEX_PREVIOUS_PARAM = "start-previous-index";
 
     /**
-     * Default value of setup parameter <code>start-previous-index</code>, ie <code>startPreviousIndex</code>.
+     * Default value of setup parameter <code>start-previous-index</code>, ie
+     * <code>startPreviousIndex</code>.
      */
     protected final static String START_INDEX_PREVIOUS_PARAM_DEFAULT = "startPreviousIndex";
 
@@ -348,20 +363,21 @@
     /**
      * Default home directory of index directories.
      * <p>
-     *   Releative index directories specified in the setup of this generator are resolved
-     *   relative to this directory.
+     * Releative index directories specified in the setup of this generator are
+     * resolved relative to this directory.
      * </p>
      * <p>
-     *   By default this directory is set to the <code>WORKING_DIR</code> of Cocoon.
+     * By default this directory is set to the <code>WORKING_DIR</code> of
+     * Cocoon.
      * </p>
      */
     private File workDir = null;
 
     /**
-     * The avalon component to use for searching.
+     * The component to use for searching.
      */
-    private LuceneCocoonSearcher lcs;
-    
+    private LuceneCocoonSearcher luceneCocoonSearcher;
+
     /**
      * Analyzer used for searching
      */
@@ -392,37 +408,48 @@
      */
     private Integer pageLength = null;
 
+    /** The consumer. */
+    protected XMLConsumer consumer;
+
     /**
-     * Set the current <code>ServiceManager</code> instance used by this
-     * <code>Serviceable</code>.
+     * @see org.apache.cocoon.sitemap.DisposableSitemapComponent#dispose()
      */
-    public void service(ServiceManager manager) throws ServiceException {
-        super.service(manager);
-        // If the index directory is specified relativly, the working directory is
-        // used as home directory of the index directory.
-        final Settings settings = (Settings)this.manager.lookup(Settings.ROLE);
-        this.workDir = new File(settings.getWorkDirectory());
-        this.manager.release(settings);
+    public void dispose() {
+        this.consumer = null;
+    }
+
+    /**
+     * configure this bean
+     * 
+     * @exception IllegalArgumentException
+     *                is thrown iff configuration of this bean fails
+     */
+    public void afterPropertiesSet() throws IllegalArgumentException {
+        if (getLuceneCocoonSearcher() == null) {
+            throw new IllegalArgumentException("Unable to initialize property 'cocoonLuceneSearcher'");
+        }
     }
 
     // TODO: parameterize()
 
     /**
-     * setup all members of this generator.
+     * Setup the file generator. Try to get the last modification date of the
+     * source for caching.
+     * 
+     * @see org.apache.cocoon.sitemap.SitemapModelComponent#setup(org.apache.cocoon.environment.SourceResolver,
+     *      java.util.Map, java.lang.String,
+     *      org.apache.avalon.framework.parameters.Parameters)
      */
-    public void setup(SourceResolver resolver, Map objectModel, String src, Parameters par)
-             throws ProcessingException, SAXException, IOException {
-        super.setup(resolver, objectModel, src, par);
-
-        try {
-            lcs = (LuceneCocoonSearcher) this.manager.lookup(LuceneCocoonSearcher.ROLE);
-        } catch (ServiceException e) {
-            throw new ProcessingException("Unable to lookup " + LuceneCocoonSearcher.ROLE, e);
-        }
+    public void setup(SourceResolver resolver, Map objectModel, String src, Parameters par) throws ProcessingException,
+            SAXException, IOException {
 
         String param_name;
         Request request = ObjectModelHelper.getRequest(objectModel);
 
+        final Settings settings = (Settings) WebAppContextUtils.getCurrentWebApplicationContext().getBean(
+                "org.apache.cocoon.configuration.Settings");
+        this.workDir = new File(settings.getWorkDirectory());
+
         String index_file_name = par.getParameter(INDEX_PARAM, INDEX_PARAM_DEFAULT);
         if (request.getParameter(INDEX_PARAM) != null) {
             index_file_name = request.getParameter(INDEX_PARAM);
@@ -433,13 +460,13 @@
         if (!index.isAbsolute()) {
             index = new File(workDir, index.toString());
         }
-        
+
         // try to get the analyzer from the sitemap parameter
         this.analyzer = par.getParameter(ANALYZER_PARAM, ANALYZER_PARAM_DEFAULT);
         if (getLogger().isDebugEnabled()) {
             getLogger().debug("Analyzer is set to: " + this.analyzer);
         }
-        
+
         // try getting the queryString from the generator sitemap params
 
         queryString = par.getParameter(QUERY_PARAM, "");
@@ -454,7 +481,7 @@
         if (getLogger().isDebugEnabled()) {
             getLogger().debug("Search index with query: " + queryString);
         }
-        
+
         // always try lookup the start index from the request params
         // get startIndex
         startIndex = null;
@@ -484,13 +511,15 @@
     }
 
     /**
-     * Generate xml content describing search results.
-     * Entry point of the ComposerGenerator.
-     * The xml content is generated from the hits object.
-     *
-     * @exception  IOException       when there is a problem reading the from file system.
-     * @throws  SAXException         when there is a problem creating the output SAX events.
-     * @throws  ProcessingException  when there is a problem obtaining the hits
+     * Generate xml content describing search results. Entry point of the
+     * ComposerGenerator. The xml content is generated from the hits object.
+     * 
+     * @exception IOException
+     *                when there is a problem reading the from file system.
+     * @throws SAXException
+     *             when there is a problem creating the output SAX events.
+     * @throws ProcessingException
+     *             when there is a problem obtaining the hits
      */
     public void generate() throws IOException, SAXException, ProcessingException {
         // set default parameter value, in case of no values are set yet.
@@ -502,26 +531,27 @@
         }
 
         // Start the document and set the namespace.
-        this.contentHandler.startDocument();
-        this.contentHandler.startPrefixMapping(PREFIX, NAMESPACE);
-        this.contentHandler.startPrefixMapping("xlink", XLINK_NAMESPACE);
+        this.consumer.startDocument();
+        this.consumer.startPrefixMapping(PREFIX, NAMESPACE);
+        this.consumer.startPrefixMapping("xlink", XLINK_NAMESPACE);
 
         generateResults();
 
         // End the document.
-        this.contentHandler.endPrefixMapping("xlink");
-        this.contentHandler.endPrefixMapping(PREFIX);
-        this.contentHandler.endDocument();
+        this.consumer.endPrefixMapping("xlink");
+        this.consumer.endPrefixMapping(PREFIX);
+        this.consumer.endDocument();
     }
 
     /**
      * Create an Integer.
      * <p>
-     *   Create an Integer from String s, if conversion fails return null.
+     * Create an Integer from String s, if conversion fails return null.
      * </p>
-     *
-     * @param  s  Converting s to an Integer
-     * @return    Integer converted value originating from s, or null
+     * 
+     * @param s
+     *            Converting s to an Integer
+     * @return Integer converted value originating from s, or null
      */
     private Integer createInteger(String s) {
         Integer i = null;
@@ -539,12 +569,14 @@
     /**
      * Build and generate the search results.
      * <p>
-     *  First build the hits, next generate xml content from the hits,
-     *  taking page index, and length into account.
+     * First build the hits, next generate xml content from the hits, taking
+     * page index, and length into account.
      * </p>
-     *
-     * @throws  SAXException         when there is a problem creating the output SAX events.
-     * @throws  ProcessingException  when there is a problem obtaining the hits
+     * 
+     * @throws SAXException
+     *             when there is a problem creating the output SAX events.
+     * @throws ProcessingException
+     *             when there is a problem obtaining the hits
      */
     private void generateResults() throws SAXException, ProcessingException, IOException {
         // Make the hits
@@ -560,40 +592,44 @@
         atts.addAttribute("", START_INDEX_ATTRIBUTE, START_INDEX_ATTRIBUTE, CDATA, String.valueOf(startIndex));
         atts.addAttribute("", PAGE_LENGTH_ATTRIBUTE, PAGE_LENGTH_ATTRIBUTE, CDATA, String.valueOf(pageLength));
 
-        contentHandler.startElement(NAMESPACE, RESULTS_ELEMENT, Q_RESULTS_ELEMENT, atts);
+        consumer.startElement(NAMESPACE, RESULTS_ELEMENT, Q_RESULTS_ELEMENT, atts);
 
         // build xml from the hits
         generateHits(pager);
         generateNavigation(pager);
 
         // End root element.
-        contentHandler.endElement(NAMESPACE, RESULTS_ELEMENT, Q_RESULTS_ELEMENT);
+        consumer.endElement(NAMESPACE, RESULTS_ELEMENT, Q_RESULTS_ELEMENT);
     }
 
     /**
      * Generate the xml content of all hits
-     *
-     * @param  pager                 the LuceneContentPager with the search results
-     * @throws  SAXException         when there is a problem creating the output SAX events.
+     * 
+     * @param pager
+     *            the LuceneContentPager with the search results
+     * @throws SAXException
+     *             when there is a problem creating the output SAX events.
      */
     private void generateHits(LuceneCocoonPager pager) throws SAXException {
         if (pager != null) {
             atts.clear();
-            atts.addAttribute("", TOTAL_COUNT_ATTRIBUTE, TOTAL_COUNT_ATTRIBUTE,
-                CDATA, String.valueOf(pager.getCountOfHits()));
-            atts.addAttribute("", COUNT_OF_PAGES_ATTRIBUTE, COUNT_OF_PAGES_ATTRIBUTE,
-                CDATA, String.valueOf(pager.getCountOfPages()));
-            contentHandler.startElement(NAMESPACE, HITS_ELEMENT, Q_HITS_ELEMENT, atts);
+            atts.addAttribute("", TOTAL_COUNT_ATTRIBUTE, TOTAL_COUNT_ATTRIBUTE, CDATA, String.valueOf(pager
+                    .getCountOfHits()));
+            atts.addAttribute("", COUNT_OF_PAGES_ATTRIBUTE, COUNT_OF_PAGES_ATTRIBUTE, CDATA, String.valueOf(pager
+                    .getCountOfPages()));
+            consumer.startElement(NAMESPACE, HITS_ELEMENT, Q_HITS_ELEMENT, atts);
             generateHit(pager);
-            contentHandler.endElement(NAMESPACE, HITS_ELEMENT, Q_HITS_ELEMENT);
+            consumer.endElement(NAMESPACE, HITS_ELEMENT, Q_HITS_ELEMENT);
         }
     }
 
     /**
      * Generate the xml content for each hit.
-     *
-     * @param  pager                 the LuceneCocoonPager with the search results.
-     * @throws  SAXException         when there is a problem creating the output SAX events.
+     * 
+     * @param pager
+     *            the LuceneCocoonPager with the search results.
+     * @throws SAXException
+     *             when there is a problem creating the output SAX events.
      */
     private void generateHit(LuceneCocoonPager pager) throws SAXException {
         // get the off set to start from
@@ -609,87 +645,84 @@
             String uri = doc.get(LuceneXMLIndexer.URL_FIELD);
 
             atts.clear();
-            atts.addAttribute("", RANK_ATTRIBUTE, RANK_ATTRIBUTE, CDATA,
-                    String.valueOf(counter));
-            atts.addAttribute("", SCORE_ATTRIBUTE, SCORE_ATTRIBUTE, CDATA,
-                    String.valueOf(score));
-            atts.addAttribute("", URI_ATTRIBUTE, URI_ATTRIBUTE, CDATA,
-                    String.valueOf(uri));
-            contentHandler.startElement(NAMESPACE, HIT_ELEMENT, Q_HIT_ELEMENT, atts);
+            atts.addAttribute("", RANK_ATTRIBUTE, RANK_ATTRIBUTE, CDATA, String.valueOf(counter));
+            atts.addAttribute("", SCORE_ATTRIBUTE, SCORE_ATTRIBUTE, CDATA, String.valueOf(score));
+            atts.addAttribute("", URI_ATTRIBUTE, URI_ATTRIBUTE, CDATA, String.valueOf(uri));
+            consumer.startElement(NAMESPACE, HIT_ELEMENT, Q_HIT_ELEMENT, atts);
             // fix me, add here a summary of this hit
-            for (Enumeration e = doc.fields(); e.hasMoreElements(); ) {
-                Field field = (Field)e.nextElement();
+            for (Enumeration e = doc.fields(); e.hasMoreElements();) {
+                Field field = (Field) e.nextElement();
                 if (field.isStored()) {
                     if (LuceneXMLIndexer.URL_FIELD.equals(field.name()))
                         continue;
                     atts.clear();
                     atts.addAttribute("", NAME_ATTRIBUTE, NAME_ATTRIBUTE, CDATA, field.name());
-                    contentHandler.startElement(NAMESPACE, FIELD_ELEMENT, Q_FIELD_ELEMENT, atts);
+                    consumer.startElement(NAMESPACE, FIELD_ELEMENT, Q_FIELD_ELEMENT, atts);
                     String value = field.stringValue();
-                    contentHandler.characters(value.toCharArray(), 0, value.length());
-                    contentHandler.endElement(NAMESPACE, FIELD_ELEMENT, Q_FIELD_ELEMENT);
+                    consumer.characters(value.toCharArray(), 0, value.length());
+                    consumer.endElement(NAMESPACE, FIELD_ELEMENT, Q_FIELD_ELEMENT);
                 }
             }
 
-            contentHandler.endElement(NAMESPACE, HIT_ELEMENT, Q_HIT_ELEMENT);
+            consumer.endElement(NAMESPACE, HIT_ELEMENT, Q_HIT_ELEMENT);
         }
     }
 
     /**
      * Generate the navigation element.
-     *
-     * @param  pager                    Description of Parameter
-     * @exception  SAXException         Description of Exception
+     * 
+     * @param pager
+     *            Description of Parameter
+     * @exception SAXException
+     *                Description of Exception
      */
     private void generateNavigation(LuceneCocoonPager pager) throws SAXException {
         if (pager != null) {
             // generate navigation element
             atts.clear();
-            atts.addAttribute("", TOTAL_COUNT_ATTRIBUTE, TOTAL_COUNT_ATTRIBUTE,
-                CDATA, String.valueOf(pager.getCountOfHits()));
-            atts.addAttribute("", COUNT_OF_PAGES_ATTRIBUTE, COUNT_OF_PAGES_ATTRIBUTE,
-                CDATA, String.valueOf(pager.getCountOfPages()));
-            atts.addAttribute("", HAS_NEXT_ATTRIBUTE, HAS_NEXT_ATTRIBUTE,
-                CDATA, String.valueOf(pager.hasNext()));
-            atts.addAttribute("", HAS_PREVIOUS_ATTRIBUTE, HAS_PREVIOUS_ATTRIBUTE,
-                CDATA, String.valueOf(pager.hasPrevious()));
-            atts.addAttribute("", NEXT_INDEX_ATTRIBUTE, NEXT_INDEX_ATTRIBUTE,
-                CDATA, String.valueOf(pager.nextIndex()));
-            atts.addAttribute("", PREVIOUS_INDEX_ATTRIBUTE, PREVIOUS_INDEX_ATTRIBUTE,
-                CDATA, String.valueOf(pager.previousIndex()));
-            contentHandler.startElement(NAMESPACE, NAVIGATION_ELEMENT, Q_NAVIGATION_ELEMENT, atts);
+            atts.addAttribute("", TOTAL_COUNT_ATTRIBUTE, TOTAL_COUNT_ATTRIBUTE, CDATA, String.valueOf(pager
+                    .getCountOfHits()));
+            atts.addAttribute("", COUNT_OF_PAGES_ATTRIBUTE, COUNT_OF_PAGES_ATTRIBUTE, CDATA, String.valueOf(pager
+                    .getCountOfPages()));
+            atts.addAttribute("", HAS_NEXT_ATTRIBUTE, HAS_NEXT_ATTRIBUTE, CDATA, String.valueOf(pager.hasNext()));
+            atts.addAttribute("", HAS_PREVIOUS_ATTRIBUTE, HAS_PREVIOUS_ATTRIBUTE, CDATA, String.valueOf(pager
+                    .hasPrevious()));
+            atts.addAttribute("", NEXT_INDEX_ATTRIBUTE, NEXT_INDEX_ATTRIBUTE, CDATA, String.valueOf(pager.nextIndex()));
+            atts.addAttribute("", PREVIOUS_INDEX_ATTRIBUTE, PREVIOUS_INDEX_ATTRIBUTE, CDATA, String.valueOf(pager
+                    .previousIndex()));
+            consumer.startElement(NAMESPACE, NAVIGATION_ELEMENT, Q_NAVIGATION_ELEMENT, atts);
             int count_of_pages = pager.getCountOfPages();
-            for (int i = 0, page_start_index = 0;
-                    i < count_of_pages;
-                    i++, page_start_index += pageLength.intValue()) {
+            for (int i = 0, page_start_index = 0; i < count_of_pages; i++, page_start_index += pageLength.intValue()) {
                 atts.clear();
-                atts.addAttribute("", START_INDEX_ATTRIBUTE, START_INDEX_ATTRIBUTE,
-                    CDATA, String.valueOf(page_start_index));
-                contentHandler.startElement(NAMESPACE, NAVIGATION_PAGE_ELEMENT, Q_NAVIGATION_PAGE_ELEMENT, atts);
-                contentHandler.endElement(NAMESPACE, NAVIGATION_PAGE_ELEMENT, Q_NAVIGATION_PAGE_ELEMENT);
+                atts.addAttribute("", START_INDEX_ATTRIBUTE, START_INDEX_ATTRIBUTE, CDATA, String
+                        .valueOf(page_start_index));
+                consumer.startElement(NAMESPACE, NAVIGATION_PAGE_ELEMENT, Q_NAVIGATION_PAGE_ELEMENT, atts);
+                consumer.endElement(NAMESPACE, NAVIGATION_PAGE_ELEMENT, Q_NAVIGATION_PAGE_ELEMENT);
             }
             // navigation is EMPTY element
-            contentHandler.endElement(NAMESPACE, NAVIGATION_ELEMENT, Q_NAVIGATION_ELEMENT);
+            consumer.endElement(NAMESPACE, NAVIGATION_ELEMENT, Q_NAVIGATION_ELEMENT);
         }
     }
 
     /**
      * Build hits from a query input, and setup paging object.
-     *
-     * @throws  ProcessingException  if an error occurs
+     * 
+     * @throws ProcessingException
+     *             if an error occurs
      */
     private LuceneCocoonPager buildHits() throws ProcessingException, IOException {
         if (queryString != null && queryString.length() != 0) {
             Hits hits = null;
 
             Analyzer analyzer = LuceneCocoonHelper.getAnalyzer(this.analyzer);
-            lcs.setAnalyzer(analyzer);
+            getLuceneCocoonSearcher().setAnalyzer(analyzer);
             // get the directory where the index resides
             Directory directory = LuceneCocoonHelper.getDirectory(index, false);
-            lcs.setDirectory(directory);
-            hits = lcs.search(queryString, LuceneXMLIndexer.BODY_FIELD);
+            getLuceneCocoonSearcher().setDirectory(directory);
+            hits = getLuceneCocoonSearcher().search(queryString, LuceneXMLIndexer.BODY_FIELD);
 
-            // wrap the hits by an pager help object for accessing only a range of hits
+            // wrap the hits by an pager help object for accessing only a range
+            // of hits
             LuceneCocoonPager pager = new LuceneCocoonPager(hits);
 
             int start_index = START_INDEX_DEFAULT;
@@ -717,18 +750,24 @@
     }
 
     /**
-     * Recycle the generator
+     * @return the luceneCocoonSearcher
+     */
+    public LuceneCocoonSearcher getLuceneCocoonSearcher() {
+        return luceneCocoonSearcher;
+    }
+
+    /**
+     * @param luceneCocoonSearcher
+     *            the luceneCocoonSearcher to set
      */
-    public void recycle() {
-        super.recycle();
-        if (lcs != null) {
-            this.manager.release(lcs);
-        }
-        this.queryString = null;
-        this.startIndex = null;
-        this.pageLength = null;
-        this.index = null;
-        this.analyzer = null;
+    public void setLuceneCocoonSearcher(LuceneCocoonSearcher luceneCocoonSearcher) {
+        this.luceneCocoonSearcher = luceneCocoonSearcher;
     }
 
+    /**
+     * @see org.apache.cocoon.xml.XMLProducer#setConsumer(org.apache.cocoon.xml.XMLConsumer)
+     */
+    public void setConsumer(XMLConsumer consumer) {
+        this.consumer = consumer;
+    }
 }



Re: svn commit: r554234 [1/2] - in /cocoon/trunk/blocks/cocoon-lucene/cocoon-lucene-impl/src: changes/ main/java/org/apache/cocoon/components/search/ main/java/org/apache/cocoon/generation/ main/java/org/apache/cocoon/samples/ main/resources/META-INF/cocoo...

Posted by Felix Knecht <fe...@apache.org>.
> +1000 for having codified rules and templates but please don't do any
> revolution with existing code. Evolution (gradual but constant) is
> much easier to handle.
>
> WDYT?
>

OK, I give my best to keep on this.

Re: svn commit: r554234 [1/2] - in /cocoon/trunk/blocks/cocoon-lucene/cocoon-lucene-impl/src: changes/ main/java/org/apache/cocoon/components/search/ main/java/org/apache/cocoon/generation/ main/java/org/apache/cocoon/samples/ main/resources/META-INF/cocoo...

Posted by Grzegorz Kossakowski <gk...@apache.org>.
Felix Knecht pisze:
>> <snip what="real changes and formatting mishmash"/>
>>
>> Felix, first of all I'm grateful for your contributions and I'm feeling
>> bad that I have to bring this issue again.
> 
> Just do it. I don't mind and it's part of OSS that codereviewing is done!
> My problem is just doing code formatting quite automatically before
> committing. 

Other very important habit is to review your changes _before_ making commit so you can spot that too much changes are going to be committed 
and do something with it.

I'm not against code formatting (I used to reformat code myself) but I would like to see it in separate commit clearly stating it's only 
about adjusting formatting. What's more, it's usually better to commit reformatting changes before you start to play with piece of code. If 
you do it in other order your reformatting commit message will overlap the previous one that is the only worth to be seen.

> I really thought I have now the right settings for Java-Code
> and for XML-Code. For me it sounds logical (because of course all others
> before me also kept to these formatting rules ;-) ) that it should be
> possible to do it this way without trapping into this formatting stuff
> again - and I really don't want to do it manually now adays.
> Maybe I should just first commit my stuff without any formattings (just
> the way I wrote it down) and then afterwards do another commit
> formatting applied ?

No, exactly opposite order should be chosen, see above.

> I don't see any other way when I don't want to so the formatting
> manually during changing the code (and manually isn't state of the art
> IMO). Do you have any other idea/way of doing it?

Isn't your IDE apply formatting to the new code you write according to your settings? I thought that you only have to reformat the code that 
you have _not_ touched.

> OTH when we want to take care about this we really should think about
> reformatting once the whole code with a well defined format (which can
> be downloaded at the apache-cocoon site) and have templates at least for
> the probably most used IDE's by cocoon developers (like Eclipse,
> NetBeans, ?).

+1000 for having codified rules and templates but please don't do any revolution with existing code. Evolution (gradual but constant) is 
much easier to handle.

WDYT?

-- 
Grzegorz Kossakowski
http://reflectingonthevicissitudes.wordpress.com/

Re: svn commit: r554234 [1/2] - in /cocoon/trunk/blocks/cocoon-lucene/cocoon-lucene-impl/src: changes/ main/java/org/apache/cocoon/components/search/ main/java/org/apache/cocoon/generation/ main/java/org/apache/cocoon/samples/ main/resources/META-INF/cocoo...

Posted by Felix Knecht <fe...@otego.com>.
>>
> 
> <snip what="real changes and formatting mishmash"/>
> 
> Felix, first of all I'm grateful for your contributions and I'm feeling
> bad that I have to bring this issue again.

Just do it. I don't mind and it's part of OSS that codereviewing is done!
My problem is just doing code formatting quite automatically before
committing. I really thought I have now the right settings for Java-Code
and for XML-Code. For me it sounds logical (because of course all others
before me also kept to these formatting rules ;-) ) that it should be
possible to do it this way without trapping into this formatting stuff
again - and I really don't want to do it manually now adays.
Maybe I should just first commit my stuff without any formattings (just
the way I wrote it down) and then afterwards do another commit
formatting applied ?
I don't see any other way when I don't want to so the formatting
manually during changing the code (and manually isn't state of the art
IMO). Do you have any other idea/way of doing it?

OTH when we want to take care about this we really should think about
reformatting once the whole code with a well defined format (which can
be downloaded at the apache-cocoon site) and have templates at least for
the probably most used IDE's by cocoon developers (like Eclipse,
NetBeans, ?).

Felix

> 
> I've been reading Karl Fogel's book[1] lately (thanks to Google for
> sending me, a SoC participant, a free, printed copy) and I stumbled
> across very interesting paragraph[2]. I would really like to take an
> advice of this paragraph and revise others changes for reasons that Karl
> already outlined.
> 
> Felix, I hope that you'll remember to make my dreams about revising
> commits come true. :-)
> 
> [1] http://producingoss.com/
> [2] http://producingoss.com/en/setting-tone.html#code-review
> 


Re: svn commit: r554234 [1/2] - in /cocoon/trunk/blocks/cocoon-lucene/cocoon-lucene-impl/src: changes/ main/java/org/apache/cocoon/components/search/ main/java/org/apache/cocoon/generation/ main/java/org/apache/cocoon/samples/ main/resources/META-INF/cocoo...

Posted by Grzegorz Kossakowski <gk...@apache.org>.
felixk@apache.org pisze:
> Author: felixk
> Date: Sat Jul  7 11:08:56 2007
> New Revision: 554234
> 
> URL: http://svn.apache.org/viewvc?view=rev&rev=554234
> Log:
> Springify lucene block.
> 
> Added:
>     cocoon/trunk/blocks/cocoon-lucene/cocoon-lucene-impl/src/main/java/org/apache/cocoon/samples/LuceneCocoonCrawler.java   (with props)
>     cocoon/trunk/blocks/cocoon-lucene/cocoon-lucene-impl/src/main/resources/META-INF/cocoon/spring/
>     cocoon/trunk/blocks/cocoon-lucene/cocoon-lucene-impl/src/main/resources/META-INF/cocoon/spring/cocoon-lucene.xml   (with props)
> Removed:
>     cocoon/trunk/blocks/cocoon-lucene/cocoon-lucene-impl/src/main/resources/META-INF/cocoon/avalon/
>     cocoon/trunk/blocks/cocoon-lucene/cocoon-lucene-impl/src/main/resources/org/
> Modified:
>     cocoon/trunk/blocks/cocoon-lucene/cocoon-lucene-impl/src/changes/changes.xml
>     cocoon/trunk/blocks/cocoon-lucene/cocoon-lucene-impl/src/main/java/org/apache/cocoon/components/search/SimpleLuceneCocoonIndexerImpl.java
>     cocoon/trunk/blocks/cocoon-lucene/cocoon-lucene-impl/src/main/java/org/apache/cocoon/components/search/SimpleLuceneCocoonSearcherImpl.java
>     cocoon/trunk/blocks/cocoon-lucene/cocoon-lucene-impl/src/main/java/org/apache/cocoon/components/search/SimpleLuceneXMLIndexerImpl.java
>     cocoon/trunk/blocks/cocoon-lucene/cocoon-lucene-impl/src/main/java/org/apache/cocoon/generation/SearchGenerator.java
>     cocoon/trunk/blocks/cocoon-lucene/cocoon-lucene-impl/src/main/java/org/apache/cocoon/samples/LuceneUtil.java

<snip what="real changes and formatting mishmash"/>

Felix, first of all I'm grateful for your contributions and I'm feeling bad that I have to bring this issue again.

I've been reading Karl Fogel's book[1] lately (thanks to Google for sending me, a SoC participant, a free, printed copy) and I stumbled
across very interesting paragraph[2]. I would really like to take an advice of this paragraph and revise others changes for reasons that 
Karl already outlined.

Felix, I hope that you'll remember to make my dreams about revising commits come true. :-)

[1] http://producingoss.com/
[2] http://producingoss.com/en/setting-tone.html#code-review

-- 
Grzegorz Kossakowski
http://reflectingonthevicissitudes.wordpress.com/


Re: svn commit: r554234 [1/2] - in /cocoon/trunk/blocks/cocoon-lucene/cocoon-lucene-impl/src: changes/ main/java/org/apache/cocoon/components/search/ main/java/org/apache/cocoon/generation/ main/java/org/apache/cocoon/samples/ main/resources/META-INF/cocoo...

Posted by Felix Knecht <fe...@otego.com>.
felixk@apache.org schrieb:
> Author: felixk
> Date: Sat Jul  7 11:08:56 2007
> New Revision: 554234
> 
> URL: http://svn.apache.org/viewvc?view=rev&rev=554234
> Log:
> Springify lucene block.
> 

I just realised that I missed the transformer - I'm working on.

Felix