Class AbstractConfigurationElement
- java.lang.Object
-
- com.microstrategy.utils.config.AbstractConfigurationElement
-
- All Implemented Interfaces:
ConfigurationElement,ConfigurationFile,java.lang.Cloneable
- Direct Known Subclasses:
AbstractConfigurationElementList,AbstractElementList,AbstractStyleCatalogElement,ActualParameterInfo,AddonInfo,AdminServer,AggregatingTaskFactoryConfig,ApplicationParameters,AppschemaDisabledSourceInfo,AreaLayerInfo,ArgumentInfo,BaseMapInfo,BeanFactory.BeanFactoryInfo,BeanFactory.BeanMappingInfo,BeanFactory.BeanPackageInfo,BeanInfo,BlockConfig,BlockLibraryConfig,BrowserSettingDefinition,ClientSideLayout,ConnectionInfo,ContentType,ContextMenuInfo,ControllerInfo,CustomThreshold,CustomThresholdBand,CustomThresholdsInfo,DBIDInfo,DBInfo,DBParamValInfo,DBPreferenceInfo,DBPreferenceItem,DBPropertiesInfo,DBTypeInfo,DBVersionInfo,DBVLDBProperty,Domain,DropZone,DropZonesResolution,ErrorInfo,ErrorInfo.ErrorMessage,ErrorInfo.ErrorTitle,ESRICloudAppInfo,ESRICloudAppKeyInfo,ESRICloudAppsInfo,ESRIJSAPIUrlInfo,ESRIOnPremiseAttributeInfo,ESRIOnPremiseMapLayerUrlInfo,ESRIOnPremiseQueryFieldInfo,ESRIProxyURL,ESRIWebMapInfo,EventArgumentInfo,EventHandlerInfo,EventHandlerInfo,EventInfo,EventMap,EventMap.EventMapArgument,ExportFormat,ExportPlaintextDelimiter,FlagInfo,FolderLink,FolderMapping,GeoRoleInfo,GeoShapeInfo,GoogleChannel,GoogleConfigurationInfo,GoogleMapKeyInfo,GraphFormatInfoHelper.Attribute,GraphFormatInfoHelper.Exception,GraphFormatInfoHelper.GraphAttribute,GraphFormatInfoHelper.GraphFormatInfo,GraphFormatInfoHelper.GraphMajorType,GraphFormatInfoHelper.GraphMinorType,GraphFormatInfoHelper.GraphObject,GraphFormatInfoHelper.IncludeType,IncludeBlock,IncludeDir,JavaScriptInfo,Macro,MapBoxConfigurationInfo,MapBoxTokenInfo,MapStyle,MapStyleJson,MessageInfoImpl,MessagesManager,MicrostrategyAttributeInfo,MultiMapConfigurationInfo,PageInfo,PageManager,PaperSizes,ParameterInfo,ParameterInfo.Description,Properties,Property,PropertyValue,ResourceFeedConfig,RibbonInfo,SectionInfo,ShapeConfigurationInfo,ShapeFileMap,ShapeKeyInfo,Shortcut,ShortcutArgument,ShortcutEvent,StaticSession,SysFolderBlackListHelper.SystemFolderNode,TaskFactoryInfo,TaskFactoryParam,TaskInfo,TaskParameterMetadataImpl,TemplateInfo,Transition,UpdateFilterInfo,Visualization,VisualizationGallery,VisualizationTemplate,VisualizationTemplateId,WebBeanInfo,WebBeanProperty,WebBeanStyle,WebGuiComponent,WebLoginProviderInfo,WhiteListCommandHelper.WhiteListCommand,WhiteListCommandHelper.WhiteListCommandInfo,Widget,WidgetProp
public abstract class AbstractConfigurationElement extends java.lang.Object implements ConfigurationElement, ConfigurationFile, java.lang.Cloneable
The AbstractConfigurationElement is the abstract class that represent a
ConfigurationElement, that is, a class that can be configured using an external file. It supports reading the definition from an XML file. It also supports loading the definition from multiple configuration sources (i.e., supports customizations).In its constructor, a subclass registers what are the valid children it may have through 2 methods:
registerElement(String nodeName, Class class): used for those nodes that can appear only once.registerElementList(String nodeName, Class class): used for those that can appear multiple times as part of a list.
By default, if the attribute was not present in the xml configuration getAttribute() returns null. If the subclass requires that an attribute has a default value other than null, it can be done by extending the
initDefaultAttributes()method and setting the attribute value there.Subclasses also need to implement the
getKeyAttributemethod to indicate the attribute that can uniquely identify this element within a list. If the Element is not intended to be used in a list, or if it uses more than one attribute as key this method should simply return null, and if necessary implement thegetKey():Objectmethod.The
AbstractConfigurationElementalso implements theConfigurationFileinterface used to load, reload, save and applyCustomizations, therefore all subclasses can be saved independently in a configuration file.- Since:
- MicroStrategy Web 9.0.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classAbstractConfigurationElement.FilteredList
-
Field Summary
Fields Modifier and Type Field Description protected static java.lang.StringATT_CONFIG_SRCprotected static java.lang.StringATT_DELETEDprotected static java.lang.StringATT_POSITIONprotected static java.lang.StringATT_PROTOTYPEstatic java.lang.StringATT_USE_DEFAULTDefines the "use-default" attribute.
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractConfigurationElement()Default constructor.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected voidaddFileSource(java.lang.String filePath, java.lang.String appPath, long lastLoaded)Adds a reference to a file from a config-source.voidapplyCustomization(CustomizationInfo c)Applies the corresponding customizations.voidapplyCustomizations()Loops through all theCustomizationInfoin theCustomizationsclass and apply the corresponding customizations.voidcleanUpDeletedElements()This method when called will delete all the child elements that are marked as deleted.java.lang.Objectclone()voiddelete(java.lang.Object key)AbstractConfigurationElementdeltas()AbstractConfigurationElementdeltas(AbstractConfigurationElement other)Returns a partial instance of this object that contains the attributes and elements required to make this object equals to theotherparamter.protected booleanequalAtts(AbstractConfigurationElement other)Returnstrueif the list of active attributes of the given AbstractConfigurationElement is equal to this list of active attributes of this AbstractConfigurationElement.protected booleanequalElements(AbstractConfigurationElement other)Returnstrueif the list of all child elements of the given AbstractConfigurationElement is equal to this list of all child-elements of this AbstractConfigurationElement.protected booleanequalNodeValues(AbstractConfigurationElement other)Returnstrueif the node value of both configuration elements is the same.booleanequals(java.lang.Object object)booleanequalsIncludingDeletedElements(java.lang.Object object)protected voidexportAttributesToXML(org.w3c.dom.Element element, ConfigurationSource source)Appends the list of attributes of thisConfigurationElementinto the given node.protected voidexportElementsToXML(org.w3c.dom.Element element, ConfigurationSource source)Appends the list of child-elements of thisConfigurationElementinto the given node.protected voidexportNodeValueToXML(org.w3c.dom.Element element, ConfigurationSource source)Appends the node value associated with the given source key into the given node.ConfigurationValuegetAttribute(java.lang.String name)Returns the value associated with the given attribute.HashListgetAttributes()Returns the list of all attributes available to this ConfigurationElement.protected booleangetBoolAttribute(java.lang.String name)Helper method, returns the value of the given attribute as boolean (true/false).protected java.lang.ObjectgetChildKey(org.w3c.dom.Node node)Returns the key that uniquely identifies the child element associated with the givenNode.java.lang.StringgetConfigSrc()Returns the value of the config-src attribute.protected java.lang.StringgetDTDFileName()Returns the name of a DTD file that will be added as SystemID to the XML resulting from serializing the contents of this ConfigurationElement into a file;nullby default.ConfigurationElementgetElement(java.lang.Object key)Returns theConfigurationElementinstance associated with the given nodeName.protected ConfigurationElementgetElement(java.lang.Object key, boolean includeDeleted)HashListgetElements()Returns the list of all child-elements available to this ConfigurationElement.FileLoadergetFileLoader()Returns the file loader instance used by this ConfigurationElement to load files from the file system.protected intgetIntAttribute(java.lang.String name)Helper method, returns the value of the given attribute as integer.protected intgetIntAttribute(java.lang.String name, int defaultValue)Helper method, returns the value of the given attribute as integer.java.lang.ObjectgetKey()Default implementation forgetKey().protected abstract java.lang.StringgetKeyAttribute()This method must return the attribute that uniquely identifies this element among its siblings; if no single attribute can be used, return null and override thegetKeyandsetKeymethods.intgetLineNumber()Returns the line number (if known) of the element in the XML file.protected AbstractConfigurationElement.FilteredListgetList(java.lang.String nodeName)Returns anImplicitListwith all the elements associated with the givennodeName.java.lang.ObjectgetNextKey()Returns an object that can be used as key for a list of child-elements that doesn't have a key by itself.java.lang.StringgetNodeName()Returns the node-name for this element.java.lang.StringgetNodeValue()Returns the node value for this element.protected java.lang.StringgetNodeValue(ConfigurationSource source)Returns the node value for this element in the given sourceKey.protected AbstractConfigurationElementgetOrCreateElement(java.lang.String nodeName, java.lang.Object key)Returns the current child instance; if null but the child is registered, it creates a new instance for it.AbstractConfigurationElementgetParent()Gets the parent for this configuration element.intgetPosition()Returns the expected position of this element.protected AbstractConfigurationElementgetPrototype()Returns the current prototype of this instance.protected java.lang.ClassgetRegisteredClass(java.lang.String nodeName)Returns theClassassociated with the givennodeName.java.lang.StringgetSelfInitPath()Returns the path to the file where this configuration element was originally loaded from.protected ConfigurationSourcegetSource(java.lang.String key)Gets theElementSourcefor the given key.java.lang.StringgetStrAttribute(java.lang.String name)Helper method, returns the value of the given attribute as a string.booleangetUseDefault()Returns the use-default value.protected ParserParametersgetXMLParserParameters(java.lang.String fileName)Returns an instance ofParserParametersused by the XML parser.protected SerializerParametersgetXMLSerializerParameters()Returns an instance ofSerializerParametersused by the XML serializer in thetoXML(org.w3c.dom.Document)By default it returnsnull.inthashCode()protected inthashCodeAtts()Returns the hashcode for attributes.protected inthashCodeElements()Returns the hashcode for attributes.protected inthashCodeNodeValues()Returns the hashcode for attributes.protected booleanhasRegisteredClass(java.lang.String nodeName)Returnstrueis there is a child registered for the givennodeName.protected voidinitAttributesFromXML(org.w3c.dom.Node root, java.lang.String sourceKey, CustomizationInfo c)Initializes the list of attributes from givenNodeprotected voidinitDefaultAttributes()This method can be overridden to set default values for attributes.protected voidinitElementFromXML(org.w3c.dom.Node child, java.lang.String sourceKey, CustomizationInfo c)Initializes a single child-element from the givenNodeprotected voidinitElementsFromXML(org.w3c.dom.Node root, java.lang.String sourceKey, CustomizationInfo c)Initializes the list of child-elements from givenNodeprotected voidinitFromFile(java.lang.String filePath, CustomizationInfo c)Initializes this configuration element by loading the contents of the givenfilePathusing the correspondingCustomizationInfo.voidinitFromResource(java.lang.String resourceName)Initializes this configuration element by loading the contents a resource that exists in the class path.voidinitFromXML(org.w3c.dom.Node root)Initialize the attributes and child elements from the values in the givenNodeprotected voidinitFromXML(org.w3c.dom.Node root, java.lang.String sourceKey, CustomizationInfo c)Initialize the attributes and child elements from the values in the givenNodeprotected voidinitNodeValueFromXML(org.w3c.dom.Node root, java.lang.String sourceKey, CustomizationInfo c)Initializes the list of child-elements from givenNodeprotected voidinitPrototype(java.lang.String protoName)Inits the prototype object of this element.booleanisActive()booleanisCustomized()booleanisDeleted()Returnstrueis this element has been mark as deleted.booleanisDirty()Returnstrueis this element or one of its children has been modified programatically after being loaded.protected booleanisInSource(java.lang.String sourceKey)Returnstrueif the element already contains anElementSourcefor the given key.protected booleanisKeyAttribute(java.lang.String name)Returnstrueis the name is that of the key attribute.voidload(java.lang.String fileName)Loads the file with the given name and initializes thisConfigurationElementwith its content.protected voidmergeChanges(java.lang.String srcKey)Removes deltas and applies them to the given source.protected AbstractConfigurationElementnewChildInstance(java.lang.String nodeName, java.lang.Class childClass)Creates a new instance of a child element for the given class.protected ConfigurationSourcenewSource(java.lang.String srcKey, CustomizationInfo c)Create a newElementSourceand adds to the list of sources of this element.AbstractConfigurationElementoriginal()Returns a new instance of this object, populated only with the out of the box values of Microstrategy Web, that is, only default values or those that came from the load method.ConfigurationElementpopulate(ConfigurationElement other)This method takes another configuration element and populates this element with the other's attributes and child-elements.protected voidprintAttributes(java.lang.StringBuffer outString)Appends the list of attributes of thisConfigurationElementinto the givenStringBuffer.protected voidprintElements(java.lang.StringBuffer outString)Appends the list of child-elements of thisConfigurationElementinto the givenStringBuffer.protected voidprintNodeValue(java.lang.StringBuffer outString)Appends the node value into the givenStringBuffer.protected voidrefreshLists()protected voidregisterClass(java.lang.String nodeName, java.lang.Class c)Registers a child class for the child with the givennodeName.protected voidregisterElement(java.lang.String nodeName, java.lang.Class c)Register a child of thisConfigurationElement.protected voidregisterElement(java.lang.String nodeName, java.lang.Class c, boolean canBeNull)Register a child of thisConfigurationElement.protected voidregisterElementList(java.lang.String nodeName, java.lang.Class c)Register a list of thisConfigurationElement.voidreload()Loops through all theElementSourceof thisConfigurationElementand reloads the content of those whose underlying configuration file has changed.protected voidreloadPrototype()Loops through all theElementSourceof thisConfigurationElementand reloads the content of those whose underlying configuration file has changed.protected voidremoveAttribute(java.lang.String name)Completely remove the value for the given attribute.protected voidremoveDefaults(CustomizationInfo c)This method is called when the use-default attribute is set false, so all previous values of attributes and children must be cleared.voidreplaceList(AbstractConfigurationElement.FilteredList list)voidrestore(java.lang.Object key)voidsave()Saves thisConfigurationElementback into the files where it was loaded from.voidsave(CustomizationInfo c)Saves deltas for thisConfigurationElementinto the given CustomizationInfo.voidsaveChangesAs(java.lang.String fileName)Saves all in-memory changes to the given file.voidsaveConfig(java.lang.String filePath)Deprecated.To save in a different location, set a custom FileLoader and use the save() method.voidsaveFlatXML(java.lang.String fileName)Saves the current element structure, in XML format, into the given file.protected voidsaveNode(org.w3c.dom.Node node, java.lang.String fileLocation)Saves an XML node into a file in the given location.protected voidsaveSource(ConfigurationSource source)Saves only the contents associated with the given source.protected voidsetAttribute(java.lang.String name, java.lang.Object value)Sets the value for the given attribute.protected voidsetBoolAttribute(java.lang.String name, boolean value)Helper method, sets the value of the given attribute from a boolean.protected voidsetChildOriginals()voidsetConfigSrc(java.lang.String path)Sets the config-src attribute.voidsetCustomized(boolean value)set if this element is a customized element or not.protected voidsetElement(java.lang.Object key, ConfigurationElement child)Allows users to add or replace an element.voidsetFileLoader(FileLoader fl)Sets theFileLoaderinstance to be used to load files.protected voidsetIntAttribute(java.lang.String name, int value)Helper method, sets the value of the given attribute from an integer.protected voidsetKey(org.w3c.dom.Element element)Default implementation forsetKey().voidsetLineNumber(int lineNumber)Sets the line number of the element in the XML file.protected voidsetNodeName(java.lang.String name)Sets the name of the node associated with this configuration element.protected voidsetNodeValue(java.lang.String value)Returns the node value for this element.voidsetPosition(int position)Sets the expected position of this element.protected voidsetPrototype(AbstractConfigurationElement prototype)Sets the prototype object for this instance.protected voidsetSelfInitPath(java.lang.String value)protected voidsetStrAttribute(java.lang.String name, java.lang.String value)Helper method, sets the value of the given attribute as a string.voidsetUseDefault(boolean useDefault)The definition of a ConfigurationElement can come come from different sources, for example, the definition can come from an external file (by specifying agetConfigSrc()value), or it can be modified through a Customization.voidsetUseValidation(boolean value)Defines whether the XML content should validated using a DTD.protected booleanthrowConfigParseException()Control whether to throw configuration parse exception DE20651: Do not throw exception for viz configurations to avoid error / empty on Main pages.java.lang.StringtoString()Generates the String representation of thisConfigurationElement.org.w3c.dom.ElementtoXML()Generates the DOM representation of thisConfigurationElement.protected org.w3c.dom.ElementtoXML(java.lang.String sourceKey)Generates the DOM representation of thisConfigurationElementfor the list of attributes and elements defined in the givenElementSource.org.w3c.dom.ElementtoXML(org.w3c.dom.Document doc)Generates the DOM representation of thisConfigurationElement.protected org.w3c.dom.ElementtoXML(org.w3c.dom.Document doc, java.lang.String sourceKey)Generates the DOM representation of thisConfigurationElementfor the list of attributes and elements defined in the givenElementSource.protected booleanuseNodeValue()Controls whether this element will use the node value as a property.booleanuseValidation()Returns whether the XML content should be validated using a DTD.
-
-
-
Field Detail
-
ATT_DELETED
protected static final java.lang.String ATT_DELETED
- See Also:
- Constant Field Values
-
ATT_CONFIG_SRC
protected static final java.lang.String ATT_CONFIG_SRC
- See Also:
- Constant Field Values
-
ATT_PROTOTYPE
protected static final java.lang.String ATT_PROTOTYPE
- See Also:
- Constant Field Values
-
ATT_USE_DEFAULT
public static final java.lang.String ATT_USE_DEFAULT
Defines the "use-default" attribute.- See Also:
setUseDefault(boolean), Constant Field Values
-
ATT_POSITION
protected static final java.lang.String ATT_POSITION
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
AbstractConfigurationElement
protected AbstractConfigurationElement()
Default constructor. CallsinitDefaultAttributes()
-
-
Method Detail
-
getNodeName
public java.lang.String getNodeName()
Description copied from interface:ConfigurationElementReturns the node-name for this element.- Specified by:
getNodeNamein interfaceConfigurationElement
-
setNodeName
protected void setNodeName(java.lang.String name)
Sets the name of the node associated with this configuration element.
-
getParent
public AbstractConfigurationElement getParent()
Gets the parent for this configuration element. Returnsnullif it's a root or if it's still not associated to any element.
-
registerElement
protected void registerElement(java.lang.String nodeName, java.lang.Class c)Register a child of thisConfigurationElement. When a child is registered with this method it is guaranteed that a non-null instance of this child is returned by thegetElement(java.lang.Object)method regardless of the child being present in the XML or not.
-
registerElement
protected void registerElement(java.lang.String nodeName, java.lang.Class c, boolean canBeNull)Register a child of thisConfigurationElement. When a node with the given name is found in the configuration file, an instance ofcis created and initialized with the corresponding configuration. It's assumed that only one child with this name is available in the configuration file; if more than one is found, the corresponding nodes are merged into a singleConfigurationElement.
The
canBeNullparameter controls whether the child instance is created by default or not. Whenfalse, thegetElement(java.lang.Object)will always return a non-null instance even if the child is not in the XML; iftruethe child instance is only created if the object is found in the XML, in this casenullchecks are necessary in your code after callinggetElementto make sure the return object is not null.
Only elements registered with this and with theregisterElementList(java.lang.String, java.lang.Class)methods are valid child nodes in the configuration file. If a child has not been registered, WARNING messages will be logged.
This method should only be called in the constructor, otherwise the clone method will fail. It can only be called if theuseNodeValue()method returns false as they are mutually exclusive: by design an element can only use children if its not using the node value.
Currently it is required that all registered child elements extendAbstractConfigurationElement. If the given classcdoesn't, this method will throw anIllegalArgumentException.- See Also:
getElement(java.lang.Object)
-
registerClass
protected void registerClass(java.lang.String nodeName, java.lang.Class c)Registers a child class for the child with the givennodeName. Used to keep track of those children than can havenullvalues.
-
hasRegisteredClass
protected boolean hasRegisteredClass(java.lang.String nodeName)
Returnstrueis there is a child registered for the givennodeName.
-
getRegisteredClass
protected java.lang.Class getRegisteredClass(java.lang.String nodeName)
Returns theClassassociated with the givennodeName.
-
registerElementList
protected void registerElementList(java.lang.String nodeName, java.lang.Class c)Register a list of thisConfigurationElement. When a node with the given name is found in the configuration file, an instance ofcis created and initialized with the corresponding configuration. If more than one subnodes are found with this name, one instance for each is created and all of them are added as child of thisConfigurationElement. The list can then be accessed through thegetList(java.lang.String)method.
Only elements registered with this and with theregisterElement(java.lang.String, java.lang.Class)methods are valid child nodes in the configuration file.
This method should only be called in the constructor, otherwise the clone method will fail. It can only be called if theuseNodeValue()method returns false as they are mutually exclusive: by design an element can only use children if its not using the node value.
Currently it is required that all registered child elements extendAbstractConfigurationElement. If the given classcdoesn't, this method will throw anIllegalArgumentException.
-
useNodeValue
protected boolean useNodeValue()
Controls whether this element will use the node value as a property. For example, nodes defined as:
can expose a property which will return the node's value (This is the node vale). When this is the case, though, the element can't have any sub elements. They're mutually exclusive.<a att="1">This is the node value</a>- Returns:
falseby default. Override this method if you want to associate the node value with some property.
-
initDefaultAttributes
protected void initDefaultAttributes()
This method can be overridden to set default values for attributes. Simply extend this method and callsetAttribute(java.lang.String, java.lang.Object)
-
getConfigSrc
public java.lang.String getConfigSrc()
Returns the value of the config-src attribute. This attribute indicates a file path where the definition of this attribute will be loaded from or saved into.
-
setConfigSrc
public void setConfigSrc(java.lang.String path)
Sets the config-src attribute. If setting it to a non-null value, the definiton of this configuration element will be saved into this location.
-
setUseDefault
public void setUseDefault(boolean useDefault)
The definition of a ConfigurationElement can come come from different sources, for example, the definition can come from an external file (by specifying agetConfigSrc()value), or it can be modified through a Customization. When theuseDefaultis set to false, values that come from previous sources are ignored and only the definition from the current source is used; this includes all attributes and child elements of this element. This is especially useful in customizations to replace the out of the box values of a node with a new definition.- Parameters:
useDefault- true/false value
-
getUseDefault
public boolean getUseDefault()
Returns the use-default value.- Returns:
- the true/false value of the useDefault flag of this Configuration Element
- See Also:
setUseDefault(boolean)
-
getPosition
public int getPosition()
Returns the expected position of this element. If the position should be automatically infered from the position found in the XML, it returns -1. This value is stored in the "position" attribute of the node. Notice that the actual position of this element might differ from this value, as the position attribute is not guaranteed to be unique or correct.
-
setPosition
public void setPosition(int position)
Sets the expected position of this element. The value is stored in the "position" attribute of the node. If when calling this method, this instance is a member of an ImplicitList, the element will automatically reposition itself in this list. Setting -1 as position indicates to automatically position this element based on its position in the XML.
-
getKey
public java.lang.Object getKey()
Default implementation forgetKey(). It assumes a single attribute can be used to uniquely identify this element among its siblings; the attribute to use is specified by thegetKeyAttribute()method.- Specified by:
getKeyin interfaceConfigurationElement- Returns:
- If
getKeyAttribute()is empty returnsnull, otherwise it returns the value of the given attribute.
-
setKey
protected void setKey(org.w3c.dom.Element element)
Default implementation forsetKey(). It assumes a single attribute can be used to uniquely identify this element among its siblings and adds this attribute to the given element; the attribute to use is specified by thegetKeyAttribute()method.
-
getKeyAttribute
protected abstract java.lang.String getKeyAttribute()
This method must return the attribute that uniquely identifies this element among its siblings; if no single attribute can be used, return null and override thegetKeyandsetKeymethods.
-
getElements
public final HashList getElements()
Description copied from interface:ConfigurationElementReturns the list of all child-elements available to this ConfigurationElement.- Specified by:
getElementsin interfaceConfigurationElement
-
getElement
public ConfigurationElement getElement(java.lang.Object key)
Returns theConfigurationElementinstance associated with the given nodeName. If theConfigurationElementwas not present in the xml configuration, this method might return an empty instance of the correspondingConfigurationElementornulldepending on thecanBeNullparameter passed to theregisterElement(java.lang.String, java.lang.Class)method. If a list is associated with the given nodeName, this method returns a list containing all theConfigurationElementinstances for that nodeName. If noConfigurationElementis associated with the given nodeName, the method returns null.- Specified by:
getElementin interfaceConfigurationElement
-
getElement
protected ConfigurationElement getElement(java.lang.Object key, boolean includeDeleted)
-
newChildInstance
protected AbstractConfigurationElement newChildInstance(java.lang.String nodeName, java.lang.Class childClass)
Creates a new instance of a child element for the given class.
-
setElement
protected void setElement(java.lang.Object key, ConfigurationElement child)Allows users to add or replace an element. If an element with the given key already exists it gets replaced, otherwise it's simply added.
-
delete
public void delete(java.lang.Object key)
-
restore
public void restore(java.lang.Object key)
-
isActive
public boolean isActive()
-
refreshLists
protected void refreshLists()
-
getList
protected AbstractConfigurationElement.FilteredList getList(java.lang.String nodeName)
Returns anImplicitListwith all the elements associated with the givennodeName. If no child was present in the xml configuration with this name, it will return an empty list. If thenodeNamehas not been registered for a list, it throws anIllegalArgumentException.
-
getAttributes
public HashList getAttributes()
Description copied from interface:ConfigurationElementReturns the list of all attributes available to this ConfigurationElement.- Specified by:
getAttributesin interfaceConfigurationElement
-
isKeyAttribute
protected boolean isKeyAttribute(java.lang.String name)
Returnstrueis the name is that of the key attribute.
-
getNodeValue
public java.lang.String getNodeValue()
Returns the node value for this element. The node value represents the inner content of the xml tag. If multipleElementSourcesare defined for this element, it returns the value of the one with greater priority.
-
getNodeValue
protected java.lang.String getNodeValue(ConfigurationSource source)
Returns the node value for this element in the given sourceKey. The node value represents the inner content of the xml tag.
If sourceKey is null, it returns the current value.
-
setNodeValue
protected void setNodeValue(java.lang.String value)
Returns the node value for this element. The node value represents the inner context of the xml tag. If multipleElementSourcesare defined for this element, it returns the value of the one with greater priority.
-
getAttribute
public final ConfigurationValue getAttribute(java.lang.String name)
Returns the value associated with the given attribute. If the attribute was not present in the xml configuration the method returns null.- Specified by:
getAttributein interfaceConfigurationElement
-
setAttribute
protected void setAttribute(java.lang.String name, java.lang.Object value)Sets the value for the given attribute.
-
removeAttribute
protected void removeAttribute(java.lang.String name)
Completely remove the value for the given attribute.
-
getStrAttribute
public java.lang.String getStrAttribute(java.lang.String name)
Helper method, returns the value of the given attribute as a string.- Specified by:
getStrAttributein interfaceConfigurationElement
-
setStrAttribute
protected void setStrAttribute(java.lang.String name, java.lang.String value)Helper method, sets the value of the given attribute as a string.
-
getIntAttribute
protected int getIntAttribute(java.lang.String name)
Helper method, returns the value of the given attribute as integer. If the attribute has no value, it returnsInteger.MIN_VALUE. If the attribute has a non-numeric value, it throws an IllegalArgumentException.
-
getIntAttribute
protected int getIntAttribute(java.lang.String name, int defaultValue)Helper method, returns the value of the given attribute as integer. If the attribute has no value, it returns thedefaultValueparameter. If the attribute has a non-numeric value, it throws an IllegalArgumentException.
-
setIntAttribute
protected void setIntAttribute(java.lang.String name, int value)Helper method, sets the value of the given attribute from an integer.
-
getBoolAttribute
protected boolean getBoolAttribute(java.lang.String name)
Helper method, returns the value of the given attribute as boolean (true/false). If the attribute has no value it returnsfalse; otherwise it returnsBoolean.valueOf(boolean).- See Also:
Boolean.valueOf(boolean)
-
setBoolAttribute
protected void setBoolAttribute(java.lang.String name, boolean value)Helper method, sets the value of the given attribute from a boolean.
-
isDeleted
public boolean isDeleted()
Returnstrueis this element has been mark as deleted.- See Also:
delete(Object)
-
isDirty
public boolean isDirty()
Returnstrueis this element or one of its children has been modified programatically after being loaded.
-
newSource
protected ConfigurationSource newSource(java.lang.String srcKey, CustomizationInfo c)
Create a newElementSourceand adds to the list of sources of this element. If there is already anElementSourcefor the given key, this method will return the same instance, but this should be avoided to prevent infinite recursive loops with the config-src attribute.
-
getSource
protected ConfigurationSource getSource(java.lang.String key)
Gets theElementSourcefor the given key. If there is noConfigurationSourcefor the given key, a new source is automatically added.
-
isInSource
protected boolean isInSource(java.lang.String sourceKey)
Returnstrueif the element already contains anElementSourcefor the given key.
-
initFromXML
public void initFromXML(org.w3c.dom.Node root)
Initialize the attributes and child elements from the values in the givenNode- Specified by:
initFromXMLin interfaceConfigurationElement- Parameters:
root- Node intance representing the configuration element properties
-
initFromXML
protected void initFromXML(org.w3c.dom.Node root, java.lang.String sourceKey, CustomizationInfo c) throws ConfigExceptionInitialize the attributes and child elements from the values in the givenNode- Parameters:
root- The DOM Node from where the information is readsourceKey- The key that identifies theElementSourcewhere the values are being readc- CustomizationInfo class where theElementSourcewas loaded from.- Throws:
ConfigException- If an error occurs while reading the definition, typically if there is a problem when reading the file pointed by the config-src attribute.
-
setChildOriginals
protected void setChildOriginals()
-
setCustomized
public void setCustomized(boolean value)
set if this element is a customized element or not. If user adds a new element it is considered a customized element and user needs to set this element as custom.- Parameters:
value-
-
isCustomized
public boolean isCustomized()
- Returns:
- true - if it is a customized element false - if it is an OOTB element
-
initPrototype
protected void initPrototype(java.lang.String protoName)
Inits the prototype object of this element. This element will inherit all the attribute and child elements from the prototype, but then any values defined through the config-src file or inline take precedence over the prototype. The name attribute represents the name of the prototype as specified in the XML. Typically this is the name of a sibling node in the xml. If name is empty, a different sibling might be used as prototype (like in the case of the PageInfo, which the page marked as isDefault is used as the default prototype). If this object already has a prototype, or if the prototype is not found in the siblings collections this methods throws an Exception.- Parameters:
protoName- Prototype name, typically the name of a sibling node in the xml.
-
setPrototype
protected void setPrototype(AbstractConfigurationElement prototype)
Sets the prototype object for this instance. The attributes and elements of the prototype are copied into this instance.
-
getPrototype
protected AbstractConfigurationElement getPrototype()
Returns the current prototype of this instance.- See Also:
initPrototype(java.lang.String)
-
removeDefaults
protected void removeDefaults(CustomizationInfo c)
This method is called when the use-default attribute is set false, so all previous values of attributes and children must be cleared.
-
initAttributesFromXML
protected void initAttributesFromXML(org.w3c.dom.Node root, java.lang.String sourceKey, CustomizationInfo c)Initializes the list of attributes from givenNode
-
initElementsFromXML
protected void initElementsFromXML(org.w3c.dom.Node root, java.lang.String sourceKey, CustomizationInfo c) throws ConfigExceptionInitializes the list of child-elements from givenNode- Throws:
ConfigException- See Also:
initFromXML(Node root, String sourceKey, CustomizationInfo c)
-
initNodeValueFromXML
protected void initNodeValueFromXML(org.w3c.dom.Node root, java.lang.String sourceKey, CustomizationInfo c) throws ConfigExceptionInitializes the list of child-elements from givenNode- Throws:
ConfigException- See Also:
initFromXML(Node root, String sourceKey, CustomizationInfo c)
-
initElementFromXML
protected void initElementFromXML(org.w3c.dom.Node child, java.lang.String sourceKey, CustomizationInfo c) throws ConfigExceptionInitializes a single child-element from the givenNode- Throws:
ConfigException
-
getLineNumber
public int getLineNumber()
Returns the line number (if known) of the element in the XML file.- Returns:
- The line number (if known). Otherwise, return -1.
-
setLineNumber
public void setLineNumber(int lineNumber)
Sets the line number of the element in the XML file.- Parameters:
lineNumber- The line number of this AbstractConfigurationElement in the XML file.
-
getOrCreateElement
protected AbstractConfigurationElement getOrCreateElement(java.lang.String nodeName, java.lang.Object key)
Returns the current child instance; if null but the child is registered, it creates a new instance for it.
-
throwConfigParseException
protected boolean throwConfigParseException()
Control whether to throw configuration parse exception DE20651: Do not throw exception for viz configurations to avoid error / empty on Main pages.
-
initFromFile
protected void initFromFile(java.lang.String filePath, CustomizationInfo c) throws ConfigExceptionInitializes this configuration element by loading the contents of the givenfilePathusing the correspondingCustomizationInfo.- Throws:
ConfigException
-
addFileSource
protected void addFileSource(java.lang.String filePath, java.lang.String appPath, long lastLoaded)Adds a reference to a file from a config-source. This file will then be automatically reloaded if changed and will be used when the save() method is called.
-
initFromResource
public void initFromResource(java.lang.String resourceName) throws ConfigExceptionInitializes this configuration element by loading the contents a resource that exists in the class path.- Throws:
ConfigException
-
getXMLParserParameters
protected ParserParameters getXMLParserParameters(java.lang.String fileName)
Returns an instance ofParserParametersused by the XML parser. By default if using validation creates a new ParserParameters instance with a SimpleErrorHandler and FileLoaderEntityResolver; otherwise it returns null;
-
getXMLSerializerParameters
protected SerializerParameters getXMLSerializerParameters()
Returns an instance ofSerializerParametersused by the XML serializer in thetoXML(org.w3c.dom.Document)By default it returnsnull. Override if the configuration element requires to pass different parameters than those used by default.
-
getDTDFileName
protected java.lang.String getDTDFileName()
Returns the name of a DTD file that will be added as SystemID to the XML resulting from serializing the contents of this ConfigurationElement into a file;nullby default. This method should be extended if the concrete instance of an element has a predefined DTD file associated.
-
setUseValidation
public void setUseValidation(boolean value)
Description copied from interface:ConfigurationFileDefines whether the XML content should validated using a DTD.- Specified by:
setUseValidationin interfaceConfigurationFile- Parameters:
value-truerequires that the XML is parsed with DTD validation on.
-
useValidation
public boolean useValidation()
Description copied from interface:ConfigurationFileReturns whether the XML content should be validated using a DTD. Iftruewhen the XML is parsed the file will be validated using the corresponding DTD (as defined in the XML itself).- Specified by:
useValidationin interfaceConfigurationFile
-
save
public void save() throws ConfigExceptionSaves thisConfigurationElementback into the files where it was loaded from. All in-memory changes are automatically applied into the lastElementSourceused to load this element.- Specified by:
savein interfaceConfigurationFile- Throws:
ConfigException
-
saveChangesAs
public void saveChangesAs(java.lang.String fileName) throws ConfigExceptionSaves all in-memory changes to the given file. If this ConfigurationElement was loaded from that file, the resulting file includes the original contents plus the changes.- Throws:
ConfigException
-
saveConfig
public final void saveConfig(java.lang.String filePath) throws ConfigExceptionDeprecated.To save in a different location, set a custom FileLoader and use the save() method.Saves this element configuration into the given filePath. Notice that this method has been deprecated: To save the configuration file into a different location it's better to create a FileLoader with the new folder path and assign it to the root element:
This makes sure all config-src are saved into their corresponding file.PageManager pm = new PageManager(); pm.load(".\\WEB-INF\\xml\\pageConfig.xml"); FileLoader fl = new FileLoader(System.getProperty("user.dir") + OUTPUT_FOLDER); //Save it in a different folder: pm.setFileLoader(fl); pm.save();- Throws:
ConfigException
-
cleanUpDeletedElements
public void cleanUpDeletedElements()
This method when called will delete all the child elements that are marked as deleted.
-
saveSource
protected void saveSource(ConfigurationSource source) throws ConfigException
Saves only the contents associated with the given source.- Throws:
ConfigException
-
saveFlatXML
public void saveFlatXML(java.lang.String fileName) throws ConfigExceptionSaves the current element structure, in XML format, into the given file.- Throws:
ConfigException
-
saveNode
protected void saveNode(org.w3c.dom.Node node, java.lang.String fileLocation) throws ConfigExceptionSaves an XML node into a file in the given location.- Parameters:
node- the xml node to savefileLocation- An absolute path for the file location- Throws:
ConfigException
-
save
public void save(CustomizationInfo c) throws ConfigException
Saves deltas for thisConfigurationElementinto the given CustomizationInfo.- Specified by:
savein interfaceConfigurationFile- Throws:
ConfigException
-
mergeChanges
protected void mergeChanges(java.lang.String srcKey)
Removes deltas and applies them to the given source.
-
getSelfInitPath
public java.lang.String getSelfInitPath()
Returns the path to the file where this configuration element was originally loaded from. It only returns a non-null value when this element was loaded using theload(java.lang.String)method, or if it was loaded from a node that had the "config-src" attribute specified.
-
setSelfInitPath
protected void setSelfInitPath(java.lang.String value)
-
toXML
public org.w3c.dom.Element toXML(org.w3c.dom.Document doc)
Generates the DOM representation of thisConfigurationElement. This method returns the list of attributes and elements merged from allElementSource. Note that the resultingElementwill not be associated with theDocumentparameter. It is important to ensure that all DOM trees have aDocumentroot as some serializers do not behave correctly otherwise. UsetoXML()if the resulting DOM is not going to be appended in another DOM structure.- Specified by:
toXMLin interfaceConfigurationElement- Parameters:
doc- factory for creating underlyingElement- Returns:
- DOM of this instance
-
toXML
public org.w3c.dom.Element toXML()
Generates the DOM representation of thisConfigurationElement. This method returns the list of attributes and elements merged from allElementSource.- Returns:
- a stand alone DOM with its own document root instance
-
toXML
protected org.w3c.dom.Element toXML(java.lang.String sourceKey)
Generates the DOM representation of thisConfigurationElementfor the list of attributes and elements defined in the givenElementSource.- Returns:
- a stand alone DOM with its own document root instance
-
toXML
protected org.w3c.dom.Element toXML(org.w3c.dom.Document doc, java.lang.String sourceKey)Generates the DOM representation of thisConfigurationElementfor the list of attributes and elements defined in the givenElementSource. Note that the resultingElementwill not be associated with theDocumentparameter. It is important to ensure that all DOM trees have aDocumentroot as some serializers do not behave correctly otherwise.
-
exportAttributesToXML
protected void exportAttributesToXML(org.w3c.dom.Element element, ConfigurationSource source)Appends the list of attributes of thisConfigurationElementinto the given node. The list is filter to include only attributes defined in the givenElementSource. IfsourceKeyisnull, it appends the list of attributes merged from allElementSources.
-
exportElementsToXML
protected void exportElementsToXML(org.w3c.dom.Element element, ConfigurationSource source)Appends the list of child-elements of thisConfigurationElementinto the given node. The list is filter to include only elements defined in the givenElementSource. IfsourceKeyisnull, it appends the list of elements merged from allElementSources.
-
exportNodeValueToXML
protected void exportNodeValueToXML(org.w3c.dom.Element element, ConfigurationSource source)Appends the node value associated with the given source key into the given node. IfsourceKeyisnull, it appends the current node value.
-
toString
public java.lang.String toString()
Generates the String representation of thisConfigurationElement.- Overrides:
toStringin classjava.lang.Object
-
printAttributes
protected void printAttributes(java.lang.StringBuffer outString)
Appends the list of attributes of thisConfigurationElementinto the givenStringBuffer. It includes the list attributes merged from allElementSources.
-
printElements
protected void printElements(java.lang.StringBuffer outString)
Appends the list of child-elements of thisConfigurationElementinto the givenStringBuffer. It appends the list of elements merged from allElementSources.
-
printNodeValue
protected void printNodeValue(java.lang.StringBuffer outString)
Appends the node value into the givenStringBuffer. It appends the node value of elements merged from allElementSources.
-
load
public void load(java.lang.String fileName) throws ConfigExceptionLoads the file with the given name and initializes thisConfigurationElementwith its content.- Specified by:
loadin interfaceConfigurationFile- Parameters:
fileName- The path to the configuration file. This path will be resolved by theFileLoader- Throws:
ConfigException
-
reload
public void reload() throws ConfigExceptionLoops through all theElementSourceof thisConfigurationElementand reloads the content of those whose underlying configuration file has changed.- Specified by:
reloadin interfaceConfigurationElement- Specified by:
reloadin interfaceConfigurationFile- Throws:
ConfigException
-
reloadPrototype
protected void reloadPrototype()
Loops through all theElementSourceof thisConfigurationElementand reloads the content of those whose underlying configuration file has changed.
-
applyCustomizations
public void applyCustomizations() throws ConfigExceptionLoops through all theCustomizationInfoin theCustomizationsclass and apply the corresponding customizations.- Specified by:
applyCustomizationsin interfaceConfigurationFile- Throws:
ConfigException
-
applyCustomization
public void applyCustomization(CustomizationInfo c) throws ConfigException
Applies the corresponding customizations.- Specified by:
applyCustomizationin interfaceConfigurationFile- Throws:
ConfigException
-
original
public final AbstractConfigurationElement original()
Returns a new instance of this object, populated only with the out of the box values of Microstrategy Web, that is, only default values or those that came from the load method. Values from customizations or programatic changes are not included.
-
deltas
public final AbstractConfigurationElement deltas()
Returns thedeltasbetween theoriginal()andthisobjects. The returned value therefore includes all changes to this object after it was loaded; this includes both programatic changes and plugins changes.- See Also:
original(),deltas()
-
deltas
public AbstractConfigurationElement deltas(AbstractConfigurationElement other)
Returns a partial instance of this object that contains the attributes and elements required to make this object equals to the
otherparamter. It is used to identify the differences between the two instances of this class.Being a partial instance, the resulting
Notice that if bothdeltaincludes strictly those attributes and elements required to make it equal to the other object; typically default attributes and elements are not included so its possible that getter methods for properties and/or chidlren will returnnull.xandyareAbstractConfigurationElement, andx != y
, thend = x.deltas(y) x + d = y
Or programatically:if (!x.equals(y)) { AbstractConfigurationElement d = x.deltas(y); x.populates(d).equals(y); //returns true }
-
clone
public java.lang.Object clone()
- Overrides:
clonein classjava.lang.Object- Returns:
- a new instance of this object with the same values.
-
equals
public boolean equals(java.lang.Object object)
- Overrides:
equalsin classjava.lang.Object
-
equalsIncludingDeletedElements
public boolean equalsIncludingDeletedElements(java.lang.Object object)
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
hashCodeAtts
protected int hashCodeAtts()
Returns the hashcode for attributes.
-
hashCodeElements
protected int hashCodeElements()
Returns the hashcode for attributes.
-
hashCodeNodeValues
protected int hashCodeNodeValues()
Returns the hashcode for attributes.
-
equalAtts
protected boolean equalAtts(AbstractConfigurationElement other)
Returnstrueif the list of active attributes of the given AbstractConfigurationElement is equal to this list of active attributes of this AbstractConfigurationElement.
-
equalElements
protected boolean equalElements(AbstractConfigurationElement other)
Returnstrueif the list of all child elements of the given AbstractConfigurationElement is equal to this list of all child-elements of this AbstractConfigurationElement.
-
equalNodeValues
protected boolean equalNodeValues(AbstractConfigurationElement other)
Returnstrueif the node value of both configuration elements is the same.
-
getFileLoader
public FileLoader getFileLoader()
Returns the file loader instance used by this ConfigurationElement to load files from the file system. IfsetFileLoader(com.microstrategy.utils.FileLoader)has not been explicitly called, this method uses the parent'sFileLoader, and if it is a root object, it uses theFileLoadersingleton, that isFileLoader.getInstance().
-
setFileLoader
public void setFileLoader(FileLoader fl)
Sets theFileLoaderinstance to be used to load files. This method is typically used to set a different root folder for relative paths. Normally, all relative paths (for example "/WEB-INF/web.xml") are relative to the application's root folder, to change this root folder users can create a new FileLoader instance and set it to this ConfigurationElement, then relative paths are resolved relative to the new FileLoader base path, for example:
In the previous sample, "/WEB-INF/xml/pageConfig.xml" is resolved toFileLoader fl = new FileLoader("C:\\Temp"); PagaManager pm = new PageManager(); pm.load("/WEB-INF/xml/pageConfig.xml", true);C:\Temp\WEB-INF\xml\pageConfig.xmlas the FileLoader's base path is "C:\Temp"
-
populate
public ConfigurationElement populate(ConfigurationElement other)
This method takes another configuration element and populates this element with the other's attributes and child-elements. Existing values are merged in this process. After this method is called, attributes and elements from the other will be available in this element.- Returns:
- this same object.
-
replaceList
public void replaceList(AbstractConfigurationElement.FilteredList list)
-
getChildKey
protected java.lang.Object getChildKey(org.w3c.dom.Node node)
Returns the key that uniquely identifies the child element associated with the givenNode.
-
getNextKey
public java.lang.Object getNextKey()
Returns an object that can be used as key for a list of child-elements that doesn't have a key by itself.
-
-