com.ephox.editlive.java2.config
Class ConfigItem

java.lang.Object
  extended by com.ephox.editlive.java2.config.ConfigItem

public class ConfigItem
extends Object

Represents an element in the configuration file and provides simple access to the attributes and child items.

Note that this class should not normally be instantiated directly. Instead, use the ELJBean.getConfig() method.


Constructor Summary
ConfigItem(Element configElement)
          Creates a new ConfigItem wrapping the specified element.
 
Method Summary
 ConfigItem addChildItem(String childName)
          Adds a child item to the configuration.
 boolean equals(Object obj)
          Compares for equality.
 List<ConfigItem> getAllChildItems()
          Get the list of all child ConfigItems.
 List<ConfigItem> getChildItems(String childName)
          Get the list of child ConfigItems with the specified name.
 ConfigItem getFirstChildItem(String childName)
          Gets the first child ConfigItem with the specified name.
 ConfigItem getFirstChildItemWithSetting(String childElementName, String setting, String expectedValue)
          Retrieves the first child item with the given name, that has the given value for a setting.
 String getName()
          Retrieves the name of this item.
 String getSetting(String name)
          Gets the value of an attribute for this config item.
 boolean getSettingAsBoolean(String name, boolean defaultValue)
          Retrieve the value of a setting as a boolean.
 String getSettingFromFirstChildItem(String childName, String settingName)
          A short cut to retrieve the first child item with the name childName and return a particular setting from it.
 Map<String,String> getSettings()
          Get a map containing all attribute name/value pairs for this item.
 int hashCode()
          Generates a hashCode for this object.
 void setSetting(String settingName, String settingValue)
          Sets the value of an attribute of this item.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ConfigItem

public ConfigItem(Element configElement)
Creates a new ConfigItem wrapping the specified element. This is not recommended for general use. Instead, use the ELJBean.getConfig() method.

Parameters:
configElement - the element to wrap.
Method Detail

getSetting

public String getSetting(String name)
Gets the value of an attribute for this config item.

Parameters:
name - the name of the attribute (case insensitive).
Returns:
the value of the attribute or null if no attribute with that name is defined.

getChildItems

public List<ConfigItem> getChildItems(String childName)
Get the list of child ConfigItems with the specified name. Each item in the list is a ConfigItem wrapping a child element from the configuration file.

Parameters:
childName - the name of the child elements to retrieve (case insensitive).
Returns:
a List of ConfigItem instances, representing each matching child element.

getAllChildItems

public List<ConfigItem> getAllChildItems()
Get the list of all child ConfigItems.

Each item in the list is an instance of ConfigItem, representing a child element in the configuration file. TextNodes, comments and other non-element nodes are excluded.

Returns:
the list of all child ConfigItems.

getFirstChildItem

public ConfigItem getFirstChildItem(String childName)
Gets the first child ConfigItem with the specified name.

Parameters:
childName - the name of the child element to find (case insensitive).
Returns:
the first matching ConfigItem or null if there are no child items with the specified name.

getSettings

public Map<String,String> getSettings()
Get a map containing all attribute name/value pairs for this item.

Note that the key lookup in the map is case insensitive.

Returns:
a Map between attribute name keys and the defined values.

getSettingAsBoolean

public boolean getSettingAsBoolean(String name,
                                   boolean defaultValue)
Retrieve the value of a setting as a boolean. If the attribute is not specified, defaultValue will be returned.

Parameters:
name - the name of the setting to retrieve.
defaultValue - the default value to return if the setting is not specified in the configuration file.
Returns:
the value as a boolean. The conversion to boolean is handled by Boolean.valueOf(String).

getSettingFromFirstChildItem

public String getSettingFromFirstChildItem(String childName,
                                           String settingName)
A short cut to retrieve the first child item with the name childName and return a particular setting from it. This is equivalent to getFirstChildItem(childName).getSetting(settingName) but includes appropriate checks for null.

Parameters:
childName - the name of the child item.
settingName - the name of the setting to retrieve from the child.
Returns:
the value of the setting from the child item, or null if either the child element or the setting is not present in the configuration file.

getFirstChildItemWithSetting

public ConfigItem getFirstChildItemWithSetting(String childElementName,
                                               String setting,
                                               String expectedValue)
Retrieves the first child item with the given name, that has the given value for a setting.

Parameters:
childElementName - the name of the child element to find.
setting - the setting name to check for.
expectedValue - the setting value to check for.
Returns:
the first child item with the specified setting value or null if no child item matches.

addChildItem

public ConfigItem addChildItem(String childName)
Adds a child item to the configuration. This can be used to dynamically update or modify the configuration file, however changes may not be reflected in the editor if they are made after the editor loads. To ensure the change is noticed, plugins should ensure they are set to early loading and should make any changes to the configuration immediately when instantiated.

Parameters:
childName - the name of the child item to add.
Returns:
the newly created child item.

setSetting

public void setSetting(String settingName,
                       String settingValue)
Sets the value of an attribute of this item. This can be used to dynamically update or modify the configuration file, however changes may not be reflected in the editor if they are made after the editor loads. To ensure the change is noticed, plugins should ensure they are set to early loading and should make any changes to the configuration immediately when instantiated.

Parameters:
settingName - the name of the setting to set.
settingValue - the value to set. This will replace any existing value.

getName

public String getName()
Retrieves the name of this item.

Returns:
the name of this item.

equals

public boolean equals(Object obj)
Compares for equality.

Overrides:
equals in class Object

hashCode

public int hashCode()
Generates a hashCode for this object.

Overrides:
hashCode in class Object

Copyright (c) 2005-2012 Ephox Pty Ltd. All rights reserved.