portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tay...@apache.org
Subject svn commit: r219579 - in /portals/jetspeed-2/trunk/components/page-manager/src: java/org/apache/jetspeed/page/impl/ test/org/apache/jetspeed/page/
Date Mon, 18 Jul 2005 22:29:34 GMT
Author: taylor
Date: Mon Jul 18 15:26:44 2005
New Revision: 219579

URL: http://svn.apache.org/viewcvs?rev=219579&view=rev
Log:
started impl of PageManager.clone:

    public Page clonePage(Page source, String path)
    throws JetspeedException, PageNotUpdatedException

most of the object model is covered with unit tests
still need to complete menus and metadata

Modified:
    portals/jetspeed-2/trunk/components/page-manager/src/java/org/apache/jetspeed/page/impl/AbstractPageManager.java
    portals/jetspeed-2/trunk/components/page-manager/src/java/org/apache/jetspeed/page/impl/CastorXmlPageManager.java
    portals/jetspeed-2/trunk/components/page-manager/src/test/org/apache/jetspeed/page/TestCastorXmlPageManager.java

Modified: portals/jetspeed-2/trunk/components/page-manager/src/java/org/apache/jetspeed/page/impl/AbstractPageManager.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/page-manager/src/java/org/apache/jetspeed/page/impl/AbstractPageManager.java?rev=219579&r1=219578&r2=219579&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/components/page-manager/src/java/org/apache/jetspeed/page/impl/AbstractPageManager.java
(original)
+++ portals/jetspeed-2/trunk/components/page-manager/src/java/org/apache/jetspeed/page/impl/AbstractPageManager.java
Mon Jul 18 15:26:44 2005
@@ -15,14 +15,16 @@
  */
 package org.apache.jetspeed.page.impl;
 
+import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Iterator;
 import java.util.List;
 import java.util.LinkedList;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.jetspeed.exception.JetspeedException;
 import org.apache.jetspeed.idgenerator.IdGenerator;
-import org.apache.jetspeed.om.common.SecuredResource;
 import org.apache.jetspeed.om.common.SecurityConstraint;
 import org.apache.jetspeed.om.common.SecurityConstraints;
 import org.apache.jetspeed.om.folder.Folder;
@@ -49,7 +51,9 @@
 import org.apache.jetspeed.om.page.psml.SecurityConstraintsImpl;
 import org.apache.jetspeed.page.PageManager;
 import org.apache.jetspeed.page.PageManagerEventListener;
+import org.apache.jetspeed.page.PageNotUpdatedException;
 import org.apache.jetspeed.page.document.Node;
+import org.apache.jetspeed.portalsite.MenuElement;
 
 /**
  * AbstractPageManagerService
@@ -508,5 +512,188 @@
                 log.error("Failed to notify page manager event listener", e);
             }
         }
+    }
+    
+    protected Fragment cloneFragment(Fragment source)
+    {
+        Fragment clone = newFragment();
+        clone.setDecorator(source.getDecorator());
+        clone.setName(source.getName());
+        clone.setShortTitle(source.getShortTitle());
+        clone.setSkin(source.getSkin());
+        clone.setTitle(source.getTitle());
+        clone.setType(source.getType());
+        clone.setState(source.getState());
+        
+        // clone properties
+        Iterator names = source.getLayoutProperties().iterator();
+        while (names.hasNext())
+        {
+            String name = (String)names.next();
+            Iterator props = source.getProperties(name).iterator();
+            while (props.hasNext())
+            {
+                Property srcProp = (Property)props.next();
+                Property dstProp = newProperty();
+                dstProp.setLayout(name);
+                dstProp.setName(srcProp.getName());
+                dstProp.setValue(srcProp.getValue());
+                clone.addProperty(dstProp);
+            }            
+        }
+        
+        // clone security constraints
+        SecurityConstraints srcSecurity = source.getSecurityConstraints();
+        if (srcSecurity != null)
+        {
+            SecurityConstraints dstSecurity = cloneSecurityConstraints(srcSecurity);
+            clone.setSecurityConstraints(dstSecurity);
+        }            
+        
+        // recursively clone fragments
+        Iterator fragments = source.getFragments().iterator();
+        while (fragments.hasNext())
+        {
+            Fragment fragment = (Fragment)fragments.next();
+            Fragment clonedFragment = cloneFragment(fragment);
+            clone.getFragments().add(clonedFragment);
+        }
+        
+        return clone;
+    }
+    
+    public Page clonePage(Page source, String path)
+    throws JetspeedException, PageNotUpdatedException
+    {
+        // create the new page and clone attributes
+        Page page = newPage(path);
+        page.setTitle(source.getTitle());
+        page.setShortTitle(source.getShortTitle());
+        page.setDefaultDecorator(source.getDefaultDecorator(Fragment.LAYOUT), Fragment.LAYOUT);
+        page.setDefaultDecorator(source.getDefaultDecorator(Fragment.PORTLET), Fragment.PORTLET);
+        page.setDefaultSkin(source.getDefaultSkin());
+            
+        // TODO: clone the metadata
+//        if (source.getMetadata() != null)
+//        {
+//            Collection fields = source.getMetadata().getFields();
+//            if (fields != null)
+//            {
+//                Iterator fieldsIterator = fields.iterator();
+//                while (fieldsIterator.hasNext())
+//                {
+//                    // LEFT OFF HERE Field srcField = (Field)fieldIterator.next();
+//                }
+//            }
+//        }
+        
+        // create the root fragment and clone attributes and all subfragments
+        Fragment root = cloneFragment(source.getRootFragment());
+        page.setRootFragment(root);
+        
+        // clone menus
+        List menus = page.getMenuDefinitions();
+        if (menus != null)
+        {
+            List clonedMenus = cloneMenuDefinitions(page.getMenuDefinitions());
+            page.setMenuDefinitions(clonedMenus);
+        }
+        
+        // clone security constraints
+        SecurityConstraints srcSecurity = source.getSecurityConstraints();        
+        if (srcSecurity != null)
+        {
+            SecurityConstraints clonedSecurity = cloneSecurityConstraints(srcSecurity);
+            page.setSecurityConstraints(clonedSecurity);
+        }    
+        
+        updatePage(page);
+        return page;
+    }
+
+    protected List cloneMenuDefinitions(List srcMenus)
+    {
+        List clonedMenus = new ArrayList(4); 
+        Iterator menus = srcMenus.iterator();
+        while (menus.hasNext())
+        {
+            MenuDefinition srcMenu = (MenuDefinition)menus.next();
+            MenuDefinition clonedMenu = newMenuDefinition();
+            clonedMenu.setDepth(srcMenu.getDepth());
+            clonedMenu.setName(srcMenu.getName());
+            clonedMenu.setOptions(srcMenu.getOptions());
+            clonedMenu.setOrder(srcMenu.getOrder());
+            clonedMenu.setPaths(srcMenu.isPaths());
+            clonedMenu.setProfile(srcMenu.getProfile());
+            clonedMenu.setRegexp(srcMenu.isRegexp());
+            
+            // TODO: how do I clone all localized short titles?
+            clonedMenu.setShortTitle(srcMenu.getShortTitle());
+            
+            clonedMenu.setSkin(srcMenu.getSkin());
+            
+            // TODO: how do I clone all localized titles?            
+            clonedMenu.setTitle(srcMenu.getTitle());
+            
+            // TODO: clone metadata
+            clonedMenu.getMetadata();
+            
+            List srcElements = clonedMenu.getMenuElements();
+            if (srcElements != null)
+            {
+                List clonedElements = cloneMenuElements(srcElements);
+                clonedMenu.setMenuElements(clonedElements);
+            }
+        }
+        return clonedMenus;
+    }
+    
+    protected List cloneMenuElements(List srcElements)
+    {
+        List clonedElements = new ArrayList(8);
+        Iterator elements = srcElements.iterator();
+        while (elements.hasNext())
+        {
+            MenuElement srcElement = (MenuElement)elements.next();
+            // MenuElement clonedElement = newMenuElement();
+        }
+        return clonedElements;
+    }
+    
+    protected SecurityConstraints cloneSecurityConstraints(SecurityConstraints source)
+    {
+        SecurityConstraints security = newSecurityConstraints();
+        if (source.getOwner() != null)        
+        {
+            security.setOwner(source.getOwner());
+        }
+        if (source.getSecurityConstraints() != null)
+        {
+            List clonedConstraints = new ArrayList(8);
+            Iterator constraints = source.getSecurityConstraints().iterator();
+            while (constraints.hasNext())
+            {
+                SecurityConstraint srcConstraint = (SecurityConstraint)constraints.next();
+                SecurityConstraint dstConstraint = newSecurityConstraint();
+                dstConstraint.setUsers(srcConstraint.getUsers());                
+                dstConstraint.setRoles(srcConstraint.getRoles());
+                dstConstraint.setGroups(srcConstraint.getGroups());
+                dstConstraint.setPermissions(srcConstraint.getPermissions());
+                clonedConstraints.add(dstConstraint);
+            }
+            security.setSecurityConstraints(clonedConstraints);
+        }
+        if (source.getSecurityConstraintsRefs() != null)
+        {
+            List clonedRefs = new ArrayList(8);
+            Iterator refs = source.getSecurityConstraintsRefs().iterator();
+            while (refs.hasNext())
+            {                
+                String constraintsRef = (String)refs.next();                
+                clonedRefs.add(constraintsRef);
+            }
+            security.setSecurityConstraintsRefs(clonedRefs);            
+        }
+        return security;
     }
 }

Modified: portals/jetspeed-2/trunk/components/page-manager/src/java/org/apache/jetspeed/page/impl/CastorXmlPageManager.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/page-manager/src/java/org/apache/jetspeed/page/impl/CastorXmlPageManager.java?rev=219579&r1=219578&r2=219579&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/components/page-manager/src/java/org/apache/jetspeed/page/impl/CastorXmlPageManager.java
(original)
+++ portals/jetspeed-2/trunk/components/page-manager/src/java/org/apache/jetspeed/page/impl/CastorXmlPageManager.java
Mon Jul 18 15:26:44 2005
@@ -45,7 +45,6 @@
 import org.apache.jetspeed.page.document.FolderHandler;
 import org.apache.jetspeed.page.document.Node;
 import org.apache.jetspeed.page.document.NodeException;
-import org.apache.jetspeed.page.document.NodeSet;
 import org.apache.jetspeed.page.document.NodeSetImpl;
 import org.apache.jetspeed.page.document.UnsupportedDocumentTypeException;
 

Modified: portals/jetspeed-2/trunk/components/page-manager/src/test/org/apache/jetspeed/page/TestCastorXmlPageManager.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/page-manager/src/test/org/apache/jetspeed/page/TestCastorXmlPageManager.java?rev=219579&r1=219578&r2=219579&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/components/page-manager/src/test/org/apache/jetspeed/page/TestCastorXmlPageManager.java
(original)
+++ portals/jetspeed-2/trunk/components/page-manager/src/test/org/apache/jetspeed/page/TestCastorXmlPageManager.java
Mon Jul 18 15:26:44 2005
@@ -850,4 +850,103 @@
         }
         assertTrue(exceptionFound);
     }
+    
+    public void testClonePage() throws Exception
+    {
+        Page testpage = pageManager.getPage("/clonetest.psml");
+        assertNotNull(testpage);
+        Page clone = pageManager.clonePage(testpage, "/cloned.psml");
+        assertNotNull(clone);
+        
+        assertTrue(clone.getId().equals("/cloned.psml"));
+        assertTrue(clone.getName().equals("cloned.psml"));
+        assertTrue(testpage.getTitle().equals("Test Page"));
+        assertTrue(testpage.getDefaultSkin().equals("test-skin"));
+        assertTrue(testpage.getDefaultDecorator(Fragment.LAYOUT).equals("test-layout"));
+        assertTrue(testpage.getDefaultDecorator(Fragment.PORTLET).equals("test-portlet"));
+
+        // TODO: Test Meta data
+        Fragment root = testpage.getRootFragment();
+        Fragment cloneRoot = clone.getRootFragment();
+        
+        assertNotNull(cloneRoot);
+        assertNotNull(cloneRoot.getId());        
+        assertFalse(cloneRoot.getId().equals(root.getId()));
+        assertTrue(cloneRoot.getName().equals("TwoColumns"));
+        assertTrue(cloneRoot.getType().equals(Fragment.LAYOUT));
+        assertNull(cloneRoot.getDecorator());
+
+        List children = root.getFragments();
+        List cloneChildren = cloneRoot.getFragments();
+        assertNotNull(cloneChildren);
+        assertTrue(cloneChildren.size() == 3);
+
+        Fragment f = (Fragment) children.get(0);
+        Fragment cf = (Fragment) cloneChildren.get(0);
+        assertNotNull(cf.getId());
+        assertFalse(cf.getId().equals(f.getId()));
+        assertTrue(cf.getName().equals("HelloPortlet"));
+        assertTrue(cf.getType().equals(Fragment.PORTLET));
+
+        List properties = f.getProperties(root.getName());
+        List cloneProperties = cf.getProperties(cloneRoot.getName());
+        
+        assertNotNull(cloneProperties);
+        assertTrue(cloneProperties.size() == 2);
+        assertTrue(((Property) cloneProperties.get(0)).getName().equals("row"));
+        assertTrue(((Property) cloneProperties.get(0)).getValue().equals("0"));
+        assertTrue(((Property) cloneProperties.get(1)).getName().equals("column"));
+        assertTrue(((Property) cloneProperties.get(1)).getValue().equals("0"));
+
+        cf = (Fragment) cloneChildren.get(1);
+        f = (Fragment) children.get(1);
+        assertNotNull(cf.getId());
+        assertFalse(cf.getId().equals(f.getId()));
+        assertTrue(cf.getName().equals("JMXPortlet"));
+        assertTrue(cf.getType().equals(Fragment.PORTLET));
+
+        properties = cf.getProperties(root.getName());        
+        assertNotNull(properties);
+        assertTrue(properties.size() == 2);
+        assertTrue(((Property) properties.get(0)).getName().equals("row"));
+        assertTrue(((Property) properties.get(0)).getValue().equals("0"));
+        assertTrue(((Property) properties.get(1)).getName().equals("column"));
+        assertTrue(((Property) properties.get(1)).getValue().equals("1"));
+
+        f = testpage.getFragmentById("f002");
+        cf = (Fragment) cloneChildren.get(2);
+        String id = cf.getId();
+        cf = clone.getFragmentById(id);
+        
+        assertNotNull(cf);        
+        assertNotNull(cf.getId());        
+        assertFalse(cf.getId().equals(f.getId()));
+        assertTrue(cf.getName().equals("Card"));
+        assertTrue(cf.getType().equals(Fragment.LAYOUT));
+        assertTrue(cf.getDecorator().equals("Tab"));
+        assertNotNull(cf.getFragments());
+        assertTrue(cf.getFragments().size() == 2);
+        
+        // security testing
+        SecurityConstraints constraints = clone.getSecurityConstraints();
+        assertNotNull(constraints); 
+        assertTrue(constraints.getOwner().equals("new-user"));
+        List secs = constraints.getSecurityConstraints();
+        assertNotNull(secs);
+        assertTrue(secs.size() == 1);
+        SecurityConstraint constraint = (SecurityConstraint)secs.get(0);
+        assertNotNull(constraint);
+        assertTrue(constraint.getUsers().equals("user10,user11"));
+        assertTrue(constraint.getRoles().equals("*"));
+        assertTrue(constraint.getPermissions().equals("edit,view"));
+        List refs = constraints.getSecurityConstraintsRefs();
+        assertNotNull(refs);
+        assertTrue(refs.size() == 1);
+        String ref = (String)refs.get(0);
+        assertNotNull(ref);
+        assertTrue(ref.equals("public-view"));
+        
+        // TODO: menu testing
+    }
+    
 }



---------------------------------------------------------------------
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