View Javadoc

1   /*
2    * Copyright (c) 2001 - 2005 ivata limited.
3    * All rights reserved.
4    * ---------------------------------------------------------
5    * ivata masks may be redistributed under the GNU General Public
6    * License as published by the Free Software Foundation;
7    * version 2 of the License.
8    *
9    * These programs are free software; you can redistribute them and/or
10   * modify them under the terms of the GNU General Public License
11   * as published by the Free Software Foundation; version 2 of the License.
12   *
13   * These programs are distributed in the hope that they will be useful,
14   * but WITHOUT ANY WARRANTY; without even the implied warranty of
15   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16   *
17   * See the GNU General Public License in the file LICENSE.txt for more
18   * details.
19   *
20   * If you would like a copy of the GNU General Public License write to
21   *
22   * Free Software Foundation, Inc.
23   * 59 Temple Place - Suite 330
24   * Boston, MA 02111-1307, USA.
25   *
26   *
27   * To arrange commercial support and licensing, contact ivata at
28   *                  http://www.ivata.com/contact.jsp
29   * ---------------------------------------------------------
30   * $Log: RewriteTag.java,v $
31   * Revision 1.2  2005/04/28 18:23:35  colinmacleod
32   * Added server/contextPath rewriting.
33   *
34   * Revision 1.1  2005/04/11 14:56:37  colinmacleod
35   * Added base tag, link tag and rewrite tag to
36   * change the host name via environment entries.
37   * Added errors tag to handle errors even when
38   * the message is not found in the application
39   * resources.
40   *
41   * ---------------------------------------------------------
42   */
43  package com.ivata.mask.web.tag.html;
44  
45  import org.apache.log4j.Logger;
46  
47  import java.net.MalformedURLException;
48  import java.util.Map;
49  
50  import javax.servlet.http.HttpServletRequest;
51  import javax.servlet.jsp.JspException;
52  
53  import org.apache.struts.taglib.TagUtils;
54  
55  import com.ivata.mask.web.RewriteHandling;
56  
57  /***
58   * <p>
59   * Overridden from <strong>Struts</strong> to let you specify a server and
60   * context as environment entries.
61   * </p>
62   *
63   * @since ivata masks 0.6 (2005-04-09)
64   * @author Colin MacLeod <colin.macleod@ivata.com>
65   * @version $Revision: 1.2 $
66   */
67  
68  public class RewriteTag extends org.apache.struts.taglib.html.RewriteTag {
69      /***
70       * Logger for this class.
71       */
72      private static final Logger logger = Logger.getLogger(RewriteTag.class);
73  
74      /***
75       * Refer to {@link org.apache.struts.taglib.html.RewriteTag#doStartTag}.
76       * @return
77       * Refer to {@link org.apache.struts.taglib.html.RewriteTag#doStartTag}.
78       * @throws JspException
79       * Refer to {@link org.apache.struts.taglib.html.RewriteTag#doStartTag}.
80       */
81      public int doStartTag() throws JspException {
82          TagUtils tagUtils = TagUtils.getInstance();
83           Map params = tagUtils.computeParameters
84                   (pageContext, paramId, paramName, paramProperty, paramScope,
85                    name, property, scope, transaction);
86           String url = null;
87           try {
88             url = tagUtils.computeURL(pageContext, forward, href,
89                                                 page, action, module, params,
90                                                 anchor, false, false);
91           } catch (MalformedURLException e) {
92             throw new JspException
93                     (messages.getMessage("rewrite.url", e.toString()));
94           }
95           HttpServletRequest request = (HttpServletRequest)
96               pageContext.getRequest();
97           url = RewriteHandling.rewriteURL(url, request.getContextPath());
98           tagUtils.write(pageContext, url);
99  
100 //      Skip the body of this tag
101          return (SKIP_BODY);
102     }
103 }