Author: ard
Date: Tue Sep 11 14:43:13 2012
New Revision: 1383438

URL: http://svn.apache.org/viewvc?rev=1383438&view=rev
Log:
RAVE-697 initial pageFragment enhancers and added unit tests

Added:
    
rave/sandbox/content-services/rave-web-hmvc/src/main/java/org/apache/rave/portal/web/mvc/config/enhancers/
    
rave/sandbox/content-services/rave-web-hmvc/src/main/java/org/apache/rave/portal/web/mvc/config/enhancers/AbstractFragmentsRemoverEnhancer.java
    
rave/sandbox/content-services/rave-web-hmvc/src/main/java/org/apache/rave/portal/web/mvc/config/enhancers/ExtendsEnhancer.java
    
rave/sandbox/content-services/rave-web-hmvc/src/main/java/org/apache/rave/portal/web/mvc/config/enhancers/PagesConfigEnhancer.java
    
rave/sandbox/content-services/rave-web-hmvc/src/main/java/org/apache/rave/portal/web/mvc/config/enhancers/SnsFragmentsRemoverEnhancer.java
    
rave/sandbox/content-services/rave-web-hmvc/src/test/resources/config/testenhancingmappings/noExtensionsButSNSPageDefinitions.xml

Added: 
rave/sandbox/content-services/rave-web-hmvc/src/main/java/org/apache/rave/portal/web/mvc/config/enhancers/AbstractFragmentsRemoverEnhancer.java
URL: 
http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-web-hmvc/src/main/java/org/apache/rave/portal/web/mvc/config/enhancers/AbstractFragmentsRemoverEnhancer.java?rev=1383438&view=auto
==============================================================================
--- 
rave/sandbox/content-services/rave-web-hmvc/src/main/java/org/apache/rave/portal/web/mvc/config/enhancers/AbstractFragmentsRemoverEnhancer.java
 (added)
+++ 
rave/sandbox/content-services/rave-web-hmvc/src/main/java/org/apache/rave/portal/web/mvc/config/enhancers/AbstractFragmentsRemoverEnhancer.java
 Tue Sep 11 14:43:13 2012
@@ -0,0 +1,67 @@
+/*
+ * 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.rave.portal.web.mvc.config.enhancers;
+
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.rave.portal.web.mvc.config.PageFragment;
+import org.apache.rave.portal.web.mvc.config.PagesConfig;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class AbstractFragmentsRemoverEnhancer implements PagesConfigEnhancer {
+
+    private final static Logger log = 
LoggerFactory.getLogger(AbstractFragmentsRemoverEnhancer.class);
+
+    @Override
+    public PagesConfig enhance(final PagesConfig pagesConfig) {
+        // we try to first find all abstractRootFragments : These are the root 
fragments that
+        // are defined to be abstract or contain some descendant that are 
abstract
+        final Set<PageFragment> abstractPages= new HashSet<PageFragment>();
+        final Map<String,PageFragment> pages = pagesConfig.getPages();
+        for (PageFragment pageFragment : pages.values()) {
+            if (pageFragment.isAbstract()) {
+                abstractPages.add(pageFragment);
+            } else {
+                traverseAndFindAbstractRootFragments(pageFragment, 
pageFragment, abstractPages);
+            }
+        }
+        for (PageFragment abstractPage : abstractPages) {
+            log.debug("Removing abstract page {}", abstractPage.toString());
+            pages.remove(abstractPage.getName());
+        }
+        return pagesConfig;
+    }
+
+    private void traverseAndFindAbstractRootFragments(final PageFragment root, 
final PageFragment fragment, final Set<PageFragment> abstractRootFragments) {
+        if (fragment.getChildren() == null) {
+            return;
+        }
+        for (PageFragment child : fragment.getChildren()) {
+            if (child.isAbstract()) {
+                // no need to further traverse
+                abstractRootFragments.add(root);
+            } else {
+                traverseAndFindAbstractRootFragments(root, child, 
abstractRootFragments);
+            }
+        }
+    }
+}

Added: 
rave/sandbox/content-services/rave-web-hmvc/src/main/java/org/apache/rave/portal/web/mvc/config/enhancers/ExtendsEnhancer.java
URL: 
http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-web-hmvc/src/main/java/org/apache/rave/portal/web/mvc/config/enhancers/ExtendsEnhancer.java?rev=1383438&view=auto
==============================================================================
--- 
rave/sandbox/content-services/rave-web-hmvc/src/main/java/org/apache/rave/portal/web/mvc/config/enhancers/ExtendsEnhancer.java
 (added)
+++ 
rave/sandbox/content-services/rave-web-hmvc/src/main/java/org/apache/rave/portal/web/mvc/config/enhancers/ExtendsEnhancer.java
 Tue Sep 11 14:43:13 2012
@@ -0,0 +1,39 @@
+/*
+ * 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.rave.portal.web.mvc.config.enhancers;
+
+import org.apache.rave.portal.web.mvc.config.PageFragment;
+import org.apache.rave.portal.web.mvc.config.PagesConfig;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class ExtendsEnhancer implements PagesConfigEnhancer {
+
+    private final static Logger log = 
LoggerFactory.getLogger(ExtendsEnhancer.class);
+
+    @Override
+    public PagesConfig enhance(final PagesConfig pagesConfig) {
+        for (PageFragment pageFragment : pagesConfig.getPages().values()) {
+
+        }
+        return pagesConfig;
+    }
+
+
+}

Added: 
rave/sandbox/content-services/rave-web-hmvc/src/main/java/org/apache/rave/portal/web/mvc/config/enhancers/PagesConfigEnhancer.java
URL: 
http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-web-hmvc/src/main/java/org/apache/rave/portal/web/mvc/config/enhancers/PagesConfigEnhancer.java?rev=1383438&view=auto
==============================================================================
--- 
rave/sandbox/content-services/rave-web-hmvc/src/main/java/org/apache/rave/portal/web/mvc/config/enhancers/PagesConfigEnhancer.java
 (added)
+++ 
rave/sandbox/content-services/rave-web-hmvc/src/main/java/org/apache/rave/portal/web/mvc/config/enhancers/PagesConfigEnhancer.java
 Tue Sep 11 14:43:13 2012
@@ -0,0 +1,12 @@
+package org.apache.rave.portal.web.mvc.config.enhancers;
+
+import org.apache.rave.portal.web.mvc.config.PagesConfig;
+
+public interface PagesConfigEnhancer {
+
+    /**
+     * @param pagesConfig the <code>pagesConfig</code> to enhance
+     * @return the enhanced {@link 
org.apache.rave.portal.web.mvc.config.PagesConfig} of the 
<code>pagesConfig</code> argument
+     */
+    PagesConfig enhance(PagesConfig pagesConfig);
+}
\ No newline at end of file

Added: 
rave/sandbox/content-services/rave-web-hmvc/src/main/java/org/apache/rave/portal/web/mvc/config/enhancers/SnsFragmentsRemoverEnhancer.java
URL: 
http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-web-hmvc/src/main/java/org/apache/rave/portal/web/mvc/config/enhancers/SnsFragmentsRemoverEnhancer.java?rev=1383438&view=auto
==============================================================================
--- 
rave/sandbox/content-services/rave-web-hmvc/src/main/java/org/apache/rave/portal/web/mvc/config/enhancers/SnsFragmentsRemoverEnhancer.java
 (added)
+++ 
rave/sandbox/content-services/rave-web-hmvc/src/main/java/org/apache/rave/portal/web/mvc/config/enhancers/SnsFragmentsRemoverEnhancer.java
 Tue Sep 11 14:43:13 2012
@@ -0,0 +1,64 @@
+/*
+ * 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.rave.portal.web.mvc.config.enhancers;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.rave.portal.web.mvc.config.PageFragment;
+import org.apache.rave.portal.web.mvc.config.PagesConfig;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class SnsFragmentsRemoverEnhancer implements PagesConfigEnhancer {
+
+    private final static Logger log = 
LoggerFactory.getLogger(SnsFragmentsRemoverEnhancer.class);
+
+    @Override
+    public PagesConfig enhance(final PagesConfig pagesConfig) {
+        for (PageFragment pageFragment : pagesConfig.getPages().values()) {
+            traverseAndRemoveSNSIfEncountered(pageFragment);
+        }
+        return pagesConfig;
+    }
+
+    private void traverseAndRemoveSNSIfEncountered(final PageFragment 
fragment) {
+        Set<String> presentChildNames = new HashSet<String>();
+        List<PageFragment> sameNameSiblings = new ArrayList<PageFragment>();
+        if (fragment.getChildren() == null) {
+            return;
+        }
+        for (PageFragment child : fragment.getChildren()) {
+            if (presentChildNames.contains(child.getName())) {
+                log.warn("Not allowed Same name sibling found for page 
frament. The following pageFragment" +
+                        " will not be included in the pages model : {}", 
child.toString());
+                sameNameSiblings.add(child);
+                continue;
+            }
+            presentChildNames.add(child.getName());
+            traverseAndRemoveSNSIfEncountered(child);
+        }
+        // now, if there are sns, remove them
+        for (PageFragment child : sameNameSiblings) {
+            fragment.getChildren().remove(child);
+        }
+    }
+}

Added: 
rave/sandbox/content-services/rave-web-hmvc/src/test/resources/config/testenhancingmappings/noExtensionsButSNSPageDefinitions.xml
URL: 
http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-web-hmvc/src/test/resources/config/testenhancingmappings/noExtensionsButSNSPageDefinitions.xml?rev=1383438&view=auto
==============================================================================
--- 
rave/sandbox/content-services/rave-web-hmvc/src/test/resources/config/testenhancingmappings/noExtensionsButSNSPageDefinitions.xml
 (added)
+++ 
rave/sandbox/content-services/rave-web-hmvc/src/test/resources/config/testenhancingmappings/noExtensionsButSNSPageDefinitions.xml
 Tue Sep 11 14:43:13 2012
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  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.
+  -->
+<pageDefinitions name="default">
+
+  <pageFragment name="top" description="Page that is being extended by other 
pages"
+                controller="org.apache.rave.unittest.NonExistingController">
+    <pageFragment name="sub"/>
+    <pageFragment name="sub"/>
+    <pageFragment name="sub"/>
+  </pageFragment>
+
+  <pageFragment name="top" description="Page that is being extended by other 
pages"
+                               
controller="org.apache.rave.unittest.NonExistingController">
+  <pageFragment name="sub"/>
+  <pageFragment name="sub"/>
+</pageFragment>
+
+
+</pageDefinitions>
\ No newline at end of file


Reply via email to