portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tay...@apache.org
Subject cvs commit: jakarta-jetspeed/src/java/org/apache/jetspeed/services/portaltoolkit JetspeedPortalToolkitService.java
Date Thu, 07 Mar 2002 01:26:24 GMT
taylor      02/03/06 17:26:24

  Modified:    src/java/org/apache/jetspeed/services/portaltoolkit
                        JetspeedPortalToolkitService.java
  Log:
  - automatically give a portlet an id if it doesn't already have one defined in the psml
  
  Revision  Changes    Path
  1.13      +59 -6     jakarta-jetspeed/src/java/org/apache/jetspeed/services/portaltoolkit/JetspeedPortalToolkitService.java
  
  Index: JetspeedPortalToolkitService.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/services/portaltoolkit/JetspeedPortalToolkitService.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- JetspeedPortalToolkitService.java	6 Mar 2002 16:58:36 -0000	1.12
  +++ JetspeedPortalToolkitService.java	7 Mar 2002 01:26:24 -0000	1.13
  @@ -74,6 +74,7 @@
   
   import java.util.Enumeration;
   import java.util.Hashtable;
  +import java.util.Stack;
   import java.util.Map;
   import javax.servlet.ServletConfig;
   
  @@ -81,7 +82,7 @@
    * Simple implementation of the PortalFactoryService.
    * 
    * @author <a href="mailto:raphael@apache.org">RaphaŽl Luta</a>
  - * @version $Id: JetspeedPortalToolkitService.java,v 1.12 2002/03/06 16:58:36 taylor Exp
$
  + * @version $Id: JetspeedPortalToolkitService.java,v 1.13 2002/03/07 01:26:24 taylor Exp
$
    */
   public class JetspeedPortalToolkitService extends TurbineBaseService
       implements PortalToolkitService
  @@ -352,7 +353,19 @@
        */
       public PortletSet getSet( Portlets portlets )
       {
  -        return getSet( portlets, new VariableInteger(0) );
  +        Stack unidentified = new Stack();
  +        VariableInteger lastID = new VariableInteger(0);
  +        PortletSet pset = getSet( portlets, new VariableInteger(0), lastID, unidentified
);
  +        int nextID = lastID.getValue() + 1;
  +        while (!unidentified.empty())
  +        {
  +            //System.out.println("nextid = " + nextID);
  +            Portlet p = (Portlet)unidentified.pop();
  +            p.setID(String.valueOf(nextID));
  +            nextID++;
  +        }
  +        unidentified = null;
  +        return pset;
       }
       
       /**
  @@ -363,14 +376,16 @@
        * @param count the portletset number within the complete tree
        * @return a new instance of PortletSet
        */
  -    protected PortletSet getSet( Portlets portlets, VariableInteger theCount)
  +    protected PortletSet getSet( Portlets portlets, VariableInteger theCount, VariableInteger
lastID, Stack unidentified )
       {
           // Create a new BasePortletSet to handle the portlets
           BasePortletSet set = new BasePortletSet();
           PortletController controller = getController( portlets.getController() );
           set.setController( controller );
           set.setName(String.valueOf(theCount.getValue()));
  -        set.setID( portlets.getId() );
  +           
  +        String id = portlets.getId();
  +        setPortletID(id, set, unidentified, lastID);
           
           theCount.setValue(theCount.getValue()+1);
           
  @@ -386,7 +401,7 @@
           {
               Map constraints = getParameters(subsets[i].getLayout());
               int position = getPosition( subsets[i].getLayout() );
  -            set.addPortlet( getSet( subsets[i], theCount ),
  +            set.addPortlet( getSet( subsets[i], theCount, lastID, unidentified ),
                               controller.getConstraints(constraints),
                               position );
           }
  @@ -404,7 +419,9 @@
                   if ( entry != null )
                   {
                       Portlet p = PortletFactory.getPortlet( entries[i] );
  -                    p.setID( entries[i].getId() );
  +
  +                    id = entries[i].getId();
  +                    setPortletID(id, p, unidentified, lastID);
                       
                       if (p != null)
                       {
  @@ -442,6 +459,42 @@
           set.sortPortletSet();
           // Or return the set
           return set;
  +    }
  +
  +    /**
  +     * Sets the id for the given portlet or portletset
  +     * If the id is not found in the entry, adds the id to the list of unidentified portlets

  +     *
  +     * @param id  The id from the portlet entry
  +     * @param p   The portlet or portletset to have its id set
  +     * @param unidentified The collection of portlets that do not have an ID in the portlet
entry
  +     * @param lastID Keeps track of the last/highest ID number
  +     */
  +    protected String setPortletID(String id, Portlet p, Stack unidentified, VariableInteger
lastID)
  +    {
  +        if (id == null || id.equals(""))
  +        {
  +            unidentified.push(p);
  +            return null;
  +        }
  +        else
  +        {
  +            try 
  +            {
  +                int newID = Integer.parseInt(id);
  +                if (newID > lastID.getValue())
  +                {
  +                    lastID.setValue(newID);
  +                }
  +            }
  +            catch (Exception e)
  +            {
  +                unidentified.push(p);
  +                return null;
  +            }
  +            p.setID( id );
  +            return id;
  +        }
       }
   
       /**
  
  
  

--
To unsubscribe, e-mail:   <mailto:jetspeed-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:jetspeed-dev-help@jakarta.apache.org>


Mime
View raw message