|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.google.clearsilver.jsilver.autoescape.AutoEscapeContext
public class AutoEscapeContext
Encapsulates auto escaping logic.
Nested Class Summary | |
---|---|
static class |
AutoEscapeContext.AutoEscapeState
Enum representing states of the data being parsed. |
Field Summary | |
---|---|
static Map<String,HtmlParser.Mode> |
CONTENT_TYPE_LIST
Map of content-type to corresponding HtmlParser.Mode , used by setContentType to
specify the content type of provided input. |
Constructor Summary | |
---|---|
AutoEscapeContext()
|
|
AutoEscapeContext(EscapeMode mode)
Create a new context in the state represented by mode. |
|
AutoEscapeContext(EscapeMode mode,
String resourceName)
Create a new context in the state represented by mode. |
Method Summary | |
---|---|
AutoEscapeContext |
cloneCurrentEscapeContext()
Create a new context that is a copy of the current state of this context. |
int |
getColumnNumber()
Returns the current column number within the resource being auto escaped. |
AutoEscapeContext.AutoEscapeState |
getCurrentState()
Calls the HtmlParser API to determine current state. |
EscapeMode |
getEscapeModeForCurrentState()
Returns the EscapeMode which will bring AutoEscapeContext into this state. |
String |
getEscapingFunctionForCurrentState()
Determine the correct escaping to apply for a variable. |
int |
getLineNumber()
Returns the current line number within the resource being auto escaped. |
String |
getResourceName()
Returns the name of the resource currently being auto escaped. |
void |
insertText()
Lets the AutoEscapeContext know that some input was skipped. |
boolean |
isPermittedStateChangeForIncludes(AutoEscapeContext.AutoEscapeState start,
AutoEscapeContext.AutoEscapeState end)
Determines whether an included template that begins in state start is allowed to end in
state end . |
void |
parseData(String data)
Parse the given data and update internal state accordingly. |
void |
setContentType(String contentType)
Resets the state of the underlying html parser to a state consistent with the contentType provided. |
void |
setCurrentPosition(int line,
int column)
Sets the current position in the resource being auto escaped. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final Map<String,HtmlParser.Mode> CONTENT_TYPE_LIST
HtmlParser.Mode
, used by setContentType
to
specify the content type of provided input. Valid values and the corresponding mode are: text/html | HtmlParser.Mode.HTML |
text/plain | HtmlParser.Mode.HTML |
application/javascript | HtmlParser.Mode.JS |
application/json | HtmlParser.Mode.JS |
text/javascript | HtmlParser.Mode.JS |
text/css | HtmlParser.Mode.CSS |
setContentType(java.lang.String)
Constructor Detail |
---|
public AutoEscapeContext()
public AutoEscapeContext(EscapeMode mode)
mode
- EscapeMode object.public AutoEscapeContext(EscapeMode mode, String resourceName)
mode
- The initial EscapeMode for this contextresourceName
- Name of the resource being auto escaped.Method Detail |
---|
public AutoEscapeContext cloneCurrentEscapeContext()
AutoEscapeContext
that is a snapshot of the current state of this context.public void setCurrentPosition(int line, int column)
line
- line number.column
- column number within line.public String getResourceName()
public int getLineNumber()
public int getColumnNumber()
public void parseData(String data)
data
- Input to parse, usually the contents of a template.public void insertText()
public boolean isPermittedStateChangeForIncludes(AutoEscapeContext.AutoEscapeState start, AutoEscapeContext.AutoEscapeState end)
start
is allowed to end in
state end
. Usually included templates are only allowed to end in the same context they
begin in. This lets auto escaping parse the remainder of the parent template without needing to
know the ending context of the included template. However, there is one exception where auto
escaping will allow a different ending context: if the included template is a URI attribute
value, it is allowed to change context from ATTR_URI_START
to ATTR_URI
. This
does not cause any issues because the including template will call insertText
when it
encounters the include command, and insertText
will cause the HTML parser to switch its
internal state in the same way.
public String getEscapingFunctionForCurrentState()
public EscapeMode getEscapeModeForCurrentState()
public AutoEscapeContext.AutoEscapeState getCurrentState()
public void setContentType(String contentType)
contentType
provided. This method should be used when the starting auto escaping context of a
resource cannot be determined from its contents - for example, a CSS stylesheet or a javascript
source file.
contentType
- MIME type header representing the content being parsed.CONTENT_TYPE_LIST
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |