nekohtml-1.9.14

rentEntity.access$300(fCurrentEntity);
          }
          else if ((c == 13) || (c == 10))
          {
            fStringBuffer.append('\n');
            if (c == 13)
            {
              c = fCurrentEntity.read();
              if (c != 10)
              {
                fCurrentEntity.offset -= 1;
                fCurrentEntity.characterOffset_ -= 1;
              }
            }
            HTMLScanner.CurrentEntity.access$1500(fCurrentEntity);
          }
          else
          {
            if (c == -1) {
              break;
            }
            fStringBuffer.append((char)c);
          }
        }
        XMLString data = fStringBuffer;
        if (fDocumentHandler != null)
        {
          fEndLineNumber = fCurrentEntity.getLineNumber();
          fEndColumnNumber = HTMLScanner.CurrentEntity.access$100(fCurrentEntity);
          fEndCharacterOffset = HTMLScanner.CurrentEntity.access$200(fCurrentEntity);
          fDocumentHandler.processingInstruction(target, data, locationAugs());
        }
      }
      else
      {
        int beginLineNumber = fBeginLineNumber;
        int beginColumnNumber = fBeginColumnNumber;
        int beginCharacterOffset = fBeginCharacterOffset;
        fAttributes.removeAllAttributes();
        int aindex = 0;
        while (scanPseudoAttribute(fAttributes)) {
          if (fAttributes.getValue(aindex).length() == 0)
          {
            fAttributes.removeAttributeAt(aindex);
          }
          else
          {
            fAttributes.getName(aindex, fQName);
            fQName.rawname = fQName.rawname.toLowerCase();
            fAttributes.setName(aindex, fQName);
            aindex++;
          }
        }
        if (fDocumentHandler != null)
        {
          String version = fAttributes.getValue("version");
          String encoding = fAttributes.getValue("encoding");
          String standalone = fAttributes.getValue("standalone");
          
          boolean xmlDeclNow = (fIgnoreSpecifiedCharset) || (!changeEncoding(encoding));
          if (xmlDeclNow)
          {
            fBeginLineNumber = beginLineNumber;
            fBeginColumnNumber = beginColumnNumber;
            fBeginCharacterOffset = beginCharacterOffset;
            fEndLineNumber = fCurrentEntity.getLineNumber();
            fEndColumnNumber = HTMLScanner.CurrentEntity.access$100(fCurrentEntity);
            fEndCharacterOffset = HTMLScanner.CurrentEntity.access$200(fCurrentEntity);
            fDocumentHandler.xmlDecl(version, encoding, standalone, locationAugs());
          }
        }
      }
      HTMLScanner.CurrentEntity.access$400(fCurrentEntity, ")scanPI: ");
    }
    
    protected String scanStartElement(boolean[] empty)
      throws IOException
    {
      String ename = scanName();
      int length = ename != null ? ename.length() : 0;
      int c = length > 0 ? ename.charAt(0) : -1;
      if ((length == 0) || (((c < 97) || (c > 122)) && ((c < 65) || (c > 90))))
      {
        if (fReportErrors) {
          fErrorReporter.reportError("HTML1009", null);
        }
        if ((fDocumentHandler != null) && (fElementCount >= fElementDepth))
        {
          fStringBuffer.clear();
          fStringBuffer.append('<');
          if (length > 0) {
            fStringBuffer.append(ename);
          }
          fDocumentHandler.characters(fStringBuffer, null);
        }
        return null;
      }
      ename = HTMLScanner.modifyName(ename, fNamesElems);
      fAttributes.removeAllAttributes();
      int beginLineNumber = fBeginLineNumber;
      int beginColumnNumber = fBeginColumnNumber;
      int beginCharacterOffset = fBeginCharacterOffset;
      while (scanAttribute(fAttributes, empty)) {}
      fBeginLineNumber = beginLineNumber;
      fBeginColumnNumber = beginColumnNumber;
      fBeginCharacterOffset = beginCharacterOffset;
      if ((fByteStream != null) && (fElementDepth == -1)) {
        if (ename.equalsIgnoreCase("META"))
        {
          String httpEquiv = HTMLScanner.getValue(fAttributes, "http-equiv");
          if ((httpEquiv != null) && (httpEquiv.equalsIgnoreCase("content-type")))
          {
            String content = HTMLScanner.getValue(fAttributes, "content");
            if (content != null)
            {
              content = removeSpaces(content);
              int index1 = content.toLowerCase().indexOf("charset=");
              if ((index1 != -1) && (!fIgnoreSpecifiedCharset))
              {
                int index2 = content.indexOf(';', index1);
                String charset = index2 != -1 ? content.substring(index1 + 8, index2) : content.substring(index1 + 8);
                changeEncoding(charset);
              }
            }
          }
        }
        else if (ename.equalsIgnoreCase("BODY"))
        {
          fByteStream.clear();
          fByteStream = null;
        }
        else
        {
          HTMLElements.Element element = HTMLElements.getElement(ename);
          if ((parent != null) && (parent.length > 0) && 
            (parent[0].code == 14))
          {
            fByteStream.clear();
            fByteStream = null;
          }
        }
      }
      if ((fDocumentHandler != null) && (fElementCount >= fElementDepth))
      {
        fQName.setValues(null, ename, ename, null);
        
        fEndLineNumber = fCurrentEntity.getLineNumber();
        fEndColumnNumber = HTMLScanner.CurrentEntity.access$100(fCurrentEntity);
        fEndCharacterOffset = HTMLScanner.CurrentEntity.access$200(fCurrentEntity);
        if (empty[0] != 0) {
          fDocumentHandler.emptyElement(fQName, fAttributes, locationAugs());
        } else {
          fDocumentHandler.startElement(fQName, fAttributes, locationAugs());
        }
      }
      return ename;
    }
    
    private String removeSpaces(String content)
    {
      StringBuffer sb = null;
      for (int i = content.length() - 1; i >= 0; i--) {
        if (Character.isWhitespace(content.charAt(i)))
        {
          if (sb == null) {
            sb = new StringBuffer(content);
          }
          sb.deleteCharAt(i);
        }
      }
      return sb == null ? content : sb.toString();
    }
    
    private boolean changeEncoding(String charset)
    {
      if ((charset == null) || (fByteStream == null)) {
        return false;
      }
      charset = charset.trim();
      boolean encodingChanged = false;
      try
      {
        String ianaEncoding = charset;
        String javaEncoding = EncodingMap.getIANA2JavaMapping(ianaEncoding.toUpperCase());
        if (javaEncoding == null)
        {
          javaEncoding = ianaEncoding;
          if (fReportErrors) {
            fErrorReporter.reportError("HTML1001", new Object[] { ianaEncoding });
          }
        }
        if (!javaEncoding.equals(fJavaEncoding)) {
          if (!isEncodingCompatible(javaEncoding, fJavaEncoding))
          {
            if (fReportErrors) {
              fErrorReporter.reportError("HTML1015", new Object[] { javaEncoding, fJavaEncoding });
            }
          }
          else
          {
            fIso8859Encoding = ((ianaEncoding == null) || (ianaEncoding.toUpperCase().startsWith("ISO-8859")) || (ianaEncoding.equalsIgnoreCase(fDefaultIANAEncoding)));
            
            fJavaEncoding = javaEncoding;
            HTMLScanner.CurrentEntity.access$1600(fCurrentEntity, new InputStreamReader(fByteStream, javaEncoding));
            fByteStream.playback();
            fElementDepth = fElementCount;
            fElementCount = 0;
            encodingChanged = true;
          }
        }
      }
      catch (UnsupportedEncodingException e)
      {
        if (fReportErrors) {
          fErrorReporter.reportError("HTML1010", new Object[] { charset });
        }
        fByteStream.clear();
        fByteStream = null;
      }
      return encodingChanged;
    }
    
    protected boolean scanAttribute(XMLAttributesImpl attributes, boolean[] empty)
      throws IOException
    {
      return scanAttribute(attributes, empty, '/');
    }
    
    protected boolean scanPseudoAttribute(XMLAttributesImpl attributes)
      throws IOException
    {
      return scanAttribute(attributes, fSingleBoolean, '?');
    }
    
    protected boolean scanAttribute(XMLAttributesImpl attributes, boolean[] empty, char endc)
      throws IOException
    {
      boolean skippedSpaces = skipSpaces();
      fBeginLineNumber = fCurrentEntity.getLineNumber();
      fBeginColumnNumber = HTMLScanner.CurrentEntity.access$100(fCurrentEntity);
      fBeginCharacterOffset = HTMLScanner.CurrentEntity.access$200(fCurrentEntity);
      int c = fCurrentEntity.read();
      if (c == -1)
      {
        if (fReportErrors) {
          fErrorReporter.reportError("HTML1007", null);
        }
        return false;
      }
      if (c == 62) {
        return false;
      }
      if (c == 60)
      {
        HTMLScanner.CurrentEntity.access$300(fCurrentEntity);
        return false;
      }
      HTMLScanner.CurrentEntity.access$300(fCurrentEntity);
      String aname = scanName();
      if (aname == null)
      {
        if (fReportErrors) {
          fErrorReporter.reportError("HTML1011", null);
        }
        empty[0] = skipMarkup(false);
        return false;
      }
      if ((!skippedSpaces) && (fReportErrors)) {
        fErrorReporter.reportError("HTML1013", new Object[] { aname });
      }
      aname = HTMLScanner.modifyName(aname, fNamesAttrs);
      skipSpaces();
      c = fCurrentEntity.read();
      if (c == -1)
      {
        if (fReportErrors) {
          fErrorReporter.reportError("HTML1007", null);
        }
        throw new EOFException();
      }
      if ((c == 47) || (c == 62))
      {
        fQName.setValues(null, aname, aname, null);
        attributes.addAttribute(fQName, "CDATA", "");
        attributes.setSpecified(attributes.getLength() - 1, true);
        if (fAugmentations) {
          addLocationItem(attributes, attributes.getLength() - 1);
        }
        if (c == 47)
        {
          HTMLScanner.CurrentEntity.access$300(fCurrentEntity);
          empty[0] = skipMarkup(false);
        }
        return false;
      }
      if (c == 61)
      {
        skipSpaces();
        c = fCurrentEntity.read();
        if (c == -1)
        {
          if (fReportErrors) {
            fErrorReporter.reportError("HTML1007", null);
          }
          throw new EOFException();
        }
        if (c == 62)
        {
          fQName.setValues(null, aname, aname, null);
          attributes.addAttribute(fQName, "CDATA", "");
          attributes.setSpecified(attributes.getLength() - 1, true);
          if (fAugmentations) {
            addLocationItem(attributes, attributes.getLength() - 1);
          }
          return false;
        }
        fStringBuffer.clear();
        fNonNormAttr.clear();
        if ((c != 39) && (c != 34))
        {
          HTMLScanner.CurrentEntity.access$300(fCurrentEntity);
          for (;;)
          {
            c = fCurrentEntity.read();
            if ((Character.isWhitespace((char)c)) || (c == 62))
            {
              HTMLScanner.CurrentEntity.access$300(fCurrentEntity);
              break;
            }
            if (c == -1)
            {
              if (fReportErrors) {
                fErrorReporter.reportError("HTML1007", null);
              }
              throw new EOFException();
            }
            if (c == 38)
            {
              int ce = scanEntityRef(fStringBuffer2, false);
              if (ce != -1) {
                fStringBuffer.append((char)ce);
              } else {
                fStringBuffer.append(fStringBuffer2);
              }
              fNonNormAttr.append(fStringBuffer2);
            }
            else
            {
              fStringBuffer.append((char)c);
              fNonNormAttr.append((char)c);
            }
          }
          fQName.setValues(null, aname, aname, null);
          String avalue = fStringBuffer.toString();
          attributes.addAttribute(fQName, "CDATA", avalue);
          
          int lastattr = attributes.getLength() - 1;
          attributes.setSpecified(lastattr, true);
          attributes.setNonNormalizedValue(lastattr, fNonNormAttr.toString());
          if (fAugmentations) {
            addLocationItem(attributes, attributes.getLength() - 1);
          }
          return true;
        }
        char quote = (char)c;
        boolean isStart = true;
        boolean prevSpace = false;
        do
        {
          boolean acceptSpace = (!fNormalizeAttributes) || ((!isStart) && (!prevSpace));
          c = fCurrentEntity.read();
          if (c == -1)
          {
            if (!fReportErrors) {
              break;
            }
            fErrorReporter.reportError("HTML1007", null); break;
          }
          if (c == 38)
          {
            isStart = false;
            int ce = scanEntityRef(fStringBuffer2, false);
            if (ce != -1) {
              fStringBuffer.append((char)ce);
            } else {
              fStringBuffer.append(fStringBuffer2);
            }
            fNonNormAttr.append(fStringBuffer2);
          }
          else if ((c == 32) || (c == 9))
          {
            if (acceptSpace) {
              fStringBuffer.append(fNormalizeAttributes ? ' ' : (char)c);
            }
            fNonNormAttr.append((char)c);
          }
          else if ((c == 13) || (c == 10))
          {
            if (c == 13)
            {
              int c2 = fCurrentEntity.read();
              if (c2 != 10)
              {
                HTMLScanner.CurrentEntity.access$300(fCurrentEntity);
              }
              else
              {
                fNonNormAttr.append('\r');
                c = c2;
              }
            }
            if (acceptSpace) {
              fStringBuffer.append(fNormalizeAttributes ? ' ' : '\n');
            }
            HTMLScanner.CurrentEntity.access$1500(fCurrentEntity);
            fNonNormAttr.append((char)c);
          }
          else if (c != quote)
          {
            isStart = false;
            fStringBuffer.append((char)c);
            fNonNormAttr.append((char)c);
          }
          prevSpace = (c == 32) || (c == 9) || (c == 13) || (c == 10);
          isStart = (isStart) && (prevSpace);
        } while (c != quote);
        if ((fNormalizeAttributes) && (fStringBuffer.length > 0)) {
          if (fStringBuffer.ch[(fStringBuffer.length - 1)] == ' ') {
            fStringBuffer.length -= 1;
          }
        }
        fQName.setValues(null, aname, aname, null);
        String avalue = fStringBuffer.toString();
        attributes.addAttribute(fQName, "CDATA", avalue);
        
        int lastattr = attributes.getLength() - 1;
        attributes.setSpecified(lastattr, true);
        attributes.setNonNormalizedValue(lastattr, fNonNormAttr.toString());
        if (fAugmentations) {
          addLocationItem(attributes, attributes.getLength() - 1);
        }
      }
      else
      {
        fQName.setValues(null, aname, aname, null);
        attributes.addAttribute(fQName, "CDATA", "");
        attributes.setSpecified(attributes.getLength() - 1, true);
        HTMLScanner.CurrentEntity.access$300(fCurrentEntity);
        if (fAugmentations) {
          addLocationItem(attributes, attributes.getLength() - 1);
        }
      }
      return true;
    }
    
    protected void addLocationItem(XMLAttributes attributes, int index)
    {
      fEndLineNumber = fCurrentEntity.getLineNumber();
      fEndColumnNumber = HTMLScanner.CurrentEntity.access$100(fCurrentEntity);
      fEndCharacterOffset = HTMLScanner.CurrentEntity.access$200(fCurrentEntity);
      HTMLScanner.LocationItem locationItem = new HTMLScanner.LocationItem();
      locationItem.setValues(fBeginLineNumber, fBeginColumnNumber, fBeginCharacterOffset, fEndLineNumber, fEndColumnNumber, fEndCharacterOffset);
      
      Augmentations augs = attributes.getAugmentations(index);
      augs.putItem("http://cyberneko.org/html/features/augmentations", locationItem);
    }
    
    protected void scanEndElement()
      throws IOException
    {
      String ename = scanName();
      if ((fReportErrors) && (ename == null)) {
        fErrorReporter.reportError("HTML1012", null);
      }
      skipMarkup(false);
      if (ename != null)
      {
        ename = HTMLScanner.modifyName(ename, fNamesElems);
        if ((fDocumentHandler != null) && (fElementCount >= fElementDepth))
        {
          fQName.setValues(null, ename, ename, null);
          
          fEndLineNumber = fCurrentEntity.getLineNumber();
          fEndColumnNumber = HTMLScanner.CurrentEntity.access$100(fCurrentEntity);
          fEndCharacterOffset = HTMLScanner.CurrentEntity.access$200(fCurrentEntity);
          fDocumentHandler.endElement(fQName, locationAugs());
        }
      }
    }
    
    private boolean isEnded(String ename)
    {
      String content = new String(fCurrentEntity.buffer, fCurrentEntity.offset, fCurrentEntity.length - fCurrentEntity.offset);
      
      return content.toLowerCase().indexOf("</" + ename.toLowerCase() + ">") != -1;
    }
  }
  
  public class SpecialScanner
    implements HTMLScanner.Scanner
  {
    protected String fElementName;
    protected boolean fStyle;
    protected boolean fTextarea;
    protected boolean fTitle;
    private final QName fQName = new QName();
    private final XMLStringBuffer fStringBuffer = new XMLStringBuffer();
    
    public SpecialScanner() {}
    
    public HTMLScanner.Scanner setElementName(String ename)
    {
      fElementName = ename;
      fStyle = fElementName.equalsIgnoreCase("STYLE");
      fTextarea = fElementName.equalsIgnoreCase("TEXTAREA");
      fTitle = fElementName.equalsIgnoreCase("TITLE");
      return this;
    }
    
    public boolean scan(boolean complete)
      throws IOException
    {
      boolean next;
      do
      {
        try
        {
          next = false;
          switch (fScannerState)
          {
          case 0: 
            fBeginLineNumber = fCurrentEntity.getLineNumber();
            fBeginColumnNumber = HTMLScanner.CurrentEntity.access$100(fCurrentEntity);
            fBeginCharacterOffset = HTMLScanner.CurrentEntity.access$200(fCurrentEntity);
            int c = fCurrentEntity.read();
            if (c == 60)
            {
              setScannerState((short)1);
            }
            else
            {
              if (c == 38)
              {
                if ((fTextarea) || (fTitle))
                {
                  scanEntityRef(fStringBuffer, true);
                  continue;
                }
                fStringBuffer.clear();
                fStringBuffer.append('&');
              }
              else
              {
                if (c == -1)
                {
                  if (fReportErrors) {
                    fErrorReporter.reportError("HTML1007", null);
                  }
                  throw new EOFException();
                }
                HTMLScanner.CurrentEntity.access$300(fCurrentEntity);
                fStringBuffer.clear();
              }
              scanCharacters(fStringBuffer, -1);
            }
            break;
          case 1: 
            int delimiter = -1;
            int c = fCurrentEntity.read();
            if (c == 47)
            {
              String ename = scanName();
              if (ename != null)
              {
                if (ename.equalsIgnoreCase(fElementName))
                {
                  if (fCurrentEntity.read() == 62)
                  {
                    ename = HTMLScanner.modifyName(ename, fNamesElems);
                    if ((fDocumentHandler != null) && (fElementCount >= fElementDepth))
                    {
                      fQName.setValues(null, ename, ename, null);
                      
                      fEndLineNumber = fCurrentEntity.getLineNumber();
                      fEndColumnNumber = HTMLScanner.CurrentEntity.access$100(fCurrentEntity);
                      fEndCharacterOffset = HTMLScanner.CurrentEntity.access$200(fCurrentEntity);
                      fDocumentHandler.endElement(fQName, locationAugs());
                    }
                    setScanner(fContentScanner);
                    setScannerState((short)0);
                    return true;
                  }
                  HTMLScanner.CurrentEntity.access$300(fCurrentEntity);
                }
                fStringBuffer.clear();
                fStringBuffer.append("</");
                fStringBuffer.append(ename);
              }
              else
              {
                fStringBuffer.clear();
                fStringBuffer.append("</");
              }
            }
            else
            {
              fStringBuffer.clear();
              fStringBuffer.append('<');
              fStringBuffer.append((char)c);
            }
            scanCharacters(fStringBuffer, delimiter);
            setScannerState((short)0);
          }
        }
        catch (EOFException e)
        {
          setScanner(fContentScanner);
          if (fCurrentEntityStack.empty())
          {
            setScannerState((short)11);
          }
          else
          {
            fCurrentEntity = ((HTMLScanner.CurrentEntity)fCurrentEntityStack.pop());
            setScannerState((short)0);
          }
          return true;
        }
      } while ((next) || (complete));
      return true;
    }
    
    protected void scanCharacters(XMLStringBuffer buffer, int delimiter)
      throws IOException
    {
      HTMLScanner.CurrentEntity.access$400(fCurrentEntity, "(scanCharacters, delimiter=" + delimiter + ": ");
      for (;;)
      {
        int c = fCurrentEntity.read();
        if ((c == -1) || (c == 60) || (c == 38))
        {
          if (c == -1) {
            break;
          }
          HTMLScanner.CurrentEntity.access$300(fCurrentEntity); break;
        }
        if ((c == 13) || (c == 10))
        {
          HTMLScanner.CurrentEntity.access$300(fCurrentEntity);
          int newlines = skipNewlines();
          for (int i = 0; i < newlines; i++) {
            buffer.append('\n');
          }
        }
        else
        {
          buffer.append((char)c);
          if (c == 10) {
            HTMLScanner.CurrentEntity.access$1500(fCurrentEntity);
          }
        }
      }
      if (fStyle)
      {
        if (fStyleStripCommentDelims) {
          HTMLScanner.reduceToContent(buffer, "<!--", "-->");
        }
        if (fStyleStripCDATADelims) {
          HTMLScanner.reduceToContent(buffer, "<![CDATA[", "]]>");
        }
      }
      if ((length > 0) && (fDocumentHandler != null) && (fElementCount >= fElementDepth))
      {
        fEndLineNumber = fCurrentEntity.getLineNumber();
        fEndColumnNumber = HTMLScanner.CurrentEntity.access$100(fCurrentEntity);
        fEndCharacterOffset = HTMLScanner.CurrentEntity.access$200(fCurrentEntity);
        fDocumentHandler.characters(buffer, locationAugs());
      }
      HTMLScanner.CurrentEntity.access$400(fCurrentEntity, ")scanCharacters: ");
    }
  }
  
  public static class PlaybackInputStream
    extends FilterInputStream
  {
    private static final boolean DEBUG_PLAYBACK = false;
    protected boolean fPlayback = false;
    protected boolean fCleared = false;
    protected boolean fDetected = false;
    protected byte[] fByteBuffer = new byte['?'];
    protected int fByteOffset = 0;
    protected int fByteLength = 0;
    public int fPushbackOffset = 0;
    public int fPushbackLength = 0;
    
    public PlaybackInputStream(InputStream in)
    {
      super();
    }
    
    public void detectEncoding(String[] encodings)
      throws IOException
    {
      if (fDetected) {
        throw new IOException("Should not detect encoding twice.");
      }
      fDetected = true;
      int b1 = read();
      if (b1 == -1) {
        return;
      }
      int b2 = read();
      if (b2 == -1)
      {
        fPushbackLength = 1;
        return;
      }
      if ((b1 == 239) && (b2 == 187))
      {
        int b3 = read();
        if (b3 == 191)
        {
          fPushbackOffset = 3;
          encodings[0] = "UTF-8";
          encodings[1] = "UTF8";
          return;
        }
        fPushbackLength = 3;
      }
      if ((b1 == 255) && (b2 == 254))
      {
        encodings[0] = "UTF-16";
        encodings[1] = "UnicodeLittleUnmarked";
        return;
      }
      if ((b1 == 254) && (b2 == 255))
      {
        encodings[0] = "UTF-16";
        encodings[1] = "UnicodeBigUnmarked";
        return;
      }
      fPushbackLength = 2;
    }
    
    public void playback()
    {
      fPlayback = true;
    }
    
    public void clear()
    {
      if (!fPlayback)
      {
        fCleared = true;
        fByteBuffer = null;
      }
    }
    
    public int read()
      throws IOException
    {
      if (fPushbackOffset < fPushbackLength) {
        return fByteBuffer[(fPushbackOffset++)];
      }
      if (fCleared) {
        return in.read();
      }
      if (fPlayback)
      {
        int c = fByteBuffer[(fByteOffset++)];
        if (fByteOffset == fByteLength)
        {
          fCleared = true;
          fByteBuffer = null;
        }
        return c;
      }
      int c = in.read();
      if (c != -1)
      {
        if (fByteLength == fByteBuffer.length)
        {
          byte[] newarray = new byte[fByteLength + 1024];
          System.arraycopy(fByteBuffer, 0, newarray, 0, fByteLength);
          fByteBuffer = newarray;
        }
        fByteBuffer[(fByteLength++)] = ((byte)c);
      }
      return c;
    }
    
    public int read(byte[] array)
      throws IOException
    {
      return read(array, 0, array.length);
    }
    
    public int read(byte[] array, int offset, int length)
      throws IOException
    {
      if (fPushbackOffset < fPushbackLength)
      {
        int count = fPushbackLength - fPushbackOffset;
        if (count > length) {
          count = length;
        }
        System.arraycopy(fByteBuffer, fPushbackOffset, array, offset, count);
        fPushbackOffset += count;
        return count;
      }
      if (fCleared) {
        return in.read(array, offset, length);
      }
      if (fPlayback)
      {
        if (fByteOffset + length > fByteLength) {
          length = fByteLength - fByteOffset;
        }
        System.arraycopy(fByteBuffer, fByteOffset, array, offset, length);
        fByteOffset += length;
        if (fByteOffset == fByteLength)
        {
          fCleared = true;
          fByteBuffer = null;
        }
        return length;
      }
      int count = in.read(array, offset, length);
      if (count != -1)
      {
        if (fByteLength + count > fByteBuffer.length)
        {
          byte[] newarray = new byte[fByteLength + count + 512];
          System.arraycopy(fByteBuffer, 0, newarray, 0, fByteLength);
          fByteBuffer = newarray;
        }
        System.arraycopy(array, offset, fByteBuffer, fByteLength, count);
        fByteLength += count;
      }
      return count;
    }
  }
  
  protected static class LocationItem
    implements HTMLEventInfo, Cloneable
  {
    protected int fBeginLineNumber;
    protected int fBeginColumnNumber;
    protected int fBeginCharacterOffset;
    protected int fEndLineNumber;
    protected int fEndColumnNumber;
    protected int fEndCharacterOffset;
    
    public LocationItem() {}
    
    LocationItem(LocationItem other)
    {
      setValues(fBeginLineNumber, fBeginColumnNumber, fBeginCharacterOffset, fEndLineNumber, fEndColumnNumber, fEndCharacterOffset);
    }
    
    public void setValues(int beginLine, int beginColumn, int beginOffset, int endLine, int endColumn, int endOffset)
    {
      fBeginLineNumber = beginLine;
      fBeginColumnNumber = beginColumn;
      fBeginCharacterOffset = beginOffset;
      fEndLineNumber = endLine;
      fEndColumnNumber = endColumn;
      fEndCharacterOffset = endOffset;
    }
    
    public int getBeginLineNumber()
    {
      return fBeginLineNumber;
    }
    
    public int getBeginColumnNumber()
    {
      return fBeginColumnNumber;
    }
    
    public int getBeginCharacterOffset()
    {
      return fBeginCharacterOffset;
    }
    
    public int getEndLineNumber()
    {
      return fEndLineNumber;
    }
    
    public int getEndColumnNumber()
    {
      return fEndColumnNumber;
    }
    
    public int getEndCharacterOffset()
    {
      return fEndCharacterOffset;
    }
    
    public boolean isSynthesized()
    {
      return false;
    }
    
    public String toString()
    {
      StringBuffer str = new StringBuffer();
      str.append(fBeginLineNumber);
      str.append(':');
      str.append(fBeginColumnNumber);
      str.append(':');
      str.append(fBeginCharacterOffset);
      str.append(':');
      str.append(fEndLineNumber);
      str.append(':');
      str.append(fEndColumnNumber);
      str.append(':');
      str.append(fEndCharacterOffset);
      return str.toString();
    }
  }
  
  boolean isEncodingCompatible(String encoding1, String encoding2)
  {
    String reference = "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html;charset=";
    try
    {
      byte[] bytesEncoding1 = "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html;charset=".getBytes(encoding1);
      String referenceWithEncoding2 = new String(bytesEncoding1, encoding2);
      return "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html;charset=".equals(referenceWithEncoding2);
    }
    catch (UnsupportedEncodingException e) {}
    return false;
  }
  
  private boolean endsWith(XMLStringBuffer buffer, String string)
  {
    int l = string.length();
    if (length < l) {
      return false;
    }
    String s = new String(ch, length - l, l);
    return string.equals(s);
  }
  
  protected int readPreservingBufferContent()
    throws IOException
  {
    fCurrentEntity.debugBufferIfNeeded("(read: ");
    if ((fCurrentEntity.offset == fCurrentEntity.length) && 
      (fCurrentEntity.load(fCurrentEntity.length) < 1)) {
      return -1;
    }
    char c = fCurrentEntity.getNextChar();
    fCurrentEntity.debugBufferIfNeeded(")read: ", " -> " + c);
    return c;
  }
  
  private boolean endCommentAvailable()
    throws IOException
  {
    int nbCaret = 0;
    int originalOffset = fCurrentEntity.offset;
    int originalColumnNumber = fCurrentEntity.getColumnNumber();
    int originalCharacterOffset = fCurrentEntity.getCharacterOffset();
    for (;;)
    {
      int c = readPreservingBufferContent();
      if (c == -1)
      {
        fCurrentEntity.restorePosition(originalOffset, originalColumnNumber, originalCharacterOffset);
        return false;
      }
      if ((c == 62) && (nbCaret >= 2))
      {
        fCurrentEntity.restorePosition(originalOffset, originalColumnNumber, originalCharacterOffset);
        return true;
      }
      if (c == 45) {
        nbCaret++;
      } else {
        nbCaret = 0;
      }
    }
  }
  
  static void reduceToContent(XMLStringBuffer buffer, String startMarker, String endMarker)
  {
    int i = 0;
    int startContent = -1;
    int l1 = startMarker.length();
    int l2 = endMarker.length();
    while (i < length - l1 - l2)
    {
      char c = ch[(offset + i)];
      if (Character.isWhitespace(c))
      {
        i++;
      }
      else
      {
        if ((c == startMarker.charAt(0)) && (startMarker.equals(new String(ch, offset + i, l1))))
        {
          startContent = offset + i + l1;
          break;
        }
        return;
      }
    }
    if (startContent == -1) {
      return;
    }
    i = length - 1;
    while (i > startContent + l2)
    {
      char c = ch[(offset + i)];
      if (Character.isWhitespace(c))
      {
        i--;
      }
      else
      {
        if ((c == endMarker.charAt(l2 - 1)) && (endMarker.equals(new String(ch, offset + i - l2 + 1, l2))))
        {
          length = (offset + i - startContent - 2);
          offset = startContent;
          return;
        }
        return;
      }
    }
  }
}

/* Location:
 * Qualified Name:     org.cyberneko.html.HTMLScanner
 * 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;

class HTMLTagBalancer$ElementEntry
{
  private final QName name_;
  private final Augmentations augs_;
  
  HTMLTagBalancer$ElementEntry(QName element, Augmentations augs)
  {
    name_ = new QName(element);
    augs_ = (augs == null ? null : new HTMLAugmentations(augs));
  }
}

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

import org.apache.xerces.util.XMLAttributesImpl;
import org.apache.xerces.xni.QName;
import org.apache.xerces.xni.XMLAttributes;

public class HTMLTagBalancer$Info
{
  public HTMLElements.Element element;
  public QName qname;
  public XMLAttributes attributes;
  
  public HTMLTagBalancer$Info(HTMLElements.Element element, QName qname)
  {
    this(element, qname, null);
  }
  
  public HTMLTagBalancer$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;
  }
}

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

public class HTMLTagBalancer$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();
  }
}

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

import java.util.ArrayList;
import java.util.List;
import org.apache.xerces.util.XMLAttributesImpl;
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.XMLComponentManager;
import org.apache.xerces.xni.parser.XMLConfigurationException;
import org.apache.xerces.xni.parser.XMLDocumentFilter;
import org.apache.xerces.xni.parser.XMLDocumentSource;
import org.cyberneko.html.xercesbridge.XercesBridge;

public class HTMLTagBalancer
  implements XMLDocumentFilter, HTMLComponent
{
  protected static final String NAMESPACES = "http://xml.org/sax/features/namespaces";
  protected static final String AUGMENTATIONS = "http://cyberneko.org/html/features/augmentations";
  protected static final String REPORT_ERRORS = "http://cyberneko.org/html/features/report-errors";
  protected static final String DOCUMENT_FRAGMENT_DEPRECATED = "http://cyberneko.org/html/features/document-fragment";
  protected static final String DOCUMENT_FRAGMENT = "http://cyberneko.org/html/features/balance-tags/document-fragment";
  protected static final String IGNORE_OUTSIDE_CONTENT = "http://cyberneko.org/html/features/balance-tags/ignore-outside-content";
  private static final String[] RECOGNIZED_FEATURES = { "http://xml.org/sax/features/namespaces", "http://cyberneko.org/html/features/augmentations", "http://cyberneko.org/html/features/report-errors", "http://cyberneko.org/html/features/document-fragment", "http://cyberneko.org/html/features/balance-tags/document-fragment", "http://cyberneko.org/html/features/balance-tags/ignore-outside-content" };
  private static final Boolean[] RECOGNIZED_FEATURES_DEFAULTS = { null, null, null, null, Boolean.FALSE, Boolean.FALSE };
  protected static final String NAMES_ELEMS = "http://cyberneko.org/html/properties/names/elems";
  protected static final String NAMES_ATTRS = "http://cyberneko.org/html/properties/names/attrs";
  protected static final String ERROR_REPORTER = "http://cyberneko.org/html/properties/error-reporter";
  public static final String FRAGMENT_CONTEXT_STACK = "http://cyberneko.org/html/properties/balance-tags/fragment-context-stack";
  private static final String[] RECOGNIZED_PROPERTIES = { "http://cyberneko.org/html/properties/names/elems", "http://cyberneko.org/html/properties/names/attrs", "http://cyberneko.org/html/properties/error-reporter", "http://cyberneko.org/html/properties/balance-tags/fragment-context-stack" };
  private static final Object[] RECOGNIZED_PROPERTIES_DEFAULTS = { null, null, null, null };
  protected static final short NAMES_NO_CHANGE = 0;
  protected static final short NAMES_MATCH = 0;
  protected static final short NAMES_UPPERCASE = 1;
  protected static final short NAMES_LOWERCASE = 2;
  protected static final HTMLEventInfo SYNTHESIZED_ITEM = new HTMLEventInfo.SynthesizedItem();
  protected boolean fNamespaces;
  protected boolean fAugmentations;
  protected boolean fReportErrors;
  protected boolean fDocumentFragment;
  protected boolean fIgnoreOutsideContent;
  protected short fNamesElems;
  protected short fNamesAttrs;
  protected HTMLErrorReporter fErrorReporter;
  protected XMLDocumentSource fDocumentSource;
  protected XMLDocumentHandler fDocumentHandler;
  protected final InfoStack fElementStack;
  protected final InfoStack fInlineStack;
  protected boolean fSeenAnything;
  protected boolean fSeenDoctype;
  protected boolean fSeenRootElement;
  protected boolean fSeenRootElementEnd;
  protected boolean fSeenHeadElement;
  protected boolean fSeenBodyElement;
  protected boolean fOpenedForm;
  private final QName fQName;
  private final XMLAttributes fEmptyAttrs;
  private final HTMLAugmentations fInfosetAugs;
  protected HTMLTagBalancingListener tagBalancingListener;
  private LostText lostText_;
  private boolean forcedStartElement_;
  private boolean forcedEndElement_;
  private QName[] fragmentContextStack_;
  private int fragmentContextStackSize_;
  private List endElementsBuffer_;
  
  public HTMLTagBalancer()
  {
    fElementStack = new InfoStack();
    
    fInlineStack = new InfoStack();
    
    fQName = new QName();
    
    fEmptyAttrs = new XMLAttributesImpl();
    
    fInfosetAugs = new HTMLAugmentations();
    
    lostText_ = new LostText();
    
    forcedStartElement_ = false;
    forcedEndElement_ = false;
    
    fra
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