logo       

svn commit: r426061 - in /lenya/trunk/src: java/org/apache/lenya/cms/cocoon: msg#00190

Subject: svn commit: r426061 - in /lenya/trunk/src: java/org/apache/lenya/cms/cocoon/generation/ modules/lucene/ modules/lucene/config/cocoon-xconf/ modules/lucene/java/src/org/apache/lenya/cms/lucene/ modules/xhtml/ modules/xhtml/config/cocoon-xconf/ pubs/defa...
Author: andreas
Date: Thu Jul 27 06:13:44 2006
New Revision: 426061

URL: http://svn.apache.org/viewvc?rev=426061&view=rev
Log:
Added IndexUpdater for lucene index

Added:
    lenya/trunk/src/modules/lucene/config/cocoon-xconf/index-updater.xconf
    
lenya/trunk/src/modules/lucene/java/src/org/apache/lenya/cms/lucene/IndexUpdater.java
Modified:
    
lenya/trunk/src/java/org/apache/lenya/cms/cocoon/generation/LenyaMetaDataGenerator.java
    lenya/trunk/src/modules/lucene/sitemap.xmap
    lenya/trunk/src/modules/xhtml/config/cocoon-xconf/resource-type-xhtml.xconf
    lenya/trunk/src/modules/xhtml/sitemap.xmap
    
lenya/trunk/src/pubs/default/modules/homepage/config/cocoon-xconf/resource-type-homepage.xconf

Modified: 
lenya/trunk/src/java/org/apache/lenya/cms/cocoon/generation/LenyaMetaDataGenerator.java
URL: 
http://svn.apache.org/viewvc/lenya/trunk/src/java/org/apache/lenya/cms/cocoon/generation/LenyaMetaDataGenerator.java?rev=426061&r1=426060&r2=426061&view=diff
==============================================================================
--- 
lenya/trunk/src/java/org/apache/lenya/cms/cocoon/generation/LenyaMetaDataGenerator.java
 (original)
+++ 
lenya/trunk/src/java/org/apache/lenya/cms/cocoon/generation/LenyaMetaDataGenerator.java
 Thu Jul 27 06:13:44 2006
@@ -39,10 +39,8 @@
 import org.apache.lenya.cms.publication.DocumentUtil;
 import org.apache.lenya.cms.publication.Publication;
 import org.apache.lenya.cms.publication.PublicationUtil;
-import org.apache.lenya.cms.publication.URLInformation;
 import org.apache.lenya.cms.repository.RepositoryUtil;
 import org.apache.lenya.cms.repository.Session;
-import org.apache.lenya.util.ServletHelper;
 import org.xml.sax.SAXException;
 import org.xml.sax.helpers.AttributesImpl;
 
@@ -132,6 +130,16 @@
 
         super.setup(resolver, objectModel, src, par);
 
+        this.publicationId = par.getParameter("pubid", null);
+        if (this.publicationId == null) {
+            throw new ProcessingException("The pubid is not set! Please set 
like e.g. <map:parameter name='pubid' value='{request-param:pubid}'/>");
+        }
+
+        this.area = par.getParameter("area", null);
+        if (this.area == null) {
+            throw new ProcessingException("The area is not set! Please set 
like e.g. <map:parameter name='area' value='{request-param:area}'/>");
+        }
+
         docId = par.getParameter("docid", null);
         if (this.docId == null) {
             throw new ProcessingException("The docid is not set! Please set 
like e.g. <map:parameter name='docid' value='{request-param:docid}'/>");
@@ -157,18 +165,10 @@
         Session session;
         try {
             session = RepositoryUtil.getSession(this.manager, request);
-            pub = PublicationUtil.getPublication(this.manager, objectModel);
+            pub = PublicationUtil.getPublication(this.manager, 
this.publicationId);
         } catch (Exception e) {
             throw new ProcessingException("Error geting publication id / area 
from page envelope",
                     e);
-        }
-        if (pub != null && pub.exists()) {
-            this.publicationId = pub.getId();
-            String url = ServletHelper.getWebappURI(request);
-            this.area = new URLInformation(url).getArea();
-            if (this.language == null) {
-                this.language = pub.getDefaultLanguage();
-            }
         }
 
         DocumentFactory map = 
DocumentUtil.createDocumentIdentityMap(this.manager, session);

Added: lenya/trunk/src/modules/lucene/config/cocoon-xconf/index-updater.xconf
URL: 
http://svn.apache.org/viewvc/lenya/trunk/src/modules/lucene/config/cocoon-xconf/index-updater.xconf?rev=426061&view=auto
==============================================================================
--- lenya/trunk/src/modules/lucene/config/cocoon-xconf/index-updater.xconf 
(added)
+++ lenya/trunk/src/modules/lucene/config/cocoon-xconf/index-updater.xconf Thu 
Jul 27 06:13:44 2006
@@ -0,0 +1,26 @@
+<?xml version="1.0"?>
+<!--
+  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.
+-->
+
+<xconf xpath="/cocoon"
+  if-prop="patch.webapp"
+  unless="/cocoon/component[@role = 
'org.apache.lenya.cms.lucene.IndexUpdater']">
+  
+  <component logger="lucene.indexupdater"
+    role="org.apache.lenya.cms.lucene.IndexUpdater"
+    class="org.apache.lenya.cms.lucene.IndexUpdater"/>
+       
+</xconf>

Added: 
lenya/trunk/src/modules/lucene/java/src/org/apache/lenya/cms/lucene/IndexUpdater.java
URL: 
http://svn.apache.org/viewvc/lenya/trunk/src/modules/lucene/java/src/org/apache/lenya/cms/lucene/IndexUpdater.java?rev=426061&view=auto
==============================================================================
--- 
lenya/trunk/src/modules/lucene/java/src/org/apache/lenya/cms/lucene/IndexUpdater.java
 (added)
+++ 
lenya/trunk/src/modules/lucene/java/src/org/apache/lenya/cms/lucene/IndexUpdater.java
 Thu Jul 27 06:13:44 2006
@@ -0,0 +1,94 @@
+/*
+ * 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.
+ *
+ */
+package org.apache.lenya.cms.lucene;
+
+import java.util.Arrays;
+
+import org.apache.avalon.framework.activity.Startable;
+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.components.source.SourceUtil;
+import org.apache.excalibur.source.Source;
+import org.apache.excalibur.source.SourceResolver;
+import org.apache.lenya.cms.observation.ObservationRegistry;
+import org.apache.lenya.cms.observation.RepositoryEvent;
+import org.apache.lenya.cms.observation.RepositoryListener;
+import org.apache.lenya.cms.publication.Document;
+
+/**
+ * Index updater which updates the index when a document changes.
+ */
+public class IndexUpdater extends AbstractLogEnabled implements 
RepositoryListener, Startable,
+        Serviceable, ThreadSafe {
+
+    public void documentChanged(RepositoryEvent event) {
+        Document doc = event.getDocument();
+        SourceResolver resolver = null;
+        Source source = null;
+
+        try {
+            String[] formats = doc.getResourceType().getFormats();
+            if (!Arrays.asList(formats).contains("luceneIndex")) {
+                getLogger().info("Document [" + doc
+                        + "] is not being indexed because resource type ["
+                        + doc.getResourceType().getName() + "] does not 
support indexing!");
+                return;
+            }
+            resolver = (SourceResolver) 
this.manager.lookup(SourceResolver.ROLE);
+            
+            String docString = 
+                doc.getPublication().getId() + "/" + doc.getArea() + 
doc.getId() + "/" + doc.getLanguage();
+            
+            source = 
resolver.resolveURI("cocoon://modules/lucene/index-document-index/" + docString 
+ ".xml");
+            SourceUtil.getInputSource(source);
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        } finally {
+            if (resolver != null) {
+                if (source != null) {
+                    resolver.release(source);
+                }
+                this.manager.release(resolver);
+            }
+        }
+    }
+
+    public void start() throws Exception {
+        ObservationRegistry registry = null;
+        try {
+            registry = (ObservationRegistry) 
this.manager.lookup(ObservationRegistry.ROLE);
+            registry.registerListener(this);
+        } finally {
+            if (registry != null) {
+                this.manager.release(registry);
+            }
+        }
+    }
+
+    public void stop() throws Exception {
+    }
+
+    private ServiceManager manager;
+
+    public void service(ServiceManager manager) throws ServiceException {
+        this.manager = manager;
+    }
+
+}

Modified: lenya/trunk/src/modules/lucene/sitemap.xmap
URL: 
http://svn.apache.org/viewvc/lenya/trunk/src/modules/lucene/sitemap.xmap?rev=426061&r1=426060&r2=426061&view=diff
==============================================================================
--- lenya/trunk/src/modules/lucene/sitemap.xmap (original)
+++ lenya/trunk/src/modules/lucene/sitemap.xmap Thu Jul 27 06:13:44 2006
@@ -86,13 +86,17 @@
 
         <map:serialize type="xml"/>
       </map:match>
-
-      <map:match pattern="search.xml">
+      
+      <map:match pattern="search/*/*.xml">
         <map:generate type="search">
-          <map:parameter name="index" 
value="{index-path:{page-envelope:publication-id}-{page-envelope:area}}"/>
+          <map:parameter name="index" value="{index-path:{1}-{2}}"/>
         </map:generate>
+        <map:serialize type="xml"/>
+      </map:match>
+
+      <map:match pattern="search.xml">
+        <map:generate 
src="cocoon:/search/{page-envelope:publication-id}/{page-envelope:area}.xml"/>
 
-        <!-- TODO: This needs to be generalized, otherwise it's working only 
for the default publication and it's derivatives -->
         <map:transform 
src="fallback://lenya/modules/lucene/xslt/search2html.xsl">
           <map:parameter name="url" value="{page-envelope:document-url}"/>
           <map:parameter name="area" value="{page-envelope:area}"/>
@@ -102,21 +106,22 @@
         </map:transform>
 
         <map:transform type="cinclude"/>
-
-<!--
-        <map:transform src="fallback://xslt/page2xhtml.xsl">
-          <map:parameter name="root" 
value="{base-url:{page-envelope:publication-id}:{page-envelope:area}}"/>
-          <map:parameter name="document-id" 
value="{page-envelope:document-id}"/>
-          <map:parameter name="document-type" value="homepage"/>
-          <map:parameter name="language" 
value="{page-envelope:document-language}"/>
-          <map:parameter name="url" value="{page-envelope:document-url}"/>
-        </map:transform>
--->
         <map:transform type="link-rewrite"/>
 
         <map:serialize type="xml"/>
       </map:match>
 
+      <!-- {index-operation}/{pub-id}/{area}{doc-id}/{language} -->
+      <map:match pattern="index-document-*/*/*/*/*.xml">
+        <map:generate 
src="{resource-type:{doc-info:{2}:{3}:/{4}:{5}:resourceType}:format-luceneIndex}/{2}/{3}/{4}/{5}"/>
+        <map:transform src="fallback://lenya/modules/lucene/xslt/index.xsl">
+          <map:parameter name="index" value="{2}-{3}"/>
+          <map:parameter name="id" 
value="{doc-info:{2}:{3}:/{4}:{5}:webappUrl}"/>
+        </map:transform>
+        <map:transform type="index2"/>
+        <map:serialize type="xml"/>
+      </map:match>
+      
       <map:match pattern="index-*.xml">
         <map:generate src="{resource-type:format-luceneIndex}"/>
         <map:transform src="fallback://lenya/modules/lucene/xslt/index.xsl">

Modified: 
lenya/trunk/src/modules/xhtml/config/cocoon-xconf/resource-type-xhtml.xconf
URL: 
http://svn.apache.org/viewvc/lenya/trunk/src/modules/xhtml/config/cocoon-xconf/resource-type-xhtml.xconf?rev=426061&r1=426060&r2=426061&view=diff
==============================================================================
--- lenya/trunk/src/modules/xhtml/config/cocoon-xconf/resource-type-xhtml.xconf 
(original)
+++ lenya/trunk/src/modules/xhtml/config/cocoon-xconf/resource-type-xhtml.xconf 
Thu Jul 27 06:13:44 2006
@@ -34,7 +34,7 @@
     <link-attribute xpath="//*[namespace-uri() = 
'http://www.w3.org/1999/xhtml']/@href"/>
     <format name="xhtml" uri="cocoon://modules/xhtml/xhtml.xml"/>
     <format name="webdavGET" uri="cocoon://modules/xhtml/davget.xml"/>
-    <format name="luceneIndex" uri="cocoon://modules/xhtml/lucene-index.xml"/>
+    <format name="luceneIndex" uri="cocoon://modules/xhtml/lucene-index"/>
   </component-instance>
   
 </xconf>

Modified: lenya/trunk/src/modules/xhtml/sitemap.xmap
URL: 
http://svn.apache.org/viewvc/lenya/trunk/src/modules/xhtml/sitemap.xmap?rev=426061&r1=426060&r2=426061&view=diff
==============================================================================
--- lenya/trunk/src/modules/xhtml/sitemap.xmap (original)
+++ lenya/trunk/src/modules/xhtml/sitemap.xmap Thu Jul 27 06:13:44 2006
@@ -38,18 +38,22 @@
     <!-- search pipeline -->
     <map:pipeline>
       
-      <map:match pattern="metadata.xml">
+      <!-- {pub-id}/{area}{doc-id}/{language} -->
+      <map:match pattern="metadata/*/*/*/*">
         <map:generate type="lenyaMetaData">
-          <map:parameter name="docid" value="{page-envelope:document-id}"/>
-          <map:parameter name="lang" 
value="{page-envelope:document-language}"/>
+          <map:parameter name="pubid" value="{1}"/>
+          <map:parameter name="area" value="{2}"/>
+          <map:parameter name="docid" value="/{3}"/>
+          <map:parameter name="lang" value="{4}"/>
         </map:generate>
         <map:serialize type="xml"/>
       </map:match>
       
-      <map:match pattern="lucene-index.xml">
+      <!-- {pub-id}/{area}{doc-id}/{language} -->
+      <map:match pattern="lucene-index/*/*/*/*">
         <map:aggregate element="cmsbody">
-          <map:part 
src="lenyadoc:/{page-envelope:document-language}/{page-envelope:document-id}"/>
-          <map:part src="cocoon:/metadata.xml"/>
+          <map:part src="lenyadoc://{1}/{2}/{4}//{3}"/>
+          <map:part src="cocoon:/metadata/{1}/{2}/{3}/{4}"/>
         </map:aggregate>
   
         <map:transform 
src="fallback://lenya/modules/xhtml/xslt/xhtml2index.xsl">

Modified: 
lenya/trunk/src/pubs/default/modules/homepage/config/cocoon-xconf/resource-type-homepage.xconf
URL: 
http://svn.apache.org/viewvc/lenya/trunk/src/pubs/default/modules/homepage/config/cocoon-xconf/resource-type-homepage.xconf?rev=426061&r1=426060&r2=426061&view=diff
==============================================================================
--- 
lenya/trunk/src/pubs/default/modules/homepage/config/cocoon-xconf/resource-type-homepage.xconf
 (original)
+++ 
lenya/trunk/src/pubs/default/modules/homepage/config/cocoon-xconf/resource-type-homepage.xconf
 Thu Jul 27 06:13:44 2006
@@ -26,7 +26,7 @@
     <sample-name>homepage.xml</sample-name>
     <link-attribute xpath="//*[namespace-uri() = 
'http://www.w3.org/1999/xhtml']/@href"/>
     <format name="xhtml" uri="cocoon://modules/homepage/xhtml.xml"/>
-    <format name="luceneIndex" uri="cocoon://modules/xhtml/lucene-index.xml"/>
+    <format name="luceneIndex" uri="cocoon://modules/xhtml/lucene-index"/>
     <format name="webdavGET" uri="cocoon://modules/xhtml/davget.xml"/>
   </component-instance>


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Recently Viewed:
qnx.openqnx.dev...    politics.lenini...    audio.emagic.ex...    tex.texinfo.gen...    handhelds.linux...    ietf.sipping/20...    lang.erlang.gen...    cygwin.talk/200...    yellowdog.gener...    mozilla.devel.l...    xfree86.newbie/...    openbsd.ports/2...    db.oracle.devel...    kde.kalyxo.deve...    user-groups.lin...    bbc.cvs/2003-04...    gnu.libtool.bug...    redhat.k12osn/2...    emulators.wine....    freebsd.devel.d...    search.xapian.g...    java.izpack.use...    network.mrtg.us...    windows.total-c...   
Home | blog view | USPTO Patent Archive | advertise | OSDir is an inevitable website. super tiny logo

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe