public class

TagsFactory

extends Object
java.lang.Object
   ↳ com.microstrategy.web.tags.TagsFactory

Class Overview

Previous versions of Microstrategy Web used methods in the HTMLHelper class to generate HTML tags; these methods return a String object with the corresponding HTML for the open tag, for example, generateIMG(MarkupOutput, int, String, String) returns:

<img src="firstArgument" title="secondArgument">
The problem is that to generate the String, the method requires to know all the tag attributes (which might be different depending on the usage scenario), so each generateTAG method became overloaded several times for the different scenarios where the tag is used. The TAGS infrastructure solves this problem by creating Tag objects responsible to generate the HTML output.

Tag objects are created using this TagsFactory; developers can set attributes to each Tag using its setAttribute(String, String) method. They can change the tag's inner-content with the getContent() method, which returns a MarkupOutput. When the Tag is ready, its 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>
Using a 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.
MicroStrategy TAGS 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>
 
Using 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 the AnchorWebTag 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>
 

Summary

Constants
String IMPLEMENTATION_CLASS_PROPERTY_NAME
String IS_CLOSE_TAG_REQUIRED_PROPERY_NAME
String PRESERVE_CASE
String TAGPROPERTIES_DELIMITER
String TAG_IMPL_PROPS
Protected Constructors
TagsFactory()
Constructs a TagsFactory instance and reads the tag implementation classes from an external property file namely TagsFactory.properties.
Public Methods
synchronized static TagsFactory getInstance()
Returns a singleton of the TagsFactory.
AnchorTag newAnchorTag()
Instantiates an empty AnchorTag.
ArgumentTag newArgumentTag()
Instantiates an empty ArgumentTag.
AttrTag newAttrTag()
Instantiates an empty AttrTag.
BaseTag newBaseTag()
Instantiates an empty BaseTag.
CellTag newCellTag()
Instantiates an empty cell tag.
DisplayTag newDisplayTag()
Instantiates an empty DisplayTag.
Tag newDivTag()
Instantiates an empty div tag.
SelectTag newDropDownBoxTag()
Instantiates a select tag with its attribute size default to 1.
IfTag newIfTag()
Instantiates an empty IfTag.
ImageTag newImageTag()
Instantiates an image tag with its attribute border default to zero.
IncludeTag newIncludeTag()
Instantiates an empty IncludeTag.
InputTag newInputButtonTag()
Instantiates a input tag with its attribute type default to button.
InputTag newInputCheckTag()
Instantiates a input tag with its attribute checked default to true.
InputTag newInputHiddenTag()
Instantiates a input tag with its attribute type default to hidden.
InputTag newInputImageTag()
Instantiates a input tag with its attribute type default to image, and attribute border default to zero.
InputTag newInputRadioTag()
Instantiates a input tag with its attribute type default to radio.
InputTag newInputSubmitTag()
Instantiates a input tag with its attribute type default to submit.
InputTag newInputTag()
Instantiates an empty input tag.
InputTag newInputTextTag()
Instantiates a input tag with its attribute type default to text.
LayoutTag newLayoutTag()
Instantiates an empty LayoutTag.
ListTag newListTag()
Instantiates an empty ListTag.
NextTag newNextTag()
Instantiates an empty NextTag.
Tag newOptionTag(String value, String content, boolean selected)
RenderTag newRenderTag()
Instantiates an empty RenderTag.
ReplaceTag newReplaceTag()
Instantiates an empty ReplaceTag.
RowTag newRowTag()
Instantiates an empty row tag.
Tag newScriptTag()
Instantiates a script tag with its attribute language default to javascript.
SelectTag newSelectTag()
Instantiates an empty select tag.
SlotTag newSlotTag()
Instantiates an empty SlotTag.
Tag newSpanTag()
Instantiates an empty span tag.
TableTag newTableTag()
Instantiates a table tag with its attributes cellspacing, cellpadding and cellborder default to zero.
Tag newTag(String name)
Instantiates an empty Tag based on the specified tag name.
Protected Methods
Map getCloseTagClassMap()
Returns an instance of Map over all the tag names which require an explicit close tag .
Map getImplClassMap()
Returns an instance of Map over all the tag implementation class names.
String getImplClassName(String tagName)
Returns the fully qualified implementation class name for the tag with the specified tag name.
boolean getIsCloseTagRequired(String tagName)
Returns true if the tag requires an explicit close tag.
boolean getPreserveCase(String tagName)
Returns true if the tag requires preserving case for the tag and attribute names.
Map getPreserveCaseMap()
Returns an instance of Map indicating whether the case of tag and attribute names will be preserved.
[Expand]
Inherited Methods
From class java.lang.Object

Constants

public static final String IMPLEMENTATION_CLASS_PROPERTY_NAME

Constant Value: "impl"

public static final String IS_CLOSE_TAG_REQUIRED_PROPERY_NAME

Constant Value: "isCloseTagRqd"

public static final String PRESERVE_CASE

Constant Value: "preserveCase"

public static final String TAGPROPERTIES_DELIMITER

Constant Value: "."

public static final String TAG_IMPL_PROPS

Constant Value: "TagsFactory.properties"

Protected Constructors

protected TagsFactory ()

Constructs a TagsFactory instance and reads the tag implementation classes from an external property file namely TagsFactory.properties.

Public Methods

public static synchronized TagsFactory getInstance ()

Returns a singleton of the TagsFactory.

Returns
  • a singleton of the TagsFactory.

public AnchorTag newAnchorTag ()

Instantiates an empty AnchorTag.

Returns
  • the newly instantiated AnchorTag.

public ArgumentTag newArgumentTag ()

Instantiates an empty ArgumentTag.

Returns
  • a new argument tag instance.

public AttrTag newAttrTag ()

Instantiates an empty AttrTag.

Returns
  • a new attr tag instance.

public BaseTag newBaseTag ()

Instantiates an empty BaseTag.

Returns
  • a new base tag instance.

public CellTag newCellTag ()

Instantiates an empty cell tag.

Returns
  • a new cell tag instance.

public DisplayTag newDisplayTag ()

Instantiates an empty DisplayTag.

Returns
  • a new display tag instance.

public Tag newDivTag ()

Instantiates an empty div tag.

Returns
  • a new div tag instance.

public SelectTag newDropDownBoxTag ()

Instantiates a select tag with its attribute size default to 1.

Returns
  • a new select tag instance.

public IfTag newIfTag ()

Instantiates an empty IfTag.

Returns
  • a new if tag instance.

public ImageTag newImageTag ()

Instantiates an image tag with its attribute border default to zero.

Returns
  • a new image tag instance.

public IncludeTag newIncludeTag ()

Instantiates an empty IncludeTag.

Returns
  • a new include tag instance.

public InputTag newInputButtonTag ()

Instantiates a input tag with its attribute type default to button.

Returns
  • a new input tag instance.

public InputTag newInputCheckTag ()

Instantiates a input tag with its attribute checked default to true.

Returns
  • a new input tag instance.

public InputTag newInputHiddenTag ()

Instantiates a input tag with its attribute type default to hidden.

Returns
  • a new input tag instance.

public InputTag newInputImageTag ()

Instantiates a input tag with its attribute type default to image, and attribute border default to zero.

Returns
  • a new input tag instance.

public InputTag newInputRadioTag ()

Instantiates a input tag with its attribute type default to radio.

Returns
  • a new input tag instance.

public InputTag newInputSubmitTag ()

Instantiates a input tag with its attribute type default to submit.

Returns
  • a new input tag instance.

public InputTag newInputTag ()

Instantiates an empty input tag.

Returns
  • a new input tag instance.

public InputTag newInputTextTag ()

Instantiates a input tag with its attribute type default to text.

Returns
  • a new input tag instance.

public LayoutTag newLayoutTag ()

Instantiates an empty LayoutTag.

Returns
  • a new layout tag instance.

public ListTag newListTag ()

Instantiates an empty ListTag.

Returns
  • a new list tag instance.

public NextTag newNextTag ()

Instantiates an empty NextTag.

Returns
  • a new next tag instance.

public Tag newOptionTag (String value, String content, boolean selected)

public RenderTag newRenderTag ()

Instantiates an empty RenderTag.

Returns
  • a new render tag instance.

public ReplaceTag newReplaceTag ()

Instantiates an empty ReplaceTag.

Returns
  • a new replace tag instance.

public RowTag newRowTag ()

Instantiates an empty row tag.

Returns
  • a new row tag instance.

public Tag newScriptTag ()

Instantiates a script tag with its attribute language default to javascript.

Returns
  • a new script tag instance.

public SelectTag newSelectTag ()

Instantiates an empty select tag.

Returns
  • a new select tag instance.

public SlotTag newSlotTag ()

Instantiates an empty SlotTag.

Returns
  • a new slot tag instance.

public Tag newSpanTag ()

Instantiates an empty span tag.

Returns
  • a new span tag instance.

public TableTag newTableTag ()

Instantiates a table tag with its attributes cellspacing, cellpadding and cellborder default to zero.

Returns
  • a new table tag instance.

public Tag newTag (String name)

Instantiates an empty Tag based on the specified tag name. For div, span and label 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.

Protected Methods

protected Map getCloseTagClassMap ()

Returns an instance of Map 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 .

protected Map getImplClassMap ()

Returns an instance of Map over all the tag implementation class names.

Returns
  • a Map over all the tag implementation class names.

protected String getImplClassName (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.

protected boolean getIsCloseTagRequired (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.

protected boolean getPreserveCase (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.

protected Map getPreserveCaseMap ()

Returns an instance of Map indicating whether the case of tag and attribute names will be preserved.

Returns
  • a Map.