FileDocCategorySizeDatePackage
DOMTest.javaAPI DocAndroid 1.5 API8369Wed May 06 22:41:04 BST 2009org.w3c.domts

DOMTest

public abstract class DOMTest extends Object
This is an abstract base class for generated DOM tests

Fields Summary
private DOMTestDocumentBuilderFactory
factory
private int
mutationCount
Constructors Summary
public DOMTest(DOMTestDocumentBuilderFactory factory)
This is the appropriate constructor for tests that make no requirements on the parser configuration.

param
factory must not be null


                                     
     
    if (factory == null) {
      throw new NullPointerException("factory");
    }
    this.factory = factory;
  
public DOMTest()
This constructor is used by tests that must create a modified document factory to meet requirements on the parser configuration. setFactory should be called within the test's constructor.

    factory = null;
  
Methods Summary
public java.io.InputStreamcreateStream(java.lang.String bytes)

    int byteCount = bytes.length() / 2;
    byte[] array = new byte[byteCount];
    for (int i = 0; i < byteCount; i++) {
      array[i] = Byte.parseByte(bytes.substring(i * 2, i * 2 + 2), 16);
    }
    return new java.io.ByteArrayInputStream(array);
  
public java.lang.StringcreateTempURI(java.lang.String scheme)

    if (scheme == null) {
      throw new NullPointerException("scheme");
    }
    if ("file".equals(scheme)) {
      try {
        File tempFile = File.createTempFile("domts", ".xml");
        try {
          //
          //   if available use JDK 1.4's File.toURI().toString()
          //
          Method method = File.class.getMethod("toURI", null);
          Object uri = method.invoke(tempFile, null);
          return uri.toString();
        }
        catch (NoSuchMethodException ex) {
          //
          //   File.toURL is not as robust
          //
          URL url = tempFile.toURL();
          return url.toString();
        }
      }
      catch (Exception ex) {
        throw new DOMTestLoadException(ex);
      }
    }
    if ("http".equals(scheme)) {
      String httpBase = System.getProperty("org.w3c.domts.httpbase",
                                           "http://localhost:8080/webdav/");
      java.lang.StringBuffer buf = new StringBuffer(httpBase);
      if (!httpBase.endsWith("/")) {
          buf.append("/");
      }
      buf.append("tmp");
      buf.append( (new java.util.Random()).nextInt(Integer.MAX_VALUE));
      buf.append(".xml");
      return buf.toString();
    }
    throw new DOMTestLoadException(new Exception("Unrecognized URI scheme " +
                                                 scheme));
  
public java.lang.ObjectcreateXPathEvaluator(org.w3c.dom.Document doc)

    return factory.createXPathEvaluator(doc);
  
public final java.lang.StringgetContentType()

    return factory.getContentType();
  
protected DOMTestDocumentBuilderFactorygetFactory()

    return factory;
  
public org.w3c.dom.DOMImplementationgetImplementation()

    return factory.getDOMImplementation();
  
public final intgetMutationCount()
Implementation of EventListener.handleEvent This method is called when a mutation is reported for a document that was declared to not be modified during testing

param
evt mutation event

    return mutationCount;
  
public java.lang.StringgetResourceURI(java.lang.String href, java.lang.String scheme, java.lang.String contentType)

    if (scheme == null) {
      throw new NullPointerException("scheme");
    }
    if ("file".equals(scheme)) {
      return resolveURI(href).toString();
    }
    if ("http".equals(scheme)) {
      StringBuffer httpURL = new StringBuffer(
          System.getProperty("org.w3c.domts.httpbase",
                             "http://localhost:8080/webdav/"));
      httpURL.append(href);
      if ("application/pdf".equals(contentType)) {
        httpURL.append(".pdf");
      }
      else {
        httpURL.append(".xml");
      }
      return httpURL.toString();
    }
    throw new DOMTestLoadException(new Exception("Unrecognized URI scheme " +
                                                 scheme));
  
public abstract java.lang.StringgetTargetURI()

public booleanhasFeature(java.lang.String feature, java.lang.String version)

    return factory.hasFeature(feature, version);
  
public booleanhasSetting(DocumentBuilderSetting setting)

    return setting.hasSetting(factory);
  
public final booleanisCoalescing()

    return factory.isCoalescing();
  
public final booleanisExpandEntityReferences()

    return factory.isExpandEntityReferences();
  
public final booleanisHasNullString()

    return true;
  
public final booleanisIgnoringElementContentWhitespace()

    return factory.isIgnoringElementContentWhitespace();
  
public final booleanisNamespaceAware()

    return factory.isNamespaceAware();
  
public final booleanisSigned()

    return true;
  
public final booleanisValidating()

    return factory.isValidating();
  
public org.w3c.dom.Documentload(java.lang.String docURI, boolean willBeModified)

    Document doc = factory.load(resolveURI(docURI));
    //
    //   if will be modified is false and doc is an EventTarget
    //
    /*
     * wBM: if (!willBeModified && doc instanceof EventTarget) {
     * ((EventTarget) doc).addEventListener("DOMSubtreeModified", this,
     * false); }
     */
    return doc;
  
public voidpreload(java.lang.String contentType, java.lang.String docURI, boolean willBeModified)

    if ("text/html".equals(contentType) ||
        "application/xhtml+xml".equals(contentType)) {
      if (docURI.startsWith("staff") || docURI.equals("datatype_normalization")) {
        throw DOMTestIncompatibleException.incompatibleLoad(docURI, contentType);
      }
    }
  
private java.net.URLresolveURI(java.lang.String baseURI)

    String docURI = factory.addExtension(baseURI);

    URL resolvedURI = null;
    try {
      resolvedURI = new URL(docURI);
      if (resolvedURI.getProtocol() != null) {
        return resolvedURI;
      }
    }
    catch (MalformedURLException ex) {
      //        throw new DOMTestLoadException(ex);
    }
    //
    //   build a URL for a test file in the JAR
    //
    resolvedURI = getClass().getResource("/" + docURI);
    if (resolvedURI == null) {
      //
      //   see if it is an absolute URI
      //
      int firstSlash = docURI.indexOf('/");
      try {
        if (firstSlash == 0
            || (firstSlash >= 1
                && docURI.charAt(firstSlash - 1) == ':")) {
          resolvedURI = new URL(docURI);
        }
        else {
          //
          //  try the files/level?/spec directory
          //
          String filename = getClass().getPackage().getName();
          filename =
              "tests/"
              + filename.substring(14).replace('.", '/")
              + "/files/"
              + docURI;
          resolvedURI = new java.io.File(filename).toURL();
        }
      }
      catch (MalformedURLException ex) {
        throw new DOMTestLoadException(ex);
      }
    }

    if (resolvedURI == null) {
      throw new DOMTestLoadException(
          new java.io.FileNotFoundException(docURI));
    }
    return resolvedURI;
  
protected voidsetFactory(DOMTestDocumentBuilderFactory factory)
Should only be called in the constructor of a derived type.

    this.factory = factory;