View Javadoc

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