raphael     01/07/23 14:48:07

  Modified:    src/java/org/apache/jetspeed/modules/actions/controllers
                        PanedControllerAction.java
                        RowColumnControllerAction.java
               src/java/org/apache/jetspeed/modules/actions/portlets
                        CustomizeSetAction.java
  Log:
  - fix portlet set customizer to check for control when updating controllers
  - factor positioned controller customizer between paned controller and row
  column controller
  
  Revision  Changes    Path
  1.4       +1 -367    
jakarta-jetspeed/src/java/org/apache/jetspeed/modules/actions/controllers/PanedControllerAction.java
  
  Index: PanedControllerAction.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/modules/actions/controllers/PanedControllerAction.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- PanedControllerAction.java        2001/07/22 20:31:11     1.3
  +++ PanedControllerAction.java        2001/07/23 21:48:07     1.4
  @@ -74,10 +74,6 @@
   import org.apache.velocity.context.Context;
   
   import java.util.Enumeration;
  -import java.util.Iterator;
  -import java.util.ArrayList;
  -import java.util.List;
  -import java.util.Collections;
   
   /**
    * This action builds a context suitable for controllers portlets
  @@ -88,9 +84,8 @@
    * 
    * @author <a href="mailto:[EMAIL PROTECTED]";>Rapha�l Luta</a>
    */
  -public class PanedControllerAction extends VelocityControllerAction
  +public class PanedControllerAction extends RowColumnControllerAction
   {
  -
       /** 
        * Adds a "pane" portlet object in the context which represents the
        * currently selected pane
  @@ -169,366 +164,5 @@
           
           Log.debug("PanedController: pane found "+pane+" context object 
"+context.get("pane"));
           cont.savePaneName(rundata,pane);
  -    }
  -
  -    /** 
  -     * Adds a "pane" portlet object in the context which represents the
  -     * currently selected pane
  -     */
  -    protected void buildCustomizeContext( PortletController controller, 
  -                                       Context context,
  -                                       RunData rundata )
  -    {
  -        super.buildCustomizeContext(controller, context, rundata);
  -        
  -        JetspeedRunData jdata = (JetspeedRunData)rundata;
  -        PortletSet set = (PortletSet)jdata.getCustomized();
  -        
  -        Portlets portlets = jdata.getProfile()
  -                                 .getDocument()
  -                                 .getPortlets(set.getName());
  -
  -        List plist = new ArrayList();
  -        List work = new ArrayList();
  -        List filler = Collections.nCopies(set.size(),null);
  -        plist.addAll(filler);
  -        
  -        for (int i=0; i < portlets.getPortletsCount(); i++)
  -        {
  -            Portlets p = portlets.getPortlets(i);
  -            Layout layout = p.getLayout();
  -            if (layout!=null)
  -            {
  -                try
  -                {
  -                    int pos = Integer.parseInt(layout.getPosition());
  -                    if (pos>=0)
  -                    {
  -                        plist.set(pos,p);
  -                    }
  -                    else
  -                    {
  -                        work.add(p);
  -                    }
  -                }
  -                catch (Exception e)
  -                {
  -                    layout.setPosition(null);
  -                    work.add(p);                    
  -                }
  -            }
  -            else
  -            {
  -                work.add(p);
  -            }
  -        }
  -
  -        for (int i=0; i < portlets.getEntryCount(); i++)
  -        {
  -            Entry p = portlets.getEntry(i);
  -            Layout layout = p.getLayout();
  -            if (layout!=null)
  -            {
  -                try
  -                {
  -                    int pos = Integer.parseInt(layout.getPosition());
  -                    if (pos>=0)
  -                    {
  -                        plist.set(pos,p);
  -                    }
  -                    else
  -                    {
  -                        work.add(p);
  -                    }
  -                }
  -                catch (Exception e)
  -                {
  -                    layout.setPosition(null);
  -                    work.add(p);                    
  -                }
  -            }
  -            else
  -            {
  -                work.add(p);
  -            }
  -        }
  -        
  -        Iterator i = work.iterator();
  -        for(int idx=0;idx < plist.size(); idx++)
  -        {
  -            if (plist.get(idx)==null)
  -            {
  -                if (i.hasNext())
  -                {
  -                    plist.set(idx,i.next());
  -                }
  -                else
  -                {
  -                    plist.remove(idx);
  -                }
  -            }
  -        }
  -        
  -        context.put("portlets",plist);
  -    }
  -
  -    public void doCancel(RunData data, Context context)
  -    {
  -        ((JetspeedRunData)data).setCustomized(null);
  -        if (((JetspeedRunData)data).getCustomized()==null)
  -        {
  -            data.setScreenTemplate("Home");
  -        }
  -    }
  -
  -    public void doSave(RunData data, Context context)
  -    {
  -        Profile profile = ((JetspeedRunData)data).getProfile();
  -
  -        try
  -        {
  -            profile.store();
  -        }
  -        catch (Exception e)
  -        {
  -            Log.error("Error while saving profile",e);
  -        }                                                
  -    }
  -
  -    public void doApply(RunData data, Context context)
  -    {
  -        doSave(data,context);
  -        doCancel(data,context);
  -    }
  -
  -    /** Remove a pane from the current set
  -     *  This method expects the following parameters
  -     * - paneid: the id a the pane to modify within the current profile
  -     * - position: the position of the component to delete
  -     */
  -    public void doDelete(RunData data, Context context)
  -    {
  -        JetspeedRunData jdata = (JetspeedRunData)data;
  -        PortletSet customizedSet = (PortletSet)jdata.getCustomized();
  -        int position = data.getParameters().getInt("position",-1);
  -        Profile profile = jdata.getProfile();
  -
  -        if (customizedSet == null) return;
  -
  -        if (position > -1)
  -        {
  -            Portlets set = profile.getDocument()
  -                                  .getPortlets(customizedSet.getName());
  -            if (set != null)
  -            {
  -                // first try explicit portlets position
  -                for(int i=0; i < set.getPortletsCount(); i++)
  -                {
  -                    Portlets p = set.getPortlets(i);
  -                    Layout layout = p.getLayout();
  -                    if (layout!=null)
  -                    {
  -                        int lpos = Integer.parseInt(layout.getPosition());
  -                        if (lpos==position)
  -                        {
  -                            set.removePortlets(i);
  -                            return;
  -                        }
  -                    }
  -                }
  -                
  -                // try explicit entry position
  -                for(int i=0; i < set.getEntryCount(); i++)
  -                {
  -                    Entry p = set.getEntry(i);
  -                    Layout layout = p.getLayout();
  -                    if (layout!=null)
  -                    {
  -                        int lpos = Integer.parseInt(layout.getPosition());
  -
  -                        if (lpos==position)
  -                        {
  -                            set.removeEntry(i);
  -                            return;
  -                        }
  -                    }
  -                }
  -                
  -                //else use implicit position
  -                if (position < set.getPortletsCount())
  -                {
  -                    set.removePortlets(position);
  -                    return;
  -                }
  -
  -                if (position < set.getEntryCount())
  -                {
  -                    set.removeEntry(position);
  -                    return;
  -                }
  -            }
  -        }
  -    }
  -    
  -    /** Move a component up within the pane
  -     *  This method expects the following parameters
  -     * - paneid: the id a the pane to modify within the current profile
  -     * - position: move the component which occupies this position
  -     */
  -    public void doUp(RunData data, Context context)
  -    {
  -        doMove(data,context,true);
  -    }
  -        
  -    /** Move a component down within the pane
  -     *  This method expects the following parameters
  -     * - paneid: the id a the pane to modify within the current profile
  -     * - position: move the component which occupies this position
  -     */
  -    public void doDown(RunData data, Context context)
  -    {
  -        doMove(data,context,false);
  -    }
  -        
  -    /** Move a component within the pane
  -     *  This method expects the following parameters
  -     * - paneid: the id a the pane to modify within the current profile
  -     * - position: move the component which occupies this position
  -     * The moveUp boolean determines the direction of the move
  -     */
  -    public void doMove(RunData data, Context context, boolean moveUp)
  -    {
  -        JetspeedRunData jdata = (JetspeedRunData)data;
  -        PortletSet customizedSet = (PortletSet)jdata.getCustomized();
  -        int position = data.getParameters().getInt("position",-1);
  -        Profile profile = jdata.getProfile();
  -        
  -        if (customizedSet == null) return;
  -        
  -        if (position > -1)
  -        {
  -            int target = -1;
  -            
  -            Portlets set = profile.getDocument()
  -                                  .getPortlets(customizedSet.getName());
  -            Layout targetLayout = null;
  -            Layout baseLayout = null;
  -
  -            if (set != null)
  -            {
  -                // check if we can possibly move as requested and calculate
  -                // target position
  -                if ( moveUp )
  -                {
  -                    if ( (position >= set.getPortletsCount()) 
  -                         && (position >= set.getEntryCount()) ) return;
  -                    target = position + 1;
  -                }
  -                else
  -                {
  -                    if (position ==0) return;
  -                    target = position - 1;
  -                }
  -
  -                // first find objects at explicit portlets position
  -                for(int i=0; i < set.getPortletsCount(); i++)
  -                {
  -                    if ((targetLayout!=null) && (baseLayout!=null)) break;
  -
  -                    Portlets p = set.getPortlets(i);
  -                    Layout layout = p.getLayout();
  -                    if (layout!=null)
  -                    {
  -                        int lpos = Integer.parseInt(layout.getPosition());
  -                        if ((baseLayout == null) && (lpos==position))
  -                        {
  -                            baseLayout = layout;
  -                        }
  -                        
  -                        if ((targetLayout == null) && (lpos==target))
  -                        {
  -                            targetLayout = layout;
  -                        }                        
  -                    }
  -                }
  -                
  -                // try explicit entry position
  -                for(int i=0; i < set.getEntryCount(); i++)
  -                {
  -                    if ((targetLayout!=null) && (baseLayout!=null)) break;
  -
  -                    Entry p = set.getEntry(i);
  -                    Layout layout = p.getLayout();
  -                    if (layout!=null)
  -                    {
  -                        int lpos = Integer.parseInt(layout.getPosition());
  -                        if ((baseLayout == null) && (lpos==position))
  -                        {
  -                            baseLayout = layout;
  -                        }
  -                        
  -                        if ((targetLayout == null) && (lpos==target))
  -                        {
  -                            targetLayout = layout;
  -                        }
  -                    }
  -                }
  -                
  -                //else use implicit position
  -                if (baseLayout == null)
  -                {
  -                    if (position < set.getPortletsCount())
  -                    {
  -                        Portlets p = set.getPortlets(position);
  -                        if (p.getLayout()==null)
  -                        {
  -                            p.setLayout(new Layout());
  -                        }
  -                        baseLayout=p.getLayout();
  -                    }
  -
  -                    if (position < set.getEntryCount())
  -                    {
  -                        Entry p = set.getEntry(position);
  -                        if (p.getLayout()==null)
  -                        {
  -                            p.setLayout(new Layout());
  -                        }
  -                        baseLayout=p.getLayout();
  -                    }
  -                }
  -
  -                if (targetLayout == null)
  -                {
  -                    if (target < set.getPortletsCount())
  -                    {
  -                        Portlets p = set.getPortlets(target);
  -                        if (p.getLayout()==null)
  -                        {
  -                            p.setLayout(new Layout());
  -                        }
  -                        targetLayout=p.getLayout();
  -                    }
  -
  -                    if (target < set.getEntryCount())
  -                    {
  -                        Entry p = set.getEntry(target);
  -                        if (p.getLayout()==null)
  -                        {
  -                            p.setLayout(new Layout());
  -                        }
  -                        targetLayout=p.getLayout();
  -                    }
  -                }
  -                
  -                //we should now have found both baseLayout and targetLayout, swap
  -                //their positions using explicit positioning
  -                
  -                if ((baseLayout == null) || (targetLayout == null)) return;
  -                
  -                baseLayout.setPosition(String.valueOf(target));
  -                targetLayout.setPosition(String.valueOf(position));                 
              
  -            }
  -        }
       }
   }
  
  
  
  1.4       +175 -75   
jakarta-jetspeed/src/java/org/apache/jetspeed/modules/actions/controllers/RowColumnControllerAction.java
  
  Index: RowColumnControllerAction.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/modules/actions/controllers/RowColumnControllerAction.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- RowColumnControllerAction.java    2001/07/22 20:31:11     1.3
  +++ RowColumnControllerAction.java    2001/07/23 21:48:07     1.4
  @@ -54,11 +54,14 @@
    
   package org.apache.jetspeed.modules.actions.controllers;
   
  +import org.apache.jetspeed.portal.PortletSet;
   import org.apache.jetspeed.portal.PortletController;
   import org.apache.jetspeed.portal.PortletControllerConfig;
   import org.apache.jetspeed.portal.PanedPortletController;
   import org.apache.jetspeed.services.rundata.JetspeedRunData;
  +import org.apache.jetspeed.services.Registry;
   import org.apache.jetspeed.om.profile.Profile;
  +import org.apache.jetspeed.om.newregistry.RegistryEntry;
   import org.apache.jetspeed.xml.api.portletmarkup.Portlets;
   import org.apache.jetspeed.xml.api.portletmarkup.Entry;
   import org.apache.jetspeed.xml.api.portletmarkup.Metainfo;
  @@ -74,6 +77,11 @@
   import java.util.Vector;
   import java.util.List;
   import java.util.StringTokenizer;
  +import java.util.Iterator;
  +import java.util.ArrayList;
  +import java.util.Map;
  +import java.util.HashMap;
  +import java.util.Collections;
   
   /**
    * This action builds a context suitable for controllers handlings simple
  @@ -120,41 +128,169 @@
       }
       
       /** 
  -     * This method is used to add a new pane in the current controller
  -     * The pane is always added at the end of the current set.
  -     * This methods expects the following parameters to work:
  -     * - paneid: the id a the pane to modify within the current profile
  -     * - title: the title for the new pane to be included
  +     * Adds a "pane" portlet object in the context which represents the
  +     * currently selected pane
        */
  -    public void doAdd(RunData data, Context context)
  +    protected void buildCustomizeContext( PortletController controller, 
  +                                       Context context,
  +                                       RunData rundata )
       {
  -        String paneid = data.getParameters().getString("paneid");
  -        String title = data.getParameters().getString("title");
  -        Profile profile = ((JetspeedRunData)data).getProfile();
  +        super.buildCustomizeContext(controller, context, rundata);
  +        
  +        JetspeedRunData jdata = (JetspeedRunData)rundata;
  +        PortletSet set = (PortletSet)jdata.getCustomized();
  +        
  +        Portlets portlets = jdata.getProfile()
  +                                 .getDocument()
  +                                 .getPortlets(set.getName());
  +
  +        List plist = new ArrayList();
  +        List work = new ArrayList();
  +        List filler = Collections.nCopies(set.size(),null);
  +        plist.addAll(filler);
           
  -        if ((paneid != null) && (title != null))
  +        for (int i=0; i < portlets.getPortletsCount(); i++)
           {
  -            Portlets set = profile.getDocument().getPortlets(paneid);
  -            if (set != null)
  +            Portlets p = portlets.getPortlets(i);
  +            Layout layout = p.getLayout();
  +            if (layout!=null)
  +            {
  +                try
  +                {
  +                    int pos = Integer.parseInt(layout.getPosition());
  +                    if (pos>=0)
  +                    {
  +                        plist.set(pos,p);
  +                    }
  +                    else
  +                    {
  +                        work.add(p);
  +                    }
  +                }
  +                catch (Exception e)
  +                {
  +                    layout.setPosition(null);
  +                    work.add(p);                    
  +                }
  +            }
  +            else
               {
  -                Portlets newset = new Portlets();
  -                Metainfo meta = new Metainfo();
  -                meta.setTitle(title);
  -                newset.setMetainfo(meta);
  -                set.addPortlets(newset);
  +                work.add(p);
  +            }
  +        }
   
  +        for (int i=0; i < portlets.getEntryCount(); i++)
  +        {
  +            Entry p = portlets.getEntry(i);
  +            Layout layout = p.getLayout();
  +            if (layout!=null)
  +            {
                   try
                   {
  -                    profile.store();
  +                    int pos = Integer.parseInt(layout.getPosition());
  +                    if (pos>=0)
  +                    {
  +                        plist.set(pos,p);
  +                    }
  +                    else
  +                    {
  +                        work.add(p);
  +                    }
                   }
                   catch (Exception e)
  +                {
  +                    layout.setPosition(null);
  +                    work.add(p);                    
  +                }
  +            }
  +            else
  +            {
  +                work.add(p);
  +            }
  +        }
  +        
  +        Iterator i = work.iterator();
  +        for(int idx=0;idx < plist.size(); idx++)
  +        {
  +            if (plist.get(idx)==null)
  +            {
  +                if (i.hasNext())
  +                {
  +                    plist.set(idx,i.next());
  +                }
  +                else
  +                {
  +                    plist.remove(idx);
  +                }
  +            }
  +        }
  +        
  +        Map titles = new HashMap();
  +        i = plist.iterator();
  +        while(i.hasNext())
  +        {
  +            Object obj = i.next();
  +            
  +            if (obj instanceof Portlets)
  +            {
  +                Portlets entry = (Portlets)obj;
  +                if 
((entry.getMetainfo()!=null)&&(entry.getMetainfo().getTitle()!=null))
  +                {
  +                    titles.put(entry.getName(),entry.getMetainfo().getTitle());
  +                }
  +            }
  +            else
  +            {    
  +                Entry entry = (Entry)obj;
  +                if 
((entry.getMetainfo()!=null)&&(entry.getMetainfo().getTitle()!=null))
  +                {
  +                    titles.put(entry.getParent(),entry.getMetainfo().getTitle());
  +                }
  +                else
                   {
  -                    Log.error("Error while saving profile",e);
  -                }                    
  +                    RegistryEntry pentry = 
Registry.getEntry(Registry.PORTLET,entry.getParent());
  +                
  +                    if (pentry!=null)
  +                    {
  +                        titles.put(entry.getParent(), pentry.getTitle());
  +                    }
  +                }
               }
           }
  +        
  +        context.put("portlets",plist);
  +        context.put("titles",titles);
       }
  -    
  +
  +    public void doCancel(RunData data, Context context)
  +    {
  +        ((JetspeedRunData)data).setCustomized(null);
  +        if (((JetspeedRunData)data).getCustomized()==null)
  +        {
  +            data.setScreenTemplate("Home");
  +        }
  +    }
  +
  +    public void doSave(RunData data, Context context)
  +    {
  +        Profile profile = ((JetspeedRunData)data).getProfile();
  +
  +        try
  +        {
  +            profile.store();
  +        }
  +        catch (Exception e)
  +        {
  +            Log.error("Error while saving profile",e);
  +        }                                                
  +    }
  +
  +    public void doApply(RunData data, Context context)
  +    {
  +        doSave(data,context);
  +        doCancel(data,context);
  +    }
  +
       /** Remove a pane from the current set
        *  This method expects the following parameters
        * - paneid: the id a the pane to modify within the current profile
  @@ -162,13 +298,17 @@
        */
       public void doDelete(RunData data, Context context)
       {
  -        String paneid = data.getParameters().getString("paneid");
  +        JetspeedRunData jdata = (JetspeedRunData)data;
  +        PortletSet customizedSet = (PortletSet)jdata.getCustomized();
           int position = data.getParameters().getInt("position",-1);
  -        Profile profile = ((JetspeedRunData)data).getProfile();
  +        Profile profile = jdata.getProfile();
  +
  +        if (customizedSet == null) return;
   
  -        if ((paneid != null) && (position > -1))
  +        if (position > -1)
           {
  -            Portlets set = profile.getDocument().getPortlets(paneid);
  +            Portlets set = profile.getDocument()
  +                                  .getPortlets(customizedSet.getName());
               if (set != null)
               {
                   // first try explicit portlets position
  @@ -182,14 +322,6 @@
                           if (lpos==position)
                           {
                               set.removePortlets(i);
  -                            try
  -                            {
  -                                profile.store();
  -                            }
  -                            catch (Exception e)
  -                            {
  -                                Log.error("Error while saving profile",e);
  -                            }                                                
                               return;
                           }
                       }
  @@ -207,14 +339,6 @@
                           if (lpos==position)
                           {
                               set.removeEntry(i);
  -                            try
  -                            {
  -                                profile.store();
  -                            }
  -                            catch (Exception e)
  -                            {
  -                                Log.error("Error while saving profile",e);
  -                            }                                                
                               return;
                           }
                       }
  @@ -224,30 +348,12 @@
                   if (position < set.getPortletsCount())
                   {
                       set.removePortlets(position);
  -                    try
  -                    {
  -                        profile.store();
  -                    }
  -                    catch (Exception e)
  -                    {
  -                        Log.error("Error while saving profile",e);
  -                    }                                                
  -
                       return;
                   }
   
                   if (position < set.getEntryCount())
                   {
                       set.removeEntry(position);
  -                    try
  -                    {
  -                        profile.store();
  -                    }
  -                    catch (Exception e)
  -                    {
  -                        Log.error("Error while saving profile",e);
  -                    }                                                
  -
                       return;
                   }
               }
  @@ -282,16 +388,19 @@
        */
       public void doMove(RunData data, Context context, boolean moveUp)
       {
  -        String paneid = data.getParameters().getString("paneid");
  +        JetspeedRunData jdata = (JetspeedRunData)data;
  +        PortletSet customizedSet = (PortletSet)jdata.getCustomized();
           int position = data.getParameters().getInt("position",-1);
  +        Profile profile = jdata.getProfile();
           
  -        Profile profile = ((JetspeedRunData)data).getProfile();
  +        if (customizedSet == null) return;
           
  -        if ((paneid != null) && (position > -1))
  +        if (position > -1)
           {
               int target = -1;
               
  -            Portlets set = profile.getDocument().getPortlets(paneid);
  +            Portlets set = profile.getDocument()
  +                                  .getPortlets(customizedSet.getName());
               Layout targetLayout = null;
               Layout baseLayout = null;
   
  @@ -318,7 +427,7 @@
   
                       Portlets p = set.getPortlets(i);
                       Layout layout = p.getLayout();
  -                    if (layout!=null)
  +                    if ((layout!=null)&&(layout.getPosition()!=null))
                       {
                           int lpos = Integer.parseInt(layout.getPosition());
                           if ((baseLayout == null) && (lpos==position))
  @@ -340,7 +449,7 @@
   
                       Entry p = set.getEntry(i);
                       Layout layout = p.getLayout();
  -                    if (layout!=null)
  +                    if ((layout!=null)&&(layout.getPosition()!=null))
                       {
                           int lpos = Integer.parseInt(layout.getPosition());
                           if ((baseLayout == null) && (lpos==position))
  @@ -409,16 +518,7 @@
                   
                   baseLayout.setPosition(String.valueOf(target));
                   targetLayout.setPosition(String.valueOf(position));                 
              
  -
  -                try
  -                {
  -                    profile.store();
  -                }
  -                catch (Exception e)
  -                {
  -                    Log.error("Error while saving profile",e);
  -                }                                                
               }
           }
  -    }    
  +    }
   }
  
  
  
  1.7       +111 -4    
jakarta-jetspeed/src/java/org/apache/jetspeed/modules/actions/portlets/CustomizeSetAction.java
  
  Index: CustomizeSetAction.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/modules/actions/portlets/CustomizeSetAction.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- CustomizeSetAction.java   2001/07/22 20:31:11     1.6
  +++ CustomizeSetAction.java   2001/07/23 21:48:07     1.7
  @@ -64,7 +64,9 @@
   import org.apache.jetspeed.services.TemplateLocator;
   import org.apache.jetspeed.services.rundata.JetspeedRunData;
   import org.apache.jetspeed.om.profile.Profile;
  +import org.apache.jetspeed.om.newregistry.RegistryEntry;
   import org.apache.jetspeed.om.newregistry.PortletEntry;
  +import org.apache.jetspeed.om.newregistry.PortletInfoEntry;
   import org.apache.jetspeed.om.newregistry.MediaTypeEntry;
   import org.apache.jetspeed.xml.api.portletmarkup.Portlets;
   import org.apache.jetspeed.xml.api.portletmarkup.Entry;
  @@ -143,8 +145,8 @@
           context.put("skin", set.getPortletConfig().getPortletSkin());
           context.put("set", set);
           context.put("action","portlets.CustomizeSetAction");        
  -        
context.put("controllers",Registry.get(Registry.PORTLET_CONTROLLER).toArray());
  -        context.put("skins",Registry.get(Registry.SKIN).toArray());
  +        context.put("controllers", buildInfoList(rundata, 
Registry.PORTLET_CONTROLLER));
  +        context.put("skins", buildList(rundata, Registry.SKIN));
           context.put("currentController", set.getController().getConfig().getName());
           context.put("currentSkin", 
set.getPortletConfig().getPortletSkin().getName());
   
  @@ -155,7 +157,6 @@
           else
           {
               context.put("allowportlet", "true");
  -            context.put("allowpane","true");
           }
               
           if ("add".equals(mode)) // build context for add mode
  @@ -337,8 +338,21 @@
                       {
                           c = new Controller();
                           portlets.setController(c);
  +                    }
  +                    c.setName(controller);
  +                    
  +                    String linkedControl = 
pc.getConfig().getInitParameter("control");
  +
  +                    if (linkedControl!=null)
  +                    {
  +                        Control ctl = new Control();
  +                        ctl.setName(linkedControl);
  +                        portlets.setControl(ctl);
                       }
  -                    c.setName(controller);                    
  +                    else
  +                    {
  +                        portlets.setControl(null);
  +                    }
                   }
               }
           }
  @@ -438,6 +452,99 @@
                           String t2 = (((PortletEntry)o2).getTitle() != null)
                               ?((PortletEntry)o2).getTitle()
                               :((PortletEntry)o2).getName();
  +                        
  +                        return t1.compareTo(t2);
  +                    }
  +                } );
  +        
  +        return list;
  +    }
  +    
  +    public static List buildInfoList(RunData data, String regName)
  +    {
  +        List list = new ArrayList();
  +        
  +        String mime = ((JetspeedRunData)data).getCapability()
  +                                             .getPreferredType()
  +                                             .toString();
  +                                             
  +        Iterator m = Registry.get(Registry.MEDIA_TYPE).listEntryNames();
  +        String mediaName = "html";
  +        
  +        while(m.hasNext())
  +        {
  +            MediaTypeEntry me = (MediaTypeEntry)
  +                Registry.getEntry(Registry.MEDIA_TYPE,(String)m.next());
  +            
  +            if (me!=null)
  +            {
  +                if (mime.equals(me.getMimeType()))
  +                {
  +                    mediaName = me.getName();
  +                    break;
  +                }
  +            }
  +        }
  +                    
  +        Iterator i = Registry.get(regName).listEntryNames();
  +        
  +        while(i.hasNext())
  +        {
  +            PortletInfoEntry entry = (PortletInfoEntry)Registry.getEntry(regName,
  +                                                                 (String)i.next());
  +            
  +            //FIXME: we should add security testing
  +            if ((!entry.isHidden())
  +                && entry.hasMediaType(mediaName))
  +            {
  +                list.add(entry);
  +            }
  +        }
  +        
  +        Collections.sort(list,
  +                new Comparator() {
  +                    public int compare(Object o1, Object o2)
  +                    {
  +                        String t1 = (((RegistryEntry)o1).getTitle() != null)
  +                            ?((RegistryEntry)o1).getTitle()
  +                            :((RegistryEntry)o1).getName();
  +                        String t2 = (((RegistryEntry)o2).getTitle() != null)
  +                            ?((RegistryEntry)o2).getTitle()
  +                            :((RegistryEntry)o2).getName();
  +                        
  +                        return t1.compareTo(t2);
  +                    }
  +                } );
  +        
  +        return list;
  +    }
  +    
  +    public static List buildList(RunData data, String regName)
  +    {
  +        List list = new ArrayList();
  +        
  +        Iterator i = Registry.get(regName).listEntryNames();        
  +        while(i.hasNext())
  +        {
  +            RegistryEntry entry = Registry.getEntry(regName,(String)i.next());
  +            
  +            //FIXME: we should add security testing
  +            if (!entry.isHidden())
  +            {
  +                list.add(entry);
  +            }
  +        }
  +        
  +        Collections.sort(list,
  +                new Comparator() {
  +                    public int compare(Object o1, Object o2)
  +                    {
  +                        String t1 = (((RegistryEntry)o1).getTitle() != null)
  +                            ?((RegistryEntry)o1).getTitle()
  +                            :((RegistryEntry)o1).getName();
  +                        String t2 = (((RegistryEntry)o2).getTitle() != null)
  +                            ?((RegistryEntry)o2).getTitle()
  +                            :((RegistryEntry)o2).getName();
                           
                           return t1.compareTo(t2);
                       }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to