KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > web > ui > repo > tag > PageTag


1 /*
2  * Copyright (C) 2005-2006 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.web.ui.repo.tag;
18
19 import java.io.IOException JavaDoc;
20 import java.io.Writer JavaDoc;
21
22 import javax.servlet.http.HttpServletRequest JavaDoc;
23 import javax.servlet.jsp.JspException JavaDoc;
24 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
25
26 import org.alfresco.web.app.Application;
27 import org.apache.commons.logging.Log;
28 import org.apache.commons.logging.LogFactory;
29
30 /**
31  * A non-JSF tag library that adds the HTML begin and end tags if running in servlet mode
32  *
33  * @author gavinc
34  */

35 public class PageTag extends TagSupport JavaDoc
36 {
37    private static final long serialVersionUID = 8142765393181557228L;
38    
39    private final static String JavaDoc SCRIPTS_START = "<script language=\"JavaScript1.2\" SRC=\"";
40    private final static String JavaDoc SCRIPTS_MENU = "/scripts/menu.js\"></script>\n";
41    private final static String JavaDoc SCRIPTS_WEBDAV = "/scripts/webdav.js\"></script>\n";
42    private final static String JavaDoc STYLES_START = "<link rel=\"stylesheet\" HREF=\"";
43    private final static String JavaDoc STYLES_MAIN = "/css/main.css\" TYPE=\"text/css\">\n";
44
45 /**
46  * Please ensure you understand the terms of the license before changing the contents of this file.
47  */

48
49    private final static String JavaDoc ALF_URL = "http://www.alfresco.com";
50    private final static String JavaDoc ALF_LOGO = "http://www.alfresco.com/images/alfresco_community_horizont.gif";
51    private final static String JavaDoc ALF_TEXT = "Alfresco Community";
52    private final static String JavaDoc ALF_COPY = "Supplied free of charge with " +
53         "<a class=footer HREF='http://www.alfresco.com/services/support/communityterms/#support'>no support</a>, " +
54         "<a class=footer HREF='http://www.alfresco.com/unsupported.html#certification'>no certification</a>, " +
55         "<a class=footer HREF='http://www.alfresco.com/services/support/communityterms/#maintenance'>no maintenance</a>, " +
56         "<a class=footer HREF='http://www.alfresco.com/services/support/communityterms/#warranty'>no warranty</a> and " +
57         "<a class=footer HREF='http://www.alfresco.com/services/support/communityterms/#indemnity'>no indemnity</a> by " +
58         "<a class=footer HREF='http://www.alfresco.com'>Alfresco</a> or its " +
59         "<a class=footer HREF='http://www.alfresco.com/partners/'>Certified Partners</a>. " +
60         "<a class=footer HREF='http://www.alfresco.com/services/support/'>Click here for support</a>. " +
61         "Alfresco Software Inc. 2005-2006 All rights reserved.";
62    
63    private static Log logger = LogFactory.getLog(PageTag.class);
64    private static String JavaDoc alfresco = null;
65    private static String JavaDoc loginPage = null;
66    
67    private long startTime = 0;
68    private String JavaDoc title;
69    private String JavaDoc titleId;
70    
71    /**
72     * @return The title for the page
73     */

74    public String JavaDoc getTitle()
75    {
76       return title;
77    }
78
79    /**
80     * @param title Sets the page title
81     */

82    public void setTitle(String JavaDoc title)
83    {
84       this.title = title;
85    }
86    
87    /**
88     * @return The title message Id for the page
89     */

90    public String JavaDoc getTitleId()
91    {
92       return titleId;
93    }
94
95    /**
96     * @param titleId Sets the page title message Id
97     */

98    public void setTitleId(String JavaDoc titleId)
99    {
100       this.titleId = titleId;
101    }
102    
103    public void release()
104    {
105       super.release();
106       title = null;
107       titleId = null;
108    }
109
110    /**
111     * @see javax.servlet.jsp.tagext.TagSupport#doStartTag()
112     */

113    public int doStartTag() throws JspException JavaDoc
114    {
115       if (logger.isDebugEnabled())
116          startTime = System.currentTimeMillis();
117       
118       try
119       {
120          Writer JavaDoc out = pageContext.getOut();
121          
122          if (Application.inPortalServer() == false)
123          {
124             out.write("<html><head><title>");
125             if (this.titleId != null && this.titleId.length() != 0)
126             {
127                out.write(Application.getMessage(pageContext.getSession(), this.titleId));
128             }
129             else if (this.title != null && this.title.length() != 0)
130             {
131                out.write(this.title);
132             }
133             else
134             {
135                out.write("Alfresco Web Client");
136             }
137             out.write("</title></head>");
138             out.write("<body>\n");
139          }
140          
141          String JavaDoc reqPath = ((HttpServletRequest JavaDoc)pageContext.getRequest()).getContextPath();
142          out.write(SCRIPTS_START);
143          out.write(reqPath);
144          out.write(SCRIPTS_MENU);
145          out.write(SCRIPTS_START);
146          out.write(reqPath);
147          out.write(SCRIPTS_WEBDAV);
148          out.write(STYLES_START);
149          out.write(reqPath);
150          out.write(STYLES_MAIN);
151       }
152       catch (IOException JavaDoc ioe)
153       {
154          throw new JspException JavaDoc(ioe.toString());
155       }
156       
157       return EVAL_BODY_INCLUDE;
158    }
159
160    /**
161     * @see javax.servlet.jsp.tagext.TagSupport#doEndTag()
162     */

163    public int doEndTag() throws JspException JavaDoc
164    {
165       try
166       {
167          HttpServletRequest JavaDoc req = (HttpServletRequest JavaDoc)pageContext.getRequest();
168          if (req.getRequestURI().endsWith(getLoginPage()) == false)
169          {
170             pageContext.getOut().write(getAlfrescoButton());
171          }
172          
173          if (Application.inPortalServer() == false)
174          {
175             pageContext.getOut().write("\n</body></html>");
176          }
177       }
178       catch (IOException JavaDoc ioe)
179       {
180          throw new JspException JavaDoc(ioe.toString());
181       }
182       
183       if (logger.isDebugEnabled())
184       {
185          long endTime = System.currentTimeMillis();
186          logger.debug("Time to generate page: " + (endTime - startTime) + "ms");
187       }
188       
189       return super.doEndTag();
190    }
191    
192    private String JavaDoc getLoginPage()
193    {
194       if (loginPage == null)
195       {
196          loginPage = Application.getLoginPage(pageContext.getServletContext());
197       }
198       
199       return loginPage;
200    }
201
202 /**
203  * Please ensure you understand the terms of the license before changing the contents of this file.
204  */

205
206    private String JavaDoc getAlfrescoButton()
207    {
208       if (alfresco == null)
209       {
210          String JavaDoc reqPath = ((HttpServletRequest JavaDoc)pageContext.getRequest()).getContextPath();
211          alfresco = "<center><table><tr><td>" +
212                     "<a HREF='" + ALF_URL + "'>" +
213                     "<img border=0 alt='' title='" + ALF_TEXT + "' align=absmiddle SRC='" + ALF_LOGO + "'>" +
214                     "</a></td><td align=center>" +
215                     "<span class=footer>" + ALF_COPY +
216                     "</span></td><td><a HREF='http://sourceforge.net/projects/alfresco'><img border=0 alt='' title='SourceForge' align=absmiddle SRC='http://sflogo.sourceforge.net/sflogo.php?group_id=143373&type=1'></a>" +
217                     "</td></tr></table></center>";
218       }
219       
220       return alfresco;
221    }
222 }
223
Popular Tags