nekohtml-1.9.14

gmentContextStack_ = null;
    fragmentContextStackSize_ = 0;
    
    endElementsBuffer_ = new ArrayList();
  }
  
  public Boolean getFeatureDefault(String featureId)
  {
    int length = RECOGNIZED_FEATURES != null ? RECOGNIZED_FEATURES.length : 0;
    for (int i = 0; i < length; i++) {
      if (RECOGNIZED_FEATURES[i].equals(featureId)) {
        return RECOGNIZED_FEATURES_DEFAULTS[i];
      }
    }
    return null;
  }
  
  public Object getPropertyDefault(String propertyId)
  {
    int length = RECOGNIZED_PROPERTIES != null ? RECOGNIZED_PROPERTIES.length : 0;
    for (int i = 0; i < length; i++) {
      if (RECOGNIZED_PROPERTIES[i].equals(propertyId)) {
        return RECOGNIZED_PROPERTIES_DEFAULTS[i];
      }
    }
    return null;
  }
  
  public String[] getRecognizedFeatures()
  {
    return RECOGNIZED_FEATURES;
  }
  
  public String[] getRecognizedProperties()
  {
    return RECOGNIZED_PROPERTIES;
  }
  
  public void reset(XMLComponentManager manager)
    throws XMLConfigurationException
  {
    fNamespaces = manager.getFeature("http://xml.org/sax/features/namespaces");
    fAugmentations = manager.getFeature("http://cyberneko.org/html/features/augmentations");
    fReportErrors = manager.getFeature("http://cyberneko.org/html/features/report-errors");
    fDocumentFragment = ((manager.getFeature("http://cyberneko.org/html/features/balance-tags/document-fragment")) || (manager.getFeature("http://cyberneko.org/html/features/document-fragment")));
    
    fIgnoreOutsideContent = manager.getFeature("http://cyberneko.org/html/features/balance-tags/ignore-outside-content");
    
    fNamesElems = getNamesValue(String.valueOf(manager.getProperty("http://cyberneko.org/html/properties/names/elems")));
    fNamesAttrs = getNamesValue(String.valueOf(manager.getProperty("http://cyberneko.org/html/properties/names/attrs")));
    fErrorReporter = ((HTMLErrorReporter)manager.getProperty("http://cyberneko.org/html/properties/error-reporter"));
    
    fragmentContextStack_ = ((QName[])manager.getProperty("http://cyberneko.org/html/properties/balance-tags/fragment-context-stack"));
  }
  
  public void setFeature(String featureId, boolean state)
    throws XMLConfigurationException
  {
    if (featureId.equals("http://cyberneko.org/html/features/augmentations"))
    {
      fAugmentations = state;
      return;
    }
    if (featureId.equals("http://cyberneko.org/html/features/report-errors"))
    {
      fReportErrors = state;
      return;
    }
    if (featureId.equals("http://cyberneko.org/html/features/balance-tags/ignore-outside-content"))
    {
      fIgnoreOutsideContent = state;
      return;
    }
  }
  
  public void setProperty(String propertyId, Object value)
    throws XMLConfigurationException
  {
    if (propertyId.equals("http://cyberneko.org/html/properties/names/elems"))
    {
      fNamesElems = getNamesValue(String.valueOf(value));
      return;
    }
    if (propertyId.equals("http://cyberneko.org/html/properties/names/attrs"))
    {
      fNamesAttrs = getNamesValue(String.valueOf(value));
      return;
    }
  }
  
  public void setDocumentHandler(XMLDocumentHandler handler)
  {
    fDocumentHandler = handler;
  }
  
  public XMLDocumentHandler getDocumentHandler()
  {
    return fDocumentHandler;
  }
  
  public void startDocument(XMLLocator locator, String encoding, NamespaceContext nscontext, Augmentations augs)
    throws XNIException
  {
    fElementStack.top = 0;
    if (fragmentContextStack_ != null)
    {
      fragmentContextStackSize_ = fragmentContextStack_.length;
      for (int i = 0; i < fragmentContextStack_.length; i++)
      {
        QName name = fragmentContextStack_[i];
        HTMLElements.Element elt = HTMLElements.getElement(localpart);
        fElementStack.push(new Info(elt, name));
      }
    }
    else
    {
      fragmentContextStackSize_ = 0;
    }
    fSeenAnything = false;
    fSeenDoctype = false;
    fSeenRootElement = false;
    fSeenRootElementEnd = false;
    fSeenHeadElement = false;
    fSeenBodyElement = false;
    if (fDocumentHandler != null) {
      XercesBridge.getInstance().XMLDocumentHandler_startDocument(fDocumentHandler, locator, encoding, nscontext, augs);
    }
  }
  
  public void xmlDecl(String version, String encoding, String standalone, Augmentations augs)
    throws XNIException
  {
    if ((!fSeenAnything) && (fDocumentHandler != null)) {
      fDocumentHandler.xmlDecl(version, encoding, standalone, augs);
    }
  }
  
  public void doctypeDecl(String rootElementName, String publicId, String systemId, Augmentations augs)
    throws XNIException
  {
    fSeenAnything = true;
    if (fReportErrors) {
      if (fSeenRootElement) {
        fErrorReporter.reportError("HTML2010", null);
      } else if (fSeenDoctype) {
        fErrorReporter.reportError("HTML2011", null);
      }
    }
    if ((!fSeenRootElement) && (!fSeenDoctype))
    {
      fSeenDoctype = true;
      if (fDocumentHandler != null) {
        fDocumentHandler.doctypeDecl(rootElementName, publicId, systemId, augs);
      }
    }
  }
  
  public void endDocument(Augmentations augs)
    throws XNIException
  {
    fIgnoreOutsideContent = true;
    consumeBufferedEndElements();
    if ((!fSeenRootElement) && (!fDocumentFragment))
    {
      if (fReportErrors) {
        fErrorReporter.reportError("HTML2000", null);
      }
      if (fDocumentHandler != null)
      {
        fSeenRootElementEnd = false;
        forceStartBody();
        String body = modifyName("body", fNamesElems);
        fQName.setValues(null, body, body, null);
        callEndElement(fQName, synthesizedAugs());
        
        String ename = modifyName("html", fNamesElems);
        fQName.setValues(null, ename, ename, null);
        callEndElement(fQName, synthesizedAugs());
      }
    }
    else
    {
      int length = fElementStack.top - fragmentContextStackSize_;
      for (int i = 0; i < length; i++)
      {
        Info info = fElementStack.pop();
        if (fReportErrors)
        {
          String ename = qname.rawname;
          fErrorReporter.reportWarning("HTML2001", new Object[] { ename });
        }
        if (fDocumentHandler != null) {
          callEndElement(qname, synthesizedAugs());
        }
      }
    }
    if (fDocumentHandler != null) {
      fDocumentHandler.endDocument(augs);
    }
  }
  
  private void consumeBufferedEndElements()
  {
    List toConsume = new ArrayList(endElementsBuffer_);
    endElementsBuffer_.clear();
    for (int i = 0; i < toConsume.size(); i++)
    {
      ElementEntry entry = (ElementEntry)toConsume.get(i);
      forcedEndElement_ = true;
      endElement(name_, augs_);
    }
    endElementsBuffer_.clear();
  }
  
  public void comment(XMLString text, Augmentations augs)
    throws XNIException
  {
    fSeenAnything = true;
    consumeEarlyTextIfNeeded();
    if (fDocumentHandler != null) {
      fDocumentHandler.comment(text, augs);
    }
  }
  
  private void consumeEarlyTextIfNeeded()
  {
    if (!lostText_.isEmpty())
    {
      if (!fSeenBodyElement) {
        forceStartBody();
      }
      lostText_.refeed(this);
    }
  }
  
  public void processingInstruction(String target, XMLString data, Augmentations augs)
    throws XNIException
  {
    fSeenAnything = true;
    consumeEarlyTextIfNeeded();
    if (fDocumentHandler != null) {
      fDocumentHandler.processingInstruction(target, data, augs);
    }
  }
  
  public void startElement(QName elem, XMLAttributes attrs, Augmentations augs)
    throws XNIException
  {
    fSeenAnything = true;
    
    boolean isForcedCreation = forcedStartElement_;
    forcedStartElement_ = false;
    if (fSeenRootElementEnd)
    {
      notifyDiscardedStartElement(elem, attrs, augs);
      return;
    }
    HTMLElements.Element element = getElement(elem);
    short elementCode = code;
    if ((isForcedCreation) && ((elementCode == 101) || (elementCode == 91))) {
      return;
    }
    if ((fSeenRootElement) && (elementCode == 46))
    {
      notifyDiscardedStartElement(elem, attrs, augs);
      return;
    }
    if (elementCode == 44)
    {
      if (fSeenHeadElement)
      {
        notifyDiscardedStartElement(elem, attrs, augs);
        return;
      }
      fSeenHeadElement = true;
    }
    else if (elementCode == 37)
    {
      consumeBufferedEndElements();
    }
    else if (elementCode == 14)
    {
      if (!fSeenHeadElement)
      {
        QName head = createQName("head");
        forceStartElement(head, null, synthesizedAugs());
        endElement(head, synthesizedAugs());
      }
      consumeBufferedEndElements();
      if (fSeenBodyElement)
      {
        notifyDiscardedStartElement(elem, attrs, augs);
        return;
      }
      fSeenBodyElement = true;
    }
    else if (elementCode == 35)
    {
      if (fOpenedForm)
      {
        notifyDiscardedStartElement(elem, attrs, augs);
        return;
      }
      fOpenedForm = true;
    }
    else if (elementCode == 117)
    {
      consumeBufferedEndElements();
    }
    if (parent != null)
    {
      HTMLElements.Element preferedParent = parent[0];
      if ((!fDocumentFragment) || ((code != 44) && (code != 14))) {
        if ((!fSeenRootElement) && (!fDocumentFragment))
        {
          String pname = name;
          pname = modifyName(pname, fNamesElems);
          if (fReportErrors)
          {
            String ename = rawname;
            fErrorReporter.reportWarning("HTML2002", new Object[] { ename, pname });
          }
          QName qname = new QName(null, pname, pname, null);
          boolean parentCreated = forceStartElement(qname, null, synthesizedAugs());
          if (!parentCreated)
          {
            if (!isForcedCreation) {
              notifyDiscardedStartElement(elem, attrs, augs);
            }
            return;
          }
        }
        else if ((code != 44) || ((!fSeenBodyElement) && (!fDocumentFragment)))
        {
          int depth = getParentDepth(parent, bounds);
          if (depth == -1)
          {
            String pname = modifyName(name, fNamesElems);
            QName qname = new QName(null, pname, pname, null);
            if (fReportErrors)
            {
              String ename = rawname;
              fErrorReporter.reportWarning("HTML2004", new Object[] { ename, pname });
            }
            boolean parentCreated = forceStartElement(qname, null, synthesizedAugs());
            if (!parentCreated)
            {
              if (!isForcedCreation) {
                notifyDiscardedStartElement(elem, attrs, augs);
              }
              return;
            }
          }
        }
      }
    }
    int depth = 0;
    if (flags == 0)
    {
      int length = fElementStack.top;
      fInlineStack.top = 0;
      for (int i = length - 1; i >= 0; i--)
      {
        Info info = fElementStack.data[i];
        if (!element.isInline()) {
          break;
        }
        fInlineStack.push(info);
        endElement(qname, synthesizedAugs());
      }
      depth = fInlineStack.top;
    }
    if (((fElementStack.top > 1) && (fElementStack.peek().element.code == 90)) || ((fElementStack.top > 2) && (fElementStack.data[(fElementStack.top - 2)].element.code == 44)))
    {
      Info info = fElementStack.pop();
      if (fDocumentHandler != null) {
        callEndElement(qname, synthesizedAugs());
      }
    }
    if (closes != null)
    {
      int length = fElementStack.top;
      for (int i = length - 1; i >= 0; i--)
      {
        Info info = fElementStack.data[i];
        if (element.closes(element.code))
        {
          if (fReportErrors)
          {
            String ename = rawname;
            String iname = qname.rawname;
            fErrorReporter.reportWarning("HTML2005", new Object[] { ename, iname });
          }
          for (int j = length - 1; j >= i; j--)
          {
            info = fElementStack.pop();
            if (fDocumentHandler != null) {
              callEndElement(qname, synthesizedAugs());
            }
          }
          length = i;
        }
        else
        {
          if ((element.isBlock()) || (element.isParent(element))) {
            break;
          }
        }
      }
    }
    else if (elementCode == 101)
    {
      for (int i = fElementStack.top - 1; i >= 0; i--)
      {
        Info info = fElementStack.data[i];
        if (!element.isInline()) {
          break;
        }
        endElement(qname, synthesizedAugs());
      }
    }
    fSeenRootElement = true;
    if ((element != null) && (element.isEmpty()))
    {
      if (attrs == null) {
        attrs = emptyAttributes();
      }
      if (fDocumentHandler != null) {
        fDocumentHandler.emptyElement(elem, attrs, augs);
      }
    }
    else
    {
      boolean inline = (element != null) && (element.isInline());
      fElementStack.push(new Info(element, elem, inline ? attrs : null));
      if (attrs == null) {
        attrs = emptyAttributes();
      }
      if (fDocumentHandler != null) {
        callStartElement(elem, attrs, augs);
      }
    }
    for (int i = 0; i < depth; i++)
    {
      Info info = fInlineStack.pop();
      forceStartElement(qname, attributes, synthesizedAugs());
    }
    if (elementCode == 14) {
      lostText_.refeed(this);
    }
  }
  
  private boolean forceStartElement(QName elem, XMLAttributes attrs, Augmentations augs)
    throws XNIException
  {
    forcedStartElement_ = true;
    startElement(elem, attrs, augs);
    
    return (fElementStack.top > 0) && (elem.equals(fElementStack.peek().qname));
  }
  
  private QName createQName(String tagName)
  {
    tagName = modifyName(tagName, fNamesElems);
    return new QName(null, tagName, tagName, "http://www.w3.org/1999/xhtml");
  }
  
  public void emptyElement(QName element, XMLAttributes attrs, Augmentations augs)
    throws XNIException
  {
    startElement(element, attrs, augs);
    
    HTMLElements.Element elem = getElement(element);
    if ((elem.isEmpty()) || (code == 117)) {
      endElement(element, augs);
    }
  }
  
  public void startGeneralEntity(String name, XMLResourceIdentifier id, String encoding, Augmentations augs)
    throws XNIException
  {
    fSeenAnything = true;
    if (fSeenRootElementEnd) {
      return;
    }
    if (!fDocumentFragment)
    {
      boolean insertBody = !fSeenRootElement;
      if (!insertBody)
      {
        Info info = fElementStack.peek();
        if ((element.code == 44) || (element.code == 46))
        {
          String hname = modifyName("head", fNamesElems);
          String bname = modifyName("body", fNamesElems);
          if (fReportErrors) {
            fErrorReporter.reportWarning("HTML2009", new Object[] { hname, bname });
          }
          fQName.setValues(null, hname, hname, null);
          endElement(fQName, synthesizedAugs());
          insertBody = true;
        }
      }
      if (insertBody) {
        forceStartBody();
      }
    }
    if (fDocumentHandler != null) {
      fDocumentHandler.startGeneralEntity(name, id, encoding, augs);
    }
  }
  
  private void forceStartBody()
  {
    QName body = createQName("body");
    if (fReportErrors) {
      fErrorReporter.reportWarning("HTML2006", new Object[] { localpart });
    }
    forceStartElement(body, null, synthesizedAugs());
  }
  
  public void textDecl(String version, String encoding, Augmentations augs)
    throws XNIException
  {
    fSeenAnything = true;
    if (fSeenRootElementEnd) {
      return;
    }
    if (fDocumentHandler != null) {
      fDocumentHandler.textDecl(version, encoding, augs);
    }
  }
  
  public void endGeneralEntity(String name, Augmentations augs)
    throws XNIException
  {
    if (fSeenRootElementEnd) {
      return;
    }
    if (fDocumentHandler != null) {
      fDocumentHandler.endGeneralEntity(name, augs);
    }
  }
  
  public void startCDATA(Augmentations augs)
    throws XNIException
  {
    fSeenAnything = true;
    
    consumeEarlyTextIfNeeded();
    if (fSeenRootElementEnd) {
      return;
    }
    if (fDocumentHandler != null) {
      fDocumentHandler.startCDATA(augs);
    }
  }
  
  public void endCDATA(Augmentations augs)
    throws XNIException
  {
    if (fSeenRootElementEnd) {
      return;
    }
    if (fDocumentHandler != null) {
      fDocumentHandler.endCDATA(augs);
    }
  }
  
  public void characters(XMLString text, Augmentations augs)
    throws XNIException
  {
    if (fSeenRootElementEnd) {
      return;
    }
    if ((fElementStack.top == 0) && (!fDocumentFragment))
    {
      lostText_.add(text, augs);
      return;
    }
    boolean whitespace = true;
    for (int i = 0; i < length; i++) {
      if (!Character.isWhitespace(ch[(offset + i)]))
      {
        whitespace = false;
        break;
      }
    }
    if (!fDocumentFragment)
    {
      if (!fSeenRootElement)
      {
        if (whitespace) {
          return;
        }
        forceStartBody();
      }
      if ((whitespace) && ((fElementStack.top < 2) || (endElementsBuffer_.size() == 1))) {
        return;
      }
      if (!whitespace)
      {
        Info info = fElementStack.peek();
        if ((element.code == 44) || (element.code == 46))
        {
          String hname = modifyName("head", fNamesElems);
          String bname = modifyName("body", fNamesElems);
          if (fReportErrors) {
            fErrorReporter.reportWarning("HTML2009", new Object[] { hname, bname });
          }
          forceStartBody();
        }
      }
    }
    if (fDocumentHandler != null) {
      fDocumentHandler.characters(text, augs);
    }
  }
  
  public void ignorableWhitespace(XMLString text, Augmentations augs)
    throws XNIException
  {
    characters(text, augs);
  }
  
  public void endElement(QName element, Augmentations augs)
    throws XNIException
  {
    boolean forcedEndElement = forcedEndElement_;
    if (fSeenRootElementEnd)
    {
      notifyDiscardedEndElement(element, augs);
      return;
    }
    HTMLElements.Element elem = getElement(element);
    if ((!fIgnoreOutsideContent) && ((code == 14) || (code == 46)))
    {
      endElementsBuffer_.add(new ElementEntry(element, augs));
      return;
    }
    if (code == 46)
    {
      fSeenRootElementEnd = true;
    }
    else if (code == 35)
    {
      fOpenedForm = false;
    }
    else if ((code == 44) && (!forcedEndElement))
    {
      endElementsBuffer_.add(new ElementEntry(element, augs));
      return;
    }
    int depth = getElementDepth(elem);
    if (depth == -1)
    {
      if (code == 77)
      {
        forceStartElement(element, emptyAttributes(), synthesizedAugs());
        endElement(element, augs);
      }
      else if (!elem.isEmpty())
      {
        notifyDiscardedEndElement(element, augs);
      }
      return;
    }
    if ((depth > 1) && (elem.isInline()))
    {
      int size = fElementStack.top;
      fInlineStack.top = 0;
      for (int i = 0; i < depth - 1; i++)
      {
        Info info = fElementStack.data[(size - i - 1)];
        HTMLElements.Element pelem = element;
        if ((pelem.isInline()) || (code == 34)) {
          fInlineStack.push(info);
        }
      }
    }
    for (int i = 0; i < depth; i++)
    {
      Info info = fElementStack.pop();
      if ((fReportErrors) && (i < depth - 1))
      {
        String ename = modifyName(rawname, fNamesElems);
        String iname = qname.rawname;
        fErrorReporter.reportWarning("HTML2007", new Object[] { ename, iname });
      }
      if (fDocumentHandler != null) {
        callEndElement(qname, i < depth - 1 ? synthesizedAugs() : augs);
      }
    }
    if (depth > 1)
    {
      int size = fInlineStack.top;
      for (int i = 0; i < size; i++)
      {
        Info info = fInlineStack.pop();
        XMLAttributes attributes = attributes;
        if (fReportErrors)
        {
          String iname = qname.rawname;
          fErrorReporter.reportWarning("HTML2008", new Object[] { iname });
        }
        forceStartElement(qname, attributes, synthesizedAugs());
      }
    }
  }
  
  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 startPrefixMapping(String prefix, String uri, Augmentations augs)
    throws XNIException
  {
    if (fSeenRootElementEnd) {
      return;
    }
    if (fDocumentHandler != null) {
      XercesBridge.getInstance().XMLDocumentHandler_startPrefixMapping(fDocumentHandler, prefix, uri, augs);
    }
  }
  
  public void endPrefixMapping(String prefix, Augmentations augs)
    throws XNIException
  {
    if (fSeenRootElementEnd) {
      return;
    }
    if (fDocumentHandler != null) {
      XercesBridge.getInstance().XMLDocumentHandler_endPrefixMapping(fDocumentHandler, prefix, augs);
    }
  }
  
  protected HTMLElements.Element getElement(QName elementName)
  {
    String name = rawname;
    if ((fNamespaces) && ("http://www.w3.org/1999/xhtml".equals(uri)))
    {
      int index = name.indexOf(':');
      if (index != -1) {
        name = name.substring(index + 1);
      }
    }
    return HTMLElements.getElement(name);
  }
  
  protected final void callStartElement(QName element, XMLAttributes attrs, Augmentations augs)
    throws XNIException
  {
    fDocumentHandler.startElement(element, attrs, augs);
  }
  
  protected final void callEndElement(QName element, Augmentations augs)
    throws XNIException
  {
    fDocumentHandler.endElement(element, augs);
  }
  
  protected final int getElementDepth(HTMLElements.Element element)
  {
    boolean container = element.isContainer();
    short elementCode = code;
    boolean tableBodyOrHtml = (elementCode == 101) || (elementCode == 14) || (elementCode == 46);
    
    int depth = -1;
    for (int i = fElementStack.top - 1; i >= fragmentContextStackSize_; i--)
    {
      Info info = fElementStack.data[i];
      if (element.code == code)
      {
        depth = fElementStack.top - i;
        break;
      }
      if ((!container) && (element.isBlock())) {
        break;
      }
      if ((element.code == 101) && (!tableBodyOrHtml)) {
        return -1;
      }
    }
    return depth;
  }
  
  protected int getParentDepth(HTMLElements.Element[] parents, short bounds)
  {
    if (parents != null) {
      for (int i = fElementStack.top - 1; i >= 0; i--)
      {
        Info info = fElementStack.data[i];
        if (element.code == bounds) {
          break;
        }
        for (int j = 0; j < parents.length; j++) {
          if (element.code == code) {
            return fElementStack.top - i;
          }
        }
      }
    }
    return -1;
  }
  
  protected final XMLAttributes emptyAttributes()
  {
    fEmptyAttrs.removeAllAttributes();
    return fEmptyAttrs;
  }
  
  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 static final String modifyName(String name, short mode)
  {
    switch (mode)
    {
    case 1: 
      return name.toUpperCase();
    case 2: 
      return name.toLowerCase();
    }
    return name;
  }
  
  protected static final short getNamesValue(String value)
  {
    if (value.equals("lower")) {
      return 2;
    }
    if (value.equals("upper")) {
      return 1;
    }
    return 0;
  }
  
  public static class Info
  {
    public HTMLElements.Element element;
    public QName qname;
    public XMLAttributes attributes;
    
    public Info(HTMLElements.Element element, QName qname)
    {
      this(element, qname, null);
    }
    
    public Info(HTMLElements.Element element, QName qname, XMLAttributes attributes)
    {
      this.element = element;
      this.qname = new QName(qname);
      if (attributes != null)
      {
        int length = attributes.getLength();
        if (length > 0)
        {
          QName aqname = new QName();
          XMLAttributes newattrs = new XMLAttributesImpl();
          for (int i = 0; i < length; i++)
          {
            attributes.getName(i, aqname);
            String type = attributes.getType(i);
            String value = attributes.getValue(i);
            String nonNormalizedValue = attributes.getNonNormalizedValue(i);
            boolean specified = attributes.isSpecified(i);
            newattrs.addAttribute(aqname, type, value);
            newattrs.setNonNormalizedValue(i, nonNormalizedValue);
            newattrs.setSpecified(i, specified);
          }
          this.attributes = newattrs;
        }
      }
    }
    
    public String toString()
    {
      return super.toString() + qname;
    }
  }
  
  public static class InfoStack
  {
    public int top;
    public HTMLTagBalancer.Info[] data = new HTMLTagBalancer.Info[10];
    
    public void push(HTMLTagBalancer.Info info)
    {
      if (top == data.length)
      {
        HTMLTagBalancer.Info[] newarray = new HTMLTagBalancer.Info[top + 10];
        System.arraycopy(data, 0, newarray, 0, top);
        data = newarray;
      }
      data[(top++)] = info;
    }
    
    public HTMLTagBalancer.Info peek()
    {
      return data[(top - 1)];
    }
    
    public HTMLTagBalancer.Info pop()
    {
      return data[(--top)];
    }
    
    public String toString()
    {
      StringBuffer sb = new StringBuffer("InfoStack(");
      for (int i = top - 1; i >= 0; i--)
      {
        sb.append(data[i]);
        if (i != 0) {
          sb.append(", ");
        }
      }
      sb.append(")");
      return sb.toString();
    }
  }
  
  void setTagBalancingListener(HTMLTagBalancingListener tagBalancingListener)
  {
    this.tagBalancingListener = tagBalancingListener;
  }
  
  private void notifyDiscardedStartElement(QName elem, XMLAttributes attrs, Augmentations augs)
  {
    if (tagBalancingListener != null) {
      tagBalancingListener.ignoredStartElement(elem, attrs, augs);
    }
  }
  
  private void notifyDiscardedEndElement(QName element, Augmentations augs)
  {
    if (tagBalancingListener != null) {
      tagBalancingListener.ignoredEndElement(element, augs);
    }
  }
  
  static class ElementEntry
  {
    private final QName name_;
    private final Augmentations augs_;
    
    ElementEntry(QName element, Augmentations augs)
    {
      name_ = new QName(element);
      augs_ = (augs == null ? null : new HTMLAugmentations(augs));
    }
  }
}

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

import org.apache.xerces.xni.Augmentations;
import org.apache.xerces.xni.QName;
import org.apache.xerces.xni.XMLAttributes;

public abstract interface HTMLTagBalancingListener
{
  public abstract void ignoredStartElement(QName paramQName, XMLAttributes paramXMLAttributes, Augmentations paramAugmentations);
  
  public abstract void ignoredEndElement(QName paramQName, Augmentations paramAugmentations);
}

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

import org.apache.xerces.xni.Augmentations;
import org.apache.xerces.xni.XMLString;

class LostText$Entry
{
  private XMLString text_;
  private Augmentations augs_;
  
  public LostText$Entry(XMLString text, Augmentations augs)
  {
    char[] chars = new char[length];
    System.arraycopy(ch, offset, chars, 0, length);
    text_ = new XMLString(chars, 0, chars.length);
    if (augs != null) {
      augs_ = new HTMLAugmentations(augs);
    }
  }
}

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

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.apache.xerces.xni.Augmentations;
import org.apache.xerces.xni.XMLDocumentHandler;
import org.apache.xerces.xni.XMLString;

class LostText
{
  static class Entry
  {
    private XMLString text_;
    private Augmentations augs_;
    
    public Entry(XMLString text, Augmentations augs)
    {
      char[] chars = new char[length];
      System.arraycopy(ch, offset, chars, 0, length);
      text_ = new XMLString(chars, 0, chars.length);
      if (augs != null) {
        augs_ = new HTMLAugmentations(augs);
      }
    }
  }
  
  private final List entries = new ArrayList();
  
  public void add(XMLString text, Augmentations augs)
  {
    if ((!entries.isEmpty()) || (text.toString().trim().length() > 0)) {
      entries.add(new Entry(text, augs));
    }
  }
  
  public void refeed(XMLDocumentHandler tagBalancer)
  {
    for (Iterator iter = entries.iterator(); iter.hasNext();)
    {
      Entry entry = (Entry)iter.next();
      tagBalancer.characters(text_, augs_);
    }
    entries.clear();
  }
  
  public boolean isEmpty()
  {
    return entries.isEmpty();
  }
}

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

class ObjectFactory$ConfigurationError
  extends Error
{
  private Exception exception;
  
  ObjectFactory$ConfigurationError(String msg, Exception x)
  {
    super(msg);
    exception = x;
  }
  
  Exception getException()
  {
    return exception;
  }
}

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

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.Properties;

class ObjectFactory
{
  private static final String DEFAULT_PROPERTIES_FILENAME = "xerces.properties";
  private static final boolean DEBUG = false;
  private static final int DEFAULT_LINE_LENGTH = 80;
  private static Properties fXercesProperties = null;
  private static long fLastModified = -1L;
  
  static Object createObject(String factoryId, String fallbackClassName)
    throws ObjectFactory.ConfigurationError
  {
    return createObject(factoryId, null, fallbackClassName);
  }
  
  static Object createObject(String factoryId, String propertiesFilename, String fallbackClassName)
    throws ObjectFactory.ConfigurationError
  {
    SecuritySupport ss = SecuritySupport.getInstance();
    ClassLoader cl = findClassLoader();
    try
    {
      String systemProp = ss.getSystemProperty(factoryId);
      if (systemProp != null) {
        return newInstance(systemProp, cl, true);
      }
    }
    catch (SecurityException se) {}
    String factoryClassName = null;
    if (propertiesFilename == null)
    {
      File propertiesFile = null;
      boolean propertiesFileExists = false;
      try
      {
        String javah = ss.getSystemProperty("java.home");
        propertiesFilename = javah + File.separator + "lib" + File.separator + "xerces.properties";
        
        propertiesFile = new File(propertiesFilename);
        propertiesFileExists = ss.getFileExists(propertiesFile);
      }
      catch (SecurityException e)
      {
        fLastModified = -1L;
        fXercesProperties = null;
      }
      synchronized (ObjectFactory.class)
      {
        boolean loadProperties = false;
        try
        {
          if (fLastModified >= 0L)
          {
            if ((propertiesFileExists) && (fLastModified < (fLastModified = ss.getLastModified(propertiesFile))))
            {
              loadProperties = true;
            }
            else if (!propertiesFileExists)
            {
              fLastModified = -1L;
              fXercesProperties = null;
            }
          }
          else if (propertiesFileExists)
          {
            loadProperties = true;
            fLastModified = ss.getLastModified(propertiesFile);
          }
          if (loadProperties)
          {
            fXercesProperties = new Properties();
            FileInputStream fis = ss.getFileInputStream(propertiesFile);
            fXercesProperties.load(fis);
            fis.close();
          }
        }
        catch (Exception x)
        {
          fXercesProperties = null;
          fLastModified = -1L;
        }
      }
      if (fXercesProperties != null) {
        factoryClassName = fXercesProperties.getProperty(factoryId);
      }
    }
    else
    {
      try
      {
        FileInputStream fis = ss.getFileInputStream(new File(propertiesFilename));
        Properties props = new Properties();
        props.load(fis);
        fis.close();
        factoryClassName = props.getProperty(factoryId);
      }
      catch (Exception x) {}
    }
    if (factoryClassName != null) {
      return newInstance(factoryClassName, cl, true);
    }
    Object provider = findJarServiceProvider(factoryId);
    if (provider != null) {
      return provider;
    }
    if (fallbackClassName == null) {
      throw new ConfigurationError("Provider for " + factoryId + " cannot be found", null);
    }
    return newInstance(fallbackClassName, cl, true);
  }
  
  private static void debugPrintln(String msg) {}
  
  static ClassLoader findClassLoader()
    throws ObjectFactory.ConfigurationError
  {
    SecuritySupport ss = SecuritySupport.getInstance();
    
    ClassLoader context = ss.getContextClassLoader();
    ClassLoader system = ss.getSystemClassLoader();
    
    ClassLoader chain = system;
    for (;;)
    {
      if (context == chain)
      {
        ClassLoader current = ObjectFactory.class.getClassLoader();
        
        chain = system;
        for (;;)
        {
          if (current == chain) {
            return system;
          }
          if (chain == null) {
            break;
          }
          chain = ss.getParentClassLoader(chain);
        }
        return current;
      }
      if (chain == null) {
        break;
      }
      chain = ss.getParentClassLoader(chain);
    }
    return context;
  }
  
  static Object newInstance(String className, ClassLoader cl, boolean doFallback)
    throws ObjectFactory.ConfigurationError
  {
    try
    {
      Class providerClass = findProviderClass(className, cl, doFallback);
      return providerClass.newInstance();
    }
    catch (ClassNotFoundException x)
    {
      throw new ConfigurationError("Provider " + className + " not found", x);
    }
    catch (Exception x)
    {
      throw new ConfigurationError("Provider " + className + " could not be instantiated: " + x, x);
    }
  }
  
  static Class findProviderClass(String className, ClassLoader cl, boolean doFallback)
    throws ClassNotFoundException, ObjectFactory.ConfigurationError
  {
    SecurityManager security = System.getSecurityManager();
    try
    {
      if (security != null)
      {
        int lastDot = className.lastIndexOf(".");
        String packageName = className;
        if (lastDot != -1) {
          packageName = className.substring(0, lastDot);
        }
        security.checkPackageAccess(packageName);
      }
    }
    catch (SecurityException e)
    {
      throw e;
    }
    Class providerClass;
    if (cl == null) {
      providerClass = Class.forName(className);
    } else {
      try
      {
        providerClass = cl.loadClass(className);
      }
      catch (ClassNotFoundException x)
      {
        Class providerClass;
        Class providerClass;
        if (doFallback)
        {
          ClassLoader current = ObjectFactory.class.getClassLoader();
          if (current == null)
          {
            providerClass = Class.forName(className);
          }
          else
          {
            Class providerClass;
            if (cl != current)
            {
              cl = current;
              providerClass = cl.loadClass(className);
            }
            else
            {
              throw x;
            }
          }
        }
        else
        {
          throw x;
        }
      }
    }
    Class providerClass;
    return providerClass;
  }
  
  private static Object findJarServiceProvider(String factoryId)
    throws ObjectFactory.ConfigurationError
  {
    SecuritySupport ss = SecuritySupport.getInstance();
    String serviceId = "META-INF/services/" + factoryId;
    InputStream is = null;
    
    ClassLoader cl = findClassLoader();
    
    is = ss.getResourceAsStream(cl, serviceId);
    if (is == null)
    {
      ClassLoader current = ObjectFactory.class.getClassLoader();
      if (cl != current)
      {
        cl = current;
        is = ss.getResourceAsStream(cl, serviceId);
      }
    }
    if (is == null) {
      return null;
    }
    BufferedReader rd;
    try
    {
      rd = new BufferedReader(new InputStreamReader(is, "UTF-8"), 80);
    }
    catch (UnsupportedEncodingException e)
    {
      rd = new BufferedReader(new InputStreamReader(is), 80);
    }
    String factoryClassName = null;
    try
    {
      factoryClassName = rd.readLine();
      rd.close();
    }
    catch (IOException x)
    {
      return null;
    }
    if ((factoryClassName != null) && (!"".equals(factoryClassName))) {
      return newInstance(factoryClassName, cl, false);
    }
    return null;
  }
  
  static class ConfigurationError
    extends Error
  {
    private Exception exception;
    
    ConfigurationError(String msg, Exception x)
    {
      super();
      exception = x;
    }
    
    Exception getException()
    {
      return exception;
    }
  }
}

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

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;

class SecuritySupport
{
  private static final Object securitySupport;
  
  static
  {
    SecuritySupport ss = null;
    try
    {
      Class c = Class.forName("java.security.AccessController");
      
      ss = new SecuritySupport12();
    }
    catch (Exception ex) {}finally
    {
      if (ss == null) {
        ss = new SecuritySupport();
      }
      securitySupport = ss;
    }
  }
  
  static SecuritySupport getInstance()
  {
    return (SecuritySupport)securitySupport;
  }
  
  ClassLoader getContextClassLoader()
  {
    return null;
  }
  
  ClassLoader getSystemClassLoader()
  {
    return null;
  }
  
  ClassLoader getParentClassLoader(ClassLoader cl)
  {
    return null;
  }
  
  String getSystemProperty(String propName)
  {
    return System.getProperty(propName);
  }
  
  FileInputStream getFileInputStream(File file)
    throws FileNotFoundException
  {
    return new FileInputStream(file);
  }
  
  InputStream getResourceAsStream(ClassLoader cl, String name)
  {
    InputStream ris;
    InputStream ris;
    if (cl == null) {
      ris = ClassLoader.getSystemResourceAsStream(name);
    } else {
      ris = cl.getResourceAsStream(name);
    }
    return ris;
  }
  
  boolean getFileExists(File f)
  {
    return f.exists();
  }
  
  long getLastModified(File f)
  {
    return f.lastModified();
  }
}

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

import java.security.PrivilegedAction;

class SecuritySupport12$1
  implements PrivilegedAction
{
  private final SecuritySupport12 this$0;
  
  SecuritySupport12$1(SecuritySupport12 paramSecuritySupport12)
  {
    this$0 = paramSecuritySupport12;
  }
  
  public Object run()
  {
    ClassLoader cl = null;
    try
    {
      cl = Thread.currentThread().getContextClassLoader();
    }
    catch (SecurityException ex) {}
    r
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