You are viewing a plain text version of this content. The canonical link for it is here.
Posted to wsrp4j-dev@portals.apache.org by dl...@apache.org on 2005/06/14 19:32:59 UTC

cvs commit: ws-wsrp4j/sandbox/wsrp4j/testportlet/src/java/org/apache/wsrp4j/testportlet TestPortlet.java

dlouzan     2005/06/14 10:32:59

  Added:       sandbox/wsrp4j/testportlet/src/java/org/apache/wsrp4j/testportlet
                        TestPortlet.java
  Log:
  
  
  Revision  Changes    Path
  1.1                  ws-wsrp4j/sandbox/wsrp4j/testportlet/src/java/org/apache/wsrp4j/testportlet/TestPortlet.java
  
  Index: TestPortlet.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.wsrp4j.testportlet;
  
  import javax.portlet.*;
  import java.io.IOException;
  
  public class TestPortlet extends GenericPortlet
  {
      public void processAction (ActionRequest request, ActionResponse actionResponse) 
      throws PortletException, java.io.IOException
      {
  
          String action = request.getParameter("ACTION");        
          if(action != null && action.equals("1"))
              handleCounter(request);
  
          String nameValue = request.getParameter("name");
          if(nameValue != null)            
              updatePreferences(request, "name", nameValue);
          
      }
  
      private void updatePreferences(ActionRequest request, String key, String value) {
          
          PortletPreferences prefs = request.getPreferences();
          
          try {
              
              prefs.setValue(key, value);
              prefs.store();
          
          } catch(Exception e) {
  
              getPortletConfig().getPortletContext().log("[Error] TestPortlet: Unable to modify preference '"+key+"'.",e);
          }
      }
  
      private void handleCounter(ActionRequest request) 
      {
         String counter1 = (String) request.getPortletSession().getAttribute("counter1", 
                                                                             PortletSession.APPLICATION_SCOPE);
         if (counter1 != null)
         {
             counter1 = Integer.toString(Integer.parseInt(counter1)+1);
         } else
         {
             counter1 = "1";
         }
  
         request.getPortletSession().setAttribute(
                                                 "counter1",
                                                 counter1, 
                                                 PortletSession.APPLICATION_SCOPE);
  
  
         String counter2 = (String) request.getPortletSession().getAttribute("counter2", 
                                                                             PortletSession.PORTLET_SCOPE);
         if (counter2 != null)
         {
             counter2 = Integer.toString(Integer.parseInt(counter2)+1);
         } else
         {
             counter2 = "1";
         }
  
         request.getPortletSession().setAttribute(
                                                 "counter2",
                                                 counter2, 
                                                 PortletSession.PORTLET_SCOPE);
     }
  
  
      public void doDispatch (RenderRequest request,
                          RenderResponse response) throws PortletException, IOException
      {
          WindowState state = request.getWindowState();
          if ( ! state.equals(WindowState.MINIMIZED)) {
              String jspName = request.getParameter("jspName");
              if (jspName==null) {
                  PortletSession session = request.getPortletSession(false);
                  if (session!=null)
                  {
                      jspName = (String)session.getAttribute("jspName", PortletSession.PORTLET_SCOPE);
                  }
                  if (jspName==null) jspName = "test1.jsp";
              }
              else
              {
                  PortletSession session = request.getPortletSession(false);
                  if (session!=null)
                  {
                      session.setAttribute("jspName", jspName, PortletSession.PORTLET_SCOPE);
                  }
              }
  
              PortletContext context = getPortletContext();
              PortletRequestDispatcher rd = context.getRequestDispatcher("/jsp/"+jspName);
              rd.include(request,response);
          }
      }
  }