You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by cz...@apache.org on 2006/10/01 19:00:01 UTC

svn commit: r451769 - in /cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon: components/treeprocessor/sitemap/ core/container/spring/

Author: cziegeler
Date: Sun Oct  1 10:00:00 2006
New Revision: 451769

URL: http://svn.apache.org/viewvc?view=rev&rev=451769
Log:
Start adding support for flow default location

Modified:
    cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/FlowNode.java
    cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/FlowNodeBuilder.java
    cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/ScriptNode.java
    cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/ScriptNodeBuilder.java
    cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/Container.java

Modified: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/FlowNode.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/FlowNode.java?view=diff&rev=451769&r1=451768&r2=451769
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/FlowNode.java (original)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/FlowNode.java Sun Oct  1 10:00:00 2006
@@ -19,7 +19,6 @@
 import org.apache.avalon.framework.activity.Disposable;
 import org.apache.avalon.framework.service.ServiceException;
 import org.apache.avalon.framework.service.ServiceManager;
-import org.apache.avalon.framework.service.ServiceSelector;
 import org.apache.avalon.framework.service.Serviceable;
 
 import org.apache.cocoon.components.flow.Interpreter;
@@ -36,10 +35,9 @@
 public class FlowNode extends AbstractProcessingNode
                       implements Serviceable, Disposable {
 
+    private final String language;
     private ServiceManager manager;
-    private String language;
     private Interpreter interpreter;
-    private ServiceSelector interpreterSelector;
 
     public FlowNode(String language) {
         this.language = language;
@@ -53,13 +51,12 @@
      * @param manager a <code>ServiceManager</code> value
      * @exception ServiceException if no flow interpreter could be obtained
      */
-    public void service(ServiceManager manager) throws ServiceException {
-        this.manager = manager;
+    public void service(ServiceManager aManager) throws ServiceException {
+        this.manager = aManager;
 
         try {
-            this.interpreterSelector = (ServiceSelector) manager.lookup(Interpreter.ROLE + "Selector");
             // Obtain the Interpreter instance for this language
-            this.interpreter = (Interpreter) this.interpreterSelector.select(language);
+            this.interpreter = (Interpreter) this.manager.lookup(Interpreter.ROLE + '/' + language);
             // Set interpreter ID as URI of the flow node (full sitemap file path)
             this.interpreter.setInterpreterID(this.location.getURI());
         } catch (ServiceException e) {
@@ -89,18 +86,13 @@
         return interpreter;
     }
 
-    /* (non-Javadoc)
+    /**
      * @see org.apache.avalon.framework.activity.Disposable#dispose()
      */
     public void dispose() {
         if (this.manager != null) {
-            if (this.interpreterSelector != null) {
-                this.interpreterSelector.release(this.interpreter);
-                this.interpreter = null;
-
-                this.manager.release(this.interpreterSelector);
-                this.interpreterSelector = null;
-            }
+            this.manager.release(this.interpreter);
+            this.interpreter = null;
             this.manager = null;
         }
     }

Modified: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/FlowNodeBuilder.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/FlowNodeBuilder.java?view=diff&rev=451769&r1=451768&r2=451769
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/FlowNodeBuilder.java (original)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/FlowNodeBuilder.java Sun Oct  1 10:00:00 2006
@@ -18,8 +18,11 @@
 
 import org.apache.avalon.framework.configuration.Configuration;
 import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.cocoon.components.flow.AbstractInterpreter;
 import org.apache.cocoon.components.treeprocessor.AbstractParentProcessingNodeBuilder;
 import org.apache.cocoon.components.treeprocessor.ProcessingNode;
+import org.springframework.core.io.Resource;
+import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
 
 /**
  * Builder of a {@link FlowNode} instance, corresponding to a
@@ -30,10 +33,15 @@
  */
 public class FlowNodeBuilder extends AbstractParentProcessingNodeBuilder {
 
+    protected static String DEFAULT_FLOW_SCRIPT_LOCATION = "flow";
+
+    /**
+     * @see org.apache.cocoon.components.treeprocessor.ProcessingNodeBuilder#buildNode(org.apache.avalon.framework.configuration.Configuration)
+     */
     public ProcessingNode buildNode(Configuration config)
     throws Exception {
-        String language = config.getAttribute("language", "javascript");
-        FlowNode node = new FlowNode(language);
+        final String language = config.getAttribute("language", "javascript");
+        final FlowNode node = new FlowNode(language);
 
         if ( !this.treeBuilder.registerNode("flow", node) ) {
             throw new ConfigurationException("Only one <map:flow> is allowed in a sitemap. Another one is declared at " +
@@ -41,6 +49,23 @@
         }
         this.treeBuilder.setupNode(node, config);
 
+        // since 2.2 we add by default all flow scripts located in the ./flow directory
+        // The default location can be overwritten by specifying the location attribute.
+        // we only include the scripts if the language is javascript
+        /*
+        if ( "javascript".equals(language) && node.getInterpreter() instanceof AbstractInterpreter ) {
+            // FIXME we need the resource loader
+            final String scriptLocation = config.getAttribute("location", DEFAULT_FLOW_SCRIPT_LOCATION);
+            PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
+            final Resource[] resources = resolver.getResources(scriptLocation + "/*.js");
+            if ( resources != null ) {
+                for(int i=0; i < resources.length; i++) {
+                    ((AbstractInterpreter)node.getInterpreter()).register(resources[i].getURL().toExternalForm());
+                }
+            }
+        }
+        */
+        // now process child nodes
         buildChildNodesList(config);
 
         return node;

Modified: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/ScriptNode.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/ScriptNode.java?view=diff&rev=451769&r1=451768&r2=451769
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/ScriptNode.java (original)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/ScriptNode.java Sun Oct  1 10:00:00 2006
@@ -28,34 +28,32 @@
  * @since March 13, 2002
  * @version $Id$
  */
-public class ScriptNode extends AbstractProcessingNode
-{
-  String source;
+public class ScriptNode extends AbstractProcessingNode {
 
-  public ScriptNode(String source)
-  {
-    this.source = source;
-  }
+    protected final String source;
+
+    public ScriptNode(String source) {
+        this.source = source;
+    }
   
-  /**
-   * This method should never be called by the TreeProcessor, since a
-   * <map:script> element should not be in an "executable" sitemap
-   * node.
-   *
-   * @param env an <code>Environment</code> value
-   * @param context an <code>InvokeContext</code> value
-   * @return a <code>boolean</code> value
-   * @exception Exception if an error occurs
-   */
-  public boolean invoke(Environment env, InvokeContext context)
-    throws Exception
-  {
-    return true;
-  }
+    /**
+     * This method should never be called by the TreeProcessor, since a
+     * <map:script> element should not be in an "executable" sitemap
+     * node.
+     *
+     * @param env an <code>Environment</code> value
+     * @param context an <code>InvokeContext</code> value
+     * @return a <code>boolean</code> value
+     * @exception Exception if an error occurs
+     */
+    public boolean invoke(Environment env, InvokeContext context)
+    throws Exception {
+        return true;
+    }
 
-  public void registerScriptWithInterpreter(Interpreter interpreter)
-  {
-    if (interpreter instanceof AbstractInterpreter)
-      ((AbstractInterpreter)interpreter).register(source);
-  }
+    public void registerScriptWithInterpreter(Interpreter interpreter) {
+        if (interpreter instanceof AbstractInterpreter) {
+            ((AbstractInterpreter)interpreter).register(this.source);
+        }
+    }
 }

Modified: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/ScriptNodeBuilder.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/ScriptNodeBuilder.java?view=diff&rev=451769&r1=451768&r2=451769
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/ScriptNodeBuilder.java (original)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/ScriptNodeBuilder.java Sun Oct  1 10:00:00 2006
@@ -30,32 +30,30 @@
  * @version $Id$
  */
 public class ScriptNodeBuilder
-  extends AbstractProcessingNodeBuilder
-  implements LinkedProcessingNodeBuilder
-{
-  protected ScriptNode node;
-
-  public ProcessingNode buildNode(Configuration config)
-    throws Exception
-  {
-    String source = config.getAttribute("src");
-
-    this.node = new ScriptNode(source);
-    this.treeBuilder.setupNode(this.node, config);
-
-    return this.node;
-  }
-
-  /**
-   * Call the built node to register the script it contains with the
-   * flow interpreter.
-   */
-  public void linkNode()
-    throws Exception
-  {
-    FlowNode flowNode = (FlowNode)this.treeBuilder.getRegisteredNode("flow");
-    Interpreter interpreter = flowNode.getInterpreter();
+    extends AbstractProcessingNodeBuilder
+    implements LinkedProcessingNodeBuilder {
 
-    this.node.registerScriptWithInterpreter(interpreter);
-  }
+    protected ScriptNode node;
+
+    public ProcessingNode buildNode(Configuration config)
+    throws Exception {
+        String source = config.getAttribute("src");
+
+        this.node = new ScriptNode(source);
+        this.treeBuilder.setupNode(this.node, config);
+
+        return this.node;
+    }
+
+    /**
+     * Call the built node to register the script it contains with the
+     * flow interpreter.
+     */
+    public void linkNode()
+    throws Exception {
+        FlowNode flowNode = (FlowNode)this.treeBuilder.getRegisteredNode("flow");
+        Interpreter interpreter = flowNode.getInterpreter();
+
+        this.node.registerScriptWithInterpreter(interpreter);
+    }
 }

Modified: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/Container.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/Container.java?view=diff&rev=451769&r1=451768&r2=451769
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/Container.java (original)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/Container.java Sun Oct  1 10:00:00 2006
@@ -29,7 +29,7 @@
 import org.springframework.web.context.support.WebApplicationContextUtils;
 
 /**
- * 
+ * FIXME - What about the ResourceLoader?
  * @version $Id$
  */
 public class Container {