Class FormBaseTag
- java.lang.Object
-
- org.apache.commons.jelly.TagSupport
-
- net.sf.jguiraffe.gui.builder.components.tags.FormBaseTag
-
- All Implemented Interfaces:
ConditionalTag
,org.apache.commons.jelly.Tag
- Direct Known Subclasses:
AbstractActionDataTag
,ComponentBaseTag
,ComponentGroupTag
,ConstraintsTag
,EventListenerTag
,EventListenerTypeTag
,FontTag
,IconTag
,LayoutTag
,ListModelItemTag
,LocalizedTag
,MenuBarTag
,MenuTag
,PercentCellConstraintsTag
,PercentCellGroupTag
,PropertiesTag
,PropertyTag
,ReferenceTag
,SeparatorTag
,TextListModelTag
,TreeIconTag
public abstract class FormBaseTag extends org.apache.commons.jelly.TagSupport implements ConditionalTag
A base class for tags of the form builder framework.
This class implements some common functionality used by form builder tags. Especially conditional execution and access to the central builder data object is implemented here.
Many operations are available both in an instance and a static form. This makes it easy for other tag classes that can not inherit from this class to make use of the provided functionality.
- Version:
- $Id: FormBaseTag.java 205 2012-01-29 18:29:57Z oheger $
- Author:
- Oliver Heger
-
-
Constructor Summary
Constructors Constructor Description FormBaseTag()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected boolean
canProcess()
Tests whether this tag should be executed.static boolean
canProcess(ConditionalTag tag)
Tests if the specified conditional tag should be executed.static Class<?>
convertToClass(Object clsObj)
Helper method for converting attributes of type class.protected static NumberWithUnit
convertToNumberWithUnit(String s)
Converts a string attribute into the corresponding number with unit.protected static NumberWithUnit
convertToNumberWithUnit(String s, NumberWithUnit defValue)
Converts a string attribute into the correspondingNumberWithUnit
returning the default value if the attribute has not been set.void
doTag(org.apache.commons.jelly.XMLOutput output)
The main method of this tag class.Composite
findContainer()
Tries to determine the container to which this component should be added.protected ComponentBuilderData
getBuilderData()
Returns the current
object for this builder operation.ComponentBuilderData
static ComponentBuilderData
getBuilderData(org.apache.commons.jelly.JellyContext context)
Returns the currentComponentBuilderData
object from the context.String
getIfName()
Returns the ifName attribute.protected String
getResourceText(Object resGrp, Object resId)
Convenience method for resolving resources.static String
getResourceText(org.apache.commons.jelly.JellyContext context, Object resGrp, Object resId)
Resolves the specified resource.String
getUnlessName()
Returns the unlessName attribute.protected abstract void
process()
Executes this tag.protected void
processBeforeBody()
Performs processing of this tag before its body is evaluated.void
setIfName(String s)
Sets the value of the ifName attribute.void
setUnlessName(String s)
Sets the value of the unlessName attribute.-
Methods inherited from class org.apache.commons.jelly.TagSupport
findAncestorWithClass, findAncestorWithClass, findAncestorWithClass, findAncestorWithClass, findAncestorWithClass, findAncestorWithClass, getBody, getBodyText, getBodyText, getContext, getParent, invokeBody, isEscapeText, isTrim, setBody, setContext, setEscapeText, setParent, setTrim, trimBody
-
-
-
-
Method Detail
-
getIfName
public String getIfName()
Returns the ifName attribute.- Specified by:
getIfName
in interfaceConditionalTag
- Returns:
- the value of the ifName attribute
-
setIfName
public void setIfName(String s)
Sets the value of the ifName attribute. This attribute is used by the mechanism for conditional execution. This method is called by jelly.- Parameters:
s
- the attribute value
-
getUnlessName
public String getUnlessName()
Returns the unlessName attribute.- Specified by:
getUnlessName
in interfaceConditionalTag
- Returns:
- the value of the unlessName attribute
-
setUnlessName
public void setUnlessName(String s)
Sets the value of the unlessName attribute. This attribute is used by the mechanism for conditional execution. This method is called by jelly.- Parameters:
s
- the attribute value
-
doTag
public void doTag(org.apache.commons.jelly.XMLOutput output) throws org.apache.commons.jelly.JellyTagException
The main method of this tag class. This implementation checks if the tag can be executed (by callingcanProcess()
. If this is the case, control is passed to theprocess()
method.- Specified by:
doTag
in interfaceorg.apache.commons.jelly.Tag
- Parameters:
output
- the output object (ignored because form builder tags do not produce any output)- Throws:
org.apache.commons.jelly.JellyTagException
- if any exception occurs
-
getBuilderData
public static ComponentBuilderData getBuilderData(org.apache.commons.jelly.JellyContext context)
Returns the currentComponentBuilderData
object from the context.- Parameters:
context
- the jelly context- Returns:
- the builder data
-
canProcess
public static boolean canProcess(ConditionalTag tag)
Tests if the specified conditional tag should be executed. This method determines based on the values of the ifName and unlessName attributes whether execution is allowed. If the ifName attribute is defined, execution is only allowed if the current builder's name exactly matches the attribute value. If the unlessName attribute is defined, then the tag is only executed if the current builder's name does not match the attribute's value. (If both attributes are defined, the ifName attribute takes precedence.)- Parameters:
tag
- the tag- Returns:
- a flag if the tag can be executed
-
getResourceText
public static String getResourceText(org.apache.commons.jelly.JellyContext context, Object resGrp, Object resId) throws FormBuilderRuntimeException
Resolves the specified resource. This is a convenience method for builder components that support i11n.- Parameters:
context
- the actual jelly contextresGrp
- the resource groupresId
- the resource ID- Returns:
- the text of the resource
- Throws:
FormBuilderRuntimeException
- if the resource cannot be resolved
-
convertToClass
public static Class<?> convertToClass(Object clsObj) throws FormBuilderRuntimeException
Helper method for converting attributes of type class. Jelly does not itself directly support class attributes, so this is handled by this helper method. The passed in object can either be directly of type class or it is interpreted as the name of a class. In the latter case the class name is resolved and the class object is returned.- Parameters:
clsObj
- an object specifying a class- Returns:
- the resolved class object
- Throws:
FormBuilderRuntimeException
- if the class cannot be resolved
-
convertToNumberWithUnit
protected static NumberWithUnit convertToNumberWithUnit(String s) throws FormBuilderException
Converts a string attribute into the corresponding number with unit. If this fails, an exception will be thrown.- Parameters:
s
- the string- Returns:
- the converted number (null if the string is undefined)
- Throws:
FormBuilderException
- if conversion fails
-
convertToNumberWithUnit
protected static NumberWithUnit convertToNumberWithUnit(String s, NumberWithUnit defValue) throws FormBuilderException
Converts a string attribute into the correspondingNumberWithUnit
returning the default value if the attribute has not been set. If the conversion fails, an exception is thrown.- Parameters:
s
- the string to be converteddefValue
- the default value- Returns:
- the converted number
- Throws:
FormBuilderException
- if conversion fails
-
getBuilderData
protected ComponentBuilderData getBuilderData()
Returns the current
object for this builder operation.ComponentBuilderData
- Returns:
- the builder data
-
getResourceText
protected String getResourceText(Object resGrp, Object resId) throws FormBuilderRuntimeException
Convenience method for resolving resources.- Parameters:
resGrp
- the resource groupresId
- the resource ID- Returns:
- the text of the specified resource
- Throws:
FormBuilderRuntimeException
- if the resource cannot be resolved
-
canProcess
protected boolean canProcess()
Tests whether this tag should be executed. Evaluates the attributes for conditional execution.- Returns:
- a flag if this tag should be executed
- See Also:
canProcess(ConditionalTag)
-
findContainer
public Composite findContainer()
Tries to determine the container to which this component should be added. This implementation first looks for an enclosing<container>
tag (i.e. a tag implementing theComposite
interface. If this is found, the container object defined there is used (determined by the currentContainerSelector
). Otherwise the method assumes that the new component should be added to the top level container, which can be obtained from the builder data object.- Returns:
- the container object
-
processBeforeBody
protected void processBeforeBody() throws org.apache.commons.jelly.JellyTagException, FormBuilderException
Performs processing of this tag before its body is evaluated. This can be necessary if some initialization has to be performed first which is required by nested tags. This method is automatically called bydoTag()
. This base implementation is left empty.- Throws:
org.apache.commons.jelly.JellyTagException
- if a jelly specific error occursFormBuilderException
- if an error in the builder framework occurs
-
process
protected abstract void process() throws org.apache.commons.jelly.JellyTagException, FormBuilderException
Executes this tag. Here concrete sub classes must place their tag logic. This method is invoked bydoTag()
if execution is allowed.- Throws:
org.apache.commons.jelly.JellyTagException
- if a jelly specific error occursFormBuilderException
- if an error in the builder framework occurs
-
-