Main Page   Packages   Class Hierarchy   Compound List   File List   Compound Members  

DOMTest.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: DOMTest.java,v $
00015  Revision 1.2  2002/02/03 04:22:35  dom-ts-4
00016  DOM4J and Batik support added.
00017  Rework of parser settings
00018 
00019  Revision 1.1  2001/07/23 04:52:20  dom-ts-4
00020  Initial test running using JUnit.
00021 
00022  */
00023 
00024 package org.w3c.domts;
00025 import org.w3c.dom.*;
00026 import java.io.*;
00027 import java.net.*;
00028 
00029 
00033 public abstract class DOMTest {
00034   private DOMTestDocumentBuilderFactory factory;
00035 
00041   public DOMTest(DOMTestDocumentBuilderFactory factory) {
00042     if(factory == null) {
00043       throw new NullPointerException("factory");
00044     }
00045     this.factory = factory;
00046   }
00047 
00054   public DOMTest() {
00055     factory = null;
00056   }
00057 
00061   protected void setFactory(DOMTestDocumentBuilderFactory factory) {
00062     this.factory = factory;
00063   }
00064 
00065   public boolean hasFeature(String feature,String version)  {
00066      return factory.hasFeature(feature,version);
00067   }
00068 
00069   public boolean hasSetting(DocumentBuilderSetting setting)  {
00070      return setting.hasSetting(factory);
00071   }
00072 
00073 
00074   protected DOMTestDocumentBuilderFactory getFactory() {
00075     return factory;
00076   }
00077 
00078   public Document load(String docURI) throws DOMTestLoadException {
00079 
00080     docURI = factory.addExtension(docURI);
00081     //
00082     //   build a URL for a test file in the JAR
00083     //
00084     URL resolvedURI = getClass().getResource("/" + docURI);
00085     if(resolvedURI == null) {
00086         //
00087         //   see if it is an absolute URI
00088         //
00089         int firstSlash = docURI.indexOf('/');
00090         try {
00091           if(firstSlash == 0 ||
00092             (firstSlash >= 1 && docURI.charAt(firstSlash-1) == ':')) {
00093               resolvedURI = new URL(docURI);
00094           }
00095           else {
00096             //
00097             //  try the files/level?/spec directory
00098             //
00099             String filename = getClass().getPackage().getName();
00100             filename = "tests/" + filename.substring(14).replace('.','/') + "/files/" + docURI;
00101             resolvedURI = new java.io.File(filename).toURL();
00102           }
00103         }
00104         catch(MalformedURLException ex) {
00105           throw new DOMTestLoadException(ex);
00106         }
00107     }
00108 
00109     if(resolvedURI == null) {
00110         throw new DOMTestLoadException(new java.io.FileNotFoundException(docURI));
00111     }
00112 
00113     return factory.load(resolvedURI);
00114   }
00115 
00116 
00117   abstract public String getTargetURI();
00118 
00119   public final boolean isCoalescing() {
00120       return factory.isCoalescing();
00121   }
00122 
00123   public final boolean isExpandEntityReferences() {
00124       return factory.isExpandEntityReferences();
00125   }
00126 
00127   public final boolean isIgnoringElementContentWhitespace() {
00128       return factory.isIgnoringElementContentWhitespace();
00129   }
00130 
00131   public final boolean isNamespaceAware() {
00132       return factory.isNamespaceAware();
00133   }
00134 
00135   public final boolean isValidating() {
00136       return factory.isValidating();
00137   }
00138 
00139   public final boolean isSigned() {
00140     return true;
00141   }
00142 
00143   public final boolean isHasNullString() {
00144     return true;
00145   }
00146 
00147 }
00148 

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