1 22 package org.jboss.test.xslt.support; 23 24 import java.io.StringReader ; 25 import java.lang.reflect.Method ; 26 import java.lang.reflect.UndeclaredThrowableException ; 27 import java.util.Hashtable ; 28 29 import javax.xml.parsers.SAXParser ; 30 import javax.xml.parsers.SAXParserFactory ; 31 import javax.xml.transform.TransformerFactory ; 32 import javax.xml.transform.dom.DOMResult ; 33 import javax.xml.transform.sax.SAXTransformerFactory ; 34 import javax.xml.transform.sax.TransformerHandler ; 35 36 import org.jboss.system.ServiceMBeanSupport; 37 import org.xml.sax.InputSource ; 38 import org.xml.sax.XMLReader ; 39 40 46 public class XalanCheck extends ServiceMBeanSupport 47 implements XalanCheckMBean 48 { 49 51 54 public XalanCheck() 55 { 56 } 58 59 61 public String getXalanVersion() 62 { 63 try 64 { 65 ClassLoader loader = Thread.currentThread().getContextClassLoader(); 66 Class c = loader.loadClass("org.apache.xalan.Version"); 67 Object v = c.newInstance(); 68 Class [] sig = {}; 69 Method getVersion = c.getDeclaredMethod("getVersion", sig); 70 Object [] args = {}; 71 String version = (String ) getVersion.invoke(v, args); 72 return version; 73 } 74 catch(Throwable e) 75 { 76 throw new UndeclaredThrowableException (e); 77 } 78 } 79 80 82 public Hashtable fetchXalanEnvironmentHash() 83 { 84 try 85 { 86 ClassLoader loader = Thread.currentThread().getContextClassLoader(); 87 Class c = loader.loadClass("org.apache.xalan.xslt.EnvironmentCheck"); 88 Object envc = c.newInstance(); 89 Class [] sig = {}; 90 Method getEnvironmentHash = c.getDeclaredMethod("getEnvironmentHash", sig); 91 Object [] args = {}; 92 Hashtable htab = (Hashtable ) getEnvironmentHash.invoke(envc, args); 93 return htab; 94 } 95 catch(Throwable e) 96 { 97 throw new UndeclaredThrowableException (e); 98 } 99 } 100 101 105 public void testXalan25Bug15140() throws Exception 106 { 107 String testString = "<doc xmlns:a=\"http://www.test.com\"/>"; 108 109 SAXParserFactory parserFactory 110 = SAXParserFactory.newInstance(); 111 SAXParser parser = parserFactory.newSAXParser(); 112 XMLReader 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 domResult = new DOMResult (); 117 SAXTransformerFactory transformerFactory 118 = (SAXTransformerFactory ) TransformerFactory.newInstance(); 119 TransformerHandler handler = transformerFactory.newTransformerHandler(); 120 handler.setResult(domResult); 121 122 reader.setContentHandler(handler); 123 124 InputSource input = new InputSource (new StringReader (testString)); 125 reader.parse(input); 126 } 127 } 128 | Popular Tags |