com.ibm.commerce.pagelayout.widget.management

Class WidgetDefinitionParser

  • java.lang.Object
    • com.ibm.commerce.pagelayout.widget.management.WidgetDefinitionParser


  • public class WidgetDefinitionParser
    extends java.lang.Object
    This class parses the XML definition of the widget to extract the following information:
    • Configurable slots available in the widget. This is applicable for container widgets.
    • Pre-configured properties of the widget.
    • Widget manager class name.
    • Supported device classes.
    The XML is free-form and hence validation is not enforced on the parser. However, the parser expects the root element to be the Definition element. Under the root element, the parser by default reads the following elements:
    • slot - This element is used to define configurable slots for the widget in case is a container widget. By default, all slots can be edited. The slot element is defined as follows:
       <slot internalSlotId="bodySlot1" slotType="ReadOnly"/>
       
    • widget-property - This element is used to define the properties of the widget. A widget property can either take a single value or a list of values. For this purpose, the element can be defined with a single value as an attribute or a list of value elements whose text content is the value of the property. A property can define its data type using the type attribute. The list of supported types are all the primitive data types and string. A property can also define if it's required to have a value.
       A single value property: 
       <widget-property name="property1" required="true" type="java.lang.Integer" value="1"/>
       
       A multi value property:
       <widget-property name="property1" required="true" type="java.lang.Integer" >
              <value>1</value>
              <value>2</value>
       </widget-property>
       
    • widget-manager - The element is used to define the widget manager class. A widget can have two managers based on the execution environment. The widget manager element is optional and can be omitted if the widget does not require any special mediation during its life-cycle on a page layout.
       <widget-manager j2se="com.ibm.commerce.pagelayout.widget.manager.J2SEWidgetManager" 
       j2ee="com.ibm.commerce.pagelayout.widget.manager.J2EEWidgetManager"/>
       
    • suppported-device-class - This element is used to define the device types supported by the widget. If the element is not defined, the widget is applicable for all device types.
       <suppported-device-class>
              <value>Web</value>
       </suppported-device-class>
       
    After the parse method is invoked, the methods getWidgetPropertiesDefined and getSlotsDefined should be used to retrieve the widget properties and configurable slots respectively. The widget manager class is returned as a property in the widget properties. The property name is PageLayoutFacadeConstants.WIDGETMANAGER_PROPERTY_NAME. The supported device classes for the widget are also returned as widget property. The property name is PageLayoutFacadeConstants.SUPPORTED_DEVICE_CLASSES_PROPERTY_NAME
    • Field Summary

      Fields 
      Modifier and Type Field and Description
      static java.lang.String COPYRIGHT
      Copyright field.
      static java.lang.String DEFINITION_ELEMENT_NAME
      The tag name for the root element of the widget definition.
      static java.lang.String ID_ATTRIBUTE
      The attribute used to define the id of the element.
      static java.lang.String INTERNAL_SLOT_ID_ATTRIBUTE
      The name of the attribute used to define the internal slot ID for the slot.
      static java.lang.String NAME_ATTRIBUTE
      The attribute used to define the name of the widget property.
      static java.lang.String POSITIONAL_PROPERTY_LEFT
      The attribute name for the positional property left for slots.
      static java.lang.String POSITIONAL_PROPERTY_TOP
      The attribute name for the positional property top for slots.
      static java.lang.String POSITIONAL_PROPERTY_X
      The attribute name for the positional property x for slots.
      static java.lang.String POSITIONAL_PROPERTY_Y
      The attribute name for the positional property y for slots.
      static java.lang.String SLOT_ELEMENT_NAME
      The element name for defining the configurable slots offered by the widget.
      static java.lang.String SLOT_TYPE_ATTRIBUTE
      The name of the attribute used to define the type of slot.
      static java.lang.String SUPPORTED_DEVICE_CLASS_ELEMENT_NAME
      The element name for defining the device classes supported by the widget.If the widget supports a single device class, it can define a value attribute.
      static java.lang.String VALUE_NODE
      This tag is used to define the value for the widget property.
      static java.lang.String WIDGET_MANAGER_ELEMENT_NAME
      The tag used to define the widget's manager class name.
      static java.lang.String WIDGET_PROPERTY_ELEMENT_NAME
      The element name for defining the properties of the widget.
    • Constructor Summary

      Constructors 
      Constructor and Description
      WidgetDefinitionParser()
      Default constructor
      WidgetDefinitionParser(com.ibm.commerce.pagelayout.facade.datatypes.WidgetDefinitionType widgetDefinition)
      Constructor for the parser.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      java.lang.String getDataTypeForProperty(java.lang.String propertyName)
      This method indicates the data type of the property specified.
      java.util.Set<java.lang.String> getMandatoryWidgetProperties()
      This method returns all the widget property names that are marked mandatory.
      java.util.List<com.ibm.commerce.pagelayout.facade.datatypes.GenericSlotType> getSlotsDefined()
      Returns the slots defined in the widget's XML definition.
      java.util.List<com.ibm.commerce.pagelayout.facade.datatypes.WidgetPropertyType> getWidgetPropertiesDefined()
      Returns the list of widget properties defined for the widget.
      java.lang.Boolean isMandatoryProperty(java.lang.String propertyName)
      This method indicates if the property specified is required or not.
      java.lang.String mergeXML(java.lang.String xml1, java.lang.String xml2)
      Given 2 XML definitions, this method merges both the XML's and returns the final merged XML.
      void parse()
      This method parses the widget's XML definition to extract the configurable slots, widget properties and the widget manager class.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • COPYRIGHT

        public static final java.lang.String COPYRIGHT
        Copyright field.
        See Also:
        Constant Field Values
      • SLOT_TYPE_ATTRIBUTE

        public static final java.lang.String SLOT_TYPE_ATTRIBUTE
        The name of the attribute used to define the type of slot. It is used in the slot elements of the widget's XML definition.
        See Also:
        Constant Field Values
      • INTERNAL_SLOT_ID_ATTRIBUTE

        public static final java.lang.String INTERNAL_SLOT_ID_ATTRIBUTE
        The name of the attribute used to define the internal slot ID for the slot. It is used in the slot elements of the widget's XML definition.
        See Also:
        Constant Field Values
      • VALUE_NODE

        public static final java.lang.String VALUE_NODE
        This tag is used to define the value for the widget property. A widget property value can either be defined as an attribute (if its a single value attribute) or as value elements (if the property takes multiple values). The text content of the value node is the value of the widget property.
        See Also:
        Constant Field Values
      • NAME_ATTRIBUTE

        public static final java.lang.String NAME_ATTRIBUTE
        The attribute used to define the name of the widget property. It is used in the widget property elements of the widget's XML definition.
        See Also:
        Constant Field Values
      • ID_ATTRIBUTE

        public static final java.lang.String ID_ATTRIBUTE
        The attribute used to define the id of the element.
        See Also:
        Constant Field Values
      • WIDGET_MANAGER_ELEMENT_NAME

        public static final java.lang.String WIDGET_MANAGER_ELEMENT_NAME
        The tag used to define the widget's manager class name. The tag takes two attributes namely j2se and j2ee whose values represent the widget manager class to be used based on the execution environment.
        See Also:
        Constant Field Values
      • WIDGET_PROPERTY_ELEMENT_NAME

        public static final java.lang.String WIDGET_PROPERTY_ELEMENT_NAME
        The element name for defining the properties of the widget. A widget property element takes a name attribute. If the property takes a single value, the element can define a value attribute. If the property takes multiple values, the element can define a list of value nodes.
        See Also:
        Constant Field Values
      • SLOT_ELEMENT_NAME

        public static final java.lang.String SLOT_ELEMENT_NAME
        The element name for defining the configurable slots offered by the widget. This element accepts internalSlotId, slotType as attributes.
        See Also:
        Constant Field Values
      • SUPPORTED_DEVICE_CLASS_ELEMENT_NAME

        public static final java.lang.String SUPPORTED_DEVICE_CLASS_ELEMENT_NAME
        The element name for defining the device classes supported by the widget.If the widget supports a single device class, it can define a value attribute. If the widget supports multiple device classes, it can define a list of value nodes.
        See Also:
        Constant Field Values
      • DEFINITION_ELEMENT_NAME

        public static final java.lang.String DEFINITION_ELEMENT_NAME
        The tag name for the root element of the widget definition. The parser checks for this element to consider the XML valid.
        See Also:
        Constant Field Values
      • POSITIONAL_PROPERTY_X

        public static final java.lang.String POSITIONAL_PROPERTY_X
        The attribute name for the positional property x for slots.
        See Also:
        Constant Field Values
      • POSITIONAL_PROPERTY_Y

        public static final java.lang.String POSITIONAL_PROPERTY_Y
        The attribute name for the positional property y for slots.
        See Also:
        Constant Field Values
      • POSITIONAL_PROPERTY_TOP

        public static final java.lang.String POSITIONAL_PROPERTY_TOP
        The attribute name for the positional property top for slots.
        See Also:
        Constant Field Values
      • POSITIONAL_PROPERTY_LEFT

        public static final java.lang.String POSITIONAL_PROPERTY_LEFT
        The attribute name for the positional property left for slots.
        See Also:
        Constant Field Values
    • Constructor Detail

      • WidgetDefinitionParser

        public WidgetDefinitionParser(com.ibm.commerce.pagelayout.facade.datatypes.WidgetDefinitionType widgetDefinition)
        Constructor for the parser.
        Parameters:
        widgetDefinition - The widget whose XML definition is being parsed.
      • WidgetDefinitionParser

        public WidgetDefinitionParser()
        Default constructor
    • Method Detail

      • parse

        public void parse()
                   throws WidgetDefinitionException
        This method parses the widget's XML definition to extract the configurable slots, widget properties and the widget manager class. The method validates if the root element of the XML definition is the DEFINITION_ELEMENT_NAME before parsing.
        Throws:
        WidgetDefinitionException - When the parsing fails due malformed XML.
        See Also:
        WidgetDefinitionParser#createSlotFromElement(Element)}, WidgetDefinitionParser#createWidgetPropertyFromElement(Element)}
      • mergeXML

        public java.lang.String mergeXML(java.lang.String xml1,
                                         java.lang.String xml2)
                                  throws WidgetDefinitionException
        Given 2 XML definitions, this method merges both the XML's and returns the final merged XML. The root element of the XMLs should be The child elements of the root element in xml2 will replace any child elements in xml1 if the elements have same attribute value for attribute: id, name, internalSlotId attributes (in that order, first not-null value will be considered)
        Parameters:
        xml1 - - First XML
        xml2 - - Second XML
        Returns:
        - Final merged XML
        Throws:
        WidgetDefinitionException
      • getSlotsDefined

        public java.util.List<com.ibm.commerce.pagelayout.facade.datatypes.GenericSlotType> getSlotsDefined()
        Returns the slots defined in the widget's XML definition. This method must be invoked after the parse method.
        Returns:
        The list of slot defined in the XML. Null if no slots are defined.
      • getWidgetPropertiesDefined

        public java.util.List<com.ibm.commerce.pagelayout.facade.datatypes.WidgetPropertyType> getWidgetPropertiesDefined()
        Returns the list of widget properties defined for the widget. This method must be invoked after the parse method.
        Returns:
        The list of widget properties found in the definition XML. Null, if no properties were defined.
      • isMandatoryProperty

        public java.lang.Boolean isMandatoryProperty(java.lang.String propertyName)
        This method indicates if the property specified is required or not. This method must be invoked after the parse method.
        Parameters:
        propertyName - The name of the widget property.
        Returns:
        A boolean to indicate if the property is required. Null, if the property name does not exist.
      • getMandatoryWidgetProperties

        public java.util.Set<java.lang.String> getMandatoryWidgetProperties()
        This method returns all the widget property names that are marked mandatory. This method must be invoked after the parse method.
        Returns:
        A Set of mandatory widget properties for the widget.
      • getDataTypeForProperty

        public java.lang.String getDataTypeForProperty(java.lang.String propertyName)
        This method indicates the data type of the property specified. This method must be invoked after the parse method.
        Parameters:
        propertyName - The name of the widget property.
        Returns:
        The data of the property. Null, if the property name does not exist.