taylor      01/05/07 23:28:30

  Added:       src/java/org/apache/jetspeed/modules/actions
                        CustomizeUserPSMLFile.java
  Log:
  adding Glucode customizer for 1.3a2
  
  Revision  Changes    Path
  1.1                  
jakarta-jetspeed/src/java/org/apache/jetspeed/modules/actions/CustomizeUserPSMLFile.java
  
  Index: CustomizeUserPSMLFile.java
  ===================================================================
  package org.apache.jetspeed.modules.actions;
  
  /*
   *
   * Copyright (c) 1998 The Java Apache Project.  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. Every modification must be notified to the Java Apache Project
   *    and redistribution of the modified code without prior notification
   *    is not permitted in any form.
   *
   * 4. All advertising materials mentioning features or use of this
   *    software must display the following acknowledgment:
   *    "This product includes software developed by the Java Apache Project
   *    (http://java.apache.org/)."
   *
   * 5. The names "Jetspeed", "Apache Jetspeed" and "Apache Jetspeed
   *    Project" must not be used to endorse or promote products
   *    derived from this software without prior written permission.
   *
   * 6. Redistributions of any form whatsoever must retain the following
   *    acknowledgment:
   *    "This product includes software developed by the Java Apache Project
   *    (http://java.apache.org/)."
   *
   * THIS SOFTWARE IS PROVIDED BY THE JAVA APACHE PROJECT "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 JAVA APACHE PROJECT 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.
   *
   * License version 1.0
   *
   */
  
  
  // Required Turbine classes
  import org.apache.turbine.modules.ActionEvent;
  import org.apache.turbine.services.resources.TurbineResources;
  import org.apache.turbine.util.*;
  
  // Jetspeed
  import org.apache.jetspeed.om.registry.peer.PortletEntry;
  
  // Java
  import java.util.*;
  
  // Customizer
  import org.apache.jetspeed.util.customization.*;
  
  
  /**
   *    Action class that handles the customization for the user portal page.  Access 
is only granted once
   *    the user has been logged on.
   *    Note: Should we throw an exception if an invalid screen tries to access on of 
the events handler?
   *
   *    @author <a href="mailto:[EMAIL PROTECTED]";>Van Truong </a>
   *    @author <a href="mailto:[EMAIL PROTECTED]";>Ernest Ros </a>
   *    @version $Id: CustomizeUserPSMLFile.java,v 1.1 2001/05/08 06:28:29 taylor Exp $
   *
   */ 
  public class CustomizeUserPSMLFile extends ActionEvent
  {
      /**
       *The method that is call when Customization is first initialized.
       */
      public void doPerform(RunData data) throws Exception
      {
          //check to make sure the user has logged
          if (!data.getUser().hasLoggedIn())
          {
              data.setMessage("USER HAS NOT LOGGED IN.");
              data.setScreen(TurbineResources.getString( "screen.mainmenu" ));
              return;
          }
  
          data.getUser().setTemp(CustomizerResources.ALLOWABLEPORTLETSET, new 
AllowablePortletSet(data));
          data.getUser().setTemp(CustomizerResources.ALLOWABLECOLUMNSET, new 
AllowableColumnSet(data));
          data.setScreen(CustomizerResources.CUSTOMIZERSCREEN1);
  
          return;
  
      } //end doPerform
  
  
      /**
       *Back event handler gets call when the user click the back button of the
       *customizer screen 2.
       */
      public void doBack(RunData data) throws Exception
      {
          //check to make sure the user has logged
          if (!data.getUser().hasLoggedIn())
          {
              data.setMessage("USER HAS NOT LOGGED IN.");
              data.setScreen(TurbineResources.getString( "screen.mainmenu" ));
              return;
          }
  
          data.setScreen(CustomizerResources.CUSTOMIZERSCREEN1);
  
      } // end doBack
  
  
      /**
       *Submit event handler gets call when the user click the submit button of the
       *customizer screen 2.
       */
      public void doSubmit(RunData data) throws CustomizerException,
                                                java.io.FileNotFoundException,
                                                java.io.IOException,
                                                UserNotLoggedInException,
                                                ElementNotFoundException
  
      {
          //check to make sure the user has logged
          if (!data.getUser().hasLoggedIn())
          {
              data.setMessage("USER HAS NOT LOGGED IN.");
              data.setScreen(TurbineResources.getString( "screen.mainmenu" ));
              return;
          }
          else if (data.getUser().getTemp(CustomizerResources.PREVIOUSSCREEN)==null ||
                   
!((String)(data.getUser().getTemp(CustomizerResources.PREVIOUSSCREEN)))
                                            
.equals(CustomizerResources.CUSTOMIZERSCREEN2))
          {
              // Check if the previous screen was correct
              data.setMessage("The previous screen was invalid!");
              data.setScreen(TurbineResources.getString( "screen.mainmenu" ));
              return;
          }
  
          // Get the user psml file object
          PSMLDocument psmlDoc = new PSMLDocument(data);
  
          // Get the parameters
          AllowablePortletSet ap = 
(AllowablePortletSet)data.getUser().getTemp(CustomizerResources.ALLOWABLEPORTLETSET);
          AllowableColumnSet ac = 
(AllowableColumnSet)data.getUser().getTemp(CustomizerResources.ALLOWABLECOLUMNSET);
  
  
          // Set the colors selected by the user
          for (int i=0; i<ac.getMaximumNumOfColumnAllowed(); i++)
          {
              
psmlDoc.setTitleColor(data.getParameters().getString(CustomizerResources.COLUMNPREFIX +
                                                                   
CustomizerResources.HEADINGCOLOR +
                                                                   i) , new int[]{i});
              
psmlDoc.setBackgroundColor(data.getParameters().getString(CustomizerResources.COLUMNPREFIX
 +
                                                                        
CustomizerResources.BACKGROUNDCOLOR +
                                                                        i) , new 
int[]{i});
          }
  
  
          // Begin transforming all the selected PEs to PSMLEntry's
          String[] portlets = (String[])ap.getUserDefaultPortletNames();
          int portletsLength = portlets==null?0:portlets.length;
  
          LinkedList list = new LinkedList();
  
          for (int i=0; i<portletsLength; i++)
          {
             // Get the column selected by the user for this portlet
             int[] coord = new int[] 
{data.getParameters().getInt(CustomizerResources.COLUMNPREFIX + portlets[i])};
             // Get the position selected by the user for this portlet
             int pos = data.getParameters().getInt(CustomizerResources.ROWPREFIX + 
portlets[i]);
  
             if (!psmlDoc.inDocument(portlets[i]))
             {
                 PortletEntry pe = ap.getPortletEntry(portlets[i]);
                 org.apache.jetspeed.xml.api.portletmarkup.Layout layout =
                                new org.apache.jetspeed.xml.api.portletmarkup.Layout();
                 layout.setPosition(String.valueOf(pos));
                 PSMLEntry psmlEntry = new PSMLEntry(pe, layout, coord);
                 list.add(psmlEntry);
             }
             else
             {
                 PSMLEntry psmlEntry = psmlDoc.getPSMLEntry(portlets[i]);
                 psmlEntry.setCoordinates(coord);
                 psmlEntry.setPosition(pos);
                 list.add(psmlEntry);
             } //end if
  
          } //end for
  
          // Delete all user's previous PortletEntry's
          psmlDoc.deleteAllEntries(null);
  
          // Add in the new selection of PortletEntry
          for (int i=0; i<list.size(); i++)
          {
              psmlDoc.addPSMLEntry((PSMLEntry)list.get(i));
          }
  
          psmlDoc.writePSMLDocument();
          removeTemp(data);
  
          DynamicURI dui = new DynamicURI (data, 
TurbineResources.getString("screen.homepage"), true);
          data.getResponse().sendRedirect(dui.toString());
  
      } //end doSubmit
  
  
      /**
       *Cancel event handler gets call when the user click the submit button of the
       *customizer screens.
       */
      public void doCancel(RunData data) throws java.io.IOException
      {
          removeTemp(data);
          DynamicURI dui = new DynamicURI (data, 
TurbineResources.getString("screen.mainmenu"), true);
          data.getResponse().sendRedirect(dui.toString());
      } //end doCancel
  
  
      /**
       *Continue event handler gets call when the user click the submit button of the
       *customizer screen 1.
       */
      public void doContinue(RunData data) throws Exception
      {
          //check to make sure the user has logged
          if (!data.getUser().hasLoggedIn())
          {
              data.setMessage("USER HAS NOT LOGGED IN.");
              data.setScreen(TurbineResources.getString( "screen.mainmenu" ));
              return;
          }
  
          // Get the parameters
          AllowablePortletSet ap = 
(AllowablePortletSet)data.getUser().getTemp(CustomizerResources.ALLOWABLEPORTLETSET);
  
          if (ap==null)
          {
              data.setMessage("WARNING: USER HAS NOT START THE CUSTOMIZATION PROCESS 
FROM THE BEGINNING.");
              data.setScreen(TurbineResources.getString( "screen.mainmenu" ));
              return;
          }
  
          String[] defaultPortlets = 
(String[])data.getParameters().getStrings(CustomizerResources.CHECKBOXPREFIX +
                                                                               
CustomizerResources.PORTLET);
  
          // Set the portlets selected by the user as their default portlets
          ap.resetAllUserDefaultPortlets();
  
          if (defaultPortlets != null)
          {
              for (int i=0; i<defaultPortlets.length; i++)
              {
                  ap.setPortletAsUserDefault(defaultPortlets[i]);
              }
          } //end if
  
          DynamicURI dui = new DynamicURI (data, 
CustomizerResources.CUSTOMIZERSCREEN2, true);
          data.getResponse().sendRedirect(dui.toString());
          //data.setScreen(CustomizerResources.CUSTOMIZERSCREEN2);
  
      } //end doContinue
  
  
      /**
       * Remove all the temporary data stored for this session.
       */
      private void removeTemp(RunData data)
      {
          data.getUser().removeTemp(CustomizerResources.ALLOWABLEPORTLETSET);
          data.getUser().removeTemp(CustomizerResources.ALLOWABLECOLUMNSET);
          data.getUser().removeTemp(CustomizerResources.PREVIOUSSCREEN);
      } //end removeTemp
  
  } //end class CustomizeUserPSMLFile
  
  
  

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

Reply via email to