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: BaseTag.java,v $
31 * Revision 1.2 2005/04/28 18:23:36 colinmacleod
32 * Added server/contextPath rewriting.
33 *
34 * Revision 1.1 2005/04/11 14:56:35 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 javax.servlet.http.HttpServletRequest;
46
47 import org.apache.log4j.Logger;
48 import org.apache.struts.util.RequestUtils;
49
50 import com.ivata.mask.web.RewriteHandling;
51
52 /***
53 * <p>
54 * Overridden from <strong>Struts</strong> to let you specify a server and
55 * context as environment entries.
56 * </p>
57 *
58 * @since ivata masks 0.6 (2005-04-09)
59 * @author Colin MacLeod <colin.macleod@ivata.com>
60 * @version $Revision: 1.2 $
61 */
62
63 public class BaseTag extends org.apache.struts.taglib.html.BaseTag {
64 /***
65 * Logger for this class.
66 */
67 private static final Logger logger = Logger.getLogger(BaseTag.class);
68
69 /***
70 * This does all the hard work!
71 * Refer to {@link BaseTag#renderBaseElement}.
72 * @param scheme
73 * Refer to {@link BaseTag#renderBaseElement}.
74 * @param serverName
75 * Refer to {@link BaseTag#renderBaseElement}.
76 * @param port
77 * Refer to {@link BaseTag#renderBaseElement}.
78 * @param uri
79 * Refer to {@link BaseTag#renderBaseElement}.
80 * @return new URL rendered from the values in the environment entries
81 * <code>
82 */
83 protected String renderBaseElement(String scheme,
84 String serverName,
85 int port,
86 String uri) {
87 HttpServletRequest request = (HttpServletRequest)
88 pageContext.getRequest();
89 return "<base href=\""
90 + RewriteHandling.rewriteURL(
91 RequestUtils.createServerUriStringBuffer(scheme,
92 serverName,port,uri).toString(),
93 request.getContextPath())
94 + "\"/>";
95 }
96
97 }