001: /*
002: * Copyright (c) 1998-2004 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: * Free SoftwareFoundation, Inc.
023: * 59 Temple Place, Suite 330
024: * Boston, MA 02111-1307 USA
025: *
026: * @author Sam
027: */
028:
029: package com.caucho.widget;
030:
031: import com.caucho.util.L10N;
032:
033: import javax.portlet.*;
034: import java.util.LinkedHashMap;
035: import java.util.Map;
036: import java.util.logging.Logger;
037:
038: public class PortletWidgetURL extends WidgetURL {
039: private static L10N L = new L10N(PortletWidgetURL.class);
040:
041: static protected final Logger log = Logger
042: .getLogger(PortletWidgetURL.class.getName());
043:
044: private PortletWidgetConnection _connection;
045:
046: private Map<String, String[]> _parameterMap;
047: private PortletMode _portletMode;
048: private WindowState _windowState;
049: private Boolean _isSecure;
050: private boolean _isAction;
051:
052: private PortletURL _portletURL;
053: private String _url;
054:
055: public PortletWidgetURL(PortletWidgetConnection connection) {
056: _connection = connection;
057:
058: }
059:
060: public void setParameter(String name, String value) {
061: String[] values = new String[] { value };
062:
063: setParameter(name, values);
064: }
065:
066: public void setParameter(String name, String[] values) {
067: if (_parameterMap == null)
068: _parameterMap = new LinkedHashMap<String, String[]>();
069:
070: _parameterMap.put(name, values);
071:
072: _url = null;
073:
074: if (_portletURL != null)
075: _portletURL.setParameter(name, values);
076: }
077:
078: public void setParameters(Map<String, String[]> parameters) {
079: if (_parameterMap == null)
080: _parameterMap = new LinkedHashMap<String, String[]>();
081: else
082: _parameterMap.clear();
083:
084: _url = null;
085:
086: _parameterMap.putAll(parameters);
087:
088: if (_portletURL != null)
089: _portletURL.setParameters(parameters);
090: }
091:
092: public void setPortletMode(PortletMode portletMode)
093: throws PortletModeException {
094: if (portletMode.equals(_portletMode))
095: return;
096:
097: _portletMode = portletMode;
098:
099: _url = null;
100:
101: if (_portletURL != null)
102: _portletURL.setPortletMode(portletMode);
103: }
104:
105: public void setWindowState(WindowState windowState)
106: throws WindowStateException {
107: if (windowState.equals(_windowState))
108: return;
109:
110: _windowState = windowState;
111:
112: _url = null;
113:
114: if (_portletURL != null)
115: _portletURL.setWindowState(windowState);
116: }
117:
118: public void setSecure(boolean secure) {
119: if (_isSecure != null && _isSecure.booleanValue() == secure)
120: return;
121:
122: _isSecure = secure ? Boolean.TRUE : Boolean.FALSE;
123:
124: _url = null;
125:
126: if (_portletURL != null) {
127: try {
128: _portletURL.setSecure(secure);
129: } catch (PortletException ex) {
130: throw new RuntimeException(ex);
131: }
132: }
133: }
134:
135: public void setAction(boolean isAction) {
136: if (isAction != _isAction) {
137: _url = null;
138: _portletURL = null;
139:
140: _isAction = isAction;
141: }
142: }
143:
144: public String toString() {
145: if (_url != null)
146: return _url;
147:
148: if (_portletURL != null)
149: return _portletURL.toString();
150:
151: try {
152: RenderResponse response = _connection.getRenderResponse();
153:
154: _portletURL = _isAction ? response.createActionURL()
155: : response.createRenderURL();
156:
157: if (_windowState != null)
158: _portletURL.setWindowState(_windowState);
159: if (_portletMode != null)
160: _portletURL.setPortletMode(_portletMode);
161:
162: if (_isSecure != null)
163: _portletURL.setSecure(_isSecure.booleanValue());
164:
165: if (_parameterMap != null) {
166: for (Map.Entry<String, String[]> entry : _parameterMap
167: .entrySet()) {
168: _portletURL.setParameter(entry.getKey(), entry
169: .getValue());
170: }
171: }
172: } catch (PortletException ex) {
173: throw new RuntimeException(ex);
174: }
175:
176: _url = _portletURL.toString();
177:
178: return _url;
179: }
180: }
|