Class 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 a String object with the corresponding HTML for the open tag, for example, HTMLHelper.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 Tag.setAttribute(java.lang.String, java.lang.String) method. They can change the tag's inner-content with the Tag.getContent() method, which returns a MarkupOutput. When the Tag is ready, its Tag.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>
     

    Since:
    MicroStrategy Web 8.0.0
    • Field Detail

      • 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
    • Constructor Detail

      • TagsFactory

        protected TagsFactory()
        Constructs a TagsFactory instance and reads the tag implementation classes from an external property file namely TagsFactory.properties.
    • 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 empty AnchorTag.
        Returns:
        the newly instantiated AnchorTag.
      • newTag

        public Tag newTag​(java.lang.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.
      • newTableTag

        public TableTag newTableTag()
        Instantiates a table tag with its attributes cellspacing, cellpadding and cellborder default to zero.
        Returns:
        a new table tag instance.
      • newRowTag

        public RowTag newRowTag()
        Instantiates an empty row tag.
        Returns:
        a new row tag instance.
      • newCellTag

        public CellTag newCellTag()
        Instantiates an empty cell tag.
        Returns:
        a new cell tag instance.
      • newDivTag

        public Tag newDivTag()
        Instantiates an empty div tag.
        Returns:
        a new div tag instance.
      • newDropDownBoxTag

        public SelectTag newDropDownBoxTag()
        Instantiates a select tag with its attribute size default to 1.
        Returns:
        a new select tag instance.
      • newSelectTag

        public SelectTag newSelectTag()
        Instantiates an empty select tag.
        Returns:
        a new select tag instance.
      • newSpanTag

        public Tag newSpanTag()
        Instantiates an empty span tag.
        Returns:
        a new span tag instance.
      • newScriptTag

        public Tag newScriptTag()
        Instantiates a script tag with its attribute language default to javascript.
        Returns:
        a new script tag instance.
      • newImageTag

        public ImageTag newImageTag()
        Instantiates an image tag with its attribute border default to zero.
        Returns:
        a new image tag instance.
      • newInputTag

        public InputTag newInputTag()
        Instantiates an empty input tag.
        Returns:
        a new input tag instance.
      • newInputImageTag

        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.
      • newInputCheckTag

        public InputTag newInputCheckTag()
        Instantiates a input tag with its attribute checked default to true.
        Returns:
        a new input tag instance.
      • newInputRadioTag

        public InputTag newInputRadioTag()
        Instantiates a input tag with its attribute type default to radio.
        Returns:
        a new input tag instance.
      • newInputButtonTag

        public InputTag newInputButtonTag()
        Instantiates a input tag with its attribute type default to button.
        Returns:
        a new input tag instance.
      • newInputSubmitTag

        public InputTag newInputSubmitTag()
        Instantiates a input tag with its attribute type default to submit.
        Returns:
        a new input tag instance.
      • newInputTextTag

        public InputTag newInputTextTag()
        Instantiates a input tag with its attribute type default to text.
        Returns:
        a new input tag instance.
      • newInputNumberTag

        public InputTag newInputNumberTag()
        Instantiates a input tag with its attribute type default to number.
        Returns:
        a new input tag instance.
      • newInputHiddenTag

        public InputTag newInputHiddenTag()
        Instantiates a input tag with its attribute type default to hidden.
        Returns:
        a new input tag instance.
      • newLayoutTag

        public LayoutTag newLayoutTag()
        Instantiates an empty LayoutTag.
        Returns:
        a new layout tag instance.
      • newIfTag

        public IfTag newIfTag()
        Instantiates an empty IfTag.
        Returns:
        a new if tag instance.
      • newListTag

        public ListTag newListTag()
        Instantiates an empty ListTag.
        Returns:
        a new list tag instance.
      • newNextTag

        public NextTag newNextTag()
        Instantiates an empty NextTag.
        Returns:
        a new next tag instance.
      • newRenderTag

        public RenderTag newRenderTag()
        Instantiates an empty RenderTag.
        Returns:
        a new render tag instance.
      • newDisplayTag

        public DisplayTag newDisplayTag()
        Instantiates an empty DisplayTag.
        Returns:
        a new display tag instance.
        Since:
        MicroStrategy Web 9.0.0
      • newBaseTag

        public BaseTag newBaseTag()
        Instantiates an empty BaseTag.
        Returns:
        a new base tag instance.
        Since:
        MicroStrategy Web 9.0.0
      • newArgumentTag

        public ArgumentTag newArgumentTag()
        Instantiates an empty ArgumentTag.
        Returns:
        a new argument tag instance.
      • newAttrTag

        public AttrTag newAttrTag()
        Instantiates an empty AttrTag.
        Returns:
        a new attr tag instance.
      • newIncludeTag

        public IncludeTag newIncludeTag()
        Instantiates an empty IncludeTag.
        Returns:
        a new include tag instance.
        Since:
        MicroStrategy Web 8.0.2
      • newReplaceTag

        public ReplaceTag newReplaceTag()
        Instantiates an empty ReplaceTag.
        Returns:
        a new replace tag instance.
        Since:
        MicroStrategy Web 8.0.2
      • newSlotTag

        public SlotTag newSlotTag()
        Instantiates an empty SlotTag.
        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 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 .
        Since:
        MicroStrategy Web 9.0.0
      • getPreserveCaseMap

        protected java.util.Map getPreserveCaseMap()
        Returns an instance of Map 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 of Map over all the tag implementation class names.
        Returns:
        a Map over all the tag implementation class names.