001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.taglib.portlet;
022:
023: import com.liferay.portal.kernel.util.BooleanWrapper;
024: import com.liferay.portal.kernel.util.LongWrapper;
025: import com.liferay.portal.kernel.util.MethodInvoker;
026: import com.liferay.portal.kernel.util.MethodWrapper;
027: import com.liferay.portal.kernel.util.NullWrapper;
028: import com.liferay.portal.kernel.util.PortalClassLoaderUtil;
029: import com.liferay.portal.kernel.util.StringPool;
030: import com.liferay.taglib.util.ParamAncestorTagImpl;
031:
032: import java.util.Map;
033:
034: import javax.servlet.jsp.JspException;
035: import javax.servlet.jsp.PageContext;
036:
037: import org.apache.commons.logging.Log;
038: import org.apache.commons.logging.LogFactory;
039:
040: /**
041: * <a href="ActionURLTag.java.html"><b><i>View Source</i></b></a>
042: *
043: * @author Brian Wing Shun Chan
044: *
045: */
046: public class ActionURLTag extends ParamAncestorTagImpl {
047:
048: public static String doTag(boolean action, String windowState,
049: String portletMode, String var, String varImpl,
050: Boolean secure, String portletName, Boolean anchor,
051: Boolean encrypt, long doAsUserId,
052: Boolean portletConfiguration, Map params,
053: boolean writeOutput, PageContext pageContext)
054: throws Exception {
055:
056: Object returnObj = null;
057:
058: ClassLoader contextClassLoader = Thread.currentThread()
059: .getContextClassLoader();
060:
061: try {
062: Thread.currentThread().setContextClassLoader(
063: PortalClassLoaderUtil.getClassLoader());
064:
065: Object windowStateWrapper = windowState;
066:
067: if (windowStateWrapper == null) {
068: windowStateWrapper = new NullWrapper(String.class
069: .getName());
070: }
071:
072: Object portletModeWrapper = portletMode;
073:
074: if (portletModeWrapper == null) {
075: portletModeWrapper = new NullWrapper(String.class
076: .getName());
077: }
078:
079: Object varWrapper = var;
080:
081: if (varWrapper == null) {
082: varWrapper = new NullWrapper(String.class.getName());
083: }
084:
085: Object varImplWrapper = varImpl;
086:
087: if (varImplWrapper == null) {
088: varImplWrapper = new NullWrapper(String.class.getName());
089: }
090:
091: Object secureWrapper = secure;
092:
093: if (secureWrapper == null) {
094: secureWrapper = new NullWrapper(Boolean.class.getName());
095: }
096:
097: Object portletNameWrapper = portletName;
098:
099: if (portletNameWrapper == null) {
100: portletNameWrapper = new NullWrapper(String.class
101: .getName());
102: }
103:
104: Object anchorWrapper = anchor;
105:
106: if (anchorWrapper == null) {
107: anchorWrapper = new NullWrapper(Boolean.class.getName());
108: }
109:
110: Object encryptWrapper = encrypt;
111:
112: if (encryptWrapper == null) {
113: encryptWrapper = new NullWrapper(Boolean.class
114: .getName());
115: }
116:
117: Object portletConfigurationWrapper = portletConfiguration;
118:
119: if (portletConfigurationWrapper == null) {
120: portletConfigurationWrapper = new NullWrapper(
121: Boolean.class.getName());
122: }
123:
124: Object paramsWrapper = params;
125:
126: if (paramsWrapper == null) {
127: paramsWrapper = new NullWrapper(Map.class.getName());
128: }
129:
130: MethodWrapper methodWrapper = new MethodWrapper(_TAG_CLASS,
131: _TAG_DO_END_METHOD, new Object[] {
132: new BooleanWrapper(action),
133: windowStateWrapper, portletModeWrapper,
134: varWrapper, varImplWrapper, secureWrapper,
135: portletNameWrapper, anchorWrapper,
136: encryptWrapper,
137: new LongWrapper(doAsUserId),
138: portletConfigurationWrapper, paramsWrapper,
139: new BooleanWrapper(writeOutput),
140: pageContext });
141:
142: returnObj = MethodInvoker.invoke(methodWrapper);
143: } catch (Exception e) {
144: _log.error(e, e);
145:
146: throw e;
147: } finally {
148: Thread.currentThread().setContextClassLoader(
149: contextClassLoader);
150: }
151:
152: if (returnObj != null) {
153: return returnObj.toString();
154: } else {
155: return StringPool.BLANK;
156: }
157: }
158:
159: public int doEndTag() throws JspException {
160: try {
161: doTag(isAction(), _windowState, _portletMode, _var,
162: _varImpl, _secure, _portletName, _anchor, _encrypt,
163: _doAsUserId, _portletConfiguration, getParams(),
164: true, pageContext);
165: } catch (Exception e) {
166: if (e instanceof JspException) {
167: throw (JspException) e;
168: } else {
169: throw new JspException(e);
170: }
171: } finally {
172: clearParams();
173: }
174:
175: return EVAL_PAGE;
176: }
177:
178: public boolean isAction() {
179: return _ACTION;
180: }
181:
182: public void setWindowState(String windowState) {
183: _windowState = windowState;
184: }
185:
186: public void setPortletMode(String portletMode) {
187: _portletMode = portletMode;
188: }
189:
190: public void setVar(String var) {
191: _var = var;
192: }
193:
194: public void setVarImpl(String varImpl) {
195: _varImpl = varImpl;
196: }
197:
198: public void setSecure(boolean secure) {
199: _secure = Boolean.valueOf(secure);
200: }
201:
202: public void setPortletName(String portletName) {
203: _portletName = portletName;
204: }
205:
206: public void setAnchor(boolean anchor) {
207: _anchor = Boolean.valueOf(anchor);
208: }
209:
210: public void setEncrypt(boolean encrypt) {
211: _encrypt = Boolean.valueOf(encrypt);
212: }
213:
214: public void setDoAsUserId(long doAsUserId) {
215: _doAsUserId = doAsUserId;
216: }
217:
218: public void setPortletConfiguration(boolean portletConfiguration) {
219: _portletConfiguration = Boolean.valueOf(portletConfiguration);
220: }
221:
222: private static final String _TAG_CLASS = "com.liferay.portal.servlet.taglib.portlet.ActionURLTagUtil";
223:
224: private static final String _TAG_DO_END_METHOD = "doEndTag";
225:
226: private static final boolean _ACTION = true;
227:
228: private static Log _log = LogFactory.getLog(ActionURLTag.class);
229:
230: private String _windowState;
231: private String _portletMode;
232: private String _var;
233: private String _varImpl;
234: private Boolean _secure;
235: private String _portletName;
236: private Boolean _anchor;
237: private Boolean _encrypt;
238: private long _doAsUserId;
239: private Boolean _portletConfiguration;
240:
241: }
|