Return-Path: Delivered-To: apmail-forrest-svn-archive@www.apache.org Received: (qmail 36292 invoked from network); 28 Aug 2005 03:19:11 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 28 Aug 2005 03:19:11 -0000 Received: (qmail 60987 invoked by uid 500); 28 Aug 2005 03:19:10 -0000 Delivered-To: apmail-forrest-svn-archive@forrest.apache.org Received: (qmail 60946 invoked by uid 500); 28 Aug 2005 03:19:10 -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 60933 invoked by uid 99); 28 Aug 2005 03:19:10 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 27 Aug 2005 20:19:10 -0700 X-ASF-Spam-Status: No, hits=-9.8 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; Sat, 27 Aug 2005 20:19:27 -0700 Received: (qmail 36256 invoked by uid 65534); 28 Aug 2005 03:19:09 -0000 Message-ID: <20050828031909.36255.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r263802 - /forrest/trunk/whiteboard/plugins/org.apache.forrest.plugin.internal.view/src/java/org/apache/forrest/plugin/internal/view/acting/RecursiveDirectoryTraversalAction.java Date: Sun, 28 Aug 2005 03:19:09 -0000 To: svn@forrest.apache.org From: thorsten@apache.org X-Mailer: svnmailer-1.0.4 X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: thorsten Date: Sat Aug 27 20:19:04 2005 New Revision: 263802 URL: http://svn.apache.org/viewcvs?rev=263802&view=rev Log: Added a more specific action for resolving recursive fallbacks Added: forrest/trunk/whiteboard/plugins/org.apache.forrest.plugin.internal.view/src/java/org/apache/forrest/plugin/internal/view/acting/RecursiveDirectoryTraversalAction.java (with props) Added: forrest/trunk/whiteboard/plugins/org.apache.forrest.plugin.internal.view/src/java/org/apache/forrest/plugin/internal/view/acting/RecursiveDirectoryTraversalAction.java URL: http://svn.apache.org/viewcvs/forrest/trunk/whiteboard/plugins/org.apache.forrest.plugin.internal.view/src/java/org/apache/forrest/plugin/internal/view/acting/RecursiveDirectoryTraversalAction.java?rev=263802&view=auto ============================================================================== --- forrest/trunk/whiteboard/plugins/org.apache.forrest.plugin.internal.view/src/java/org/apache/forrest/plugin/internal/view/acting/RecursiveDirectoryTraversalAction.java (added) +++ forrest/trunk/whiteboard/plugins/org.apache.forrest.plugin.internal.view/src/java/org/apache/forrest/plugin/internal/view/acting/RecursiveDirectoryTraversalAction.java Sat Aug 27 20:19:04 2005 @@ -0,0 +1,288 @@ +/* + * 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.plugin.internal.view.acting; + +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; + +/** + * Selects the first of a set of Sources that exists in the context. + *

+ * For example, we could define a SourceExistsSelector with: + * + *

+ * 
+ *  <map:selector name="exists"
+ *                logger="sitemap.selector.source-exists"
+ *                src="org.apache.cocoon.selection.SourceExistsSelector" />
+ *  
+ * 
+ * + * And use it to build a PDF from XSL:FO or a higher-level XML format with: + * + *
+ * 
+ *   <map:match pattern="**.pdf">
+ *     <map:select type="exists">
+ *        <map:when test="context/xdocs/{1}.fo">
+ *           <map:generate src="content/xdocs/{1}.fo" />
+ *        </map:when>
+ *        <map:otherwise>
+ *          <map:generate src="content/xdocs/{1}.xml" />
+ *          <map:transform src="stylesheets/document2fo.xsl" />
+ *        </map:otherwise>
+ *     </map:select>
+ *     <map:serialize type="fo2pdf" />
+ *  
+ * 
+ */ +public class RecursiveDirectoryTraversalAction extends ServiceableAction + implements ThreadSafe, Serviceable { + + SourceResolver resolver = null; + HashMap map = new HashMap(); + + private String request, projectFallback, projectExtension, projectDir, + rest; + + /** + * Set the current ComponentManager instance used by this + * Composable. + * + * @throws ServiceException + */ + + public void service(ServiceManager manager) throws ServiceException { + this.resolver = (SourceResolver) manager.lookup(SourceResolver.ROLE); + } + + /* + * (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.getProjectExtension(); + Map returnMap = act(uri); + return returnMap; + } + + /** Return a Map if Source 'uri' resolves and exists. */ + public Map act(String uri) { + Source src = null; + + // The locationmap module will return null if there is no match for + // the supplied hint, without the following the URI will be resolved to + // the context root, which always exists, but does not contain a valid + // resource. + if (uri == null || uri == "") { + return null; + } + + try { + this.computeResponseURI(uri, src); + //src = resolver.resolveURI(uri); + 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; + } finally { + resolver.release(src); + } + } + + /** + * @param resolver + * @param uri + * *viewSelector* project-xdocs will return which view is + * responsible for the requested path. If no view + * (choice|fallback) could be found the template will return the + * viewFallback (resources/views/default.fv). + * + * ex.: 1.request: index First choice: index.fv First/last fallback: + * default.fv + * + * 2.request: sample/index First choice: sample/index.fv First fallback: + * sample/default.fv Last fallback: default.fv + * + * 3.request: sample/subdir/index First choice: sample/subdir/index.fv First + * fallback: sample/subdir/default.fv Second fallback: sample/default.fv + * Last fallback: default.fv + * + * ... + * + * des.: The parent view (root-view) inherits to its children until a child + * is overriding this view. This override can be used for directories + * (default.fv) and/or files (*.fv). That means that the root view is the + * default view as long no other view can be found in the requested child. + * @throws IOException + * @throws MalformedURLException + * + */ + private void computeResponseURI(String uri, Source src) + throws MalformedURLException, IOException { + src = resolver.resolveURI(uri); + if (src.exists()) { + this.map.put("uri", uri); + } else { + if (this.getRest().lastIndexOf("/") > -1) { + this.setRest(this.getRest().substring(0, + this.getRest().lastIndexOf("/"))); + uri = this.getProjectDir() + this.getRest() + "/" + + this.getProjectFallback() + + this.getProjectExtension(); + this.computeResponseURI(uri, src); + } else { + uri = this.getProjectDir() + this.getProjectFallback() + + this.getProjectExtension(); + src = resolver.resolveURI(uri); + if (src.exists()) { + this.map.put("uri", uri); + } + } + } + } + + public void prepare(Parameters parameters, String src) { + this.setRequest(parameters.getParameter("request", src)); + this.setProjectFallback(parameters.getParameter("projectFallback", + src)); + this.setProjectExtension(parameters.getParameter("projectExtension", + src)); + this.setProjectDir(parameters.getParameter("projectDir", src)); + this.setRest(this.getRequest()); + } + + /** + * @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 projectExtension. + */ + public String getProjectExtension() { + return projectExtension; + } + + /** + * @param projectExtension + * The projectExtension to set. + */ + public void setProjectExtension(String projectExtension) { + this.projectExtension = projectExtension; + } + + /** + * @return Returns the projectFallback. + */ + public String getProjectFallback() { + return projectFallback; + } + + /** + * @param projectFallback + * The projectFallback to set. + */ + public void setProjectFallback(String projectFallback) { + this.projectFallback = projectFallback; + } + + /** + * @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; + } + + /** + * @return Returns the rest. + */ + public String getRest() { + return rest; + } + + /** + * @param rest + * The rest to set. + */ + public void setRest(String rest) { + this.rest = rest; + } +} Propchange: forrest/trunk/whiteboard/plugins/org.apache.forrest.plugin.internal.view/src/java/org/apache/forrest/plugin/internal/view/acting/RecursiveDirectoryTraversalAction.java ------------------------------------------------------------------------------ svn:eol-style = native