001: /**
002: * Copyright 2003 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: */package com.sun.portal.wsrp.producer.markup.impl;
013:
014: import com.sun.portal.providers.context.ProviderContext;
015: import com.sun.portal.providers.window.util.Util;
016: import com.sun.portal.wsrp.common.WSRPToContainerMap;
017: import com.sun.portal.wsrp.common.WSRPSpecKeys;
018: import com.sun.portal.wsrp.common.stubs.*;
019: import com.sun.portal.container.*;
020: import com.sun.portal.log.common.PortalLogger;
021:
022: import java.util.Map;
023: import java.util.HashMap;
024: import java.util.logging.Logger;
025: import java.util.logging.Level;
026: import java.net.URLEncoder;
027:
028: import com.iplanet.am.util.Debug;
029:
030: public class ProducerChannelURL implements ChannelURL {
031:
032: private String _desktopURL;
033: private Map _params = null;
034: private String _action;
035: private ChannelMode _newChannelMode;
036: private WindowState _newWindowState;
037: private boolean _secure = false;
038: private Debug _debug = null;
039: private Templates _templates = null;
040: private Map _baseMap = null;
041: private boolean _requiresConsumerRewriting = false;
042: private static Logger logger = PortalLogger
043: .getLogger(ProducerChannelURL.class);
044:
045: public ProducerChannelURL(Debug debug, Templates templates,
046: Map baseParamMap) {
047: _templates = templates;
048: _baseMap = baseParamMap;
049: }
050:
051: public void setChannelMode(ChannelMode newChannelMode) {
052: _newChannelMode = newChannelMode;
053: }
054:
055: public void setWindowState(WindowState newWindowState) {
056: _newWindowState = newWindowState;
057: }
058:
059: public void setURLType(String type) {
060: _action = type;
061: }
062:
063: public void setParameter(String name, String value) {
064: String values[] = new String[1];
065: values[0] = value;
066: setParameter(name, values);
067: }
068:
069: public void setParameter(String name, String[] values) {
070: if (_params == null) {
071: _params = new HashMap();
072: }
073: _params.put(name, values);
074: }
075:
076: public void setParameters(Map parametersMap) {
077: _params = parametersMap;
078: }
079:
080: public void setSecure(boolean secure) {
081: _secure = secure;
082: }
083:
084: public WindowState getWindowState() {
085: return _newWindowState;
086: }
087:
088: public ChannelMode getChannelMode() {
089: return _newChannelMode;
090: }
091:
092: public String getURLType() {
093: return _action;
094: }
095:
096: public Map getParameters() {
097: return _params;
098: }
099:
100: public boolean isSecure() {
101: return _secure;
102: }
103:
104: public String toString() {
105:
106: String mode = null;
107: String state = null;
108: String paramStr = null;
109: String template = null;
110:
111: // Determine whether to do producer rewrite or consumer rewrite.
112: if (_templates != null) {
113: if (_action != null) {
114: if (_action.equals(ChannelURL.ACTION_URL_TYPE)) {
115: if (_secure) {
116: template = _templates
117: .getSecureBlockingActionTemplate();
118: } else {
119: template = _templates
120: .getBlockingActionTemplate();
121: }
122: } else if (_action.equals(ChannelURL.RENDER_URL_TYPE)) {
123: if (_secure) {
124: template = _templates.getSecureRenderTemplate();
125: } else {
126: template = _templates.getRenderTemplate();
127: }
128: } else {
129: if (logger.isLoggable(Level.SEVERE))
130: logger.log(Level.SEVERE, "PSWS_CSPWPMI0003",
131: _action);
132:
133: throw new RuntimeException(
134: "ProducerChannelURL.toString(): unknown URL type "
135: + _action);
136: }
137: } else {
138: if (logger.isLoggable(Level.SEVERE))
139: logger.log(Level.SEVERE, "PSWS_CSPWPMI0004");
140: throw new RuntimeException(
141: "ProducerChannelURL.toString(): null type.");
142: }
143: }
144:
145: // Get the channel mode and window state in WSRP form
146: if (_newChannelMode != null) {
147: mode = WSRPToContainerMap
148: .mapChannelModeToWSRP(_newChannelMode);
149: if (mode == null) {
150: mode = _newChannelMode.toString();
151: }
152: }
153:
154: if (_newWindowState != null) {
155: state = WSRPToContainerMap
156: .mapWindowStateToWSRP(_newWindowState);
157: if (state == null) {
158: state = _newWindowState.toString();
159: }
160: }
161:
162: Map params = getParameters();
163: if (params != null && !params.isEmpty()) {
164: paramStr = URLEncoder.encode(Util.getStringFromMap(params));
165: }
166:
167: // If we can a template here, that means we can do producer rewrite
168: if (template == null) {
169: // Comsumer rewrite
170:
171: _requiresConsumerRewriting = true;
172:
173: StringBuffer urlsb = new StringBuffer(
174: WSRPSpecKeys.URL_REWRITE_START);
175: urlsb.append(WSRPSpecKeys.URL_TYPE);
176: urlsb.append("=");
177:
178: if (_action.equals(ChannelURL.ACTION_URL_TYPE)) {
179: urlsb.append(WSRPSpecKeys.URL_TYPE_BLOCKING_ACTION);
180: if (params != null && !params.isEmpty()) {
181: urlsb.append("&");
182: urlsb.append(WSRPSpecKeys.INTERACTION_STATE);
183: urlsb.append("=");
184: urlsb.append(paramStr);
185: }
186: } else if (_action.equals(ChannelURL.RENDER_URL_TYPE)) {
187: urlsb.append(WSRPSpecKeys.URL_TYPE_RENDER);
188: if (params != null && !params.isEmpty()) {
189: urlsb.append("&");
190: urlsb.append(WSRPSpecKeys.NAVIGATIONAL_STATE);
191: urlsb.append("=");
192: urlsb.append(paramStr);
193: }
194: }
195:
196: if (_newChannelMode != null) {
197: urlsb.append("&");
198: urlsb.append(WSRPSpecKeys.MODE);
199: urlsb.append("=");
200: urlsb.append(mode);
201: }
202:
203: if (_newWindowState != null) {
204: urlsb.append("&");
205: urlsb.append(WSRPSpecKeys.WINDOW_STATE);
206: urlsb.append("=");
207: urlsb.append(state);
208: }
209:
210: if (_secure) {
211: urlsb.append("&");
212: urlsb.append(WSRPSpecKeys.SECURE_URL);
213: urlsb.append("=");
214: urlsb.append(WSRPSpecKeys.SECURE_URL_TRUE);
215: }
216:
217: urlsb.append(WSRPSpecKeys.URL_REWRITE_END);
218: return urlsb.toString();
219: } else {
220: //Producer rewriting
221:
222: _requiresConsumerRewriting = false;
223:
224: Map paramMap = new HashMap();
225: paramMap.putAll(_baseMap);
226: paramMap.put(WSRPSpecKeys.MODE, mode);
227: paramMap.put(WSRPSpecKeys.WINDOW_STATE, state);
228: if (_action.equals(ChannelURL.ACTION_URL_TYPE)) {
229: paramMap.put(WSRPSpecKeys.INTERACTION_STATE, paramStr);
230: paramMap.put(WSRPSpecKeys.URL_TYPE,
231: WSRPSpecKeys.URL_TYPE_BLOCKING_ACTION);
232: } else {
233: paramMap.put(WSRPSpecKeys.NAVIGATIONAL_STATE, paramStr);
234: paramMap.put(WSRPSpecKeys.URL_TYPE,
235: WSRPSpecKeys.URL_TYPE_RENDER);
236: }
237: ProducerRewriter pr = new ProducerRewriter(_debug);
238: return pr.rewrite(template, paramMap);
239: }
240: }
241:
242: /**
243: * Determines whether consumer rewriting is required for this
244: * channel URL.
245: **/
246: public boolean requiresConsumerRewriting() {
247: return _requiresConsumerRewriting;
248: }
249: }
|