[portal-commits] JBoss Portal SVN: r5774 - in trunk: common/src/main/org/jboss/portal/common/util core/src/main/org/jboss/portal/core/deployment/jboss core/src/main/org/jboss/portal/core/impl/model/portal core/src/main/org/jboss/portal/core/metadata core/src/main/org/jboss/portal/core/model/portal core/src/main/org/jboss/portal/core/model/portal/command core/src/main/org/jboss/portal/core/portlet/management core/src/main/org/jboss/portal/test/core/model/portal core/src/resources/portal-core-sar/conf/data

portal-commits at lists.jboss.org portal-commits at lists.jboss.org
Sat Dec 9 12:55:37 EST 2006


Author: julien at jboss.com
Date: 2006-12-09 12:55:16 -0500 (Sat, 09 Dec 2006)
New Revision: 5774

Added:
   trunk/core/src/main/org/jboss/portal/core/metadata/ContextMetaData.java
Modified:
   trunk/common/src/main/org/jboss/portal/common/util/Tools.java
   trunk/core/src/main/org/jboss/portal/core/deployment/jboss/ObjectDeployment.java
   trunk/core/src/main/org/jboss/portal/core/impl/model/portal/ContextImpl.java
   trunk/core/src/main/org/jboss/portal/core/impl/model/portal/PageImpl.java
   trunk/core/src/main/org/jboss/portal/core/impl/model/portal/PersistentPortalObjectContainer.java
   trunk/core/src/main/org/jboss/portal/core/impl/model/portal/PortalImpl.java
   trunk/core/src/main/org/jboss/portal/core/impl/model/portal/PortalObjectIdImpl.java
   trunk/core/src/main/org/jboss/portal/core/impl/model/portal/PortalObjectImpl.java
   trunk/core/src/main/org/jboss/portal/core/impl/model/portal/WindowImpl.java
   trunk/core/src/main/org/jboss/portal/core/metadata/PortalObjectMetaData.java
   trunk/core/src/main/org/jboss/portal/core/model/portal/PortalContainer.java
   trunk/core/src/main/org/jboss/portal/core/model/portal/PortalObject.java
   trunk/core/src/main/org/jboss/portal/core/model/portal/PortalObjectId.java
   trunk/core/src/main/org/jboss/portal/core/model/portal/command/ViewDashboardCommand.java
   trunk/core/src/main/org/jboss/portal/core/portlet/management/LazyPortalObjectTreeNode.java
   trunk/core/src/main/org/jboss/portal/test/core/model/portal/PortalObjectContainerTestCase.java
   trunk/core/src/main/org/jboss/portal/test/core/model/portal/PortalObjectIdTestCase.java
   trunk/core/src/resources/portal-core-sar/conf/data/default-object.xml
Log:
- added iterator(Object[] objects, int from, int to) in Tools
- use now a portal per user instead of a page per user in the dashboard
- added a portal called "template" that is used to implicitely create the default dashboard when the user wants to use its dashboard the first time
- added a PortalObject.copy(PortalObject parent, String name) operation to facilitate the cloning of a portal object subtree used in the dashboard creation for a particular user

Modified: trunk/common/src/main/org/jboss/portal/common/util/Tools.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/common/util/Tools.java	2006-12-09 02:41:26 UTC (rev 5773)
+++ trunk/common/src/main/org/jboss/portal/common/util/Tools.java	2006-12-09 17:55:16 UTC (rev 5774)
@@ -465,10 +465,17 @@
       return list;
    }
 
+   /**
+    * Returns a singleton iterator.
+    *
+    * @param o the singleton object
+    * @return the iterator
+    */
    public static Iterator iterator(final Object o)
    {
       return new Iterator()
       {
+         /** The status of the iterator. */
          boolean done = false;
 
          public boolean hasNext()
@@ -493,23 +500,53 @@
       };
    }
 
-   public static Iterator iterator(final Object[] objects)
+   /**
+    * Returns an iterator over the array elements.
+    *
+    * @param objects the array containing the objects to iterate on
+    * @return the iterator
+    * @throws IllegalArgumentException if the object array is null or the specified range is not valid
+    */
+   public static Iterator iterator(final Object[] objects) throws IllegalArgumentException
    {
+      if (objects == null)
+      {
+         throw new IllegalArgumentException("No null object array");
+      }
+      return iterator(objects, 0, objects.length);
+   }
+
+   /**
+    * Returns an iterator over the array elements within the specified range.
+    *
+    * @param objects the array containing the objects to iterate on
+    * @param from the inclusive start index
+    * @param to the exclusive stop index
+    * @return the iterator
+    * @throws IllegalArgumentException if the object array is null or the specified range is not valid
+    */
+   public static Iterator iterator(final Object[] objects, final int from, final int to) throws IllegalArgumentException
+   {
+      if (objects == null)
+      {
+         throw new IllegalArgumentException("No null object array");
+      }
+      if (from > to || from < 0 || to > objects.length)
+      {
+         throw new IllegalArgumentException("Invalid range [" + from + "," + to + "] for array of length " + objects.length);
+      }
       return new Iterator()
       {
-         int index = 0;
+         /** . */
+         int index = from;
 
          public boolean hasNext()
          {
-            return objects != null && index < objects.length;
+            return index < to;
          }
 
          public Object next()
          {
-            if (objects == null)
-            {
-               throw new NoSuchElementException("Wrapped array is null");
-            }
             if (index >= objects.length)
             {
                throw new NoSuchElementException("Index is greater than the array length");

Modified: trunk/core/src/main/org/jboss/portal/core/deployment/jboss/ObjectDeployment.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/core/deployment/jboss/ObjectDeployment.java	2006-12-09 02:41:26 UTC (rev 5773)
+++ trunk/core/src/main/org/jboss/portal/core/deployment/jboss/ObjectDeployment.java	2006-12-09 17:55:16 UTC (rev 5774)
@@ -147,6 +147,10 @@
                if (metaDataElt == null)
                {
                   metaDataElt = XML.getUniqueChild(deploymentElt, "window", false);
+                  if (metaDataElt == null)
+                  {
+                     metaDataElt = XML.getUniqueChild(deploymentElt, "context", false);
+                  }
                }
             }
             if (metaDataElt != null)

Modified: trunk/core/src/main/org/jboss/portal/core/impl/model/portal/ContextImpl.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/core/impl/model/portal/ContextImpl.java	2006-12-09 02:41:26 UTC (rev 5773)
+++ trunk/core/src/main/org/jboss/portal/core/impl/model/portal/ContextImpl.java	2006-12-09 17:55:16 UTC (rev 5774)
@@ -27,6 +27,8 @@
 import org.jboss.portal.core.model.portal.Portal;
 import org.jboss.portal.core.model.portal.PortalObject;
 
+import java.util.HashMap;
+
 /**
  * @author <a href="mailto:julien at jboss.org">Julien Viet</a>
  * @version $Revision$
@@ -46,14 +48,10 @@
 
    public Portal getPortal(String name)
    {
-      ObjectNode childNode = (ObjectNode)objectNode.getChildren().get(name);
-      if (childNode != null)
+      PortalObject child = getChild(name);
+      if (child instanceof Portal)
       {
-         PortalObjectImpl childObject = childNode.getObject();
-         if (childObject instanceof Portal)
-         {
-            return (Portal)childObject;
-         }
+         return (Portal)child;
       }
       return null;
    }
@@ -79,8 +77,32 @@
       return null;
    }
 
+   public PortalContainer createPortalContainer(String name) throws DuplicatePortalObjectException
+   {
+      ContextImpl portalContainer = new ContextImpl(false);
+      addChild(name, portalContainer);
+      return portalContainer;
+   }
+
+   public PortalContainer getPortalContainer(String name) throws IllegalArgumentException
+   {
+      PortalObject child = getChild(name);
+      if (child instanceof PortalContainer)
+      {
+         return (PortalContainer)child;
+      }
+      return null;
+   }
+
    public int getType()
    {
       return PortalObject.TYPE_CONTEXT;
    }
+
+   protected PortalObjectImpl cloneObject()
+   {
+      ContextImpl clone = new ContextImpl();
+      clone.setDeclaredPropertyMap(new HashMap(getDeclaredPropertyMap()));
+      return clone;
+   }
 }

Modified: trunk/core/src/main/org/jboss/portal/core/impl/model/portal/PageImpl.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/core/impl/model/portal/PageImpl.java	2006-12-09 02:41:26 UTC (rev 5773)
+++ trunk/core/src/main/org/jboss/portal/core/impl/model/portal/PageImpl.java	2006-12-09 17:55:16 UTC (rev 5774)
@@ -28,6 +28,8 @@
 import org.jboss.portal.core.model.portal.PortalObject;
 import org.jboss.portal.core.model.portal.Window;
 
+import java.util.HashMap;
+
 /**
  * @author <a href="mailto:julien at jboss.org">Julien Viet</a>
  * @version $Revision$
@@ -57,14 +59,10 @@
 
    public Page getPage(String name)
    {
-      ObjectNode childNode = (ObjectNode)objectNode.getChildren().get(name);
-      if (childNode != null)
+      PortalObject child = getChild(name);
+      if (child instanceof Page)
       {
-         PortalObjectImpl childObject = childNode.getObject();
-         if (childObject instanceof Page)
-         {
-            return (Page)childObject;
-         }
+         return (Page)child;
       }
       return null;
    }
@@ -78,14 +76,10 @@
 
    public Window getWindow(String name)
    {
-      ObjectNode childNode = (ObjectNode)objectNode.getChildren().get(name);
-      if (childNode != null)
+      PortalObject child = getChild(name);
+      if (child instanceof Window)
       {
-         PortalObjectImpl childObject = childNode.getObject();
-         if (childObject instanceof Window)
-         {
-            return (Window)childObject;
-         }
+         return (Window)child;
       }
       return null;
    }
@@ -101,4 +95,11 @@
    {
       return PortalObject.TYPE_PAGE;
    }
+
+   protected PortalObjectImpl cloneObject()
+   {
+      PageImpl clone = new PageImpl();
+      clone.setDeclaredPropertyMap(new HashMap(getDeclaredPropertyMap()));
+      return clone;
+   }
 }

Modified: trunk/core/src/main/org/jboss/portal/core/impl/model/portal/PersistentPortalObjectContainer.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/core/impl/model/portal/PersistentPortalObjectContainer.java	2006-12-09 02:41:26 UTC (rev 5773)
+++ trunk/core/src/main/org/jboss/portal/core/impl/model/portal/PersistentPortalObjectContainer.java	2006-12-09 17:55:16 UTC (rev 5774)
@@ -38,6 +38,8 @@
 
 import EDU.oswego.cs.dl.util.concurrent.ConcurrentReaderHashMap;
 
+import java.util.List;
+
 /**
  * @author <a href="mailto:julien at jboss.org">Julien Viet</a>
  * @version $Revision$
@@ -254,6 +256,7 @@
 
    private ObjectNode getObjectNodeNoCache(Session session, String path)
    {
+      List results;
       if (path.length() == 0)
       {
          // For oracle where an empty path is treated as null so we need to add that here
@@ -261,15 +264,20 @@
          Query query = session.createQuery(LOOKUP_QUERY_FOR_NULL_PATH);
          query.setParameter("path", path);
          query.setCacheable(true);
-         return (ObjectNode)query.uniqueResult();
+         results = query.list();
       }
       else
       {
          Criteria criteria = session.createCriteria(ObjectNode.class);
          criteria.add(Restrictions.naturalId().set("path", path));
          criteria.setCacheable(true);
-         return (ObjectNode)criteria.uniqueResult();
+         results = criteria.list();
       }
+      if (results.isEmpty())
+      {
+         return null;
+      }
+      return (ObjectNode)results.get(0);
    }
 
    private ObjectNode getObjectNode(Session session, String path)

Modified: trunk/core/src/main/org/jboss/portal/core/impl/model/portal/PortalImpl.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/core/impl/model/portal/PortalImpl.java	2006-12-09 02:41:26 UTC (rev 5773)
+++ trunk/core/src/main/org/jboss/portal/core/impl/model/portal/PortalImpl.java	2006-12-09 17:55:16 UTC (rev 5774)
@@ -29,6 +29,7 @@
 
 import java.util.HashSet;
 import java.util.Set;
+import java.util.HashMap;
 
 /**
  * @author <a href="mailto:julien at jboss.org">Julien Viet</a>
@@ -85,14 +86,10 @@
 
    public Page getPage(String name)
    {
-      ObjectNode childNode = (ObjectNode)objectNode.getChildren().get(name);
-      if (childNode != null)
+      PortalObject child = getChild(name);
+      if (child instanceof Page)
       {
-         PortalObjectImpl childObject = childNode.getObject();
-         if (childObject instanceof Page)
-         {
-            return (Page)childObject;
-         }
+         return (Page)child;
       }
       return null;
    }
@@ -122,4 +119,13 @@
       }
       return null;
    }
+
+   protected PortalObjectImpl cloneObject()
+   {
+      PortalImpl clone = new PortalImpl();
+      clone.setWindowStates(new HashSet(getWindowStates()));
+      clone.setModes(new HashSet(getModes()));
+      clone.setDeclaredPropertyMap(new HashMap(getDeclaredPropertyMap()));
+      return clone;
+   }
 }

Modified: trunk/core/src/main/org/jboss/portal/core/impl/model/portal/PortalObjectIdImpl.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/core/impl/model/portal/PortalObjectIdImpl.java	2006-12-09 02:41:26 UTC (rev 5773)
+++ trunk/core/src/main/org/jboss/portal/core/impl/model/portal/PortalObjectIdImpl.java	2006-12-09 17:55:16 UTC (rev 5774)
@@ -58,7 +58,7 @@
       super(names);
 
       //
-      this.internalId = LEGACY_FORMAT.toString(names);
+      this.internalId = LEGACY_FORMAT.toString(names, 0, names.length);
    }
 
    PortalObjectIdImpl(PortalObjectImpl object)

Modified: trunk/core/src/main/org/jboss/portal/core/impl/model/portal/PortalObjectImpl.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/core/impl/model/portal/PortalObjectImpl.java	2006-12-09 02:41:26 UTC (rev 5773)
+++ trunk/core/src/main/org/jboss/portal/core/impl/model/portal/PortalObjectImpl.java	2006-12-09 17:55:16 UTC (rev 5774)
@@ -103,7 +103,6 @@
 
    //
 
-
    public PortalObjectId getId()
    {
       if (id == null)
@@ -123,6 +122,43 @@
       return objectNode.getName();
    }
 
+
+   public PortalObject copy(PortalObject parent, String name) throws DuplicatePortalObjectException, IllegalArgumentException
+   {
+      if (parent == null)
+      {
+         throw new IllegalArgumentException("No null parent accepted");
+      }
+      if (name == null)
+      {
+         throw new IllegalArgumentException("No null name accepted");
+      }
+      return copy((PortalObjectImpl)parent, name);
+   }
+
+   private PortalObjectImpl copy(PortalObjectImpl parent, String name) throws DuplicatePortalObjectException
+   {
+      // Clone this node
+      PortalObjectImpl clone = cloneObject();
+
+      // Add the clone to the specified parent
+      parent.addChild(name, clone);
+
+      // Clone children reccursively
+      for (Iterator i = getChildren().iterator();i.hasNext();)
+      {
+         PortalObjectImpl child = (PortalObjectImpl)i.next();
+
+         //
+         child.copy(clone, child.getName());
+      }
+
+      //
+      return clone;
+   }
+
+   protected abstract PortalObjectImpl cloneObject();
+
    public Collection getChildren()
    {
       if (collection == null)
@@ -247,6 +283,10 @@
 
    public PortalObject getChild(String name)
    {
+      if (name == null)
+      {
+         throw new IllegalArgumentException();
+      }
       ObjectNode childNode = (ObjectNode)objectNode.getChildren().get(name);
       if (childNode != null)
       {

Modified: trunk/core/src/main/org/jboss/portal/core/impl/model/portal/WindowImpl.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/core/impl/model/portal/WindowImpl.java	2006-12-09 02:41:26 UTC (rev 5773)
+++ trunk/core/src/main/org/jboss/portal/core/impl/model/portal/WindowImpl.java	2006-12-09 17:55:16 UTC (rev 5774)
@@ -25,6 +25,8 @@
 import org.jboss.portal.core.model.portal.PortalObject;
 import org.jboss.portal.core.model.portal.Window;
 
+import java.util.HashMap;
+
 /**
  * @author <a href="mailto:julien at jboss.org">Julien Viet</a>
  * @version $Revision$
@@ -60,4 +62,12 @@
    {
       return PortalObject.TYPE_WINDOW;
    }
+
+   protected PortalObjectImpl cloneObject()
+   {
+      WindowImpl clone = new WindowImpl();
+      clone.setInstanceRef(instanceRef);
+      clone.setDeclaredPropertyMap(new HashMap(getDeclaredPropertyMap()));
+      return clone;
+   }
 }

Added: trunk/core/src/main/org/jboss/portal/core/metadata/ContextMetaData.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/core/metadata/ContextMetaData.java	2006-12-09 02:41:26 UTC (rev 5773)
+++ trunk/core/src/main/org/jboss/portal/core/metadata/ContextMetaData.java	2006-12-09 17:55:16 UTC (rev 5774)
@@ -0,0 +1,92 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat                                               *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual                    *
+ * contributors as indicated by the @authors tag. See the                     *
+ * copyright.txt in the distribution for a full listing of                    *
+ * individual contributors.                                                   *
+ *                                                                            *
+ * This is free software; you can redistribute it and/or modify it            *
+ * under the terms of the GNU Lesser General Public License as                *
+ * published by the Free Software Foundation; either version 2.1 of           *
+ * the License, or (at your option) any later version.                        *
+ *                                                                            *
+ * This software is distributed in the hope that it will be useful,           *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU           *
+ * Lesser General Public License for more details.                            *
+ *                                                                            *
+ * You should have received a copy of the GNU Lesser General Public           *
+ * License along with this software; if not, write to the Free                *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA         *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.                   *
+ ******************************************************************************/
+package org.jboss.portal.core.metadata;
+
+import org.jboss.portal.core.model.portal.PortalObject;
+import org.jboss.portal.core.model.portal.PortalContainer;
+import org.jboss.portal.common.util.XML;
+import org.w3c.dom.Element;
+
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * @author <a href="mailto:julien at jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class ContextMetaData extends PortalObjectMetaData
+{
+   public PortalObject create(PortalObject parent, BuildContext buildContext) throws Exception
+   {
+      if (parent instanceof PortalContainer == false)
+      {
+         throw new IllegalArgumentException("Not a context");
+      }
+
+      //
+      PortalContainer container = ((PortalContainer)parent).createPortalContainer(getName());
+
+      //
+      configure(container, buildContext);
+
+      //
+      for (Iterator i = getChildren().values().iterator(); i.hasNext();)
+      {
+         PortalObjectMetaData portalObjectMD = (PortalObjectMetaData)i.next();
+         portalObjectMD.create(container, buildContext);
+      }
+
+      //
+      return container;
+   }
+
+   /** Parse the following XML elements : context-name. */
+   public static ContextMetaData buildContextMetaData(Element contextElt) throws Exception
+   {
+      ContextMetaData contextMD = new ContextMetaData();
+
+      //
+      String contextName = XML.asString(XML.getUniqueChild(contextElt, "context-name", true));
+      if (contextName != null && contextName.length() > 0 && contextName.indexOf(".") < 0)
+      {
+         contextMD.setName(contextName);
+      }
+      else
+      {
+         throw new IllegalArgumentException("Invalid context-name: '" + contextName
+            + "'. Must not be null, empty or contain a '.'");
+      }
+
+      //
+      List pageElts = XML.getChildren(contextElt, "portal");
+      for (int i = 0; i < pageElts.size(); i++)
+      {
+         Element portalElt = (Element)pageElts.get(i);
+         PortalMetaData pageMD = (PortalMetaData)PortalObjectMetaData.buildMetaData(portalElt);
+         contextMD.getChildren().put(pageMD.getName(), pageMD);
+      }
+
+      //
+      return contextMD;
+   }
+}

Modified: trunk/core/src/main/org/jboss/portal/core/metadata/PortalObjectMetaData.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/core/metadata/PortalObjectMetaData.java	2006-12-09 02:41:26 UTC (rev 5773)
+++ trunk/core/src/main/org/jboss/portal/core/metadata/PortalObjectMetaData.java	2006-12-09 17:55:16 UTC (rev 5774)
@@ -185,6 +185,12 @@
       {
          portalObjectMD = WindowMetaData.buildWindowMetaData(portalObjectElt);
       }
+      else if ("context".equals(type))
+      {
+         portalObjectMD = ContextMetaData.buildContextMetaData(portalObjectElt);
+      }
+
+      // Parse common XML stuff
       if (portalObjectMD != null)
       {
          // Add the security constraints

Modified: trunk/core/src/main/org/jboss/portal/core/model/portal/PortalContainer.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/core/model/portal/PortalContainer.java	2006-12-09 02:41:26 UTC (rev 5773)
+++ trunk/core/src/main/org/jboss/portal/core/model/portal/PortalContainer.java	2006-12-09 17:55:16 UTC (rev 5774)
@@ -56,4 +56,25 @@
     * @return the default portal of that container
     */
    Portal getDefaultPortal();
+
+   /**
+    * Returns an existing portal container or null if such a child does not exist or does not have the appropriate type.
+    *
+    * @param name the portal container name
+    * @return the specified portal container
+    * @throws IllegalArgumentException if the specified name is null
+    */
+   PortalContainer getPortalContainer(String name) throws IllegalArgumentException;
+
+   /**
+    * Creates a new portal container.
+    *
+    * @param name the portal container name
+    * @return the newly created portal container
+    * @throws DuplicatePortalObjectException if a child with the specified name already exists
+    * @throws IllegalArgumentException if the name argument is null
+    */
+   PortalContainer createPortalContainer(String name) throws DuplicatePortalObjectException, IllegalArgumentException;
+
+
 }

Modified: trunk/core/src/main/org/jboss/portal/core/model/portal/PortalObject.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/core/model/portal/PortalObject.java	2006-12-09 02:41:26 UTC (rev 5773)
+++ trunk/core/src/main/org/jboss/portal/core/model/portal/PortalObject.java	2006-12-09 17:55:16 UTC (rev 5774)
@@ -118,6 +118,17 @@
    void destroyChild(String name) throws NoSuchPortalObjectException, IllegalArgumentException;
 
    /**
+    * Copy the portal object as a child of the specified object.
+    *
+    * @param parent the parent of the copy
+    * @param name the name of the child
+    * @return the newly created node child of the specified parent
+    * @throws DuplicatePortalObjectException if the specified parent has already a node with such a name
+    * @throws IllegalArgumentException if the specified parent is null
+    */
+   PortalObject copy(PortalObject parent, String name) throws DuplicatePortalObjectException, IllegalArgumentException;
+
+   /**
     * Return a property of that object.
     *
     * @return the property value

Modified: trunk/core/src/main/org/jboss/portal/core/model/portal/PortalObjectId.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/core/model/portal/PortalObjectId.java	2006-12-09 02:41:26 UTC (rev 5773)
+++ trunk/core/src/main/org/jboss/portal/core/model/portal/PortalObjectId.java	2006-12-09 17:55:16 UTC (rev 5774)
@@ -37,12 +37,28 @@
 public class PortalObjectId implements Comparable
 {
 
+   /** . */
+   private static final String[] EMPTY_STRINGS = new String[0];
+
    /** The composites. */
    private final String[] names;
 
+   /** Inclusive start index. */
+   private final int from;
+
+   /** Exclusive stop index. */
+   private final int to;
+
    /** The lazy computed hash code. */
    private Integer hashCode;
 
+   public PortalObjectId()
+   {
+      this.names = EMPTY_STRINGS;
+      this.from = 0;
+      this.to = 0;
+   }
+
    /**
     * Copy constructor.
     *
@@ -54,6 +70,8 @@
       ParameterValidation.throwIllegalArgExceptionIfNull(that, "PortalObjectId to be copied");
       this.names = that.names;
       this.hashCode = that.hashCode;
+      this.from = that.from;
+      this.to = that.to;
    }
 
    /**
@@ -66,9 +84,34 @@
    {
       ParameterValidation.throwIllegalArgExceptionIfNull(names, "composing names");
       this.names = names;
+      this.from = 0;
+      this.to = names.length;
    }
 
    /**
+    * Build an id directly from its composing names.
+    *
+    * @param names the id names
+    * @throws IllegalArgumentException if any argument is null or not well formed
+    */
+   private PortalObjectId(String[] names, int from, int to) throws IllegalArgumentException
+   {
+      ParameterValidation.throwIllegalArgExceptionIfNull(names, "composing names");
+      this.names = names;
+      this.from = from;
+      this.to = to;
+   }
+
+   public PortalObjectId blah() throws IllegalStateException
+   {
+      if (from == to)
+      {
+         throw new IllegalStateException();
+      }
+      return new PortalObjectId(names, from + 1, to);
+   }
+
+   /**
     * Build an id by parsing a string representation.
     *
     * @param value  the string representation
@@ -79,8 +122,28 @@
    {
       ParameterValidation.throwIllegalArgExceptionIfNull(format, "Format");
       this.names = format.parse(value);
+      this.from = 0;
+      this.to = names.length;
    }
 
+   public int getLength()
+   {
+      return from - to;
+   }
+
+   public String getName(int index)
+   {
+      if (index < from)
+      {
+         throw new IllegalArgumentException();
+      }
+      if (index >= to)
+      {
+         throw new IllegalArgumentException();
+      }
+      return names[index - from];
+   }
+
    public boolean equals(Object obj)
    {
       if (obj == this)
@@ -90,19 +153,23 @@
       if (obj instanceof PortalObjectId)
       {
          PortalObjectId that = (PortalObjectId)obj;
+         String[] thisNames = this.names;
          String[] thatNames = that.names;
-         String[] thisNames = this.names;
 
          //
-         if (thatNames.length != thisNames.length)
+         int thisLen = this.to - this.from;
+         int thatLen = that.to - that.from;
+         if (thisLen != thatLen)
          {
             return false;
          }
 
          //
-         for (int i = thisNames.length - 1; i >= 0; i--)
+         int thisIdx = this.from;
+         int thatIdx = that.from;
+         while (thisLen-- > 0)
          {
-            if (!thisNames[i].equals(thatNames[i]))
+            if (!thisNames[thisIdx++].equals(thatNames[thatIdx++]))
             {
                return false;
             }
@@ -119,7 +186,7 @@
       if (hashCode == null)
       {
          int value = 0;
-         for (int i = names.length - 1; i >= 0; i--)
+         for (int i = to - 1; i >= from; i--)
          {
             value = value * 41 + names[i].hashCode();
          }
@@ -140,13 +207,13 @@
     */
    public Iterator names()
    {
-      return Tools.iterator(names);
+      return Tools.iterator(names, from, to);
    }
 
    /** Returns the canonical representation of the id. */
    public String toString()
    {
-      return CANONICAL_FORMAT.toString(names);
+      return CANONICAL_FORMAT.toString(names, from, to);
    }
 
    /**
@@ -158,7 +225,7 @@
    public String toString(Format format)
    {
       ParameterValidation.throwIllegalArgExceptionIfNull(format, "Format");
-      return format.toString(names);
+      return format.toString(names, from, to);
    }
 
    public static PortalObjectId parse(String value, Format format)
@@ -179,7 +246,7 @@
        * @param names
        * @return
        */
-      public abstract String toString(String[] names) throws IllegalArgumentException;
+      public abstract String toString(String[] names, int from, int to) throws IllegalArgumentException;
 
       /**
        * @param id
@@ -188,7 +255,7 @@
       public final String toString(PortalObjectId id) throws IllegalArgumentException
       {
          ParameterValidation.throwIllegalArgExceptionIfNull(id, "PortalObjectId");
-         return toString(id.names);
+         return toString(id.names, id.from, id.to);
       }
    }
 
@@ -241,17 +308,17 @@
          return names;
       }
 
-      public String toString(String[] names)
+      public String toString(String[] names, int from, int to)
       {
          ParameterValidation.throwIllegalArgExceptionIfNull(names, "name string array");
-         if (names.length == 0)
+         if (from == to)
          {
             return "/";
          }
          else
          {
             StringBuffer tmp = new StringBuffer(names.length * 10);
-            for (int i = 0; i < names.length; i++)
+            for (int i = from; i < to; i++)
             {
                String name = names[i];
                if (name == null)
@@ -300,15 +367,15 @@
          return names;
       }
 
-      public String toString(String[] names)
+      public String toString(String[] names, int from, int to)
       {
          ParameterValidation.throwIllegalArgExceptionIfNull(names, "name string array");
-         if (names.length == 0)
+         if (from == to)
          {
             return "";
          }
-         StringBuffer buffer = new StringBuffer(names.length * 8);
-         for (int i = 0; i < names.length; i++)
+         StringBuffer buffer = new StringBuffer((to - from) * 8);
+         for (int i = from; i < to; i++)
          {
             if (i > 0)
             {

Modified: trunk/core/src/main/org/jboss/portal/core/model/portal/command/ViewDashboardCommand.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/core/model/portal/command/ViewDashboardCommand.java	2006-12-09 02:41:26 UTC (rev 5773)
+++ trunk/core/src/main/org/jboss/portal/core/model/portal/command/ViewDashboardCommand.java	2006-12-09 17:55:16 UTC (rev 5774)
@@ -29,29 +29,32 @@
 import org.jboss.portal.core.model.portal.command.response.UpdateViewResponse;
 import org.jboss.portal.core.model.portal.DuplicatePortalObjectException;
 import org.jboss.portal.core.model.portal.Page;
-import org.jboss.portal.core.model.portal.PortalObject;
-import org.jboss.portal.core.model.portal.Window;
 import org.jboss.portal.core.model.portal.PortalObjectId;
+import org.jboss.portal.core.model.portal.Portal;
+import org.jboss.portal.core.model.portal.PortalContainer;
 import org.jboss.portal.security.PortalSecurityException;
 import org.jboss.portal.security.spi.auth.PortalAuthorizationManager;
 
-import java.util.Iterator;
-import java.util.Map;
-
 /**
  * @author <a href="mailto:julien at jboss.org">Julien Viet</a>
  * @version $Revision: 1.1 $
  */
-public class ViewDashboardCommand extends PortalCommand
+public class ViewDashboardCommand extends PortalObjectCommand
 {
 
    /** . */
    private static final CommandInfo info = new ViewCommandInfo(false, "view");
 
    /** . */
+   private Portal dashboardPortal;
+
+   /** . */
    private Page dashboardPage;
 
    /** . */
+   private PortalContainer dashboardContext;
+
+   /** . */
    private String userId;
 
    public ViewDashboardCommand(PortalObjectId portalId)
@@ -64,12 +67,58 @@
       return info;
    }
 
+   public PortalContainer getDashboardContext()
+   {
+      return dashboardContext;
+   }
+
+   public Portal getDashboardPortal()
+   {
+      return dashboardPortal;
+   }
+
+   public Page getDashboardPage()
+   {
+      return dashboardPage;
+   }
+
+   /**
+    * Initialize the command
+    *
+    * @throws org.jboss.portal.common.invocation.InvocationException
+    *
+    */
    public void create() throws ControllerException
    {
       super.create();
 
       //
+      dashboardContext = (PortalContainer)getTarget();
+
+      //
       userId = getControllerContext().getServerInvocation().getServerContext().getClientRequest().getRemoteUser();
+
+      try
+      {
+         //
+         dashboardPortal = dashboardContext.getPortal(userId);
+
+         // Create if not exist
+         if (dashboardPortal == null)
+         {
+            Portal templatePortal = (Portal)context.getController().getPortalObjectContainer().getObject(new PortalObjectId("/template", PortalObjectId.CANONICAL_FORMAT));
+
+            // Copy the template portal
+            dashboardPortal = (Portal)templatePortal.copy(dashboardContext, userId);
+         }
+
+         //
+         dashboardPage = dashboardPortal.getDefaultPage();
+      }
+      catch (DuplicatePortalObjectException e)
+      {
+         throw new ControllerException(e);
+      }
    }
 
    public void enforceSecurity(PortalAuthorizationManager pam) throws ControllerSecurityException, PortalSecurityException
@@ -82,45 +131,6 @@
 
    public Object execute() throws ControllerException
    {
-      dashboardPage = portal.getPage(userId);
-
-      // Create if not exist 
-      if (dashboardPage == null)
-      {
-         try
-         {
-            dashboardPage = portal.createPage(userId);
-            Page templatePage = (Page)portal.getParent().getChild("default").getChild("default");
-            for (Iterator i = templatePage.getChildren().iterator(); i.hasNext();)
-            {
-               PortalObject child = (PortalObject)i.next();
-               if (child.getType() == PortalObject.TYPE_WINDOW)
-               {
-                  Window window = (Window)child;
-                  Window newWindow = dashboardPage.createWindow(window.getName());
-                  newWindow.setInstanceRef(window.getInstanceRef());
-                  for (Iterator j = window.getDeclaredProperties().entrySet().iterator(); j.hasNext();)
-                  {
-                     Map.Entry entry = (Map.Entry)j.next();
-                     String name = (String)entry.getKey();
-                     String value = (String)entry.getValue();
-                     newWindow.setDeclaredProperty(name, value);
-                  }
-               }
-            }
-         }
-         catch (DuplicatePortalObjectException e)
-         {
-            throw new ControllerException(e);
-         }
-      }
-
-      //
       return new UpdateViewResponse(dashboardPage.getId());
    }
-
-   public Page getDashboardPage()
-   {
-      return dashboardPage;
-   }
-}
+}
\ No newline at end of file

Modified: trunk/core/src/main/org/jboss/portal/core/portlet/management/LazyPortalObjectTreeNode.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/core/portlet/management/LazyPortalObjectTreeNode.java	2006-12-09 02:41:26 UTC (rev 5773)
+++ trunk/core/src/main/org/jboss/portal/core/portlet/management/LazyPortalObjectTreeNode.java	2006-12-09 17:55:16 UTC (rev 5774)
@@ -64,7 +64,6 @@
       switch (object.getType())
       {
          case PortalObject.TYPE_CONTEXT:
-            description = "root";
             type = "context";
             break;
          case PortalObject.TYPE_PORTAL:

Modified: trunk/core/src/main/org/jboss/portal/test/core/model/portal/PortalObjectContainerTestCase.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/test/core/model/portal/PortalObjectContainerTestCase.java	2006-12-09 02:41:26 UTC (rev 5773)
+++ trunk/core/src/main/org/jboss/portal/test/core/model/portal/PortalObjectContainerTestCase.java	2006-12-09 17:55:16 UTC (rev 5774)
@@ -37,8 +37,11 @@
 import org.jboss.portal.common.test.TestParametrization;
 import org.jboss.portal.common.test.junit.JUnitAdapter;
 import org.jboss.portal.common.test.junit.POJOJUnitTest;
+import org.jboss.portal.WindowState;
+import org.jboss.portal.Mode;
 
 import java.net.URL;
+import java.util.Collections;
 
 /**
  * Portal Object Container Test Cases based on the microcontainer architecture
@@ -229,10 +232,6 @@
 
       //
       hibernate.openSession();
-      assertTrue(hibernate.commitTransaction());
-
-      //
-      hibernate.openSession();
       PortalContainer ctx = (PortalContainer)container.getRootObject();
       Portal portal = ctx.createPortal("default");
       assertNotNull(portal);
@@ -255,6 +254,50 @@
       container.stop();
    }
 
+   public void testCopy() throws Exception
+   {
+      container.start();
+
+      //
+      PortalObjectId defaultId = new PortalObjectId(new String[]{"portal"});
+
+      //
+      hibernate.openSession();
+      PortalContainer ctx = (PortalContainer)container.getRootObject();
+      Portal portal = ctx.createPortal("portal");
+      portal.setDeclaredProperty("portalname", "portalvalue");
+      portal.getSupportedWindowStates().add(WindowState.NORMAL);
+      portal.getSupportedModes().add(Mode.VIEW);
+      Page page = portal.createPage("default");
+      page.setDeclaredProperty("pagename", "pagevalue");
+      Window window = page.createWindow("window");
+      window.setDeclaredProperty("windowname", "windowvalue");
+      window.setInstanceRef("instance");
+      assertTrue(hibernate.commitTransaction());
+
+      //
+      hibernate.openSession();
+      ctx = (PortalContainer)container.getRootObject();
+      portal = (Portal)container.getObject(defaultId);
+      portal = (Portal)portal.copy(ctx, "copy");
+      assertNotNull(portal);
+      assertEquals("copy", portal.getName());
+      assertEquals(Collections.singleton(WindowState.NORMAL), portal.getSupportedWindowStates());
+      assertEquals(Collections.singleton(Mode.VIEW), portal.getSupportedModes());
+      assertEquals("portalvalue", portal.getDeclaredProperty("portalname"));
+      page = portal.getPage("default");
+      assertNotNull(page);
+      assertEquals("pagevalue", page.getDeclaredProperty("pagename"));
+      window = page.getWindow("window");
+      assertNotNull(window);
+      assertEquals("windowvalue", window.getDeclaredProperty("windowname"));
+      assertEquals("instance", window.getInstanceRef());
+      assertTrue(hibernate.commitTransaction());
+
+      //
+      container.stop();
+   }
+
 //   private void constructPortalObjects() throws Exception
 //   {
 //      Context root = container.getContext();

Modified: trunk/core/src/main/org/jboss/portal/test/core/model/portal/PortalObjectIdTestCase.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/test/core/model/portal/PortalObjectIdTestCase.java	2006-12-09 02:41:26 UTC (rev 5773)
+++ trunk/core/src/main/org/jboss/portal/test/core/model/portal/PortalObjectIdTestCase.java	2006-12-09 17:55:16 UTC (rev 5774)
@@ -112,7 +112,7 @@
    {
       try
       {
-         format.toString((String[])null);
+         format.toString(null, 0, 0);
          fail();
       }
       catch (IllegalArgumentException expected)
@@ -128,7 +128,7 @@
       }
       try
       {
-         format.toString(new String[]{"a",null,"b"});
+         format.toString(new String[]{"a",null,"b"}, 0, 3);
          fail();
       }
       catch (IllegalArgumentException expected)

Modified: trunk/core/src/resources/portal-core-sar/conf/data/default-object.xml
===================================================================
--- trunk/core/src/resources/portal-core-sar/conf/data/default-object.xml	2006-12-09 02:41:26 UTC (rev 5773)
+++ trunk/core/src/resources/portal-core-sar/conf/data/default-object.xml	2006-12-09 17:55:16 UTC (rev 5774)
@@ -162,8 +162,8 @@
    <deployment>
       <parent-ref/>
       <if-exists>keep</if-exists>
-      <portal>
-         <portal-name>dashboard</portal-name>
+      <context>
+         <context-name>dashboard</context-name>
          <properties>
             <!--
             | Set the layout for the default portal, see also portal-layouts.xml.
@@ -210,9 +210,106 @@
                <action-name>dashboard</action-name>
             </policy-permission>
          </security-constraint>
+      </context>
+   </deployment>
+   <deployment>
+      <parent-ref/>
+      <if-exists>keep</if-exists>
+      <portal>
+         <portal-name>template</portal-name>
+         <properties>
+            <!--
+            | Set the layout for the default portal, see also portal-layouts.xml.
+            -->
+            <property>
+               <name>layout.id</name>
+               <value>generic</value>
+            </property>
+            <!--
+            | Set the theme for the default portal, see also portal-themes.xml.
+            -->
+            <property>
+               <name>theme.id</name>
+               <value>renaissance</value>
+            </property>
+            <!--
+            | Set the default render set name (used by the render tag in layouts), see also portal-renderSet.xml
+            -->
+            <property>
+               <name>theme.renderSetId</name>
+               <value>divRenderer</value>
+            </property>
+            <!--
+            | Set the default strategy name (used by the strategy interceptor), see also portal-strategies.xml
+            -->
+            <property>
+               <name>layout.strategyId</name>
+               <value>maximizedRegion</value>
+            </property>
+            <!--
+            | The default page name, if the property is not explicited then the default page name is "default"
+            -->
+            <property>
+               <name>portal.defaultObjectName</name>
+               <value>default</value>
+            </property>
+         </properties>
+         <supported-modes>
+            <mode>view</mode>
+            <mode>edit</mode>
+            <mode>help</mode>
+         </supported-modes>
+         <supported-window-states>
+            <window-state>normal</window-state>
+            <window-state>minimized</window-state>
+            <window-state>maximized</window-state>
+         </supported-window-states>
+         <page>
+            <page-name>default</page-name>
+            <properties>
+               <property>
+                  <name>order</name>
+                  <value>1</value>
+               </property>
+            </properties>
+            <window>
+               <window-name>JSPPortletWindow</window-name>
+               <instance-ref>JSPPortletInstance</instance-ref>
+               <region>left</region>
+               <height>0</height>
+            </window>
+            <window>
+               <window-name>DefaultCMSPortletWindow</window-name>
+               <instance-ref>CMSPortletInstance</instance-ref>
+               <region>center</region>
+               <height>0</height>
+               <properties>
+                  <!-- use the window renderer from the emptyRenderer renderSet -->
+                  <property>
+                     <name>theme.windowRendererId</name>
+                     <value>emptyRenderer</value>
+                  </property>
+                  <!-- use the decoration renderer from the emptyRenderer renderSet -->
+                  <property>
+                     <name>theme.decorationRendererId</name>
+                     <value>emptyRenderer</value>
+                  </property>
+                  <!-- use the portlet renderer from the emptyRenderer renderSet -->
+                  <property>
+                     <name>theme.portletRendererId</name>
+                     <value>emptyRenderer</value>
+                  </property>
+               </properties>
+            </window>
+            <window>
+               <window-name>UserPortletWindow</window-name>
+               <instance-ref>UserPortletInstance</instance-ref>
+               <region>left</region>
+               <height>1</height>
+            </window>
+         </page>
       </portal>
    </deployment>
-
    <deployment>
       <parent-ref/>
       <if-exists>keep</if-exists>




More information about the portal-commits mailing list