KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ofbiz > widget > WidgetWorker


1 /*
2  * $Id: WidgetWorker.java 5764 2005-09-17 08:09:02Z jonesde $
3  *
4  * Copyright (c) 2003-2005 The Open For Business Project - www.ofbiz.org
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included
14  * in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
21  * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
22  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  */

24 package org.ofbiz.widget;
25
26 import java.util.Map JavaDoc;
27 import javax.servlet.ServletContext JavaDoc;
28 import javax.servlet.http.HttpServletRequest JavaDoc;
29 import javax.servlet.http.HttpServletResponse JavaDoc;
30
31 import org.ofbiz.base.util.UtilHttp;
32 import org.ofbiz.base.util.UtilValidate;
33 import org.ofbiz.webapp.control.RequestHandler;
34 import org.ofbiz.webapp.taglib.ContentUrlTag;
35
36 public class WidgetWorker {
37
38     public static final String JavaDoc module = WidgetWorker.class.getName();
39
40     public WidgetWorker () {}
41
42     public static void buildHyperlinkUrl(StringBuffer JavaDoc buffer, String JavaDoc requestName, String JavaDoc targetType, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response, Map JavaDoc context) {
43         String JavaDoc localRequestName = UtilHttp.encodeAmpersands(requestName);
44         
45         if ("intra-app".equals(targetType)) {
46             appendOfbizUrl(buffer, "/" + localRequestName, request, response);
47         } else if ("inter-app".equals(targetType)) {
48             String JavaDoc fullTarget = localRequestName;
49             buffer.append(fullTarget);
50             String JavaDoc externalLoginKey = (String JavaDoc) request.getAttribute("externalLoginKey");
51             if (UtilValidate.isNotEmpty(externalLoginKey)) {
52                 if (fullTarget.indexOf('?') == -1) {
53                     buffer.append('?');
54                 } else {
55                     buffer.append("&");
56                 }
57                 buffer.append("externalLoginKey=");
58                 buffer.append(externalLoginKey);
59             }
60         } else if ("content".equals(targetType)) {
61             appendContentUrl(buffer, localRequestName, request);
62         } else if ("plain".equals(targetType)) {
63             buffer.append(localRequestName);
64         } else {
65             buffer.append(localRequestName);
66         }
67
68     
69         return;
70     }
71
72     public static void appendOfbizUrl(StringBuffer JavaDoc buffer, String JavaDoc location, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) {
73         ServletContext JavaDoc ctx = (ServletContext JavaDoc) request.getAttribute("servletContext");
74         RequestHandler rh = (RequestHandler) ctx.getAttribute("_REQUEST_HANDLER_");
75         // make and append the link
76
buffer.append(rh.makeLink(request, response, location));
77     }
78
79     public static void appendContentUrl(StringBuffer JavaDoc buffer, String JavaDoc location, HttpServletRequest JavaDoc request) {
80         ContentUrlTag.appendContentPrefix(request, buffer);
81         buffer.append(location);
82     }
83
84     public static void makeHyperlinkString(StringBuffer JavaDoc buffer, String JavaDoc linkStyle, String JavaDoc targetType, String JavaDoc target, String JavaDoc description, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response, Map JavaDoc context, String JavaDoc targetWindow) {
85         if (UtilValidate.isNotEmpty(description)) {
86             buffer.append("<a");
87
88             if (UtilValidate.isNotEmpty(linkStyle)) {
89                 buffer.append(" class=\"");
90                 buffer.append(linkStyle);
91                 buffer.append("\"");
92             }
93
94             buffer.append(" HREF=\"");
95
96             WidgetWorker.buildHyperlinkUrl(buffer, target, targetType, request, response, context);
97
98             buffer.append("\"");
99             
100             if (UtilValidate.isNotEmpty(targetWindow)) {
101                 buffer.append(" target=\"");
102                 buffer.append(targetWindow);
103                 buffer.append("\"");
104             }
105
106
107             buffer.append('>');
108
109             buffer.append(description);
110             buffer.append("</a>");
111         }
112     }
113 }
114
Popular Tags