1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package org.dbforms.taglib;
25
26 import java.io.IOException;
27
28 import javax.servlet.http.HttpServletRequest;
29 import javax.servlet.jsp.JspException;
30 import javax.servlet.jsp.JspWriter;
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 AbstractScriptHandlerTag {
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 {
53 HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
54 StringBuffer buf = new StringBuffer("<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 out = pageContext.getOut();
70
71 try {
72 out.write(buf.toString());
73 } catch (IOException e) {
74 throw new JspException(e.toString());
75 }
76
77 return EVAL_BODY_INCLUDE;
78 }
79 }