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

LSDocumentBuilderFactory

public class LSDocumentBuilderFactory extends DOMTestDocumentBuilderFactory
This class implements the generic parser and configuation abstract class for the DOM L3 implementations
author
Curt Arnold

Fields Summary
private final Object
parser
private final Method
parseURIMethod
private final DOMImplementation
impl
private static final Map
strategies
Strategies for mapping DocumentBuilderSettings to actions on LSParser
Constructors Summary
public LSDocumentBuilderFactory(DocumentBuilderSetting[] settings)
Creates a LS implementation of DOMTestDocumentBuilderFactory.

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

    strategies = new HashMap();
    strategies.put("coalescing", new LSParameterStrategy("cdata-sections", true));
    strategies.put("expandEntityReferences", new LSParameterStrategy("entities", true));
    strategies.put("ignoringElementContentWhitespace",
                   new LSParameterStrategy("element-content-whitespace", true));
    strategies.put("namespaceAware", new LSParameterStrategy("namespaces", false));
    strategies.put("validating",
                   new LSValidateStrategy("http://www.w3.org/TR/REC-xml"));
    strategies.put("schemaValidating",
                   new LSValidateStrategy("http://www.w3.org/2001/XMLSchema"));
    strategies.put("ignoringComments", new LSParameterStrategy("comments", true));
    strategies.put("signed", new LSFixedStrategy(true));
    strategies.put("hasNullString", new LSFixedStrategy(true));
  
    super(settings);

    try {
      Class domImplRegistryClass = Class.forName(
          "org.w3c.dom.bootstrap.DOMImplementationRegistry");
      Method newInstanceMethod = domImplRegistryClass.getMethod("newInstance", null);
      Object domRegistry = newInstanceMethod.invoke(null, null);
      Method getDOMImplementationMethod = domImplRegistryClass.getMethod(
          "getDOMImplementation", new Class[] {String.class});
      impl = (DOMImplementation) getDOMImplementationMethod.invoke(domRegistry,
          new Object[] {"LS"});
      Method createLSParserMethod = impl.getClass().getMethod("createLSParser",
          new Class[] {short.class, String.class});
      parser = createLSParserMethod.invoke(impl,
                                           new Object[] {new Short( (short) 1), null});
      parseURIMethod = parser.getClass().getMethod("parseURI",
          new Class[] {String.class});
    }
    catch (InvocationTargetException ex) {
      throw new DOMTestIncompatibleException(ex.getTargetException(), null);
    }
    catch (Exception ex) {
      throw new DOMTestIncompatibleException(ex, null);
    }

    if (settings != null) {
      for (int i = 0; i < settings.length; i++) {
        Object strategy = strategies.get(settings[i].getProperty());
        if (strategy == null) {
          throw new DOMTestIncompatibleException(null, settings[i]);
        }
        else {
          ( (LSStrategy) strategy).applySetting(settings[i], parser);
        }
      }
    }
  
Methods Summary
public org.w3c.dom.DOMImplementationgetDOMImplementation()
Gets DOMImplementation

return
DOM implementation, may be null

    return impl;
  
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);
  
private booleanhasProperty(java.lang.String parameter)

    try {
      return ( (Boolean) LSParameterStrategy.getParameter(parser, parameter)).
          booleanValue();
    }
    catch (Exception ex) {
      return true;
    }

  
public booleanisCoalescing()
Indicates whether the implementation combines text and cdata nodes.

return
true if coalescing

    return!hasProperty("cdata-sections");
  
public booleanisExpandEntityReferences()
Indicates whether the implementation expands entity references.

return
true if expanding entity references

    return!hasProperty("entities");
  
public booleanisIgnoringElementContentWhitespace()
Indicates whether the implementation ignores element content whitespace.

return
true if ignoring element content whitespace

    return!hasProperty("element-content-whitespace");
  
public booleanisNamespaceAware()
Indicates whether the implementation is namespace aware.

return
true if namespace aware

    return hasProperty("namespaces");
  
public booleanisValidating()
Indicates whether the implementation is validating.

return
true if validating

    return hasProperty("validate");
  
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 {
      return (Document) parseURIMethod.invoke(parser,
                                              new Object[] {url.toString()});
    }
    catch (InvocationTargetException ex) {
      throw new DOMTestLoadException(ex.getTargetException());
    }
    catch (Exception ex) {
      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 LSDocumentBuilderFactory(mergedSettings);