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

XercesHTML2DocumentBuilderFactory

public class XercesHTML2DocumentBuilderFactory extends DOMTestDocumentBuilderFactory
This class implements the generic parser and configuation class for the HTML DOM L2 implementation in Xerces-J

Fields Summary
private SAXParserFactory
factory
private Constructor
htmlBuilderConstructor
private Method
getHTMLDocumentMethod
private DOMImplementation
domImpl
private static final Class[]
NO_CLASSES
private static final Object[]
NO_OBJECTS
Constructors Summary
public XercesHTML2DocumentBuilderFactory(DocumentBuilderSetting[] settings)
Creates a implementation of DOMTestDocumentBuilderFactory using org.apache.html.dom.HTMLBuilder

param
settings array of settings, may be null.


                    
     
       
    super(settings);

    try {
      ClassLoader classLoader = ClassLoader.getSystemClassLoader();
      Class htmlBuilderClass =
          classLoader.loadClass("org.apache.html2.dom.HTMLBuilder");

      htmlBuilderConstructor =
          htmlBuilderClass.getConstructor(NO_CLASSES);

      getHTMLDocumentMethod =
          htmlBuilderClass.getMethod("getHTMLDocument", NO_CLASSES);

      Class htmlDOMImpl =
          classLoader.loadClass(
          "org.apache.html2.dom.HTMLDOMImplementationImpl");
      Method method =
          htmlDOMImpl.getMethod("getHTMLDOMImplementation", NO_CLASSES);
      domImpl = (DOMImplementation) method.invoke(null, NO_OBJECTS);

      Class saxFactoryClass =
          classLoader.loadClass(
          "org.apache.xerces.jaxp.SAXParserFactoryImpl");
      factory = (SAXParserFactory) saxFactoryClass.newInstance();
    }
    catch (InvocationTargetException ex) {
      throw new DOMTestIncompatibleException(
          ex.getTargetException(),
          null);
    }
    catch (Exception ex) {
      throw new DOMTestIncompatibleException(ex, null);
    }

    //
    //    apply settings to selected document builder
    //         may throw exception if incompatible
    if (settings != null) {
      for (int i = 0; i < settings.length; i++) {
        //        settings[i].applySetting(factory);
      }
    }
    try {
      factory.newSAXParser();
    }
    catch (ParserConfigurationException ex) {
      throw new DOMTestIncompatibleException(ex, null);
    }
    catch (SAXException ex) {
      throw new DOMTestIncompatibleException(ex, null);
    }
  
Methods Summary
public static DocumentBuilderSetting[]getConfiguration1()

    return new DocumentBuilderSetting[] {
        DocumentBuilderSetting.notCoalescing,
        DocumentBuilderSetting.notExpandEntityReferences,
        DocumentBuilderSetting.notIgnoringElementContentWhitespace,
        DocumentBuilderSetting.notNamespaceAware,
        DocumentBuilderSetting.notValidating};
  
public static DocumentBuilderSetting[]getConfiguration2()

    return new DocumentBuilderSetting[] {
        DocumentBuilderSetting.notCoalescing,
        DocumentBuilderSetting.expandEntityReferences,
        DocumentBuilderSetting.ignoringElementContentWhitespace,
        DocumentBuilderSetting.namespaceAware,
        DocumentBuilderSetting.validating};

  
public org.w3c.dom.DOMImplementationgetDOMImplementation()

    return domImpl;
  
public booleanhasFeature(java.lang.String feature, java.lang.String version)

    return domImpl.hasFeature(feature, version);
  
public booleanisCoalescing()

    return false;
  
public booleanisExpandEntityReferences()

    return false;
  
public booleanisIgnoringElementContentWhitespace()

    return false;
  
public booleanisNamespaceAware()

    return factory.isNamespaceAware();
  
public booleanisValidating()

    return factory.isValidating();
  
public org.w3c.dom.Documentload(java.net.URL url)

    Document doc = null;
    try {
      SAXParser parser = factory.newSAXParser();
      HTMLHandler handler =
          new HTMLHandler(htmlBuilderConstructor, getHTMLDocumentMethod);
      parser.parse(url.toString(), handler);
      doc = handler.getHTMLDocument();
    }
    catch (Exception ex) {
      throw new DOMTestLoadException(ex);
    }
    return doc;
  
public DOMTestDocumentBuilderFactorynewInstance(DocumentBuilderSetting[] newSettings)

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