001: /*
002: * File : $Source: /usr/local/cvs/opencms/src-setup/org/opencms/setup/comptest/CmsSetupTestXercesVersion.java,v $
003: * Date : $Date: 2008-02-27 12:05:32 $
004: * Version: $Revision: 1.2 $
005: *
006: * This library is part of OpenCms -
007: * the Open Source Content Management System
008: *
009: * Copyright (c) 2002 - 2008 Alkacon Software GmbH (http://www.alkacon.com)
010: *
011: * This library is free software; you can redistribute it and/or
012: * modify it under the terms of the GNU Lesser General Public
013: * License as published by the Free Software Foundation; either
014: * version 2.1 of the License, or (at your option) any later version.
015: *
016: * This library is distributed in the hope that it will be useful,
017: * but WITHOUT ANY WARRANTY; without even the implied warranty of
018: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
019: * Lesser General Public License for more details.
020: *
021: * For further information about Alkacon Software GmbH, please see the
022: * company website: http://www.alkacon.com
023: *
024: * For further information about OpenCms, please see the
025: * project website: http://www.opencms.org
026: *
027: * You should have received a copy of the GNU Lesser General Public
028: * License along with this library; if not, write to the Free Software
029: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
030: */
031:
032: package org.opencms.setup.comptest;
033:
034: import org.opencms.i18n.CmsEncoder;
035: import org.opencms.setup.CmsSetupBean;
036:
037: import java.io.ByteArrayInputStream;
038:
039: import org.apache.xerces.impl.Version;
040: import org.apache.xerces.parsers.DOMParser;
041:
042: import org.w3c.dom.Document;
043: import org.xml.sax.InputSource;
044:
045: /**
046: * Test for the Xerces version.<p>
047: *
048: * @author Michael Moossen
049: *
050: * @version $Revision: 1.2 $
051: *
052: * @since 6.1.8
053: */
054: public class CmsSetupTestXercesVersion implements I_CmsSetupTest {
055:
056: /** The test name. */
057: public static final String TEST_NAME = "XML Parser";
058:
059: /**
060: * @see org.opencms.setup.comptest.I_CmsSetupTest#getName()
061: */
062: public String getName() {
063:
064: return TEST_NAME;
065: }
066:
067: /**
068: * @see org.opencms.setup.comptest.I_CmsSetupTest#execute(org.opencms.setup.CmsSetupBean)
069: */
070: public CmsSetupTestResult execute(CmsSetupBean setupBean)
071: throws Exception {
072:
073: CmsSetupTestResult testResult = new CmsSetupTestResult(this );
074:
075: DOMParser parser = new DOMParser();
076: String document = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<test>test</test>\n";
077: parser.parse(new InputSource(new ByteArrayInputStream(document
078: .getBytes(CmsEncoder.ENCODING_UTF_8))));
079: Document doc = parser.getDocument();
080:
081: // Xerces 1 and 2 APIs are different, let's see what we have...
082: String versionStr = null;
083: int xercesVersion = 0;
084:
085: try {
086: doc.getClass().getMethod("getXmlEncoding", new Class[] {})
087: .invoke(doc, new Object[] {});
088: versionStr = Version.getVersion();
089: xercesVersion = 2;
090: } catch (Throwable t) {
091: // noop
092: }
093: if (versionStr == null) {
094: try {
095: doc.getClass().getMethod("getEncoding", new Class[] {})
096: .invoke(doc, new Object[] {});
097: versionStr = "Xerces version 1";
098: xercesVersion = 1;
099: } catch (Throwable t) {
100: // noop
101: }
102: }
103:
104: switch (xercesVersion) {
105: case 2:
106: testResult.setResult(versionStr);
107: testResult
108: .setHelp("OpenCms 6.0 requires Xerces version 2 to run. Usually this should be available as part of the servlet environment.");
109: testResult.setGreen();
110: break;
111: case 1:
112: testResult.setResult(versionStr);
113: testResult.setRed();
114: testResult
115: .setInfo("OpenCms 6.0 requires Xerces version 2 to run, your Xerces version is 1. "
116: + "Usually Xerces 2 should be installed by default as part of the servlet environment.");
117: testResult.setHelp(testResult.getInfo());
118: break;
119: default:
120: if (versionStr == null) {
121: versionStr = "Unknown version";
122: }
123: testResult.setResult(versionStr);
124: testResult.setRed();
125: testResult
126: .setInfo("OpenCms 6.0 requires Xerces version 2 to run. "
127: + "Usually Xerces 2 should be installed by default as part of the servlet environment.");
128: testResult.setHelp(testResult.getInfo());
129: }
130: return testResult;
131: }
132: }
|