nekohtml-1.9.14

.NamespaceContext;
import org.apache.xerces.xni.QName;
import org.apache.xerces.xni.XMLAttributes;
import org.apache.xerces.xni.XMLLocator;
import org.apache.xerces.xni.XMLString;
import org.apache.xerces.xni.XNIException;
import org.apache.xerces.xni.parser.XMLComponentManager;
import org.apache.xerces.xni.parser.XMLConfigurationException;
import org.cyberneko.html.HTMLAugmentations;
import org.cyberneko.html.HTMLEventInfo;
import org.cyberneko.html.HTMLEventInfo.SynthesizedItem;
import org.cyberneko.html.xercesbridge.XercesBridge;

public class Purifier
  extends DefaultFilter
{
  public static final String SYNTHESIZED_NAMESPACE_PREFX = "http://cyberneko.org/html/ns/synthesized/";
  protected static final String NAMESPACES = "http://xml.org/sax/features/namespaces";
  protected static final String AUGMENTATIONS = "http://cyberneko.org/html/features/augmentations";
  private static final String[] RECOGNIZED_FEATURES = { "http://xml.org/sax/features/namespaces", "http://cyberneko.org/html/features/augmentations" };
  protected static final HTMLEventInfo SYNTHESIZED_ITEM = new HTMLEventInfo.SynthesizedItem();
  protected boolean fNamespaces;
  protected boolean fAugmentations;
  protected boolean fSeenDoctype;
  protected boolean fSeenRootElement;
  protected boolean fInCDATASection;
  protected String fPublicId;
  protected String fSystemId;
  protected NamespaceContext fNamespaceContext;
  protected int fSynthesizedNamespaceCount;
  private QName fQName = new QName();
  private final HTMLAugmentations fInfosetAugs = new HTMLAugmentations();
  private final XMLStringBuffer fStringBuffer = new XMLStringBuffer();
  
  public void reset(XMLComponentManager manager)
    throws XMLConfigurationException
  {
    fInCDATASection = false;
    
    fNamespaces = manager.getFeature("http://xml.org/sax/features/namespaces");
    fAugmentations = manager.getFeature("http://cyberneko.org/html/features/augmentations");
  }
  
  public void startDocument(XMLLocator locator, String encoding, Augmentations augs)
    throws XNIException
  {
    fNamespaceContext = (fNamespaces ? new NamespaceBinder.NamespaceSupport() : null);
    
    fSynthesizedNamespaceCount = 0;
    handleStartDocument();
    super.startDocument(locator, encoding, augs);
  }
  
  public void startDocument(XMLLocator locator, String encoding, NamespaceContext nscontext, Augmentations augs)
    throws XNIException
  {
    fNamespaceContext = nscontext;
    fSynthesizedNamespaceCount = 0;
    handleStartDocument();
    super.startDocument(locator, encoding, nscontext, augs);
  }
  
  public void xmlDecl(String version, String encoding, String standalone, Augmentations augs)
    throws XNIException
  {
    if ((version == null) || (!version.equals("1.0"))) {
      version = "1.0";
    }
    if ((encoding != null) && (encoding.length() == 0)) {
      encoding = null;
    }
    if (standalone != null) {
      if ((!standalone.equalsIgnoreCase("true")) && (!standalone.equalsIgnoreCase("false"))) {
        standalone = null;
      } else {
        standalone = standalone.toLowerCase();
      }
    }
    super.xmlDecl(version, encoding, standalone, augs);
  }
  
  public void comment(XMLString text, Augmentations augs)
    throws XNIException
  {
    StringBuffer str = new StringBuffer(purifyText(text).toString());
    int length = str.length();
    for (int i = length - 1; i >= 0; i--)
    {
      char c = str.charAt(i);
      if (c == '-') {
        str.insert(i + 1, ' ');
      }
    }
    fStringBuffer.length = 0;
    fStringBuffer.append(str.toString());
    text = fStringBuffer;
    super.comment(text, augs);
  }
  
  public void processingInstruction(String target, XMLString data, Augmentations augs)
    throws XNIException
  {
    target = purifyName(target, true);
    data = purifyText(data);
    super.processingInstruction(target, data, augs);
  }
  
  public void doctypeDecl(String root, String pubid, String sysid, Augmentations augs)
    throws XNIException
  {
    fSeenDoctype = true;
    
    fPublicId = pubid;
    fSystemId = sysid;
    if ((fPublicId != null) && (fSystemId == null)) {
      fSystemId = "";
    }
  }
  
  public void startElement(QName element, XMLAttributes attrs, Augmentations augs)
    throws XNIException
  {
    handleStartElement(element, attrs);
    super.startElement(element, attrs, augs);
  }
  
  public void emptyElement(QName element, XMLAttributes attrs, Augmentations augs)
    throws XNIException
  {
    handleStartElement(element, attrs);
    super.emptyElement(element, attrs, augs);
  }
  
  public void startCDATA(Augmentations augs)
    throws XNIException
  {
    fInCDATASection = true;
    super.startCDATA(augs);
  }
  
  public void endCDATA(Augmentations augs)
    throws XNIException
  {
    fInCDATASection = false;
    super.endCDATA(augs);
  }
  
  public void characters(XMLString text, Augmentations augs)
    throws XNIException
  {
    text = purifyText(text);
    if (fInCDATASection)
    {
      StringBuffer str = new StringBuffer(text.toString());
      int length = str.length();
      for (int i = length - 1; i >= 0; i--)
      {
        char c = str.charAt(i);
        if (c == ']') {
          str.insert(i + 1, ' ');
        }
      }
      fStringBuffer.length = 0;
      fStringBuffer.append(str.toString());
      text = fStringBuffer;
    }
    super.characters(text, augs);
  }
  
  public void endElement(QName element, Augmentations augs)
    throws XNIException
  {
    element = purifyQName(element);
    if ((fNamespaces) && 
      (prefix != null) && (uri == null)) {
      uri = fNamespaceContext.getURI(prefix);
    }
    super.endElement(element, augs);
  }
  
  protected void handleStartDocument()
  {
    fSeenDoctype = false;
    fSeenRootElement = false;
  }
  
  protected void handleStartElement(QName element, XMLAttributes attrs)
  {
    element = purifyQName(element);
    int attrCount = attrs != null ? attrs.getLength() : 0;
    for (int i = attrCount - 1; i >= 0; i--)
    {
      attrs.getName(i, fQName);
      attrs.setName(i, purifyQName(fQName));
      if ((fNamespaces) && 
        (!fQName.rawname.equals("xmlns")) && (!fQName.rawname.startsWith("xmlns:")))
      {
        attrs.getName(i, fQName);
        if ((fQName.prefix != null) && (fQName.uri == null)) {
          synthesizeBinding(attrs, fQName.prefix);
        }
      }
    }
    if ((fNamespaces) && 
      (prefix != null) && (uri == null)) {
      synthesizeBinding(attrs, prefix);
    }
    if ((!fSeenRootElement) && (fSeenDoctype))
    {
      Augmentations augs = synthesizedAugs();
      super.doctypeDecl(rawname, fPublicId, fSystemId, augs);
    }
    fSeenRootElement = true;
  }
  
  protected void synthesizeBinding(XMLAttributes attrs, String ns)
  {
    String prefix = "xmlns";
    String localpart = ns;
    String qname = prefix + ':' + localpart;
    String uri = "http://cyberneko.org/html/properties/namespaces-uri";
    String atype = "CDATA";
    String avalue = "http://cyberneko.org/html/ns/synthesized/" + fSynthesizedNamespaceCount++;
    
    fQName.setValues(prefix, localpart, qname, uri);
    attrs.addAttribute(fQName, atype, avalue);
    
    XercesBridge.getInstance().NamespaceContext_declarePrefix(fNamespaceContext, ns, avalue);
  }
  
  protected final Augmentations synthesizedAugs()
  {
    HTMLAugmentations augs = null;
    if (fAugmentations)
    {
      augs = fInfosetAugs;
      augs.removeAllItems();
      augs.putItem("http://cyberneko.org/html/features/augmentations", SYNTHESIZED_ITEM);
    }
    return augs;
  }
  
  protected QName purifyQName(QName qname)
  {
    prefix = purifyName(prefix, true);
    localpart = purifyName(localpart, true);
    rawname = purifyName(rawname, false);
    return qname;
  }
  
  protected String purifyName(String name, boolean localpart)
  {
    if (name == null) {
      return name;
    }
    StringBuffer str = new StringBuffer();
    int length = name.length();
    boolean seenColon = localpart;
    for (int i = 0; i < length; i++)
    {
      char c = name.charAt(i);
      if (i == 0)
      {
        if (!XMLChar.isNameStart(c)) {
          str.append("_u" + toHexString(c, 4) + "_");
        } else {
          str.append(c);
        }
      }
      else
      {
        if (((fNamespaces) && (c == ':') && (seenColon)) || (!XMLChar.isName(c))) {
          str.append("_u" + toHexString(c, 4) + "_");
        } else {
          str.append(c);
        }
        seenColon = (seenColon) || (c == ':');
      }
    }
    return str.toString();
  }
  
  protected XMLString purifyText(XMLString text)
  {
    fStringBuffer.length = 0;
    for (int i = 0; i < length; i++)
    {
      char c = ch[(offset + i)];
      if (XMLChar.isInvalid(c)) {
        fStringBuffer.append("\\u" + toHexString(c, 4));
      } else {
        fStringBuffer.append(c);
      }
    }
    return fStringBuffer;
  }
  
  protected static String toHexString(int c, int padlen)
  {
    StringBuffer str = new StringBuffer(padlen);
    str.append(Integer.toHexString(c));
    int len = padlen - str.length();
    for (int i = 0; i < len; i++) {
      str.insert(0, '0');
    }
    return str.toString().toUpperCase();
  }
}

/* Location:
 * Qualified Name:     org.cyberneko.html.filters.Purifier
 * Java Class Version: 1.3 (47.0)
 * JD-Core Version:    0.7.1
 */
package org.cyberneko.html.filters;

import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.util.Vector;
import org.apache.xerces.xni.Augmentations;
import org.apache.xerces.xni.NamespaceContext;
import org.apache.xerces.xni.QName;
import org.apache.xerces.xni.XMLAttributes;
import org.apache.xerces.xni.XMLLocator;
import org.apache.xerces.xni.XMLResourceIdentifier;
import org.apache.xerces.xni.XMLString;
import org.apache.xerces.xni.XNIException;
import org.apache.xerces.xni.parser.XMLDocumentFilter;
import org.apache.xerces.xni.parser.XMLInputSource;
import org.apache.xerces.xni.parser.XMLParserConfiguration;
import org.cyberneko.html.HTMLConfiguration;
import org.cyberneko.html.HTMLElements;
import org.cyberneko.html.HTMLElements.Element;
import org.cyberneko.html.HTMLEntities;

public class Writer
  extends DefaultFilter
{
  public static final String NOTIFY_CHAR_REFS = "http://apache.org/xml/features/scanner/notify-char-refs";
  public static final String NOTIFY_HTML_BUILTIN_REFS = "http://cyberneko.org/html/features/scanner/notify-builtin-refs";
  protected static final String AUGMENTATIONS = "http://cyberneko.org/html/features/augmentations";
  protected static final String FILTERS = "http://cyberneko.org/html/properties/filters";
  protected String fEncoding;
  protected PrintWriter fPrinter;
  protected boolean fSeenRootElement;
  protected boolean fSeenHttpEquiv;
  protected int fElementDepth;
  protected boolean fNormalize;
  protected boolean fPrintChars;
  
  public Writer()
  {
    try
    {
      fEncoding = "UTF-8";
      fPrinter = new PrintWriter(new OutputStreamWriter(System.out, fEncoding));
    }
    catch (UnsupportedEncodingException e)
    {
      throw new RuntimeException(e.getMessage());
    }
  }
  
  public Writer(OutputStream outputStream, String encoding)
    throws UnsupportedEncodingException
  {
    this(new OutputStreamWriter(outputStream, encoding), encoding);
  }
  
  public Writer(java.io.Writer writer, String encoding)
  {
    fEncoding = encoding;
    if ((writer instanceof PrintWriter)) {
      fPrinter = ((PrintWriter)writer);
    } else {
      fPrinter = new PrintWriter(writer);
    }
  }
  
  public void startDocument(XMLLocator locator, String encoding, NamespaceContext nscontext, Augmentations augs)
    throws XNIException
  {
    fSeenRootElement = false;
    fSeenHttpEquiv = false;
    fElementDepth = 0;
    fNormalize = true;
    fPrintChars = true;
    super.startDocument(locator, encoding, nscontext, augs);
  }
  
  public void startDocument(XMLLocator locator, String encoding, Augmentations augs)
    throws XNIException
  {
    startDocument(locator, encoding, null, augs);
  }
  
  public void comment(XMLString text, Augmentations augs)
    throws XNIException
  {
    if ((fSeenRootElement) && (fElementDepth <= 0)) {
      fPrinter.println();
    }
    fPrinter.print("<!--");
    printCharacters(text, false);
    fPrinter.print("-->");
    if (!fSeenRootElement) {
      fPrinter.println();
    }
    fPrinter.flush();
  }
  
  public void startElement(QName element, XMLAttributes attributes, Augmentations augs)
    throws XNIException
  {
    fSeenRootElement = true;
    fElementDepth += 1;
    fNormalize = (!HTMLElements.getElement(rawname).isSpecial());
    printStartElement(element, attributes);
    super.startElement(element, attributes, augs);
  }
  
  public void emptyElement(QName element, XMLAttributes attributes, Augmentations augs)
    throws XNIException
  {
    fSeenRootElement = true;
    printStartElement(element, attributes);
    super.emptyElement(element, attributes, augs);
  }
  
  public void characters(XMLString text, Augmentations augs)
    throws XNIException
  {
    if (fPrintChars) {
      printCharacters(text, fNormalize);
    }
    super.characters(text, augs);
  }
  
  public void endElement(QName element, Augmentations augs)
    throws XNIException
  {
    fElementDepth -= 1;
    fNormalize = true;
    
    printEndElement(element);
    super.endElement(element, augs);
  }
  
  public void startGeneralEntity(String name, XMLResourceIdentifier id, String encoding, Augmentations augs)
    throws XNIException
  {
    fPrintChars = false;
    if (name.startsWith("#")) {
      try
      {
        boolean hex = name.startsWith("#x");
        int offset = hex ? 2 : 1;
        int base = hex ? 16 : 10;
        int value = Integer.parseInt(name.substring(offset), base);
        String entity = HTMLEntities.get(value);
        if (entity != null) {
          name = entity;
        }
      }
      catch (NumberFormatException e) {}
    }
    printEntity(name);
    super.startGeneralEntity(name, id, encoding, augs);
  }
  
  public void endGeneralEntity(String name, Augmentations augs)
    throws XNIException
  {
    fPrintChars = true;
    super.endGeneralEntity(name, augs);
  }
  
  protected void printAttributeValue(String text)
  {
    int length = text.length();
    for (int j = 0; j < length; j++)
    {
      char c = text.charAt(j);
      if (c == '"') {
        fPrinter.print("&quot;");
      } else {
        fPrinter.print(c);
      }
    }
    fPrinter.flush();
  }
  
  protected void printCharacters(XMLString text, boolean normalize)
  {
    if (normalize) {
      for (int i = 0; i < length; i++)
      {
        char c = ch[(offset + i)];
        if (c != '\n')
        {
          String entity = HTMLEntities.get(c);
          if (entity != null) {
            printEntity(entity);
          } else {
            fPrinter.print(c);
          }
        }
        else
        {
          fPrinter.println();
        }
      }
    } else {
      for (int i = 0; i < length; i++)
      {
        char c = ch[(offset + i)];
        fPrinter.print(c);
      }
    }
    fPrinter.flush();
  }
  
  protected void printStartElement(QName element, XMLAttributes attributes)
  {
    int contentIndex = -1;
    String originalContent = null;
    if (rawname.toLowerCase().equals("meta"))
    {
      String httpEquiv = null;
      int length = attributes.getLength();
      for (int i = 0; i < length; i++)
      {
        String aname = attributes.getQName(i).toLowerCase();
        if (aname.equals("http-equiv")) {
          httpEquiv = attributes.getValue(i);
        } else if (aname.equals("content")) {
          contentIndex = i;
        }
      }
      if ((httpEquiv != null) && (httpEquiv.toLowerCase().equals("content-type")))
      {
        fSeenHttpEquiv = true;
        String content = null;
        if (contentIndex != -1)
        {
          originalContent = attributes.getValue(contentIndex);
          content = originalContent.toLowerCase();
        }
        if (content != null)
        {
          int charsetIndex = content.indexOf("charset=");
          if (charsetIndex != -1) {
            content = content.substring(0, charsetIndex + 8);
          } else {
            content = content + ";charset=";
          }
          content = content + fEncoding;
          attributes.setValue(contentIndex, content);
        }
      }
    }
    fPrinter.print('<');
    fPrinter.print(rawname);
    int attrCount = attributes != null ? attributes.getLength() : 0;
    for (int i = 0; i < attrCount; i++)
    {
      String aname = attributes.getQName(i);
      String avalue = attributes.getValue(i);
      fPrinter.print(' ');
      fPrinter.print(aname);
      fPrinter.print("=\"");
      printAttributeValue(avalue);
      fPrinter.print('"');
    }
    fPrinter.print('>');
    fPrinter.flush();
    if ((contentIndex != -1) && (originalContent != null)) {
      attributes.setValue(contentIndex, originalContent);
    }
  }
  
  protected void printEndElement(QName element)
  {
    fPrinter.print("</");
    fPrinter.print(rawname);
    fPrinter.print('>');
    fPrinter.flush();
  }
  
  protected void printEntity(String name)
  {
    fPrinter.print('&');
    fPrinter.print(name);
    fPrinter.print(';');
    fPrinter.flush();
  }
  
  public static void main(String[] argv)
    throws Exception
  {
    if (argv.length == 0)
    {
      printUsage();
      System.exit(1);
    }
    XMLParserConfiguration parser = new HTMLConfiguration();
    parser.setFeature("http://apache.org/xml/features/scanner/notify-char-refs", true);
    parser.setFeature("http://cyberneko.org/html/features/scanner/notify-builtin-refs", true);
    String iencoding = null;
    String oencoding = "Windows-1252";
    boolean identity = false;
    boolean purify = false;
    for (int i = 0; i < argv.length; i++)
    {
      String arg = argv[i];
      if (arg.equals("-ie"))
      {
        iencoding = argv[(++i)];
      }
      else if ((arg.equals("-e")) || (arg.equals("-oe")))
      {
        oencoding = argv[(++i)];
      }
      else if (arg.equals("-i"))
      {
        identity = true;
      }
      else if (arg.equals("-p"))
      {
        purify = true;
      }
      else
      {
        if (arg.equals("-h"))
        {
          printUsage();
          System.exit(1);
        }
        Vector filtersVector = new Vector(2);
        if (identity) {
          filtersVector.addElement(new Identity());
        } else if (purify) {
          filtersVector.addElement(new Purifier());
        }
        filtersVector.addElement(new Writer(System.out, oencoding));
        XMLDocumentFilter[] filters = new XMLDocumentFilter[filtersVector.size()];
        
        filtersVector.copyInto(filters);
        parser.setProperty("http://cyberneko.org/html/properties/filters", filters);
        XMLInputSource source = new XMLInputSource(null, arg, null);
        source.setEncoding(iencoding);
        parser.parse(source);
      }
    }
  }
  
  private static void printUsage()
  {
    System.err.println("usage: java " + Writer.class.getName() + " (options) file ...");
    System.err.println();
    System.err.println("options:");
    System.err.println("  -ie name  Specify IANA name of input encoding.");
    System.err.println("  -oe name  Specify IANA name of output encoding.");
    System.err.println("  -i        Perform identity transform.");
    System.err.println("  -p        Purify output to ensure XML well-formedness.");
    System.err.println("  -h        Display help screen.");
    System.err.println();
    System.err.println("notes:");
    System.err.println("  The -i and -p options are mutually exclusive.");
    System.err.println("  The -e option has been replaced with -oe.");
  }
}

/* Location:
 * Qualified Name:     org.cyberneko.html.filters.Writer
 * Java Class Version: 1.3 (47.0)
 * JD-Core Version:    0.7.1
 */
package org.cyberneko.html.parsers;

import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import org.apache.xerces.util.ErrorHandlerWrapper;
import org.apache.xerces.util.XMLChar;
import org.apache.xerces.xni.Augmentations;
import org.apache.xerces.xni.NamespaceContext;
import org.apache.xerces.xni.QName;
import org.apache.xerces.xni.XMLAttributes;
import org.apache.xerces.xni.XMLDocumentHandler;
import org.apache.xerces.xni.XMLLocator;
import org.apache.xerces.xni.XMLResourceIdentifier;
import org.apache.xerces.xni.XMLString;
import org.apache.xerces.xni.XNIException;
import org.apache.xerces.xni.parser.XMLConfigurationException;
import org.apache.xerces.xni.parser.XMLDocumentSource;
import org.apache.xerces.xni.parser.XMLErrorHandler;
import org.apache.xerces.xni.parser.XMLInputSource;
import org.apache.xerces.xni.parser.XMLParseException;
import org.apache.xerces.xni.parser.XMLParserConfiguration;
import org.cyberneko.html.HTMLConfiguration;
import org.w3c.dom.CDATASection;
import org.w3c.dom.Comment;
import org.w3c.dom.Document;
import org.w3c.dom.DocumentFragment;
import org.w3c.dom.Element;
import org.w3c.dom.EntityReference;
import org.w3c.dom.Node;
import org.w3c.dom.ProcessingInstruction;
import org.w3c.dom.Text;
import org.xml.sax.ErrorHandler;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.SAXNotRecognizedException;
import org.xml.sax.SAXNotSupportedException;
import org.xml.sax.SAXParseException;

public class DOMFragmentParser
  implements XMLDocumentHandler
{
  protected static final String DOCUMENT_FRAGMENT = "http://cyberneko.org/html/features/document-fragment";
  protected static final String[] RECOGNIZED_FEATURES = { "http://cyberneko.org/html/features/document-fragment" };
  protected static final String ERROR_HANDLER = "http://apache.org/xml/properties/internal/error-handler";
  protected static final String CURRENT_ELEMENT_NODE = "http://apache.org/xml/properties/dom/current-element-node";
  protected static final String[] RECOGNIZED_PROPERTIES = { "http://apache.org/xml/properties/internal/error-handler", "http://apache.org/xml/properties/dom/current-element-node" };
  protected XMLParserConfiguration fParserConfiguration;
  protected XMLDocumentSource fDocumentSource;
  protected DocumentFragment fDocumentFragment;
  protected Document fDocument;
  protected Node fCurrentNode;
  protected boolean fInCDATASection;
  
  public DOMFragmentParser()
  {
    fParserConfiguration = new HTMLConfiguration();
    fParserConfiguration.addRecognizedFeatures(RECOGNIZED_FEATURES);
    fParserConfiguration.addRecognizedProperties(RECOGNIZED_PROPERTIES);
    fParserConfiguration.setFeature("http://cyberneko.org/html/features/document-fragment", true);
    fParserConfiguration.setDocumentHandler(this);
  }
  
  public void parse(String systemId, DocumentFragment fragment)
    throws SAXException, IOException
  {
    parse(new InputSource(systemId), fragment);
  }
  
  public void parse(InputSource source, DocumentFragment fragment)
    throws SAXException, IOException
  {
    fCurrentNode = (fDocumentFragment = fragment);
    fDocument = fDocumentFragment.getOwnerDocument();
    try
    {
      String pubid = source.getPublicId();
      String sysid = source.getSystemId();
      String encoding = source.getEncoding();
      InputStream stream = source.getByteStream();
      Reader reader = source.getCharacterStream();
      
      XMLInputSource inputSource = new XMLInputSource(pubid, sysid, sysid);
      
      inputSource.setEncoding(encoding);
      inputSource.setByteStream(stream);
      inputSource.setCharacterStream(reader);
      
      fParserConfiguration.parse(inputSource);
    }
    catch (XMLParseException e)
    {
      Exception ex = e.getException();
      if (ex != null) {
        throw new SAXParseException(e.getMessage(), null, ex);
      }
      throw new SAXParseException(e.getMessage(), null);
    }
  }
  
  public void setErrorHandler(ErrorHandler errorHandler)
  {
    fParserConfiguration.setErrorHandler(new ErrorHandlerWrapper(errorHandler));
  }
  
  public ErrorHandler getErrorHandler()
  {
    ErrorHandler errorHandler = null;
    try
    {
      XMLErrorHandler xmlErrorHandler = (XMLErrorHandler)fParserConfiguration.getProperty("http://apache.org/xml/properties/internal/error-handler");
      if ((xmlErrorHandler != null) && ((xmlErrorHandler instanceof ErrorHandlerWrapper))) {
        errorHandler = ((ErrorHandlerWrapper)xmlErrorHandler).getErrorHandler();
      }
    }
    catch (XMLConfigurationException e) {}
    return errorHandler;
  }
  
  public void setFeature(String featureId, boolean state)
    throws SAXNotRecognizedException, SAXNotSupportedException
  {
    try
    {
      fParserConfiguration.setFeature(featureId, state);
    }
    catch (XMLConfigurationException e)
    {
      String message = e.getMessage();
      if (e.getType() == 0) {
        throw new SAXNotRecognizedException(message);
      }
      throw new SAXNotSupportedException(message);
    }
  }
  
  public boolean getFeature(String featureId)
    throws SAXNotRecognizedException, SAXNotSupportedException
  {
    try
    {
      return fParserConfiguration.getFeature(featureId);
    }
    catch (XMLConfigurationException e)
    {
      String message = e.getMessage();
      if (e.getType() == 0) {
        throw new SAXNotRecognizedException(message);
      }
      throw new SAXNotSupportedException(message);
    }
  }
  
  public void setProperty(String propertyId, Object value)
    throws SAXNotRecognizedException, SAXNotSupportedException
  {
    try
    {
      fParserConfiguration.setProperty(propertyId, value);
    }
    catch (XMLConfigurationException e)
    {
      String message = e.getMessage();
      if (e.getType() == 0) {
        throw new SAXNotRecognizedException(message);
      }
      throw new SAXNotSupportedException(message);
    }
  }
  
  public Object getProperty(String propertyId)
    throws SAXNotRecognizedException, SAXNotSupportedException
  {
    if (propertyId.equals("http://apache.org/xml/properties/dom/current-element-node")) {
      return (fCurrentNode != null) && (fCurrentNode.getNodeType() == 1) ? fCurrentNode : null;
    }
    try
    {
      return fParserConfiguration.getProperty(propertyId);
    }
    catch (XMLConfigurationException e)
    {
      String message = e.getMessage();
      if (e.getType() == 0) {
        throw new SAXNotRecognizedException(message);
      }
      throw new SAXNotSupportedException(message);
    }
  }
  
  public void setDocumentSource(XMLDocumentSource source)
  {
    fDocumentSource = source;
  }
  
  public XMLDocumentSource getDocumentSource()
  {
    return fDocumentSource;
  }
  
  public void startDocument(XMLLocator locator, String encoding, Augmentations augs)
    throws XNIException
  {
    startDocument(locator, encoding, null, augs);
  }
  
  public void startDocument(XMLLocator locator, String encoding, NamespaceContext nscontext, Augmentations augs)
    throws XNIException
  {
    fInCDATASection = false;
  }
  
  public void xmlDecl(String version, String encoding, String standalone, Augmentations augs)
    throws XNIException
  {}
  
  public void doctypeDecl(String root, String pubid, String sysid, Augmentations augs)
    throws XNIException
  {}
  
  public void processingInstruction(String target, XMLString data, Augmentations augs)
    throws XNIException
  {
    String s = data.toString();
    if (XMLChar.isValidName(s))
    {
      ProcessingInstruction pi = fDocument.createProcessingInstruction(target, s);
      fCurrentNode.appendChild(pi);
    }
  }
  
  public void comment(XMLString text, Augmentations augs)
    throws XNIException
  {
    Comment comment = fDocument.createComment(text.toString());
    fCurrentNode.appendChild(comment);
  }
  
  public void startPrefixMapping(String prefix, String uri, Augmentations augs)
    throws XNIException
  {}
  
  public void endPrefixMapping(String prefix, Augmentations augs)
    throws XNIException
  {}
  
  public void startElement(QName element, XMLAttributes attrs, Augmentations augs)
    throws XNIException
  {
    Element elementNode = fDocument.createElement(rawname);
    int count = attrs != null ? attrs.getLength() : 0;
    for (int i = 0; i < count; i++)
    {
      String aname = attrs.getQName(i);
      String avalue = attrs.getValue(i);
      if (XMLChar.isValidName(aname)) {
        elementNode.setAttribute(aname, avalue);
      }
    }
    fCurrentNode.appendChild(elementNode);
    fCurrentNode = elementNode;
  }
  
  public void emptyElement(QName element, XMLAttributes attrs, Augmentations augs)
    throws XNIException
  {
    startElement(element, attrs, augs);
    endElement(element, augs);
  }
  
  public void characters(XMLString text, Augmentations augs)
    throws XNIException
  {
    if (fInCDATASection)
    {
      Node node = fCurrentNode.getLastChild();
      if ((node != null) && (node.getNodeType() == 4))
      {
        CDATASection cdata = (CDATASection)node;
        cdata.appendData(text.toString());
      }
      else
      {
        CDATASection cdata = fDocument.createCDATASection(text.toString());
        fCurrentNode.appendChild(cdata);
      }
    }
    else
    {
      Node node = fCurrentNode.getLastChild();
      if ((node != null) && (node.getNodeType() == 3))
      {
        Text textNode = (Text)node;
        textNode.appendData(text.toString());
      }
      else
      {
        Text textNode = fDocument.createTextNode(text.toString());
        fCurrentNode.appendChild(textNode);
      }
    }
  }
  
  public void ignorableWhitespace(XMLString text, Augmentations augs)
    throws XNIException
  {
    characters(text, augs);
  }
  
  public void startGeneralEntity(String name, XMLResourceIdentifier id, String encoding, Augmentations augs)
    throws XNIException
  {
    EntityReference entityRef = fDocument.createEntityReference(name);
    fCurrentNode.appendChild(entityRef);
    fCurrentNode = entityRef;
  }
  
  public void textDecl(String version, String encoding, Augmentations augs)
    throws XNIException
  {}
  
  public void endGeneralEntity(String name, Augmentations augs)
    throws XNIException
  {
    fCurrentNode = fCurrentNode.getParentNode();
  }
  
  public void startCDATA(Augmentations augs)
    throws XNIException
  {
    fInCDATASection = true;
  }
  
  public void endCDATA(Augmentations augs)
    throws XNIException
  {
    fInCDATASection = false;
  }
  
  public void endElement(QName element, Augmentations augs)
    throws XNIException
  {
    fCurrentNode = fCurrentNode.getParentNode();
  }
  
  public void endDocument(Augmentations augs)
    throws XNIException
  {}
}

/* Location:
 * Qualified Name:     org.cyberneko.html.parsers.DOMFragmentParser
 * Java Class Version: 1.3 (47.0)
 * JD-Core Version:    0.7.1
 */
package org.cyberneko.html.parsers;

import org.apache.xerces.xni.Augmentations;
import org.apache.xerces.xni.XNIException;
import org.cyberneko.html.HTMLConfiguration;
import org.cyberneko.html.xercesbridge.XercesBridge;
import org.xml.sax.SAXNotRecognizedException;
import org.xml.sax.SAXNotSupportedException;

public class DOMParser
  extends org.apache.xerces.parsers.DOMParser
{
  public DOMParser()
  {
    super(new HTMLConfiguration());
    try
    {
      setProperty("http://apache.org/xml/properties/dom/document-class-name", "org.apache.html.dom.HTMLDocumentImpl");
    }
    catch (SAXNotRecognizedException e)
    {
      throw new RuntimeException("http://apache.org/xml/properties/dom/document-class-name property not recognized");
    }
    catch (SAXNotSupportedException e)
    {
      throw new RuntimeException("http://apache.org/xml/properties/dom/document-class-name property not supported");
    }
  }
  
  public void doctypeDecl(String root, String pubid, String sysid, Augmentations augs)
    throws XNIException
  {
    String VERSION = XercesBridge.getInstance().getVersion();
    boolean okay = true;
    if (VERSION.startsWith("Xerces-J 2.")) {
      okay = getParserSubVersion() > 5;
    } else if (VERSION.startsWith("XML4J")) {
      okay = false;
    }
    if (okay) {
      super.doctypeDecl(root, pubid, sysid, augs);
    }
  }
  
  private static int getParserSubVersion()
  {
    try
    {
      String VERSION = XercesBridge.getInstance().getVersion();
      int index1 = VERSION.indexOf('.') + 1;
      int index2 = VERSION.indexOf('.', index1);
      if (index2 == -1) {
        index2 = VERSION.length();
      }
      return Integer.parseInt(VERSION.substring(index1, index2));
    }
    catch (Exception e) {}
    return -1;
  }
}

/* Location:
 * Qualified Name:     org.cyberneko.html.parsers.DOMParser
 * Java Class Version: 1.3 (47.0)
 * JD-Core Version:    0.7.1
 */
package org.cyberneko.html.parsers;

import org.apache.xerces.parsers.AbstractSAXParser;
import org.cyberneko.html.HTMLConfiguration;

public class SAXParser
  extends AbstractSAXParser
{
  public SAXParser()
  {
    super(new HTMLConfiguration());
  }
}

/* Location:
 * Qualified Name:     org.cyberneko.html.parsers.SAXParser
 * Java Class Version: 1.3 (47.0)
 * JD-Core Version:    0.7.1
 */
package org.cyberneko.html.xercesbridge;

import org.apache.xerces.xni.Augmentations;
import org.apache.xerces.xni.NamespaceContext;
import org.apache.xerces.xni.XMLDocumentHandler;
import org.apache.xerces.xni.XMLLocator;
import org.apache.xerces.xni.parser.XMLDocumentFilter;
import org.apache.xerces.xni.parser.XMLDocumentSource;

public abstract class XercesBridge
{
  private static final XercesBridge instance = ;
  
  public static XercesBridge getInstance()
  {
    return instance;
  }
  
  private static XercesBridge makeInstance()
  {
    String[] classNames = { "org.cyberneko.html.xercesbridge.XercesBridge_2_3", "org.cyberneko.html.xercesbridge.XercesBridge_2_2", "org.cyberneko.html.xercesbridge.XercesBridge_2_1", "org.cyberneko.html.xercesbridge.XercesBridge_2_0" };
    for (int i = 0; i != classNames.length; i++)
    {
      String className = classNames[i];
      XercesBridge bridge = newInstanceOrNull(className);
      if (bridge != null) {
        return bridge;
      }
    }
    throw new IllegalStateException("Failed to create XercesBridge instance");
  }
  
  private static XercesBridge newInstanceOrNull(String className)
  {
    try
    {
      return (XercesBridge)Class.forName(className).newInstance();
    }
    catch (ClassNotFoundException ex) {}catch (SecurityException ex) {}catch (LinkageError ex) {}catch (IllegalArgumentException e) {}catch (IllegalAccessException e) {}catch (InstantiationException e) {}
    return null;
  }
  
  public void NamespaceContext_declarePrefix(NamespaceContext namespaceContext, String ns, String avalue) {}
  
  public abstract String getVersion();
  
  public abstract void XMLDocumentHandler_startDocument(XMLDocumentHandler paramXMLDocumentHandler, XMLLocator paramXMLLocator, String paramString, NamespaceContext paramNamespaceContext, Augmentations paramAugmentations);
  
  public void XMLDocumentHandler_startPrefixMapping(XMLDocumentHandler documentHandler, String prefix, String uri, Augmentations augs) {}
  
  public void XMLDocumentHandler_endPrefixMapping(XMLDocumentHandler documentHandler, String prefix, Augmentations augs) {}
  
  public void XMLDocumentFilter_setDocumentSource(XMLDocumentFilter filter, XMLDocumentSource lastSource) {}
}

/* Location:
 * Qualified Name:     org.cyberneko.html.xercesbridge.XercesBridge
 * Java Class Version: 1.3 (47.0)
 * JD-Core Version:    0.7.1
 */
package org.cyberneko.html.xercesbridge;

import org.apache.xerces.impl.Version;
import org.apache.xerces.xni.Augmentations;
import org.apache.xerces.xni.NamespaceContext;
import org.apache.xerces.xni.XMLDocumentHandler;
import org.apache.xerces.xni.XMLLocator;

public class XercesBridge_2_0
  extends XercesBridge
{
  public String getVersion()
  {
    return Version.fVersion;
  }
  
  public void XMLDocumentHandler_startPrefixMapping(XMLDocumentHandler documentHandler, String prefix, String uri, Augmentations augs)
  {
    documentHandler.startPrefixMapping(prefix, uri, augs);
  }
  
  public void XMLDocumentHandler_endPrefixMapping(XMLDocumentHandler documentHandler, String prefix, Augmentations augs)
  {
    documentHandler.endPrefixMapping(prefix, augs);
  }
  
  public void XMLDocumentHandler_startDocument(XMLDocumentHandler documentHandler, XMLLocator locator, String encoding, NamespaceContext nscontext, Augmentations augs)
  {
    documentHandler.startDocument(locator, encoding, augs);
  }
}

/* Location:
 * Qualified Name:     org.cyberneko.html.xercesbridge.XercesBridge_2_0
 * Java Class Version: 1.3 (47.0)
 * JD-Core Version:    0.7.1
 */
package org.cyberneko.html.xercesbridge;

import org.apache.xerces.impl.Version;
import org.apache.xerces.xni.Augmentations;
import org.apache.xerces.xni.NamespaceContext;
import org.apache.xerces.xni.XMLDocumentHandler;
import org.apache.xerces.xni.XMLLocator;
import org.apache.xerces.xni.parser.XMLDocumentFilter;
import org.apache.xerces.xni.parser.XMLDocumentSource;

public class XercesBridge_2_1
  extends XercesBridge
{
  public XercesBridge_2_1()
    throws InstantiationException
  {
    try
    {
      getVersion();
    }
    catch (Error e)
    {
      throw new InstantiationException(e.getMessage());
    }
  }
  
  public String getVersion()
  {
    return new Version().getVersion();
  }
  
  public void XMLDocumentHandler_startDocument(XMLDocumentHandler documentHandler, XMLLocator locator, String encoding, NamespaceContext nscontext, Augmentations augs)
  {
    documentHandler.startDocument(locator, encoding, augs);
  }
  
  public void XMLDocumentFilter_setDocumentSource(XMLDocumentFilter filter, XMLDocumentSource lastSource)
  {
    filter.setDocumentSource(lastSource);
  }
}

/* Location:
 * Qualified Name:     org.cyberneko.html.xercesbridge.XercesBridge_2_1
 * Java Class Version: 1.3 (47.0)
 * JD-Core Version:    0.7.1
 */
package org.cyberneko.html.xercesbridge;

import org.apache.xerces.impl.Version;
import org.apache.xerces.xni.Augmentations;
import org.apache.xerces.xni.NamespaceContext;
import org.apache.xerces.xni.XMLDocumentHandler;
import org.apache.xerces.xni.XMLLocator;
import org.apache.xerces.xni.parser.XMLDocumentFilter;
import org.apache.xerces.xni.parser.XMLDocumentSource;

public class XercesBridge_2_2
  extends XercesBridge
{
  protected XercesBridge_2_2()
    throws InstantiationException
  {
    try
    {
      getVersion();
    }
    catch (Throwable e)
    {
      throw new InstantiationException(e.getMessage());
    }
  }
  
  public String getVersion()
  {
    return Version.getVersion();
  }
  
  public void XMLDocumentHandler_startPrefixMapping(XMLDocumentHandler documentHandler, String prefix, String uri, Augmentations augs) {}
  
  public void XMLDocumentHandler_startDocument(XMLDocumentHandler documentHandler, XMLLocator locator, String encoding, NamespaceContext nscontext, Augmentations augs)
  {
    documentHandler.startDocument(locator, encoding, nscontext, augs);
  }
  
  public void XMLDocumentFilter_setDocumentSource(XMLDocumentFilter filter, XMLDocumentSource lastSource)
  {
    filter.setDocumentSource(lastSource);
  }
}

/* Location:
 * Qualified Name:     org.cyberneko.html.xercesbridge.XercesBridge_2_2
 * Java Class Version: 1.3 (47.0)
 * JD-Core Version:    0.7.1
 */
package org.cyberneko.html.xercesbridge;

import org.apache.xerces.xni.NamespaceContext;

public class XercesBridge_2_3
  extends XercesBridge_2_2
{
  public XercesBridge_2_3()
    throws InstantiationException
  {
    try
    {
      Class[] args = { String.class, String.class };
      NamespaceContext.class.getMethod("declarePrefix", args);
    }
    catch (NoSuchMethodException e)
    {
      throw new InstantiationException(e.getMessage());
    }
  }
  
  public void NamespaceContext_declarePrefix(NamespaceContext namespaceContext, String ns, Strin
1 2 3 4 5 6 7 8 9

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2017. Infinite Loop Ltd