Package edu.uiuc.ncsa.security.core.cf
Class CFXMLConfigurations
- java.lang.Object
-
- edu.uiuc.ncsa.security.core.cf.CFXMLConfigurations
-
public class CFXMLConfigurations extends Object
Utility class for processing XML configuration files. This is for managing XML nodes at a low level.
-
-
Field Summary
Fields Modifier and Type Field Description static StringCONFIGURATION_TAGTop-level tag for all configurations this system understands
-
Constructor Summary
Constructors Constructor Description CFXMLConfigurations()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Collection<LocalTime>getAlarms(Node node, String tag)Get alarms that are in a given tag.static NodegetConfig(Document cfg, String tagName, String configName)Loads the named configuration that resides under the tagName, e.g.static StringgetFirstAttribute(Node node, String name)Get the very first attribute with the given name from theNode.static booleangetFirstBooleanValue(Node node, String attrib, boolean defaultValue)static longgetFirstLongValue(Node node, String attrib, long defaultValue)Return the first long value of an attribute.static NodegetFirstNode(Node node, String name)Return the first named child configuration node of the given node or null if there is no such named child.static StringgetNodeValue(Node node, String name)Convenience method for getting the value of a single node, i.e.static StringgetNodeValue(Node node, String name, String defaultValue)Return the default value if none is found.static DocumentloadDocument(File file)This just returns theDocument.static DocumentloadDocument(InputStream inputStream)Loads tjhe given inputStream.static DocumentloadDocument(String uri)Loads a file as a resource.static voidprintDocument(Document doc, OutputStream out)Utility to print a DOM document.static StringprintNode(Node node)static NoderesolveAliases(Document cfg, String topNodeName, String configName)Given an alias, resolve it to the correct node, checking for cycles.
-
-
-
Field Detail
-
CONFIGURATION_TAG
public static final String CONFIGURATION_TAG
Top-level tag for all configurations this system understands- See Also:
- Constant Field Values
-
-
Method Detail
-
loadDocument
public static Document loadDocument(File file) throws MyConfigurationException
This just returns theDocument.- Parameters:
file-- Returns:
- Throws:
MyConfigurationException
-
loadDocument
public static Document loadDocument(String uri) throws MyConfigurationException
Loads a file as a resource. This just returns theDocument.- Parameters:
uri-- Returns:
- Throws:
MyConfigurationException
-
loadDocument
public static Document loadDocument(InputStream inputStream) throws MyConfigurationException
Loads tjhe given inputStream. The stream is closed at the end. This just returns theDocument.- Parameters:
inputStream-- Returns:
- Throws:
MyConfigurationException
-
getNodeValue
public static String getNodeValue(Node node, String name)
Convenience method for getting the value of a single node, i.e. the contents, so
<foo>value</foo>
would have name equal to 'foo' and return the string 'value'.- Parameters:
node-name-- Returns:
-
getFirstNode
public static Node getFirstNode(Node node, String name)
Return the first named child configuration node of the given node or null if there is no such named child. Very useful if your specification only allows for a single child node.- Parameters:
node-name-- Returns:
-
getFirstAttribute
public static String getFirstAttribute(Node node, String name)
Get the very first attribute with the given name from theNode. A null is returned if there is no such value.- Parameters:
node-name-- Returns:
-
getFirstBooleanValue
public static boolean getFirstBooleanValue(Node node, String attrib, boolean defaultValue)
-
getFirstLongValue
public static long getFirstLongValue(Node node, String attrib, long defaultValue)
Return the first long value of an attribute. Must have the default value specified. There is no promise as to what "first value" means thanks to the XML spec., so effectively you should restrict your XML to have at most one such value.- Parameters:
node-attrib-defaultValue-- Returns:
-
getNodeValue
public static String getNodeValue(Node node, String name, String defaultValue)
Return the default value if none is found.- Parameters:
node-name-defaultValue-- Returns:
-
getConfig
public static Node getConfig(Document cfg, String tagName, String configName)
Loads the named configuration that resides under the tagName, e.g. tagName might be 'my-server'. This supports aliases too, so if the top level tag contains an alias="x" attribute, then the configuration named "x" is loaded instead. This allows for things like a "default" or "current" configuration which need never change once deployed. The aim is to make this all as configuration driven as possible.- Parameters:
cfg-tagName-configName-- Returns:
-
resolveAliases
public static Node resolveAliases(Document cfg, String topNodeName, String configName)
Given an alias, resolve it to the correct node, checking for cycles.- Parameters:
cfg-topNodeName- The tag inside the outermost tag you want, e.g. "service", "client"configName- The name (i.e. value of name attributes)- Returns:
-
getAlarms
public static Collection<LocalTime> getAlarms(Node node, String tag)
Get alarms that are in a given tag. returns null if no alarms are set- Parameters:
node-tag-- Returns:
-
printDocument
public static void printDocument(Document doc, OutputStream out)
Utility to print a DOM document. This is really basic, just a debugging tool really.- Parameters:
doc-out-- Throws:
IOExceptionTransformerException
-
-