KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jetspeed > modules > actions > portlets > ControllerUpdateAction


1 /*
2  * Copyright 2000-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.jetspeed.modules.actions.portlets;
17
18 import org.apache.jetspeed.modules.actions.portlets.security.SecurityConstants;
19 import org.apache.jetspeed.om.registry.MediaTypeRegistry;
20 import org.apache.jetspeed.om.registry.PortletControllerEntry;
21 import org.apache.jetspeed.om.registry.RegistryEntry;
22 import org.apache.jetspeed.portal.portlets.VelocityPortlet;
23 import org.apache.jetspeed.services.logging.JetspeedLogFactoryService;
24 import org.apache.jetspeed.services.logging.JetspeedLogger;
25
26 import org.apache.jetspeed.services.Registry;
27 import org.apache.turbine.util.RunData;
28 import org.apache.velocity.context.Context;
29
30 /**
31  * This action enables to update the controller entries
32  *
33  * @author <a HREF="mailto:caius1440@hotmail.com">Jeremy Ford</a>
34  * @version $Id: ControllerUpdateAction.java,v 1.4 2004/02/23 02:56:58 jford Exp $
35  */

36 public class ControllerUpdateAction extends RegistryUpdateAction
37 {
38     private static final String JavaDoc CONTROLLER_UPDATE_PANE = "ControllerForm";
39     
40     /**
41      * Static initialization of the logger for this class
42      */

43     private static final JetspeedLogger logger = JetspeedLogFactoryService.getLogger(ControllerUpdateAction.class.getName());
44
45     public ControllerUpdateAction()
46     {
47         registryEntryName = "controller_name";
48         registry = Registry.PORTLET_CONTROLLER;
49         pane = CONTROLLER_UPDATE_PANE;
50     }
51
52     /**
53      * @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)
54      */

55     protected void buildNormalContext(
56         VelocityPortlet portlet,
57         Context context,
58         RunData rundata)
59         throws Exception JavaDoc
60     {
61         super.buildNormalContext(portlet, context, rundata);
62
63         String JavaDoc mode =
64             rundata.getParameters().getString(SecurityConstants.PARAM_MODE);
65
66         if (mode != null)
67         {
68             if(mode.equals(SecurityConstants.PARAM_MODE_DELETE)
69                 || mode.equals(SecurityConstants.PARAM_MODE_UPDATE))
70             {
71                 String JavaDoc controllerName =
72                     rundata.getParameters().getString(registryEntryName);
73                 PortletControllerEntry controllerEntry =
74                     (PortletControllerEntry) Registry.getEntry(
75                         registry,
76                         controllerName);
77                 context.put("entry", controllerEntry);
78             }
79             
80             if(mode.equals(SecurityConstants.PARAM_MODE_UPDATE))
81             {
82                 MediaTypeRegistry mediaTypeReg = (MediaTypeRegistry)Registry.get(Registry.MEDIA_TYPE);
83                 context.put("media_types", iteratorToCollection(mediaTypeReg.listEntryNames()));
84             }
85         }
86     }
87
88     protected void updateRegistryEntry(
89         RunData rundata,
90         RegistryEntry registryEntry)
91         throws Exception JavaDoc
92     {
93         super.updateRegistryEntry(rundata, registryEntry);
94
95         PortletControllerEntry controllerEntry =
96             (PortletControllerEntry) registryEntry;
97         String JavaDoc className = rundata.getParameters().getString("class_name");
98         if (hasChanged(controllerEntry.getClassname(), className))
99         {
100             controllerEntry.setClassname(className);
101         }
102     }
103
104     /**
105      * @param rundata
106      */

107     protected void clearUserData(RunData rundata)
108     {
109         try
110         {
111             super.clearUserData(rundata);
112
113             rundata.getUser().removeTemp("media_type_ref");
114         }
115         catch (Exception JavaDoc e)
116         {
117             if (logger.isDebugEnabled())
118             {
119                 logger.debug("ControllerUpdateAction: Failed to clear user data");
120             }
121         }
122
123     }
124
125     /**
126      * @param rundata
127      */

128     protected void resetForm(RunData rundata)
129     {
130         super.resetForm(rundata);
131         String JavaDoc mediaTypeRef =
132             rundata.getParameters().getString("media_type_ref");
133
134         rundata.getUser().setTemp("media_type_ref", mediaTypeRef);
135     }
136 }
137
Popular Tags