Class TagsFactory
- java.lang.Object
-
- com.microstrategy.web.tags.TagsFactory
-
public class TagsFactory extends java.lang.ObjectPrevious versions of Microstrategy Web used methods in the
HTMLHelperclass to generate HTML tags; these methods return aStringobject with the corresponding HTML for the open tag, for example,HTMLHelper.generateIMG(MarkupOutput, int, String, String)returns:
The problem is that to generate the<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 eachgenerateTAGmethod became overloaded several times for the different scenarios where the tag is used. TheTAGSinfrastructure solves this problem by creatingTagobjects responsible to generate the HTML output.Tagobjects are created using thisTagsFactory; developers can set attributes to eachTagusing 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 theTagis 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:
Using a<div class="web-link" title="Some title" onclick="alert('this');">Click to see an alert!</div>Tagobject 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.
MicroStrategyTAGSinfrastructure supports this same behavior. For example, suppose we would like to generate a list of elements using the following HTML:
Using<ol> <li>First element</li> <li>Second element</li> <li>Third element</li> </ol>
Tagobjects 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
TagImplto render any tag. This default implementing class can be overridden for a tag as can be seen in the second line where we use theAnchorWebTagto 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.StringIMPLEMENTATION_CLASS_PROPERTY_NAMEstatic java.lang.StringIS_CLOSE_TAG_REQUIRED_PROPERY_NAMEstatic java.lang.StringPRESERVE_CASEstatic java.lang.StringTAG_IMPL_PROPSstatic java.lang.StringTAGPROPERTIES_DELIMITER
-
Constructor Summary
Constructors Modifier Constructor Description protectedTagsFactory()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.MapgetCloseTagClassMap()Returns an instance ofMapover all the tag names which require an explicit close tag .protected java.util.MapgetImplClassMap()Returns an instance ofMapover all the tag implementation class names.protected java.lang.StringgetImplClassName(java.lang.String tagName)Returns the fully qualified implementation class name for the tag with the specified tag name.static TagsFactorygetInstance()Returns a singleton of the TagsFactory.protected booleangetIsCloseTagRequired(java.lang.String tagName)Returns true if the tag requires an explicit close tag.protected booleangetPreserveCase(java.lang.String tagName)Returns true if the tag requires preserving case for the tag and attribute names.protected java.util.MapgetPreserveCaseMap()Returns an instance ofMapindicating whether the case of tag and attribute names will be preserved.AnchorTagnewAnchorTag()Instantiates an emptyAnchorTag.ArgumentTagnewArgumentTag()Instantiates an emptyArgumentTag.AttrTagnewAttrTag()Instantiates an emptyAttrTag.BaseTagnewBaseTag()Instantiates an emptyBaseTag.CellTagnewCellTag()Instantiates an emptycelltag.DisplayTagnewDisplayTag()Instantiates an emptyDisplayTag.TagnewDivTag()Instantiates an emptydivtag.SelectTagnewDropDownBoxTag()Instantiates aselecttag with its attributesizedefault to1.IfTagnewIfTag()Instantiates an emptyIfTag.ImageTagnewImageTag()Instantiates animagetag with its attributeborderdefault to zero.IncludeTagnewIncludeTag()Instantiates an emptyIncludeTag.InputTagnewInputButtonTag()Instantiates ainputtag with its attributetypedefault tobutton.InputTagnewInputCheckTag()Instantiates ainputtag with its attributecheckeddefault totrue.InputTagnewInputHiddenTag()Instantiates ainputtag with its attributetypedefault tohidden.InputTagnewInputImageTag()Instantiates ainputtag with its attributetypedefault toimage, and attributeborderdefault to zero.InputTagnewInputNumberTag()Instantiates ainputtag with its attributetypedefault tonumber.InputTagnewInputRadioTag()Instantiates ainputtag with its attributetypedefault toradio.InputTagnewInputSubmitTag()Instantiates ainputtag with its attributetypedefault tosubmit.InputTagnewInputTag()Instantiates an emptyinputtag.InputTagnewInputTextTag()Instantiates ainputtag with its attributetypedefault totext.LayoutTagnewLayoutTag()Instantiates an emptyLayoutTag.ListTagnewListTag()Instantiates an emptyListTag.NextTagnewNextTag()Instantiates an emptyNextTag.TagnewOptionTag(java.lang.String value, java.lang.String content, boolean selected)RenderTagnewRenderTag()Instantiates an emptyRenderTag.ReplaceTagnewReplaceTag()Instantiates an emptyReplaceTag.RowTagnewRowTag()Instantiates an emptyrowtag.TagnewScriptTag()Instantiates ascripttag with its attributelanguagedefault tojavascript.SelectTagnewSelectTag()Instantiates an emptyselecttag.SlotTagnewSlotTag()Instantiates an emptySlotTag.TagnewSpanTag()Instantiates an emptyspantag.TableTagnewTableTag()Instantiates atabletag with its attributescellspacing,cellpaddingandcellborderdefault to zero.TagnewTag(java.lang.String name)Instantiates an emptyTagbased 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 emptyTagbased on the specified tag name. Fordiv,spanandlabeltags, 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 atabletag with its attributescellspacing,cellpaddingandcellborderdefault to zero.- Returns:
- a new table tag instance.
-
newRowTag
public RowTag newRowTag()
Instantiates an emptyrowtag.- Returns:
- a new row tag instance.
-
newCellTag
public CellTag newCellTag()
Instantiates an emptycelltag.- Returns:
- a new cell tag instance.
-
newDivTag
public Tag newDivTag()
Instantiates an emptydivtag.- Returns:
- a new div tag instance.
-
newDropDownBoxTag
public SelectTag newDropDownBoxTag()
Instantiates aselecttag with its attributesizedefault to1.- Returns:
- a new select tag instance.
-
newSelectTag
public SelectTag newSelectTag()
Instantiates an emptyselecttag.- Returns:
- a new select tag instance.
-
newSpanTag
public Tag newSpanTag()
Instantiates an emptyspantag.- Returns:
- a new span tag instance.
-
newScriptTag
public Tag newScriptTag()
Instantiates ascripttag with its attributelanguagedefault tojavascript.- Returns:
- a new script tag instance.
-
newImageTag
public ImageTag newImageTag()
Instantiates animagetag with its attributeborderdefault to zero.- Returns:
- a new image tag instance.
-
newInputTag
public InputTag newInputTag()
Instantiates an emptyinputtag.- Returns:
- a new input tag instance.
-
newInputImageTag
public InputTag newInputImageTag()
Instantiates ainputtag with its attributetypedefault toimage, and attributeborderdefault to zero.- Returns:
- a new input tag instance.
-
newInputCheckTag
public InputTag newInputCheckTag()
Instantiates ainputtag with its attributecheckeddefault totrue.- Returns:
- a new input tag instance.
-
newInputRadioTag
public InputTag newInputRadioTag()
Instantiates ainputtag with its attributetypedefault toradio.- Returns:
- a new input tag instance.
-
newInputButtonTag
public InputTag newInputButtonTag()
Instantiates ainputtag with its attributetypedefault tobutton.- Returns:
- a new input tag instance.
-
newInputSubmitTag
public InputTag newInputSubmitTag()
Instantiates ainputtag with its attributetypedefault tosubmit.- Returns:
- a new input tag instance.
-
newInputTextTag
public InputTag newInputTextTag()
Instantiates ainputtag with its attributetypedefault totext.- Returns:
- a new input tag instance.
-
newInputNumberTag
public InputTag newInputNumberTag()
Instantiates ainputtag with its attributetypedefault tonumber.- Returns:
- a new input tag instance.
-
newInputHiddenTag
public InputTag newInputHiddenTag()
Instantiates ainputtag with its attributetypedefault 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 ofMapover all the tag names which require an explicit close tag .- Returns:
- a
Mapover 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 ofMapindicating 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 ofMapover all the tag implementation class names.- Returns:
- a
Mapover all the tag implementation class names.
-
-