Source code: com/newsfighter/layout/jsptags/ManagerTag.java
1 /*
2 * ManagerTag.java
3 *
4 * Created on February 16, 2003, 1:30 PM
5 * Written by N. Alex Rupp, Minneapolis
6 */
7
8 package com.newsfighter.layout.jsptags;
9
10 import javax.servlet.*;
11 import javax.servlet.jsp.*;
12 import javax.servlet.jsp.tagext.*;
13
14 /** <!-- =============================================================== -->
15 * ManagerTag creates an environment for the panels to reside in. It
16 * has several important functions.<br/>
17 * <br/>
18 * First, it creates the
19 * <code><html></code>,
20 * <code><head></code>,
21 * <code><link></code>,
22 * <code><title></code> and
23 * <code><body></code> elements--essentially the entire first part
24 * of an html document. This is restrictive because it prevents the
25 * user from specifying <code><meta></code> content and special
26 * <code><head></code> content (such as local style information or
27 * scripting code. Because of this we're going to reimplement the class
28 * to allow the "autohead" feature to be disabled.<br/>
29 * <br/>
30 * Second, it takes a <code>skin</code> attribute and uses it to create
31 * an instance of the (@link SkinFactory) object. All of the layout
32 * components which reside within the <code>ManagerTag</code> will be
33 * able to access this object, or create their own if they must.<br/>
34 * @author <a href="mailto:n_alex_rupp@users.sourceforge.net">N. Alex Rupp</a>
35 */
36 public class ManagerTag extends TagSupport {
37
38 /** <!-- =============================================================== -->
39 * records the name of the skin the page author wishes to use. defaults
40 * to the "default" skin.
41 */
42 private String skin = "default";
43
44 /** <!-- =============================================================== -->
45 * stores the contents of the <title> tag for this page. defaults to "".
46 */
47 private String title = "";
48
49 /** <!-- =============================================================== -->
50 * reference to the {@link SkinFactory} object.
51 */
52 private SkinFactory factory;
53
54 // ============================================================
55 // skin support fuctions, required for all skinnable tags.
56
57 /** <!-- =============================================================== -->
58 * Sets the value of the <code>skin</code> attribute.
59 *
60 * @param skinName the name of the skin. Later passed to the
61 * (@link SkinFactory) object.
62 */
63 public void setSkin(String skinName){
64 this.setSkinFactory(skinName);
65 this.skin = skinName;
66 }
67
68 /** <!-- =============================================================== -->
69 * Returns the value of the local <code>skin</code> variable.
70 * @return <code>this.skin</code>
71 */
72 public String getSkin() {
73 if(this.factory == null) {
74 this.setSkinFactory(this.skin);
75 }
76 return this.skin;
77 }
78
79 /** <!-- =============================================================== -->
80 * Creates a new (@link SkinFactory) object and sets a local reference.
81 *
82 * @param skinName the name of the skin this method should use when
83 * creating a new (@link SkinFactory) object.
84 */
85 private void setSkinFactory(String skinName) {
86 String path = "/layout/skins/" + skinName + "/skin.xml";
87 this.factory = new SkinFactory(pageContext.getServletContext().getRealPath(path));
88 }
89
90 /** <!-- =============================================================== -->
91 * Returns a reference to the local SkinFactory object.
92 * @return <code>this.factory</code>
93 */
94 public SkinFactory getSkinFactory() {
95 return this.factory;
96 }
97
98 /** <!-- =============================================================== -->
99 * Sets the value of the <code>title</code> variable.
100 *
101 * @param value the contents of the <code><title></code> element
102 * in html
103 */
104 public void setTitle(String value){
105 title = value;
106 }
107
108 /** <!-- =============================================================== -->
109 * Returns the value of the local <code>title</code> variable.
110 *
111 * @return <code>this.title</code>
112 */
113 public String getTitle(){
114 return(title);
115 }
116
117 /**
118 * doStartTag is called by the JSP container when the tag is encountered
119 * @return <code>EVAL_BODY_INCLUDE</code>
120 */
121 public int doStartTag() {
122 try {
123 JspWriter out = pageContext.getOut();
124 out.println("<html>");
125 out.println("<head>");
126 out.println("\t<title> " + this.getTitle() + " </title>");
127 out.println("\t<link rel=\"stylesheet\" href=\"/layout/skins/" + this.getSkin() + "/style.css\" type=\"text/css\"/>");
128 out.println("</head>");
129 out.println("<body>");
130 // out.println("" + pageContext.getServletContext().getRealPath("/skins/default/skin.xml") ); <-- Debugging code
131 // out.println("" + factory.getBgColor() ); <-- Debugging code
132
133
134 } catch (Exception ex) {
135 throw new Error("========== Error in ManagerTag.doStartTag()");
136 }
137
138 return EVAL_BODY_INCLUDE;
139 }
140
141 // ===================================================================
142 /**
143 * doEndTag is called by the JSP container when the tag is closed
144 * @return <code>EVAL_PAGE</code>
145 */
146 public int doEndTag(){
147 try {
148 JspWriter out = pageContext.getOut();
149 out.println("");
150 out.println("</body>");
151 out.println("</html>");
152
153 } catch (Exception ex){
154 throw new Error("========== Error in net.glaive.taglibs.layout.ManagerTag");
155 }
156 return EVAL_PAGE;
157 }
158 }
159