KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > xslt > support > XalanCheck


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.test.xslt.support;
23
24 import java.io.StringReader JavaDoc;
25 import java.lang.reflect.Method JavaDoc;
26 import java.lang.reflect.UndeclaredThrowableException JavaDoc;
27 import java.util.Hashtable JavaDoc;
28
29 import javax.xml.parsers.SAXParser JavaDoc;
30 import javax.xml.parsers.SAXParserFactory JavaDoc;
31 import javax.xml.transform.TransformerFactory JavaDoc;
32 import javax.xml.transform.dom.DOMResult JavaDoc;
33 import javax.xml.transform.sax.SAXTransformerFactory JavaDoc;
34 import javax.xml.transform.sax.TransformerHandler JavaDoc;
35
36 import org.jboss.system.ServiceMBeanSupport;
37 import org.xml.sax.InputSource JavaDoc;
38 import org.xml.sax.XMLReader JavaDoc;
39
40 /**
41  * A test mbean service.
42  *
43  * @author <a HREF="mailto:dimitris@jboss.org">Dimitris Andreadis</a>
44  * @version $Revision: 37406 $
45  */

46 public class XalanCheck extends ServiceMBeanSupport
47    implements XalanCheckMBean
48 {
49    // Constructors --------------------------------------------------
50

51    /**
52     * CTOR
53    **/

54    public XalanCheck()
55    {
56       // empty
57
}
58
59    // Attributes -----------------------------------------------------
60

61    public String JavaDoc getXalanVersion()
62    {
63       try
64       {
65          ClassLoader JavaDoc loader = Thread.currentThread().getContextClassLoader();
66          Class JavaDoc c = loader.loadClass("org.apache.xalan.Version");
67          Object JavaDoc v = c.newInstance();
68          Class JavaDoc[] sig = {};
69          Method JavaDoc getVersion = c.getDeclaredMethod("getVersion", sig);
70          Object JavaDoc[] args = {};
71          String JavaDoc version = (String JavaDoc) getVersion.invoke(v, args);
72          return version;
73       }
74       catch(Throwable JavaDoc e)
75       {
76          throw new UndeclaredThrowableException JavaDoc(e);
77       }
78    }
79    
80    // Operations -----------------------------------------------------
81

82    public Hashtable JavaDoc fetchXalanEnvironmentHash()
83    {
84       try
85       {
86          ClassLoader JavaDoc loader = Thread.currentThread().getContextClassLoader();
87          Class JavaDoc c = loader.loadClass("org.apache.xalan.xslt.EnvironmentCheck");
88          Object JavaDoc envc = c.newInstance();
89          Class JavaDoc[] sig = {};
90          Method JavaDoc getEnvironmentHash = c.getDeclaredMethod("getEnvironmentHash", sig);
91          Object JavaDoc[] args = {};
92          Hashtable JavaDoc htab = (Hashtable JavaDoc) getEnvironmentHash.invoke(envc, args);
93          return htab;
94       }
95       catch(Throwable JavaDoc e)
96       {
97          throw new UndeclaredThrowableException JavaDoc(e);
98       }
99    }
100    
101    /**
102     * Throws an exception when run using xalan 2.5.2
103     * Borrowed from here: http://issues.apache.org/bugzilla/show_bug.cgi?id=15140
104     */

105    public void testXalan25Bug15140() throws Exception JavaDoc
106    {
107        String JavaDoc testString = "<doc xmlns:a=\"http://www.test.com\"/>";
108        
109        SAXParserFactory JavaDoc parserFactory
110          = SAXParserFactory.newInstance();
111        SAXParser JavaDoc parser = parserFactory.newSAXParser();
112        XMLReader JavaDoc reader = parser.getXMLReader();
113        reader.setFeature("http://xml.org/sax/features/namespaces", true);
114        reader.setFeature("http://xml.org/sax/features/namespace-prefixes", true);
115
116        DOMResult JavaDoc domResult = new DOMResult JavaDoc();
117        SAXTransformerFactory JavaDoc transformerFactory
118          = (SAXTransformerFactory JavaDoc) TransformerFactory.newInstance();
119        TransformerHandler JavaDoc handler = transformerFactory.newTransformerHandler();
120        handler.setResult(domResult);
121
122        reader.setContentHandler(handler);
123
124        InputSource JavaDoc input = new InputSource JavaDoc(new StringReader JavaDoc(testString));
125        reader.parse(input);
126    }
127 }
128
Popular Tags