portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From woon...@apache.org
Subject svn commit: r1066694 - in /portals/jetspeed-2/portal/trunk: components/jetspeed-portal/src/main/java/org/apache/jetspeed/pipeline/ components/jetspeed-portal/src/test/java/org/apache/jetspeed/pipeline/ jetspeed-api/src/main/java/org/apache/jetspeed/pip...
Date Wed, 02 Feb 2011 23:43:03 GMT
Author: woonsan
Date: Wed Feb  2 23:43:02 2011
New Revision: 1066694

URL: http://svn.apache.org/viewvc?rev=1066694&view=rev
Log:
JS2-1238: Adding Pipelines path mapping component to allow to find servlet path mapping by
pipeline id from custom filter implementations.
Also, added another method to return all mapped servlet paths by pipeline id.
The existing pipeline map definition has been changed from HashMap to LinkedHashMap to keep
insertion order.
(Because there are multiple mapping for jetspeed-pipeline, we should return the first one
in this case.)

Added:
    portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/pipeline/JetspeedPipelineMapper.java
    portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/java/org/apache/jetspeed/pipeline/TestPipelineMapper.java
    portals/jetspeed-2/portal/trunk/jetspeed-api/src/main/java/org/apache/jetspeed/pipeline/PipelineMapper.java
Modified:
    portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/pipelines.xml

Added: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/pipeline/JetspeedPipelineMapper.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/pipeline/JetspeedPipelineMapper.java?rev=1066694&view=auto
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/pipeline/JetspeedPipelineMapper.java
(added)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/pipeline/JetspeedPipelineMapper.java
Wed Feb  2 23:43:02 2011
@@ -0,0 +1,127 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.jetspeed.pipeline;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.jetspeed.Jetspeed;
+import org.apache.jetspeed.components.ComponentManager;
+
+
+/**
+ * JetspeedPipelineMapper
+ * @version $Id$
+ */
+public class JetspeedPipelineMapper implements PipelineMapper
+{
+    
+    private Map<String, String> pipelineNamesMap;
+    private Map<String, String[]> pipelineIdPathsMap;
+    
+    public JetspeedPipelineMapper(Map<String, String> pipelineNamesMap) 
+    {
+        this.pipelineNamesMap = pipelineNamesMap;
+        
+        pipelineIdPathsMap = new HashMap<String, String[]>();
+        
+        for (Map.Entry<String, String> entry : this.pipelineNamesMap.entrySet())
+        {
+            String path = entry.getKey();
+            String pipelineId = entry.getValue();
+            
+            if (!pipelineIdPathsMap.containsKey(pipelineId))
+            {
+                pipelineIdPathsMap.put(pipelineId, new String[] { path });
+            }
+            else
+            {
+                String [] paths = pipelineIdPathsMap.get(pipelineId);
+                String [] mappedPaths = new String[paths.length + 1];
+                System.arraycopy(paths, 0, mappedPaths, 0, paths.length);
+                mappedPaths[mappedPaths.length - 1] = path;
+                pipelineIdPathsMap.put(pipelineId, mappedPaths);
+            }
+        }
+    }
+    
+    public Pipeline getPipelineByMappedPath(String mappedPath)
+    {
+        if (pipelineNamesMap == null)
+        {
+            return null;
+        }
+        
+        String pipelineId = pipelineNamesMap.get(mappedPath);
+        
+        if (pipelineId != null)
+        {
+            return getPipelineById(pipelineId);
+        }
+        
+        return null;
+    }
+    
+    public Pipeline getPipelineById(String pipelineId)
+    {
+        ComponentManager componentManager = Jetspeed.getComponentManager();
+        
+        if (componentManager == null)
+        {
+            return null;
+        }
+        
+        return (Pipeline) componentManager.getComponent(pipelineId);
+    }
+    
+    public String getMappedPathByPipelineId(String pipelineId)
+    {
+        if (pipelineIdPathsMap == null)
+        {
+            return null;
+        }
+        
+        String [] paths = pipelineIdPathsMap.get(pipelineId);
+        
+        if (paths == null)
+        {
+            return null;
+        }
+        
+        return (paths.length > 0 ? paths[0] : null);
+    }
+    
+    public String[] getMappedPathsByPipelineId(String pipelineId)
+    {
+        if (pipelineIdPathsMap == null)
+        {
+            return null;
+        }
+        
+        String [] paths = pipelineIdPathsMap.get(pipelineId);
+        
+        if (paths == null)
+        {
+            return new String[0];
+        }
+        
+        String [] mappedPaths = new String[paths.length];
+        System.arraycopy(paths, 0, mappedPaths, 0, paths.length);
+        return mappedPaths;
+    }
+    
+}
\ No newline at end of file

Added: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/java/org/apache/jetspeed/pipeline/TestPipelineMapper.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/java/org/apache/jetspeed/pipeline/TestPipelineMapper.java?rev=1066694&view=auto
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/java/org/apache/jetspeed/pipeline/TestPipelineMapper.java
(added)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/java/org/apache/jetspeed/pipeline/TestPipelineMapper.java
Wed Feb  2 23:43:02 2011
@@ -0,0 +1,95 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.jetspeed.pipeline;
+
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+/**
+ * TestPipelineMapper
+ *
+ * @version $Id$
+ */
+public class TestPipelineMapper extends TestCase
+{
+    private PipelineMapper pipelineMapper;
+    private String defaultPipelineId = "jetspeed-pipeline";
+    
+    @Override
+    public void setUp() throws Exception
+    {
+        Map<String, String> pipelinesMap = new LinkedHashMap<String, String>();
+        
+        pipelinesMap.put("/portlet", 
+                         "portlet-pipeline");
+        pipelinesMap.put("/portal", 
+                         "jetspeed-pipeline");
+        pipelinesMap.put("/login", 
+                         "jetspeed-pipeline");
+        pipelinesMap.put("/fileserver", 
+                         "fileserver-pipeline");
+        pipelinesMap.put("/ajaxapi", 
+                         "ajax-pipeline");
+        pipelinesMap.put("/ajax", 
+                         "ajax-direct-pipeline");
+        pipelinesMap.put("/services", 
+                         "restful-services-pipeline");
+        pipelinesMap.put("/configure", 
+                         "configure-pipeline");
+        pipelinesMap.put("/healthcheck", 
+                         "healthcheck-pipeline");
+        pipelinesMap.put("/ui", 
+                         "jetui-pipeline");
+        
+        pipelineMapper = new JetspeedPipelineMapper(pipelinesMap);
+    }
+    
+    /**
+     * Tests PipelineMapper
+     *
+     * @throws Exception
+     */
+    public void testPipelineMapper() throws Exception
+    {
+        String mappedPathOfDefaultPipeline = pipelineMapper.getMappedPathByPipelineId(defaultPipelineId);
+        assertEquals("/portal", mappedPathOfDefaultPipeline);
+        
+        String [] mappedPaths = pipelineMapper.getMappedPathsByPipelineId(defaultPipelineId);
+        assertNotNull(mappedPaths);
+        assertEquals(2, mappedPaths.length);
+        assertEquals("/portal", mappedPaths[0]);
+        assertEquals("/login", mappedPaths[1]);
+        
+        assertEquals("/portlet", pipelineMapper.getMappedPathByPipelineId("portlet-pipeline"));
+        mappedPaths = pipelineMapper.getMappedPathsByPipelineId("portlet-pipeline");
+        assertNotNull(mappedPaths);
+        assertEquals(1, mappedPaths.length);
+        
+        assertEquals("/fileserver", pipelineMapper.getMappedPathByPipelineId("fileserver-pipeline"));
+        mappedPaths = pipelineMapper.getMappedPathsByPipelineId("fileserver-pipeline");
+        assertNotNull(mappedPaths);
+        assertEquals(1, mappedPaths.length);
+        
+        assertNull(pipelineMapper.getMappedPathByPipelineId("nonexisting-pipeline"));
+        mappedPaths = pipelineMapper.getMappedPathsByPipelineId("nonexisting-pipeline");
+        assertNotNull(mappedPaths);
+        assertEquals(0, mappedPaths.length);
+    }
+    
+}

Added: portals/jetspeed-2/portal/trunk/jetspeed-api/src/main/java/org/apache/jetspeed/pipeline/PipelineMapper.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/jetspeed-api/src/main/java/org/apache/jetspeed/pipeline/PipelineMapper.java?rev=1066694&view=auto
==============================================================================
--- portals/jetspeed-2/portal/trunk/jetspeed-api/src/main/java/org/apache/jetspeed/pipeline/PipelineMapper.java
(added)
+++ portals/jetspeed-2/portal/trunk/jetspeed-api/src/main/java/org/apache/jetspeed/pipeline/PipelineMapper.java
Wed Feb  2 23:43:02 2011
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.jetspeed.pipeline;
+
+
+/**
+ * Jetspeed PipelineMapper
+ *
+ * @version $Id$
+ */
+public interface PipelineMapper
+{
+    
+    /**
+     * Returns pipeline mapped by the specified path.
+     * @param path
+     * @return
+     */
+    Pipeline getPipelineByMappedPath(String mappedPath);
+    
+    /**
+     * Returns pipeline by the pipeline component ID. 
+     * @param name
+     * @return
+     */
+    Pipeline getPipelineById(String id);
+    
+    /**
+     * Returns mapped base path found first for the pipeline ID.
+     * If nothing found, returns null.
+     * @param id
+     * @return
+     */
+    String getMappedPathByPipelineId(String pipelineId);
+    
+    /**
+     * Returns all mapped base paths for the pipeline ID.
+     * If nothing found, returns an empty array.
+     * @param id
+     * @return
+     */
+    String [] getMappedPathsByPipelineId(String pipelineId);
+    
+}
\ No newline at end of file

Modified: portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/pipelines.xml
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/pipelines.xml?rev=1066694&r1=1066693&r2=1066694&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/pipelines.xml
(original)
+++ portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/pipelines.xml
Wed Feb  2 23:43:02 2011
@@ -815,7 +815,7 @@
     </constructor-arg>
   </bean>
   
-  <bean id='pipeline-map' class='java.util.HashMap'>
+  <bean id='pipeline-map' class='java.util.LinkedHashMap'>
     <meta key="j2:cat" value="default" />
     <constructor-arg>
       <map>
@@ -852,6 +852,11 @@
       </map>
     </constructor-arg>
   </bean>
+  
+  <bean id="pipeline-mapper" class="org.apache.jetspeed.pipeline.JetspeedPipelineMapper">
+    <meta key="j2:cat" value="default" />
+    <constructor-arg ref="pipeline-map" />
+  </bean>
 
   <bean id="debugValve" class="org.apache.jetspeed.pipeline.valve.impl.DebugValveImpl">
     <meta key="j2:cat" value="default" />



---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org


Mime
View raw message