Return-Path: Delivered-To: apmail-forrest-svn-archive@www.apache.org Received: (qmail 61288 invoked from network); 2 Apr 2006 16:55:06 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 2 Apr 2006 16:55:06 -0000 Received: (qmail 88135 invoked by uid 500); 2 Apr 2006 16:55:05 -0000 Delivered-To: apmail-forrest-svn-archive@forrest.apache.org Received: (qmail 88104 invoked by uid 500); 2 Apr 2006 16:55:05 -0000 Mailing-List: contact svn-help@forrest.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: "Forrest Developers List" List-Id: Delivered-To: mailing list svn@forrest.apache.org Received: (qmail 88093 invoked by uid 99); 2 Apr 2006 16:55:05 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 02 Apr 2006 09:55:05 -0700 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.29) with SMTP; Sun, 02 Apr 2006 09:55:04 -0700 Received: (qmail 61229 invoked by uid 65534); 2 Apr 2006 16:54:44 -0000 Message-ID: <20060402165444.61228.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: svn@forrest.apache.org From: thorsten@apache.org X-Mailer: svnmailer-1.0.7 X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N 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 @@ - + @@ -126,6 +126,16 @@ http://forrest.apache.org/docs/cap.html--> + + + + + + + + + + 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) + * <action name="resourceTypeAction" + * src="org.apache.forrest.dispatcher.acting.ResourceTypeAction"/> + * + *pipline usage lm +* <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> + */ +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 >code>ComponentManager instance used by this + * Composable. + * + * @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