jsilver-1.0.0

ate()
  {
    name = "InternalStateError";
    id = 0;
  }
  
  public String getName()
  {
    return name;
  }
  
  public int getId()
  {
    return id;
  }
  
  public String toString()
  {
    return String.format("InternalState: Name: %s; Id: %d", new Object[] { name, Integer.valueOf(id) });
  }
  
  static InternalState getInstanceHtml(String name)
  {
    int htmlStateId = htmlStates.getAndIncrement();
    return new InternalState(name, htmlStateId);
  }
  
  static InternalState getInstanceJavascript(String name)
  {
    int javascriptStateId = javascriptStates.getAndIncrement();
    return new InternalState(name, javascriptStateId);
  }
}

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

public class ParseException
  extends Exception
{
  public ParseException() {}
  
  public ParseException(Parser parser, String msg)
  {
    super(String.format("At line: %d (col: %d); %s", new Object[] { Integer.valueOf(parser.getLineNumber()), Integer.valueOf(parser.getColumnNumber()), msg }));
  }
}

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

public abstract interface Parser
{
  public static final ExternalState STATE_ERROR = new ExternalState("STATE_ERROR");
  
  public abstract void parse(char paramChar)
    throws ParseException;
  
  public abstract void parse(String paramString)
    throws ParseException;
  
  public abstract void reset();
  
  public abstract ExternalState getState();
  
  public abstract void setLineNumber(int paramInt);
  
  public abstract int getLineNumber();
  
  public abstract void setColumnNumber(int paramInt);
  
  public abstract int getColumnNumber();
}

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

public abstract interface HtmlParser
  extends Parser
{
  public abstract boolean inJavascript();
  
  public abstract boolean isJavascriptQuoted();
  
  public abstract boolean inAttribute();
  
  public abstract boolean inCss();
  
  public abstract ATTR_TYPE getAttributeType();
  
  public abstract boolean isAttributeQuoted();
  
  public abstract String getTag();
  
  public abstract String getAttribute();
  
  public abstract String getValue();
  
  public abstract int getValueIndex();
  
  public abstract boolean isUrlStart();
  
  public abstract void resetMode(Mode paramMode);
  
  public abstract void insertText()
    throws ParseException;
  
  public abstract ExternalState getJavascriptState();
  
  public static enum Mode
  {
    HTML,  JS,  CSS,  HTML_IN_TAG;
    
    private Mode() {}
  }
  
  public static enum ATTR_TYPE
  {
    NONE,  REGULAR,  URI,  JS,  STYLE;
    
    private ATTR_TYPE() {}
  }
  
  public static final ExternalState STATE_TEXT = new ExternalState("STATE_TEXT");
  public static final ExternalState STATE_TAG = new ExternalState("STATE_TAG");
  public static final ExternalState STATE_COMMENT = new ExternalState("STATE_COMMENT");
  public static final ExternalState STATE_ATTR = new ExternalState("STATE_ATTR");
  public static final ExternalState STATE_VALUE = new ExternalState("STATE_VALUE");
  public static final ExternalState STATE_JS_FILE = new ExternalState("STATE_JS_FILE");
  public static final ExternalState STATE_CSS_FILE = new ExternalState("STATE_CSS_FILE");
}

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

public enum HtmlParserFactory$ModeOptions
{
  JS_QUOTED;
  
  private HtmlParserFactory$ModeOptions() {}
}

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

public class CharacterRecorder
{
  public static final int RECORDING_BUFFER_SIZE = 255;
  private final StringBuilder sb;
  private boolean recording;
  
  public CharacterRecorder()
  {
    sb = new StringBuilder(255);
    recording = false;
  }
  
  public CharacterRecorder(CharacterRecorder aCharacterRecorder)
  {
    recording = recording;
    sb = new StringBuilder(255);
    sb.append(aCharacterRecorder.getContent());
  }
  
  public void startRecording()
  {
    sb.setLength(0);
    recording = true;
  }
  
  public void stopRecording()
  {
    recording = false;
  }
  
  public void maybeRecord(char input)
  {
    if ((recording) && (sb.length() < 255)) {
      sb.append(input);
    }
  }
  
  public void clear()
  {
    sb.setLength(0);
  }
  
  public void reset()
  {
    clear();
    recording = false;
  }
  
  public String getContent()
  {
    return sb.toString();
  }
  
  public boolean isRecording()
  {
    return recording;
  }
  
  public String toString()
  {
    return String.format("In recording: %s; Value: %s", new Object[] { Boolean.valueOf(isRecording()), sb.toString() });
  }
}

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

public enum HtmlUtils$META_REDIRECT_TYPE
{
  NONE,  URL_START,  URL;
  
  private HtmlUtils$META_REDIRECT_TYPE() {}
}

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

import com.google.common.collect.ImmutableSortedSet;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public final class HtmlUtils
{
  private static final String META_REDIRECT_REGEX = "^\\s*\\d*\\s*;\\s*URL\\s*=\\s*['\"]?";
  
  public static enum META_REDIRECT_TYPE
  {
    NONE,  URL_START,  URL;
    
    private META_REDIRECT_TYPE() {}
  }
  
  private static final Pattern META_REDIRECT_PATTERN = Pattern.compile("^\\s*\\d*\\s*;\\s*URL\\s*=\\s*['\"]?", 2);
  private static final Set<String> REGEXP_TOKEN_PREFIXS = ImmutableSortedSet.of("abstract", "break", "case", "catch", "class", "const", new String[] { "continue", "debugger", "default", "delete", "do", "else", "enum", "eval", "export", "extends", "field", "final", "finally", "for", "function", "goto", "if", "implements", "import", "in", "instanceof", "native", "new", "package", "private", "protected", "public", "return", "static", "switch", "synchronized", "throw", "throws", "transient", "try", "typeof", "var", "void", "volatile", "while", "with" });
  private static final Set<String> ATTRIBUTE_EXPECTS_URI = ImmutableSortedSet.of("action", "archive", "background", "cite", "classid", "codebase", new String[] { "data", "dynsrc", "href", "longdesc", "src", "usemap" });
  private static final Set<Character> JAVASCRIPT_WHITESPACE = ImmutableSortedSet.of(Character.valueOf('\t'), Character.valueOf('\n'), Character.valueOf('\013'), Character.valueOf('\f'), Character.valueOf('\r'), Character.valueOf(' '), new Character[] { Character.valueOf('�'), Character.valueOf('?'), Character.valueOf('?') });
  private static final Set<Character> HTML_WHITESPACE = ImmutableSortedSet.of(Character.valueOf(' '), Character.valueOf('\t'), Character.valueOf('\n'), Character.valueOf('\r'), Character.valueOf('?'));
  
  public static boolean isAttributeJavascript(String attribute)
  {
    return (attribute != null) && (attribute.startsWith("on"));
  }
  
  public static boolean isAttributeStyle(String attribute)
  {
    return "style".equals(attribute);
  }
  
  public static boolean isAttributeUri(String attribute)
  {
    return ATTRIBUTE_EXPECTS_URI.contains(attribute);
  }
  
  public static boolean isHtmlSpace(char chr)
  {
    return HTML_WHITESPACE.contains(Character.valueOf(chr));
  }
  
  public static boolean isJavascriptWhitespace(char chr)
  {
    return JAVASCRIPT_WHITESPACE.contains(Character.valueOf(chr));
  }
  
  public static boolean isJavascriptIdentifier(char chr)
  {
    return ((chr >= 'a') && (chr <= 'z')) || ((chr >= 'A') && (chr <= 'Z')) || ((chr >= '0') && (chr <= '9')) || (chr == '_') || (chr == '$');
  }
  
  public static boolean isJavascriptRegexpPrefix(String input)
  {
    return REGEXP_TOKEN_PREFIXS.contains(input);
  }
  
  public static String encodeCharForAscii(char chr)
  {
    if (chr == '\'') {
      return "\\'";
    }
    if (chr == '\\') {
      return "\\\\";
    }
    if ((chr >= ' ') && (chr <= '~')) {
      return String.format("%c", new Object[] { Character.valueOf(chr) });
    }
    if (chr == '\n') {
      return "\\n";
    }
    if (chr == '\r') {
      return "\\r";
    }
    if (chr == '\t') {
      return "\\t";
    }
    return String.format("\\u%04x", new Object[] { Integer.valueOf(chr) });
  }
  
  public static META_REDIRECT_TYPE parseContentAttributeForUrl(String value)
  {
    if (value == null) {
      return META_REDIRECT_TYPE.NONE;
    }
    Matcher matcher = META_REDIRECT_PATTERN.matcher(value);
    if (!matcher.find()) {
      return META_REDIRECT_TYPE.NONE;
    }
    if (value.length() > matcher.end()) {
      return META_REDIRECT_TYPE.URL;
    }
    return META_REDIRECT_TYPE.URL_START;
  }
}

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

public enum EntityResolver$Status
{
  NOT_STARTED("Not Started"),  IN_PROGRESS("In Progress"),  COMPLETED("Completed");
  
  private final String message;
  
  private EntityResolver$Status(String message)
  {
    this.message = message;
  }
  
  public String toString()
  {
    return message;
  }
}

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

import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMap.Builder;
import java.util.Map;

public class EntityResolver
{
  private static final int MAX_ENTITY_SIZE = 10;
  
  public static enum Status
  {
    NOT_STARTED("Not Started"),  IN_PROGRESS("In Progress"),  COMPLETED("Completed");
    
    private final String message;
    
    private Status(String message)
    {
      this.message = message;
    }
    
    public String toString()
    {
      return message;
    }
  }
  
  private static final Map<String, String> HTML_ENTITIES_MAP = new ImmutableMap.Builder().put("&lt", "<").put("&gt", ">").put("&amp", "&").put("&apos", "'").build();
  private final StringBuilder sb;
  private Status status;
  private String entity;
  
  public EntityResolver()
  {
    sb = new StringBuilder();
    status = Status.NOT_STARTED;
    entity = "";
  }
  
  public EntityResolver(EntityResolver aEntityResolver)
  {
    sb = new StringBuilder();
    sb.replace(0, sb.length(), sb.toString());
    entity = entity;
    status = status;
  }
  
  public void reset()
  {
    status = Status.NOT_STARTED;
    sb.setLength(0);
    entity = "";
  }
  
  public String toString()
  {
    return String.format("Status: %s; Contents (%d): %s", new Object[] { status.toString(), Integer.valueOf(sb.length()), sb.toString() });
  }
  
  public String getEntity()
  {
    return entity;
  }
  
  public Status processChar(char input)
  {
    Preconditions.checkState((status != Status.NOT_STARTED) || (sb.length() == 0));
    if (status == Status.NOT_STARTED)
    {
      if (input == '&')
      {
        sb.append(input);
        status = Status.IN_PROGRESS;
      }
    }
    else if (status == Status.IN_PROGRESS) {
      if ((input == ';') || (HtmlUtils.isHtmlSpace(input)))
      {
        status = Status.COMPLETED;
        entity = convertEntity(input);
      }
      else if (sb.length() < 10)
      {
        sb.append(input);
      }
      else
      {
        status = Status.COMPLETED;
        entity = uncovertedInput(input);
      }
    }
    return status;
  }
  
  private String convertEntity(char terminator)
  {
    Preconditions.checkArgument(sb.length() > 0);
    Preconditions.checkArgument(sb.charAt(0) == '&');
    if (sb.length() > 1)
    {
      if (sb.charAt(1) == '#')
      {
        if (sb.length() <= 2) {
          return uncovertedInput(terminator);
        }
        try
        {
          if ((sb.charAt(2) == 'x') || (sb.charAt(2) == 'X')) {
            return new String(Character.toChars(Integer.parseInt(sb.substring(3), 16)));
          }
          return new String(Character.toChars(Integer.parseInt(sb.substring(2))));
        }
        catch (NumberFormatException e)
        {
          return uncovertedInput(terminator);
        }
      }
      String key = sb.toString();
      if (HTML_ENTITIES_MAP.containsKey(key)) {
        return (String)HTML_ENTITIES_MAP.get(key);
      }
    }
    return uncovertedInput(terminator);
  }
  
  private String uncovertedInput(char terminator)
  {
    return String.format("%s%c", new Object[] { sb.toString(), Character.valueOf(terminator) });
  }
}

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

import com.google.common.base.Preconditions;
import java.util.Arrays;

public class JavascriptTokenBuffer
{
  private static final int BUFFER_SIZE = 18;
  private final char[] buffer;
  private int startIndex;
  private int endIndex;
  
  public JavascriptTokenBuffer()
  {
    buffer = new char[18];
    startIndex = 0;
    endIndex = 0;
  }
  
  public JavascriptTokenBuffer(JavascriptTokenBuffer aJavascriptTokenBuffer)
  {
    buffer = Arrays.copyOf(buffer, buffer.length);
    
    startIndex = startIndex;
    endIndex = endIndex;
  }
  
  public void appendString(String input)
  {
    if (input == null) {
      throw new NullPointerException("input == null is not allowed");
    }
    for (int i = 0; i < input.length(); i++) {
      appendChar(input.charAt(i));
    }
  }
  
  public void appendChar(char input)
  {
    if ((HtmlUtils.isJavascriptWhitespace(input)) && (HtmlUtils.isJavascriptWhitespace(getChar(-1)))) {
      return;
    }
    buffer[endIndex] = input;
    endIndex = ((endIndex + 1) % buffer.length);
    if (endIndex == startIndex) {
      startIndex = ((endIndex + 1) % buffer.length);
    }
  }
  
  public char popChar()
  {
    if (startIndex == endIndex) {
      return '\000';
    }
    endIndex -= 1;
    if (endIndex < 0) {
      endIndex += buffer.length;
    }
    return buffer[endIndex];
  }
  
  public char getChar(int position)
  {
    assert (position < 0);
    
    int absolutePosition = getAbsolutePosition(position);
    if (absolutePosition < 0) {
      return '\000';
    }
    return buffer[absolutePosition];
  }
  
  public boolean setChar(int position, char input)
  {
    assert (position < 0);
    
    int absolutePosition = getAbsolutePosition(position);
    if (absolutePosition < 0) {
      return false;
    }
    buffer[absolutePosition] = input;
    return true;
  }
  
  public String getLastIdentifier()
  {
    int end = -1;
    if (HtmlUtils.isJavascriptWhitespace(getChar(-1))) {
      end--;
    }
    for (int position = end; HtmlUtils.isJavascriptIdentifier(getChar(position));) {
      position--;
    }
    if (position + 1 >= end) {
      return null;
    }
    return slice(position + 1, end);
  }
  
  public String slice(int start, int end)
  {
    Preconditions.checkArgument(start <= end);
    Preconditions.checkArgument(start < 0);
    Preconditions.checkArgument(end < 0);
    
    StringBuffer output = new StringBuffer();
    for (int position = start; position <= end; position++)
    {
      char c = getChar(position);
      if (c != 0) {
        output.append(c);
      }
    }
    return new String(output);
  }
  
  private int getAbsolutePosition(int position)
  {
    assert (position < 0);
    if (position <= -buffer.length) {
      return -1;
    }
    int len = endIndex - startIndex;
    if (len < 0) {
      len += buffer.length;
    }
    if (position < -len) {
      return -1;
    }
    int absolutePosition = (position + endIndex) % buffer.length;
    if (absolutePosition < 0) {
      absolutePosition += buffer.length;
    }
    return absolutePosition;
  }
}

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

public abstract interface JavascriptParser
  extends Parser
{
  public static final ExternalState STATE_TEXT = new ExternalState("STATE_TEXT");
  public static final ExternalState STATE_Q = new ExternalState("STATE_Q");
  public static final ExternalState STATE_DQ = new ExternalState("STATE_DQ");
  public static final ExternalState STATE_REGEXP = new ExternalState("STATE_REGEXP");
  public static final ExternalState STATE_COMMENT = new ExternalState("STATE_COMMENT");
}

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

class HtmlParserFactory$1 {}

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

import com.google.streamhtmlparser.impl.HtmlParserImpl;
import java.io.PrintStream;
import java.util.Set;
import java.util.logging.Logger;

public class HtmlParserFactory
{
  private static final Logger logger = Logger.getLogger(HtmlParserFactory.class.getName());
  
  public static enum AttributeOptions
  {
    JS_QUOTED,  URL_PARTIAL;
    
    private AttributeOptions() {}
  }
  
  public static enum ModeOptions
  {
    JS_QUOTED;
    
    private ModeOptions() {}
  }
  
  private static final HtmlParser parserInDefaultAttr = createParser();
  private static final HtmlParser parserInDefaultAttrQ = createParser();
  private static final HtmlParser parserInUriAttrComplete = createParser();
  private static final HtmlParser parserInUriAttrQComplete = createParser();
  private static final HtmlParser parserInUriAttrPartial = createParser();
  private static final HtmlParser parserInUriAttrQPartial = createParser();
  private static final HtmlParser parserInJsAttr = createParser();
  private static final HtmlParser parserInJsAttrQ = createParser();
  private static final HtmlParser parserInQJsAttr = createParser();
  private static final HtmlParser parserInStyleAttr = createParser();
  private static final HtmlParser parserInStyleAttrQ = createParser();
  private static final HtmlParser parserInJsQ = createParser();
  private static boolean initSuccess = false;
  
  static
  {
    try
    {
      initializeParsers();
      initSuccess = true;
    }
    catch (ParseException e)
    {
      String error = HtmlParserFactory.class.getName() + " Failed initialization: " + e.getMessage();
      
      logger.severe(error);
      System.err.println(error);
      e.printStackTrace();
    }
  }
  
  public static HtmlParser createParser()
  {
    return new HtmlParserImpl();
  }
  
  public static HtmlParser createParserInMode(HtmlParser.Mode mode, Set<ModeOptions> options)
  {
    
    if ((options != null) && (options.contains(ModeOptions.JS_QUOTED))) {
      return createParser(parserInJsQ);
    }
    HtmlParser parser = new HtmlParserImpl();
    parser.resetMode(mode);
    return parser;
  }
  
  public static HtmlParser createParser(HtmlParser aHtmlParser)
  {
    requireInitialized();
    
    return new HtmlParserImpl((HtmlParserImpl)aHtmlParser);
  }
  
  public static HtmlParser createParserInAttribute(HtmlParser.ATTR_TYPE attrtype, boolean quoted, Set<AttributeOptions> options)
  {
    
    HtmlParser parser;
    HtmlParser parser;
    HtmlParser parser;
    switch (attrtype)
    {
    case REGULAR: 
      parser = createParser(quoted ? parserInDefaultAttrQ : parserInDefaultAttr);
      
      break;
    case URI: 
      if ((options != null) && (options.contains(AttributeOptions.URL_PARTIAL))) {
        parser = createParser(quoted ? parserInUriAttrQPartial : parserInUriAttrPartial);
      } else {
        parser = createParser(quoted ? parserInUriAttrQComplete : parserInUriAttrComplete);
      }
      break;
    case JS: 
      HtmlParser parser;
      if (quoted)
      {
        if ((options != null) && (options.contains(AttributeOptions.JS_QUOTED))) {
          parser = createParser(parserInQJsAttr);
        } else {
          parser = createParser(parserInJsAttrQ);
        }
      }
      else {
        parser = createParser(parserInJsAttr);
      }
      break;
    case STYLE: 
      parser = createParser(quoted ? parserInStyleAttrQ : parserInStyleAttr);
      
      break;
    case NONE: 
      parser = createParserInMode(HtmlParser.Mode.HTML_IN_TAG, null);
      break;
    default: 
      throw new IllegalArgumentException("Did not recognize ATTR_TYPE given: " + attrtype);
    }
    return parser;
  }
  
  private static void initializeParsers()
    throws ParseException
  {
    parserInDefaultAttr.parse("<xparsertag htmlparser=");
    parserInDefaultAttrQ.parse("<xparsertag htmlparser=\"");
    
    parserInUriAttrComplete.parse("<xparsertag src=");
    parserInUriAttrQComplete.parse("<xparsertag src=\"");
    
    String fakeUrlPrefix = "http://example.com/fakequeryparam=";
    parserInUriAttrPartial.parse("<xparsertag src=http://example.com/fakequeryparam=");
    parserInUriAttrQPartial.parse("<xparsertag src=\"http://example.com/fakequeryparam=");
    
    parserInJsAttr.parse("<xparsertag onmouse=");
    parserInJsAttrQ.parse("<xparsertag onmouse=\"");
    
    parserInQJsAttr.parse("<xparsertag onmouse=\"'");
    
    parserInJsQ.resetMode(HtmlParser.Mode.JS);
    parserInJsQ.parse("var fakeparservar='");
    
    parserInStyleAttr.parse("<xparsertag style=");
    parserInStyleAttrQ.parse("<xparsertag style=\"");
  }
  
  private static void requireInitialized()
  {
    if (!initSuccess) {
      throw new AssertionError("HtmlParserFactory failed initialization.");
    }
  }
}

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

import com.google.common.base.Preconditions;

public class ExternalState
{
  private final String name;
  
  public ExternalState(String name)
  {
    Preconditions.checkNotNull(name);
    this.name = name;
  }
  
  public String getName()
  {
    return name;
  }
  
  public String toString()
  {
    return String.format("ExternalState: %s", new Object[] { name });
  }
}

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

public enum HtmlParserFactory$AttributeOptions
{
  JS_QUOTED,  URL_PARTIAL;
  
  private HtmlParserFactory$AttributeOptions() {}
}

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

public enum HtmlParser$ATTR_TYPE
{
  NONE,  REGULAR,  URI,  JS,  STYLE;
  
  private HtmlParser$ATTR_TYPE() {}
}

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

import com.google.clearsilver.jsilver.syntax.analysis.DepthFirstAdapter;
import com.google.clearsilver.jsilver.syntax.node.AAddExpression;
import com.google.clearsilver.jsilver.syntax.node.ADecimalExpression;
import com.google.clearsilver.jsilver.syntax.node.ADivideExpression;
import com.google.clearsilver.jsilver.syntax.node.AEqExpression;
import com.google.clearsilver.jsilver.syntax.node.AFunctionExpression;
import com.google.clearsilver.jsilver.syntax.node.AHexExpression;
import com.google.clearsilver.jsilver.syntax.node.AModuloExpression;
import com.google.clearsilver.jsilver.syntax.node.AMultiplyExpression;
import com.google.clearsilver.jsilver.syntax.node.ANameVariable;
import com.google.clearsilver.jsilver.syntax.node.ANeExpression;
import com.google.clearsilver.jsilver.syntax.node.ANegativeExpression;
import com.google.clearsilver.jsilver.syntax.node.ANumericAddExpression;
import com.google.clearsilver.jsilver.syntax.node.ANumericEqExpression;
import com.google.clearsilver.jsilver.syntax.node.ANumericExpression;
import com.google.clearsilver.jsilver.syntax.node.ANumericNeExpression;
import com.google.clearsilver.jsilver.syntax.node.ASubtractExpression;
import com.google.clearsilver.jsilver.syntax.node.PExpression;
import com.google.clearsilver.jsilver.syntax.node.PVariable;
import com.google.clearsilver.jsilver.syntax.node.TWord;

public class TypeResolver
  extends DepthFirstAdapter
{
  public void caseAAddExpression(AAddExpression node)
  {
    super.caseAAddExpression(node);
    PExpression lhs = node.getLeft();
    PExpression rhs = node.getRight();
    if ((isNumeric(lhs)) || (isNumeric(rhs))) {
      node.replaceBy(new ANumericAddExpression(lhs, rhs));
    }
  }
  
  public void caseAEqExpression(AEqExpression node)
  {
    super.caseAEqExpression(node);
    PExpression lhs = node.getLeft();
    PExpression rhs = node.getRight();
    if ((isNumeric(lhs)) || (isNumeric(rhs))) {
      node.replaceBy(new ANumericEqExpression(lhs, rhs));
    }
  }
  
  public void caseANeExpression(ANeExpression node)
  {
    super.caseANeExpression(node);
    PExpression lhs = node.getLeft();
    PExpression rhs = node.getRight();
    if ((isNumeric(lhs)) || (isNumeric(rhs))) {
      node.replaceBy(new ANumericNeExpression(lhs, rhs));
    }
  }
  
  static boolean isNumeric(PExpression node)
  {
    return ((node instanceof ANumericExpression)) || ((node instanceof ANumericAddExpression)) || ((node instanceof ASubtractExpression)) || ((node instanceof AMultiplyExpression)) || ((node instanceof ADivideExpression)) || ((node instanceof AModuloExpression)) || ((node instanceof ADecimalExpression)) || ((node instanceof AHexExpression)) || ((node instanceof ANegativeExpression)) || (isNumericFunction(node));
  }
  
  static boolean isNumericFunction(PExpression node)
  {
    if (!(node instanceof AFunctionExpression)) {
      return false;
    }
    PVariable functionName = ((AFunctionExpression)node).getName();
    if ((functionName instanceof ANameVariable))
    {
      String name = ((ANameVariable)functionName).getWord().getText();
      if (("max".equals(name)) || ("min".equals(name)) || ("abs".equals(name)) || ("subcount".equals(name))) {
        return true;
      }
    }
    return false;
  }
}

/* Location:
 * Qualified Name:     com.google.clearsilver.jsilver.syntax.TypeResolver
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.google.clearsilver.jsilver.syntax;

import com.google.clearsilver.jsilver.syntax.analysis.DepthFirstAdapter;
import com.google.clearsilver.jsilver.syntax.node.AMultipleCommand;
import com.google.clearsilver.jsilver.syntax.node.AOptimizedMultipleCommand;

public class SyntaxTreeOptimizer
  extends DepthFirstAdapter
{
  public void caseAMultipleCommand(AMultipleCommand originalNode)
  {
    super.caseAMultipleCommand(originalNode);
    
    originalNode.replaceBy(new AOptimizedMultipleCommand(originalNode));
  }
}

/* Location:
 * Qualified Name:     com.google.clearsilver.jsilver.syntax.SyntaxTreeOptimizer
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.google.clearsilver.jsilver.syntax;

import com.google.clearsilver.jsilver.syntax.analysis.DepthFirstAdapter;
import com.google.clearsilver.jsilver.syntax.node.AAddExpression;
import com.google.clearsilver.jsilver.syntax.node.AEscapeCommand;
import com.google.clearsilver.jsilver.syntax.node.AFunctionExpression;
import com.google.clearsilver.jsilver.syntax.node.AMultipleCommand;
import com.google.clearsilver.jsilver.syntax.node.ANameVariable;
import com.google.clearsilver.jsilver.syntax.node.AStringExpression;
import com.google.clearsilver.jsilver.syntax.node.AVarCommand;
import com.google.clearsilver.jsilver.syntax.node.Node;
import com.google.clearsilver.jsilver.syntax.node.PCommand;
import com.google.clearsilver.jsilver.syntax.node.PExpression;
import com.google.clearsilver.jsilver.syntax.node.PPosition;
import com.google.clearsilver.jsilver.syntax.node.PVariable;
import com.google.clearsilver.jsilver.syntax.node.TString;
import com.google.clearsilver.jsilver.syntax.node.TWord;
import java.util.Collection;
import java.util.LinkedList;

public class VarOptimizer
  extends DepthFirstAdapter
{
  private final Collection<String> escaperNames;
  private static final String ESCAPE_SUFFIX = "_escape";
  
  public VarOptimizer(Collection<String> escaperNames)
  {
    this.escaperNames = escaperNames;
  }
  
  public void caseAMultipleCommand(AMultipleCommand multiCommand)
  {
    super.caseAMultipleCommand(multiCommand);
    multiCommand.replaceBy(optimizeEscapeSequences(multiCommand));
  }
  
  public void caseAVarCommand(AVarCommand varCommand)
  {
    super.caseAVarCommand(varCommand);
    varCommand.replaceBy(optimizeVarCommands(varCommand));
  }
  
  private PCommand optimizeVarCommands(AVarCommand varCommand)
  {
    PExpression expression = varCommand.getExpression();
    PPosition position = varCommand.getPosition();
    if ((expression instanceof AAddExpression))
    {
      AAddExpression addExpression = (AAddExpression)expression;
      AMultipleCommand multiCommand = new AMultipleCommand();
      addToContents(multiCommand, optimizedVarCommandOf(position, addExpression.getLeft()));
      addToContents(multiCommand, optimizedVarCommandOf(position, addExpression.getRight()));
      return optimizeEscapeSequences(multiCommand);
    }
    if ((expression instanceof AFunctionExpression))
    {
      AFunctionExpression functionExpression = (AFunctionExpression)expression;
      String name = escapeNameOf(functionExpression);
      if (escaperNames.contains(name))
      {
        LinkedList<PExpression> args = functionExpression.getArgs();
        if (args.size() == 1) {
          return new AEscapeCommand(position, quotedStringExpressionOf(name), optimizedVarCommandOf(position, (PExpression)args.getFirst()));
        }
      }
    }
    return varCommand;
  }
  
  private PCommand optimizedVarCommandOf(PPosition position, PExpression expression)
  {
    return optimizeVarCommands(new AVarCommand((PPosition)cloneOf(position), (PExpression)cloneOf(expression)));
  }
  
  private static <T extends Node> T cloneOf(T t)
  {
    return (Node)t.clone();
  }
  
  private static void addToContents(AMultipleCommand multi, PCommand command)
  {
    if ((command instanceof AMultipleCommand)) {
      multi.getCommand().addAll(((AMultipleCommand)command).getCommand());
    } else {
      multi.getCommand().add(command);
    }
  }
  
  private static String escapeNameOf(AFunctionExpression function)
  {
    PVariable nvar = function.getName();
    if (!(nvar instanceof ANameVariable)) {
      return null;
    }
    String name = ((ANameVariable)nvar).getWord().getText();
    if (!name.endsWith("_escape")) {
      return null;
    }
    return name.substring(0, name.length() - "_escape".length());
  }
  
  private static AStringExpression quotedStringExpressionOf(String text)
  {
    assert (text.indexOf('"') == -1);
    return new AStringExpression(new TString('"' + text + '"'));
  }
  
  private static PCommand optimizeEscapeSequences(AMultipleCommand multiCommand)
  {
    AEscapeCommand lastEscapeCommand = null;
    LinkedList<PCommand> commands = new LinkedList();
    for (PCommand command : multiCommand.getCommand())
    {
      AEscapeCommand escapeCommand = asSimpleEscapeCommand(command);
      if (isSameEscaper(escapeCommand, lastEscapeCommand))
      {
        addToContents(contentsOf(lastEscapeCommand), escapeCommand.getCommand());
      }
      else
      {
        commands.add(command);
        lastEscapeCommand = escapeCommand;
      }
    }
    assert (!commands.isEmpty());
    return commands.size() > 1 ? new AMultipleCommand(commands) : (PCommand)commands.getFirst();
  }
  
  private static AMultipleCommand contentsOf(AEscapeCommand escapeCommand)
  {
    PCommand escapedCommand = escapeCommand.getCommand();
    if ((escapedCommand instanceof AMultipleCommand)) {
      return (AMultipleCommand)escapedCommand;
    }
    AMultipleCommand multiCommand = new AMultipleCommand();
    multiCommand.getCommand().add(escapedCommand);
    escapeCommand.setCommand(multiCommand);
    return multiCommand;
  }
  
  private static AEscapeCommand asSimpleEscapeCommand(PCommand command)
  {
    if (!(command instanceof AEscapeCommand)) {
      return null;
    }
    AEscapeCommand escapeCommand = (AEscapeCommand)command;
    if (!(escapeCommand.getExpression() instanceof AStringExpression)) {
      return null;
    }
    return escapeCommand;
  }
  
  private static boolean isSameEscaper(AEscapeCommand newCommand, AEscapeCommand oldCommand)
  {
    if ((newCommand == null) || (oldCommand == null)) {
      return false;
    }
    return simpleNameOf(newCommand).equals(simpleNameOf(oldCommand));
  }
  
  private static String simpleNameOf(AEscapeCommand escapeCommand)
  {
    return ((AStringExpression)escapeCommand.getExpression()).getValue().getText();
  }
}

/* Location:
 * Qualified Name:     com.google.clearsilver.jsilver.syntax.VarOptimizer
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.google.clearsilver.jsilver.syntax;

import com.google.clearsilver.jsilver.syntax.node.Start;
import com.google.clearsilver.jsilver.syntax.node.Switch;
import com.google.clearsilver.jsilver.syntax.node.Switchable;

public class TemplateSyntaxTree
  implements Switchable
{
  private final Start root;
  
  TemplateSyntaxTree(Start root)
  {
    this.root = root;
  }
  
  public Start getRoot()
  {
    return root;
  }
  
  public void apply(Switch sw)
  {
    root.apply(sw);
  }
}

/* Location:
 * Qualified Name:     com.google.clearsilver.jsilver.syntax.TemplateSyntaxTree
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.google.clearsilver.jsilver.syntax;

import com.google.clearsilver.jsilver.autoescape.EscapeMode;
import com.google.clearsilver.jsilver.exceptions.JSilverIOException;
import com.google.clearsilver.jsilver.syntax.analysis.DepthFirstAdapter;
import com.google.clearsilver.jsilver.syntax.node.EOF;
import com.google.clearsilver.jsilver.syntax.node.Node;
import com.google.clearsilver.jsilver.syntax.node.Start;
import com.google.clearsilver.jsilver.syntax.node.Token;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintStream;
import java.io.Reader;

public class SyntaxTreeDumper
  extends DepthFirstAdapter
{
  private final Appendable out;
  private final String newLine = System.getProperty("line.separator");
  private int indent;
  
  public SyntaxTreeDumper(Appendable out)
  {
    this.out = out;
  }
  
  public SyntaxTreeDumper()
  {
    this(System.out);
  }
  
  public void defaultIn(Node node)
  {
    write(nodeName(node) + " {");
    indent += 1;
  }
  
  public void defaultOut(Node node)
  {
    indent -= 1;
    write("}");
  }
  
  public void defaultCase(Node node)
  {
    write(nodeName(node));
  }
  
  private String nodeName(Node node)
  {
    if (((node instanceof Start)) || ((node instanceof EOF))) {
      return node.getClass().getSimpleName();
    }
    if ((node instanceof Token))
    {
      Token token = (Token)node;
      String tokenType = token.getClass().getSimpleName().substring(1);
      return tokenType + " [line:" + token.getLine() + ",pos:" + token.getPos() + "] \"" + escape(token.getText()) + "\"";
    }
    String p = node.getClass().getSuperclass().getSimpleName().substring(1);
    String a = node.getClass().getSimpleName().substring(1);
    a = a.substring(0, a.length() - p.length());
    return "<" + a + ">" + p;
  }
  
  private String escape(String text)
  {
    StringBuilder result = new StringBuilder();
    for (int i = 0; i < text.length(); i++)
    {
      char c = text.charAt(i);
      switch (c)
      {
      case '\\': 
        result.append("\\\\");
        break;
      case '"': 
        result.append("\\\"");
        break;
      case '\n': 
        result.append("\\n");
        break;
      case '\r': 
        result.append("\\r");
        break;
      case '\t': 
        result.append("\\t");
        break;
      default: 
        result.append(c);
      }
    }
    return result.toString();
  }
  
  private void write(String text)
  {
    try
    {
      StringBuilder line = new StringBuilder();
      for (int i = 0; i < indent; i++) {
        line.append("  ");
      }
      line.append(text);
      line.append(newLine);
      out.append(line);
    }
    catch (IOException e)
    {
      throw new JSilverIOException(e);
    }
  }
  
  public static void main(String[] args)
    throws IOException
  {
    if (args.length == 0)
    {
      System.err.println("Provide filename of template.");
      return;
    }
    String filename = args[0];
    Reader reader = new BufferedReader(new FileReader(filename));
    try
    {
      SyntaxTreeBuilder builder = new SyntaxTreeBuilder();
      TemplateSyntaxTree tree = builder.parse(reader, filename, EscapeMode.ESCAPE_NONE);
      tree.apply(new SyntaxTreeDumper(System.out));
    }
    finally
    {
      reader.close();
    }
  }
}

/* Location:
 * Qualified Name:     com.google.clearsilver.jsilver.syntax.SyntaxTreeDumper
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.google.clearsilver.jsilver.syntax;

import com.google.clearsilver.jsilver.syntax.analysis.DepthFirstAdapter;
import com.google.clearsilver.jsilver.syntax.node.AAltCommand;
import com.google.clearsilver.jsilver.syntax.node.ACallCommand;
import com.google.clearsilver.jsilver.syntax.node.ADataCommand;
import com.google.clearsilver.jsilver.syntax.node.ADefCommand;
import com.google.clearsilver.jsilver.syntax.node.AEachCommand;
import com.google.clearsilver.jsilver.syntax.node.AEvarCommand;
import com.google.clearsilver.jsilver.syntax.node.AHardIncludeCommand;
import com.google.clearsilver.jsilver.syntax.node.AHardLincludeCommand;
import com.google.clearsilver.jsilver.syntax.node.AIfCommand;
import com.google.clearsilver.jsilver.syntax.node.AIncludeCommand;
import com.google.clearsilver.jsilver.syntax.node.ALincludeCommand;
import com.google.clearsilver.jsilver.syntax.node.ALoopCommand;
import com.google.clearsilver.jsilver.syntax.node.ALoopIncCommand;
import com.google.clearsilver.jsilver.syntax.node.ALoopToCommand;
import com.google.clearsilver.jsilver.syntax.node.ALvarCommand;
import com.google.clearsilver.jsilver.syntax.node.ANameCommand;
import com.google.clearsilver.jsilver.syntax.node.AUvarCommand;
import com.google.clearsilver.jsilver.syntax.node.AVarCommand;
import com.google.clearsilver.jsilver.syntax.node.AWithCommand;
import com.google.clearsilver.jsilver.syntax.node.EOF;
import com.google.clearsilver.jsilver.syntax.node.PCommand;
import com.google.clearsilver.jsilver.syntax.node.TData;
import java.util.ArrayList;
import java.util.List;

public class DataCommandConsolidator
  extends DepthFirstAdapter
{
  private int currentBlockNestingLevel = 0;
  private final List<ADataCommand> datas = new ArrayList();
  private int datasBlockNestingLevel = -1;
  
  private void barrier()
  {
    if (datas.size() > 1)
    {
      ADataCommand last = (ADataCommand)datas.remove(datas.size() - 1);
      
      StringBuilder sb = new Stri
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