1 /*
2 * $Id: RewriteTag.java 471754 2006-11-06 14:55:09Z husted $
3 *
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "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 =
49 TagUtils.getInstance().computeParameters(pageContext, paramId,
50 paramName, paramProperty, paramScope, name, property, scope,
51 transaction);
52
53 // Add parameters collected from the tag's inner body
54 if (!this.parameters.isEmpty()) {
55 if (params == null) {
56 params = new HashMap();
57 }
58 params.putAll(this.parameters);
59 }
60
61 String url = null;
62
63 try {
64 // Note that we're encoding the & character to & in XHTML mode only,
65 // otherwise the & is written as is to work in javascripts.
66 url = TagUtils.getInstance().computeURLWithCharEncoding(pageContext,
67 forward, href, page, action, module, params, anchor, false,
68 this.isXhtml(), useLocalEncoding);
69 } catch (MalformedURLException e) {
70 TagUtils.getInstance().saveException(pageContext, e);
71 throw new JspException(messages.getMessage("rewrite.url",
72 e.toString()));
73 }
74
75 TagUtils.getInstance().write(pageContext, url);
76 return (EVAL_PAGE);
77 }
78 }