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

JTidyDocumentBuilderFactory

public class JTidyDocumentBuilderFactory extends DOMTestDocumentBuilderFactory
This class implements the generic parser builder for JTidy (http://sf.net/projects/JTidy) which reads HTML and supports the fundamental DOM interfaces but not either HTML L1 DOM or HTML L2 DOM

Fields Summary
private final Constructor
tidyConstructor
private final Method
parseDOMMethod
private final DOMImplementation
domImpl
private static final Class[]
NO_CLASSES
private static final Object[]
NO_OBJECTS
Constructors Summary
public JTidyDocumentBuilderFactory(DocumentBuilderSetting[] settings)
Creates a implementation of DOMTestDocumentBuilderFactory using JTidy's HTML parser and DOM implementation

param
settings array of settings, may be null.


                         
   
          
    super(settings);

    try {
      ClassLoader classLoader = ClassLoader.getSystemClassLoader();
      Class tidyClass = classLoader.loadClass("org.w3c.tidy.Tidy");

      tidyConstructor =
          tidyClass.getConstructor(NO_CLASSES);

      parseDOMMethod =
          tidyClass.getMethod("parseDOM",
                              new Class[] {java.io.InputStream.class,
                              java.io.OutputStream.class});

      //
      //  JTidy doesn't implement DOMImplementation so
      //    we will do it here
      domImpl = new JTidyDOMImplementation();

    }
    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);
      }
    }
  
Methods Summary
public java.lang.StringgetContentType()

    return "text/html";
  
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 false;
  
public booleanisValidating()

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

    Document doc = null;
    try {
      java.io.InputStream stream = url.openStream();
      Object tidyObj = tidyConstructor.newInstance(new Object[0]);
      doc = (Document) parseDOMMethod.invoke(tidyObj,
                                             new Object[] {stream, null});
    }
    catch (InvocationTargetException ex) {
      throw new DOMTestLoadException(ex.getTargetException());
    }
    catch (Exception ex) {
      throw new DOMTestLoadException(ex);
    }
    return doc;
  
public DOMTestDocumentBuilderFactorynewInstance(DocumentBuilderSetting[] newSettings)

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