org.apache.cocoon.components.language.markup.xsp
Class XSPExpressionParser

java.lang.Object
  extended byorg.apache.cocoon.components.language.markup.xsp.XSPExpressionParser

public class XSPExpressionParser
extends Object

Parse XSP expressions. Expressions are embedded in attribute="value" and text elements and are expanded by the PreProcessFilter and have the form {#expression}. To prevent interpolation, use {##quote}, which results in the text {#quote}. An exception is thrown if the closing brace is missing.

The parser has a rudimentary understanding of expressions concerning nested braces and braces inside quoted strings and character constants. All valid Java, Javascript, and Python expressions can be used.

Example: <h1>Hello {#user.getName()}</h1> <img or src="image_{#image.getId()}"/>

Version:
SVN $Id: XSPExpressionParser.java 278686 2005-09-05 07:31:04Z anathaniel $

Nested Class Summary
static interface XSPExpressionParser.Handler
          Handler interface for parsed expressions and text fragments.
protected static class XSPExpressionParser.QuotedState
          Parser state in a quoted string.
protected static class XSPExpressionParser.State
          Parser state.
 
Field Summary
protected static XSPExpressionParser.State EXPRESSION_CHAR_STATE
          The parser has encountered '\'' in EXPRESSION_STATE to start a character constant.
protected static XSPExpressionParser.State EXPRESSION_SHELL_STATE
          The parser has encountered '`' (Backtick, ASCII 0x60) in EXPRESSION_STATE to start a Python string constant.
protected static XSPExpressionParser.State EXPRESSION_STATE
          The parser is parsing an expression.
protected static XSPExpressionParser.State EXPRESSION_STRING_STATE
          The parser has encountered '"' in EXPRESSION_STATE to start a string constant.
protected static XSPExpressionParser.State LBRACE_STATE
          The parser has encountered '{' in TEXT_STATE.
protected static XSPExpressionParser.State TEXT_HASH_STATE
          The parser has encountered '#' in LBRACE_STATE.
protected static XSPExpressionParser.State TEXT_STATE
          The parser is parsing text.
 
Constructor Summary
XSPExpressionParser(XSPExpressionParser.Handler handler)
          Create a new XSPExpressionParser.
 
Method Summary
protected  void append(char ch)
           
 void consume(char[] chars, int start, int length)
          Parses part of a character array.
 void consume(CharSequence chars)
          Parses a character sequence.
protected  int decrNesting()
           
 void flush()
          Flushes the parser
protected  String getExpression()
           
protected  XSPExpressionParser.State getState()
           
protected  void handleExpression()
           
protected  void handleText()
           
protected  void incrNesting()
           
protected  void initExpression()
           
protected  boolean isEscaped()
           
protected  void setEscaped(boolean escaped)
           
protected  void setState(XSPExpressionParser.State state)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TEXT_STATE

protected static final XSPExpressionParser.State TEXT_STATE
The parser is parsing text.


LBRACE_STATE

protected static final XSPExpressionParser.State LBRACE_STATE
The parser has encountered '{' in TEXT_STATE.


TEXT_HASH_STATE

protected static final XSPExpressionParser.State TEXT_HASH_STATE
The parser has encountered '#' in LBRACE_STATE.


EXPRESSION_STATE

protected static final XSPExpressionParser.State EXPRESSION_STATE
The parser is parsing an expression.


EXPRESSION_STRING_STATE

protected static final XSPExpressionParser.State EXPRESSION_STRING_STATE
The parser has encountered '"' in EXPRESSION_STATE to start a string constant.


EXPRESSION_CHAR_STATE

protected static final XSPExpressionParser.State EXPRESSION_CHAR_STATE
The parser has encountered '\'' in EXPRESSION_STATE to start a character constant.


EXPRESSION_SHELL_STATE

protected static final XSPExpressionParser.State EXPRESSION_SHELL_STATE
The parser has encountered '`' (Backtick, ASCII 0x60) in EXPRESSION_STATE to start a Python string constant.

Constructor Detail

XSPExpressionParser

public XSPExpressionParser(XSPExpressionParser.Handler handler)
Create a new XSPExpressionParser.

Parameters:
handler - The handler for parsed text and expression fragments.
Method Detail

consume

public void consume(CharSequence chars)
             throws SAXException
Parses a character sequence.

Parameters:
chars - The character sequence to parse
Throws:
SAXException - If there is an error in the sequence.

consume

public void consume(char[] chars,
                    int start,
                    int length)
             throws SAXException
Parses part of a character array.

Parameters:
chars - The characters
start - The start position in the character array
length - The number of characters to parse
Throws:
SAXException - If there is an error in the sequence.

flush

public void flush()
           throws SAXException
Flushes the parser

Throws:
SAXException - If there is an error in the parsed text.

getState

protected XSPExpressionParser.State getState()

setState

protected void setState(XSPExpressionParser.State state)

initExpression

protected void initExpression()

incrNesting

protected void incrNesting()

decrNesting

protected int decrNesting()

setEscaped

protected void setEscaped(boolean escaped)

isEscaped

protected boolean isEscaped()

getExpression

protected String getExpression()

handleText

protected void handleText()
                   throws SAXException
Throws:
SAXException

handleExpression

protected void handleExpression()
                         throws SAXException
Throws:
SAXException

append

protected void append(char ch)


Copyright ? 1999-2005 The Apache Software Foundation. All Rights Reserved.