Main Page   Packages   Class Hierarchy   Compound List   File List   Compound Members  

JAXPDOMTestDocumentBuilderFactory.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: JAXPDOMTestDocumentBuilderFactory.java,v $
00015  Revision 1.1  2002/02/03 07:47:51  dom-ts-4
00016  More missing files
00017 
00018  */
00019 
00020 package org.w3c.domts;
00021 
00022 import javax.xml.parsers.*;
00023 import org.w3c.dom.*;
00024 import org.w3c.domts.*;
00025 import org.xml.sax.*;
00026 
00031 public class JAXPDOMTestDocumentBuilderFactory
00032   extends DOMTestDocumentBuilderFactory {
00033 
00034   private DocumentBuilderFactory factory;
00035   private DocumentBuilder builder;
00036 
00044   public JAXPDOMTestDocumentBuilderFactory(
00045     DocumentBuilderFactory baseFactory,
00046     DocumentBuilderSetting[] settings)
00047     throws DOMTestIncompatibleException {
00048     super(settings);
00049     if(baseFactory == null) {
00050       factory = DocumentBuilderFactory.newInstance();
00051     }
00052     else {
00053       factory = baseFactory;
00054     }
00055     //
00056     //    apply settings to selected document builder
00057     //         may throw exception if incompatible
00058     if(settings != null) {
00059       for(int i = 0; i < settings.length; i++) {
00060         settings[i].applySetting(factory);
00061       }
00062     }
00063     try {
00064       this.builder = factory.newDocumentBuilder();
00065     }
00066     catch(ParserConfigurationException ex) {
00067       throw new DOMTestIncompatibleException(ex,null);
00068     }
00069   }
00070 
00071   public DOMTestDocumentBuilderFactory newInstance(DocumentBuilderSetting[] newSettings)
00072     throws DOMTestIncompatibleException {
00073     if(newSettings == null) {
00074       return this;
00075     }
00076     DocumentBuilderSetting[] mergedSettings = mergeSettings(newSettings);
00077     DocumentBuilderFactory newFactory = factory.newInstance();
00078     return new JAXPDOMTestDocumentBuilderFactory(newFactory,mergedSettings);
00079   }
00080 
00081   private class LoadErrorHandler implements org.xml.sax.ErrorHandler {
00082     private SAXException parseException;
00083     private int errorCount;
00084     private int warningCount;
00085     public LoadErrorHandler() {
00086       parseException = null;
00087       errorCount = 0;
00088       warningCount = 0;
00089     }
00090     public void error(SAXParseException ex) {
00091       errorCount++;
00092       if(parseException == null) {
00093         parseException = ex;
00094       }
00095     }
00096 
00097     public void warning(SAXParseException ex) {
00098       warningCount++;
00099     }
00100 
00101     public void fatalError(SAXParseException ex) {
00102       if(parseException == null) {
00103         parseException = ex;
00104       }
00105     }
00106 
00107     public SAXException getFirstException() {
00108       return parseException;
00109     }
00110   }
00111 
00112 
00113   public Document load(java.net.URL url) throws DOMTestLoadException {
00114     Document doc = null;
00115     Exception parseException = null;
00116     try {
00117       LoadErrorHandler errorHandler = new LoadErrorHandler();
00118       builder.setErrorHandler(errorHandler);
00119       doc = builder.parse(url.openStream(),url.toString());
00120       parseException = errorHandler.getFirstException();
00121     }
00122     catch(Exception ex) {
00123       parseException = ex;
00124     }
00125     builder.setErrorHandler(null);
00126     if(parseException != null) {
00127       throw new DOMTestLoadException(parseException);
00128     }
00129     return doc;
00130   }
00131 
00132   public DOMImplementation getDOMImplementation() {
00133     return builder.getDOMImplementation();
00134   }
00135 
00136   public boolean hasFeature(String feature, String version) {
00137     return builder.getDOMImplementation().hasFeature(feature,version);
00138   }
00139 
00140 
00141     public boolean isCoalescing() {
00142       return factory.isCoalescing();
00143     }
00144 
00145     public boolean isExpandEntityReferences() {
00146       return factory.isExpandEntityReferences();
00147     }
00148 
00149     public boolean isIgnoringElementContentWhitespace() {
00150       return factory.isIgnoringElementContentWhitespace();
00151     }
00152 
00153     public boolean isNamespaceAware() {
00154       return factory.isNamespaceAware();
00155     }
00156 
00157     public boolean isValidating() {
00158       return factory.isValidating();
00159     }
00160 
00161   public static DocumentBuilderSetting[] getConfiguration1()
00162   {
00163     return new DocumentBuilderSetting[] {
00164           DocumentBuilderSetting.notCoalescing,
00165           DocumentBuilderSetting.notExpandEntityReferences,
00166           DocumentBuilderSetting.notIgnoringElementContentWhitespace,
00167           DocumentBuilderSetting.notNamespaceAware,
00168           DocumentBuilderSetting.notValidating };
00169   }
00170 
00171   public static DocumentBuilderSetting[] getConfiguration2() {
00172       return new DocumentBuilderSetting[] {
00173           DocumentBuilderSetting.notCoalescing,
00174           DocumentBuilderSetting.expandEntityReferences,
00175           DocumentBuilderSetting.ignoringElementContentWhitespace,
00176           DocumentBuilderSetting.namespaceAware,
00177           DocumentBuilderSetting.validating };
00178 
00179   }
00180 
00181 
00182 }
00183 

Generated on Thu Feb 14 19:46:07 2002 for DOM Level 1 Core Test Suite by doxygen1.2.13.1 written by Dimitri van Heesch, © 1997-2001