Source code: info/crossbar/view/taglib/JavascriptGenerator.java
1 /*
2 * @(#)JavascriptGenerator.java $Revision: 1.3 $ $Date: 2003/06/04 04:55:20 $
3 *
4 * Copyright 2002 by Daniel Kehoe <kehoe@fortuity.com>
5 * All Rights Reserved
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 */
28 package info.crossbar.view.taglib;
29
30 import java.util.logging.Logger;
31
32 import java.util.*;
33
34 import java.io.*;
35
36 import javax.servlet.jsp.*;
37 import javax.servlet.jsp.tagext.*;
38
39 import javax.servlet.http.HttpServletRequest;
40
41 /**
42 * JavascriptGenerator class for use by <a href="http://www.crossbar.info/">Crossbar</a>
43 *
44 * @author Daniel Kehoe, <a href="http://www.fortuity.com/">Fortuity Consulting</a>
45 * @version <a href="http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/crossbar/crossbar-sitemap/src/java/info/crossbar/view/taglib/JavascriptGenerator.java">View source, revision history</a>
46 * $Revision: 1.3 $ $Date: 2003/06/04 04:55:20 $
47 * <p>
48 * DESCRIPTION:
49 * This tag outputs Javascript functions for use by pages in a Crossbar web application.
50 */
51
52 public class JavascriptGenerator extends TagSupport {
53
54 /**
55 * Process the start tag for this instance. See the JSP API specification for details.
56 *
57 * @return int (see the spec)
58 */
59 public int doStartTag() {
60 try {
61 JspWriter out = pageContext.getOut();
62 StringBuffer buffer = new StringBuffer("");
63 buffer.append("<script type=\"text/javascript\" language=\"JavaScript\">\n");
64 buffer.append("\n");
65 buffer.append("///////////////////////////////////////////////////////////////\n");
66 buffer.append("// Set a base URL so all relative links are formed relative to the docroot of the web application:\n");
67 buffer.append("document.write(\"<BASE HREF=\" + " + ((HttpServletRequest)pageContext.getRequest()).getContextPath() + " + \">\");\n");
68 buffer.append("\n");
69 buffer.append("</SCRIPT>\n");
70 out.print(buffer.toString());
71 } catch (IOException ioe) {
72 System.out.println("Error in tag: " + ioe);
73 }
74 return (SKIP_BODY);
75 }
76
77 }
78