001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.test.xslt.support;
023:
024: import java.io.StringReader;
025: import java.lang.reflect.Method;
026: import java.lang.reflect.UndeclaredThrowableException;
027: import java.util.Hashtable;
028:
029: import javax.xml.parsers.SAXParser;
030: import javax.xml.parsers.SAXParserFactory;
031: import javax.xml.transform.TransformerFactory;
032: import javax.xml.transform.dom.DOMResult;
033: import javax.xml.transform.sax.SAXTransformerFactory;
034: import javax.xml.transform.sax.TransformerHandler;
035:
036: import org.jboss.system.ServiceMBeanSupport;
037: import org.xml.sax.InputSource;
038: import org.xml.sax.XMLReader;
039:
040: /**
041: * A test mbean service.
042: *
043: * @author <a href="mailto:dimitris@jboss.org">Dimitris Andreadis</a>
044: * @version $Revision: 57211 $
045: */
046: public class XalanCheck extends ServiceMBeanSupport implements
047: XalanCheckMBean {
048: // Constructors --------------------------------------------------
049:
050: /**
051: * CTOR
052: **/
053: public XalanCheck() {
054: // empty
055: }
056:
057: // Attributes -----------------------------------------------------
058:
059: public String getXalanVersion() {
060: try {
061: ClassLoader loader = Thread.currentThread()
062: .getContextClassLoader();
063: Class c = loader.loadClass("org.apache.xalan.Version");
064: Object v = c.newInstance();
065: Class[] sig = {};
066: Method getVersion = c.getDeclaredMethod("getVersion", sig);
067: Object[] args = {};
068: String version = (String) getVersion.invoke(v, args);
069: return version;
070: } catch (Throwable e) {
071: throw new UndeclaredThrowableException(e);
072: }
073: }
074:
075: // Operations -----------------------------------------------------
076:
077: public Hashtable fetchXalanEnvironmentHash() {
078: try {
079: ClassLoader loader = Thread.currentThread()
080: .getContextClassLoader();
081: Class c = loader
082: .loadClass("org.apache.xalan.xslt.EnvironmentCheck");
083: Object envc = c.newInstance();
084: Class[] sig = {};
085: Method getEnvironmentHash = c.getDeclaredMethod(
086: "getEnvironmentHash", sig);
087: Object[] args = {};
088: Hashtable htab = (Hashtable) getEnvironmentHash.invoke(
089: envc, args);
090: return htab;
091: } catch (Throwable e) {
092: throw new UndeclaredThrowableException(e);
093: }
094: }
095:
096: /**
097: * Throws an exception when run using xalan 2.5.2
098: * Borrowed from here: http://issues.apache.org/bugzilla/show_bug.cgi?id=15140
099: */
100: public void testXalan25Bug15140() throws Exception {
101: String testString = "<doc xmlns:a=\"http://www.test.com\"/>";
102:
103: SAXParserFactory parserFactory = SAXParserFactory.newInstance();
104: SAXParser parser = parserFactory.newSAXParser();
105: XMLReader reader = parser.getXMLReader();
106: reader.setFeature("http://xml.org/sax/features/namespaces",
107: true);
108: reader.setFeature(
109: "http://xml.org/sax/features/namespace-prefixes", true);
110:
111: DOMResult domResult = new DOMResult();
112: SAXTransformerFactory transformerFactory = (SAXTransformerFactory) TransformerFactory
113: .newInstance();
114: TransformerHandler handler = transformerFactory
115: .newTransformerHandler();
116: handler.setResult(domResult);
117:
118: reader.setContentHandler(handler);
119:
120: InputSource input = new InputSource(
121: new StringReader(testString));
122: reader.parse(input);
123: }
124: }
|