KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opensymphony > webwork > components > Href


1 package com.opensymphony.webwork.components;
2
3 import com.opensymphony.util.TextUtils;
4 import com.opensymphony.webwork.config.Configuration;
5 import com.opensymphony.webwork.portlet.context.PortletContext;
6 import com.opensymphony.xwork.util.OgnlValueStack;
7
8 import javax.servlet.http.HttpServletRequest JavaDoc;
9 import javax.servlet.http.HttpServletResponse JavaDoc;
10
11 /**
12  * User: plightbo
13  * Date: Jul 20, 2005
14  * Time: 7:22:58 AM
15  */

16 public class Href extends ClosingUIBean {
17     final public static String JavaDoc OPEN_TEMPLATE = "a";
18     final public static String JavaDoc TEMPLATE = "a-close";
19     final public static String JavaDoc COMPONENT_NAME = Href.class.getName();
20
21     protected String JavaDoc href;
22     protected String JavaDoc errorText;
23     protected String JavaDoc showErrorTransportText;
24     protected String JavaDoc notifyTopics;
25     protected String JavaDoc afterLoading;
26
27     public Href(OgnlValueStack stack, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) {
28         super(stack, request, response);
29     }
30
31     public String JavaDoc getDefaultOpenTemplate() {
32         return OPEN_TEMPLATE;
33     }
34
35     protected String JavaDoc getDefaultTemplate() {
36         return TEMPLATE;
37     }
38
39     protected void evaluateExtraParams() {
40         super.evaluateExtraParams();
41
42         //Fix for wwportlet Support -- Added by Henry Hu
43
if (href != null) {
44             String JavaDoc hrefValue = findString(href);
45             String JavaDoc contextPath = request.getContextPath();
46             StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
47             String JavaDoc actionUrl = PortletContext.getContext().getActionURL();
48
49             if (!TextUtils.stringSet(actionUrl)) {
50                 if (hrefValue.startsWith("/") && hrefValue.startsWith(contextPath)) {
51                     contextPath = "";
52                 }
53                 sb.append(contextPath).append(hrefValue);
54             } else {
55                 String JavaDoc actionExtension = (String JavaDoc) Configuration.get("webwork.action.extension");
56
57                 if (actionExtension == null || "".equals(actionExtension)) {
58                     actionExtension = ".action";
59                 } else {
60                     actionExtension = "." + actionExtension;
61                 }
62
63                 boolean isWebWorkAction = hrefValue.indexOf(actionExtension) >= 0;
64
65                 if (isWebWorkAction) {
66                     sb.append(actionUrl).append("?wwXAction=.").append(hrefValue);
67                 } else {
68                     sb.append(actionUrl).append("?wwLink=").append(hrefValue);
69                 }
70             }
71
72             addParameter("href", sb.toString());
73         }
74
75         if (showErrorTransportText != null) {
76             addParameter("showErrorTransportText", findValue(showErrorTransportText, Boolean JavaDoc.class));
77         }
78
79         if (errorText != null) {
80             addParameter("errorText", findString(errorText));
81         }
82
83         if (notifyTopics != null) {
84             addParameter("notifyTopics", findString(notifyTopics));
85         }
86
87         if (afterLoading != null) {
88             addParameter("afterLoading", findString(afterLoading));
89         }
90     }
91
92     public void setHref(String JavaDoc href) {
93         this.href = href;
94     }
95
96     public void setErrorText(String JavaDoc errorText) {
97         this.errorText = errorText;
98     }
99
100     public void setShowErrorTransportText(String JavaDoc showErrorTransportText) {
101         this.showErrorTransportText = showErrorTransportText;
102     }
103
104     public void setNotifyTopics(String JavaDoc notifyTopics) {
105         this.notifyTopics = notifyTopics;
106     }
107
108     public void setAfterLoading(String JavaDoc afterLoading) {
109         this.afterLoading = afterLoading;
110     }
111 }
112
Popular Tags