jh-2.0_05

16:37:52.630 INFO  jd.cli.Main - Decompiling jh-2.0_05.jar
package com.sun.java.help.impl;

import java.io.CharConversionException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.io.Reader;
import java.io.UnsupportedEncodingException;
import java.net.URLConnection;

public final class XmlReader
  extends Reader
{
  private boolean closed;
  private InputStreamReader in;
  private InputStream raw;
  private byte[] buffer;
  private boolean isASCII;
  private boolean isLatin1;
  private int offset;
  private int length;
  private char nextChar;
  private int switchover;
  private String encodingAssigned;
  
  public static Reader createReader(URLConnection paramURLConnection)
    throws IOException
  {
    String str = getEncodingFromContentType(paramURLConnection.getContentType());
    if (str == null) {
      return createReader(paramURLConnection.getInputStream());
    }
    return createReader(paramURLConnection.getInputStream(), str);
  }
  
  private static String getEncodingFromContentType(String paramString)
  {
    debug("type=" + paramString);
    if (paramString == null) {
      return null;
    }
    int i = paramString.indexOf(";");
    if (i > -1)
    {
      String str = paramString.substring(i);
      
      paramString = paramString.substring(0, i).trim();
      if (paramString.compareTo("text/xml") == 0) {
        return getCharsetFromContentTypeParameters(str);
      }
    }
    return null;
  }
  
  private static String getCharsetFromContentTypeParameters(String paramString)
  {
    String str = null;
    try
    {
      int i = paramString.indexOf(';');
      if ((i > -1) && (i < paramString.length() - 1)) {
        paramString = paramString.substring(i + 1);
      }
      if (paramString.length() > 0)
      {
        HeaderParser localHeaderParser = new HeaderParser(paramString);
        return localHeaderParser.findValue("charset");
      }
    }
    catch (IndexOutOfBoundsException localIndexOutOfBoundsException) {}catch (NullPointerException localNullPointerException) {}catch (Exception localException)
    {
      System.err.println("Indexer.getCharsetFromContentTypeParameters failed on: " + paramString);
      localException.printStackTrace();
    }
    return str;
  }
  
  public static Reader createReader(InputStream paramInputStream)
    throws IOException
  {
    return new XmlReader(paramInputStream);
  }
  
  public static Reader createReader(InputStream paramInputStream, String paramString)
    throws IOException
  {
    if (paramString == null) {
      return new XmlReader(paramInputStream);
    }
    if (("UTF-16".equalsIgnoreCase(paramString)) || ("ISO-106460-UCS-2".equalsIgnoreCase(paramString)))
    {
      paramString = "Unicode";
    }
    else
    {
      if ("UTF-8".equalsIgnoreCase(paramString)) {
        return new XmlReader(paramInputStream, "UTF-8");
      }
      if ("EUC-JP".equalsIgnoreCase(paramString))
      {
        paramString = "EUCJIS";
      }
      else
      {
        if (isAsciiName(paramString)) {
          return new XmlReader(paramInputStream, "US-ASCII");
        }
        if (isLatinName(paramString)) {
          return new XmlReader(paramInputStream, "ISO-8859-1");
        }
      }
    }
    return new InputStreamReader(paramInputStream, paramString);
  }
  
  private XmlReader(InputStream paramInputStream, String paramString)
    throws IOException
  {
    buffer = new byte['?'];
    length = 0;
    raw = paramInputStream;
    if ("US-ASCII".equals(paramString))
    {
      setASCII();
    }
    else if ("ISO-8859-1".equals(paramString))
    {
      setLatin1();
    }
    else
    {
      if (!"UTF-8".equals(paramString)) {
        throw new UnsupportedEncodingException(paramString);
      }
      setUTF8();
    }
  }
  
  private static boolean isAsciiName(String paramString)
  {
    return ("US-ASCII".equalsIgnoreCase(paramString)) || ("ASCII".equalsIgnoreCase(paramString));
  }
  
  private static boolean isLatinName(String paramString)
  {
    return ("ISO-8859-1".equalsIgnoreCase(paramString)) || ("Latin1".equalsIgnoreCase(paramString)) || ("8859_1".equalsIgnoreCase(paramString));
  }
  
  private void setASCII()
  {
    encodingAssigned = "US-ASCII";
    isASCII = true;
    isLatin1 = false;
    offset = 0;
  }
  
  private void setLatin1()
  {
    encodingAssigned = "ISO-8859-1";
    isASCII = false;
    isLatin1 = true;
    offset = 0;
  }
  
  private void setUTF8()
  {
    encodingAssigned = "UTF-8";
    isASCII = false;
    isLatin1 = false;
    offset = 0;
  }
  
  public String getEncoding()
  {
    return encodingAssigned;
  }
  
  private XmlReader(InputStream paramInputStream)
    throws IOException
  {
    raw = paramInputStream;
    switchover = -1;
    buffer = new byte['?'];
    offset = (length = 0);
    isLatin1 = true;
    int i;
    switch (i = read())
    {
    case 0: 
      if (((i = read()) == 60) && ((i = read()) == 0) && ((i = read()) == 63))
      {
        setSwitchover("UnicodeBig");
        
        return;
      }
      throw new UnsupportedEncodingException("UCS-4 (?)");
    case 60: 
      switch (i = read())
      {
      default: 
        break;
      case 0: 
        if ((read() == 63) && (read() == 0))
        {
          setSwitchover("UnicodeLittle");
          
          return;
        }
        throw new UnsupportedEncodingException("UCS-4");
      case 63: 
        if ((read() == 120) && (read() == 109) && (read() == 108) && (read() == 32))
        {
          guessEncoding(); return;
        }
        break;
      }
      break;
    case 254: 
      if ((i = read()) == 255)
      {
        setSwitchover("UnicodeBig");
        offset = 2; return;
      }
      break;
    case 255: 
      if ((i = read()) == 254)
      {
        setSwitchover("UnicodeLittle");
        offset = 2; return;
      }
      break;
    case -1: 
      return;
    }
    setUTF8();
  }
  
  private void setSwitchover(String paramString)
    throws IOException
  {
    switchover = offset;
    encodingAssigned = paramString;
    offset = 0;
  }
  
  private void doSwitchover()
    throws IOException
  {
    if (offset != switchover) {
      throw new InternalError();
    }
    in = new InputStreamReader(raw, encodingAssigned);
    buffer = null;
    switchover = -1;
  }
  
  private void guessEncoding()
    throws IOException
  {
    StringBuffer localStringBuffer1 = new StringBuffer();
    StringBuffer localStringBuffer2 = null;
    String str1 = null;
    int j = 0;
    int k = 0;
    int m = 0;
    for (int n = 0; n < 100; n++)
    {
      int i;
      if ((i = read()) == -1)
      {
        setASCII();
        return;
      }
      if (!Character.isWhitespace((char)i))
      {
        if (i == 63)
        {
          m = 1;
        }
        else if (m != 0)
        {
          if (i == 62) {
            break;
          }
          m = 0;
        }
        if ((str1 == null) || (j == 0))
        {
          if (localStringBuffer2 == null)
          {
            if (!Character.isWhitespace((char)i))
            {
              localStringBuffer2 = localStringBuffer1;
              localStringBuffer1.setLength(0);
              localStringBuffer1.append((char)i);
              j = 0;
            }
          }
          else if (Character.isWhitespace((char)i))
          {
            str1 = localStringBuffer2.toString();
          }
          else if (i == 61)
          {
            if (str1 == null) {
              str1 = localStringBuffer2.toString();
            }
            j = 1;
            localStringBuffer2 = null;
            k = 0;
          }
          else
          {
            localStringBuffer2.append((char)i);
          }
        }
        else if (!Character.isWhitespace((char)i))
        {
          if ((i == 34) || (i == 39))
          {
            if (k == 0)
            {
              k = (char)i;
              localStringBuffer1.setLength(0);
              continue;
            }
            if (i == k)
            {
              if ("encoding".equals(str1))
              {
                String str2 = localStringBuffer1.toString();
                for (n = 0; n < str2.length(); n++)
                {
                  i = str2.charAt(n);
                  if (((i < 65) || (i > 90)) && ((i < 97) || (i > 122)) && (
                  
                    (n <= 0) || ((i != 45) && ((i < 48) || (i > 57)) && (i != 46) && (i != 95)))) {
                    break label427;
                  }
                }
                if (isAsciiName(str2))
                {
                  setASCII();
                  return;
                }
                if (isLatinName(str2))
                {
                  setLatin1();
                  return;
                }
                if (("UTF-8".equalsIgnoreCase(str2)) || ("UTF8".equalsIgnoreCase(str2))) {
                  break;
                }
                if ("EUC-JP".equalsIgnoreCase(str2)) {
                  str2 = "EUCJIS";
                }
                setSwitchover(str2);
                return;
              }
              str1 = null;
              continue;
            }
          }
          localStringBuffer1.append((char)i);
        }
      }
    }
    label427:
    setUTF8();
  }
  
  private char utf8char()
    throws IOException
  {
    if (nextChar != 0)
    {
      c = nextChar;
      nextChar = '\000';
      return c;
    }
    char c = (char)buffer[offset];
    if ((c & 0x80) == 0)
    {
      offset += 1;
      return c;
    }
    if (isASCII) {
      throw new CharConversionException("Not US-ASCII:  0x" + Integer.toHexString(c & 0xFF));
    }
    int j = offset;
    int i;
    try
    {
      if ((buffer[j] & 0xE0) == 192)
      {
        i = (buffer[(j++)] & 0x1F) << 6;
        i += (buffer[(j++)] & 0x3F);
        c = (char)i;
        i = 0;
      }
      else if ((buffer[j] & 0xF0) == 224)
      {
        i = (buffer[(j++)] & 0xF) << 12;
        i += ((buffer[(j++)] & 0x3F) << 6);
        i += (buffer[(j++)] & 0x3F);
        c = (char)i;
        i = 0;
      }
      else if ((buffer[j] & 0xF8) == 240)
      {
        i = (buffer[(j++)] & 0x7) << 18;
        i += ((buffer[(j++)] & 0x3F) << 12);
        i += ((buffer[(j++)] & 0x3F) << 6);
        i += (buffer[(j++)] & 0x3F);
        
        i -= 65536;
        c = (char)(55296 + (i >> 10));
        i = 56320 + (i & 0x3FF);
      }
      else
      {
        throw new CharConversionException("Illegal XML character 0x" + Integer.toHexString(buffer[offset] & 0xFF));
      }
    }
    catch (ArrayIndexOutOfBoundsException localArrayIndexOutOfBoundsException)
    {
      c = '\000';
      i = 0;
    }
    if (j > length)
    {
      System.arraycopy(buffer, offset, buffer, 0, length - offset);
      length -= offset;
      offset = 0;
      j = raw.read(buffer, length, buffer.length - length);
      if (j < 0) {
        throw new CharConversionException("Partial UTF-8 char");
      }
      length += j;
      return utf8char();
    }
    for (offset += 1; offset < j; offset += 1) {
      if ((buffer[offset] & 0xC0) != 128) {
        throw new CharConversionException("Malformed UTF-8 char");
      }
    }
    nextChar = ((char)i);
    return c;
  }
  
  public int read(char[] paramArrayOfChar, int paramInt1, int paramInt2)
    throws IOException
  {
    if (closed) {
      return -1;
    }
    if ((switchover > 0) && (offset == switchover)) {
      doSwitchover();
    }
    if (in != null) {
      return in.read(paramArrayOfChar, paramInt1, paramInt2);
    }
    if (offset >= length)
    {
      offset = 0;
      length = raw.read(buffer, 0, buffer.length);
    }
    if (length <= 0) {
      return -1;
    }
    int i;
    if ((encodingAssigned == null) || (isLatin1)) {
      for (i = 0; (i < paramInt2) && (offset < length);)
      {
        paramArrayOfChar[(paramInt1++)] = ((char)(buffer[(offset++)] & 0xFF));i++; continue;
        for (i = 0; (i < paramInt2) && (offset < length); i++) {
          paramArrayOfChar[(paramInt1++)] = utf8char();
        }
      }
    }
    return i;
  }
  
  public int read()
    throws IOException
  {
    if (closed) {
      return -1;
    }
    if ((switchover > 0) && (offset == switchover)) {
      doSwitchover();
    }
    if (in != null) {
      return in.read();
    }
    if (offset >= length) {
      if (encodingAssigned == null)
      {
        if (length == buffer.length) {
          throw new InternalError("too much peekahead");
        }
        int i = raw.read(buffer, offset, 1);
        if (i <= 0) {
          return -1;
        }
        length += i;
      }
      else
      {
        offset = 0;
        length = raw.read(buffer, 0, buffer.length);
        if (length <= 0) {
          return -1;
        }
      }
    }
    if ((isLatin1) || (encodingAssigned == null)) {
      return buffer[(offset++)] & 0xFF;
    }
    return utf8char();
  }
  
  public boolean markSupported()
  {
    return (in != null) && (in.markSupported());
  }
  
  public void mark(int paramInt)
    throws IOException
  {
    if (in != null) {
      in.mark(paramInt);
    }
  }
  
  public void reset()
    throws IOException
  {
    if (in != null) {
      in.reset();
    }
  }
  
  public long skip(long paramLong)
    throws IOException
  {
    if (paramLong < 0L) {
      return 0L;
    }
    if (in != null) {
      return in.skip(paramLong);
    }
    long l = length - offset;
    if (l >= paramLong)
    {
      offset += (int)paramLong;
      return paramLong;
    }
    offset = ((int)(offset + l));
    return l + raw.skip(paramLong - l);
  }
  
  public boolean ready()
    throws IOException
  {
    if (in != null) {
      return in.ready();
    }
    return (length > offset) || (raw.available() != 0);
  }
  
  public void close()
    throws IOException
  {
    if (closed) {
      return;
    }
    if (in != null) {
      in.close();
    } else {
      raw.close();
    }
    closed = true;
  }
  
  private static boolean debug = false;
  
  private static void debug(String paramString)
  {
    if (debug) {
      System.out.println("XmlReader: " + paramString);
    }
  }
}

/* Location:
 * Qualified Name:     com.sun.java.help.impl.XmlReader
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.java.help.impl;

public class HeaderParser
{
  String raw;
  String[][] tab;
  
  public HeaderParser(String paramString)
  {
    raw = paramString;
    tab = new String[10][2];
    parse();
  }
  
  private void parse()
  {
    if (raw != null)
    {
      raw = raw.trim();
      char[] arrayOfChar = raw.toCharArray();
      int i = 0;int j = 0;int k = 0;
      int m = 1;
      int n = 0;
      int i1 = arrayOfChar.length;
      while (j < i1)
      {
        int i2 = arrayOfChar[j];
        if (i2 == 61)
        {
          tab[k][0] = new String(arrayOfChar, i, j - i).toLowerCase();
          m = 0;
          j++;
          i = j;
        }
        else if (i2 == 34)
        {
          if (n != 0)
          {
            tab[(k++)][1] = new String(arrayOfChar, i, j - i);
            n = 0;
            do
            {
              j++;
            } while ((j < i1) && ((arrayOfChar[j] == ' ') || (arrayOfChar[j] == ',')));
            m = 1;
            i = j;
          }
          else
          {
            n = 1;
            j++;
            i = j;
          }
        }
        else if ((i2 == 32) || (i2 == 44))
        {
          if (n != 0)
          {
            j++;
          }
          else
          {
            if (m != 0) {
              tab[(k++)][0] = new String(arrayOfChar, i, j - i).toLowerCase();
            } else {
              tab[(k++)][1] = new String(arrayOfChar, i, j - i);
            }
            while ((j < i1) && ((arrayOfChar[j] == ' ') || (arrayOfChar[j] == ','))) {
              j++;
            }
            m = 1;
            i = j;
          }
        }
        else
        {
          j++;
        }
      }
      j--;
      if (j > i)
      {
        if (m == 0)
        {
          if (arrayOfChar[j] == '"') {
            tab[(k++)][1] = new String(arrayOfChar, i, j - i);
          } else {
            tab[(k++)][1] = new String(arrayOfChar, i, j - i + 1);
          }
        }
        else {
          tab[k][0] = new String(arrayOfChar, i, j - i + 1).toLowerCase();
        }
      }
      else if (j == i) {
        if (m == 0)
        {
          if (arrayOfChar[j] == '"') {
            tab[(k++)][1] = String.valueOf(arrayOfChar[(j - 1)]);
          } else {
            tab[(k++)][1] = String.valueOf(arrayOfChar[j]);
          }
        }
        else {
          tab[k][0] = String.valueOf(arrayOfChar[j]).toLowerCase();
        }
      }
    }
  }
  
  public String findKey(int paramInt)
  {
    if ((paramInt < 0) || (paramInt > 10)) {
      return null;
    }
    return tab[paramInt][0];
  }
  
  public String findValue(int paramInt)
  {
    if ((paramInt < 0) || (paramInt > 10)) {
      return null;
    }
    return tab[paramInt][1];
  }
  
  public String findValue(String paramString)
  {
    return findValue(paramString, null);
  }
  
  public String findValue(String paramString1, String paramString2)
  {
    if (paramString1 == null) {
      return paramString2;
    }
    paramString1.toLowerCase();
    for (int i = 0; i < 10; i++)
    {
      if (tab[i][0] == null) {
        return paramString2;
      }
      if (paramString1.equals(tab[i][0])) {
        return tab[i][1];
      }
    }
    return paramString2;
  }
  
  public int findInt(String paramString, int paramInt)
  {
    try
    {
      return Integer.parseInt(findValue(paramString, String.valueOf(paramInt)));
    }
    catch (Throwable localThrowable) {}
    return paramInt;
  }
}

/* Location:
 * Qualified Name:     com.sun.java.help.impl.HeaderParser
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.java.help.impl;

import java.util.Locale;

public class LangElement
{
  Tag tag;
  Locale locale;
  
  public LangElement(Tag paramTag, Locale paramLocale)
  {
    tag = paramTag;
    locale = paramLocale;
  }
  
  public Tag getTag()
  {
    return tag;
  }
  
  public Locale getLocale()
  {
    return locale;
  }
}

/* Location:
 * Qualified Name:     com.sun.java.help.impl.LangElement
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.java.help.impl;

public class Tag
{
  public String name;
  public boolean isEnd;
  public boolean isEmpty;
  public TagProperties atts;
  
  public Tag(String paramString, TagProperties paramTagProperties, boolean paramBoolean1, boolean paramBoolean2)
  {
    name = paramString;
    atts = paramTagProperties;
    isEnd = paramBoolean1;
    isEmpty = paramBoolean2;
  }
}

/* Location:
 * Qualified Name:     com.sun.java.help.impl.Tag
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.java.help.impl;

import java.util.Enumeration;
import java.util.NoSuchElementException;

class TagProperties$EmptyEnumerator
  implements Enumeration
{
  private final TagProperties this$0;
  
  TagProperties$EmptyEnumerator(TagProperties paramTagProperties)
  {
    this$0 = paramTagProperties;
  }
  
  public boolean hasMoreElements()
  {
    return false;
  }
  
  public Object nextElement()
  {
    throw new NoSuchElementException("EmptyEnumerator");
  }
}

/* Location:
 * Qualified Name:     com.sun.java.help.impl.TagProperties.EmptyEnumerator
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.java.help.impl;

import java.io.PrintStream;
import java.io.PrintWriter;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.NoSuchElementException;

public class TagProperties
  implements Cloneable
{
  static int count2 = 0;
  static int count1 = 0;
  protected int initialSize;
  protected Hashtable hashtable;
  
  public TagProperties()
  {
    this(7);
  }
  
  public TagProperties(int paramInt)
  {
    initialSize = paramInt;
  }
  
  public String getProperty(String paramString)
  {
    return (String)get(paramString);
  }
  
  public String getProperty(String paramString1, String paramString2)
  {
    String str = getProperty(paramString1);
    return str == null ? paramString2 : str;
  }
  
  public Enumeration propertyNames()
  {
    Hashtable localHashtable = new Hashtable(11);
    enumerate(localHashtable);
    return localHashtable.keys();
  }
  
  public void list(PrintStream paramPrintStream)
  {
    paramPrintStream.println("-- listing properties --");
    Hashtable localHashtable = new Hashtable(11);
    enumerate(localHashtable);
    for (Enumeration localEnumeration = localHashtable.keys(); localEnumeration.hasMoreElements();)
    {
      String str1 = (String)localEnumeration.nextElement();
      String str2 = (String)localHashtable.get(str1);
      if (str2.length() > 40) {
        str2 = str2.substring(0, 37) + "...";
      }
      paramPrintStream.println(str1 + "=" + str2);
    }
  }
  
  public void list(PrintWriter paramPrintWriter)
  {
    paramPrintWriter.println("-- listing properties --");
    Hashtable localHashtable = new Hashtable(11);
    enumerate(localHashtable);
    for (Enumeration localEnumeration = localHashtable.keys(); localEnumeration.hasMoreElements();)
    {
      String str1 = (String)localEnumeration.nextElement();
      String str2 = (String)localHashtable.get(str1);
      if (str2.length() > 40) {
        str2 = str2.substring(0, 37) + "...";
      }
      paramPrintWriter.println(str1 + "=" + str2);
    }
  }
  
  private synchronized void enumerate(Hashtable paramHashtable)
  {
    for (Enumeration localEnumeration = keys(); localEnumeration.hasMoreElements();)
    {
      String str = (String)localEnumeration.nextElement();
      paramHashtable.put(str, get(str));
    }
  }
  
  public int size()
  {
    if (hashtable != null) {
      return hashtable.size();
    }
    return 0;
  }
  
  public boolean isEmpty()
  {
    if (hashtable != null) {
      return hashtable.isEmpty();
    }
    return true;
  }
  
  public synchronized Enumeration keys()
  {
    if (hashtable != null) {
      return hashtable.keys();
    }
    return new EmptyEnumerator();
  }
  
  public synchronized Enumeration elements()
  {
    if (hashtable != null) {
      return hashtable.elements();
    }
    return new EmptyEnumerator();
  }
  
  public synchronized boolean contains(Object paramObject)
  {
    if (hashtable != null) {
      return hashtable.contains(paramObject);
    }
    return false;
  }
  
  public synchronized boolean containsKey(Object paramObject)
  {
    if (hashtable != null) {
      return hashtable.containsKey(paramObject);
    }
    return false;
  }
  
  public synchronized Object get(Object paramObject)
  {
    if (hashtable != null) {
      return hashtable.get(paramObject);
    }
    return null;
  }
  
  public synchronized Object put(Object paramObject1, Object paramObject2)
  {
    if (hashtable == null) {
      hashtable = new Hashtable(initialSize);
    }
    return hashtable.put(paramObject1, paramObject2);
  }
  
  public synchronized Object remove(Object paramObject)
  {
    if (hashtable != null) {
      return hashtable.remove(paramObject);
    }
    return null;
  }
  
  public synchronized void clear()
  {
    if (hashtable != null) {
      hashtable.clear();
    }
  }
  
  protected void setHashtable(Hashtable paramHashtable)
  {
    hashtable = paramHashtable;
  }
  
  public Hashtable getHashtable()
  {
    return hashtable;
  }
  
  public synchronized Object clone()
  {
    try
    {
      TagProperties localTagProperties = (TagProperties)super.clone();
      if (hashtable != null) {
        localTagProperties.setHashtable((Hashtable)hashtable.clone());
      }
      return localTagProperties;
    }
    catch (CloneNotSupportedException localCloneNotSupportedException)
    {
      throw new InternalError();
    }
  }
  
  public synchronized String toString()
  {
    if (hashtable != null) {
      return hashtable.toString();
    }
    return "{ }";
  }
  
  class EmptyEnumerator
    implements Enumeration
  {
    EmptyEnumerator() {}
    
    public boolean hasMoreElements()
    {
      return false;
    }
    
    public Object nextElement()
    {
      throw new NoSuchElementException("EmptyEnumerator");
    }
  }
}

/* Location:
 * Qualified Name:     com.sun.java.help.impl.TagProperties
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.java.help.impl;

import java.io.CharConversionException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.io.Reader;
import java.io.UnsupportedEncodingException;
import java.util.Hashtable;

public abstract class DocumentParser
{
  static final char EOF = '?';
  protected Reader source;
  int readOffset;
  ScanBuffer buffer;
  ScanBuffer escapeBuffer;
  ScanBuffer documentSource;
  boolean shouldCacheSource;
  Hashtable entities;
  
  public DocumentParser(InputStream paramInputStream)
  {
    source = new MyBufferedReader(new InputStreamReader(paramInputStream));
    init();
  }
  
  public DocumentParser(Reader paramReader)
  {
    if ((paramReader instanceof MyBufferedReader)) {
      source = paramReader;
    } else {
      source = new MyBufferedReader(paramReader);
    }
    init();
  }
  
  public void setInput(Reader paramReader)
  {
    if ((paramReader instanceof MyBufferedReader)) {
      source = paramReader;
    } else {
      source = new MyBufferedReader(paramReader);
    }
  }
  
  public void setInput(InputStream paramInputStream, String paramString)
    throws UnsupportedEncodingException
  {
    if (paramInputStream == null)
    {
      source = null;
      return;
    }
    source = new MyBufferedReader(new InputStreamReader(paramInputStream, paramString));
  }
  
  public void setShouldCacheSource(boolean paramBoolean)
  {
    shouldCacheSource = paramBoolean;
  }
  
  public String getDocumentSource()
  {
    if (!shouldCacheSource) {
      return null;
    }
    int i = 0 == documentSource.length() ? 0 : documentSource.length() - 1;
    
    return new String(documentSource.buf, 0, i) + "\n";
  }
  
  public void parse()
    throws IOException
  {
    int i = 65535;
    
    buffer.clear();
    if (source != null) {
      i = readChar();
    }
    while (i != 65535) {
      if (i == 38)
      {
        i = parseEscape();
      }
      else if (i == 60)
      {
        buffer.flush(this);
        i = parseTag();
      }
      else
      {
        if (buffer.buflen >= buffer.buf.length)
        {
          char[] arrayOfChar = new char[buffer.buf.length * buffer.scale];
          System.arraycopy(buffer.buf, 0, arrayOfChar, 0, buffer.buf.length);
          buffer.buf = arrayOfChar;
        }
        if (i != 13) {
          buffer.buf[(buffer.buflen++)] = i;
        }
        if (myCount >= mySize) {
          try
          {
            mySize = source.read(cb, 0, defaultCharBufferSize);
            if (mySize < 0) {
              break;
            }
            if (mySize == 0)
            {
              System.err.println(" DocumentParser::parse() !!!ERROR !!! source.read(...) == 0");
              break;
            }
            myCount = 0;
          }
          catch (CharConversionException localCharConversionException)
          {
            throw localCharConversionException;
          }
          catch (IOException localIOException)
          {
            break;
          }
        }
        if (shouldCacheSource) {
          documentSource.add(cb[myCount]);
        }
        i = cb[(myCount++)];
      }
    }
    buffer.flush(this);
  }
  
  public void parseText()
    throws IOException
  {
    tag("PRE", null, false, false);
    
    buffer.clear();
    int i = readChar();
    while (i != 65535)
    {
      buffer.add(i);
      int j = readChar();
    }
    buffer.flush(this);
  }
  
  protected void callFlush(char[] paramArrayOfChar, int paramInt1, int paramInt2)
  {
    flush(paramArrayOfChar, paramInt1, paramInt2);
  }
  
  protected abstract void flush(char[] paramArrayOfChar, int paramInt1, int paramInt2);
  
  protected abstract void comment(String paramString);
  
  protected abstract void tag(String paramString, TagProperties paramTagProperties, boolean paramBoolean1, boolean paramBoolean2);
  
  protected abstract void pi(String paramString1, String paramString2);
  
  protected abstract void doctype(String paramString1, String paramString2, String paramString3);
  
  protected abstract String documentAttribute(String paramString);
  
  protected abstract void errorString(String paramString);
  
  private void init()
  {
    buffer = new ScanBuffer(8192, 4);
    
    escapeBuffer = new ScanBuffer(8192, 4);
    documentSource = new ScanBuffer(8192, 4);
    readOffset = 0;
  }
  
  protected void findCloseAngleForComment(char paramChar)
    throws IOException
  {
    buffer.add(paramChar);
    for (;;)
    {
      paramChar = readChar();
      if (paramChar == '>') {
        break;
      }
      buffer.add(paramChar);
    }
    buffer.add(paramChar);
    comment(buffer.extract(0));
    buffer.clear();
  }
  
  protected char handleCommentOrDoctype(char paramChar)
    throws IOException
  {
    buffer.add(paramChar);
    int i = buffer.length();
    paramChar = scanIdentifier(paramChar);
    String str1 = buffer.extract(i);
    if (!str1.equals("DOCTYPE"))
    {
      findCloseAngleForComment(paramChar);
      return readChar();
    }
    paramChar = skipWhite(paramChar);
    
    i = buffer.length();
    paramChar = scanIdentifier(paramChar);
    String str2 = buffer.extract(i);
    
    paramChar = skipWhite(paramChar);
    if (paramChar == '>')
    {
      buffer.clear();
      return readChar();
    }
    i = buffer.length();
    paramChar = scanIdentifier(paramChar);
    str1 = buffer.extract(i);
    
    String str3 = null;
    String str4 = null;
    if (str1.equals("SYSTEM"))
    {
      paramChar = skipWhite(paramChar);
      
      i = buffer.length();
      paramChar = scanQuotedString(paramChar);
      str4 = buffer.extract(i);
      
      doctype(str2, null, str4);
      if (paramChar != '>') {
        findCloseAngleForComment(paramChar);
      }
      buffer.clear();
      return readChar();
    }
    if (str1.equals("PUBLIC"))
    {
      paramChar = skipWhite(paramChar);
      
      i = buffer.length();
      paramChar = scanQuotedString(paramChar);
      str3 = buffer.extract(i);
      
      paramChar = skipWhite(paramChar);
      
      i = buffer.length();
      paramChar = scanQuotedString(paramChar);
      str4 = buffer.extract(i);
      
      doctype(str2, str3, str4);
      if (paramChar != '>') {
        findCloseAngleForComment(paramChar);
      }
      buffer.clear();
      return readChar();
    }
    if (paramChar != '>') {
      findCloseAngleForComment(paramChar);
    }
    findCloseAngleForComment(paramChar);
    
    doctype(str2, null, null);
    
    buffer.clear();
    return readChar();
  }
  
  protected void setXmlEntities(TagProperties paramTagProperties) {}
  
  protected char parseTag()
    throws IOException
  {
    buffer.clear();
    int i9 = 0;
    int i = 60;
    buffer.add('<');
    i = readChar();
    int i10;
    int j;
    if (i == 33)
    {
      i10 = 0;
      buffer.add('!');
      
      i = readChar();
      if (i != 45) {
        return handleCommentOrDoctype(i);
      }
      buffer.add(i);
      i = readChar();
      if (i != 45)
      {
        findCloseAngleForComment(i);
        return readChar();
      }
      buffer.add(i);
      
      i10 = buffer.length();
      
      int i11 = 0;
      for (;;)
      {
        i = readChar();
        if (i == 65535)
        {
          commentEOFError(i10);
          break;
        }
        if (i != 45)
        {
          buffer.add(i);
        }
        else
        {
          while (i == 45)
          {
            buffer.add(i);
            i11++;
            j = readChar();
          }
          if (j == 65535)
          {
            commentEOFError(i10);
            break;
          }
          buffer.add(j);
          if ((i11 >= 2) && (j == 62))
          {
            comment(buffer.extract(0));
            buffer.clear();
            return readChar();
          }
          i11 = 0;
        }
      }
    }
    Object localObject;
    if (j == 63)
    {
      i10 = 0;
      localObject = new StringBuffer();
      buffer.add('?');
      int k;
      while (((k = readChar()) != '"') && (k != 32) && (k != 9) && (k != 10) && (k != 62))
      {
        buffer.add(k);
        ((StringBuffer)localObject).append(k);
      }
      if (!((StringBuffer)localObject).toString().equals("xml"))
      {
        buffer.clear();
        while (((k = readChar()) != '?') && (k != 65535)) {
          buffer.add(k);
        }
        if (k == 65535)
        {
          eofError();
          return readChar();
        }
        int m = readChar();
        if ((m != 62) && (m != 65535))
        {
          buffer.add('?');
          buffer.add(m);
        }
        if (m == 65535)
        {
          eofError();
          return readChar();
        }
        pi(((StringBuffer)localObject).toString(), buffer.extract(0));
        return readChar();
      }
      localObject = null;
      
      int n = readChar();
      localTagProperties = null;
      for (;;)
      {
        n = skipWhite(n);
        if (n == 65535)
        {
          eofError();
          return n;
        }
        if (n == 63) {
          break;
        }
        i8 = buffer.length();
        int i1 = scanIdentifier(n);
        if (i8 == buffer.length())
        {
          error("Expecting an attribute");
          skipToCloseAngle(i1);
          return readChar();
        }
        String str3 = buffer.extract(i8);
        i1 = skipWhite(i1);
        if (localTagProperties == null) {
          localTagProperties = new TagProperties();
        }
        String str4;
        if (i1 == 61)
        {
          buffer.add(i1);
          i1 = readChar();
          
          i1 = skipWhite(i1);
          if ((i1 == 63) || (i1 == 60))
          {
            str4 = "";
          }
          else
          {
            int i13;
            int i2;
            if (i1 == 34)
            {
              buffer.add(i1);
              i13 = buffer.length();
              for (;;)
              {
                i1 = readChar();
                if (i1 == 65535)
                {
                  eofError();
                  return i1;
                }
                if (i1 == 34) {
                  break;
                }
                if (i1 == 38) {
                  i2 = parseEscape();
                }
                buffer.add(i2);
              }
              str4 = buffer.extract(i13);
              buffer.add(i2);
              i2 = readChar();
            }
            else
            {
              i13 = buffer.length();
              buffer.add(i2);
              for (;;)
              {
                i2 = readChar();
                if (i2 == 65535)
                {
                  eofError();
                  return i2;
                }
                if ((i2 == 34) || (i2 == 32) || (i2 == 9) || (i2 == 10) || (i2 == 63)) {
                  break;
                }
                if (i2 == 38) {
                  i3 = parseEscape();
                }
                buffer.add(i3);
              }
              str4 = buffer.extract(i13);
            }
          }
        }
        else
        {
          str4 = "true";
        }
        localTagProperties.put(str3, str4);
      }
      int i3 = readChar();
      if (i3 == 65535)
      {
        eofError();
        return readChar();
      }
      i4 = skipWhite(i3);
      buffer.add(i4);
      if (i4 == 62)
      {
        setXmlEntities(localTagProperties);
        buffer.clear();
        return readChar();
      }
      error("Expecting ?>");
      skipToCloseAngle(i4);
      return readChar();
    }
    int i4 = skipWhite(i4);
    if (i4 == 65535)
    {
      eofError();
      return i4;
    }
    boolean bool1;
    boolean bool2;
    if (i4 == 47)
    {
      buffer.add(i4);
      i5 = skipWhite(readChar());
      bool1 = true;
      bool2 = false;
    }
    else
    {
      bool1 = false;
      bool2 = false;
    }
    int i8 = buffer.length();
    int i5 = scanIdentifier(i5);
    String str1 = buffer.extract(i8);
    TagProperties localTagProperties = null;
    for (;;)
    {
      i5 = skipWhite(i5);
      if (i5 == 65535)
      {
        eofError();
        return i5;
      }
      if (i5 == 62) {
        break;
      }
      if (i5 == 47)
      {
        buffer.add(i5);
        i6 = readChar();
        if (i6 == 62)
        {
          bool1 = true;
          bool2 = true;
          break;
        }
        error("Expecting />");
        skipToCloseAngle(i6);
        return readChar();
      }
      if (i6 == 60)
      {
        tag(str1, localTagProperties, bool1, false);
        buffer.clear();
        return '<';
      }
      i8 = buffer.length();
      int i6 = scanIdentifier(i6);
      if (i8 == buffer.length())
      {
        error("Expecting an attribute (2)");
        skipToCloseAngle(i6);
        return readChar();
      }
      String str2 = buffer.extract(i8);
      i6 = skipWhite(i6);
      if (localTagProperties == null) {
        localTagProperties = new TagProperties();
      }
      if (i6 == 61)
      {
        buffer.add(i6);
        i6 = readChar();
        
        i6 = skipWhite(i6);
        if ((i6 == 62) || (i6 == 60))
        {
          localObject = "";
        }
        else
        {
          int i12;
          int i7;
          if (i6 == 34)
          {
            buffer.add(i6);
            i12 = buffer.length();
            for (;;)
            {
              i6 = readChar();
              if (i6 == 65535)
              {
                eofError();
                return i6;
              }
              if (i6 == 34) {
                break;
              }
              if (i6 == 38) {
                i7 = parseEscape();
              }
              buffer.add(i7);
            }
            localObject = buffer.extract(i12);
            buffer.add(i7);
            i7 = readChar();
          }
          else
          {
            i12 = buffer.length();
            buffer.add(i7);
            for (;;)
            {
              i7 = readChar();
              if (i7 == 65535)
              {
                eofError();
                return i7;
              }
              if ((i7 == 34) || (i7 == 32) || (i7 == 9) || (i7 == 10) || (i7 == 62)) {
                break;
              }
              char c;
              if (i7 == 38) {
                c = parseEscape();
              }
              buffer.add(c);
            }
            localObject = buffer.extract(i12);
          }
        }
      }
      else
      {
        localObject = "true";
      }
      localTagProperties.put(str2, localObject);
    }
    tag(str1, localTagProperties, bool1, bool2);
    buffer.clear();
    return readChar();
  }
  
  protected char parseEscape()
    throws IOException
  {
    int m = buffer.length();
    buffer.add('&');
    int i = readChar();
    if (i == 65535)
    {
      generateError(m);
      return i;
    }
    int k;
    char c;
    label288:
    String str2;
    int i1;
    if (i == 35)
    {
      int n = 0;
      for (;;)
      {
        int j = readChar();
        if (j == 65535)
        {
          generateError(m);
          return j;
        }
        if (j == 59)
        {
          k = 0;
          break;
        }
        if (!Character.isDigit(k))
        {
          if (n > 0) {
            break;
          }
          error("Expecting a digit");
          generateError(m);
          return k;
        }
        buffer.add(k);
      
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30

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