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 Tue, 02 Jul 2002 01:23:10 GMT
taylor      2002/07/01 18:23:10

  Added:       src/java/org/apache/jetspeed/modules/actions/portlets
                        PsmlBrowseAction.java PsmlUpdateAction.java
  Log:
  Added actions to build, add and delete from the Psml browser - Partially complete.
  Updates are not working yet.
  
  Revision  Changes    Path
  1.1                  jakarta-jetspeed/src/java/org/apache/jetspeed/modules/actions/portlets/PsmlBrowseAction.java
  
  Index: PsmlBrowseAction.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2000-2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *     "Apache Jetspeed" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache" or
   *    "Apache Jetspeed", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  package org.apache.jetspeed.modules.actions.portlets;
  
  import org.apache.jetspeed.portal.portlets.VelocityPortlet;
  import org.apache.jetspeed.services.Profiler;
  import org.apache.jetspeed.services.PsmlManager;
  
  import org.apache.jetspeed.om.profile.BaseProfile;
  import org.apache.jetspeed.om.profile.BaseProfileLocator;
  import org.apache.jetspeed.om.profile.Profile;
  import org.apache.jetspeed.om.profile.ProfileException;
  import org.apache.jetspeed.om.profile.ProfileLocator;
  import org.apache.jetspeed.om.profile.QueryLocator;
  
  import org.apache.jetspeed.om.profile.psml.PsmlEntry;
  
  // Turbine stuff
  import org.apache.turbine.util.Log;
  import org.apache.turbine.util.RunData;
  
  // Velocity Stuff
  import org.apache.velocity.context.Context;
  
  import java.util.Vector;
  import java.util.Iterator;
  
  /**
   * This action enables to browse any of the psml info, for displaying
   * available entries and information on these entries
   *
   * @author <a href="mailto:david@apache.org">David Sean Taylor</a>
   */
  public class PsmlBrowseAction extends VelocityPortletAction
  {
  
      /**
       * Subclasses must override this method to provide default behavior
       * for the portlet action
       */
      protected void buildNormalContext( VelocityPortlet portlet,
                                         Context context,
                                         RunData rundata )
      {
          int start = rundata.getParameters().getInt("start",0);
  
          if (start < 0) start = 0;
  
          String pageSize = portlet.getPortletConfig()
                                   .getInitParameter("page-size","20");
  
          int size = Integer.parseInt(pageSize);
  
          int next = start+size+1;
          int prev = start-size-1;
  
          //System.out.println("start="+start+" size="+size+" next="+next+" prev="+prev);
  
          Iterator i = Profiler.query(new QueryLocator(QueryLocator.QUERY_ALL));
          Vector entries = new Vector();
  
          int count = start;
          int index = 0;
  
          while(i.hasNext())
          {
              Profile profile = (Profile)i.next();
              System.out.println("profile["+index+"]="+profile.getName()+" count="+count);
              if (count < (next - 1) && index >= count)
              {
                  entries.add(profile);
                  count++;
              }
              index++;
          }
          //System.out.println("count="+count+" total="+index);
          context.put("psml", entries);
          if (start > 0)
          {
              context.put("prev",String.valueOf(prev+1));
          }
          if (    (count == (next - 1))
               && ( count <  index) )
          {
              context.put("next",String.valueOf(next-1));
          }
  
      }
  }
  
  
  
  
  1.1                  jakarta-jetspeed/src/java/org/apache/jetspeed/modules/actions/portlets/PsmlUpdateAction.java
  
  Index: PsmlUpdateAction.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2000-2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *     "Apache Jetspeed" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache" or
   *    "Apache Jetspeed", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  package org.apache.jetspeed.modules.actions.portlets;
  
  // Turbine stuff
  import org.apache.turbine.util.Log;
  import org.apache.turbine.util.DynamicURI;
  import org.apache.turbine.util.RunData;
  import org.apache.turbine.util.StringUtils;
  import org.apache.turbine.util.security.EntityExistsException;
  
  // Velocity Stuff
  import org.apache.velocity.context.Context;
  
  //Java
  import java.util.Vector;
  import java.util.Iterator;
  
  //Jetspeed
  import org.apache.jetspeed.modules.actions.portlets.security.SecurityConstants;
  import org.apache.jetspeed.om.profile.BaseProfile;
  import org.apache.jetspeed.om.profile.BaseProfileLocator;
  import org.apache.jetspeed.om.profile.Profile;
  import org.apache.jetspeed.om.profile.ProfileException;
  import org.apache.jetspeed.om.profile.ProfileLocator;
  import org.apache.jetspeed.portal.portlets.VelocityPortlet;
  import org.apache.jetspeed.services.Profiler;
  import org.apache.jetspeed.services.PsmlManager;
  import org.apache.jetspeed.services.resources.JetspeedResources;
  
  /**
   * This action enables to update the psml entries
   *
   * @author <a href="mailto:david@apache.org">David Sean Taylor</a>
   */
  public class PsmlUpdateAction extends VelocityPortletAction
  {
  
      protected static final String TEMP_PSML = "tempPsml";
      /**
       * Subclasses must override this method to provide default behavior
       * for the portlet action
       */
      /**
       * 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 )
      {
          try
          {
  
              //
              // 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
                   Profile profile = (Profile)rundata.getUser().getTemp(TEMP_PSML);
                  if (profile != null)
                      context.put("psml", profile);
  
              }
  
          }
          catch (Exception e)
          {
              Log.error(e);
              rundata.setMessage("Error in PsmlUpdateAction: " + e.toString());
              rundata.setStackTrace(StringUtils.stackTrace(e), e);
              rundata.setScreenTemplate(JetspeedResources.getString("template.error","Error"));
          }
      }
  
      /**
       * Database Insert Action for Psml.
       *
       * @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
      {
           Profile profile = null;
           ProfileLocator locator = null;
          try
          {
              //
              // validate that its not an 'blank' profile -- 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, "PsmlForm");
                  duri.addPathInfo(SecurityConstants.PARAM_MSGID, SecurityConstants.MID_INVALID_ENTITY_NAME);
                  rundata.setRedirectURI(duri.toString());
                  // save values that user just entered so they don't have to re-enter
                  if (profile != null)
                     rundata.getUser().setTemp(TEMP_PSML, profile);
                  return;
              }
  
  
              //
              // create a new profile
              //
              locator = new BaseProfileLocator();
              rundata.getParameters().setProperties(locator);
              profile = new BaseProfile(locator);
              profile = Profiler.createProfile(rundata, profile);
          }
          catch (EntityExistsException e)
          {
              // log the error msg
              Log.error(e);
  
              //
              // dup key found - display error message - bring back to same screen
              //
              DynamicURI duri = new DynamicURI (rundata);
              duri.addPathInfo(SecurityConstants.PANE_NAME, "PsmlForm");
              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 (profile != null)
                 rundata.getUser().setTemp(TEMP_PSML, profile);
          }
  
      }
  
      /**
       * Delete Psml entry
       */
      public void doDelete(RunData rundata, Context context) throws Exception
      {
          try
          {
              ProfileLocator locator = new BaseProfileLocator();
              locator.createFromPath(rundata.getParameters().getString("link"));
              Profiler.removeProfile(locator);
          }
          catch(Exception e)
          {
              // log the error msg
              Log.error(e);
  
              //
              // dup key found - display error message - bring back to same screen
              //
              DynamicURI duri = new DynamicURI (rundata);
              duri.addPathInfo(SecurityConstants.PANE_NAME, "PsmlForm");
              duri.addPathInfo(SecurityConstants.PARAM_MSGID, SecurityConstants.MID_DELETE_FAILED);
              rundata.setRedirectURI(duri.toString());
          }
  
      }
  
  }
  
  
  
  
  

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