jsilver-1.0.0

16:38:09.857 INFO  jd.cli.Main - Decompiling jsilver-1.0.0.jar
package com.google.streamhtmlparser;

import com.google.streamhtmlparser.impl.JavascriptParserImpl;

public class JavascriptParserFactory
{
  public static JavascriptParser getInstance()
  {
    return new JavascriptParserImpl();
  }
}

/* Location:
 * Qualified Name:     com.google.streamhtmlparser.JavascriptParserFactory
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.google.streamhtmlparser;

public enum HtmlParser$Mode
{
  HTML,  JS,  CSS,  HTML_IN_TAG;
  
  private HtmlParser$Mode() {}
}

/* Location:
 * Qualified Name:     com.google.streamhtmlparser.HtmlParser.Mode
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.google.streamhtmlparser.impl;

import com.google.common.base.Preconditions;

class StateTableTransition
{
  private final String expression;
  private final InternalState from;
  private final InternalState to;
  
  public String toString()
  {
    return String.format("Expression: %s; From: %s; To: %s", new Object[] { expression, from, to });
  }
  
  StateTableTransition(String expression, InternalState from, InternalState to)
  {
    Preconditions.checkNotNull(expression);
    Preconditions.checkNotNull(from);
    Preconditions.checkNotNull(to);
    this.expression = expression;
    this.from = from;
    this.to = to;
  }
  
  String getExpression()
  {
    return expression;
  }
  
  InternalState getFrom()
  {
    return from;
  }
  
  InternalState getTo()
  {
    return to;
  }
}

/* Location:
 * Qualified Name:     com.google.streamhtmlparser.impl.StateTableTransition
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.google.streamhtmlparser.impl;

import com.google.common.base.Preconditions;
import com.google.common.collect.Maps;
import com.google.streamhtmlparser.ExternalState;
import com.google.streamhtmlparser.HtmlParser;
import com.google.streamhtmlparser.HtmlParser.ATTR_TYPE;
import com.google.streamhtmlparser.HtmlParser.Mode;
import com.google.streamhtmlparser.ParseException;
import com.google.streamhtmlparser.util.CharacterRecorder;
import com.google.streamhtmlparser.util.EntityResolver;
import com.google.streamhtmlparser.util.EntityResolver.Status;
import com.google.streamhtmlparser.util.HtmlUtils;
import com.google.streamhtmlparser.util.HtmlUtils.META_REDIRECT_TYPE;
import java.util.Map;

public class HtmlParserImpl
  extends GenericParser
  implements HtmlParser
{
  private static final InternalState TEXT = InternalState.getInstanceHtml("TEXT");
  private static final InternalState TAG_START = InternalState.getInstanceHtml("TAG_START");
  private static final InternalState TAG_NAME = InternalState.getInstanceHtml("TAG_NAME");
  private static final InternalState DECL_START = InternalState.getInstanceHtml("DECL_START");
  private static final InternalState DECL_BODY = InternalState.getInstanceHtml("DECL_BODY");
  private static final InternalState COM_OPEN = InternalState.getInstanceHtml("COM_OPEN");
  private static final InternalState COM_BODY = InternalState.getInstanceHtml("COM_BODY");
  private static final InternalState COM_DASH = InternalState.getInstanceHtml("COM_DASH");
  private static final InternalState COM_DASH_DASH = InternalState.getInstanceHtml("COM_DASH_DASH");
  private static final InternalState PI = InternalState.getInstanceHtml("PI");
  private static final InternalState PI_MAY_END = InternalState.getInstanceHtml("PI_MAY_END");
  private static final InternalState TAG_SPACE = InternalState.getInstanceHtml("TAG_SPACE");
  private static final InternalState TAG_CLOSE = InternalState.getInstanceHtml("TAG_CLOSE");
  private static final InternalState ATTR = InternalState.getInstanceHtml("ATTR");
  private static final InternalState ATTR_SPACE = InternalState.getInstanceHtml("ATTR_SPACE");
  private static final InternalState VALUE = InternalState.getInstanceHtml("VALUE");
  private static final InternalState VALUE_TEXT = InternalState.getInstanceHtml("VALUE_TEXT");
  private static final InternalState VALUE_Q_START = InternalState.getInstanceHtml("VALUE_Q_START");
  private static final InternalState VALUE_Q = InternalState.getInstanceHtml("VALUE_Q");
  private static final InternalState VALUE_DQ_START = InternalState.getInstanceHtml("VALUE_DQ_START");
  private static final InternalState VALUE_DQ = InternalState.getInstanceHtml("VALUE_DQ");
  private static final InternalState CDATA_COM_START = InternalState.getInstanceHtml("CDATA_COM_START");
  private static final InternalState CDATA_COM_START_DASH = InternalState.getInstanceHtml("CDATA_COM_START_DASH");
  private static final InternalState CDATA_COM_BODY = InternalState.getInstanceHtml("CDATA_COM_BODY");
  private static final InternalState CDATA_COM_DASH = InternalState.getInstanceHtml("CDATA_COM_DASH");
  private static final InternalState CDATA_COM_DASH_DASH = InternalState.getInstanceHtml("CDATA_COM_DASH_DASH");
  private static final InternalState CDATA_TEXT = InternalState.getInstanceHtml("CDATA_TEXT");
  private static final InternalState CDATA_LT = InternalState.getInstanceHtml("CDATA_LT");
  private static final InternalState CDATA_MAY_CLOSE = InternalState.getInstanceHtml("CDATA_MAY_CLOSE");
  private static final InternalState JS_FILE = InternalState.getInstanceHtml("JS_FILE");
  private static final InternalState CSS_FILE = InternalState.getInstanceHtml("CSS_FILE");
  private static final Map<InternalState, ExternalState> STATE_MAPPING = Maps.newHashMap();
  private static final ParserStateTable STATE_TABLE;
  private final CharacterRecorder tag;
  private final CharacterRecorder attr;
  private final CharacterRecorder value;
  private final CharacterRecorder cdataCloseTag;
  private final EntityResolver entityResolver;
  private final JavascriptParserImpl jsParser;
  private boolean insideJavascript;
  private int valueIndex;
  private boolean textInsideUrlValue;
  
  static
  {
    initializeStateMapping();
    
    STATE_TABLE = new ParserStateTable();
    
    initializeParserStateTable();
  }
  
  public HtmlParserImpl()
  {
    super(STATE_TABLE, STATE_MAPPING, TEXT);
    tag = new CharacterRecorder();
    attr = new CharacterRecorder();
    value = new CharacterRecorder();
    cdataCloseTag = new CharacterRecorder();
    entityResolver = new EntityResolver();
    jsParser = new JavascriptParserImpl();
    insideJavascript = false;
    valueIndex = 0;
    textInsideUrlValue = false;
  }
  
  public HtmlParserImpl(HtmlParserImpl aHtmlParserImpl)
  {
    super(aHtmlParserImpl);
    tag = new CharacterRecorder(tag);
    attr = new CharacterRecorder(attr);
    value = new CharacterRecorder(value);
    cdataCloseTag = new CharacterRecorder(cdataCloseTag);
    entityResolver = new EntityResolver(entityResolver);
    jsParser = new JavascriptParserImpl(jsParser);
    insideJavascript = insideJavascript;
    valueIndex = valueIndex;
    textInsideUrlValue = textInsideUrlValue;
  }
  
  public boolean inJavascript()
  {
    return (insideJavascript) && ((getState() == STATE_VALUE) || (currentState == CDATA_TEXT) || (currentState == CDATA_COM_START) || (currentState == CDATA_COM_START_DASH) || (currentState == CDATA_COM_BODY) || (currentState == CDATA_COM_DASH) || (currentState == CDATA_COM_DASH_DASH) || (currentState == CDATA_LT) || (currentState == CDATA_MAY_CLOSE) || (currentState == JS_FILE));
  }
  
  public boolean isJavascriptQuoted()
  {
    if (inJavascript())
    {
      ExternalState jsParserState = jsParser.getState();
      return (jsParserState == JavascriptParserImpl.STATE_Q) || (jsParserState == JavascriptParserImpl.STATE_DQ);
    }
    return false;
  }
  
  public boolean inAttribute()
  {
    ExternalState extState = getState();
    return (extState != null) && ((extState == STATE_ATTR) || (extState == STATE_VALUE));
  }
  
  public boolean inCss()
  {
    return (currentState == CSS_FILE) || ((getState() == STATE_VALUE) && (getAttributeType() == HtmlParser.ATTR_TYPE.STYLE)) || ("style".equals(getTag()));
  }
  
  public HtmlParser.ATTR_TYPE getAttributeType()
  {
    String attribute = getAttribute();
    if (!inAttribute()) {
      return HtmlParser.ATTR_TYPE.NONE;
    }
    if (HtmlUtils.isAttributeJavascript(attribute)) {
      return HtmlParser.ATTR_TYPE.JS;
    }
    if (HtmlUtils.isAttributeUri(attribute)) {
      return HtmlParser.ATTR_TYPE.URI;
    }
    if (HtmlUtils.isAttributeStyle(attribute)) {
      return HtmlParser.ATTR_TYPE.STYLE;
    }
    if (("meta".equals(getTag())) && ("content".equals(getAttribute())))
    {
      HtmlUtils.META_REDIRECT_TYPE redirectType = HtmlUtils.parseContentAttributeForUrl(getValue());
      if ((redirectType == HtmlUtils.META_REDIRECT_TYPE.URL_START) || (redirectType == HtmlUtils.META_REDIRECT_TYPE.URL)) {
        return HtmlParser.ATTR_TYPE.URI;
      }
    }
    return HtmlParser.ATTR_TYPE.REGULAR;
  }
  
  public ExternalState getJavascriptState()
  {
    return jsParser.getState();
  }
  
  public boolean isAttributeQuoted()
  {
    return (currentState == VALUE_Q_START) || (currentState == VALUE_Q) || (currentState == VALUE_DQ_START) || (currentState == VALUE_DQ);
  }
  
  public String getTag()
  {
    return tag.getContent().toLowerCase();
  }
  
  public String getAttribute()
  {
    return inAttribute() ? attr.getContent().toLowerCase() : "";
  }
  
  public String getValue()
  {
    return getState() == STATE_VALUE ? value.getContent() : "";
  }
  
  public int getValueIndex()
  {
    if (getState() != STATE_VALUE) {
      return 0;
    }
    return valueIndex;
  }
  
  public boolean isUrlStart()
  {
    if (getState() != STATE_VALUE) {
      return false;
    }
    if (getAttributeType() != HtmlParser.ATTR_TYPE.URI) {
      return false;
    }
    if (textInsideUrlValue) {
      return false;
    }
    if ("meta".equals(getTag())) {
      return HtmlUtils.parseContentAttributeForUrl(getValue()) == HtmlUtils.META_REDIRECT_TYPE.URL_START;
    }
    return getValueIndex() == 0;
  }
  
  public void resetMode(HtmlParser.Mode mode)
  {
    insideJavascript = false;
    tag.reset();
    attr.reset();
    value.reset();
    cdataCloseTag.reset();
    valueIndex = 0;
    textInsideUrlValue = false;
    jsParser.reset();
    switch (mode)
    {
    case HTML: 
      currentState = TEXT;
      break;
    case JS: 
      currentState = JS_FILE;
      insideJavascript = true;
      break;
    case CSS: 
      currentState = CSS_FILE;
      break;
    case HTML_IN_TAG: 
      currentState = TAG_SPACE;
      break;
    default: 
      throw new IllegalArgumentException("Did not recognize Mode: " + mode.toString());
    }
  }
  
  public void reset()
  {
    super.reset();
    resetMode(HtmlParser.Mode.HTML);
  }
  
  public void insertText()
    throws ParseException
  {
    if ((getState() == STATE_VALUE) && (getAttributeType() == HtmlParser.ATTR_TYPE.URI) && (isUrlStart())) {
      textInsideUrlValue = true;
    }
    if (currentState == VALUE) {
      setNextState(VALUE_TEXT);
    }
  }
  
  protected InternalState handleEnterState(InternalState currentState, InternalState expectedNextState, char input)
  {
    InternalState nextState = expectedNextState;
    if (currentState == TAG_NAME) {
      enterTagName();
    } else if (currentState == ATTR) {
      enterAttribute();
    } else if (currentState == TAG_CLOSE) {
      nextState = tagClose(currentState);
    } else if (currentState == CDATA_MAY_CLOSE) {
      enterStateCdataMayClose();
    } else if (currentState == VALUE) {
      enterValue();
    } else if ((currentState == VALUE_TEXT) || (currentState == VALUE_Q) || (currentState == VALUE_DQ)) {
      enterValueContent();
    }
    return nextState;
  }
  
  protected InternalState handleExitState(InternalState currentState, InternalState expectedNextState, char input)
  {
    InternalState nextState = expectedNextState;
    if (currentState == TAG_NAME) {
      exitTagName();
    } else if (currentState == ATTR) {
      exitAttribute();
    } else if (currentState == CDATA_MAY_CLOSE) {
      nextState = exitStateCdataMayClose(nextState, input);
    } else if ((currentState == VALUE_TEXT) || (currentState == VALUE_Q) || (currentState == VALUE_DQ)) {
      exitValueContent();
    }
    return nextState;
  }
  
  protected InternalState handleInState(InternalState currentState, char input)
    throws ParseException
  {
    if ((currentState == CDATA_TEXT) || (currentState == CDATA_COM_START) || (currentState == CDATA_COM_START_DASH) || (currentState == CDATA_COM_BODY) || (currentState == CDATA_COM_DASH) || (currentState == CDATA_COM_DASH_DASH) || (currentState == CDATA_LT) || (currentState == CDATA_MAY_CLOSE) || (currentState == JS_FILE)) {
      inStateCdata(input);
    } else if ((currentState == VALUE_TEXT) || (currentState == VALUE_Q) || (currentState == VALUE_DQ)) {
      inStateValue(input);
    }
    return currentState;
  }
  
  protected void record(char input)
  {
    attr.maybeRecord(input);
    tag.maybeRecord(input);
    value.maybeRecord(input);
    cdataCloseTag.maybeRecord(input);
  }
  
  private void enterTagName()
  {
    tag.startRecording();
  }
  
  private void exitTagName()
  {
    tag.stopRecording();
    String tagString = tag.getContent();
    if ((!tagString.isEmpty()) && (tagString.charAt(0) == '/')) {
      tag.reset();
    }
  }
  
  private void enterAttribute()
  {
    attr.startRecording();
  }
  
  private void exitAttribute()
  {
    attr.stopRecording();
  }
  
  private void enterValue()
  {
    valueIndex = 0;
    textInsideUrlValue = false;
    if (HtmlUtils.isAttributeJavascript(getAttribute()))
    {
      entityResolver.reset();
      jsParser.reset();
      insideJavascript = true;
    }
    else
    {
      insideJavascript = false;
    }
  }
  
  private void enterValueContent()
  {
    value.startRecording();
  }
  
  private void exitValueContent()
  {
    value.stopRecording();
    insideJavascript = false;
  }
  
  private void inStateValue(char input)
    throws ParseException
  {
    valueIndex += 1;
    if (insideJavascript)
    {
      EntityResolver.Status status = entityResolver.processChar(input);
      if (status == EntityResolver.Status.COMPLETED)
      {
        jsParser.parse(entityResolver.getEntity());
        entityResolver.reset();
      }
      else if (status == EntityResolver.Status.NOT_STARTED)
      {
        jsParser.parse(input);
      }
    }
  }
  
  private InternalState tagClose(InternalState state)
  {
    InternalState nextState = state;
    String tagName = getTag();
    if ("script".equals(tagName))
    {
      nextState = CDATA_TEXT;
      jsParser.reset();
      insideJavascript = true;
    }
    else if (("style".equals(tagName)) || ("title".equals(tagName)) || ("textarea".equals(tagName)))
    {
      nextState = CDATA_TEXT;
      insideJavascript = false;
    }
    return nextState;
  }
  
  private void inStateCdata(char input)
    throws ParseException
  {
    if (insideJavascript) {
      jsParser.parse(input);
    }
  }
  
  private void enterStateCdataMayClose()
  {
    cdataCloseTag.startRecording();
  }
  
  private InternalState exitStateCdataMayClose(InternalState expectedNextState, char input)
  {
    InternalState nextState = expectedNextState;
    cdataCloseTag.stopRecording();
    String cdataCloseTagString = cdataCloseTag.getContent();
    Preconditions.checkState((!cdataCloseTagString.isEmpty()) && (cdataCloseTagString.charAt(0) == '/'));
    if ((cdataCloseTagString.substring(1).equalsIgnoreCase(getTag())) && ((input == '>') || (HtmlUtils.isHtmlSpace(input))))
    {
      tag.clear();
      insideJavascript = false;
    }
    else
    {
      nextState = CDATA_TEXT;
    }
    return nextState;
  }
  
  private static void registerMapping(InternalState internalState, ExternalState externalState)
  {
    STATE_MAPPING.put(internalState, externalState);
  }
  
  private static void initializeStateMapping()
  {
    registerMapping(InternalState.INTERNAL_ERROR_STATE, HtmlParser.STATE_ERROR);
    
    registerMapping(TEXT, HtmlParser.STATE_TEXT);
    registerMapping(TAG_START, HtmlParser.STATE_TAG);
    registerMapping(TAG_NAME, HtmlParser.STATE_TAG);
    registerMapping(DECL_START, HtmlParser.STATE_TEXT);
    registerMapping(DECL_BODY, HtmlParser.STATE_TEXT);
    registerMapping(COM_OPEN, HtmlParser.STATE_TEXT);
    registerMapping(COM_BODY, HtmlParser.STATE_COMMENT);
    registerMapping(COM_DASH, HtmlParser.STATE_COMMENT);
    registerMapping(COM_DASH_DASH, HtmlParser.STATE_COMMENT);
    registerMapping(PI, HtmlParser.STATE_TEXT);
    registerMapping(PI_MAY_END, HtmlParser.STATE_TEXT);
    registerMapping(TAG_SPACE, HtmlParser.STATE_TAG);
    registerMapping(TAG_CLOSE, HtmlParser.STATE_TEXT);
    registerMapping(ATTR, HtmlParser.STATE_ATTR);
    registerMapping(ATTR_SPACE, HtmlParser.STATE_ATTR);
    registerMapping(VALUE, HtmlParser.STATE_VALUE);
    registerMapping(VALUE_TEXT, HtmlParser.STATE_VALUE);
    registerMapping(VALUE_Q_START, HtmlParser.STATE_VALUE);
    registerMapping(VALUE_Q, HtmlParser.STATE_VALUE);
    registerMapping(VALUE_DQ_START, HtmlParser.STATE_VALUE);
    registerMapping(VALUE_DQ, HtmlParser.STATE_VALUE);
    registerMapping(CDATA_COM_START, HtmlParser.STATE_TEXT);
    registerMapping(CDATA_COM_START_DASH, HtmlParser.STATE_TEXT);
    registerMapping(CDATA_COM_BODY, HtmlParser.STATE_TEXT);
    registerMapping(CDATA_COM_DASH, HtmlParser.STATE_TEXT);
    registerMapping(CDATA_COM_DASH_DASH, HtmlParser.STATE_TEXT);
    registerMapping(CDATA_TEXT, HtmlParser.STATE_TEXT);
    registerMapping(CDATA_LT, HtmlParser.STATE_TEXT);
    registerMapping(CDATA_MAY_CLOSE, HtmlParser.STATE_TEXT);
    registerMapping(JS_FILE, HtmlParser.STATE_JS_FILE);
    registerMapping(CSS_FILE, HtmlParser.STATE_CSS_FILE);
  }
  
  private static void registerTransition(String expression, InternalState source, InternalState to)
  {
    StateTableTransition stt = new StateTableTransition(expression, source, to);
    
    STATE_TABLE.setExpression(stt.getExpression(), stt.getFrom(), stt.getTo());
  }
  
  private static void initializeParserStateTable()
  {
    registerTransition("[:default:]", CSS_FILE, CSS_FILE);
    registerTransition("[:default:]", JS_FILE, JS_FILE);
    registerTransition("[:default:]", CDATA_MAY_CLOSE, CDATA_TEXT);
    registerTransition(" \t\n\r", CDATA_MAY_CLOSE, TAG_SPACE);
    registerTransition(">", CDATA_MAY_CLOSE, TEXT);
    registerTransition("A-Za-z0-9/_:-", CDATA_MAY_CLOSE, CDATA_MAY_CLOSE);
    registerTransition("[:default:]", CDATA_LT, CDATA_TEXT);
    registerTransition("!", CDATA_LT, CDATA_COM_START);
    registerTransition("/", CDATA_LT, CDATA_MAY_CLOSE);
    registerTransition("[:default:]", CDATA_TEXT, CDATA_TEXT);
    registerTransition("<", CDATA_TEXT, CDATA_LT);
    registerTransition("[:default:]", CDATA_COM_DASH_DASH, CDATA_COM_BODY);
    registerTransition(">", CDATA_COM_DASH_DASH, CDATA_TEXT);
    registerTransition("-", CDATA_COM_DASH_DASH, CDATA_COM_DASH_DASH);
    registerTransition("[:default:]", CDATA_COM_DASH, CDATA_COM_BODY);
    registerTransition("-", CDATA_COM_DASH, CDATA_COM_DASH_DASH);
    registerTransition("[:default:]", CDATA_COM_BODY, CDATA_COM_BODY);
    registerTransition("-", CDATA_COM_BODY, CDATA_COM_DASH);
    registerTransition("[:default:]", CDATA_COM_START_DASH, CDATA_TEXT);
    registerTransition("-", CDATA_COM_START_DASH, CDATA_COM_BODY);
    registerTransition("[:default:]", CDATA_COM_START, CDATA_TEXT);
    registerTransition("-", CDATA_COM_START, CDATA_COM_START_DASH);
    registerTransition("[:default:]", VALUE_DQ, VALUE_DQ);
    registerTransition("\"", VALUE_DQ, TAG_SPACE);
    registerTransition("[:default:]", VALUE_DQ_START, VALUE_DQ);
    registerTransition("\"", VALUE_DQ_START, TAG_SPACE);
    registerTransition("[:default:]", VALUE_Q, VALUE_Q);
    registerTransition("'", VALUE_Q, TAG_SPACE);
    registerTransition("[:default:]", VALUE_Q_START, VALUE_Q);
    registerTransition("'", VALUE_Q_START, TAG_SPACE);
    registerTransition("[:default:]", VALUE_TEXT, VALUE_TEXT);
    registerTransition(" \t\n\r", VALUE_TEXT, TAG_SPACE);
    registerTransition(">", VALUE_TEXT, TAG_CLOSE);
    registerTransition("[:default:]", VALUE, VALUE_TEXT);
    registerTransition(">", VALUE, TAG_CLOSE);
    registerTransition(" \t\n\r", VALUE, VALUE);
    registerTransition("\"", VALUE, VALUE_DQ_START);
    registerTransition("'", VALUE, VALUE_Q_START);
    registerTransition("=", ATTR_SPACE, VALUE);
    registerTransition("/", ATTR_SPACE, TAG_SPACE);
    registerTransition("A-Za-z0-9_:-", ATTR_SPACE, ATTR);
    registerTransition(" \t\n\r", ATTR_SPACE, ATTR_SPACE);
    registerTransition(">", ATTR_SPACE, TAG_CLOSE);
    registerTransition(" \t\n\r", ATTR, ATTR_SPACE);
    registerTransition("=", ATTR, VALUE);
    registerTransition("/", ATTR, TAG_SPACE);
    registerTransition(">", ATTR, TAG_CLOSE);
    registerTransition("A-Za-z0-9_:.-", ATTR, ATTR);
    registerTransition("[:default:]", TAG_CLOSE, TEXT);
    registerTransition("<", TAG_CLOSE, TAG_START);
    registerTransition("/", TAG_SPACE, TAG_SPACE);
    registerTransition("A-Za-z0-9_:-", TAG_SPACE, ATTR);
    registerTransition(" \t\n\r", TAG_SPACE, TAG_SPACE);
    registerTransition(">", TAG_SPACE, TAG_CLOSE);
    registerTransition("[:default:]", PI_MAY_END, PI);
    registerTransition(">", PI_MAY_END, TEXT);
    registerTransition("[:default:]", PI, PI);
    registerTransition("?", PI, PI_MAY_END);
    registerTransition("[:default:]", COM_DASH_DASH, COM_BODY);
    registerTransition(">", COM_DASH_DASH, TEXT);
    registerTransition("-", COM_DASH_DASH, COM_DASH_DASH);
    registerTransition("[:default:]", COM_DASH, COM_BODY);
    registerTransition("-", COM_DASH, COM_DASH_DASH);
    registerTransition("[:default:]", COM_BODY, COM_BODY);
    registerTransition("-", COM_BODY, COM_DASH);
    registerTransition("[:default:]", COM_OPEN, TEXT);
    registerTransition("-", COM_OPEN, COM_BODY);
    registerTransition("[:default:]", DECL_BODY, DECL_BODY);
    registerTransition(">", DECL_BODY, TEXT);
    registerTransition("[:default:]", DECL_START, DECL_BODY);
    registerTransition(">", DECL_START, TEXT);
    registerTransition("-", DECL_START, COM_OPEN);
    registerTransition(">", TAG_NAME, TAG_CLOSE);
    registerTransition(" \t\n\r", TAG_NAME, TAG_SPACE);
    registerTransition("A-Za-z0-9/_:-", TAG_NAME, TAG_NAME);
    
    registerTransition("[:default:]", TAG_START, TEXT);
    registerTransition("<", TAG_START, TAG_START);
    
    registerTransition("!", TAG_START, DECL_START);
    registerTransition("?", TAG_START, PI);
    registerTransition("A-Za-z0-9/_:-", TAG_START, TAG_NAME);
    registerTransition("[:default:]", TEXT, TEXT);
    registerTransition("<", TEXT, TAG_START);
  }
}

/* Location:
 * Qualified Name:     com.google.streamhtmlparser.impl.HtmlParserImpl
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.google.streamhtmlparser.impl;

import com.google.common.collect.Maps;
import com.google.streamhtmlparser.ExternalState;
import com.google.streamhtmlparser.JavascriptParser;
import com.google.streamhtmlparser.util.HtmlUtils;
import com.google.streamhtmlparser.util.JavascriptTokenBuffer;
import java.util.Map;

public class JavascriptParserImpl
  extends GenericParser
  implements JavascriptParser
{
  static final InternalState JS_TEXT = InternalState.getInstanceJavascript("JS_TEXT");
  static final InternalState JS_Q = InternalState.getInstanceJavascript("JS_Q");
  static final InternalState JS_Q_E = InternalState.getInstanceJavascript("JS_Q_E");
  static final InternalState JS_DQ = InternalState.getInstanceJavascript("JS_DQ");
  static final InternalState JS_DQ_E = InternalState.getInstanceJavascript("JS_DQ_E");
  static final InternalState JS_SLASH = InternalState.getInstanceJavascript("JS_SLASH");
  static final InternalState JS_REGEXP_SLASH;
  static final InternalState JS_REGEXP = InternalState.getInstanceJavascript("JS_REGEXP");
  static final InternalState JS_REGEXP_BRK;
  static final InternalState JS_REGEXP_BRK_E;
  static final InternalState JS_REGEXP_E;
  static final InternalState JS_COM_LN;
  static final InternalState JS_COM_ML;
  static final InternalState JS_COM_ML_CLOSE;
  static final InternalState JS_COM_AFTER;
  private static final Map<InternalState, ExternalState> STATE_MAPPING;
  private static final ParserStateTable STATE_TABLE;
  private final JavascriptTokenBuffer ccBuffer;
  
  static
  {
    JS_REGEXP_SLASH = InternalState.getInstanceJavascript("JS_REGEXP_SLASH");
    JS_REGEXP_E = InternalState.getInstanceJavascript("JS_REGEXP_E");
    JS_REGEXP_BRK = InternalState.getInstanceJavascript("JS_REGEXP_BRK");
    JS_REGEXP_BRK_E = InternalState.getInstanceJavascript("JS_REGEXP_BRK_E");
    JS_COM_LN = InternalState.getInstanceJavascript("COMMENT_LN");
    JS_COM_ML = InternalState.getInstanceJavascript("COMMENT_ML");
    JS_COM_ML_CLOSE = InternalState.getInstanceJavascript("COMMENT_ML_CLOSE");
    JS_COM_AFTER = InternalState.getInstanceJavascript("COMMENT_AFTER");
    
    STATE_MAPPING = Maps.newHashMap();
    
    initializeStateMapping();
    
    STATE_TABLE = new ParserStateTable();
    
    initializeParserStateTable();
  }
  
  public JavascriptParserImpl()
  {
    super(STATE_TABLE, STATE_MAPPING, JS_TEXT);
    ccBuffer = new JavascriptTokenBuffer();
  }
  
  public JavascriptParserImpl(JavascriptParserImpl aJavascriptParserImpl)
  {
    super(aJavascriptParserImpl);
    ccBuffer = new JavascriptTokenBuffer(ccBuffer);
  }
  
  public void reset()
  {
    super.reset();
    currentState = JS_TEXT;
  }
  
  protected InternalState handleEnterState(InternalState currentState, InternalState expectedNextState, char input)
  {
    InternalState nextState = expectedNextState;
    if (currentState == JS_SLASH) {
      nextState = enterStateJsSlash(currentState, input);
    } else if (currentState == JS_COM_AFTER) {
      enterStateJsCommentAfter();
    }
    return nextState;
  }
  
  protected InternalState handleExitState(InternalState currentState, InternalState expectedNextState, char input)
  {
    return expectedNextState;
  }
  
  protected InternalState handleInState(InternalState currentState, char input)
  {
    if (currentState == JS_TEXT) {
      inStateJsText(input);
    }
    return currentState;
  }
  
  private InternalState enterStateJsSlash(InternalState state, char input)
  {
    InternalState nextState = state;
    int position = -1;
    if (HtmlUtils.isJavascriptWhitespace(ccBuffer.getChar(position))) {
      position--;
    }
    switch (ccBuffer.getChar(position))
    {
    case '+': 
      if (ccBuffer.getChar(position - 1) != '+') {
        nextState = JS_REGEXP_SLASH;
      }
      break;
    case '-': 
      if (ccBuffer.getChar(position - 1) != '-') {
        nextState = JS_REGEXP_SLASH;
      }
      break;
    case '\000': 
    case '!': 
    case '%': 
    case '&': 
    case '(': 
    case '*': 
    case ',': 
    case '/': 
    case ':': 
    case ';': 
    case '<': 
    case '=': 
    case '>': 
    case '?': 
    case '[': 
    case '^': 
    case '{': 
    case '|': 
    case '}': 
    case '~': 
      nextState = JS_REGEXP_SLASH;
      break;
    default: 
      String lastIdentifier = ccBuffer.getLastIdentifier();
      if ((lastIdentifier != null) && (HtmlUtils.isJavascriptRegexpPrefix(lastIdentifier))) {
        nextState = JS_REGEXP_SLASH;
      }
      break;
    }
    ccBuffer.appendChar(input);
    return nextState;
  }
  
  private void enterStateJsCommentAfter()
  {
    if (HtmlUtils.isJavascriptWhitespace(ccBuffer.getChar(-2))) {
      ccBuffer.popChar();
    } else {
      ccBuffer.setChar(-1, ' ');
    }
  }
  
  private void inStateJsText(char input)
  {
    ccBuffer.appendChar(input);
  }
  
  private static void registerMapping(InternalState internalState, ExternalState externalState)
  {
    STATE_MAPPING.put(internalState, externalState);
  }
  
  private static void initializeStateMapping()
  {
    registerMapping(InternalState.INTERNAL_ERROR_STATE, JavascriptParser.STATE_ERROR);
    
    registerMapping(JS_TEXT, JavascriptParser.STATE_TEXT);
    registerMapping(JS_Q, JavascriptParser.STATE_Q);
    registerMapping(JS_Q_E, JavascriptParser.STATE_Q);
    registerMapping(JS_DQ, JavascriptParser.STATE_DQ);
    registerMapping(JS_DQ_E, JavascriptParser.STATE_DQ);
    registerMapping(JS_SLASH, JavascriptParser.STATE_TEXT);
    registerMapping(JS_REGEXP_SLASH, JavascriptParser.STATE_TEXT);
    registerMapping(JS_REGEXP, JavascriptParser.STATE_REGEXP);
    registerMapping(JS_REGEXP_BRK, JavascriptParser.STATE_REGEXP);
    registerMapping(JS_REGEXP_BRK_E, JavascriptParser.STATE_REGEXP);
    registerMapping(JS_REGEXP_E, JavascriptParser.STATE_REGEXP);
    registerMapping(JS_COM_LN, JavascriptParser.STATE_COMMENT);
    registerMapping(JS_COM_ML, JavascriptParser.STATE_COMMENT);
    registerMapping(JS_COM_ML_CLOSE, JavascriptParser.STATE_COMMENT);
    registerMapping(JS_COM_AFTER, JavascriptParser.STATE_TEXT);
  }
  
  private static void registerTransition(String expression, InternalState source, InternalState to)
  {
    StateTableTransition stt = new StateTableTransition(expression, source, to);
    
    STATE_TABLE.setExpression(stt.getExpression(), stt.getFrom(), stt.getTo());
  }
  
  private static void initializeParserStateTable()
  {
    registerTransition("[:default:]", JS_COM_AFTER, JS_TEXT);
    registerTransition("/", JS_COM_AFTER, JS_SLASH);
    registerTransition("\"", JS_COM_AFTER, JS_DQ);
    registerTransition("'", JS_COM_AFTER, JS_Q);
    registerTransition("[:default:]", JS_COM_ML_CLOSE, JS_COM_ML);
    registerTransition("/", JS_COM_ML_CLOSE, JS_COM_AFTER);
    registerTransition("[:default:]", JS_COM_ML, JS_COM_ML);
    registerTransition("*", JS_COM_ML, JS_COM_ML_CLOSE);
    registerTransition("[:default:]", JS_COM_LN, JS_COM_LN);
    registerTransition("\n", JS_COM_LN, JS_COM_AFTER);
    registerTransition("[:default:]", JS_REGEXP_E, JS_REGEXP);
    registerTransition("[:default:]", JS_REGEXP_BRK_E, JS_REGEXP_BRK);
    registerTransition("[:default:]", JS_REGEXP_BRK, JS_REGEXP_BRK);
    registerTransition("]", JS_REGEXP_BRK, JS_REGEXP);
    registerTransition("\\", JS_REGEXP_BRK, JS_REGEXP_BRK_E);
    registerTransition("[:default:]", JS_REGEXP, JS_REGEXP);
    registerTransition("/", JS_REGEXP, JS_TEXT);
    registerTransition("[", JS_REGEXP, JS_REGEXP_BRK);
    registerTransition("\\", JS_REGEXP, JS_REGEXP_E);
    registerTransition("[:default:]", JS_REGEXP_SLASH, JS_REGEXP);
    registerTransition("[", JS_REGEXP_SLASH, JS_REGEXP_BRK);
    registerTransition("\\", JS_REGEXP_SLASH, JS_REGEXP_E);
    registerTransition("*", JS_REGEXP_SLASH, JS_COM_ML);
    registerTransition("/", JS_REGEXP_SLASH, JS_COM_LN);
    registerTransition("[:default:]", JS_SLASH, JS_TEXT);
    registerTransition("*", JS_SLASH, JS_COM_ML);
    registerTransition("/", JS_SLASH, JS_COM_LN);
    registerTransition("[:default:]", JS_DQ_E, JS_DQ);
    registerTransition("[:default:]", JS_DQ, JS_DQ);
    registerTransition("\"", JS_DQ, JS_TEXT);
    registerTransition("\\", JS_DQ, JS_DQ_E);
    registerTransition("[:default:]", JS_Q_E, JS_Q);
    registerTransition("[:default:]", JS_Q, JS_Q);
    registerTransition("'", JS_Q, JS_TEXT);
    registerTransition("\\", JS_Q, JS_Q_E);
    registerTransition("[:default:]", JS_TEXT, JS_TEXT);
    registerTransition("/", JS_TEXT, JS_SLASH);
    registerTransition("\"", JS_TEXT, JS_DQ);
    registerTransition("'", JS_TEXT, JS_Q);
  }
}

/* Location:
 * Qualified Name:     com.google.streamhtmlparser.impl.JavascriptParserImpl
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.google.streamhtmlparser.impl;

import com.google.common.base.Preconditions;

class ParserStateTable
{
  private static final int MAX_STATES = 256;
  private static final int MAX_CHARS = 256;
  private final InternalState[][] stateTable;
  private final InternalState[] defaultStateTable;
  
  public ParserStateTable()
  {
    stateTable = new InternalState['?']['?'];
    defaultStateTable = new InternalState['?'];
  }
  
  InternalState getNextState(InternalState from, int currentChar)
  {
    if ((from == null) || (currentChar < 0)) {
      return InternalState.INTERNAL_ERROR_STATE;
    }
    int id = from.getId();
    if ((id < 0) || (id >= 256)) {
      return InternalState.INTERNAL_ERROR_STATE;
    }
    InternalState result = null;
    if (currentChar < 256) {
      result = stateTable[id][currentChar];
    }
    if (result == null) {
      result = defaultStateTable[from.getId()];
    }
    return result != null ? result : InternalState.INTERNAL_ERROR_STATE;
  }
  
  void setExpression(String expr, InternalState from, InternalState to)
  {
    if ((expr == null) || (from == null) || (to == null)) {
      return;
    }
    if ("[:default:]".equals(expr))
    {
      setDefaultDestination(from, to);
      return;
    }
    int i = 0;
    while (i < expr.length()) {
      if ((i < expr.length() - 2) && (expr.charAt(i + 1) == '-'))
      {
        setRange(from, expr.charAt(i), expr.charAt(i + 2), to);
        i += 2;
      }
      else
      {
        setDestination(from, expr.charAt(i), to);
        i++;
      }
    }
  }
  
  private void fill(InternalState from, InternalState to)
  {
    for (char c = '\000'; c < '?'; c = (char)(c + '\001')) {
      setDestination(from, c, to);
    }
  }
  
  private void setDefaultDestination(InternalState from, InternalState to)
  {
    Preconditions.checkNotNull(from);
    Preconditions.checkNotNull(to);
    int id = from.getId();
    if ((id < 0) || (id >= 256)) {
      return;
    }
    defaultStateTable[from.getId()] = to;
  }
  
  private void setDestination(InternalState from, char chr, InternalState to)
  {
    Preconditions.checkNotNull(from);
    Preconditions.checkNotNull(to);
    Preconditions.checkArgument((chr >= 0) && (chr < '?'), "char must be in ASCII set: %c", new Object[] { Character.valueOf(chr) });
    
    int id = from.getId();
    if ((id < 0) || (id >= 256)) {
      return;
    }
    stateTable[from.getId()][chr] = to;
  }
  
  private void setRange(InternalState from, char start, char end, InternalState to)
  {
    Preconditions.checkArgument((start >= 0) && (start < '?'), "char must be in ASCII set: %c", new Object[] { Character.valueOf(start) });
    
    Preconditions.checkArgument((end >= 0) && (end < '?'), "char must be in ASCII set: %c", new Object[] { Character.valueOf(end) });
    for (char c = start; c <= end; c = (char)(c + '\001')) {
      setDestination(from, c, to);
    }
  }
}

/* Location:
 * Qualified Name:     com.google.streamhtmlparser.impl.ParserStateTable
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.google.streamhtmlparser.impl;

class HtmlParserImpl$1 {}

/* Location:
 * Qualified Name:     com.google.streamhtmlparser.impl.HtmlParserImpl.1
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.google.streamhtmlparser.impl;

import com.google.common.base.Preconditions;
import com.google.streamhtmlparser.ExternalState;
import com.google.streamhtmlparser.ParseException;
import com.google.streamhtmlparser.Parser;
import com.google.streamhtmlparser.util.HtmlUtils;
import java.util.Map;

public class GenericParser
  implements Parser
{
  protected final ParserStateTable parserStateTable;
  protected final Map<InternalState, ExternalState> intToExtStateTable;
  protected final InternalState initialState;
  protected InternalState currentState;
  protected int lineNumber;
  protected int columnNumber;
  
  protected GenericParser(ParserStateTable parserStateTable, Map<InternalState, ExternalState> intToExtStateTable, InternalState initialState)
  {
    this.parserStateTable = parserStateTable;
    this.intToExtStateTable = intToExtStateTable;
    this.initialState = initialState;
    currentState = initialState;
    lineNumber = 1;
    columnNumber = 1;
  }
  
  protected GenericParser(GenericParser aGenericParser)
  {
    parserStateTable = parserStateTable;
    intToExtStateTable = intToExtStateTable;
    initialState = initialState;
    currentState = currentState;
    lineNumber = lineNumber;
    columnNumber = columnNumber;
  }
  
  public void parse(String input)
    throws ParseException
  {
    for (int i = 0; i < input.length(); i++) {
      parse(input.charAt(i));
    }
  }
  
  public void parse(char input)
    throws ParseException
  {
    InternalState nextState = parserStateTable.getNextState(currentState, input);
    if (nextState == InternalState.INTERNAL_ERROR_STATE)
    {
      String errorMsg = String.format("Unexpected character '%s' in int_state '%s' (ext_state '%s')", new Object[] { HtmlUtils.encodeCharForAscii(input), currentState.getName(), getState().getName() });
      
      currentState = InternalState.INTERNAL_ERROR_STATE;
      throw new ParseException(this, errorMsg);
    }
    if (currentState != nextState) {
      nextState = handleExitState(currentState, nextState, input);
    }
    if (currentState != nextState) {
      nextState = handleEnterState(nextState, nextState, input);
    }
    nextState = handleInState(nextState, input);
    currentState = nextState;
    record(input);
    
    columnNumber += 1;
    if (input == '\n')
    {
      lineNumber += 1;
      columnNumber = 1;
    }
  }
  
  public ExternalState getState()
  {
    if (!intToExtStateTable.containsKey(currentState)) {
      throw new NullPointerException("Did not find external state mapping For internal state: " + currentState);
    }
    return (ExternalState)intToExtStateTable.get(currentState);
  }
  
  public void reset()
  {
    currentState = initialState;
    lineNumber = 1;
    columnNumber = 1;
  }
  
  public void setLineNumber(int lineNumber)
  {
    this.lineNumber = lineNumber;
  }
  
  public int getLineNumber()
  {
    return lineNumber;
  }
  
  public void setColumnNumber(int columnNumber)
  {
    this.columnNumber = columnNumber;
  }
  
  public int getColumnNumber()
  {
    return columnNumber;
  }
  
  InternalState getCurrentInternalState()
  {
    return currentState;
  }
  
  protected void setNextState(InternalState nextState)
    throws ParseException
  {
    Preconditions.checkNotNull(nextState);
    
    char nullChar = '\000';
    if (currentState != nextState) {
      nextState = handleExitState(currentState, nextState, '\000');
    }
    if (currentState != nextState) {
      handleEnterState(nextState, nextState, '\000');
    }
    currentState = nextState;
  }
  
  protected InternalState handleEnterState(InternalState currentState, InternalState expectedNextState, char input)
    throws ParseException
  {
    return expectedNextState;
  }
  
  protected InternalState handleExitState(InternalState currentState, InternalState expectedNextState, char input)
    throws ParseException
  {
    return expectedNextState;
  }
  
  protected InternalState handleInState(InternalState currentState, char input)
    throws ParseException
  {
    return currentState;
  }
  
  protected void record(char input) {}
}

/* Location:
 * Qualified Name:     com.google.streamhtmlparser.impl.GenericParser
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.google.streamhtmlparser.impl;

import com.google.common.base.Preconditions;
import java.util.concurrent.atomic.AtomicInteger;

class InternalState
{
  static final InternalState INTERNAL_ERROR_STATE = new InternalState();
  private static final int MAX_ID = 255;
  private static final int FIRST_ID = 1;
  private static AtomicInteger htmlStates = new AtomicInteger(1);
  private static AtomicInteger javascriptStates = new AtomicInteger(1);
  private final String name;
  private final int id;
  
  private InternalState(String name, int id)
  {
    Preconditions.checkNotNull(name);
    Preconditions.checkArgument(id >= 1);
    Preconditions.checkArgument(id <= 255);
    this.name = name;
    this.id = id;
  }
  
  private InternalSt
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

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