You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by jo...@apache.org on 2006/02/07 15:36:55 UTC

svn commit: r375611 - in /lenya/trunk/src/modules/lucene: ./ config/cocoon-xconf/ java/src/org/apache/cocoon/components/modules/ java/src/org/apache/cocoon/components/modules/input/

Author: josias
Date: Tue Feb  7 06:36:53 2006
New Revision: 375611

URL: http://svn.apache.org/viewcvs?rev=375611&view=rev
Log:
added input module to get the path of the lucene search index, instead of hardcoding it in the sitemap

Added:
    lenya/trunk/src/modules/lucene/config/cocoon-xconf/index-path-module.xconf   (with props)
    lenya/trunk/src/modules/lucene/java/src/org/apache/cocoon/components/modules/
    lenya/trunk/src/modules/lucene/java/src/org/apache/cocoon/components/modules/input/
    lenya/trunk/src/modules/lucene/java/src/org/apache/cocoon/components/modules/input/IndexPathModule.java   (with props)
Modified:
    lenya/trunk/src/modules/lucene/sitemap.xmap

Added: lenya/trunk/src/modules/lucene/config/cocoon-xconf/index-path-module.xconf
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/modules/lucene/config/cocoon-xconf/index-path-module.xconf?rev=375611&view=auto
==============================================================================
--- lenya/trunk/src/modules/lucene/config/cocoon-xconf/index-path-module.xconf (added)
+++ lenya/trunk/src/modules/lucene/config/cocoon-xconf/index-path-module.xconf Tue Feb  7 06:36:53 2006
@@ -0,0 +1,22 @@
+<?xml version="1.0"?>
+<!--
+  Copyright 1999-2005 The Apache Software Foundation
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+
+  <xconf xpath="/cocoon/input-modules" unless="/cocoon/input-modules/component-instance[@name = 'index-path']">
+    <component-instance logger="core.modules.input.index-path" name="index-path"
+      class="org.apache.cocoon.components.modules.input.IndexPathModule">
+    </component-instance>
+  </xconf>

Propchange: lenya/trunk/src/modules/lucene/config/cocoon-xconf/index-path-module.xconf
------------------------------------------------------------------------------
    svn:eol-style = native

Added: lenya/trunk/src/modules/lucene/java/src/org/apache/cocoon/components/modules/input/IndexPathModule.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/modules/lucene/java/src/org/apache/cocoon/components/modules/input/IndexPathModule.java?rev=375611&view=auto
==============================================================================
--- lenya/trunk/src/modules/lucene/java/src/org/apache/cocoon/components/modules/input/IndexPathModule.java (added)
+++ lenya/trunk/src/modules/lucene/java/src/org/apache/cocoon/components/modules/input/IndexPathModule.java Tue Feb  7 06:36:53 2006
@@ -0,0 +1,99 @@
+/*
+ * Copyright  1999-2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+
+package org.apache.cocoon.components.modules.input;
+
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.service.ServiceException;
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.avalon.framework.service.Serviceable;
+import org.apache.cocoon.components.search.Index;
+import org.apache.cocoon.components.search.components.IndexManager;
+import org.apache.lucene.store.FSDirectory;
+
+/**
+ * This module returns the directory path of a search index given by its id,
+ * which normally is "pubid-area".
+ */
+public class IndexPathModule extends AbstractInputModule implements Serviceable {
+
+    protected ServiceManager serviceManager;
+    
+    public void service(ServiceManager manager) throws ServiceException {
+        this.serviceManager = manager;
+    }
+
+    /**
+     * @see org.apache.cocoon.components.modules.input.InputModule#getAttribute(java.lang.String,
+     *      org.apache.avalon.framework.configuration.Configuration, java.util.Map)
+     */
+    public Object getAttribute(String name, Configuration modeConf, Map objectModel)
+            throws ConfigurationException {
+
+        String value = null;
+        
+        IndexManager indexManager = null;
+        try {
+            indexManager = (IndexManager) this.serviceManager.lookup(IndexManager.ROLE);
+            
+            Index index = indexManager.getIndex(name);
+            
+            if (index == null) {
+                throw new ConfigurationException("no search index with id [" + name + "] found.");
+            }
+            
+            value = ((FSDirectory)index.getDirectory()).getFile().getCanonicalPath();
+
+            if (getLogger().isDebugEnabled()) {
+                getLogger().debug("resolved search index with id [" + name + "] to directory " + value);
+            }
+        } catch (Exception e) {
+            throw new ConfigurationException("Resolving attribute [" + name + "] failed: ", e);
+        } finally {
+            if (indexManager != null) {
+                this.serviceManager.release(indexManager);
+            }
+        }
+        return value;
+    }
+
+    /**
+     * @see org.apache.cocoon.components.modules.input.InputModule#getAttributeNames(org.apache.avalon.framework.configuration.Configuration,
+     *      java.util.Map)
+     */
+    public Iterator getAttributeNames(Configuration modeConf, Map objectModel)
+            throws ConfigurationException {
+        return Collections.EMPTY_SET.iterator();
+    }
+
+    /**
+     * @see org.apache.cocoon.components.modules.input.InputModule#getAttributeValues(java.lang.String,
+     *      org.apache.avalon.framework.configuration.Configuration, java.util.Map)
+     */
+    public Object[] getAttributeValues(String name, Configuration modeConf, Map objectModel)
+            throws ConfigurationException {
+        Object[] objects = { getAttribute(name, modeConf, objectModel) };
+
+        return objects;
+    }
+
+}
\ No newline at end of file

Propchange: lenya/trunk/src/modules/lucene/java/src/org/apache/cocoon/components/modules/input/IndexPathModule.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: lenya/trunk/src/modules/lucene/sitemap.xmap
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/modules/lucene/sitemap.xmap?rev=375611&r1=375610&r2=375611&view=diff
==============================================================================
--- lenya/trunk/src/modules/lucene/sitemap.xmap (original)
+++ lenya/trunk/src/modules/lucene/sitemap.xmap Tue Feb  7 06:36:53 2006
@@ -45,7 +45,7 @@
       <map:match pattern="opensearch.xml">
           <!-- TODO: implement the opensearch results to make the search results available for an external app -->
         <map:generate type="search">
-          <map:parameter name="index" value="{realpath://lenya/pubs/{page-envelope:publication-id}/work/lucene/index}"/>
+          <map:parameter name="index" value="{index-path:{page-envelope:publication-id}-{page-envelope:area}}"/>
         </map:generate>
 
         <map:transform src="fallback://lenya/modules/lucene/xslt/search2opensearch.xsl">
@@ -89,7 +89,7 @@
 
       <map:match pattern="search.xml">
         <map:generate type="search">
-          <map:parameter name="index" value="{realpath://lenya/pubs/{page-envelope:publication-id}/work/lucene/index/{page-envelope:area}/index}"/>
+          <map:parameter name="index" value="{index-path:{page-envelope:publication-id}-{page-envelope:area}}"/>
         </map:generate>
 
         <map:transform src="fallback://lenya/modules/lucene/xslt/search2html.xsl">



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@lenya.apache.org
For additional commands, e-mail: commits-help@lenya.apache.org