01: /*******************************************************************************
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: *******************************************************************************/package org.ofbiz.webapp.taglib;
19:
20: import java.io.IOException;
21: import javax.servlet.ServletContext;
22: import javax.servlet.http.HttpServletRequest;
23: import javax.servlet.http.HttpServletResponse;
24: import javax.servlet.jsp.JspException;
25: import javax.servlet.jsp.tagext.BodyContent;
26: import javax.servlet.jsp.tagext.BodyTagSupport;
27:
28: import org.ofbiz.base.util.Debug;
29: import org.ofbiz.base.util.UtilJ2eeCompat;
30: import org.ofbiz.webapp.control.RequestHandler;
31:
32: /**
33: * UrlTag - Creates a URL string prepending the current control path.
34: */
35: public class UrlTag extends BodyTagSupport {
36:
37: public static final String module = UrlTag.class.getName();
38:
39: public int doEndTag() throws JspException {
40: HttpServletRequest request = (HttpServletRequest) pageContext
41: .getRequest();
42: HttpServletResponse response = (HttpServletResponse) pageContext
43: .getResponse();
44:
45: ServletContext context = (ServletContext) request
46: .getAttribute("servletContext");
47: RequestHandler rh = (RequestHandler) context
48: .getAttribute("_REQUEST_HANDLER_");
49:
50: BodyContent body = getBodyContent();
51:
52: String baseURL = body.getString();
53: String newURL = rh.makeLink(request, response, baseURL);
54:
55: body.clearBody();
56:
57: try {
58: getPreviousOut().print(newURL);
59: } catch (IOException e) {
60: if (UtilJ2eeCompat.useNestedJspException(pageContext
61: .getServletContext())) {
62: throw new JspException(e.getMessage(), e);
63: } else {
64: Debug
65: .logError(
66: e,
67: "Server does not support nested exceptions, here is the exception",
68: module);
69: throw new JspException(e.toString());
70: }
71: }
72: return SKIP_BODY;
73: }
74: }
|