001: /*
002: * Copyright 2002 Sun Microsystems, Inc. All
003: * rights reserved. Use of this product is subject
004: * to license terms. Federal Acquisitions:
005: * Commercial Software -- Government Users
006: * Subject to Standard License Terms and
007: * Conditions.
008: *
009: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
010: * are trademarks or registered trademarks of Sun Microsystems,
011: * Inc. in the United States and other countries.
012: */
013: package com.sun.portal.wsrp.common;
014:
015: import java.util.List;
016: import java.util.ArrayList;
017: import java.util.Map;
018: import java.util.HashMap;
019: import java.util.Hashtable;
020: import java.util.Iterator;
021: import java.util.Collections;
022: import java.util.StringTokenizer;
023:
024: import com.sun.portal.container.*;
025:
026: public class WSRPToContainerMap {
027:
028: //*****************************************************************
029: //
030: // Channel Mode conversion
031: //
032: //***************************************************************
033:
034: private static final Map _windowStateMap = getWindowStateMap();
035: private static final Map _windowStateReverseMap = getWindowStateReverseMap();
036:
037: private static Map getWindowStateMap() {
038: Map windowStateMap = new HashMap();
039:
040: windowStateMap.put(WSRPSpecKeys.WINDOW_STATE_MINIMIZED,
041: WindowState.MINIMIZED);
042: windowStateMap.put(WSRPSpecKeys.WINDOW_STATE_MAXIMIZED,
043: WindowState.MAXIMIZED);
044: windowStateMap.put(WSRPSpecKeys.WINDOW_STATE_NORMAL,
045: WindowState.NORMAL);
046: return windowStateMap;
047:
048: }
049:
050: private static Map getWindowStateReverseMap() {
051:
052: Map windowStateReverseMap = new HashMap();
053: windowStateReverseMap.put(WindowState.MINIMIZED,
054: WSRPSpecKeys.WINDOW_STATE_MINIMIZED);
055: windowStateReverseMap.put(WindowState.MAXIMIZED,
056: WSRPSpecKeys.WINDOW_STATE_MAXIMIZED);
057: windowStateReverseMap.put(WindowState.NORMAL,
058: WSRPSpecKeys.WINDOW_STATE_NORMAL);
059:
060: return windowStateReverseMap;
061: }
062:
063: /**
064: * Convert the window state representation used by the WSRP to
065: * the representation understood by the container layer
066: */
067: public static List mapWindowStateToContainer(
068: String[] wsrpWindowStates) {
069: List newList = new ArrayList();
070: for (int i = 0; wsrpWindowStates != null
071: && i < wsrpWindowStates.length; i++) {
072: WindowState winState = (WindowState) _windowStateMap
073: .get(wsrpWindowStates[i]);
074: if (winState != null) {
075: newList.add(winState);
076: }
077: }
078: return newList;
079:
080: }
081:
082: /**
083: * Convert the WindowState representation
084: * underderstood by the container layer to WSRP
085: * Check for null
086: */
087: public static String[] mapWindowStateToWSRP(
088: List containerWindowStates) {
089: String[] wsrpWindowStates = new String[containerWindowStates
090: .size()];
091:
092: Iterator iter = containerWindowStates.iterator();
093: int i = 0;
094: while (iter.hasNext()) {
095: wsrpWindowStates[i] = (String) _windowStateReverseMap
096: .get(iter.next());
097: i++;
098: }
099: return wsrpWindowStates;
100:
101: }
102:
103: /**
104: /**
105: * Convert the window state representation used by the WSRP to
106: * the representation understood by the container layer
107: */
108: public static WindowState mapWindowStateToContainer(
109: String wsrpWindowState) {
110: WindowState winState = (WindowState) _windowStateMap
111: .get(wsrpWindowState);
112: return winState;
113: }
114:
115: /**
116: * Convert the window state representation used by the container layer to
117: * the representation understood by the WSRP
118: */
119: public static String mapWindowStateToWSRP(WindowState windowState) {
120: String winState = (String) _windowStateReverseMap
121: .get(windowState);
122: return winState;
123: }
124:
125: //*****************************************************************
126: //
127: // Channel Mode conversion
128: //
129: //***************************************************************
130:
131: private static final Map _channelModeMap = getChannelModeMap();
132: private static final Map _channelModeReverseMap = getChannelModeReverseMap();
133:
134: private static Map getChannelModeMap() {
135: Map channelModeMap = new HashMap();
136:
137: channelModeMap.put(WSRPSpecKeys.MODE_VIEW, ChannelMode.VIEW);
138: channelModeMap.put(WSRPSpecKeys.MODE_EDIT, ChannelMode.EDIT);
139: channelModeMap.put(WSRPSpecKeys.MODE_HELP, ChannelMode.HELP);
140: return channelModeMap;
141:
142: }
143:
144: private static Map getChannelModeReverseMap() {
145:
146: Map channelModeReverseMap = new HashMap();
147: channelModeReverseMap.put(ChannelMode.VIEW,
148: WSRPSpecKeys.MODE_VIEW);
149: channelModeReverseMap.put(ChannelMode.EDIT,
150: WSRPSpecKeys.MODE_EDIT);
151: channelModeReverseMap.put(ChannelMode.HELP,
152: WSRPSpecKeys.MODE_HELP);
153:
154: return channelModeReverseMap;
155: }
156:
157: /**
158: * Convert the channelMode representation
159: * underderstood by the container layer to WSRP
160: * Check for null
161: */
162: public static String[] mapChannelModeToWSRP(
163: List containerChannelModes) {
164: String[] wsrpChannelModes = new String[containerChannelModes
165: .size()];
166:
167: Iterator iter = containerChannelModes.iterator();
168: int i = 0;
169: while (iter.hasNext()) {
170: wsrpChannelModes[i] = (String) _channelModeReverseMap
171: .get(iter.next());
172: i++;
173: }
174: return wsrpChannelModes;
175:
176: }
177:
178: /**
179: * Convert the channelMode representation used by the WSRP to
180: * the representation understood by the container layer
181: */
182: public static List mapChannelModeToContainer(
183: String[] wsrpChannelModes) {
184: List newList = new ArrayList();
185: for (int i = 0; wsrpChannelModes != null
186: && i < wsrpChannelModes.length; i++) {
187: ChannelMode mode = (ChannelMode) _channelModeMap
188: .get(wsrpChannelModes[i]);
189: if (mode != null) {
190: newList.add(mode);
191: }
192: }
193: return newList;
194:
195: }
196:
197: /**
198: * Convert the window state representation used by the WSRP to
199: * the representation understood by the container layer
200: */
201: public static ChannelMode mapChannelModeToContainer(
202: String wsrpChannelMode) {
203: ChannelMode mode = (ChannelMode) _channelModeMap
204: .get(wsrpChannelMode);
205: return mode;
206: }
207:
208: /**
209: * Convert the window state representation used by the container layer to
210: * the representation understood by the WSRP
211: */
212: public static String mapChannelModeToWSRP(ChannelMode channelMode) {
213: String mode = (String) _channelModeReverseMap.get(channelMode);
214: return mode;
215: }
216:
217: //***************************************************************
218: // URL Type
219: //
220: //************************************************************
221:
222: private static final Map _urlTypeMap = getURLTypeMap();
223: private static final Map _urlTypeReverseMap = getURLTypeReverseMap();
224:
225: private static Map getURLTypeMap() {
226: Map urlTypeMap = new HashMap();
227:
228: urlTypeMap.put("blockingAction", ChannelURL.ACTION_URL_TYPE);
229: urlTypeMap.put("render", ChannelURL.RENDER_URL_TYPE);
230: return urlTypeMap;
231:
232: }
233:
234: private static Map getURLTypeReverseMap() {
235: Map urlTypeReverseMap = new HashMap();
236:
237: urlTypeReverseMap.put(ChannelURL.ACTION_URL_TYPE,
238: "blockingAction");
239: urlTypeReverseMap.put(ChannelURL.RENDER_URL_TYPE, "render");
240: return urlTypeReverseMap;
241:
242: }
243:
244: /**
245: * Convert the URLType representation used by the Portlet to
246: * the representation understood by the container layer
247: */
248: public static String mapURLTypeToContainer(String urlType) {
249: String channelURLType = (String) _urlTypeMap.get(urlType);
250: return channelURLType;
251: }
252:
253: /**
254: * Convert the URLType representation used by the container layer to
255: * the representation understood by the WSRP
256: */
257: public static String mapURLTypeToWSRP(String urlType) {
258: String wsrpUrlType = (String) _urlTypeReverseMap.get(urlType);
259: return wsrpUrlType;
260: }
261:
262: }
|