01: /*
02: * $Id: RewriteTag.java 471754 2006-11-06 14:55:09Z husted $
03: *
04: * Licensed to the Apache Software Foundation (ASF) under one
05: * or more contributor license agreements. See the NOTICE file
06: * distributed with this work for additional information
07: * regarding copyright ownership. The ASF licenses this file
08: * to you under the Apache License, Version 2.0 (the
09: * "License"); you may not use this file except in compliance
10: * with the License. You may obtain a copy of the License at
11: *
12: * http://www.apache.org/licenses/LICENSE-2.0
13: *
14: * Unless required by applicable law or agreed to in writing,
15: * software distributed under the License is distributed on an
16: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17: * KIND, either express or implied. See the License for the
18: * specific language governing permissions and limitations
19: * under the License.
20: */
21: package org.apache.struts.taglib.html;
22:
23: import org.apache.struts.taglib.TagUtils;
24:
25: import javax.servlet.jsp.JspException;
26:
27: import java.net.MalformedURLException;
28:
29: import java.util.HashMap;
30: import java.util.Map;
31:
32: /**
33: * Generate a URL-encoded URI as a string.
34: *
35: * @version $Rev: 471754 $ $Date: 2004-10-16 12:38:42 -0400 (Sat, 16 Oct 2004)
36: * $
37: */
38: public class RewriteTag extends LinkTag {
39: // --------------------------------------------------------- Public Methods
40:
41: /**
42: * Render the URI.
43: *
44: * @throws JspException if a JSP exception has occurred
45: */
46: public int doEndTag() throws JspException {
47: // Generate the hyperlink URL
48: Map params = TagUtils.getInstance().computeParameters(
49: pageContext, paramId, paramName, paramProperty,
50: paramScope, name, property, scope, transaction);
51:
52: // Add parameters collected from the tag's inner body
53: if (!this .parameters.isEmpty()) {
54: if (params == null) {
55: params = new HashMap();
56: }
57: params.putAll(this .parameters);
58: }
59:
60: String url = null;
61:
62: try {
63: // Note that we're encoding the & character to & in XHTML mode only,
64: // otherwise the & is written as is to work in javascripts.
65: url = TagUtils.getInstance().computeURLWithCharEncoding(
66: pageContext, forward, href, page, action, module,
67: params, anchor, false, this .isXhtml(),
68: useLocalEncoding);
69: } catch (MalformedURLException e) {
70: TagUtils.getInstance().saveException(pageContext, e);
71: throw new JspException(messages.getMessage("rewrite.url", e
72: .toString()));
73: }
74:
75: TagUtils.getInstance().write(pageContext, url);
76: return (EVAL_PAGE);
77: }
78: }
|