00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 package org.w3c.domts;
00022
00023 import javax.xml.parsers.*;
00024 import org.w3c.dom.*;
00025 import org.w3c.domts.*;
00026 import org.xml.sax.*;
00027 import java.lang.reflect.*;
00028
00033 public class BatikTestDocumentBuilderFactory
00034 extends DOMTestDocumentBuilderFactory {
00035
00036 private Object domFactory;
00037 private org.xml.sax.XMLReader xmlReader;
00038 private Method createDocument;
00039 private DOMImplementation domImpl;
00040
00041
00046 public BatikTestDocumentBuilderFactory(DocumentBuilderSetting[] settings)
00047 throws DOMTestIncompatibleException {
00048 super(settings);
00049 domImpl = null;
00050
00051
00052
00053
00054 SAXParserFactory saxFactory = SAXParserFactory.newInstance();
00055 try {
00056 SAXParser saxParser = saxFactory.newSAXParser();
00057 xmlReader = saxParser.getXMLReader();
00058 }
00059 catch(Exception ex) {
00060 throw new DOMTestIncompatibleException(ex,null);
00061 }
00062 String xmlReaderClassName = xmlReader.getClass().getName();
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077 try {
00078 ClassLoader classLoader = ClassLoader.getSystemClassLoader();
00079 Class domFactoryClass = classLoader.loadClass("org.apache.batik.dom.svg.SAXSVGDocumentFactory");
00080
00081 Constructor domFactoryConstructor =
00082 domFactoryClass.getConstructor(new Class[] { String.class });
00083 domFactory = domFactoryConstructor.newInstance(
00084 new Object[] { xmlReaderClassName } );
00085 createDocument = domFactoryClass.getMethod("createDocument",
00086 new Class[] { String.class, java.io.InputStream.class });
00087 }
00088 catch(InvocationTargetException ex) {
00089 throw new DOMTestIncompatibleException(ex.getTargetException(),null);
00090 }
00091 catch(Exception ex) {
00092 throw new DOMTestIncompatibleException(ex,null);
00093 }
00094 }
00095
00096 public DOMTestDocumentBuilderFactory newInstance(DocumentBuilderSetting[] newSettings)
00097 throws DOMTestIncompatibleException {
00098 if(newSettings == null) {
00099 return this;
00100 }
00101 DocumentBuilderSetting[] mergedSettings = mergeSettings(newSettings);
00102 return new BatikTestDocumentBuilderFactory(mergedSettings);
00103 }
00104
00105 public Document load(java.net.URL url) throws DOMTestLoadException {
00106 try {
00107 java.io.InputStream stream = url.openStream();
00108 return (org.w3c.dom.Document)
00109 createDocument.invoke(domFactory, new Object[] { url.toString(), stream });
00110 }
00111 catch(InvocationTargetException ex) {
00112 ex.printStackTrace();
00113 throw new DOMTestLoadException(ex.getTargetException());
00114 }
00115 catch(Exception ex) {
00116 ex.printStackTrace();
00117 throw new DOMTestLoadException(ex);
00118 }
00119 }
00120
00121 public DOMImplementation getDOMImplementation() {
00122
00123
00124
00125 if(domImpl == null) {
00126 try {
00127 Class svgDomImplClass = ClassLoader.getSystemClassLoader().loadClass("org.apache.batik.dom.svg.SVGDOMImplementation");
00128 Method getImpl = svgDomImplClass.getMethod("getDOMImplementation",new Class[0]);
00129 domImpl = (DOMImplementation) getImpl.invoke(null,new Object[0]);
00130 }
00131 catch(Exception ex) {
00132 }
00133 }
00134 return domImpl;
00135 }
00136
00137 public boolean hasFeature(String feature, String version) {
00138 return getDOMImplementation().hasFeature(feature,version);
00139 }
00140
00141 public String addExtension(String testFileName) {
00142 return testFileName + ".svg";
00143 }
00144
00145 public boolean isCoalescing() {
00146 return false;
00147 }
00148
00149 public boolean isExpandEntityReferences() {
00150 return false;
00151 }
00152
00153 public boolean isIgnoringElementContentWhitespace() {
00154 return false;
00155 }
00156
00157 public boolean isNamespaceAware() {
00158 return true;
00159 }
00160
00161 public boolean isValidating() {
00162 return false;
00163 }
00164
00165
00166 }
00167