KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > setup > comptest > CmsSetupTestServletEngine


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/setup/comptest/CmsSetupTestServletEngine.java,v $
3  * Date : $Date: 2006/03/27 14:52:42 $
4  * Version: $Revision: 1.2 $
5  *
6  * This library is part of OpenCms -
7  * the Open Source Content Mananagement System
8  *
9  * Copyright (c) 2005 Alkacon Software GmbH (http://www.alkacon.com)
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation; either
14  * version 2.1 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * Lesser General Public License for more details.
20  *
21  * For further information about Alkacon Software GmbH, please see the
22  * company website: http://www.alkacon.com
23  *
24  * For further information about OpenCms, please see the
25  * project website: http://www.opencms.org
26  *
27  * You should have received a copy of the GNU Lesser General Public
28  * License along with this library; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */

31
32 package org.opencms.setup.comptest;
33
34 import org.opencms.setup.CmsSetupBean;
35
36 import javax.servlet.ServletConfig JavaDoc;
37
38 /**
39  * Tests the servlet engine.<p>
40  *
41  * @author Michael Moossen
42  *
43  * @version $Revision: 1.2 $
44  *
45  * @since 6.1.8
46  */

47 public class CmsSetupTestServletEngine implements I_CmsSetupTest {
48
49     /** The test name. */
50     public static final String JavaDoc TEST_NAME = "Servlet Engine";
51
52     /**
53      * @see org.opencms.setup.comptest.I_CmsSetupTest#getName()
54      */

55     public String JavaDoc getName() {
56
57         return TEST_NAME;
58     }
59
60     /**
61      * @see org.opencms.setup.comptest.I_CmsSetupTest#execute(org.opencms.setup.CmsSetupBean)
62      */

63     public CmsSetupTestResult execute(CmsSetupBean setupBean) {
64
65         CmsSetupTestResult testResult = new CmsSetupTestResult(this);
66
67         String JavaDoc[] supportedEngines = {"Apache Tomcat/4.1", "Apache Tomcat/4.0", "Apache Tomcat/5.0", "Apache Tomcat/5.5"};
68
69         String JavaDoc[] unsupportedEngines = {"Tomcat Web Server/3.2", "Tomcat Web Server/3.3", "Resin/2.0.b2"};
70
71         String JavaDoc[] unsupportedServletEngineInfo = {
72             "Tomcat 3.2 is no longer supported. Please use Tomcat 4.x instead.",
73             "Tomcat 3.3 is no longer supported. Please use Tomcat 4.x instead.",
74             "The OpenCms JSP integration does currently not work with Resin. Please use Tomcat 4.x instead."};
75
76         ServletConfig JavaDoc config = setupBean.getServletConfig();
77         String JavaDoc servletEngine = config.getServletContext().getServerInfo();
78         boolean supportedServletEngine = hasSupportedServletEngine(servletEngine, supportedEngines);
79         int unsupportedServletEngine = unsupportedServletEngine(servletEngine, unsupportedEngines);
80
81         testResult.setResult(servletEngine);
82
83         if (unsupportedServletEngine > -1) {
84             testResult.setRed();
85             testResult.setInfo(unsupportedServletEngineInfo[unsupportedServletEngine]);
86             testResult.setHelp("This servlet engine does not work with OpenCms. Even though OpenCms is fully standards compliant, "
87                 + "the standard leaves some 'grey' (i.e. undefined) areas. "
88                 + "Please consider using another, supported engine.");
89         } else if (!supportedServletEngine) {
90             testResult.setYellow();
91             testResult.setHelp("This servlet engine has not been tested with OpenCms. Please consider using another, supported engine.");
92         } else {
93             testResult.setGreen();
94         }
95         return testResult;
96     }
97
98     /**
99      * Checks if the used servlet engine is part of the servlet engines OpenCms supports.<p>
100      *
101      * @param thisEngine The servlet engine in use
102      * @param supportedEngines All known servlet engines OpenCms supports
103      *
104      * @return true if this engine is supported, false if it was not found in the list
105      */

106     private boolean hasSupportedServletEngine(String JavaDoc thisEngine, String JavaDoc[] supportedEngines) {
107
108         boolean supported = false;
109         engineCheck: for (int i = 0; i < supportedEngines.length; i++) {
110             if (thisEngine.indexOf(supportedEngines[i]) >= 0) {
111                 supported = true;
112                 break engineCheck;
113             }
114         }
115         return supported;
116     }
117
118     /**
119      * Checks if the used servlet engine is part of the servlet engines OpenCms
120      * does NOT support.<p>
121      *
122      * @param thisEngine the servlet engine in use
123      * @param unsupportedEngines all known servlet engines OpenCms does NOT support
124      * @return the engine id or -1 if the engine is not supported
125      */

126     private int unsupportedServletEngine(String JavaDoc thisEngine, String JavaDoc[] unsupportedEngines) {
127
128         for (int i = 0; i < unsupportedEngines.length; i++) {
129             if (thisEngine.indexOf(unsupportedEngines[i]) >= 0) {
130                 return i;
131             }
132         }
133         return -1;
134     }
135 }
136
Popular Tags