portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jf...@apache.org
Subject cvs commit: jakarta-jetspeed-2/applications/pam/src/java/org/apache/jetspeed/portlets/pam PortletApplicationBrowser.java PortletApplicationDetail.java PortletApplicationResources.java
Date Fri, 03 Sep 2004 19:35:50 GMT
jford       2004/09/03 12:35:50

  Modified:    applications/pam/src/java/org/apache/jetspeed/portlets/pam
                        PortletApplicationBrowser.java
                        PortletApplicationDetail.java
                        PortletApplicationResources.java
  Log:
  Added support for editing metadata
  
  Revision  Changes    Path
  1.7       +2 -1      jakarta-jetspeed-2/applications/pam/src/java/org/apache/jetspeed/portlets/pam/PortletApplicationBrowser.java
  
  Index: PortletApplicationBrowser.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/applications/pam/src/java/org/apache/jetspeed/portlets/pam/PortletApplicationBrowser.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- PortletApplicationBrowser.java	2 Sep 2004 16:10:58 -0000	1.6
  +++ PortletApplicationBrowser.java	3 Sep 2004 19:35:50 -0000	1.7
  @@ -106,6 +106,7 @@
               if (null != pa)
               {
                   actionRequest.getPortletSession().setAttribute(PortletApplicationResources.PAM_CURRENT_PA,
pa, PortletSession.APPLICATION_SCOPE);
  +                actionRequest.getPortletSession().removeAttribute(PortletApplicationResources.REQUEST_SELECT_PORTLET,
PortletSession.APPLICATION_SCOPE);
               }
   		}	
   	}
  
  
  
  1.5       +3 -3      jakarta-jetspeed-2/applications/pam/src/java/org/apache/jetspeed/portlets/pam/PortletApplicationDetail.java
  
  Index: PortletApplicationDetail.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/applications/pam/src/java/org/apache/jetspeed/portlets/pam/PortletApplicationDetail.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- PortletApplicationDetail.java	3 Sep 2004 04:10:23 -0000	1.4
  +++ PortletApplicationDetail.java	3 Sep 2004 19:35:50 -0000	1.5
  @@ -1,9 +1,9 @@
   /*
 * Copyright 2000-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.portlets.pam;
   
  -import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;

import
javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.PortletConfig;
import
javax.portlet.PortletContext;
import javax.portlet.PortletException;
import javax.portlet.PortletSession;
import
javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
import org.apache.jetspeed.portlet.ServletPortlet;
import
org.apache.jetspeed.portlets.pam.beans.PortletApplicationBean;
import org.apache.jetspeed.portlets.pam.beans.TabBean;
import
org.apache.jetspeed.components.portletregistry.PortletRegistryComponent;
import org.apache.jetspeed.om.common.portlet.MutablePortletApplication;
import
org.apache.pluto.om.portlet.PortletDefinition;
/**
 * This portlet is a browser over all the
portlet applications in the system.
 *
 * @author <a href="mailto:jford@apache.com">Jeremy
Ford</a>
 * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
* @version $Id$
 */
public class PortletApplicationDetail extends ServletPortlet
{
    private
final String VIEW_PA = "portletApplication"; 
    private final String VIEW_PD = "portletDefinition";

   private PortletContext context;
    private PortletRegistryComponent registry;
    private
HashMap tabMap = new HashMap();
    
    public void init(PortletConfig config)
    throws
PortletException 
    {
        super.init(config);
        context = getPortletContext();
       registry = (PortletRegistryComponent)context.getAttribute(PortletApplicationResources.CPS_REGISTRY_COMPONENT);
       if (null == registry)
        {
            throw new PortletException("Failed to find
the Portlet Registry on portlet initialization");
        }
        
        TabBean tb1 =
new TabBean("Details", "Details");
        TabBean tb2 = new TabBean("Metadata", "Metadata");
       TabBean tb3 = new TabBean("Portlets", "Portlets");
        
        tabMap.put(tb1.getId(),
tb1);
        tabMap.put(tb2.getId(), tb2);
        tabMap.put(tb3.getId(), tb3);
    }
 
  
    public void doView(RenderRequest request, RenderResponse response)
  +import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
import
java.util.Locale;

import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import
javax.portlet.PortletConfig;
import javax.portlet.PortletContext;
import javax.portlet.PortletException;
import
javax.portlet.PortletSession;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
import
org.apache.jetspeed.portlet.ServletPortlet;
import org.apache.jetspeed.portlets.pam.beans.PortletApplicationBean;
import
org.apache.jetspeed.portlets.pam.beans.TabBean;
import org.apache.jetspeed.components.persistence.store.PersistenceStore;
import
org.apache.jetspeed.components.portletregistry.PortletRegistryComponent;
import org.apache.jetspeed.om.common.GenericMetadata;
import
org.apache.jetspeed.om.common.LocalizedField;
import org.apache.jetspeed.om.common.portlet.MutablePortletApplication;
import
org.apache.pluto.om.portlet.PortletDefinition;
/**
 * This portlet is a browser over all the
portlet applications in the system.
 *
 * @author <a href="mailto:jford@apache.com">Jeremy
Ford</a>
 * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
* @version $Id$
 */
public class PortletApplicationDetail extends ServletPortlet
{
    private
static final String PORTLET_ACTION = "portlet_action";
    private final String VIEW_PA =
"portletApplication"; 
    private final String VIEW_PD = "portletDefinition";

    private
PortletContext context;
    private PortletRegistryComponent registry;
    private HashMap
tabMap = new HashMap();
    
    public void init(PortletConfig config)
    throws PortletException

    {
        super.init(config);
        context = getPortletContext();
        registry
= (PortletRegistryComponent)context.getAttribute(PortletApplicationResources.CPS_REGISTRY_COMPONENT);
       if (null == registry)
        {
            throw new PortletException("Failed to find
the Portlet Registry on portlet initialization");
        }
        
        TabBean tb1 =
new TabBean("Details", "Details");
        TabBean tb2 = new TabBean("Metadata", "Metadata");
       TabBean tb3 = new TabBean("Portlets", "Portlets");
        
        tabMap.put(tb1.getId(),
tb1);
        tabMap.put(tb2.getId(), tb2);
        tabMap.put(tb3.getId(), tb3);
    }
 
  
    public void doView(RenderRequest request, RenderResponse response)
       throws PortletException, IOException
  -    {
        response.setContentType("text/html");
        
        MutablePortletApplication
pa = (MutablePortletApplication)
                request.getPortletSession().getAttribute(PortletApplicationResources.PAM_CURRENT_PA,

                                                         PortletSession.APPLICATION_SCOPE);
       
        if (null != pa)
        {
            request.setAttribute(VIEW_PA, new PortletApplicationBean(pa));
           
            PortletDefinition pdef = (PortletDefinition) request.getPortletSession().getAttribute("select_portlet");
           
            request.setAttribute(VIEW_PD, pdef);
            
            request.setAttribute("tabs",
tabMap.values());
            
            TabBean selectedTab = (TabBean) request.getPortletSession().getAttribute("selected_tab");
           if(selectedTab == null) {
                selectedTab = (TabBean) tabMap.values().iterator().next();
           }
            request.setAttribute("selected_tab", selectedTab);
            
       }
  +    {
        response.setContentType("text/html");
        
        MutablePortletApplication
pa = (MutablePortletApplication)
                request.getPortletSession().getAttribute(PortletApplicationResources.PAM_CURRENT_PA,

                                                         PortletSession.APPLICATION_SCOPE);
       
        if (null != pa)
        {
            request.setAttribute(VIEW_PA, new PortletApplicationBean(pa));
           
            PortletDefinition pdef = (PortletDefinition) request.getPortletSession().getAttribute(PortletApplicationResources.REQUEST_SELECT_PORTLET,
PortletSession.APPLICATION_SCOPE);
            
            request.setAttribute(VIEW_PD,
pdef);
            
            request.setAttribute("tabs", tabMap.values());
          
 
            TabBean selectedTab = (TabBean) request.getPortletSession().getAttribute("selected_tab");
           if(selectedTab == null) {
                selectedTab = (TabBean) tabMap.values().iterator().next();
           }
            request.setAttribute("selected_tab", selectedTab);
            
       }
           super.doView(request, response);
       }
  -    
    public void processAction(ActionRequest actionRequest, ActionResponse actionResponse)
throws PortletException, IOException
	{
        System.out.println("PorletApplicationDetail:
processAction()");
        
        String selectedPortlet = actionRequest.getParameter("select_portlet");
       if(selectedPortlet != null)
        {
	        MutablePortletApplication pa = (MutablePortletApplication)
        	actionRequest.getPortletSession().getAttribute(PortletApplicationResources.PAM_CURRENT_PA,

	                                                 PortletSession.APPLICATION_SCOPE);
	  
     
	        PortletDefinition pdef = pa.getPortletDefinitionByName(selectedPortlet);
	
       actionRequest.getPortletSession().setAttribute("select_portlet", pdef);
        }
       
        String selectedTab = actionRequest.getParameter("selected_tab");
        if(selectedTab
!= null)
        {
            TabBean tab = (TabBean) tabMap.get(selectedTab);
         
  actionRequest.getPortletSession().setAttribute("selected_tab", tab);
        }
	}
  +    
    public void processAction(ActionRequest actionRequest, ActionResponse actionResponse)
throws PortletException, IOException
	{
        //System.out.println("PorletApplicationDetail:
processAction()");
        MutablePortletApplication pa = (MutablePortletApplication)
   
	actionRequest.getPortletSession().getAttribute(PortletApplicationResources.PAM_CURRENT_PA,

                                             PortletSession.APPLICATION_SCOPE);
        
       String selectedPortlet = actionRequest.getParameter(PortletApplicationResources.REQUEST_SELECT_PORTLET);
       if(selectedPortlet != null)
        {
	        
	        
	        PortletDefinition
pdef = pa.getPortletDefinitionByName(selectedPortlet);
	        actionRequest.getPortletSession().setAttribute(PortletApplicationResources.REQUEST_SELECT_PORTLET,
pdef, PortletSession.APPLICATION_SCOPE);
        }
        
        String selectedTab = actionRequest.getParameter("selected_tab");
       if(selectedTab != null)
        {
            TabBean tab = (TabBean) tabMap.get(selectedTab);
           actionRequest.getPortletSession().setAttribute("selected_tab", tab);
        }
       
        String action = actionRequest.getParameter(PORTLET_ACTION);
        if(action
!= null)
        {
            if(action.equals("edit_metadata"))
            {
         
      GenericMetadata md = pa.getMetadata();
                Iterator fieldsIter = md.getFields().iterator();
               
                registry.getPersistenceStore().getTransaction().begin();
               
                while (fieldsIter.hasNext())
                {
          
         LocalizedField field = (LocalizedField) fieldsIter.next();
                    String
id = field.getId().toString();
                    String value = actionRequest.getParameter(id
+ ":value");
                    if(value != null)
                    {
                
       if(!value.equals(field.getValue()))
                        {
                    
       field.setValue(value);
                        }
                    }
           
    }
                
                registry.getPersistenceStore().getTransaction().commit();
           }
            else if(action.equals("remove_metadata"))
            {
        
       GenericMetadata md = pa.getMetadata();
                Iterator fieldsIter = md.getFields().iterator();
               
                registry.getPersistenceStore().getTransaction().begin();
               while (fieldsIter.hasNext())
                {
                    LocalizedField
field = (LocalizedField) fieldsIter.next();
                    String id = field.getId().toString();
                   String[] ids = actionRequest.getParameterValues("metadata_id");
      
             if(ids != null)
                    {
                        for(int i=0; i<ids.length;
i++)
                        {
                            String mid = ids[i];
         
                  if(mid.equals(id))
                            {
                      
         fieldsIter.remove();
                            }
                        }
   
                }
                }
                registry.getPersistenceStore().getTransaction().commit();
           }
            else if(action.equals("add_metadata"))
            {
           
    GenericMetadata md = pa.getMetadata();
                
                PersistenceStore
store = registry.getPersistenceStore();
                System.out.println("Transcation is
open: " + store.getTransaction().isOpen());
                store.getTransaction().begin();
               System.out.println("Transcation is open: " + store.getTransaction().isOpen());
               String name = actionRequest.getParameter("name");
                String value
= actionRequest.getParameter("value");
                String localeParam = actionRequest.getParameter("locale");
               if(localeParam == null)
                {
                    localeParam =
"en"; //need to default better
                }
                Locale locale = new Locale(localeParam);
               
                md.addField(locale, name, value);
                
      
         store.getTransaction().commit();
            }
        }
	}
   }
  
  
  
  1.2       +2 -1      jakarta-jetspeed-2/applications/pam/src/java/org/apache/jetspeed/portlets/pam/PortletApplicationResources.java
  
  Index: PortletApplicationResources.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/applications/pam/src/java/org/apache/jetspeed/portlets/pam/PortletApplicationResources.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- PortletApplicationResources.java	6 Jul 2004 16:11:25 -0000	1.1
  +++ PortletApplicationResources.java	3 Sep 2004 19:35:50 -0000	1.2
  @@ -24,6 +24,7 @@
   public final class PortletApplicationResources
   {
       final static String REQUEST_SELECT_NODE = "select_node";
  +    final static String REQUEST_SELECT_PORTLET = "select_portlet";
       final static String PAM_CURRENT_PA = "org.apache.jetspeed.pam.pa";
       final static String CPS_REGISTRY_COMPONENT = "cps:PortletRegistryComponent";
   }
  
  
  

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


Mime
View raw message