You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-dev@portals.apache.org by ta...@apache.org on 2004/08/03 07:06:17 UTC

cvs commit: jakarta-jetspeed/fusion/src/java/org/apache/jetspeed/fusion/modules/actions/portlets AbstractPortletApplicationAction.java RegisterPortletApplicationAction.java

taylor      2004/08/02 22:06:17

  Modified:    fusion/src/java/org/apache/jetspeed/fusion/modules/actions/portlets
                        AbstractPortletApplicationAction.java
                        RegisterPortletApplicationAction.java
  Log:
  Portlet application registration (sans deploy) an registration UI completed
  CVS: ----------------------------------------------------------------------
  CVS: PR:
  CVS:   If this change addresses a PR in the problem report tracking
  CVS:   database, then enter the PR number(s) here.
  CVS: Obtained from:
  CVS:   If this change has been taken from another system, such as NCSA,
  CVS:   then name the system in this line, otherwise delete it.
  CVS: Submitted by:
  CVS:   If this code has been contributed to Apache by someone else; i.e.,
  CVS:   they sent us a patch or a new module, then include their name/email
  CVS:   address here. If this is your work then delete this line.
  CVS: Reviewed by:
  CVS:   If we are doing pre-commit code reviews and someone else has
  CVS:   reviewed your changes, include their name(s) here.
  CVS:   If you have not had it reviewed then delete this line.
  
  Revision  Changes    Path
  1.2       +2 -2      jakarta-jetspeed/fusion/src/java/org/apache/jetspeed/fusion/modules/actions/portlets/AbstractPortletApplicationAction.java
  
  Index: AbstractPortletApplicationAction.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed/fusion/src/java/org/apache/jetspeed/fusion/modules/actions/portlets/AbstractPortletApplicationAction.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- AbstractPortletApplicationAction.java	2 Aug 2004 19:33:42 -0000	1.1
  +++ AbstractPortletApplicationAction.java	3 Aug 2004 05:06:16 -0000	1.2
  @@ -71,7 +71,7 @@
           return new PortletApplicationViewBean(pa.getName(), pa.getWebApplicationDefinition().getContextRoot());
       }
       
  -    private DeploymentRegistration getRegistrationComponent()
  +    protected DeploymentRegistration getRegistrationComponent()
       {
           if (registrar != null)
           {
  
  
  
  1.3       +127 -62   jakarta-jetspeed/fusion/src/java/org/apache/jetspeed/fusion/modules/actions/portlets/RegisterPortletApplicationAction.java
  
  Index: RegisterPortletApplicationAction.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed/fusion/src/java/org/apache/jetspeed/fusion/modules/actions/portlets/RegisterPortletApplicationAction.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- RegisterPortletApplicationAction.java	2 Aug 2004 21:01:59 -0000	1.2
  +++ RegisterPortletApplicationAction.java	3 Aug 2004 05:06:16 -0000	1.3
  @@ -15,9 +15,15 @@
    */
   package org.apache.jetspeed.fusion.modules.actions.portlets;
   
  +import java.io.InputStream;
  +
  +import javax.servlet.ServletContext;
  +
   import org.apache.jetspeed.modules.actions.portlets.security.SecurityConstants;
   import org.apache.jetspeed.portal.portlets.VelocityPortlet;
   import org.apache.jetspeed.services.resources.JetspeedResources;
  +import org.apache.jetspeed.tools.pamanager.Registration;
  +import org.apache.jetspeed.tools.pamanager.PortletApplicationException;
   import org.apache.turbine.util.DynamicURI;
   import org.apache.turbine.util.RunData;
   import org.apache.turbine.util.StringUtils;
  @@ -118,7 +124,7 @@
                   PortletApplicationViewBean tempApp = (PortletApplicationViewBean)rundata.getUser().getTemp(TEMP_APP);
                   if (tempApp != null)
                   {
  -                    context.put(SecurityConstants.CONTEXT_GROUP, tempApp);
  +                    context.put(CONTEXT_APP, tempApp);
                   }
               }
               context.put(SecurityConstants.PARAM_MODE, mode);
  @@ -133,6 +139,25 @@
           }
       }
   
  +    private boolean validateParam(RunData rundata, String value, int msg)
  +    {
  +        if (value == null || value.trim().length() == 0)
  +        {
  +            redirect(rundata, msg);
  +            return false;
  +        }       
  +        return true;
  +    }
  +    
  +    private void redirect(RunData rundata, int msg)
  +    {
  +        DynamicURI duri = new DynamicURI (rundata);
  +        duri.addPathInfo(SecurityConstants.PANE_NAME, PANEID_PA_UPDATE);
  +        duri.addPathInfo(SecurityConstants.PARAM_MSGID, msg);
  +        rundata.setRedirectURI(duri.toString());
  +        rundata.getUser().setTemp(TEMP_APP, null);        
  +    }
  +    
       /**
        * Database Insert Action for Security Groups. Performs inserts into security database.
        *
  @@ -143,60 +168,93 @@
           throws Exception
       {
           PortletApplicationViewBean bean = null;
  +        String name = rundata.getParameters().getString("name");
  +        String pacontext = rundata.getParameters().getString("context");           
  +        
  +        if (!validateParam(rundata, name, SecurityConstants.MID_INVALID_ENTITY_NAME))
  +        {
  +            storeBean(rundata, new PortletApplicationViewBean(name, pacontext));
  +            return;
  +        }
  +
  +        if (!validateParam(rundata, pacontext, SecurityConstants.MID_MISSING_PARAMETER))
  +        {
  +            storeBean(rundata, new PortletApplicationViewBean(name, pacontext));
  +            return;
  +        }
  +
  +        PortletApplicationViewBean dup = this.getPortletApplication(name);
  +        if (dup != null)
  +        {
  +            redirect(rundata, SecurityConstants.MID_ENTITY_ALREADY_EXISTS);
  +            storeBean(rundata, new PortletApplicationViewBean(name, pacontext));
  +            return;               
  +        }
  +        
  +        bean = new PortletApplicationViewBean(name, pacontext);
  +        System.out.println("Adding PA here: name    = " + name);
  +        System.out.println("Adding PA here: context = " + pacontext);
  +
  +        ServletContext webContext = rundata.getServletContext().getContext(pacontext);
  +        InputStream portletXml = null;
  +        InputStream webXml = null;
  +        
           try
           {
  -            //
  -            // validate that its not an 'blank' name -- not allowed
  -            //
  -            String name = rundata.getParameters().getString("name");
  -            if (name == null || name.trim().length() == 0)
  +            if (webContext == null)
               {
  -                DynamicURI duri = new DynamicURI (rundata);
  -                duri.addPathInfo(SecurityConstants.PANE_NAME, PANEID_PA_UPDATE);
  -                duri.addPathInfo(SecurityConstants.PARAM_MSGID, SecurityConstants.MID_INVALID_ENTITY_NAME);
  -                rundata.setRedirectURI(duri.toString());
  -                rundata.getUser().setTemp(TEMP_APP, null);
  -                return;
  +                throw new Exception("Invalid Portlet Application Context specified: " + pacontext);
               }
  -
  -            //
  -            // validate that its not an 'blank' context -- not allowed
  -            //
  -            String pacontext = rundata.getParameters().getString("context");
  -            if (pacontext == null || pacontext.trim().length() == 0)
  +            portletXml = webContext.getResourceAsStream("WEB-INF/portlet.xml");
  +            if (portletXml == null)
  +            {
  +                throw new PortletApplicationException("Failed to find Web XML");
  +            }            
  +        }
  +        catch (Exception pe)
  +        {
  +            redirect(rundata, SecurityConstants.MID_FAILED_PORTLET_XML);
  +            storeBean(rundata, bean);            
  +            return;
  +        }
  +        try
  +        {
  +            webXml = webContext.getResourceAsStream("WEB-INF/web.xml");
  +            if (webXml == null)
               {
  -                DynamicURI duri = new DynamicURI (rundata);
  -                duri.addPathInfo(SecurityConstants.PANE_NAME, PANEID_PA_UPDATE);
  -                duri.addPathInfo(SecurityConstants.PARAM_MSGID, SecurityConstants.MID_INVALID_ENTITY_NAME);
  -                rundata.setRedirectURI(duri.toString());
  -                rundata.getUser().setTemp(TEMP_APP, null);
  -                return;
  +                throw new PortletApplicationException("Failed to find Web XML");
               }
               
  -            bean = new PortletApplicationViewBean(name, pacontext);
  -            System.out.println("Adding PA here: name    = " + name);
  -            System.out.println("Adding PA here: context = " + pacontext);
  +        }
  +        catch (Exception pe)
  +        {
  +            redirect(rundata, SecurityConstants.MID_FAILED_WEB_XML);
  +            storeBean(rundata, bean);
  +            return;
  +        }
  +        finally
  +        {
  +            if (portletXml != null)
  +            {
  +                portletXml.close();
  +            }
  +        }
               
  +        if (webXml != null)
  +        {
  +            webXml.close();
           }
  -        catch (Exception e)
  +        System.out.println("Registering " + name);
  +        try
           {
  -            // log the error msg
  -            logger.error("Exception", e);
  -
  -            //
  -            // dup key found - display error message - bring back to same screen
  -            //
  -            DynamicURI duri = new DynamicURI (rundata);
  -            duri.addPathInfo(SecurityConstants.PANE_NAME, SecurityConstants.PANEID_GROUP_UPDATE);
  -            duri.addPathInfo(SecurityConstants.PARAM_MSGID, SecurityConstants.MID_ENTITY_ALREADY_EXISTS);
  -            rundata.setRedirectURI(duri.toString());
  -
  -            // save values that user just entered so they don't have to re-enter
  -           if (bean != null)
  -           {
  -               rundata.getUser().setTemp(TEMP_APP, bean);
  -           }
  +            getRegistrationComponent().registerPortletApplication(name, pacontext, webContext);
  +        }
  +        catch (Throwable t)
  +        {
  +            redirect(rundata, SecurityConstants.MID_FAILED_REGISTER_PA);
  +            storeBean(rundata, bean);
           }
  +        System.out.println("Done registering ");
       }
   
   
  @@ -210,19 +268,22 @@
           throws Exception
       {
           PortletApplicationViewBean bean = null;
  +        String name = rundata.getParameters().getString("name");
  +        String pacontext = rundata.getParameters().getString("context");                           
   
           try
  -        {
  -            //
  -            // get the group object from the selected group entry in the browser
  -            //
  -            bean = this.getPortletApplication(rundata.getParameters().getString( SecurityConstants.PARAM_ENTITY_ID)); 
  -
  -            //
  -            // remove the group
  -            //
  -            System.out.println("Removing Portlet App Bean = " + bean.getContext());
  -
  +        {            
  +            bean = getPortletApplication(rundata.getParameters().getString( SecurityConstants.PARAM_ENTITY_ID));
  +            if (bean == null)
  +            {
  +                redirect(rundata, SecurityConstants.MID_INVALID_ENTITY_NAME);
  +                storeBean(rundata, new PortletApplicationViewBean(name, pacontext));
  +                return;               
  +            }
  +            
  +            Registration registration = (Registration)this.getRegistrationComponent();
  +            registration.unregister(name);
  +            
           }
           catch (Exception e)
           {
  @@ -237,19 +298,23 @@
               duri.addPathInfo(SecurityConstants.PARAM_MSGID, SecurityConstants.MID_DELETE_FAILED);
               if (bean != null)
               {
  -                duri.addPathInfo(SecurityConstants.PARAM_ENTITY_ID, bean.getName());
  +                duri.addPathInfo(SecurityConstants.PARAM_ENTITY_ID, name);
               }
               duri.addQueryData(SecurityConstants.PARAM_MODE, SecurityConstants.PARAM_MODE_DELETE);
               rundata.setRedirectURI(duri.toString());
   
               // save values that user just entered so they don't have to re-enter
  -           if (bean != null)
  -           {
  -               rundata.getUser().setTemp(TEMP_APP, bean);
  -           }
  +            storeBean(rundata, new PortletApplicationViewBean(name, pacontext));
   
           }
   
       }
  -    
  +
  +    private void storeBean(RunData rundata, PortletApplicationViewBean bean)
  +    {
  +        if (bean != null)
  +        {
  +            rundata.getUser().setTemp(TEMP_APP, bean);
  +        }        
  +    }
   }
  
  
  

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