taylor      2004/08/02 12:33:43

  Added:       fusion/src/java/org/apache/jetspeed/fusion/modules/actions/portlets
                        AbstractPortletApplicationAction.java
                        RegisterPortletApplicationAction.java
                        PortletApplicationViewBean.java
                        BrowsePortletApplicationAction.java
  Log:
  start of Fusion Portlet Application management for non-supported app servers which 
require deployment procedures not yet supported by J2
  
  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.1                  
jakarta-jetspeed/fusion/src/java/org/apache/jetspeed/fusion/modules/actions/portlets/AbstractPortletApplicationAction.java
  
  Index: AbstractPortletApplicationAction.java
  ===================================================================
  /*
   * Copyright 2000-2001,2004 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package org.apache.jetspeed.fusion.modules.actions.portlets;
  
  import java.util.ArrayList;
  import java.util.List;
  
  import org.apache.jetspeed.components.portletregistry.PortletRegistryComponent;
  import org.apache.jetspeed.modules.actions.portlets.VelocityPortletAction;
  import org.apache.jetspeed.om.common.portlet.MutablePortletApplication;
  import org.apache.jetspeed.services.JetspeedPortletServices;
  import org.apache.jetspeed.services.PortletServices;
  import org.apache.jetspeed.services.logging.JetspeedLogFactoryService;
  import org.apache.jetspeed.services.logging.JetspeedLogger;
  import org.apache.jetspeed.tools.pamanager.DeploymentRegistration;
  
  
  /**
   * Abstract class for Registers or UnRegisters Portlet Applications 
   * For registration, requires that the portlet application is predeployed to
   * the specific application server.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">David Sean Taylor</a>
   * @version $Id: AbstractPortletApplicationAction.java,v 1.1 2004/08/02 19:33:42 
taylor Exp $
   */
  public abstract class AbstractPortletApplicationAction 
      extends
          VelocityPortletAction
  {
      protected static final JetspeedLogger logger = 
JetspeedLogFactoryService.getLogger(AbstractPortletApplicationAction.class.getName());
      protected DeploymentRegistration registrar = null;
      protected PortletRegistryComponent registry = null;
      protected final String PANEID_PA_UPDATE = "PAUpdate";
      protected final String PANEID_PA_BROWSER = "PABrowser";
      
      protected List getPortletApplications()
      {
          PortletRegistryComponent reg = getRegistryComponent();
          if (null == reg)
          {
              return new ArrayList(); 
          }
          return reg.getPortletApplications();
      }
      
      protected PortletApplicationViewBean getPortletApplication(String name)
      {
          PortletRegistryComponent reg = getRegistryComponent();
          if (null == reg)
          {
              return null; 
          }
          MutablePortletApplication pa = reg.getPortletApplication(name);
          if (null == pa)
          {
              return null;
          }
          return new PortletApplicationViewBean(pa.getName(), 
pa.getWebApplicationDefinition().getContextRoot());
      }
      
      private DeploymentRegistration getRegistrationComponent()
      {
          if (registrar != null)
          {
              return registrar;
          }
          
          try
          {
              PortletServices services = JetspeedPortletServices.getSingleton();
              if (services != null)
              {
                  registrar = (DeploymentRegistration)services.getService("PAM");
              }
          }
          catch (Exception e)
          {
              logger.error("Failed to get registration service");
          }
          System.out.println("Returning PAM Component: " + registrar);        
          return registrar;
      }
  
      private PortletRegistryComponent getRegistryComponent()
      {
          if (registry != null)
          {
              return registry;
          }
          
          try
          {
              PortletServices services = JetspeedPortletServices.getSingleton();
              if (services != null)
              {
                  registry = 
(PortletRegistryComponent)services.getService("PortletRegistryComponent");
              }
          }
          catch (Exception e)
          {
              logger.error("Failed to get portlet registry component");
          }
          System.out.println("Returning Reg Component: " + registry);
          return registry;        
      }
  
  }
  
  
  
  1.1                  
jakarta-jetspeed/fusion/src/java/org/apache/jetspeed/fusion/modules/actions/portlets/RegisterPortletApplicationAction.java
  
  Index: RegisterPortletApplicationAction.java
  ===================================================================
  /*
   * Copyright 2000-2001,2004 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package org.apache.jetspeed.fusion.modules.actions.portlets;
  
  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.turbine.util.DynamicURI;
  import org.apache.turbine.util.RunData;
  import org.apache.turbine.util.StringUtils;
  import org.apache.velocity.context.Context;
  
  
  /**
   * Registers or UnRegisters Portlet Applications 
   * For registration, requires that the portlet application is predeployed to
   * the specific application server.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">David Sean Taylor</a>
   * @version $Id: RegisterPortletApplicationAction.java,v 1.1 2004/08/02 19:33:42 
taylor Exp $
   */
  public class RegisterPortletApplicationAction 
      extends 
          AbstractPortletApplicationAction
  {
      private static final String TEMP_APP = 
"org.apache.jetspeed.modules.actions.temp.app";
      private static final String CONTEXT_APP = "app";
      
      /**
       * Build the maximized state content for this portlet. (Same as normal state).
       *
       * @param portlet The velocity-based portlet that is being built.
       * @param context The velocity context for this request.
       * @param rundata The turbine rundata context for this request.
       */
      protected void buildMaximizedContext( VelocityPortlet portlet,
                                            Context context,
                                            RunData rundata )
      throws Exception
      {
          buildNormalContext( portlet, context, rundata);
      }
  
      /**
       * Build the configure state content for this portlet.
       *
       * @param portlet The velocity-based portlet that is being built.
       * @param context The velocity context for this request.
       * @param rundata The turbine rundata context for this request.
       */
      protected void buildConfigureContext( VelocityPortlet portlet,
                                            Context context,
                                            RunData rundata )
      throws Exception
      {
          buildNormalContext( portlet, context, rundata);
      }
  
  
      /**
       * Build the normal state content for this portlet.
       *
       * @param portlet The velocity-based portlet that is being built.
       * @param context The velocity context for this request.
       * @param rundata The turbine rundata context for this request.
       */    
      protected void buildNormalContext(VelocityPortlet portlet, 
                                        Context context,
                                        RunData rundata) 
      throws Exception
      {
          try
          {
              PortletApplicationViewBean bean = null;
  
              /*
               * Grab the mode for the form.
               */
              String mode = 
rundata.getParameters().getString(SecurityConstants.PARAM_MODE);
  
              // if we are updating or deleting - put the name in the context
              //
              if (mode != null && (mode.equals(SecurityConstants.PARAM_MODE_UPDATE) ||
                                   mode.equals(SecurityConstants.PARAM_MODE_DELETE)))
              {
                  // get the primary key and put the object in the context
                  String appName = 
rundata.getParameters().getString(SecurityConstants.PARAM_ENTITY_ID);
                  bean = this.getPortletApplication(appName);
                  context.put(CONTEXT_APP, bean);
              }
  
              //
              // if there was an error, display the message
              //
              String msgid = 
rundata.getParameters().getString(SecurityConstants.PARAM_MSGID);
              if (msgid != null)
              {
                  int id = Integer.parseInt(msgid);
                  if (id < SecurityConstants.MESSAGES.length)
                      context.put(SecurityConstants.PARAM_MSG, 
SecurityConstants.MESSAGES[id]);
  
                  // get the bad entered data and put it back for convenient update
                  PortletApplicationViewBean tempApp = 
(PortletApplicationViewBean)rundata.getUser().getTemp(TEMP_APP);
                  if (tempApp != null)
                  {
                      context.put(SecurityConstants.CONTEXT_GROUP, tempApp);
                  }
              }
              context.put(SecurityConstants.PARAM_MODE, mode);
  
          }
          catch (Exception e)
          {
              logger.error("Error in Portlet Application Registration", e);
              rundata.setMessage("Error in Jetspeed Portlet Application Registration: 
" + e.toString());
              rundata.setStackTrace(StringUtils.stackTrace(e), e);
              
rundata.setScreenTemplate(JetspeedResources.getString("template.error","Error"));
          }
      }
  
      /**
       * Database Insert Action for Security Groups. Performs inserts into security 
database.
       *
       * @param rundata The turbine rundata context for this request.
       * @param context The velocity context for this request.
       */
      public void doInsert(RunData rundata, Context context)
          throws Exception
      {
          PortletApplicationViewBean bean = null;
          try
          {
              //
              // validate that its not an 'blank' name -- not allowed
              //
              String name = rundata.getParameters().getString("name");
              if (name == null || name.trim().length() == 0)
              {
                  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;
              }
  
              //
              // validate that its not an 'blank' context -- not allowed
              //
              String pacontext = rundata.getParameters().getString("context");
              if (pacontext == null || pacontext.trim().length() == 0)
              {
                  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;
              }
              
              bean = new PortletApplicationViewBean(name, pacontext);
              System.out.println("Adding PA here: name    = " + name);
              System.out.println("Adding PA here: context = " + pacontext);
              
          }
          catch (Exception e)
          {
              // 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);
             }
          }
      }
  
  
      /**
       * Database Delete Action for Security Groups. Performs deletes into security 
database.
       *
       * @param rundata The turbine rundata context for this request.
       * @param context The velocity context for this request.
       */
      public void doDelete(RunData rundata, Context context)
          throws Exception
      {
          PortletApplicationViewBean bean = null;
  
          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());
  
          }
          catch (Exception e)
          {
             // log the error msg
              logger.error("Exception", e);
  
              //
              // error on delete - display error message
              //
              DynamicURI duri = new DynamicURI (rundata);
              duri.addPathInfo(SecurityConstants.PANE_NAME, PANEID_PA_UPDATE);
              duri.addPathInfo(SecurityConstants.PARAM_MSGID, 
SecurityConstants.MID_DELETE_FAILED);
              if (bean != null)
              {
                  duri.addPathInfo(SecurityConstants.PARAM_ENTITY_ID, bean.getName());
              }
              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);
             }
  
          }
  
      }
      
  }
  
  
  
  1.1                  
jakarta-jetspeed/fusion/src/java/org/apache/jetspeed/fusion/modules/actions/portlets/PortletApplicationViewBean.java
  
  Index: PortletApplicationViewBean.java
  ===================================================================
  /*
   * Copyright 2000-2001,2004 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package org.apache.jetspeed.fusion.modules.actions.portlets;
  
  
  /**
   * MVC 'View' bean passed to Velocity
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">David Sean Taylor</a>
   * @version $Id: PortletApplicationViewBean.java,v 1.1 2004/08/02 19:33:42 taylor 
Exp $
   */
  public class PortletApplicationViewBean
  {
          private String name;
          private String context;
          
          PortletApplicationViewBean(String name, String context)
          {
              this.name = name;
              this.context = context;
          }
          
          String getName()
          {
              return name;
          }
          
          String getContext()
          {
              return context;
          }
   
          void setName(String name)
          {
              this.name = name;
          }
          
          void setContext(String context)
          {
              this.context = context;
          }        
  }
  
  
  
  1.1                  
jakarta-jetspeed/fusion/src/java/org/apache/jetspeed/fusion/modules/actions/portlets/BrowsePortletApplicationAction.java
  
  Index: BrowsePortletApplicationAction.java
  ===================================================================
  /*
   * Copyright 2000-2001,2004 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package org.apache.jetspeed.fusion.modules.actions.portlets;
  
  import org.apache.jetspeed.portal.portlets.VelocityPortlet;
  import org.apache.turbine.util.RunData;
  import org.apache.velocity.context.Context;
  
  /**
   * Registers or UnRegisters Portlet Applications 
   * For registration, requires that the portlet application is predeployed to
   * the specific application server.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">David Sean Taylor</a>
   * @version $Id: BrowsePortletApplicationAction.java,v 1.1 2004/08/02 19:33:42 
taylor Exp $
   */
  public class BrowsePortletApplicationAction 
      extends 
          AbstractPortletApplicationAction
  {
  
      /* (non-Javadoc)
       * @see 
org.apache.jetspeed.modules.actions.portlets.VelocityPortletAction#buildNormalContext(org.apache.jetspeed.portal.portlets.VelocityPortlet,
 org.apache.velocity.context.Context, org.apache.turbine.util.RunData)
       */
      protected void buildNormalContext(VelocityPortlet portlet, Context context,
              RunData rundata) throws Exception
      {
          context.put("apps", getPortletApplications());
      }
  
  }
  
  
  

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

Reply via email to