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/modules/actions/portlets PsmlBrowseAction.java PsmlUpdateAction.java
Date Wed, 03 Jul 2002 21:03:35 GMT
taylor      2002/07/03 14:03:35

  Modified:    src/java/org/apache/jetspeed/modules/actions/portlets
                        PsmlBrowseAction.java PsmlUpdateAction.java
  Log:
  Cached the browser and reconstruct it only when the result set is updated or the page size
is changed.
  Can customize the page size through the customizer.
  
  In the case of clones now the fields are pre populated.
  Mesia Type is a drop down populated through the registry.
  
  Revision  Changes    Path
  1.3       +96 -21    jakarta-jetspeed/src/java/org/apache/jetspeed/modules/actions/portlets/PsmlBrowseAction.java
  
  Index: PsmlBrowseAction.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/modules/actions/portlets/PsmlBrowseAction.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- PsmlBrowseAction.java	3 Jul 2002 02:13:57 -0000	1.2
  +++ PsmlBrowseAction.java	3 Jul 2002 21:03:35 -0000	1.3
  @@ -64,8 +64,11 @@
   import org.apache.jetspeed.om.profile.QueryLocator;
   import org.apache.jetspeed.om.profile.psml.PsmlEntry;
   import org.apache.jetspeed.portal.portlets.VelocityPortlet;
  +import org.apache.jetspeed.portal.portlets.browser.DatabaseBrowserIterator;
   import org.apache.jetspeed.services.Profiler;
   import org.apache.jetspeed.services.PsmlManager;
  +import org.apache.jetspeed.util.PortletConfigState;
  +import org.apache.jetspeed.util.PortletSessionState;
   
   // Turbine stuff
   import org.apache.turbine.util.Log;
  @@ -89,6 +92,33 @@
   public class PsmlBrowseAction extends VelocityPortletAction
   {
   
  +    protected static final String PSML_REFRESH_FLAG = "psmlRefreshFlag";
  +    protected static final String TRUE = "true";
  +    protected static final String FALSE = "false";
  +    protected static final String PROFILE_ITERATOR = "profileIterator";
  +    protected static final String PAGE_SIZE = "page-size";
  +    protected static final String CUSTOMIZE_TEMPLATE = "customize-template";
  +    private static final String PEID = "js_peid";
  +    /**
  +     * Subclasses should override this method if they wish to
  +     * provide their own customization behavior.
  +     * Default is to use Portal base customizer action
  +     */
  +    protected void buildConfigureContext( VelocityPortlet portlet,
  +                                          Context context,
  +                                          RunData rundata )
  +    {
  +        try
  +        {
  +            super.buildConfigureContext( portlet, context, rundata);
  +        }
  +        catch (Exception ex)
  +        {
  +            Log.error(ex);
  +        }
  +        context.put(PAGE_SIZE, PortletConfigState.getParameter(portlet, rundata, PAGE_SIZE,
"20"));
  +        setTemplate(rundata, PortletConfigState.getParameter(portlet, rundata, CUSTOMIZE_TEMPLATE,
null));
  +    }
       /**
        * Subclasses must override this method to provide default behavior
        * for the portlet action
  @@ -101,9 +131,7 @@
   
           if (start < 0) start = 0;
   
  -        String pageSize = portlet.getPortletConfig()
  -                                 .getInitParameter("page-size","20");
  -
  +        String pageSize = PortletConfigState.getParameter(portlet, rundata, PAGE_SIZE,
"20");
           int size = Integer.parseInt(pageSize);
   
           int next = start+size+1;
  @@ -111,35 +139,82 @@
   
           //System.out.println("start="+start+" size="+size+" next="+next+" prev="+prev);
   
  -        Iterator i = Profiler.query(new QueryLocator(QueryLocator.QUERY_ALL));
  -        Vector entries = new Vector();
  +        //check to see if resultset has changed due to PsmlUpdateAction
  +        //if so reconstruct the iterator and rest the flag
  +        boolean refreshFlag = (rundata.getUser().getTemp(PSML_REFRESH_FLAG, FALSE)).equals(TRUE);
  +        rundata.getUser().setTemp(PSML_REFRESH_FLAG, FALSE);
  +        //Get the iterator
  +        DatabaseBrowserIterator windowIterator =
  +            (DatabaseBrowserIterator)PortletSessionState.getAttribute(portlet, rundata,
PROFILE_ITERATOR);
  +        if (windowIterator == null || refreshFlag)
  +        {
  +            int index = 0;
  +            Iterator i = Profiler.query(new QueryLocator(QueryLocator.QUERY_ALL));
  +            Vector entries = new Vector();
  +            while(i.hasNext())
  +            {
  +                Profile profile = (Profile)i.next();
  +                //System.out.println("profile["+index+"]="+profile.getPath());
  +                entries.add(profile);
  +                index ++;
  +            }
  +            Vector entryType = new Vector();
  +            entryType.add("Profile");
  +            windowIterator = new DatabaseBrowserIterator(entries, entryType, entryType,
size);
  +            PortletSessionState.setAttribute(portlet, rundata, PROFILE_ITERATOR, windowIterator);
  +        }
  +        else
  +        {
  +            windowIterator.setTop(start);
  +        }
   
  -        int count = start;
  -        int index = 0;
   
  -        while(i.hasNext())
  +        if (windowIterator != null)
           {
  -            Profile profile = (Profile)i.next();
  -            //System.out.println("profile["+index+"]="+profile.getPath());
  -            if (count < (next - 1) && index >= count)
  +            context.put("psml", windowIterator);
  +            if (start > 0)
               {
  -                entries.add(profile);
  -                count++;
  +                context.put("prev", String.valueOf(prev + 1));
  +            }
  +            if (next <= windowIterator.getResultSetSize())
  +            {
  +                context.put("next", String.valueOf(next - 1));
               }
  -            index++;
  +
           }
  -        //System.out.println("count="+count+" total="+index);
  -        context.put("psml", entries);
  -        if (start > 0)
  +        else
           {
  -            context.put("prev",String.valueOf(prev+1));
  +            Log.error("No Psml entries Found");
           }
  -        if (    (count == (next - 1))
  -             && ( count <  index) )
  +
  +    }
  +
  +    /**
  +     * This method is called when the user configures any of the parameters.
  +     * @param data The turbine rundata context for this request.
  +     * @param context The velocity context for this request.
  +     */
  +    public void doUpdate(RunData rundata, Context context)
  +    {
  +        String pageSize = null;
  +
  +        VelocityPortlet portlet = (VelocityPortlet)context.get("portlet");
  +        if (portlet != null)
           {
  -            context.put("next",String.valueOf(next-1));
  +            String peid = portlet.getID();
  +            if(peid != null &&
  +               peid.equals(rundata.getParameters().getString(PEID)))
  +            {
  +                pageSize = rundata.getParameters().getString(PAGE_SIZE);
  +            }
  +            if (pageSize != null)
  +            {
  +                PortletConfigState.setInstanceParameter(portlet, rundata, PAGE_SIZE, pageSize);
  +                PortletSessionState.clearAttribute(portlet, rundata, PROFILE_ITERATOR);
  +            }
           }
   
  +        buildNormalContext( portlet, context, rundata);
       }
   
   }
  
  
  
  1.3       +59 -9     jakarta-jetspeed/src/java/org/apache/jetspeed/modules/actions/portlets/PsmlUpdateAction.java
  
  Index: PsmlUpdateAction.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/modules/actions/portlets/PsmlUpdateAction.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- PsmlUpdateAction.java	3 Jul 2002 02:13:57 -0000	1.2
  +++ PsmlUpdateAction.java	3 Jul 2002 21:03:35 -0000	1.3
  @@ -79,7 +79,9 @@
   import org.apache.jetspeed.om.profile.Portlets;
   import org.apache.jetspeed.portal.portlets.VelocityPortlet;
   import org.apache.jetspeed.services.Profiler;
  +import org.apache.jetspeed.services.Registry;
   import org.apache.jetspeed.services.JetspeedSecurity;
  +import org.apache.jetspeed.services.PsmlManager;
   import org.apache.jetspeed.util.template.JetspeedLink;
   import org.apache.jetspeed.util.template.JetspeedLinkFactory;
   import org.apache.jetspeed.services.resources.JetspeedResources;
  @@ -92,10 +94,14 @@
   public class PsmlUpdateAction extends VelocityPortletAction
   {
   
  +    protected static final String PSML_REFRESH_FLAG = "psmlRefreshFlag";
  +    protected static final String TRUE = "true";
  +    protected static final String FALSE = "false";
       protected static final String CATEGORY_NAME = "categoryName";
       protected static final String CATEGORY_VALUE = "categoryValue";
       protected static final String COPY_FROM = "copyFrom";
       protected static final String TEMP_LOCATOR = "tempLocator";
  +    protected static final String PSML_UPDATE_PANE = "PsmlForm";
       /**
        * Subclasses must override this method to provide default behavior
        * for the portlet action
  @@ -149,20 +155,54 @@
   
               if(mode != null && mode.equals(SecurityConstants.PARAM_MODE_INSERT))
               {
  +                org.apache.jetspeed.om.registry.Registry mediaTypes = Registry.get(Registry.MEDIA_TYPE);
  +                context.put("mediaTypes", mediaTypes.listEntryNames());
                   if (msgid == null)
                   {
  -                    context.put("categoryName", "user");
  -                    context.put("categoryValue", "anon");
                       if(path == null)
  +                    {
  +                        context.put(CATEGORY_NAME, "user");
  +                        context.put("categoryValue", "anon");
                           context.put("copyFrom", "user/anon/media-type/html/page/default.psml");
  +                    }
                       else
  +                    {
  +                        ProfileLocator tmpLocator = new BaseProfileLocator();
  +                        tmpLocator.createFromPath(path);
  +                        Profile profile = Profiler.getProfile(tmpLocator);
  +                        if (profile != null)
  +                        {
  +                            rundata.getUser().setTemp(TEMP_LOCATOR, tmpLocator);
  +                            context.put("profile", profile);
  +                        }
  +                        String categoryName = "group";
  +                        String categoryValue = tmpLocator.getGroupName();
  +                        if (categoryValue == null)
  +                        {
  +                            categoryName = "role";
  +                            categoryValue = tmpLocator.getRoleName();
  +                            if (categoryValue == null)
  +                            {
  +                                categoryName = "user";
  +                                categoryValue = tmpLocator.getUserName();
  +                                if (categoryValue == null)
  +                                {
  +                                    categoryName = "user";
  +                                    categoryValue = "anon";
  +                                }
  +                            }
  +
  +                        }
  +                        context.put(CATEGORY_NAME, categoryName);
  +                        context.put("categoryValue", categoryValue);
                           context.put("copyFrom", path);
  +                    }
                   }
                   else
                   {
  -                    context.put("categoryName", rundata.getUser().getTemp(CATEGORY_NAME));
  -                    context.put("categoryValue", rundata.getUser().getTemp(CATEGORY_VALUE));
  -                    context.put("copyFrom", rundata.getUser().getTemp(COPY_FROM));
  +                    context.put(CATEGORY_NAME, rundata.getUser().getTemp(CATEGORY_NAME));
  +                    context.put(CATEGORY_VALUE, rundata.getUser().getTemp(CATEGORY_VALUE));
  +                    context.put(COPY_FROM, rundata.getUser().getTemp(COPY_FROM));
                   }
               }
           }
  @@ -237,13 +277,17 @@
               }
   
               locator.setName(name);
  +
  +            //check if profile to be created already exists
  +            if (PsmlManager.getDocument(locator) != null )
  +                throw new EntityExistsException("Profile:"+locator.getPath()+" Already
Exists!");
               //
               // validate that its not an 'blank' profile -- not allowed
               //
               if (name == null || name.trim().length() == 0)
               {
                   JetspeedLink link = JetspeedLinkFactory.getInstance(rundata);
  -                DynamicURI duri = link.getPaneByName("PsmlForm")
  +                DynamicURI duri = link.getPaneByName(PSML_UPDATE_PANE)
                                         .addPathInfo(SecurityConstants.PARAM_MODE,
                                                      SecurityConstants.PARAM_MODE_INSERT)
                                         .addPathInfo(SecurityConstants.PARAM_MSGID,
  @@ -286,6 +330,7 @@
                   {
                       profile = Profiler.createProfile(locator, null);
                   }
  +                setRefreshPsmlFlag(rundata, TRUE);
               }
               else
               {
  @@ -301,7 +346,7 @@
               // dup key found - display error message - bring back to same screen
               //
               JetspeedLink link = JetspeedLinkFactory.getInstance(rundata);
  -            DynamicURI duri = link.getPaneByName("PsmlForm")
  +            DynamicURI duri = link.getPaneByName(PSML_UPDATE_PANE)
                                     .addPathInfo(SecurityConstants.PARAM_MODE,
                                                  SecurityConstants.PARAM_MODE_INSERT)
                                     .addPathInfo(SecurityConstants.PARAM_MSGID,
  @@ -318,7 +363,7 @@
               // dup key found - display error message - bring back to same screen
               //
               JetspeedLink link = JetspeedLinkFactory.getInstance(rundata);
  -            DynamicURI duri = link.getPaneByName("PsmlForm")
  +            DynamicURI duri = link.getPaneByName(PSML_UPDATE_PANE)
                                     .addPathInfo(SecurityConstants.PARAM_MODE,
                                                  SecurityConstants.PARAM_MODE_INSERT)
                                     .addPathInfo(SecurityConstants.PARAM_MSGID,
  @@ -349,6 +394,7 @@
               if (locator != null)
               {
                   Profiler.removeProfile(locator);
  +                setRefreshPsmlFlag(rundata, TRUE);
               }
               else
               {
  @@ -364,7 +410,7 @@
               // dup key found - display error message - bring back to same screen
               //
               JetspeedLink link = JetspeedLinkFactory.getInstance(rundata);
  -            DynamicURI duri = link.getPaneByName("PsmlForm")
  +            DynamicURI duri = link.getPaneByName(PSML_UPDATE_PANE)
                                     .addPathInfo(SecurityConstants.PARAM_MODE, SecurityConstants.PARAM_MODE_DELETE)
                                     .addPathInfo(SecurityConstants.PARAM_MSGID,
                                                  SecurityConstants.MID_DELETE_FAILED);
  @@ -374,6 +420,10 @@
   
       }
   
  +    public void setRefreshPsmlFlag(RunData rundata, String value)
  +    {
  +        rundata.getUser().setTemp(PSML_REFRESH_FLAG, TRUE);
  +    }
   
   }
   
  
  
  

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