Main Page Packages Class Hierarchy Compound List File List Compound Members

# BatikTestDocumentBuilderFactory.java

Go to the documentation of this file.

    00001 /*
    00002  * Copyright (c) 2001 World Wide Web Consortium,
    00003  * (Massachusetts Institute of Technology, Institut National de
    00004  * Recherche en Informatique et en Automatique, Keio University). All
    00005  * Rights Reserved. This program is distributed under the W3C's Software
    00006  * Intellectual Property License. This program is distributed in the
    00007  * hope that it will be useful, but WITHOUT ANY WARRANTY; without even
    00008  * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
    00009  * PURPOSE.
    00010  * See W3C License http://www.w3.org/Consortium/Legal/ for more details.
    00011  */
    00012
    00013  /*
    00014  $Log: BatikTestDocumentBuilderFactory.java,v $
    00015  Revision 1.1  2002/02/03 04:22:35  dom-ts-4
    00016  DOM4J and Batik support added.
    00017  Rework of parser settings
    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 /* org.dom4j.DocumentFactory */ 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     //   get the JAXP specified SAX parser's class name
    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     //   can't change settings, so if not the same as
    00066     //      the default SAX parser then throw an exception
    00067     //
    00068 //    for(int i = 0; i < settings.length; i++) {
    00069 //      if(!settings[i].hasSetting(this)) {
    00070       //        TODO
    00071       //        throw new DOMTestIncompatibleException(null,settings[i]);
    00072 //      }
    00073 //    }
    00074     //
    00075     //   try loading Batik reflectively
    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       //   get DOM implementation
    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