portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jf...@apache.org
Subject cvs commit: jakarta-jetspeed/src/java/org/apache/jetspeed/modules/actions/portlets CustomizeSetAction.java
Date Mon, 03 Nov 2003 05:47:51 GMT
jford       2003/11/02 21:47:51

  Modified:    src/java/org/apache/jetspeed/modules/actions/portlets
                        CustomizeSetAction.java
  Log:
  Added the ability to filter the customizer portlet list by parent and category
  
  
  PR:Bugzilla #24343
  
  Revision  Changes    Path
  1.49      +70 -54    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.48
  retrieving revision 1.49
  diff -u -r1.48 -r1.49
  --- CustomizeSetAction.java	29 Oct 2003 22:25:51 -0000	1.48
  +++ CustomizeSetAction.java	3 Nov 2003 05:47:51 -0000	1.49
  @@ -91,6 +91,7 @@
   import org.apache.jetspeed.om.profile.psml.PsmlControl;
   import org.apache.jetspeed.om.profile.PSMLDocument;
   import org.apache.jetspeed.om.security.JetspeedUser;
  +import org.apache.jetspeed.services.customlocalization.CustomLocalization;
   import org.apache.jetspeed.services.idgenerator.JetspeedIdGenerator;
   import org.apache.jetspeed.services.JetspeedSecurity;
   import org.apache.jetspeed.services.logging.JetspeedLogFactoryService;
  @@ -106,7 +107,6 @@
   // Turbine stuff
   import org.apache.turbine.util.DynamicURI;
   import org.apache.turbine.util.RunData;
  -import org.apache.turbine.services.localization.Localization;
   
   
   // Velocity Stuff
  @@ -142,6 +142,9 @@
       private static final String ALL_PORTLET_LIST = "session.all.portlets.list";
       private static final String PORTLET_LIST_PAGE_SIZE = "session.portlets.page.size";
       private static final String HIDE_EMPTY_CATEGORIES = "customizer.hide.empty.categories";
  +    
  +    public static final String FILTER_FIELDS = "filter_fields";
  +    public static final String FILTER_VALUES = "filter_values";
   
       /**
        * Static initialization of the logger for this class
  @@ -297,6 +300,9 @@
               List categories = buildCategoryList(rundata, mediaType, allPortlets);
               context.put("categories", categories);
               
  +            context.put("parents", PortletFilter.buildParentList(allPortlets));
  +            addFiltersToContext(rundata, context);
  +            
               int size = getSize(portlet);               
               int end = Math.min(start + size, portlets.size());
                   
  @@ -743,7 +749,7 @@
                   }
                   else
                   {
  -                    String tmpl = Localization.getString(rundata, "CUSTOMIZER_ADD_REF_ERROR");
  +                    String tmpl = CustomLocalization.getString("CUSTOMIZER_ADD_REF_ERROR",
rundata);
                       Object[] args = {
                           refNames[i]
                       };
  @@ -1025,41 +1031,7 @@
       // Create a list of all available portlets
       public static List buildPortletList(RunData data, PortletSet set, String mediaType,
List allPortlets)
       {
  -        /* Can not use this as filtering of category requires us to rebuild the portlet
  -           list and the allPortlets list each time.
  -        List list = (List)PortletSessionState.getAttribute(data,PORTLET_LIST,null);
  -        if (list != null)
  -        {   
  -            allPortlets = (List)PortletSessionState.getAttribute(data,ALL_PORTLET_LIST,null);
  -            if (allPortlets != null)
  -            {
  -                return list;
  -            }
  -        }
  -        */    
  -        List list = new ArrayList();
  -        
  -        String mime = ((JetspeedRunData) data).getCapability()
  -                                              .getPreferredType()
  -                                              .toString();
  -                                             
  -        Iterator m = Registry.get(Registry.MEDIA_TYPE).listEntryNames();
  -//        
  -//        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;
  -//                }
  -//            }
  -//        }
  -                    
  +        List list = new ArrayList();                                                  
              
           Iterator i = Registry.get(Registry.PORTLET).listEntryNames();
           
           while (i.hasNext())
  @@ -1078,22 +1050,14 @@
                   && (!entry.getType().equals(PortletEntry.TYPE_ABSTRACT))
                   && entry.hasMediaType(mediaType)))
               {
  -                medias = entry.listMediaTypes();
  -//                Logme.now ("MediaTypes for entry: "+entry.getName()+"  type = "+entry.getType());
  -//                while (medias.hasNext())
  -//                {
  -//                  Logme.now ((String)medias.next());
  -//                }
  -//  
  -                // Filter by category
  -                String filterCat = (String)  data.getUser().getTemp("filter_category");
  -                if (filterCat == null || (filterCat.equals("All Portlets") || entry.hasCategory(filterCat)))
  -                {                
  -                    list.add(entry);
  -                }
  +                list.add(entry);
               }
           }
           
  +        String[] filterFields = (String[]) PortletSessionState.getAttribute(data, FILTER_FIELDS);
  +        String[] filterValues = (String[]) PortletSessionState.getAttribute(data, FILTER_VALUES);
  +        list = PortletFilter.filterPortlets(list, filterFields, filterValues);
  +        
           Collections.sort(list,
                   new Comparator() {
                       public int compare(Object o1, Object o2)
  @@ -1264,9 +1228,9 @@
               }
           }
           
  -        BaseCategory allCat = new BaseCategory();
  -                allCat.setName("All Portlets");
  -                catMap.put(allCat.getName(), allCat);
  +        //BaseCategory allCat = new BaseCategory();
  +          //      allCat.setName("All Portlets");
  +            //    catMap.put(allCat.getName(), allCat);
           return new ArrayList(catMap.values());
           
       }
  @@ -1294,8 +1258,60 @@
           JetspeedLinkFactory.putInstance(link);
           rundata.setRedirectURI(duri.toString());
           return;
  +    }
  +    
  +    /**
  +     * Adds a filter over the available portlets list based on category
  +     */
  +    public void doFilter(RunData rundata, Context context) throws Exception
  +    {
  +        String[] filterFields = rundata.getParameters().getStrings("filter_field");
  +        String[] filterValues = new String[filterFields.length];
  +        for(int i=0; i<filterFields.length; i++)
  +        {
  +            String filterField = filterFields[i];
  +            if(filterField != null)
  +            {
  +                String filterValue = rundata.getParameters().getString(filterField + ":filter_value");
  +                filterValues[i] = filterValue;
  +            }
  +         }
           
  +        PortletSessionState.setAttribute(rundata, FILTER_FIELDS, filterFields);
  +        PortletSessionState.setAttribute(rundata, FILTER_VALUES, filterValues);
  +         
  +        maintainUserSelections(rundata);
  +    
  +        String mtype = rundata.getParameters().getString("mtype", null);
  +        JetspeedLink link = JetspeedLinkFactory.getInstance(rundata);
  +        DynamicURI duri = null;
  +        if (mtype == null)
  +        {
  +            duri = link.setTemplate("Customize").addQueryData("start", "0");
  +        }
  +        else
  +        {
  +            duri = link.setTemplate("Customize").addQueryData("start", "0").addQueryData("mtype",
mtype);
  +        }
  +        JetspeedLinkFactory.putInstance(link);
  +        rundata.setRedirectURI(duri.toString());
  +        return;
  +    }
  +    
  +    private void addFiltersToContext(RunData data, Context context)
  +    {
  +        String[] filterFields = (String[]) PortletSessionState.getAttribute(data, FILTER_FIELDS);
  +        String[] filterValues = (String[]) PortletSessionState.getAttribute(data, FILTER_VALUES);
  +        if(filterFields != null && filterValues != null && filterFields.length
== filterValues.length)
  +        {
  +            for(int i=0; i<filterFields.length; i++)
  +            {
  +                String field = filterFields[i];
  +                String value = filterValues[i];
           
  +                context.put(field + "_filter_value", value);
  +            }
  +        }
       }
           
   }
  
  
  

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


Mime
View raw message