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

BatikTestDocumentBuilderFactory

public class BatikTestDocumentBuilderFactory extends DOMTestDocumentBuilderFactory
This class implements the generic parser and configuation abstract class for the DOM implementation of Batik.
author
Curt Arnold

Fields Summary
private Object
domFactory
dom factory.
private XMLReader
xmlReader
xml reader.
private Method
createDocument
reflective method to create document in Batik.
private DOMImplementation
domImpl
dom implementation from Batik.
Constructors Summary
public BatikTestDocumentBuilderFactory(DocumentBuilderSetting[] settings)
Creates a Batik implementation of DOMTestDocumentBuilderFactory.

param
settings array of settings, may be null.
throws
DOMTestIncompatibleException If implementation does not support the specified settings

    super(settings);
    domImpl = null;

    //
    //   get the JAXP specified SAX parser's class name
    //
    SAXParserFactory saxFactory = SAXParserFactory.newInstance();
    try {
      SAXParser saxParser = saxFactory.newSAXParser();
      xmlReader = saxParser.getXMLReader();
    } catch (Exception ex) {
      throw new DOMTestIncompatibleException(ex, null);
    }
    String xmlReaderClassName = xmlReader.getClass().getName();

    //
    //   can't change settings, so if not the same as
    //      the default SAX parser then throw an exception
    //
    //    for(int i = 0; i < settings.length; i++) {
    //      if(!settings[i].hasSetting(this)) {
    //        TODO
    //        throw new DOMTestIncompatibleException(null,settings[i]);
    //      }
    //    }
    //
    //   try loading Batik reflectively
    //
    try {
      ClassLoader classLoader = ClassLoader.getSystemClassLoader();
      Class domFactoryClass =
          classLoader.loadClass(
          "org.apache.batik.dom.svg.SAXSVGDocumentFactory");

      Constructor domFactoryConstructor =
          domFactoryClass.getConstructor(new Class[] {String.class});
      domFactory =
          domFactoryConstructor.newInstance(
          new Object[] {xmlReaderClassName});
      createDocument =
          domFactoryClass.getMethod(
          "createDocument",
          new Class[] {String.class, java.io.InputStream.class});
    } catch (InvocationTargetException ex) {
      throw new DOMTestIncompatibleException(
          ex.getTargetException(),
          null);
    } catch (Exception ex) {
      throw new DOMTestIncompatibleException(ex, null);
    }
  
Methods Summary
public java.lang.StringaddExtension(java.lang.String testFileName)
Adds any specialized extension required by the implementation.

param
testFileName file name from test
return
possibly modified file name

    return testFileName + ".svg";
  
public java.lang.StringgetContentType()
Gets content type.

return
content type, "image/svg+xml"

    return "image/svg+xml";
  
public org.w3c.dom.DOMImplementationgetDOMImplementation()
Gets DOMImplementation.

return
DOM implementation, may be null

    //
    //   get DOM implementation
    //
    if (domImpl == null) {
      try {
        Class svgDomImplClass =
            ClassLoader.getSystemClassLoader().loadClass(
            "org.apache.batik.dom.svg.SVGDOMImplementation");
        Method getImpl =
            svgDomImplClass.getMethod(
            "getDOMImplementation",
            new Class[0]);
        domImpl =
            (DOMImplementation) getImpl.invoke(null, new Object[0]);
      } catch (Exception ex) {
        return null;
      }
    }
    return domImpl;
  
public booleanhasFeature(java.lang.String feature, java.lang.String version)
Determines if the implementation supports the specified feature.

param
feature Feature
param
version Version
return
true if implementation supports the feature

    return getDOMImplementation().hasFeature(feature, version);
  
public booleanisCoalescing()
Indicates whether the implementation combines text and cdata nodes.

return
true if coalescing

    return false;
  
public booleanisExpandEntityReferences()
Indicates whether the implementation expands entity references.

return
true if expanding entity references

    return false;
  
public booleanisIgnoringElementContentWhitespace()
Indicates whether the implementation ignores element content whitespace.

return
true if ignoring element content whitespace

    return false;
  
public booleanisNamespaceAware()
Indicates whether the implementation is namespace aware.

return
true if namespace aware

    return true;
  
public booleanisValidating()
Indicates whether the implementation is validating.

return
true if validating

    return false;
  
public org.w3c.dom.Documentload(java.net.URL url)
Loads specified URL.

param
url url to load
return
DOM document
throws
DOMTestLoadException if unable to load document

    try {
      java.io.InputStream stream = url.openStream();
      return (org.w3c.dom.Document) createDocument.invoke(
          domFactory,
          new Object[] {url.toString(), stream});
    } catch (InvocationTargetException ex) {
      ex.printStackTrace();
      throw new DOMTestLoadException(ex.getTargetException());
    } catch (Exception ex) {
      ex.printStackTrace();
      throw new DOMTestLoadException(ex);
    }
  
public DOMTestDocumentBuilderFactorynewInstance(DocumentBuilderSetting[] newSettings)
Create new instance of document builder factory reflecting specified settings.

param
newSettings new settings
return
New instance
throws
DOMTestIncompatibleException if settings are not supported by implementation

    if (newSettings == null) {
      return this;
    }
    DocumentBuilderSetting[] mergedSettings = mergeSettings(newSettings);
    return new BatikTestDocumentBuilderFactory(mergedSettings);