forrest-svn mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thors...@apache.org
Subject svn commit: r263492 - in /forrest/trunk/main/java/org/apache/forrest/locationmap/lm: ActNode.java LocationMap.java LocatorNode.java MatchNode.java SelectNode.java
Date Sun, 28 Aug 2005 03:09:33 GMT
Author: thorsten
Date: Sat Aug 27 20:09:25 2005
New Revision: 263492

URL: http://svn.apache.org/viewcvs?rev=263492&view=rev
Log:
Added support for actions in the locationmap.

Added:
    forrest/trunk/main/java/org/apache/forrest/locationmap/lm/ActNode.java   (with props)
Modified:
    forrest/trunk/main/java/org/apache/forrest/locationmap/lm/LocationMap.java
    forrest/trunk/main/java/org/apache/forrest/locationmap/lm/LocatorNode.java
    forrest/trunk/main/java/org/apache/forrest/locationmap/lm/MatchNode.java
    forrest/trunk/main/java/org/apache/forrest/locationmap/lm/SelectNode.java

Added: forrest/trunk/main/java/org/apache/forrest/locationmap/lm/ActNode.java
URL: http://svn.apache.org/viewcvs/forrest/trunk/main/java/org/apache/forrest/locationmap/lm/ActNode.java?rev=263492&view=auto
==============================================================================
--- forrest/trunk/main/java/org/apache/forrest/locationmap/lm/ActNode.java (added)
+++ forrest/trunk/main/java/org/apache/forrest/locationmap/lm/ActNode.java Sat Aug 27 20:09:25
2005
@@ -0,0 +1,146 @@
+/*
+ * 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.locationmap.lm;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+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.ServiceSelector;
+import org.apache.cocoon.acting.Action;
+import org.apache.cocoon.components.treeprocessor.InvokeContext;
+import org.apache.cocoon.environment.Redirector;
+import org.apache.cocoon.selection.Selector;
+import org.apache.cocoon.environment.SourceResolver;
+
+
+/**
+ * Locationmap select statement.
+ */
+public final class ActNode extends AbstractNode {
+    
+    // the containing LocatorNode
+    private final LocatorNode m_ln;
+    
+    // the action that does the work
+    private Action m_action;
+    
+    // the type of action for this node
+    private String m_type;
+    
+    // the locations to test against
+    private AbstractNode[] m_nodes;
+
+    private SourceResolver resolver;
+    
+    
+    public ActNode(LocatorNode ln, ServiceManager manager) {
+        super(manager);
+        m_ln = ln;
+    }
+    
+    public void build(Configuration configuration) throws ConfigurationException {
+        
+        super.build(configuration);
+        
+        // get the selector
+        m_type = configuration.getAttribute("type",m_ln.getDefaultAction());
+        try {
+            final ServiceSelector selectors = (ServiceSelector) super.m_manager.lookup(Selector.ROLE
+ "Selector");
+            m_action = (Action) selectors.select(m_type);
+        } catch (ServiceException e) {
+            final String message = "Unable to get Selector of type " + m_type;
+            throw new ConfigurationException(message,e);
+        }
+        
+        // build the child nodes
+        final Configuration[] children = configuration.getChildren();
+        final List nodes = new ArrayList(children.length);
+        for (int i = 0; i < children.length; i++) {
+            AbstractNode node = null;
+            String name = children[i].getName();
+            if (name.equals("location")) {
+                node = new LocationNode(m_ln, super.m_manager);
+            } 
+            else if (name.equals("match")) {
+                node = new MatchNode(m_ln, super.m_manager);
+            }
+            else if (name.equals("select")) {
+                node = new SelectNode(m_ln, super.m_manager);
+            }
+            else if (name.equals("act")) {
+                node = new ActNode(m_ln, super.m_manager);
+            }
+            else if (!name.equals("parameter")) {
+                final String message = "Unknown select node child:" + name;
+                throw new ConfigurationException(message);
+            }
+            if (node != null) {
+                node.enableLogging(getLogger());
+                node.build(children[i]);
+                nodes.add(node);
+            }
+        }
+        m_nodes = (AbstractNode[]) nodes.toArray(new AbstractNode[nodes.size()]);
+    }
+    public void service(ServiceManager manager) throws ServiceException {
+        this.resolver = (SourceResolver) manager.lookup(SourceResolver.ROLE);
+    }
+    /* (non-Javadoc)
+     * @see org.apache.forrest.locationmap.lm.AbstractNode#locate(java.util.Map, org.apache.cocoon.components.treeprocessor.InvokeContext)
+     */
+    public String locate(Map objectModel, InvokeContext context) throws Exception {
+        Parameters parameters = resolveParameters(context,objectModel);
+        Redirector redirector = context.getRedirector();
+        String source = "";
+        Map substitutions = m_action.act(redirector, resolver, objectModel, source, parameters);
+        if (substitutions != null) {
+            if (getLogger().isDebugEnabled()) {
+             //   getLogger().debug("matched: " + m_pattern);
+            }
+            context.pushMap(null,substitutions);
+            for (int i = 0; i < m_nodes.length; i++) {
+                String location = m_nodes[i].locate(objectModel,context);
+                if (location != null) {
+                    return location;
+                }
+            }
+            context.popMap();
+        }
+        return null;
+    }
+    
+//    public String locate(Map om, InvokeContext context) throws Exception {
+//        
+//        Parameters parameters = resolveParameters(context,om);
+//        for (int i = 0; i < m_nodes.length; i++) {
+//            String location = m_nodes[i].locate(om,context);
+//            if (m_action.act().select(location,om,parameters)) {
+//                if (getLogger().isDebugEnabled()) {
+//                    getLogger().debug("selected: " + location);
+//                }
+//                return location;
+//            }
+//        }
+//        return null;
+//    }
+}
\ No newline at end of file

Propchange: forrest/trunk/main/java/org/apache/forrest/locationmap/lm/ActNode.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: forrest/trunk/main/java/org/apache/forrest/locationmap/lm/LocationMap.java
URL: http://svn.apache.org/viewcvs/forrest/trunk/main/java/org/apache/forrest/locationmap/lm/LocationMap.java?rev=263492&r1=263491&r2=263492&view=diff
==============================================================================
--- forrest/trunk/main/java/org/apache/forrest/locationmap/lm/LocationMap.java (original)
+++ forrest/trunk/main/java/org/apache/forrest/locationmap/lm/LocationMap.java Sat Aug 27
20:09:25 2005
@@ -32,6 +32,7 @@
 import org.apache.cocoon.components.treeprocessor.InvokeContext;
 import org.apache.cocoon.matching.Matcher;
 import org.apache.cocoon.selection.Selector;
+import org.apache.cocoon.acting.*;
 
 /**
  * A LocationMap defines a mapping from requests to locations.
@@ -99,6 +100,9 @@
     /** default matcher */
     private String m_defaultMatcher;
     
+    /** default action */
+    private String m_defaultAction;
+    
     /** default selector */
     private String m_defaultSelector;
     
@@ -169,6 +173,25 @@
             }
             m_manager.put(Selector.ROLE+"Selector",selectorSelector);
         }
+        
+        // actions
+        child = components.getChild("actions",false);
+        if (child != null) {
+            final DefaultServiceSelector actionSelector = new DefaultServiceSelector();
+            m_defaultAction = child.getAttribute("default");
+            final Configuration[] actions = child.getChildren("action");
+            for (int i = 0; i < actions.length; i++) {
+                String name = actions[i].getAttribute("name");
+                String src  = actions[i].getAttribute("src");
+                Action action = (Action) createComponent(src,actions[i]);
+                actionSelector.put(name,action);
+            }
+            actionSelector.makeReadOnly();
+            if (!actionSelector.isSelectable(m_defaultAction)) {
+                throw new ConfigurationException("Default action is not defined.");
+            }
+            m_manager.put(Selector.ROLE+"Selector",actionSelector);
+        }
 
         m_manager.makeReadOnly();
 
@@ -292,4 +315,10 @@
 
     }
 
+    /**
+     * Expose the default Action to LocatorNodes
+     */
+    String getDefaultAction() {
+        return m_defaultAction;
+    }
 }

Modified: forrest/trunk/main/java/org/apache/forrest/locationmap/lm/LocatorNode.java
URL: http://svn.apache.org/viewcvs/forrest/trunk/main/java/org/apache/forrest/locationmap/lm/LocatorNode.java?rev=263492&r1=263491&r2=263492&view=diff
==============================================================================
--- forrest/trunk/main/java/org/apache/forrest/locationmap/lm/LocatorNode.java (original)
+++ forrest/trunk/main/java/org/apache/forrest/locationmap/lm/LocatorNode.java Sat Aug 27
20:09:25 2005
@@ -138,5 +138,9 @@
     String getDefaultSelector() {
         return m_lm.getDefaultSelector();
     }
+
+    String getDefaultAction() {
+        return  m_lm.getDefaultAction();
+    }
     
 }

Modified: forrest/trunk/main/java/org/apache/forrest/locationmap/lm/MatchNode.java
URL: http://svn.apache.org/viewcvs/forrest/trunk/main/java/org/apache/forrest/locationmap/lm/MatchNode.java?rev=263492&r1=263491&r2=263492&view=diff
==============================================================================
--- forrest/trunk/main/java/org/apache/forrest/locationmap/lm/MatchNode.java (original)
+++ forrest/trunk/main/java/org/apache/forrest/locationmap/lm/MatchNode.java Sat Aug 27 20:09:25
2005
@@ -101,6 +101,9 @@
             else if (name.equals("select")) {
                 node = new SelectNode(m_ln, super.m_manager);
             }
+            else if (name.equals("act")) {
+                node = new ActNode(m_ln, super.m_manager);
+            }
             else if (!name.equals("parameter")) {
                 final String message =
                     "Unknown match node child: " + name;

Modified: forrest/trunk/main/java/org/apache/forrest/locationmap/lm/SelectNode.java
URL: http://svn.apache.org/viewcvs/forrest/trunk/main/java/org/apache/forrest/locationmap/lm/SelectNode.java?rev=263492&r1=263491&r2=263492&view=diff
==============================================================================
--- forrest/trunk/main/java/org/apache/forrest/locationmap/lm/SelectNode.java (original)
+++ forrest/trunk/main/java/org/apache/forrest/locationmap/lm/SelectNode.java Sat Aug 27 20:09:25
2005
@@ -82,6 +82,9 @@
             else if (name.equals("select")) {
                 node = new SelectNode(m_ln, super.m_manager);
             }
+            else if (name.equals("act")) {
+                node = new ActNode(m_ln, super.m_manager);
+            }
             else if (!name.equals("parameter")) {
                 final String message = "Unknown select node child:" + name;
                 throw new ConfigurationException(message);



Mime
View raw message