forrest-svn mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thors...@apache.org
Subject svn commit: r233401 - in /forrest/trunk: main/webapp/ main/webapp/WEB-INF/xconf/ site-author/ whiteboard/plugins/org.apache.forrest.plugin.internal.view/ whiteboard/plugins/org.apache.forrest.plugin.internal.view/resources/stylesheets/ whiteboard/plugi...
Date Fri, 19 Aug 2005 00:44:14 GMT
Author: thorsten
Date: Thu Aug 18 17:44:00 2005
New Revision: 233401

URL: http://svn.apache.org/viewcvs?rev=233401&view=rev
Log:
Refactored the view resolver code of the internal.view plugin. Created an action that is doing
the same as before the combination of sitemap+xsl. 
Added 2 java classes to package org.apache.forrest.plugin.internal.view.acting:
1.FallbackResolverAction.java
2.FallbackResolverHelper.java

Removed project.view-defaultView properties and added project.theme-extension instead. The
combination
of project.theme-extension and project.theme is equal to project.view-defaultView.

Added new elements to org.apache.forrest.conf.ForrestConfModule name="defaults":
view-themes
theme-ext
theme

Removed "defaultView" and added new element to org.apache.forrest.conf.ForrestConfModule name="project":
theme-ext

normalize-space() the forrest:properties before parsing them to the pipe

Added:
    forrest/trunk/whiteboard/plugins/org.apache.forrest.plugin.internal.view/src/java/
    forrest/trunk/whiteboard/plugins/org.apache.forrest.plugin.internal.view/src/java/org/
    forrest/trunk/whiteboard/plugins/org.apache.forrest.plugin.internal.view/src/java/org/apache/
    forrest/trunk/whiteboard/plugins/org.apache.forrest.plugin.internal.view/src/java/org/apache/forrest/
    forrest/trunk/whiteboard/plugins/org.apache.forrest.plugin.internal.view/src/java/org/apache/forrest/plugin/
    forrest/trunk/whiteboard/plugins/org.apache.forrest.plugin.internal.view/src/java/org/apache/forrest/plugin/internal/
    forrest/trunk/whiteboard/plugins/org.apache.forrest.plugin.internal.view/src/java/org/apache/forrest/plugin/internal/view/
    forrest/trunk/whiteboard/plugins/org.apache.forrest.plugin.internal.view/src/java/org/apache/forrest/plugin/internal/view/acting/
    forrest/trunk/whiteboard/plugins/org.apache.forrest.plugin.internal.view/src/java/org/apache/forrest/plugin/internal/view/acting/FallbackResolverAction.java
  (with props)
    forrest/trunk/whiteboard/plugins/org.apache.forrest.plugin.internal.view/src/java/org/apache/forrest/plugin/internal/view/acting/FallbackResolverHelper.java
  (with props)
Modified:
    forrest/trunk/main/webapp/WEB-INF/xconf/forrest-core.xconf
    forrest/trunk/main/webapp/default-forrest.properties
    forrest/trunk/site-author/status.xml
    forrest/trunk/whiteboard/plugins/org.apache.forrest.plugin.internal.view/internal.xmap
    forrest/trunk/whiteboard/plugins/org.apache.forrest.plugin.internal.view/resources/stylesheets/prepare.xhtml.xsl

Modified: forrest/trunk/main/webapp/WEB-INF/xconf/forrest-core.xconf
URL: http://svn.apache.org/viewcvs/forrest/trunk/main/webapp/WEB-INF/xconf/forrest-core.xconf?rev=233401&r1=233400&r2=233401&view=diff
==============================================================================
--- forrest/trunk/main/webapp/WEB-INF/xconf/forrest-core.xconf (original)
+++ forrest/trunk/main/webapp/WEB-INF/xconf/forrest-core.xconf Thu Aug 18 17:44:00 2005
@@ -131,12 +131,15 @@
         <plugins>@forrest.home@/build/plugins</plugins>
         <locationmap>@context.home@/locationmap.xml</locationmap>
         <view-internal>@forrest.home@/build/plugins/org.apache.forrest.plugin.internal.view</view-internal>
+        <view-themes>@forrest.home@/build/plugins/org.apache.forrest.plugin.internal.view/resources/views</view-themes>
+        <theme-ext>.fv</theme-ext>
+        <theme>default</theme>
       </values>
     </component-instance>
 
     <component-instance name="project" class="org.apache.forrest.conf.ForrestConfModule">
       <values>
-        <defaultView>@project.view-defaultView@</defaultView>
+        <theme-ext>@project.theme-extension@</theme-ext>
         <theme>@project.theme@</theme>
         <skin>@project.skin@</skin>
         <sitemap>@project.home@/@project.sitemap@</sitemap>

Modified: forrest/trunk/main/webapp/default-forrest.properties
URL: http://svn.apache.org/viewcvs/forrest/trunk/main/webapp/default-forrest.properties?rev=233401&r1=233400&r2=233401&view=diff
==============================================================================
--- forrest/trunk/main/webapp/default-forrest.properties (original)
+++ forrest/trunk/main/webapp/default-forrest.properties Thu Aug 18 17:44:00 2005
@@ -24,7 +24,7 @@
 project.name=my-project
 
 #views
-project.view-defaultView=default.fv
+project.theme-extension=.fv
 project.theme=default
 
 # Specifies name of Forrest skin to use

Modified: forrest/trunk/site-author/status.xml
URL: http://svn.apache.org/viewcvs/forrest/trunk/site-author/status.xml?rev=233401&r1=233400&r2=233401&view=diff
==============================================================================
--- forrest/trunk/site-author/status.xml (original)
+++ forrest/trunk/site-author/status.xml Thu Aug 18 17:44:00 2005
@@ -131,6 +131,32 @@
         <link href="site:v0.80//upgrading_08">upgrading to v0.8</link>
       </action>
 
+      <action context="code" type="add" dev="TS">
+        Refactored the view resolver code of the internal.view plugin. Created an action
that
+        is doing the same as before the combination of sitemap+xsl. <br/>Added 2 java
classes to package
+        org.apache.forrest.plugin.internal.view.acting:<br/>
+        1.FallbackResolverAction.java<br/>2.FallbackResolverHelper.java
+      </action>
+
+      <action context="code" type="add" dev="TS">
+       Removed project.view-defaultView properties and added project.theme-extension instead.
The combination
+       of project.theme-extension and project.theme is equal to project.view-defaultView.
+      </action>
+
+      <action context="code" type="add" dev="TS">
+       Added new elements to org.apache.forrest.conf.ForrestConfModule name="defaults":
+       <br/> view-themes<br/>theme-ext<br/>theme<br/>
+      </action>
+
+      <action context="code" type="add" dev="TS">
+       Removed "defaultView" and added new element to org.apache.forrest.conf.ForrestConfModule
name="project":
+       <br/>theme-ext
+      </action>
+
+      <action context="code" type="add" dev="TS">
+       normalize-space() the forrest:properties before parsing them to the pipe
+      </action>
+
       <action type="add" context="docs" fixes-bug="FOR-603"
         due-to="Addison Berry">
         Added document to explain the process for

Modified: forrest/trunk/whiteboard/plugins/org.apache.forrest.plugin.internal.view/internal.xmap
URL: http://svn.apache.org/viewcvs/forrest/trunk/whiteboard/plugins/org.apache.forrest.plugin.internal.view/internal.xmap?rev=233401&r1=233400&r2=233401&view=diff
==============================================================================
--- forrest/trunk/whiteboard/plugins/org.apache.forrest.plugin.internal.view/internal.xmap
(original)
+++ forrest/trunk/whiteboard/plugins/org.apache.forrest.plugin.internal.view/internal.xmap
Thu Aug 18 17:44:00 2005
@@ -70,6 +70,10 @@
 			   logger="sitemap.serializer.text" 
 			 />
     </map:serializers>
+    <map:actions>
+      <map:action name="fallbackResolverAction" 
+        src="org.apache.forrest.plugin.internal.view.acting.FallbackResolverAction"/>
+    </map:actions>
   </map:components>
 
 <map:pipelines>
@@ -87,6 +91,7 @@
   3. views
   prepares and transforms the requested contracts (viewHelper) and populate them with the
content (businessHelper).
   -->
+  <!--FIXME: We should refactor this pipeline when we want to use it-->
   <map:pipeline type="noncaching">
     <!--Refactor for dir-->
     <map:match pattern="viewLocationmap.xml">
@@ -107,30 +112,20 @@
     {1} - requested url
     -->
     <map:match pattern="prepare.view.**">
-      <map:generate src="cocoon:/viewLocationmap.xml"/>
-      <map:transform src="resources/stylesheets/viewLocationmap2path.xsl"/>
-      <map:select type="exists">
-      	<map:when test="resources/views/{project:defaultView}">
-		      <map:transform src="resources/stylesheets/includes-viewLocationmap.xsl">
-		        <map:parameter value="{project:defaultView}" name="defaultView"/>
-		        <map:parameter value="{1}" name="path"/>
-		        <map:parameter value="{project:content.xdocs}" name="root"/>
-		        <map:parameter value="resources/views/{project:defaultView}" name="viewFallback"/>
-		      </map:transform>
-        </map:when>
-        <map:otherwise>
-		      <map:transform src="resources/stylesheets/includes-viewLocationmap.xsl">
-		        <map:parameter value="{project:defaultView}" name="defaultView"/>
-		        <map:parameter value="{1}" name="path"/>
-		        <map:parameter value="{project:content.xdocs}" name="root"/>
-		        <map:parameter value="resources/views/default.fv" name="viewFallback"/>
-		      </map:transform>
-        </map:otherwise>
-      </map:select>
-      <map:transform type="xinclude"/>
-      <map:transform src="resources/stylesheets/prepare.include.templates.xsl"/>
-      <map:transform type="xinclude"/>
-    	<map:serialize type="xml"/>
+      <map:act type="fallbackResolverAction">
+        <map:parameter value="{1}" name="request"/>
+        <map:parameter value="{project:theme}" name="projectFallback"/>
+        <map:parameter value="{project:theme-ext}" name="projectExtension"/>
+        <map:parameter value="{project:content.xdocs}" name="projectDir"/>
+        <map:parameter value="{defaults:view-themes}" name="defaultDir"/>
+        <map:parameter value="{defaults:theme}" name="defaultFallback"/>
+        <map:parameter value="{defaults:theme-ext}" name="defaultExtension"/>
+      	
+        <map:generate src="file:/{uri}"/>
+        <map:transform src="resources/stylesheets/prepare.include.templates.xsl"/>
+        <map:transform type="xinclude"/>
+        <map:serialize type="xml"/>
+      </map:act>
     </map:match>
     
     <!--Add businessHelper to the presentation model that the content can be used later
on.

Modified: forrest/trunk/whiteboard/plugins/org.apache.forrest.plugin.internal.view/resources/stylesheets/prepare.xhtml.xsl
URL: http://svn.apache.org/viewcvs/forrest/trunk/whiteboard/plugins/org.apache.forrest.plugin.internal.view/resources/stylesheets/prepare.xhtml.xsl?rev=233401&r1=233400&r2=233401&view=diff
==============================================================================
--- forrest/trunk/whiteboard/plugins/org.apache.forrest.plugin.internal.view/resources/stylesheets/prepare.xhtml.xsl
(original)
+++ forrest/trunk/whiteboard/plugins/org.apache.forrest.plugin.internal.view/resources/stylesheets/prepare.xhtml.xsl
Thu Aug 18 17:44:00 2005
@@ -112,7 +112,7 @@
                 <xsl:when test="forrest:properties[@contract=$name]">
                     <alias:call-template name="{@name}-head">
                         <xsl:for-each select="forrest:properties[@contract=$name]/forrest:property">
-                            <alias:with-param name="{@name}" select="'{.}'"/>
+                            <alias:with-param name="{@name}" select="'{normalize-space(.)}'"/>
                         </xsl:for-each>
                     </alias:call-template>
                 </xsl:when>
@@ -132,7 +132,7 @@
                 <xsl:when test="forrest:properties[@contract=$name]">
                     <alias:call-template name="{@name}-body">
                         <xsl:for-each select="forrest:properties[@contract=$name]/forrest:property">
-                            <alias:with-param name="{@name}" select="'{.}'"/>
+                            <alias:with-param name="{@name}" select="'{normalize-space(.)}'"/>
                         </xsl:for-each>
                     </alias:call-template>
                 </xsl:when>

Added: forrest/trunk/whiteboard/plugins/org.apache.forrest.plugin.internal.view/src/java/org/apache/forrest/plugin/internal/view/acting/FallbackResolverAction.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/FallbackResolverAction.java?rev=233401&view=auto
==============================================================================
--- forrest/trunk/whiteboard/plugins/org.apache.forrest.plugin.internal.view/src/java/org/apache/forrest/plugin/internal/view/acting/FallbackResolverAction.java
(added)
+++ forrest/trunk/whiteboard/plugins/org.apache.forrest.plugin.internal.view/src/java/org/apache/forrest/plugin/internal/view/acting/FallbackResolverAction.java
Thu Aug 18 17:44:00 2005
@@ -0,0 +1,131 @@
+/*
+ * 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.forrest.plugin.internal.view.acting;
+
+import org.apache.avalon.framework.parameters.Parameters;
+import org.apache.avalon.framework.thread.ThreadSafe;
+import org.apache.cocoon.acting.ServiceableAction;
+import org.apache.cocoon.environment.Redirector;
+import org.apache.cocoon.environment.SourceResolver;
+import org.apache.excalibur.source.Source;
+import org.apache.excalibur.source.SourceNotFoundException;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * This action simply checks to see if a resource identified by the <code>src</code>
+ * sitemap attribute exists or not. The action returns empty <code>Map</code>
if
+ * resource exists, <code>null</code> otherwise.
+ * 
+ * <p>Instead of src attribute, source can be specified using
+ * parameter named <code>url</code> (this is old syntax, should be removed soon).
+ * 
+ * <p><b>NOTE:</b> {@link org.apache.cocoon.selection.ResourceExistsSelector}
+ * should be preferred to this component, as the semantics of a Selector better
+ * matches the supplied functionality.
+ *
+ * @author <a href="mailto:balld@apache.org">Donald Ball</a>
+ * @version CVS $Id$
+ */
+
+public class FallbackResolverAction extends ServiceableAction implements
+        ThreadSafe {
+    private FallbackResolverHelper fallbackHelper = new FallbackResolverHelper();
+
+    public Map act(Redirector redirector, SourceResolver resolver,
+            Map objectModel, String src, Parameters parameters)
+            throws Exception {
+        this.prepare(parameters, src);
+        String uri = fallbackHelper.getProjectDir() + fallbackHelper.getRequest()
+                + fallbackHelper.getProjectExtension();
+        computeResponseURI(resolver, uri);
+        if (fallbackHelper.getResponseURI()==null){
+            uri = fallbackHelper.getDefaultDir()+"/"
+                +fallbackHelper.getProjectFallback()
+                +fallbackHelper.getDefaultExtension();
+            if (this.resourceExist(resolver, uri)) {
+                fallbackHelper.setResponseURI(uri);
+            }else{
+                fallbackHelper.setResponseURI(fallbackHelper.getDefaultDir()+"/"
+                        +fallbackHelper.getDefaultFallback()
+                        +fallbackHelper.getDefaultExtension());
+            }
+        }
+        HashMap map = new HashMap();
+        map.put("uri", fallbackHelper.getResponseURI());
+        return map;
+    }
+
+    public void prepare(Parameters parameters, String src) {
+        fallbackHelper.setRequest(parameters.getParameter("request", src));
+        fallbackHelper.setProjectFallback(parameters.getParameter(
+                "projectFallback", src));
+        fallbackHelper.setProjectExtension(parameters.getParameter(
+                "projectExtension", src));
+        fallbackHelper
+                .setProjectDir(parameters.getParameter("projectDir", src));
+        fallbackHelper.setDefaultFallback(parameters.getParameter(
+                "defaultFallback", src));
+        fallbackHelper.setDefaultExtension(parameters.getParameter(
+                "defaultExtension", src));
+        fallbackHelper.setDefaultDir(parameters.getParameter(
+                "defaultDir", src));
+        fallbackHelper.setRest(fallbackHelper.getRequest());
+        fallbackHelper.setResponseURI(null);
+    }
+
+    public void computeResponseURI(SourceResolver resolver, String uri) {
+        if (this.resourceExist(resolver, uri)) {
+            fallbackHelper.setResponseURI(uri);
+        } else {
+            if (fallbackHelper.getRest().lastIndexOf("/") > -1) {
+                fallbackHelper.setRest(fallbackHelper.getRest().substring(0,
+                        fallbackHelper.getRest().lastIndexOf("/")));
+                uri = fallbackHelper.getProjectDir() + fallbackHelper.getRest()
+                        + "/" + fallbackHelper.getProjectFallback()
+                        + fallbackHelper.getProjectExtension();
+                this.computeResponseURI(resolver,uri);
+            }else{
+                uri = fallbackHelper.getProjectDir()
+                    +fallbackHelper.getProjectFallback()
+                    +fallbackHelper.getProjectExtension();
+                if (this.resourceExist(resolver, uri)) {
+                    fallbackHelper.setResponseURI(uri);
+                }
+            }
+        }
+    }
+
+    public boolean resourceExist(SourceResolver resolver, String uri) {
+        Source source = null;
+        try {
+            source = resolver.resolveURI(uri);
+            if (source.exists()) {
+                return true;
+            }
+        } catch (SourceNotFoundException e) {
+            // Do not log
+        } catch (Exception e) {
+            getLogger().warn("Exception resolving resource " + uri, e);
+        } finally {
+            if (source != null) {
+                resolver.release(source);
+            }
+        }
+        return false;
+    }
+}

Propchange: forrest/trunk/whiteboard/plugins/org.apache.forrest.plugin.internal.view/src/java/org/apache/forrest/plugin/internal/view/acting/FallbackResolverAction.java
------------------------------------------------------------------------------
    svn:keywords = Id svn:eol-style=native

Added: forrest/trunk/whiteboard/plugins/org.apache.forrest.plugin.internal.view/src/java/org/apache/forrest/plugin/internal/view/acting/FallbackResolverHelper.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/FallbackResolverHelper.java?rev=233401&view=auto
==============================================================================
--- forrest/trunk/whiteboard/plugins/org.apache.forrest.plugin.internal.view/src/java/org/apache/forrest/plugin/internal/view/acting/FallbackResolverHelper.java
(added)
+++ forrest/trunk/whiteboard/plugins/org.apache.forrest.plugin.internal.view/src/java/org/apache/forrest/plugin/internal/view/acting/FallbackResolverHelper.java
Thu Aug 18 17:44:00 2005
@@ -0,0 +1,139 @@
+/*
+ * 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.forrest.plugin.internal.view.acting;
+
+/**
+ *  <map:parameter value="{1}" name="request"/><br/>
+ *  <map:parameter value="{project:theme}" name="projectFallback"/><br/>
+ *  <map:parameter value="{project:theme-ext}" name="projectExtension"/><br/>
+ *  <map:parameter value="{project:content.xdocs}" name="projectDir"/><br/>
+ *  <map:parameter value="{defaults:view-themes}" name="defaultDir"/><br/>
+ *  <map:parameter value="{defaults:theme}" name="defaultFallback"/><br/>
+ *  <map:parameter value="{defaults:theme-ext}" name="defaultExtension"/>
+ *
+ */
+public class FallbackResolverHelper {
+    private String request, projectFallback, projectExtension, projectDir,
+            defaultFallback, defaultExtension, defaultDir, rest,responseURI;
+    /**
+     * @return Returns the defaultExtension.
+     */
+    public String getDefaultExtension() {
+        return defaultExtension;
+    }
+    /**
+     * @param defaultExtension The defaultExtension to set.
+     */
+    public void setDefaultExtension(String defaultExtension) {
+        this.defaultExtension = defaultExtension;
+    }
+    /**
+     * @return Returns the defaultFallback.
+     */
+    public String getDefaultFallback() {
+        return defaultFallback;
+    }
+    /**
+     * @param defaultFallback The defaultFallback to set.
+     */
+    public void setDefaultFallback(String defaultFallback) {
+        this.defaultFallback = defaultFallback;
+    }
+    /**
+     * @return Returns the request.
+     */
+    public String getRequest() {
+        return request;
+    }
+    /**
+     * @param request The request to set.
+     */
+    public void setRequest(String path) {
+        this.request = path;
+    }
+    /**
+     * @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 rest.
+     */
+    public String getRest() {
+        return rest;
+    }
+    /**
+     * @param rest The rest to set.
+     */
+    public void setRest(String rest) {
+        this.rest = rest;
+    }
+    /**
+     * @return Returns the responseURI.
+     */
+    public String getResponseURI() {
+        return responseURI;
+    }
+    /**
+     * @param responseURI The responseURI to set.
+     */
+    public void setResponseURI(String responseURI) {
+        this.responseURI = responseURI;
+    }
+    /**
+     * @return Returns the defaultDir.
+     */
+    public String getDefaultDir() {
+        return defaultDir;
+    }
+    /**
+     * @param defaultDir The defaultDir to set.
+     */
+    public void setDefaultDir(String defaultDir) {
+        this.defaultDir = defaultDir;
+    }
+}

Propchange: forrest/trunk/whiteboard/plugins/org.apache.forrest.plugin.internal.view/src/java/org/apache/forrest/plugin/internal/view/acting/FallbackResolverHelper.java
------------------------------------------------------------------------------
    svn:keywords = Id svn:eol-style=native



Mime
View raw message