org.mmbase.bridge.jsp.taglib
Class ContextReferrerTag

java.lang.Object
  extended by javax.servlet.jsp.tagext.TagSupport
      extended by javax.servlet.jsp.tagext.BodyTagSupport
          extended by org.mmbase.bridge.jsp.taglib.ContextReferrerTag
All Implemented Interfaces:
Serializable, BodyTag, IterationTag, JspTag, Tag, TryCatchFinally
Direct Known Subclasses:
AbstractParamTag, BranchTag, CloudReferrerTag, CloudTag, ContextTag, EscaperTag, EscapeTag, HasPageTag, ImportTag, LeafConstraintsTag, ListReferrerTag, LogTag, PresentTag, QueryAddNodeTag, RemoveTag, TimerTag, TimeTag, ValidTag, WriteTag, XsltTag

public abstract class ContextReferrerTag
extends BodyTagSupport
implements TryCatchFinally

If you want to have attributes which obtain the value from a parameter or other context variable, or if you want to be able to refer to other tags, then your tag can extend from this one.

Version:
$Id: ContextReferrerTag.java 35869 2009-06-09 14:02:59Z michiel $
Author:
Michiel Meeuwissen
See Also:
ContextTag, Serialized Form

Field Summary
protected  Attribute contextId
           
static int EVAL_BODY
          EVAL_BODY is EVAL_BODY_INCLUDE or EVAL_BODY_BUFFERED.
protected  WriterHelper helper
          The helper member is only used by 'Writer' extensions.
protected  Attribute id
           
protected  ContextTag pageContextTag
           
protected  Attribute referid
           
protected  Attribute writerid
          Which writer to use.
 
Fields inherited from class javax.servlet.jsp.tagext.BodyTagSupport
bodyContent
 
Fields inherited from class javax.servlet.jsp.tagext.TagSupport
pageContext
 
Fields inherited from interface javax.servlet.jsp.tagext.BodyTag
EVAL_BODY_BUFFERED, EVAL_BODY_TAG
 
Fields inherited from interface javax.servlet.jsp.tagext.IterationTag
EVAL_BODY_AGAIN
 
Fields inherited from interface javax.servlet.jsp.tagext.Tag
EVAL_BODY_INCLUDE, EVAL_PAGE, SKIP_BODY, SKIP_PAGE
 
Constructor Summary
ContextReferrerTag()
           
 
Method Summary
 String appendMoreParameters(String connector, String amp, StringBuffer buf)
          Deprecated.  
 void doCatch(Throwable e)
           
 int doEndTag()
           
 void doFinally()
           
 void fillStandardParameters(Parameters p)
          Fill standard parameters like request, response, language and locale
 Tag findLoopOrQuery(String tagId, boolean exception)
          Find loop or query tag using an id
protected
<C> C
findParentTag(Class<C> clazz, String id)
          Finds a parent tag by class and id.
<C> C
findParentTag(Class<C> clazz, String tagId, boolean exception)
          Finds a parent tag by class and id.
 Writer findWriter()
          Find the parent writer tag.
 Writer findWriter(boolean th)
          Find the parent writer tag.
 Attribute getAttribute(String attribute)
           
 Attribute getAttribute(String attribute, boolean interpretEmptyAsAbsent)
           
protected  Boolean getAttributeBoolean(String b)
          Like getAttributeValue but converts the result to a Boolean, and throws an exception if this cannot be done.
protected  Integer getAttributeInteger(String i)
          Like getAttributeValue but converts the result to an Integer, and throws an exception if this cannot be done.
protected  Integer getAttributeInteger(String i, int def)
           
 String getAttributeValue(String attribute)
          Deprecated. Call getAttribute in the set-method and 'toString(tag)' when using it. This is better for performance and makes sure the impl. works in all servlet containers.
 ContentTag getContentTag()
          Returns the content-tag in which this context-referrer is in, or a default (compatible with MMBase 1.6) if there is none.
 ContextProvider getContextProvider()
          Finds the parent context provider.
 ContextTag getContextTag()
          Finds the parent context tag.
protected  Block getCurrentBlock()
           
 Locale getDefaultLocale()
          Get the default locale which is set in mmbase.
protected  Object getEscapedValue(Object value)
          Returns the escaped value associated with this tag, but only if the escape attribute was set explicitly (so not when only inherited from content-tag).
 FormTag getFormTag(boolean excpetion, Attribute form)
          Get the surrounding form tag
 String getId()
           
 Locale getLocale()
          Get the locale which is defined by surrounding tags or the cloud
 Locale getLocaleFromContext()
          Get the locale which is defined by surrounding tags or the cloud
 Object getObject(String key)
          Gets an object from the Context.
 Object getObjectConditional(String key)
          Support '[key]?', which returns the object with name [key] if it is present, or simply null otherwise.
 PageContext getPageContext()
          Just exposes the (otherwise protected) pageContext member.
protected  ContextTag getPageContextTag()
          Returns the ContextTag first on the page
protected  Query getQuery(Attribute container)
          Implements a getQuery for QueryContainerReferrers
protected  String getReferid()
           
protected  String getString(String key)
          Gets an object from the Context, and returns it as a String.
protected static String getTaglibVersion()
           
static PageContext getThreadPageContext()
          Returns the pageContext which is stored on a trhead local for this request
 TimeZone getTimeZone()
          Get the timezone from the context or the timezone set in mmbase
 Object getWriterValue()
           
 void haveBody()
           
 void release()
          Release all allocated resources.
 void setContext(String c)
          Refer to a specific context.
 void setEscape(String e)
           
 void setId(String i)
           
 void setJspvar(String j)
           
 void setListdelimiter(String l)
          Set list delimiter
 void setPageContext(PageContext pc)
           
(package private)  void setPageContextOnly(PageContext pc)
           
 void setReferid(String r)
          ContextReferrers normally can have the attribute 'referid'.
 void setVartype(String t)
           
 void setWrite(String w)
           
 void setWriter(String w)
          Sets the writer attribute.
 
Methods inherited from class javax.servlet.jsp.tagext.BodyTagSupport
doAfterBody, doInitBody, doStartTag, getBodyContent, getPreviousOut, setBodyContent
 
Methods inherited from class javax.servlet.jsp.tagext.TagSupport
findAncestorWithClass, getParent, getValue, getValues, removeValue, setParent, setValue
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface javax.servlet.jsp.tagext.Tag
getParent, setParent
 

Field Detail

EVAL_BODY

public static int EVAL_BODY
EVAL_BODY is EVAL_BODY_INCLUDE or EVAL_BODY_BUFFERED. It wants to be EVAL_BODY_INCLUDE, but because that often not works, it on default is EVAL_BODY_BUFFERED. This configurable constant might become deprecated, because it is a bit experimental.


pageContextTag

protected ContextTag pageContextTag

contextId

protected Attribute contextId

referid

protected Attribute referid

id

protected Attribute id

writerid

protected Attribute writerid
Which writer to use.


helper

protected final WriterHelper helper
The helper member is only used by 'Writer' extensions.

Constructor Detail

ContextReferrerTag

public ContextReferrerTag()
Method Detail

getTaglibVersion

protected static String getTaglibVersion()

setPageContextOnly

void setPageContextOnly(PageContext pc)

getThreadPageContext

public static PageContext getThreadPageContext()
Returns the pageContext which is stored on a trhead local for this request

Returns:
jsp pageContext
Since:
MMBase-1.8.5

getPageContext

public PageContext getPageContext()
Just exposes the (otherwise protected) pageContext member. Needed by some helper classes in the neighbourhood. Lacking concept of friends.

Returns:
JSP Page Context

getPageContextTag

protected ContextTag getPageContextTag()
Returns the ContextTag first on the page

Returns:
ContextTag of page
Since:
MMBase-1.7.4

setPageContext

public void setPageContext(PageContext pc)
Specified by:
setPageContext in interface Tag
Overrides:
setPageContext in class TagSupport

setReferid

public void setReferid(String r)
                throws JspTagException
ContextReferrers normally can have the attribute 'referid'. If a ContextReferrer has the 'id' attribute it registers its output in the surrounding Context. With 'referid' you can 'repeat' a tag which had the 'id' attribute.

Parameters:
r - referid value
Throws:
JspTagException - when parsing of attributes fails

setId

public void setId(String i)
Overrides:
setId in class TagSupport

getId

public String getId()
Overrides:
getId in class TagSupport

getReferid

protected String getReferid()
                     throws JspTagException
Throws:
JspTagException

findWriter

public Writer findWriter()
                  throws JspTagException
Find the parent writer tag. It also calls haveBody on this parent tag, so that this knows that it has a body. If a write-tag has a body, then on default it will not write itself, but only communicate itself tot the body's tags.

Returns:
Writer
Throws:
JspTagException - when parsing of attributes fails

findWriter

public Writer findWriter(boolean th)
                  throws JspTagException
Find the parent writer tag. It also calls haveBody on this parent tag, so that this knows that it has a body. If a write-tag has a body, then on default it will not write itself, but only communicate itself tot the body's tags.

Parameters:
th - if it has to throw an exception if the parent can not be found (default: yes).
Returns:
Writer
Throws:
JspTagException - when parsing of attributes fails
Since:
MMBase-1.6.2

setWriter

public void setWriter(String w)
               throws JspTagException
Sets the writer attribute.

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

doEndTag

public int doEndTag()
             throws JspTagException
Specified by:
doEndTag in interface Tag
Overrides:
doEndTag in class BodyTagSupport
Throws:
JspTagException

doFinally

public void doFinally()
Specified by:
doFinally in interface TryCatchFinally

doCatch

public void doCatch(Throwable e)
             throws Throwable
Specified by:
doCatch in interface TryCatchFinally
Throws:
Throwable

release

public void release()
Release all allocated resources.

Specified by:
release in interface Tag
Overrides:
release in class BodyTagSupport

setContext

public void setContext(String c)
                throws JspTagException
Refer to a specific context. With this you can refer to, and write in, another context then the direct parent (but is must be an ancestor). This is for analogy with other attributes like this.

Parameters:
c - name of specific context
Throws:
JspTagException - when parsing of attributes fails

getAttributeValue

public String getAttributeValue(String attribute)
                         throws JspTagException
Deprecated. Call getAttribute in the set-method and 'toString(tag)' when using it. This is better for performance and makes sure the impl. works in all servlet containers.

Call this function in your set-attribute function. It makes it possible for the user of the taglib to include ids of values stored in the context. The method replaces all occurrences of ${x} and $x, where x is a reference to a attribute value, possibly prefixed with context names. The end of the variable if determined by the closing bracket (${x}) or by the first non ContextIndentifierChar or end of string ($x). Simple arithmetic is possible with ${+...}, and since you can even use $-vars inside ${}, you can do in this way some arithmetic on variables.

Parameters:
attribute - name of attribute
Returns:
Value of attribute
Throws:
JspTagException - when parsing of attributes fails

getAttribute

public Attribute getAttribute(String attribute)
                       throws JspTagException
Parameters:
attribute - unparsed attribute
Returns:
Attribute
Throws:
JspTagException - when parsing of attributes fails
Since:
MMBase-1.6.1

getAttribute

public Attribute getAttribute(String attribute,
                              boolean interpretEmptyAsAbsent)
                       throws JspTagException
Throws:
JspTagException
Since:
MMBase-1.9

getAttributeBoolean

protected Boolean getAttributeBoolean(String b)
                               throws JspTagException
Like getAttributeValue but converts the result to a Boolean, and throws an exception if this cannot be done.

Parameters:
b - unparsed attribute
Returns:
boolean
Throws:
JspTagException - when parsing of attributes fails

getAttributeInteger

protected Integer getAttributeInteger(String i)
                               throws JspTagException
Like getAttributeValue but converts the result to an Integer, and throws an exception if this cannot be done. It the incoming string evaluates to an empty string, then it will return 0, unless the second optional parameter specifies another default value;

Parameters:
i - unparsed attribute
Returns:
integer value of attribute
Throws:
JspTagException - when parsing of attributes fails

getAttributeInteger

protected Integer getAttributeInteger(String i,
                                      int def)
                               throws JspTagException
Throws:
JspTagException

findParentTag

public <C> C findParentTag(Class<C> clazz,
                           String tagId,
                           boolean exception)
                throws JspTagException
Finds a parent tag by class and id. This is a base function for 'getContext', but it is handy in itself, so also available for extended classes.

Type Parameters:
C - type of the tag class
Parameters:
clazz - the class of the Tag to find.
tagId - the id of the Tag to find.
exception - if it has to throw an exception if the parent can not be found (default: yes).
Returns:
Parent tag
Throws:
JspTagException - when the parent tag is not found
Since:
MMBase-1.7

findLoopOrQuery

public Tag findLoopOrQuery(String tagId,
                           boolean exception)
                    throws JspTagException
Find loop or query tag using an id

Parameters:
tagId - the id of the Tag to find.
exception - if it has to throw an exception if the parent can not be found (default: yes).
Returns:
Tag
Throws:
JspTagException - when parent tag is not found
Since:
MMBase-1.8

findParentTag

protected final <C> C findParentTag(Class<C> clazz,
                                    String id)
                         throws JspTagException
Finds a parent tag by class and id. This is a base function for 'getContext', but it is handy in itself, so also available for extended classes.

Type Parameters:
C - type of the tag class
Parameters:
clazz - the class of the Tag to find.
id - the id of the Tag to find.
Returns:
Parent tag
Throws:
JspTagException - when parent tag is not found
Since:
MMBase-1.7

getContextProvider

public ContextProvider getContextProvider()
                                   throws JspTagException
Finds the parent context provider.

Returns:
ContextProvider
Throws:
JspTagException - when context provider is not found
Since:
MMBase-1.7

getContextTag

public ContextTag getContextTag()
                         throws JspTagException
Finds the parent context tag. In MMBase 1.7 and higher, normally you would like to use getContextProvider in stead.

Returns:
ContextTag
Throws:
JspTagException - when context provider is not found

getObject

public Object getObject(String key)
                 throws JspTagException
Gets an object from the Context.

Parameters:
key - key the object is stored under
Returns:
stored object
Throws:
JspTagException - when context provider is not found

getObjectConditional

public Object getObjectConditional(String key)
                            throws JspTagException
Support '[key]?', which returns the object with name [key] if it is present, or simply null otherwise. If not ends with ?, it simply behaves like getObject(String).

Parameters:
key - key the object is stored under
Returns:
stored object
Throws:
JspTagException - when context provider is not found
Since:
MMBase-1.8.1

getString

protected String getString(String key)
                    throws JspTagException
Gets an object from the Context, and returns it as a String. This is not always a simple 'toString'. For example a getString on a Node will return the number, which also uniquely identifies it. If the object is 'not present' then it returns an empty string.

Parameters:
key - key the string is stored under
Returns:
stored string
Throws:
JspTagException - when context provider is not found

getContentTag

public ContentTag getContentTag()
                         throws JspTagException
Returns the content-tag in which this context-referrer is in, or a default (compatible with MMBase 1.6) if there is none.

Returns:
ContextTag
Throws:
JspTagException - when parent tag is not found
Since:
MMBase-1.7

getLocale

public Locale getLocale()
                 throws JspTagException
Get the locale which is defined by surrounding tags or the cloud

Returns:
a locale when defined or otherwise the mmbase locale.
Throws:
JspTagException - when parent tag is not found
Since:
MMBase-1.7.1

getLocaleFromContext

public Locale getLocaleFromContext()
                            throws JspTagException
Get the locale which is defined by surrounding tags or the cloud

Returns:
a locale when defined or otherwise null
Throws:
JspTagException - when parent tag is not found
Since:
MMBase-1.8.1

getDefaultLocale

public Locale getDefaultLocale()
Get the default locale which is set in mmbase.

Returns:
default locale
Since:
MMBase-1.8.1

getTimeZone

public TimeZone getTimeZone()
Get the timezone from the context or the timezone set in mmbase

Returns:
timezone
Since:
MMBase-1.8

fillStandardParameters

public void fillStandardParameters(Parameters p)
                            throws JspTagException
Fill standard parameters like request, response, language and locale

Parameters:
p - the parameters
Throws:
JspTagException - when parent tag is not found
Since:
MMBase-1.7.4

getCurrentBlock

protected Block getCurrentBlock()
                         throws JspTagException
Throws:
JspTagException
Since:
MMBase-1.9

setVartype

public void setVartype(String t)
                throws JspTagException
Throws:
JspTagException

setListdelimiter

public final void setListdelimiter(String l)
                            throws JspTagException
Set list delimiter

Parameters:
l - delimiter
Throws:
JspTagException - when parsing of attributes fails
Since:
MMBase-1.8

setJspvar

public void setJspvar(String j)

setWrite

public final void setWrite(String w)
                    throws JspTagException
Throws:
JspTagException

setEscape

public final void setEscape(String e)
                     throws JspTagException
Throws:
JspTagException

getWriterValue

public final Object getWriterValue()

haveBody

public final void haveBody()

getEscapedValue

protected Object getEscapedValue(Object value)
                          throws JspTagException
Returns the escaped value associated with this tag, but only if the escape attribute was set explicitly (so not when only inherited from content-tag).

Parameters:
value - initial value
Returns:
escaped value
Throws:
JspTagException - when parsing of attributes fails
Since:
MMBase-1.8

getFormTag

public FormTag getFormTag(boolean excpetion,
                          Attribute form)
                   throws JspTagException
Get the surrounding form tag

Parameters:
excpetion - throw exception when form tag not found
form - name of form
Returns:
FormTag
Throws:
JspTagException - when parsing of attributes fails
Since:
MMBase-1.8.5

getQuery

protected final Query getQuery(Attribute container)
                        throws JspTagException
Implements a getQuery for QueryContainerReferrers

Throws:
JspTagException
Since:
MMBase-1.9.0

appendMoreParameters

public String appendMoreParameters(String connector,
                                   String amp,
                                   StringBuffer buf)
                            throws JspTagException
Deprecated. 

Can be overriden in extensions.

Returns:
new connector
Throws:
JspTagException
Since:
MMBase-1.8.5


MMBase 2.0-SNAPSHOT - null