jsilver-1.0.0

ue = value;
  }
  
  public boolean asBoolean()
  {
    return value != 0;
  }
  
  public String asString()
  {
    return Integer.toString(value);
  }
  
  public int asNumber()
  {
    return value;
  }
  
  public boolean exists()
  {
    return true;
  }
  
  public boolean isEmpty()
  {
    return value == 0;
  }
}

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

import com.google.clearsilver.jsilver.autoescape.EscapeMode;
import com.google.clearsilver.jsilver.data.DataContext;
import java.util.HashMap;
import java.util.Map;

public abstract class Value
{
  private static final Map<EscapeMode, Value> EMPTY_PART_ESCAPED = new HashMap(2);
  private static final Map<EscapeMode, Value> EMPTY_UNESCAPED;
  private static final Map<EscapeMode, Value> ZERO_PART_ESCAPED;
  private static final Map<EscapeMode, Value> ZERO_UNESCAPED;
  private static final Map<EscapeMode, Value> ONE_PART_ESCAPED;
  private static final Map<EscapeMode, Value> ONE_UNESCAPED;
  private final boolean partiallyEscaped;
  private final EscapeMode escapeMode;
  
  static
  {
    EMPTY_PART_ESCAPED.put(EscapeMode.ESCAPE_NONE, new StringValue("", EscapeMode.ESCAPE_NONE, true));
    
    EMPTY_PART_ESCAPED.put(EscapeMode.ESCAPE_IS_CONSTANT, new StringValue("", EscapeMode.ESCAPE_IS_CONSTANT, true));
    
    EMPTY_UNESCAPED = new HashMap(2);
    EMPTY_UNESCAPED.put(EscapeMode.ESCAPE_NONE, new StringValue("", EscapeMode.ESCAPE_NONE, false));
    EMPTY_UNESCAPED.put(EscapeMode.ESCAPE_IS_CONSTANT, new StringValue("", EscapeMode.ESCAPE_IS_CONSTANT, false));
    
    ZERO_PART_ESCAPED = new HashMap(2);
    ZERO_PART_ESCAPED.put(EscapeMode.ESCAPE_NONE, new NumberValue(0, EscapeMode.ESCAPE_NONE, true));
    ZERO_PART_ESCAPED.put(EscapeMode.ESCAPE_IS_CONSTANT, new NumberValue(0, EscapeMode.ESCAPE_IS_CONSTANT, true));
    
    ZERO_UNESCAPED = new HashMap(2);
    ZERO_UNESCAPED.put(EscapeMode.ESCAPE_NONE, new NumberValue(0, EscapeMode.ESCAPE_NONE, false));
    ZERO_UNESCAPED.put(EscapeMode.ESCAPE_IS_CONSTANT, new NumberValue(0, EscapeMode.ESCAPE_IS_CONSTANT, false));
    
    ONE_PART_ESCAPED = new HashMap(2);
    ONE_PART_ESCAPED.put(EscapeMode.ESCAPE_NONE, new NumberValue(1, EscapeMode.ESCAPE_NONE, true));
    ONE_PART_ESCAPED.put(EscapeMode.ESCAPE_IS_CONSTANT, new NumberValue(1, EscapeMode.ESCAPE_IS_CONSTANT, true));
    
    ONE_UNESCAPED = new HashMap(2);
    ONE_UNESCAPED.put(EscapeMode.ESCAPE_NONE, new NumberValue(1, EscapeMode.ESCAPE_NONE, false));
    ONE_UNESCAPED.put(EscapeMode.ESCAPE_IS_CONSTANT, new NumberValue(1, EscapeMode.ESCAPE_IS_CONSTANT, false));
  }
  
  public Value(EscapeMode escapeMode, boolean partiallyEscaped)
  {
    this.escapeMode = escapeMode;
    this.partiallyEscaped = partiallyEscaped;
  }
  
  public static Value literalValue(int value, EscapeMode mode, boolean partiallyEscaped)
  {
    return getIntValue(mode, partiallyEscaped, value);
  }
  
  public static Value literalValue(String value, EscapeMode mode, boolean partiallyEscaped)
  {
    if (value.isEmpty())
    {
      Value v = (Value)(partiallyEscaped ? EMPTY_PART_ESCAPED : EMPTY_UNESCAPED).get(mode);
      if (v != null) {
        return v;
      }
    }
    return new StringValue(value, mode, partiallyEscaped);
  }
  
  public static Value literalValue(boolean value, EscapeMode mode, boolean partiallyEscaped)
  {
    return getIntValue(mode, partiallyEscaped, value ? 1 : 0);
  }
  
  private static Value getIntValue(EscapeMode mode, boolean partiallyEscaped, int num)
  {
    Value v = null;
    if (num == 0) {
      v = (Value)(partiallyEscaped ? ZERO_PART_ESCAPED : ZERO_UNESCAPED).get(mode);
    } else if (num == 1) {
      v = (Value)(partiallyEscaped ? ONE_PART_ESCAPED : ONE_UNESCAPED).get(mode);
    }
    if (v != null) {
      return v;
    }
    return new NumberValue(num, mode, partiallyEscaped);
  }
  
  public static Value literalConstant(int value, Value... inputs)
  {
    boolean isPartiallyEscaped = false;
    for (Value input : inputs) {
      if (input.isPartiallyEscaped())
      {
        isPartiallyEscaped = true;
        break;
      }
    }
    return literalValue(value, EscapeMode.ESCAPE_IS_CONSTANT, isPartiallyEscaped);
  }
  
  public static Value literalConstant(String value, Value... inputs)
  {
    boolean isPartiallyEscaped = false;
    for (Value input : inputs) {
      if (input.isPartiallyEscaped())
      {
        isPartiallyEscaped = true;
        break;
      }
    }
    return literalValue(value, EscapeMode.ESCAPE_IS_CONSTANT, isPartiallyEscaped);
  }
  
  public static Value literalConstant(boolean value, Value... inputs)
  {
    boolean isPartiallyEscaped = false;
    for (Value input : inputs) {
      if (input.isPartiallyEscaped())
      {
        isPartiallyEscaped = true;
        break;
      }
    }
    return literalValue(value, EscapeMode.ESCAPE_IS_CONSTANT, isPartiallyEscaped);
  }
  
  public static Value variableValue(String name, DataContext dataContext)
  {
    return new VariableValue(name, dataContext);
  }
  
  public boolean equals(Object other)
  {
    if ((other == null) || (!(other instanceof Value))) {
      return false;
    }
    Value otherValue = (Value)other;
    
    return (exists() == otherValue.exists()) && ((asString().equals(otherValue.asString())) || ((isEmpty()) && (otherValue.isEmpty())));
  }
  
  public int hashCode()
  {
    return toString().hashCode();
  }
  
  public String toString()
  {
    return asString();
  }
  
  public boolean isPartiallyEscaped()
  {
    return partiallyEscaped;
  }
  
  public EscapeMode getEscapeMode()
  {
    return escapeMode;
  }
  
  public abstract boolean asBoolean();
  
  public abstract String asString();
  
  public abstract int asNumber();
  
  public abstract boolean exists();
  
  public abstract boolean isEmpty();
}

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

import com.google.clearsilver.jsilver.autoescape.EscapeMode;
import com.google.clearsilver.jsilver.data.TypeConverter;

abstract class VariantValue
  extends Value
{
  private static final String EMPTY = "";
  
  VariantValue(EscapeMode escapeMode, boolean partiallyEscaped)
  {
    super(escapeMode, partiallyEscaped);
  }
  
  protected abstract String value();
  
  public boolean asBoolean()
  {
    return TypeConverter.asBoolean(value());
  }
  
  public String asString()
  {
    String value = value();
    return value == null ? "" : value;
  }
  
  public int asNumber()
  {
    return TypeConverter.asNumber(value());
  }
  
  public boolean isEmpty()
  {
    return asString().isEmpty();
  }
}

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

import com.google.clearsilver.jsilver.autoescape.EscapeMode;

class StringValue
  extends VariantValue
{
  private final String value;
  
  public StringValue(String value, EscapeMode escapeMode, boolean partiallyEscaped)
  {
    super(escapeMode, partiallyEscaped);
    this.value = value;
  }
  
  protected String value()
  {
    return value;
  }
  
  public boolean exists()
  {
    return true;
  }
  
  public boolean isEmpty()
  {
    return value.length() == 0;
  }
}

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

import com.google.clearsilver.jsilver.autoescape.EscapeMode;
import com.google.clearsilver.jsilver.data.Data;
import com.google.clearsilver.jsilver.data.DataContext;
import com.google.clearsilver.jsilver.data.TypeConverter;

public class VariableValue
  extends VariantValue
{
  private final String name;
  private final DataContext dataContext;
  private boolean gotRef = false;
  private Data reference;
  
  public VariableValue(String name, DataContext dataContext)
  {
    super(EscapeMode.ESCAPE_NONE, false);
    this.dataContext = dataContext;
    this.name = name;
  }
  
  public String getName()
  {
    return name;
  }
  
  public Data getReference()
  {
    if (!gotRef)
    {
      reference = dataContext.findVariable(name, false);
      gotRef = true;
    }
    return reference;
  }
  
  protected String value()
  {
    Data data = getReference();
    return data == null ? null : data.getValue();
  }
  
  public boolean exists()
  {
    return TypeConverter.exists(getReference());
  }
  
  public String toString()
  {
    return name;
  }
  
  public EscapeMode getEscapeMode()
  {
    Data data = getReference();
    if (data == null) {
      return super.getEscapeMode();
    }
    return data.getEscapeMode();
  }
}

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

public enum AutoEscapeContext$AutoEscapeState
{
  HTML("html", EscapeMode.ESCAPE_AUTO_HTML),  JS("js", EscapeMode.ESCAPE_AUTO_JS),  STYLE("css", EscapeMode.ESCAPE_AUTO_STYLE),  JS_UNQUOTED("js_check_number", EscapeMode.ESCAPE_AUTO_JS_UNQUOTED),  ATTR("html", EscapeMode.ESCAPE_AUTO_ATTR),  UNQUOTED_ATTR("html_unquoted", EscapeMode.ESCAPE_AUTO_UNQUOTED_ATTR),  ATTR_URI("html", EscapeMode.ESCAPE_AUTO_ATTR_URI),  UNQUOTED_ATTR_URI("html_unquoted", EscapeMode.ESCAPE_AUTO_UNQUOTED_ATTR_URI),  ATTR_URI_START("url_validate", EscapeMode.ESCAPE_AUTO_ATTR_URI_START),  UNQUOTED_ATTR_URI_START("url_validate_unquoted", EscapeMode.ESCAPE_AUTO_UNQUOTED_ATTR_URI_START),  ATTR_JS("js", EscapeMode.ESCAPE_AUTO_ATTR_JS),  ATTR_UNQUOTED_JS("js_check_number", EscapeMode.ESCAPE_AUTO_ATTR_UNQUOTED_JS),  UNQUOTED_ATTR_JS("js_attr_unquoted", EscapeMode.ESCAPE_AUTO_UNQUOTED_ATTR_JS),  UNQUOTED_ATTR_UNQUOTED_JS("js_check_number", EscapeMode.ESCAPE_AUTO_UNQUOTED_ATTR_UNQUOTED_JS),  ATTR_CSS("css", EscapeMode.ESCAPE_AUTO_ATTR_CSS),  UNQUOTED_ATTR_CSS("css_unquoted", EscapeMode.ESCAPE_AUTO_UNQUOTED_ATTR_CSS);
  
  private final String functionName;
  private final EscapeMode escapeMode;
  
  private AutoEscapeContext$AutoEscapeState(String functionName, EscapeMode mode)
  {
    this.functionName = functionName;
    escapeMode = mode;
  }
  
  public String getFunctionName()
  {
    return functionName;
  }
  
  public EscapeMode getEscapeMode()
  {
    return escapeMode;
  }
}

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

public class AutoEscapeOptions
{
  private boolean propagateEscapeStatus = false;
  private boolean logEscapedVariables = false;
  
  public boolean getLogEscapedVariables()
  {
    return logEscapedVariables;
  }
  
  public void setLogEscapedVariables(boolean logEscapedVariables)
  {
    this.logEscapedVariables = logEscapedVariables;
  }
  
  public boolean getPropagateEscapeStatus()
  {
    return propagateEscapeStatus;
  }
  
  public void setPropagateEscapeStatus(boolean propagateEscapeStatus)
  {
    this.propagateEscapeStatus = propagateEscapeStatus;
  }
}

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

import com.google.clearsilver.jsilver.exceptions.JSilverAutoEscapingException;

public enum EscapeMode
{
  ESCAPE_NONE("none", false),  ESCAPE_HTML("html", false),  ESCAPE_JS("js", false),  ESCAPE_URL("url", false),  ESCAPE_IS_CONSTANT("constant", false),  ESCAPE_AUTO("auto", true),  ESCAPE_AUTO_HTML("auto_html", true),  ESCAPE_AUTO_JS("auto_js", true),  ESCAPE_AUTO_JS_UNQUOTED("auto_js_unquoted", true),  ESCAPE_AUTO_STYLE("auto_style", true),  ESCAPE_AUTO_ATTR("auto_attr", true),  ESCAPE_AUTO_UNQUOTED_ATTR("auto_attr_unquoted", true),  ESCAPE_AUTO_ATTR_URI("auto_attr_uri", true),  ESCAPE_AUTO_UNQUOTED_ATTR_URI("auto_attr_uri_unquoted", true),  ESCAPE_AUTO_ATTR_URI_START("auto_attr_uri_start", true),  ESCAPE_AUTO_UNQUOTED_ATTR_URI_START("auto_attr_uri_start_unquoted", true),  ESCAPE_AUTO_ATTR_JS("auto_attr_js", true),  ESCAPE_AUTO_ATTR_UNQUOTED_JS("auto_attr_unquoted_js", true),  ESCAPE_AUTO_UNQUOTED_ATTR_JS("auto_attr_js_unquoted", true),  ESCAPE_AUTO_UNQUOTED_ATTR_UNQUOTED_JS("auto_attr_js_unquoted_js", true),  ESCAPE_AUTO_ATTR_CSS("auto_attr_style", true),  ESCAPE_AUTO_UNQUOTED_ATTR_CSS("auto_attr_style_unquoted", true);
  
  private String escapeCmd;
  private boolean autoEscaper;
  
  private EscapeMode(String escapeCmd, boolean autoEscaper)
  {
    this.escapeCmd = escapeCmd;
    this.autoEscaper = autoEscaper;
  }
  
  public static EscapeMode computeEscapeMode(String escapeCmd, boolean doAutoEscape)
  {
    if (escapeCmd != null)
    {
      for (EscapeMode e : values()) {
        if (escapeCmd.equals(escapeCmd)) {
          return e;
        }
      }
      throw new JSilverAutoEscapingException("Invalid escaping mode specified: " + escapeCmd);
    }
    EscapeMode escapeMode;
    EscapeMode escapeMode;
    if (doAutoEscape) {
      escapeMode = ESCAPE_AUTO;
    } else {
      escapeMode = ESCAPE_NONE;
    }
    return escapeMode;
  }
  
  public static EscapeMode computeEscapeMode(String escapeCmd)
  {
    return computeEscapeMode(escapeCmd, false);
  }
  
  public static EscapeMode combineModes(EscapeMode left, EscapeMode right)
  {
    if ((left.equals(ESCAPE_NONE)) || (right.equals(ESCAPE_NONE))) {
      return ESCAPE_NONE;
    }
    return ESCAPE_IS_CONSTANT;
  }
  
  public boolean isAutoEscapingMode()
  {
    return autoEscaper;
  }
  
  public String getEscapeCommand()
  {
    return escapeCmd;
  }
}

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

import com.google.clearsilver.jsilver.exceptions.JSilverAutoEscapingException;
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.HtmlParserFactory;
import com.google.streamhtmlparser.HtmlParserFactory.AttributeOptions;
import com.google.streamhtmlparser.HtmlParserFactory.ModeOptions;
import com.google.streamhtmlparser.ParseException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;

public class AutoEscapeContext
{
  public static final Map<String, HtmlParser.Mode> CONTENT_TYPE_LIST;
  private static final HashSet<HtmlParserFactory.AttributeOptions> quotedJsAttributeOption = new HashSet();
  private static final HashSet<HtmlParserFactory.AttributeOptions> partialUrlAttributeOption;
  private static final HashSet<HtmlParserFactory.ModeOptions> jsModeOption;
  private HtmlParser htmlParser;
  private String resourceName;
  
  static
  {
    quotedJsAttributeOption.add(HtmlParserFactory.AttributeOptions.JS_QUOTED);
    
    partialUrlAttributeOption = new HashSet();
    partialUrlAttributeOption.add(HtmlParserFactory.AttributeOptions.URL_PARTIAL);
    
    jsModeOption = new HashSet();
    jsModeOption.add(HtmlParserFactory.ModeOptions.JS_QUOTED);
    
    CONTENT_TYPE_LIST = new HashMap();
    CONTENT_TYPE_LIST.put("text/html", HtmlParser.Mode.HTML);
    CONTENT_TYPE_LIST.put("text/plain", HtmlParser.Mode.HTML);
    CONTENT_TYPE_LIST.put("application/javascript", HtmlParser.Mode.JS);
    CONTENT_TYPE_LIST.put("application/json", HtmlParser.Mode.JS);
    CONTENT_TYPE_LIST.put("text/javascript", HtmlParser.Mode.JS);
    CONTENT_TYPE_LIST.put("text/css", HtmlParser.Mode.CSS);
  }
  
  public AutoEscapeContext()
  {
    this(EscapeMode.ESCAPE_AUTO, null);
  }
  
  public AutoEscapeContext(EscapeMode mode)
  {
    this(mode, null);
  }
  
  public AutoEscapeContext(EscapeMode mode, String resourceName)
  {
    this.resourceName = resourceName;
    htmlParser = createHtmlParser(mode);
  }
  
  public AutoEscapeContext cloneCurrentEscapeContext()
  {
    AutoEscapeContext autoEscapeContext = new AutoEscapeContext();
    resourceName = resourceName;
    htmlParser = HtmlParserFactory.createParser(htmlParser);
    return autoEscapeContext;
  }
  
  public void setCurrentPosition(int line, int column)
  {
    htmlParser.setLineNumber(line);
    htmlParser.setColumnNumber(column);
  }
  
  public String getResourceName()
  {
    return resourceName;
  }
  
  public int getLineNumber()
  {
    return htmlParser.getLineNumber();
  }
  
  public int getColumnNumber()
  {
    return htmlParser.getColumnNumber();
  }
  
  private HtmlParser createHtmlParser(EscapeMode mode)
  {
    switch (mode)
    {
    case ESCAPE_AUTO: 
    case ESCAPE_AUTO_HTML: 
      return HtmlParserFactory.createParser();
    case ESCAPE_AUTO_JS_UNQUOTED: 
      return HtmlParserFactory.createParserInMode(HtmlParser.Mode.JS, null);
    case ESCAPE_AUTO_JS: 
      return HtmlParserFactory.createParserInMode(HtmlParser.Mode.JS, jsModeOption);
    case ESCAPE_AUTO_STYLE: 
      return HtmlParserFactory.createParserInMode(HtmlParser.Mode.CSS, null);
    case ESCAPE_AUTO_ATTR: 
      return HtmlParserFactory.createParserInAttribute(HtmlParser.ATTR_TYPE.REGULAR, true, null);
    case ESCAPE_AUTO_UNQUOTED_ATTR: 
      return HtmlParserFactory.createParserInAttribute(HtmlParser.ATTR_TYPE.REGULAR, false, null);
    case ESCAPE_AUTO_ATTR_URI: 
      return HtmlParserFactory.createParserInAttribute(HtmlParser.ATTR_TYPE.URI, true, partialUrlAttributeOption);
    case ESCAPE_AUTO_UNQUOTED_ATTR_URI: 
      return HtmlParserFactory.createParserInAttribute(HtmlParser.ATTR_TYPE.URI, false, partialUrlAttributeOption);
    case ESCAPE_AUTO_ATTR_URI_START: 
      return HtmlParserFactory.createParserInAttribute(HtmlParser.ATTR_TYPE.URI, true, null);
    case ESCAPE_AUTO_UNQUOTED_ATTR_URI_START: 
      return HtmlParserFactory.createParserInAttribute(HtmlParser.ATTR_TYPE.URI, false, null);
    case ESCAPE_AUTO_ATTR_JS: 
      return HtmlParserFactory.createParserInAttribute(HtmlParser.ATTR_TYPE.JS, true, quotedJsAttributeOption);
    case ESCAPE_AUTO_ATTR_UNQUOTED_JS: 
      return HtmlParserFactory.createParserInAttribute(HtmlParser.ATTR_TYPE.JS, true, null);
    case ESCAPE_AUTO_UNQUOTED_ATTR_JS: 
      throw new JSilverAutoEscapingException("Attempting to start HTML parser in unsupported mode" + mode, resourceName);
    case ESCAPE_AUTO_UNQUOTED_ATTR_UNQUOTED_JS: 
      return HtmlParserFactory.createParserInAttribute(HtmlParser.ATTR_TYPE.JS, false, null);
    case ESCAPE_AUTO_ATTR_CSS: 
      return HtmlParserFactory.createParserInAttribute(HtmlParser.ATTR_TYPE.STYLE, true, null);
    case ESCAPE_AUTO_UNQUOTED_ATTR_CSS: 
      return HtmlParserFactory.createParserInAttribute(HtmlParser.ATTR_TYPE.STYLE, false, null);
    }
    throw new JSilverAutoEscapingException("Attempting to start HTML parser in invalid mode" + mode, resourceName);
  }
  
  public void parseData(String data)
  {
    try
    {
      htmlParser.parse(data);
    }
    catch (ParseException e)
    {
      throw new JSilverAutoEscapingException("Error in HtmlParser: " + e, resourceName);
    }
  }
  
  public void insertText()
  {
    try
    {
      htmlParser.insertText();
    }
    catch (ParseException e)
    {
      throw new JSilverAutoEscapingException("Error during insertText(): " + e, resourceName, htmlParser.getLineNumber(), htmlParser.getColumnNumber());
    }
  }
  
  public boolean isPermittedStateChangeForIncludes(AutoEscapeState start, AutoEscapeState end)
  {
    return (start.equals(end)) || ((start.equals(AutoEscapeState.ATTR_URI_START)) && (end.equals(AutoEscapeState.ATTR_URI))) || ((start.equals(AutoEscapeState.UNQUOTED_ATTR_URI_START)) && (end.equals(AutoEscapeState.UNQUOTED_ATTR_URI)));
  }
  
  public String getEscapingFunctionForCurrentState()
  {
    return getCurrentState().getFunctionName();
  }
  
  public EscapeMode getEscapeModeForCurrentState()
  {
    return getCurrentState().getEscapeMode();
  }
  
  public AutoEscapeState getCurrentState()
  {
    ExternalState state = htmlParser.getState();
    String tag = htmlParser.getTag();
    if ((state.equals(HtmlParser.STATE_CSS_FILE)) || (tag.equals("style"))) {
      return AutoEscapeState.STYLE;
    }
    if ((htmlParser.inJavascript()) && (!state.equals(HtmlParser.STATE_VALUE)))
    {
      if (htmlParser.isJavascriptQuoted()) {
        return AutoEscapeState.JS;
      }
      return AutoEscapeState.JS_UNQUOTED;
    }
    if ((state.equals(HtmlParser.STATE_ATTR)) || (state.equals(HtmlParser.STATE_TAG))) {
      return AutoEscapeState.ATTR;
    }
    if (state.equals(HtmlParser.STATE_VALUE)) {
      return getCurrentAttributeState();
    }
    if ((state.equals(HtmlParser.STATE_COMMENT)) || (state.equals(HtmlParser.STATE_TEXT))) {
      return AutoEscapeState.HTML;
    }
    throw new JSilverAutoEscapingException("Invalid state received from HtmlParser: " + state.toString(), resourceName, htmlParser.getLineNumber(), htmlParser.getColumnNumber());
  }
  
  private AutoEscapeState getCurrentAttributeState()
  {
    HtmlParser.ATTR_TYPE type = htmlParser.getAttributeType();
    boolean attrQuoted = htmlParser.isAttributeQuoted();
    switch (type)
    {
    case REGULAR: 
      if (attrQuoted) {
        return AutoEscapeState.ATTR;
      }
      return AutoEscapeState.UNQUOTED_ATTR;
    case URI: 
      if (htmlParser.isUrlStart())
      {
        if (attrQuoted) {
          return AutoEscapeState.ATTR_URI_START;
        }
        return AutoEscapeState.UNQUOTED_ATTR_URI_START;
      }
      if (attrQuoted) {
        return AutoEscapeState.ATTR_URI;
      }
      return AutoEscapeState.UNQUOTED_ATTR_URI;
    case JS: 
      if (htmlParser.isJavascriptQuoted())
      {
        if (attrQuoted) {
          return AutoEscapeState.ATTR_JS;
        }
        return AutoEscapeState.UNQUOTED_ATTR_JS;
      }
      if (attrQuoted) {
        return AutoEscapeState.ATTR_UNQUOTED_JS;
      }
      return AutoEscapeState.UNQUOTED_ATTR_UNQUOTED_JS;
    case STYLE: 
      if (attrQuoted) {
        return AutoEscapeState.ATTR_CSS;
      }
      return AutoEscapeState.UNQUOTED_ATTR_CSS;
    }
    throw new JSilverAutoEscapingException("Invalid attribute type in HtmlParser: " + type, resourceName, htmlParser.getLineNumber(), htmlParser.getColumnNumber());
  }
  
  public void setContentType(String contentType)
  {
    HtmlParser.Mode mode = (HtmlParser.Mode)CONTENT_TYPE_LIST.get(contentType);
    if (mode == null) {
      throw new JSilverAutoEscapingException("Invalid content type specified: " + contentType, resourceName, htmlParser.getLineNumber(), htmlParser.getColumnNumber());
    }
    htmlParser.resetMode(mode);
  }
  
  public static enum AutoEscapeState
  {
    HTML("html", EscapeMode.ESCAPE_AUTO_HTML),  JS("js", EscapeMode.ESCAPE_AUTO_JS),  STYLE("css", EscapeMode.ESCAPE_AUTO_STYLE),  JS_UNQUOTED("js_check_number", EscapeMode.ESCAPE_AUTO_JS_UNQUOTED),  ATTR("html", EscapeMode.ESCAPE_AUTO_ATTR),  UNQUOTED_ATTR("html_unquoted", EscapeMode.ESCAPE_AUTO_UNQUOTED_ATTR),  ATTR_URI("html", EscapeMode.ESCAPE_AUTO_ATTR_URI),  UNQUOTED_ATTR_URI("html_unquoted", EscapeMode.ESCAPE_AUTO_UNQUOTED_ATTR_URI),  ATTR_URI_START("url_validate", EscapeMode.ESCAPE_AUTO_ATTR_URI_START),  UNQUOTED_ATTR_URI_START("url_validate_unquoted", EscapeMode.ESCAPE_AUTO_UNQUOTED_ATTR_URI_START),  ATTR_JS("js", EscapeMode.ESCAPE_AUTO_ATTR_JS),  ATTR_UNQUOTED_JS("js_check_number", EscapeMode.ESCAPE_AUTO_ATTR_UNQUOTED_JS),  UNQUOTED_ATTR_JS("js_attr_unquoted", EscapeMode.ESCAPE_AUTO_UNQUOTED_ATTR_JS),  UNQUOTED_ATTR_UNQUOTED_JS("js_check_number", EscapeMode.ESCAPE_AUTO_UNQUOTED_ATTR_UNQUOTED_JS),  ATTR_CSS("css", EscapeMode.ESCAPE_AUTO_ATTR_CSS),  UNQUOTED_ATTR_CSS("css_unquoted", EscapeMode.ESCAPE_AUTO_UNQUOTED_ATTR_CSS);
    
    private final String functionName;
    private final EscapeMode escapeMode;
    
    private AutoEscapeState(String functionName, EscapeMode mode)
    {
      this.functionName = functionName;
      escapeMode = mode;
    }
    
    public String getFunctionName()
    {
      return functionName;
    }
    
    public EscapeMode getEscapeMode()
    {
      return escapeMode;
    }
  }
}

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

class AutoEscapeContext$1 {}

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

public abstract interface DelegatingTemplateLoader
  extends TemplateLoader
{
  public abstract void setTemplateLoaderDelegate(TemplateLoader paramTemplateLoader);
}

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

import com.google.clearsilver.jsilver.autoescape.AutoEscapeOptions;
import com.google.clearsilver.jsilver.autoescape.EscapeMode;
import com.google.clearsilver.jsilver.data.DataContext;
import com.google.clearsilver.jsilver.exceptions.JSilverInterpreterException;
import com.google.clearsilver.jsilver.resourceloader.ResourceLoader;
import com.google.clearsilver.jsilver.values.Value;

public abstract interface RenderingContext
{
  public abstract Value executeFunction(String paramString, Value... paramVarArgs)
    throws JSilverInterpreterException;
  
  public abstract boolean isEscapingFunction(String paramString);
  
  public abstract void writeEscaped(String paramString);
  
  public abstract void writeUnescaped(CharSequence paramCharSequence);
  
  public abstract void pushEscapingFunction(String paramString);
  
  public abstract void popEscapingFunction();
  
  public abstract void pushExecutionContext(Template paramTemplate);
  
  public abstract void popExecutionContext();
  
  public abstract void setCurrentPosition(int paramInt1, int paramInt2);
  
  public abstract void registerMacro(String paramString, Macro paramMacro);
  
  public abstract Macro findMacro(String paramString)
    throws JSilverInterpreterException;
  
  public abstract DataContext getDataContext();
  
  public abstract ResourceLoader getResourceLoader();
  
  public abstract AutoEscapeOptions getAutoEscapeOptions();
  
  public abstract void pushAutoEscapeMode(EscapeMode paramEscapeMode);
  
  public abstract void popAutoEscapeMode();
  
  public abstract EscapeMode getAutoEscapeMode();
  
  public abstract boolean isRuntimeAutoEscaping();
  
  public abstract void startRuntimeAutoEscaping();
  
  public abstract void stopRuntimeAutoEscaping();
  
  public abstract boolean pushIncludeStackEntry(String paramString);
  
  public abstract boolean popIncludeStackEntry(String paramString);
  
  public abstract Iterable<String> getIncludedTemplateNames();
}

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

import com.google.clearsilver.jsilver.autoescape.AutoEscapeContext;
import com.google.clearsilver.jsilver.autoescape.AutoEscapeContext.AutoEscapeState;
import com.google.clearsilver.jsilver.autoescape.AutoEscapeOptions;
import com.google.clearsilver.jsilver.autoescape.EscapeMode;
import com.google.clearsilver.jsilver.data.DataContext;
import com.google.clearsilver.jsilver.data.UniqueStack;
import com.google.clearsilver.jsilver.exceptions.JSilverAutoEscapingException;
import com.google.clearsilver.jsilver.exceptions.JSilverIOException;
import com.google.clearsilver.jsilver.exceptions.JSilverInterpreterException;
import com.google.clearsilver.jsilver.functions.FunctionExecutor;
import com.google.clearsilver.jsilver.resourceloader.ResourceLoader;
import com.google.clearsilver.jsilver.values.Value;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;

public class DefaultRenderingContext
  implements RenderingContext, FunctionExecutor
{
  public static final Logger logger = Logger.getLogger(DefaultRenderingContext.class.getName());
  private final DataContext dataContext;
  private final ResourceLoader resourceLoader;
  private final Appendable out;
  private final FunctionExecutor globalFunctionExecutor;
  private final AutoEscapeOptions autoEscapeOptions;
  private final UniqueStack<String> includeStack;
  private List<String> escaperStack = new ArrayList(8);
  private String currentEscaper;
  private List<Template> executionStack = new ArrayList(8);
  private Map<String, Macro> macros = new HashMap();
  private List<EscapeMode> autoEscapeStack = new ArrayList();
  private EscapeMode autoEscapeMode;
  private AutoEscapeContext autoEscapeContext;
  private int line;
  private int column;
  private AutoEscapeContext.AutoEscapeState startingAutoEscapeState;
  
  public DefaultRenderingContext(DataContext dataContext, ResourceLoader resourceLoader, Appendable out, FunctionExecutor globalFunctionExecutor, AutoEscapeOptions autoEscapeOptions)
  {
    this.dataContext = dataContext;
    this.resourceLoader = resourceLoader;
    this.out = out;
    this.globalFunctionExecutor = globalFunctionExecutor;
    this.autoEscapeOptions = autoEscapeOptions;
    autoEscapeMode = EscapeMode.ESCAPE_NONE;
    autoEscapeContext = null;
    includeStack = new UniqueStack();
  }
  
  public Value executeFunction(String name, Value... args)
  {
    return globalFunctionExecutor.executeFunction(name, args);
  }
  
  public void escape(String name, String input, Appendable output)
    throws IOException
  {
    globalFunctionExecutor.escape(name, input, output);
  }
  
  public boolean isEscapingFunction(String name)
  {
    return globalFunctionExecutor.isEscapingFunction(name);
  }
  
  public void pushEscapingFunction(String name)
  {
    escaperStack.add(currentEscaper);
    if ((name == null) || (name.equals(""))) {
      currentEscaper = null;
    } else {
      currentEscaper = name;
    }
  }
  
  public void popEscapingFunction()
  {
    int len = escaperStack.size();
    if (len == 0) {
      throw new IllegalStateException("No more escaping functions to pop.");
    }
    currentEscaper = ((String)escaperStack.remove(len - 1));
  }
  
  public void writeEscaped(String text)
  {
    boolean applyAutoEscape = (isRuntimeAutoEscaping()) && (currentEscaper == null);
    if (applyAutoEscape)
    {
      autoEscapeContext.setCurrentPosition(line, column);
      pushEscapingFunction(autoEscapeContext.getEscapingFunctionForCurrentState());
    }
    try
    {
      if (shouldLogEscapedVariables())
      {
        StringBuilder tmp = new StringBuilder();
        globalFunctionExecutor.escape(currentEscaper, text, tmp);
        if (!tmp.toString().equals(text)) {
          logger.warning(getLoggingPrefix() + " Auto-escape changed [" + text + "] to [" + tmp.toString() + "]");
        }
        out.append(tmp);
      }
      else
      {
        globalFunctionExecutor.escape(currentEscaper, text, out);
      }
    }
    catch (IOException e)
    {
      throw new JSilverIOException(e);
    }
    finally
    {
      if (applyAutoEscape)
      {
        autoEscapeContext.insertText();
        popEscapingFunction();
      }
    }
  }
  
  private String getLoggingPrefix()
  {
    return "[" + getCurrentResourceName() + ":" + line + ":" + column + "]";
  }
  
  private boolean shouldLogEscapedVariables()
  {
    return (autoEscapeOptions != null) && (autoEscapeOptions.getLogEscapedVariables());
  }
  
  public void writeUnescaped(CharSequence text)
  {
    if ((isRuntimeAutoEscaping()) && (currentEscaper == null))
    {
      autoEscapeContext.setCurrentPosition(line, column);
      autoEscapeContext.parseData(text.toString());
    }
    try
    {
      out.append(text);
    }
    catch (IOException e)
    {
      throw new JSilverIOException(e);
    }
  }
  
  public void pushExecutionContext(Template template)
  {
    executionStack.add(template);
  }
  
  public void popExecutionContext()
  {
    executionStack.remove(executionStack.size() - 1);
  }
  
  public void setCurrentPosition(int line, int column)
  {
    this.line = line;
    this.column = column;
  }
  
  public void registerMacro(String name, Macro macro)
  {
    macros.put(name, macro);
  }
  
  public Macro findMacro(String name)
  {
    Macro macro = (Macro)macros.get(name);
    if (macro == null) {
      throw new JSilverInterpreterException("No such macro: " + name);
    }
    return macro;
  }
  
  public DataContext getDataContext()
  {
    return dataContext;
  }
  
  public ResourceLoader getResourceLoader()
  {
    return resourceLoader;
  }
  
  public AutoEscapeOptions getAutoEscapeOptions()
  {
    return autoEscapeOptions;
  }
  
  public EscapeMode getAutoEscapeMode()
  {
    if ((isRuntimeAutoEscaping()) || (currentEscaper != null)) {
      return EscapeMode.ESCAPE_NONE;
    }
    return autoEscapeMode;
  }
  
  public void pushAutoEscapeMode(EscapeMode mode)
  {
    if (isRuntimeAutoEscaping()) {
      throw new JSilverInterpreterException("cannot call pushAutoEscapeMode while runtime auto escaping is in progress");
    }
    autoEscapeStack.add(autoEscapeMode);
    autoEscapeMode = mode;
  }
  
  public void popAutoEscapeMode()
  {
    int len = autoEscapeStack.size();
    if (len == 0) {
      throw new IllegalStateException("No more auto escaping modes to pop.");
    }
    autoEscapeMode = ((EscapeMode)autoEscapeStack.remove(autoEscapeStack.size() - 1));
  }
  
  public boolean isRuntimeAutoEscaping()
  {
    return autoEscapeContext != null;
  }
  
  public void startRuntimeAutoEscaping()
  {
    if (isRuntimeAutoEscaping()) {
      throw new JSilverInterpreterException("startRuntimeAutoEscaping() is not re-entrant at " + getCurrentResourceName());
    }
    if (!autoEscapeMode.equals(EscapeMode.ESCAPE_NONE))
    {
      autoEscapeContext = new AutoEscapeContext(autoEscapeMode, getCurrentResourceName());
      startingAutoEscapeState = autoEscapeContext.getCurrentState();
    }
    else
    {
      autoEscapeContext = null;
    }
  }
  
  private String getCurrentResourceName()
  {
    if (executionStack.size() == 0) {
      return "";
    }
    return ((Template)executionStack.get(executionStack.size() - 1)).getDisplayName();
  }
  
  public void stopRuntimeAutoEscaping()
  {
    if ((autoEscapeContext != null) && 
      (!startingAutoEscapeState.equals(autoEscapeContext.getCurrentState()))) {
      throw new JSilverAutoEscapingException("Macro starts in context " + startingAutoEscapeState + " but ends in different context " + autoEscapeContext.getCurrentState(), autoEscapeContext.getResourceName());
    }
    autoEscapeContext = null;
  }
  
  public boolean pushIncludeStackEntry(String templateName)
  {
    return includeStack.push(templateName);
  }
  
  public boolean popIncludeStackEntry(String templateName)
  {
    return templateName.equals(includeStack.pop());
  }
  
  public Iterable<String> getIncludedTemplateNames()
  {
    return includeStack;
  }
}

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

import com.google.clearsilver.jsilver.autoescape.EscapeMode;
import com.google.clearsilver.jsilver.resourceloader.ResourceLoader;

public abstract interface TemplateLoader
{
  public abstract Template load(String paramString, ResourceLoader paramResourceLoader, EscapeMode paramEscapeMode);
  
  public abstract Template createTemp(String paramString1, String paramString2, EscapeMode paramEscapeMode);
}

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

import java.io.IOException;

public class HtmlWhiteSpaceStripper
  implements Appendable
{
  private final Appendable out;
  private final int level;
  private boolean nonWsSeen = false;
  private char pendingWs = '\000';
  private boolean startHtmlTag = false;
  private boolean inOpenTag = false;
  private boolean inCloseTag = false;
  private boolean inTagName = false;
  private int textAreaScope = 0;
  private int preScope = 0;
  private int verbatimScope = 0;
  private int scriptScope = 0;
  private StringBuilder tagName = new StringBuilder(16);
  
  public HtmlWhiteSpaceStripper(Appendable out)
  {
    this(out, 1);
  }
  
  public HtmlWhiteSpaceStripper(Appendable out, int level)
  {
    this.out = out;
    this.level = level;
  }
  
  public String toString()
  {
    return out.toString();
  }
  
  public Appendable append(CharSequence csq)
    throws IOException
  {
    return append(csq, 0, csq.length());
  }
  
  public Appendable append(CharSequence csq, int start, int end)
    throws IOException
  {
    for (int i = start; i < end; i++) {
      append(csq.charAt(i));
    }
    return this;
  }
  
  public Appendable append(char c)
    throws IOException
  {
    if ((inOpenTag) || (inCloseTag))
    {
      if (startHtmlTag)
      {
        if (c == '/')
        {
          inOpenTag = false;
          inCloseTag = true;
        }
        else
        {
          startHtmlTag = false;
          if (isTagNameStartChar(c))
          {
            inTagName = true;
            tagName.append(c);
          }
        }
      }
      else if (inTagName) {
        if (isTagNameChar(c))
        {
          tagName.append(c);
        }
        else
        {
          processTagName();
          inTagName = false;
        }
      }
      if (c == '>')
      {
        inOpenTag = (inCloseTag = 0);
        nonWsSeen = true;
      }
      stripLeadingWsAndEmptyLines(c);
    }
    else
    {
      if (c == '<')
      {
        inOpenTag = true;
        startHtmlTag = true;
      }
      if ((preScope > 0) || (verbatimScope > 0) || (textAreaScope > 0)) {
        out.append(c);
      } else if (scriptScope > 0) {
        stripLeadingWsAndEmptyLines(c);
      } else {
        stripAll(c);
      }
    }
    return this;
  }
  
  private void stripLeadingWsAndEmptyLines(char c)
    throws IOException
  {
    switch (c)
    {
    case '\n': 
      if (nonWsSeen) {
        out.append(c);
      }
      nonWsSeen = false;
      break;
    case '\t': 
    case '\r': 
    case ' ': 
      if (nonWsSeen) {
        out.append(c);
      }
      break;
    default: 
      if (!nonWsSeen) {
        nonWsSeen = true;
      }
      out.append(c);
    }
  }
  
  private void stripAll(char c)
    throws IOException
  {
    switch (c)
    {
    case '\n': 
      if (nonWsSeen) {
        out.append(c);
      }
      pendingWs = '\000';
      nonWsSeen = false;
      break;
    case '\t': 
    case '\r': 
    case ' ': 
      if (nonWsSeen) {
        pendingWs = c;
      }
      break;
    default: 
      if (pendingWs != 0)
      {
        out.append(pendingWs);
        pendingWs = '\000';
      }
      nonWsSeen = true;
      out.append(c);
    }
  }
  
  private int updateScope(int current, int inc)
  {
    current += inc;
    return current < 0 ? 0 : current;
  }
  
  private void processTagName()
  {
    inTagName = false;
    String name = tagName.toString();
    tagName.delete(0, tagName.length());
    int inc = inOpenTag ? 1 : -1;
    if ("textarea".e
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