KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > ivata > groupware > web > tag > CheckSiteTag


1 /*
2  * Copyright (c) 2001 - 2005 ivata limited.
3  * All rights reserved.
4  * -----------------------------------------------------------------------------
5  * ivata groupware may be redistributed under the GNU General Public
6  * License as published by the Free Software Foundation;
7  * version 2 of the License.
8  *
9  * These programs are free software; you can redistribute them and/or
10  * modify them under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; version 2 of the License.
12  *
13  * These programs are distributed in the hope that they will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  *
17  * See the GNU General Public License in the file LICENSE.txt for more
18  * details.
19  *
20  * If you would like a copy of the GNU General Public License write to
21  *
22  * Free Software Foundation, Inc.
23  * 59 Temple Place - Suite 330
24  * Boston, MA 02111-1307, USA.
25  *
26  *
27  * To arrange commercial support and licensing, contact ivata at
28  * http://www.ivata.com/contact.jsp
29  * -----------------------------------------------------------------------------
30  * $Log: CheckSiteTag.java,v $
31  * Revision 1.2 2005/04/09 17:19:59 colinmacleod
32  * Changed copyright text to GPL v2 explicitly.
33  *
34  * Revision 1.1.1.1 2005/03/10 17:51:32 colinmacleod
35  * Restructured ivata op around Hibernate/PicoContainer.
36  * Renamed ivata groupware.
37  *
38  * Revision 1.2 2004/11/03 16:10:11 colinmacleod
39  * Changed todo comments to TODO: all caps.
40  *
41  * Revision 1.1 2004/09/30 15:16:02 colinmacleod
42  * Split off addressbook elements into security subproject.
43  *
44  * Revision 1.4 2004/07/13 19:41:15 colinmacleod
45  * Moved project to POJOs from EJBs.
46  * Applied PicoContainer to services layer (replacing session EJBs).
47  * Applied Hibernate to persistence layer (replacing entity EJBs).
48  *
49  * Revision 1.3 2004/03/21 21:16:08 colinmacleod
50  * Shortened name to ivata op.
51  *
52  * Revision 1.2 2004/02/01 22:00:34 colinmacleod
53  * Added full names to author tags
54  *
55  * Revision 1.1.1.1 2004/01/27 20:57:56 colinmacleod
56  * Moved ivata openportal to SourceForge..
57  *
58  * Revision 1.1.1.1 2003/10/13 20:50:09 colin
59  * Restructured portal into subprojects
60  *
61  * Revision 1.3 2003/06/04 12:24:45 peter
62  * fixed maintenance redirect
63  *
64  * Revision 1.2 2003/03/11 18:25:45 colin
65  * changes to allow just one webapp
66  *
67  * Revision 1.1 2003/02/24 19:33:33 colin
68  * moved to jsp
69  *
70  * Revision 1.10 2003/02/20 14:18:01 colin
71  * removed s if https
72  *
73  * Revision 1.9 2003/02/20 13:19:47 colin
74  * fixed bug in lastURL
75  *
76  * Revision 1.8 2003/02/20 12:34:47 colin
77  * finally got maintenance page working again
78  *
79  * Revision 1.7 2003/02/20 10:46:07 colin
80  * more bugfixes in URL code
81  *
82  * Revision 1.6 2003/02/20 10:36:03 colin
83  * bugfixes in URL code
84  *
85  * Revision 1.5 2003/02/20 10:33:28 colin
86  * prepended protocol
87  *
88  * Revision 1.4 2003/02/20 10:20:13 colin
89  * added lastURL to session
90  *
91  * Revision 1.3 2003/02/20 10:04:25 colin
92  * removed secure protocol and made it a comment
93  *
94  * Revision 1.2 2003/02/20 09:56:15 colin
95  * bugfix in URL
96  *
97  * Revision 1.1 2003/02/20 09:44:12 colin
98  * split off from checkLogin
99  * -----------------------------------------------------------------------------
100  */

101 package com.ivata.groupware.web.tag;
102
103 import java.io.File JavaDoc;
104 import java.io.IOException JavaDoc;
105
106 import javax.servlet.RequestDispatcher JavaDoc;
107 import javax.servlet.ServletException JavaDoc;
108 import javax.servlet.http.HttpServletRequest JavaDoc;
109 import javax.servlet.jsp.JspException JavaDoc;
110 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
111
112 /**
113  * <p>Check that the site is okay and is not being worked on.
114  * The presence of a file in the location
115  * <code>/var/lock/ivata groupware/site_down{prefix}_down
116  * indicates the site should not be displayed.<p>
117  *
118  * <p>{prefix} = context path of the site</p>
119  *
120  * <p>If the site should not be displayed, the contents of
121  * <code>/maintenance.jsp</code> are shown.</p>
122  *
123  * @since 2003-02-20
124  * @author Colin MacLeod
125  * <a HREF='mailto:colin.macleod@ivata.com'>colin.macleod@ivata.com</a>
126  * @version $Revision: 1.2 $
127  */

128 public class CheckSiteTag extends TagSupport JavaDoc {
129
130     /**
131      * <p>This method is called after the JSP engine finished processing
132      * the tag.</p>
133      *
134      * @return <code>SKIP_PAGE</code> if the site is being
135      * worked on, otherwise <code>EVAL_PAGE</code>.
136      * @throws JspException if there is an error accessing the
137      * maintenance page for sites which are not active.
138      */

139     public int doEndTag() throws JspException JavaDoc {
140         HttpServletRequest JavaDoc request = (HttpServletRequest JavaDoc) pageContext.getRequest();
141         String JavaDoc jndiPrefix = "";
142         // TODO:
143
//jndiPrefix = applicationServer.getJndiPrefix();
144
File JavaDoc siteDownFile = new File JavaDoc("/var/lock/ivata groupware/site_down/" +
145             jndiPrefix + "_down");
146
147         // store the last visited URL in the session - good for the error page
148
String JavaDoc requestURL = request.getRequestURL().toString();
149         if (requestURL.indexOf("error.jsp") == -1) {
150             request.getSession().setAttribute("lastURL", requestURL);
151         }
152
153         // if there is no file, evaluate the rest of the page as normal
154
if (!siteDownFile.exists()) {
155             return EVAL_PAGE;
156         }
157
158         try {
159             // if it gets here, just show the contents of the maintenance page
160
// and get out
161
RequestDispatcher JavaDoc dispatcher = pageContext.getServletContext().getRequestDispatcher("/maintenance.jsp?jndiPrefix=" + jndiPrefix);
162                 dispatcher.forward(request, pageContext.getResponse());
163         } catch (IOException JavaDoc e) {
164             throw new JspException JavaDoc(e);
165         } catch (ServletException JavaDoc e) {
166             throw new JspException JavaDoc(e);
167         }
168         return SKIP_PAGE;
169     }
170 }
171
Popular Tags