forrest-svn mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thors...@apache.org
Subject svn commit: r390856 - in /forrest/trunk/whiteboard/plugins/org.apache.forrest.plugin.internal.dispatcher: locationmap.xml src/java/org/apache/forrest/dispatcher/acting/ResourceTypeAction.java
Date Sun, 02 Apr 2006 16:54:43 GMT
Author: thorsten
Date: Sun Apr  2 09:54:42 2006
New Revision: 390856

URL: http://svn.apache.org/viewcvs?rev=390856&view=rev
Log:
FOR-843
The need for resource type specific based on meta data rather then sourcetypes occured in
DOCO. 
The new action looksup a meta data file and an element to determine which resource type the
request is based on.
It will then return the string value of the resource type to the sitemap again.

Added:
    forrest/trunk/whiteboard/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/acting/ResourceTypeAction.java
  (with props)
Modified:
    forrest/trunk/whiteboard/plugins/org.apache.forrest.plugin.internal.dispatcher/locationmap.xml

Modified: forrest/trunk/whiteboard/plugins/org.apache.forrest.plugin.internal.dispatcher/locationmap.xml
URL: http://svn.apache.org/viewcvs/forrest/trunk/whiteboard/plugins/org.apache.forrest.plugin.internal.dispatcher/locationmap.xml?rev=390856&r1=390855&r2=390856&view=diff
==============================================================================
--- forrest/trunk/whiteboard/plugins/org.apache.forrest.plugin.internal.dispatcher/locationmap.xml
(original)
+++ forrest/trunk/whiteboard/plugins/org.apache.forrest.plugin.internal.dispatcher/locationmap.xml
Sun Apr  2 09:54:42 2006
@@ -25,8 +25,8 @@
     <actions default="RecursiveDirectoryTraversalAction">
       <action name="RecursiveDirectoryTraversalAction" 
         src="org.apache.forrest.dispatcher.acting.RecursiveDirectoryTraversalAction"/>
-      <!--<action name="resourceTypeAction" 
-        src="org.apache.forrest.dispatcher.acting.ResourceTypeAction"/>-->
+      <action name="resourceTypeAction" 
+        src="org.apache.forrest.dispatcher.acting.ResourceTypeAction"/>
       <action logger="sitemap.action.sourcetype" name="sourcetype" src="org.apache.forrest.sourcetype.SourceTypeAction">
        <sourcetype name="document-v10">
          <document-declaration public-id="-//APACHE//DTD Documentation V1.0//EN" />
@@ -126,6 +126,16 @@
           http://forrest.apache.org/docs/cap.html-->
           <location src="lm://dispatcher.structurer.resourceType.{sourcetype}" 
             />
+        </act>
+        <act type="resourceTypeAction">
+          <parameter value="{1}" name="request"/>
+          <parameter value="{project:content.xdocs}" name="projectDir"/>
+          <parameter value="lm://dispatcher.structurer.resourceType." name="resourceTypeBase"/>
+          <parameter value=".xml.meta" name="metaExtension"/>
+          <parameter value="resourceType" name="resourceTypeElement"/>
+          <parameter value="http://apache.org/cocoon/lenya/page-envelope/1.0" name="resourceTypeElementNS"/>
+          <!--  Meta data based -->
+          <location src="{uri}" />
         </act>
         <act type="RecursiveDirectoryTraversalAction">
           <parameter value="{1}" name="request"/>

Added: forrest/trunk/whiteboard/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/acting/ResourceTypeAction.java
URL: http://svn.apache.org/viewcvs/forrest/trunk/whiteboard/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/acting/ResourceTypeAction.java?rev=390856&view=auto
==============================================================================
--- forrest/trunk/whiteboard/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/acting/ResourceTypeAction.java
(added)
+++ forrest/trunk/whiteboard/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/acting/ResourceTypeAction.java
Sun Apr  2 09:54:42 2006
@@ -0,0 +1,239 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation or its licensors,
+ * as applicable.
+ * 
+ * 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.forrest.dispatcher.acting;
+/**
+ * Looks up a meta data file to determine which resource type should be returned. 
+ */
+/**
+ * component declaration (lm and sitemap)
+ * &lt;action name="resourceTypeAction" 
+ *      src="org.apache.forrest.dispatcher.acting.ResourceTypeAction"/&gt;
+ *
+ *pipline usage lm
+*  &lt;act type="resourceTypeAction"&gt;
+*     &lt;parameter value="{1}" name="request"/&gt;
+*     &lt;parameter value="{project:content.xdocs}" name="projectDir"/&gt;
+*     &lt;parameter value="lm://dispatcher.structurer.resourceType." name="resourceTypeBase"/&gt;
+*     &lt;parameter value=".xml.meta" name="metaExtension"/&gt;
+*     &lt;parameter value="resourceType" name="resourceTypeElement"/&gt;
+*     &lt;parameter value="http://apache.org/cocoon/lenya/page-envelope/1.0" name="resourceTypeElementNS"/&gt;
+*     &lt;!--  Meta data based --&gt;
+*     &lt;location src="{uri}" /&gt;
+ * &lt;/act&gt;
+ */
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.avalon.framework.parameters.Parameters;
+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.acting.ServiceableAction;
+import org.apache.cocoon.environment.Redirector;
+import org.apache.excalibur.source.Source;
+import org.apache.excalibur.source.SourceResolver;
+import org.w3c.dom.Document;
+import org.w3c.dom.NodeList;
+
+
+public class ResourceTypeAction extends ServiceableAction
+        implements ThreadSafe, Serviceable {
+
+    SourceResolver resolver = null;
+    HashMap map = new HashMap();
+
+    private String request, metaExtension, resourceTypeElement,resourceTypeElementNS, projectDir,resourceTypeBase;
+            
+
+    /**
+     * Set the current &gt;code>ComponentManager</code> instance used by this
+     * <code>Composable</code>.
+     * 
+     * @throws ServiceException
+     */
+
+    public void service(ServiceManager manager) throws ServiceException {
+        this.resolver = (SourceResolver) manager.lookup(SourceResolver.ROLE);
+        this.manager=manager;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.cocoon.acting.Action#act(org.apache.cocoon.environment.Redirector,
+     *      org.apache.cocoon.environment.SourceResolver, java.util.Map,
+     *      java.lang.String, org.apache.avalon.framework.parameters.Parameters)
+     */
+    public Map act(Redirector redirector,
+            org.apache.cocoon.environment.SourceResolver resolver,
+            Map objectModel, String source, Parameters parameters)
+            throws Exception {
+        this.prepare(parameters, source);
+        String uri = this.getProjectDir() + this.getRequest()
+                + this.getMetaExtension();
+        Map returnMap = act(uri);
+        return returnMap;
+    }
+    
+    /** Return a Map if Source 'uri' resolves and exists. */
+    public Map act(String uri) {
+        Source src = null;
+        if (uri == null || uri == "") {
+            return null;
+        }
+
+        try {
+            this.computeResponseURI(uri, src);
+            if (this.map.containsKey("uri")) {
+                return this.map;
+            } else {
+                return null;
+            }
+        } catch (MalformedURLException e) {
+            getLogger().warn(
+                    "Selector URL '" + uri + "' is not a valid Source URL");
+            return null;
+        } catch (IOException e) {
+            getLogger().warn(
+                    "Error reading from source '" + uri + "': "
+                            + e.getMessage());
+            return null;
+        } catch (Exception e) {
+            getLogger().warn(
+                    "Error reading from source '" + uri + "': "
+                            + e.getMessage());
+            return null;
+        }finally {
+            resolver.release(src);
+        }
+    }
+       
+       private void computeResponseURI(String uri, Source src)
+            throws Exception {
+        src = resolver.resolveURI(uri);
+        if (src.exists()) {
+            Document rawData =  org.apache.forrest.dispatcher.util.SourceUtil.readDOM(
+                    uri, this.manager);
+            NodeList type = rawData.getElementsByTagNameNS(getResourceTypeElementNS(),getResourceTypeElement());
+            String typeString = type.item(0).getFirstChild().getNodeValue();
+            Source typeSource = resolver.resolveURI(resourceTypeBase+typeString);
+            if (typeSource.exists()) {
+                this.map.put("uri", typeSource.getURI());
+            }
+        }
+    }
+
+    public void prepare(Parameters parameters, String src) {
+        this.setRequest(parameters.getParameter("request", src));
+        this.setMetaExtension(parameters.getParameter("metaExtension",
+                src));
+        this.setResourceTypeElement(parameters.getParameter("resourceTypeElement",
+                src));
+        this.setProjectDir(parameters.getParameter("projectDir", src));
+        this.setResourceTypeElementNS(parameters.getParameter("resourceTypeElementNS",
+                src));
+        this.resourceTypeBase = parameters.getParameter("resourceTypeBase",
+                src);
+    }
+
+    /**
+     * @return Returns the projectDir.
+     */
+    public String getProjectDir() {
+        return projectDir;
+    }
+
+    /**
+     * @param projectDir
+     *            The projectDir to set.
+     */
+    public void setProjectDir(String projectDir) {
+        this.projectDir = projectDir;
+    }
+
+    /**
+     * @return Returns the resourceTypeElement.
+     */
+    public String getResourceTypeElement() {
+        return resourceTypeElement;
+    }
+
+    /**
+     * @param resourceTypeElement
+     *            The resourceTypeElement to set.
+     */
+    public void setResourceTypeElement(String resourceTypeElement) {
+        this.resourceTypeElement = resourceTypeElement;
+    }
+
+    /**
+     * @return Returns the metaExtension.
+     */
+    public String getMetaExtension() {
+        return metaExtension;
+    }
+
+    /**
+     * @param metaExtension
+     *            The metaExtension to set.
+     */
+    public void setMetaExtension(String metaExtension) {
+        this.metaExtension = metaExtension;
+    }
+
+    /**
+     * @return Returns the request.
+     */
+    public String getRequest() {
+        return request;
+    }
+
+    /**
+     * @param request
+     *            The request to set.
+     */
+    public void setRequest(String request) {
+        this.request = request;
+    }
+
+    /**
+     * @return Returns the resolver.
+     */
+    public SourceResolver getResolver() {
+        return resolver;
+    }
+
+    /**
+     * @param resolver
+     *            The resolver to set.
+     */
+    public void setResolver(SourceResolver resolver) {
+        this.resolver = resolver;
+    }
+
+    public String getResourceTypeElementNS() {
+        return resourceTypeElementNS;
+    }
+
+    public void setResourceTypeElementNS(String resourceTypeElementNS) {
+        this.resourceTypeElementNS = resourceTypeElementNS;
+    }
+
+}

Propchange: forrest/trunk/whiteboard/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/acting/ResourceTypeAction.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message