Class TagsFactory
- java.lang.Object
-
- com.microstrategy.web.tags.TagsFactory
-
public class TagsFactory extends java.lang.Object
Previous versions of Microstrategy Web used methods in the
HTMLHelper
class to generate HTML tags; these methods return aString
object with the corresponding HTML for the open tag, for example,HTMLHelper.generateIMG(MarkupOutput, int, String, String)
returns:<img src="firstArgument" title="secondArgument">
String
, the method requires to know all the tag attributes (which might be different depending on the usage scenario), so eachgenerateTAG
method became overloaded several times for the different scenarios where the tag is used. TheTAGS
infrastructure solves this problem by creatingTag
objects responsible to generate the HTML output.Tag
objects are created using thisTagsFactory
; developers can set attributes to eachTag
using itsTag.setAttribute(java.lang.String, java.lang.String)
method. They can change the tag's inner-content with theTag.getContent()
method, which returns a MarkupOutput. When theTag
is ready, itsTag.render(MarkupOutput)
method generates the HTML inside the MarkupOutput it receives as argument.For example, suppose we would like to generate the following HTML:
<div class="web-link" title="Some title" onclick="alert('this');">Click to see an alert!</div>
Tag
object this is the Java code to generate it://All tags are created using an instance of the TagsFactory: Tag anchor = TagsFactory.getInstance().newTag("div"); //Set any necessary attributes to the Tag: anchor.setAttribute("class", "web-link"); anchor.setAttribute("title", "Some title"); anchor.setAttribute("onclick", "alert('this');"); //Populate the tag's content anchor.getContent().append("Click to see an alert!"); //Call render to generate the HTML. anchor.render(out);
HTML tags are hierarchical by nature: any tag can have any other as its child, all children are rendered within the parent's content.
MicroStrategyTAGS
infrastructure supports this same behavior. For example, suppose we would like to generate a list of elements using the following HTML:<ol> <li>First element</li> <li>Second element</li> <li>Third element</li> </ol>
Tag
objects this is the Java code to generate it://All tags are created using the TagsFactory: TagsFactory tf = TagsFactory.getInstance(); //Create the ol: Tag olTag = tf.newTag("ol"); //Create each element, add it to the olTag Tag li = tf.newTag("li"); li.getContent().append("First element"); olTag.addChild(li); li = tf.newTag("li"); li.getContent().append("Second element"); olTag.addChild(li); li = tf.newTag("li"); li.getContent().append("Third element"); olTag.addChild(li); //Call render to generate the HTML. //Notice you only need to call it on the root TAG: ol.render(out);
The tags can be configured from a properties file
TAG_IMPL_PROPS
. Currently you can configure the actual implementation class for a tag and a property of the tag. This property will denote if a tag requires an explicit close tag. Below are some examples of sample entries in this file.*.impl=com.microstrategy.web.tags.TagImpl a.impl=com.microstrategy.web.app.tags.AnchorWebTag
The above two lines in this file indicate that by default we will use the class
TagImpl
to render any tag. This default implementing class can be overridden for a tag as can be seen in the second line where we use theAnchorWebTag
to render the anchor tag. The general syntax for adding any implementation class definition to this file is<tagname>
TAGPROPERTIES_DELIMITER
<IMPLEMENTATION_CLASS_PROPERTY_NAME
>=<Fully qualified implementation class name>*.isCloseTagRqd=true area.isCloseTagRqd=false
The above two lines in this file indicate that by default all tags require an explicit close tag. This default can be overridden for a tag as can be seen in the second line where we we denote the area tag to not have an explicit close tag. The general syntax for adding a new tag to this property is
<tagname>
TAGPROPERTIES_DELIMITER
<IS_CLOSE_TAG_REQUIRED_PROPERY_NAME
>=<true or false>- Since:
- MicroStrategy Web 8.0.0
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
IMPLEMENTATION_CLASS_PROPERTY_NAME
static java.lang.String
IS_CLOSE_TAG_REQUIRED_PROPERY_NAME
static java.lang.String
PRESERVE_CASE
static java.lang.String
TAG_IMPL_PROPS
static java.lang.String
TAGPROPERTIES_DELIMITER
-
Constructor Summary
Constructors Modifier Constructor Description protected
TagsFactory()
Constructs a TagsFactory instance and reads the tag implementation classes from an external property file namelyTagsFactory.properties
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.util.Map
getCloseTagClassMap()
Returns an instance ofMap
over all the tag names which require an explicit close tag .protected java.util.Map
getImplClassMap()
Returns an instance ofMap
over all the tag implementation class names.protected java.lang.String
getImplClassName(java.lang.String tagName)
Returns the fully qualified implementation class name for the tag with the specified tag name.static TagsFactory
getInstance()
Returns a singleton of the TagsFactory.protected boolean
getIsCloseTagRequired(java.lang.String tagName)
Returns true if the tag requires an explicit close tag.protected boolean
getPreserveCase(java.lang.String tagName)
Returns true if the tag requires preserving case for the tag and attribute names.protected java.util.Map
getPreserveCaseMap()
Returns an instance ofMap
indicating whether the case of tag and attribute names will be preserved.AnchorTag
newAnchorTag()
Instantiates an emptyAnchorTag
.ArgumentTag
newArgumentTag()
Instantiates an emptyArgumentTag
.AttrTag
newAttrTag()
Instantiates an emptyAttrTag
.BaseTag
newBaseTag()
Instantiates an emptyBaseTag
.CellTag
newCellTag()
Instantiates an emptycell
tag.DisplayTag
newDisplayTag()
Instantiates an emptyDisplayTag
.Tag
newDivTag()
Instantiates an emptydiv
tag.SelectTag
newDropDownBoxTag()
Instantiates aselect
tag with its attributesize
default to1
.IfTag
newIfTag()
Instantiates an emptyIfTag
.ImageTag
newImageTag()
Instantiates animage
tag with its attributeborder
default to zero.IncludeTag
newIncludeTag()
Instantiates an emptyIncludeTag
.InputTag
newInputButtonTag()
Instantiates ainput
tag with its attributetype
default tobutton
.InputTag
newInputCheckTag()
Instantiates ainput
tag with its attributechecked
default totrue
.InputTag
newInputHiddenTag()
Instantiates ainput
tag with its attributetype
default tohidden
.InputTag
newInputImageTag()
Instantiates ainput
tag with its attributetype
default toimage
, and attributeborder
default to zero.InputTag
newInputNumberTag()
Instantiates ainput
tag with its attributetype
default tonumber
.InputTag
newInputRadioTag()
Instantiates ainput
tag with its attributetype
default toradio
.InputTag
newInputSubmitTag()
Instantiates ainput
tag with its attributetype
default tosubmit
.InputTag
newInputTag()
Instantiates an emptyinput
tag.InputTag
newInputTextTag()
Instantiates ainput
tag with its attributetype
default totext
.LayoutTag
newLayoutTag()
Instantiates an emptyLayoutTag
.ListTag
newListTag()
Instantiates an emptyListTag
.NextTag
newNextTag()
Instantiates an emptyNextTag
.Tag
newOptionTag(java.lang.String value, java.lang.String content, boolean selected)
RenderTag
newRenderTag()
Instantiates an emptyRenderTag
.ReplaceTag
newReplaceTag()
Instantiates an emptyReplaceTag
.RowTag
newRowTag()
Instantiates an emptyrow
tag.Tag
newScriptTag()
Instantiates ascript
tag with its attributelanguage
default tojavascript
.SelectTag
newSelectTag()
Instantiates an emptyselect
tag.SlotTag
newSlotTag()
Instantiates an emptySlotTag
.Tag
newSpanTag()
Instantiates an emptyspan
tag.TableTag
newTableTag()
Instantiates atable
tag with its attributescellspacing
,cellpadding
andcellborder
default to zero.Tag
newTag(java.lang.String name)
Instantiates an emptyTag
based on the specified tag name.
-
-
-
Field Detail
-
TAG_IMPL_PROPS
public static final java.lang.String TAG_IMPL_PROPS
- See Also:
- Constant Field Values
-
TAGPROPERTIES_DELIMITER
public static final java.lang.String TAGPROPERTIES_DELIMITER
- Since:
- MicroStrategy Web 9.0.0
- See Also:
- Constant Field Values
-
IMPLEMENTATION_CLASS_PROPERTY_NAME
public static final java.lang.String IMPLEMENTATION_CLASS_PROPERTY_NAME
- Since:
- MicroStrategy Web 9.0.0
- See Also:
- Constant Field Values
-
IS_CLOSE_TAG_REQUIRED_PROPERY_NAME
public static final java.lang.String IS_CLOSE_TAG_REQUIRED_PROPERY_NAME
- Since:
- MicroStrategy Web 9.0.0
- See Also:
- Constant Field Values
-
PRESERVE_CASE
public static final java.lang.String PRESERVE_CASE
- Since:
- MicroStrategy Web 9.0.0
- See Also:
- Constant Field Values
-
-
Method Detail
-
getInstance
public static TagsFactory getInstance()
Returns a singleton of the TagsFactory.- Returns:
- a singleton of the TagsFactory.
-
newAnchorTag
public AnchorTag newAnchorTag()
Instantiates an emptyAnchorTag
.- Returns:
- the newly instantiated
AnchorTag
.
-
newTag
public Tag newTag(java.lang.String name)
Instantiates an emptyTag
based on the specified tag name. Fordiv
,span
andlabel
tags, sets their closing tag as required due to Web browser limitation.- Parameters:
name
- the tag name to be instantiated.- Returns:
- the newly instantiated
Tag
.
-
newTableTag
public TableTag newTableTag()
Instantiates atable
tag with its attributescellspacing
,cellpadding
andcellborder
default to zero.- Returns:
- a new table tag instance.
-
newRowTag
public RowTag newRowTag()
Instantiates an emptyrow
tag.- Returns:
- a new row tag instance.
-
newCellTag
public CellTag newCellTag()
Instantiates an emptycell
tag.- Returns:
- a new cell tag instance.
-
newDivTag
public Tag newDivTag()
Instantiates an emptydiv
tag.- Returns:
- a new div tag instance.
-
newDropDownBoxTag
public SelectTag newDropDownBoxTag()
Instantiates aselect
tag with its attributesize
default to1
.- Returns:
- a new select tag instance.
-
newSelectTag
public SelectTag newSelectTag()
Instantiates an emptyselect
tag.- Returns:
- a new select tag instance.
-
newSpanTag
public Tag newSpanTag()
Instantiates an emptyspan
tag.- Returns:
- a new span tag instance.
-
newScriptTag
public Tag newScriptTag()
Instantiates ascript
tag with its attributelanguage
default tojavascript
.- Returns:
- a new script tag instance.
-
newImageTag
public ImageTag newImageTag()
Instantiates animage
tag with its attributeborder
default to zero.- Returns:
- a new image tag instance.
-
newInputTag
public InputTag newInputTag()
Instantiates an emptyinput
tag.- Returns:
- a new input tag instance.
-
newInputImageTag
public InputTag newInputImageTag()
Instantiates ainput
tag with its attributetype
default toimage
, and attributeborder
default to zero.- Returns:
- a new input tag instance.
-
newInputCheckTag
public InputTag newInputCheckTag()
Instantiates ainput
tag with its attributechecked
default totrue
.- Returns:
- a new input tag instance.
-
newInputRadioTag
public InputTag newInputRadioTag()
Instantiates ainput
tag with its attributetype
default toradio
.- Returns:
- a new input tag instance.
-
newInputButtonTag
public InputTag newInputButtonTag()
Instantiates ainput
tag with its attributetype
default tobutton
.- Returns:
- a new input tag instance.
-
newInputSubmitTag
public InputTag newInputSubmitTag()
Instantiates ainput
tag with its attributetype
default tosubmit
.- Returns:
- a new input tag instance.
-
newInputTextTag
public InputTag newInputTextTag()
Instantiates ainput
tag with its attributetype
default totext
.- Returns:
- a new input tag instance.
-
newInputNumberTag
public InputTag newInputNumberTag()
Instantiates ainput
tag with its attributetype
default tonumber
.- Returns:
- a new input tag instance.
-
newInputHiddenTag
public InputTag newInputHiddenTag()
Instantiates ainput
tag with its attributetype
default tohidden
.- Returns:
- a new input tag instance.
-
newLayoutTag
public LayoutTag newLayoutTag()
Instantiates an emptyLayoutTag
.- Returns:
- a new layout tag instance.
-
newListTag
public ListTag newListTag()
Instantiates an emptyListTag
.- Returns:
- a new list tag instance.
-
newNextTag
public NextTag newNextTag()
Instantiates an emptyNextTag
.- Returns:
- a new next tag instance.
-
newRenderTag
public RenderTag newRenderTag()
Instantiates an emptyRenderTag
.- Returns:
- a new render tag instance.
-
newDisplayTag
public DisplayTag newDisplayTag()
Instantiates an emptyDisplayTag
.- Returns:
- a new display tag instance.
- Since:
- MicroStrategy Web 9.0.0
-
newBaseTag
public BaseTag newBaseTag()
Instantiates an emptyBaseTag
.- Returns:
- a new base tag instance.
- Since:
- MicroStrategy Web 9.0.0
-
newArgumentTag
public ArgumentTag newArgumentTag()
Instantiates an emptyArgumentTag
.- Returns:
- a new argument tag instance.
-
newAttrTag
public AttrTag newAttrTag()
Instantiates an emptyAttrTag
.- Returns:
- a new attr tag instance.
-
newIncludeTag
public IncludeTag newIncludeTag()
Instantiates an emptyIncludeTag
.- Returns:
- a new include tag instance.
- Since:
- MicroStrategy Web 8.0.2
-
newReplaceTag
public ReplaceTag newReplaceTag()
Instantiates an emptyReplaceTag
.- Returns:
- a new replace tag instance.
- Since:
- MicroStrategy Web 8.0.2
-
newSlotTag
public SlotTag newSlotTag()
Instantiates an emptySlotTag
.- Returns:
- a new slot tag instance.
- Since:
- MicroStrategy Web 8.0.2
-
newOptionTag
public Tag newOptionTag(java.lang.String value, java.lang.String content, boolean selected)
-
getIsCloseTagRequired
protected boolean getIsCloseTagRequired(java.lang.String tagName)
Returns true if the tag requires an explicit close tag.- Parameters:
tagName
- the tag name.- Returns:
- true if the tag requires an explicit close tag.
- Since:
- MicroStrategy Web 9.0.0
-
getPreserveCase
protected boolean getPreserveCase(java.lang.String tagName)
Returns true if the tag requires preserving case for the tag and attribute names.- Parameters:
tagName
- the tag name.- Returns:
- true if the tag requires preserving case for the tag and attribute names.
- Since:
- MicroStrategy Web 9.0.0
-
getImplClassName
protected java.lang.String getImplClassName(java.lang.String tagName)
Returns the fully qualified implementation class name for the tag with the specified tag name.- Parameters:
tagName
- the tag name.- Returns:
- the fully qualified implementation class name.
-
getCloseTagClassMap
protected java.util.Map getCloseTagClassMap()
Returns an instance ofMap
over all the tag names which require an explicit close tag .- Returns:
- a
Map
over all the tag names which require an explicit close tag . - Since:
- MicroStrategy Web 9.0.0
-
getPreserveCaseMap
protected java.util.Map getPreserveCaseMap()
Returns an instance ofMap
indicating whether the case of tag and attribute names will be preserved.- Returns:
- a
Map
. - Since:
- MicroStrategy Web 9.0.0
-
getImplClassMap
protected java.util.Map getImplClassMap()
Returns an instance ofMap
over all the tag implementation class names.- Returns:
- a
Map
over all the tag implementation class names.
-
-