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.framework.ThreadContext;
22: import org.araneaframework.framework.TopServiceContext;
23: import org.araneaframework.framework.TransactionContext;
24: import org.araneaframework.http.HttpInputData;
25: import org.araneaframework.http.HttpOutputData;
26: import org.araneaframework.http.util.EnvironmentUtil;
27: import org.araneaframework.http.util.URLUtil;
28: import org.araneaframework.jsp.tag.BaseTag;
29:
30: /**
31: * Service action url tag. Makes available <code>serviceActionUrl</code> EL
32: * variable that can be used to fetch data from a service.
33: *
34: * @author Alar Kvell (alar@araneaframework.org)
35: *
36: * @jsp.tag
37: * name = "serviceActionUrl"
38: * body-content = "JSP"
39: * description = "Service action url tag.<br/>
40: Makes available following page scope variables:
41: <ul>
42: <li><i>serviceActionUrl</i> - URL which points to service.
43: </ul> "
44: */
45: public class ServiceActionUrlTag extends BaseTag {
46:
47: public static final String WIDGET_ACTION_URL_KEY = "serviceActionUrl";
48:
49: protected String id;
50:
51: public int doStartTag(Writer out) throws Exception {
52: super .doStartTag(out);
53: addContextEntry(WIDGET_ACTION_URL_KEY, getWidgetActionUrl());
54: return EVAL_BODY_INCLUDE;
55: }
56:
57: protected String getWidgetActionUrl() throws JspException {
58: Map m = new HashMap();
59: m.put(TransactionContext.TRANSACTION_ID_KEY,
60: TransactionContext.OVERRIDE_KEY);
61: m.put(TopServiceContext.TOP_SERVICE_KEY, EnvironmentUtil
62: .requireTopServiceId(getEnvironment()));
63: m.put(ThreadContext.THREAD_SERVICE_KEY, id);
64: return ((HttpOutputData) getOutputData()).encodeURL(URLUtil
65: .parametrizeURI(((HttpInputData) getOutputData()
66: .getInputData()).getContainerURL(), m));
67: }
68:
69: public void doFinally() {
70: super .doFinally();
71: id = null;
72: }
73:
74: /**
75: * @jsp.attribute
76: * type = "java.lang.String"
77: * required = "true"
78: * description = "Service id."
79: */
80: public void setId(String id) throws JspException {
81: this .id = (String) evaluateNotNull("id", id, String.class);
82: }
83:
84: }
|