01: /**
02: * Copyright 2006 Webmedia Group Ltd.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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: **/package org.araneaframework.jsp.tag.support;
16:
17: import java.io.Writer;
18: import java.util.HashMap;
19: import java.util.Map;
20: import javax.servlet.jsp.JspException;
21: import org.araneaframework.core.ApplicationService;
22: import org.araneaframework.framework.ThreadContext;
23: import org.araneaframework.framework.TopServiceContext;
24: import org.araneaframework.framework.TransactionContext;
25: import org.araneaframework.http.HttpInputData;
26: import org.araneaframework.http.HttpOutputData;
27: import org.araneaframework.http.util.EnvironmentUtil;
28: import org.araneaframework.http.util.URLUtil;
29: import org.araneaframework.jsp.tag.uilib.BaseWidgetTag;
30:
31: /**
32: * Widget action url tag. Makes available <code>widgetActionUrl</code> EL
33: * variable that can be used to fetch data from widget's action.
34: *
35: * @author Alar Kvell (alar@araneaframework.org)
36: *
37: * @jsp.tag
38: * name = "widgetActionUrl"
39: * body-content = "JSP"
40: * description = "Widget action url tag.<br/>
41: Makes available following page scope variables:
42: <ul>
43: <li><i>widgetActionUrl</i> - URL which points to widget's action.
44: </ul> "
45: */
46: public class WidgetActionUrlTag extends BaseWidgetTag {
47:
48: public static final String WIDGET_ACTION_URL_KEY = "widgetActionUrl";
49:
50: protected String actionId;
51:
52: public int doStartTag(Writer out) throws Exception {
53: super .doStartTag(out);
54: addContextEntry(WIDGET_ACTION_URL_KEY, getWidgetActionUrl());
55: return EVAL_BODY_INCLUDE;
56: }
57:
58: protected String getWidgetActionUrl() throws JspException {
59: Map m = new HashMap();
60: m.put(TransactionContext.TRANSACTION_ID_KEY,
61: TransactionContext.OVERRIDE_KEY);
62: m.put(TopServiceContext.TOP_SERVICE_KEY, EnvironmentUtil
63: .requireTopServiceId(getEnvironment()));
64: m.put(ThreadContext.THREAD_SERVICE_KEY, EnvironmentUtil
65: .requireThreadServiceId(getEnvironment()));
66: m.put(ApplicationService.ACTION_PATH_KEY, fullId);
67: if (actionId != null) {
68: m.put(ApplicationService.ACTION_HANDLER_ID_KEY, actionId);
69: }
70: return ((HttpOutputData) getOutputData()).encodeURL(URLUtil
71: .parametrizeURI(((HttpInputData) getOutputData()
72: .getInputData()).getContainerURL(), m));
73: }
74:
75: public void doFinally() {
76: super .doFinally();
77: actionId = null;
78: }
79:
80: /**
81: * @jsp.attribute
82: * type = "java.lang.String"
83: * required = "false"
84: * description = "Action id"
85: */
86: public void setActionId(String actionId) throws JspException {
87: this .actionId = (String) evaluateNotNull("actionId", actionId,
88: String.class);
89: }
90:
91: }
|