org.mmbase.bridge.jsp.taglib.util
Class Attribute

java.lang.Object
  extended by org.mmbase.bridge.jsp.taglib.util.Attribute
Direct Known Subclasses:
NullAttribute

public class Attribute
extends Object

MMBase Taglib attributes can contain $-variables. Parsing of these $-variables is cached. Evaluation of these vars must be postponed until doStartTag because servlet containers can decide not to call the set-function of the attribute (in case of tag-instance-reuse).

Since:
MMBase-1.7
Version:
$Id: Attribute.java 35335 2009-05-21 08:14:41Z michiel $
Author:
Michiel Meeuwissen

Nested Class Summary
(package private) static class Attribute.ExpressionPart
          A ${+ } part containing an 'expression'.
(package private) static class Attribute.Part
          A Part represents one part of an Attribute.
(package private) static class Attribute.StringPart
          A simple 'string' part, wich does not need any evaluating or parsing any more.
(package private) static class Attribute.VariablePart
          A part containing a $-variable.
 
Field Summary
static Attribute NULL
           
 
Constructor Summary
protected Attribute()
           
protected Attribute(String at)
          The constructor is protected, construction is done by the cache.
 
Method Summary
 void appendValue(ContextReferrerTag tag, StringBuilder buffer)
          Appends the evaluated Attribute to StringBuilder
(package private)  boolean containsVars()
           
static Attribute getAttribute(String at)
           
static Attribute getAttribute(String at, boolean interpretEmptyAsAbsent)
          This is the function for public use.
 boolean getBoolean(ContextReferrerTag tag, boolean def)
          Returns the evaluated Attribute as a boolean (depending on if getValue returns one of the strings 'true' or 'false' (case insensitive)).
 int getInt(ContextReferrerTag tag, int def)
          Returns the evaluated Attribute as a int
 List<String> getList(ContextReferrerTag tag)
          Returns the evaluated Attribute as a List (evaluated to comma-separated String, which is 'split').
 long getLong(ContextReferrerTag tag, long def)
           
 String getString(ContextReferrerTag tag)
          Returns the evaluated Attribute as a String.
 Object getValue(ContextReferrerTag tag)
          Returns the evaluated Attribute as an Object.
protected  void parse()
          Parses this attribute into list of 'attributeparts'.
 String toString()
          String representation of this Attribute object (for debugging)
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

NULL

public static final Attribute NULL
Constructor Detail

Attribute

protected Attribute(String at)
             throws JspTagException
The constructor is protected, construction is done by the cache.

Parameters:
at - unparsed attribute
Throws:
JspTagException - when parsing of attributes fails

Attribute

protected Attribute()
Method Detail

getAttribute

public static final Attribute getAttribute(String at,
                                           boolean interpretEmptyAsAbsent)
                                    throws JspTagException
This is the function for public use. It takes the string and returns an Attribute, creating a new one if it is not in the Attribute cache.

Parameters:
at - unparsed attribute
interpretEmptyAsAbsent - whether the empty attribute should be interpreted as no attribute at all (default to false).
Returns:
Attribute
Throws:
JspTagException - when parsing of attributes fails
Since:
MMBase-1.9

getAttribute

public static final Attribute getAttribute(String at)
                                    throws JspTagException
Throws:
JspTagException

containsVars

final boolean containsVars()

appendValue

public void appendValue(ContextReferrerTag tag,
                        StringBuilder buffer)
                 throws JspTagException
Appends the evaluated Attribute to StringBuilder

Parameters:
tag - The tag relative to which the variable evaluations must be done (normally 'this' in a Tag implementation)
buffer - buffer to write attribute value to
Throws:
JspTagException - when parsing of attributes fails

getValue

public Object getValue(ContextReferrerTag tag)
                throws JspTagException
Returns the evaluated Attribute as an Object. Can also be null.

Parameters:
tag - tag with the attribute
Returns:
Value of attribute
Throws:
JspTagException - when parsing of attributes fails

getString

public String getString(ContextReferrerTag tag)
                 throws JspTagException
Returns the evaluated Attribute as a String. This is never null (empty string in that case)..

Parameters:
tag - tag with the attribute
Returns:
Value of attribute
Throws:
JspTagException - when parsing of attributes fails

getInt

public int getInt(ContextReferrerTag tag,
                  int def)
           throws JspTagException
Returns the evaluated Attribute as a int

Parameters:
tag - tag with the attribute
def - default value
Returns:
Value of attribute
Throws:
JspTagException - when parsing of attributes fails

getLong

public long getLong(ContextReferrerTag tag,
                    long def)
             throws JspTagException
Throws:
JspTagException

getList

public List<String> getList(ContextReferrerTag tag)
                     throws JspTagException
Returns the evaluated Attribute as a List (evaluated to comma-separated String, which is 'split'). The List is empty if getValue would give empty String or null.

Parameters:
tag - tag with the attribute
Returns:
Value of attribute
Throws:
JspTagException - when parsing of attributes fails

getBoolean

public boolean getBoolean(ContextReferrerTag tag,
                          boolean def)
                   throws JspTagException
Returns the evaluated Attribute as a boolean (depending on if getValue returns one of the strings 'true' or 'false' (case insensitive)).

Parameters:
def - If the string is not "true" or "false', then this value is returned.
tag - tag with the attribute
Returns:
true or false
Throws:
JspTagException - when parsing of attributes fails

toString

public String toString()
String representation of this Attribute object (for debugging)

Overrides:
toString in class Object
See Also:
Object.toString()

parse

protected void parse()
              throws JspTagException
Parses this attribute into list of 'attributeparts'. This is the heart of the Attribute class. The method getValue(org.mmbase.bridge.jsp.taglib.ContextReferrerTag) will concatenate them together again (after evaluation).

Throws:
JspTagException - when parsing of attributes fails


MMBase 2.0-SNAPSHOT - null