01: /*
02: * $Id: UrlTag.java,v 1.2 2003/09/14 05:36:48 jonesde Exp $
03: *
04: * Copyright (c) 2001-2003 The Open For Business Project - www.ofbiz.org
05: *
06: * Permission is hereby granted, free of charge, to any person obtaining a
07: * copy of this software and associated documentation files (the "Software"),
08: * to deal in the Software without restriction, including without limitation
09: * 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: */
25: package org.ofbiz.content.webapp.taglib;
26:
27: import java.io.IOException;
28:
29: import javax.servlet.ServletContext;
30: import javax.servlet.http.HttpServletRequest;
31: import javax.servlet.http.HttpServletResponse;
32: import javax.servlet.jsp.JspException;
33: import javax.servlet.jsp.tagext.BodyContent;
34: import javax.servlet.jsp.tagext.BodyTagSupport;
35:
36: import org.ofbiz.base.util.Debug;
37: import org.ofbiz.base.util.UtilJ2eeCompat;
38: import org.ofbiz.content.webapp.control.RequestHandler;
39:
40: /**
41: * UrlTag - Creates a URL string prepending the current control path.
42: *
43: * @author <a href="mailto:jaz@ofbiz.org">Andy Zeneski</a>
44: * @version $Revision: 1.2 $
45: * @since 2.0
46: */
47: public class UrlTag extends BodyTagSupport {
48:
49: public static final String module = UrlTag.class.getName();
50:
51: public int doEndTag() throws JspException {
52: HttpServletRequest request = (HttpServletRequest) pageContext
53: .getRequest();
54: HttpServletResponse response = (HttpServletResponse) pageContext
55: .getResponse();
56:
57: ServletContext context = (ServletContext) request
58: .getAttribute("servletContext");
59: RequestHandler rh = (RequestHandler) context
60: .getAttribute("_REQUEST_HANDLER_");
61:
62: BodyContent body = getBodyContent();
63:
64: String baseURL = body.getString();
65: String newURL = rh.makeLink(request, response, baseURL);
66:
67: body.clearBody();
68:
69: try {
70: getPreviousOut().print(newURL);
71: } catch (IOException e) {
72: if (UtilJ2eeCompat.useNestedJspException(pageContext
73: .getServletContext())) {
74: throw new JspException(e.getMessage(), e);
75: } else {
76: Debug
77: .logError(
78: e,
79: "Server does not support nested exceptions, here is the exception",
80: module);
81: throw new JspException(e.toString());
82: }
83: }
84: return SKIP_BODY;
85: }
86: }
|