KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jetspeed > modules > actions > controllers > XMultiColumnControllerAction


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.controllers;
17
18 import java.util.List JavaDoc;
19 import java.util.Map JavaDoc;
20
21 import javax.servlet.ServletRequest JavaDoc;
22
23 import org.apache.jetspeed.om.profile.psml.PsmlEntry;
24 import org.apache.jetspeed.portal.Portlet;
25 import org.apache.jetspeed.portal.PortletController;
26 import org.apache.jetspeed.services.rundata.JetspeedRunData;
27 import org.apache.jetspeed.services.statemanager.SessionState;
28 import org.apache.jetspeed.util.template.JetspeedTool;
29 import org.apache.jetspeed.util.template.JspTemplate;
30 import org.apache.jetspeed.util.StringUtils;
31 import org.apache.turbine.util.RunData;
32 import org.apache.velocity.context.Context;
33
34 /**
35  * XMultiColumnControllerAction
36  *
37  * @author <a HREF="mailto:junyang@cisco.com">Jun Yang</a>
38  * @version $Id: XMultiColumnControllerAction.java,v 1.2 2004/02/23 02:49:58 jford Exp $
39  */

40 public class XMultiColumnControllerAction extends MultiColumnControllerAction
41 {
42     protected void buildCustomizeContext(
43         PortletController controller,
44         Context context,
45         RunData rundata
46     )
47     {
48         super.buildCustomizeContext(controller, context, rundata);
49         context.put("template", "x-multicolumn-customize.vm");
50         context.put("action", "controllers.XMultiColumnControllerAction");
51
52         context.put("includedContent", new JspTemplate(rundata, "/controllers/html/x-multicolumn-customize.jsp"));
53         ServletRequest JavaDoc request = rundata.getRequest();
54         request.setAttribute("jspContext", context);
55
56         // debug
57
Object JavaDoc[] columns = (Object JavaDoc[]) context.get("portlets");
58         Map JavaDoc portletTitleMap = (Map JavaDoc) context.get("titles");
59         for (int i = 0; i < columns.length; i++)
60         {
61             List JavaDoc portletList = (List JavaDoc) columns[i];
62             for (int j = 0; j < portletList.size(); j++)
63             {
64                 PsmlEntry entry = (PsmlEntry) portletList.get(j);
65                 String JavaDoc portletTitle = (String JavaDoc) portletTitleMap.get(entry.getId());
66                 String JavaDoc portletSkinName = entry.getSkin() == null ? "-- Default --" : entry.getSkin().getName();
67                 String JavaDoc portletSecurityId =
68                     entry.getSecurityRef() == null ?
69                     "-- Default --" :
70                     entry.getSecurityRef().getParent();
71                 String JavaDoc controlListBox =
72                 (entry.getControl() != null && entry.getControl().getName() != null) ?
73                     JetspeedTool.getPortletParameter(rundata,
74                                                      (Portlet) rundata.getUser().getTemp("customizer"),
75                                                       "control", entry.getControl().getName()) :
76                     JetspeedTool.getPortletParameter(rundata, (Portlet) rundata.getUser().getTemp("customizer"), "control");
77                 controlListBox = controlListBox.substring(12);
78                 controlListBox = controlListBox.replace('\n', ' ');
79                 controlListBox = controlListBox.replace('\r', ' ');
80                 int z = 0;
81             }
82         }
83     }
84     
85     public void doSave(RunData data, Context context)
86     {
87         applyModelChanges(data, context);
88         super.doSave(data, context);
89     }
90
91     public void doDelete(RunData data, Context context)
92     {
93         applyModelChanges(data, context);
94         super.doDelete(data, context);
95     }
96
97     public void doControl(RunData data, Context context)
98     {
99         applyModelChanges(data, context);
100         super.doControl(data, context);
101     }
102
103     protected void applyModelChanges(RunData data, Context context)
104     {
105         ServletRequest JavaDoc request = data.getRequest();
106         String JavaDoc[] modelChangeList = request.getParameterValues("modelChangeList");
107         if (modelChangeList != null)
108         {
109             String JavaDoc[] moves = StringUtils.stringToArray(modelChangeList[0], ";");
110
111             SessionState customizationState = ((JetspeedRunData) data).getPageSessionState();
112             List JavaDoc[] columns = (List JavaDoc[]) customizationState.getAttribute("customize-columns");
113
114             for (int i = 0; i < moves.length; i++)
115             {
116                 String JavaDoc[] values = StringUtils.stringToArray(moves[i], ",");
117                 int originCol = Integer.parseInt(values[0]);
118                 int originRow = Integer.parseInt(values[1]);
119                 int destCol = Integer.parseInt(values[2]);
120                 int destRow = Integer.parseInt(values[3]);
121
122                 Object JavaDoc portletEntry = columns[originCol].get(originRow);
123                 columns[originCol].remove(originRow);
124                 columns[destCol].add(destRow, portletEntry);
125             }
126         }
127     }
128 }
129
130
Popular Tags