KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/setup/comptest/CmsSetupTestXercesVersion.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.i18n.CmsEncoder;
35 import org.opencms.setup.CmsSetupBean;
36
37 import java.io.ByteArrayInputStream JavaDoc;
38
39 import org.apache.xerces.impl.Version;
40 import org.apache.xerces.parsers.DOMParser;
41
42 import org.w3c.dom.Document JavaDoc;
43 import org.xml.sax.InputSource JavaDoc;
44
45 /**
46  * Test for the Xerces version.<p>
47  *
48  * @author Michael Moossen
49  *
50  * @version $Revision: 1.2 $
51  *
52  * @since 6.1.8
53  */

54 public class CmsSetupTestXercesVersion implements I_CmsSetupTest {
55
56     /** The test name. */
57     public static final String JavaDoc TEST_NAME = "XML Parser";
58
59     /**
60      * @see org.opencms.setup.comptest.I_CmsSetupTest#getName()
61      */

62     public String JavaDoc getName() {
63
64         return TEST_NAME;
65     }
66
67     /**
68      * @see org.opencms.setup.comptest.I_CmsSetupTest#execute(org.opencms.setup.CmsSetupBean)
69      */

70     public CmsSetupTestResult execute(CmsSetupBean setupBean) throws Exception JavaDoc {
71
72         CmsSetupTestResult testResult = new CmsSetupTestResult(this);
73
74         DOMParser parser = new DOMParser();
75         String JavaDoc document = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<test>test</test>\n";
76         parser.parse(new InputSource JavaDoc(new ByteArrayInputStream JavaDoc(document.getBytes(CmsEncoder.ENCODING_UTF_8))));
77         Document JavaDoc doc = parser.getDocument();
78
79         // Xerces 1 and 2 APIs are different, let's see what we have...
80
String JavaDoc versionStr = null;
81         int xercesVersion = 0;
82
83         try {
84             doc.getClass().getMethod("getXmlEncoding", new Class JavaDoc[] {}).invoke(doc, new Object JavaDoc[] {});
85             versionStr = Version.getVersion();
86             xercesVersion = 2;
87         } catch (Throwable JavaDoc t) {
88             // noop
89
}
90         if (versionStr == null) {
91             try {
92                 doc.getClass().getMethod("getEncoding", new Class JavaDoc[] {}).invoke(doc, new Object JavaDoc[] {});
93                 versionStr = "Xerces version 1";
94                 xercesVersion = 1;
95             } catch (Throwable JavaDoc t) {
96                 // noop
97
}
98         }
99
100         switch (xercesVersion) {
101             case 2:
102                 testResult.setResult(versionStr);
103                 testResult.setHelp("OpenCms 6.0 requires Xerces version 2 to run. Usually this should be available as part of the servlet environment.");
104                 testResult.setGreen();
105                 break;
106             case 1:
107                 testResult.setResult(versionStr);
108                 testResult.setRed();
109                 testResult.setInfo("OpenCms 6.0 requires Xerces version 2 to run, your Xerces version is 1. "
110                     + "Usually Xerces 2 should be installed by default as part of the servlet environment.");
111                 testResult.setHelp(testResult.getInfo());
112                 break;
113             default:
114                 if (versionStr == null) {
115                     versionStr = "Unknown version";
116                 }
117                 testResult.setResult(versionStr);
118                 testResult.setRed();
119                 testResult.setInfo("OpenCms 6.0 requires Xerces version 2 to run. "
120                     + "Usually Xerces 2 should be installed by default as part of the servlet environment.");
121                 testResult.setHelp(testResult.getInfo());
122         }
123         return testResult;
124     }
125 }
126
Popular Tags