KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > dbforms > taglib > BaseTag


1 /*
2  * $Header: /cvsroot/jdbforms/dbforms/src/org/dbforms/taglib/BaseTag.java,v 1.13 2004/08/18 12:26:05 hkollmann Exp $
3  * $Revision: 1.13 $
4  * $Date: 2004/08/18 12:26:05 $
5  *
6  * DbForms - a Rapid Application Development Framework
7  * Copyright (C) 2001 Joachim Peer <joepeer@excite.com>
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22  */

23
24 package org.dbforms.taglib;
25
26 import java.io.IOException JavaDoc;
27
28 import javax.servlet.http.HttpServletRequest JavaDoc;
29 import javax.servlet.jsp.JspException JavaDoc;
30 import javax.servlet.jsp.JspWriter JavaDoc;
31
32
33
34 /**
35  * Renders an HTML base element with an href attribute pointing to the absolute
36  * location of the enclosing JSP page. The presence of this tag allows the
37  * browser to resolve relative URL's to images, CSS stylesheets and other
38  * resources in a manner independent of the URL used to call the
39  * ControllerServlet. There are no attributes associated with this tag.
40  *
41  * @author Luis Arias
42  * @author Joe Peer (changed class for use in DbForms-Framework)
43  */

44 public class BaseTag extends TagSupportWithScriptHandler {
45    /**
46     * Process the start of this tag.
47     *
48     * @return DOCUMENT ME!
49     *
50     * @exception JspException if a JSP exception has occurred
51     */

52    public int doStartTag() throws JspException JavaDoc {
53       HttpServletRequest JavaDoc request = (HttpServletRequest JavaDoc) pageContext.getRequest();
54       StringBuffer JavaDoc buf = new StringBuffer JavaDoc("<base HREF=\"");
55       buf.append(request.getScheme());
56       buf.append("://");
57       buf.append(request.getServerName());
58
59       int port = request.getServerPort();
60
61       if ((port != 80) && (port != 443)) {
62          buf.append(":");
63          buf.append(String.valueOf(port));
64       }
65
66       buf.append(request.getRequestURI());
67       buf.append("\"/>");
68
69       JspWriter JavaDoc out = pageContext.getOut();
70
71       try {
72          out.write(buf.toString());
73       } catch (IOException JavaDoc e) {
74          throw new JspException JavaDoc(e.toString());
75       }
76
77       return EVAL_BODY_INCLUDE;
78    }
79 }
80
Popular Tags