public class CmsSetupXmlHelper
extends java.lang.Object
For more info about xpath see:
构造器和说明 |
---|
CmsSetupXmlHelper()
Default constructor.
|
CmsSetupXmlHelper(java.lang.String basePath)
Uses an optional base file path.
|
限定符和类型 | 方法和说明 |
---|---|
void |
flush(java.lang.String xmlFilename)
Discards the changes in the given file.
|
void |
flushAll()
Discards the changes in all files.
|
static java.lang.String |
format(java.lang.String xml)
Unmarshals (reads) an XML string into a new document.
|
java.lang.String |
getBasePath()
Returns the base file Path.
|
org.dom4j.Document |
getDocument(java.lang.String xmlFilename)
Returns the document for the given filename.
|
static java.lang.String |
getValue(org.dom4j.Document document,
java.lang.String xPath)
Returns the value in the given xpath of the given xml file.
|
java.lang.String |
getValue(java.lang.String xmlFilename,
java.lang.String xPath)
Returns the value in the given xpath of the given xml file.
|
static boolean |
setAttribute(org.dom4j.Document document,
java.lang.String xPath,
java.lang.String attribute,
java.lang.String value)
Replaces a attibute's value in the given node addressed by the xPath.
|
boolean |
setAttribute(java.lang.String xmlFilename,
java.lang.String xPath,
java.lang.String attribute,
java.lang.String value)
Replaces a attibute's value in the given node addressed by the xPath.
|
static int |
setValue(org.dom4j.Document document,
java.lang.String xPath,
java.lang.String value)
Sets the given value in all nodes identified by the given xpath of the given xml file.
|
static int |
setValue(org.dom4j.Document document,
java.lang.String xPath,
java.lang.String value,
java.lang.String nodeToInsert)
Sets the given value in all nodes identified by the given xpath of the given xml file.
|
int |
setValue(java.lang.String xmlFilename,
java.lang.String xPath,
java.lang.String value)
Sets the given value in all nodes identified by the given xpath of the given xml file.
|
int |
setValue(java.lang.String xmlFilename,
java.lang.String xPath,
java.lang.String value,
java.lang.String nodeToInsert)
Sets the given value in all nodes identified by the given xpath of the given xml file.
|
void |
write(java.lang.String xmlFilename)
Writes the given file back to disk.
|
void |
writeAll()
Flushes all cached documents.
|
public CmsSetupXmlHelper()
Uses no base path.
public CmsSetupXmlHelper(java.lang.String basePath)
basePath
- the base file path to use;public static java.lang.String format(java.lang.String xml) throws CmsXmlException
xml
- the XML code to unmarshalCmsXmlException
- if something goes wrongpublic static java.lang.String getValue(org.dom4j.Document document, java.lang.String xPath)
document
- the xml documentxPath
- the xpath to read (should select a single node or attribute)null
if no matching nodepublic static boolean setAttribute(org.dom4j.Document document, java.lang.String xPath, java.lang.String attribute, java.lang.String value)
document
- the document to replace the node attributexPath
- the xPath to the nodeattribute
- the attribute to replace the value ofvalue
- the new value to settrue
if successful false
otherwisepublic static int setValue(org.dom4j.Document document, java.lang.String xPath, java.lang.String value)
If value is null
, all nodes identified by the given xpath will be deleted.
If the node identified by the given xpath does not exists, the missing nodes will be created
(if value
not null
).
document
- the xml documentxPath
- the xpath to setvalue
- the value to set (can be null
for deletion)public static int setValue(org.dom4j.Document document, java.lang.String xPath, java.lang.String value, java.lang.String nodeToInsert)
If value is null
, all nodes identified by the given xpath will be deleted.
If the node identified by the given xpath does not exists, the missing nodes will be created
(if value
not null
).
document
- the xml documentxPath
- the xpath to setvalue
- the value to set (can be null
for deletion)nodeToInsert
- optional, if given it will be inserted after xPath with the given valuepublic void flush(java.lang.String xmlFilename)
xmlFilename
- the xml config file (could be relative to the base path)public void flushAll()
public java.lang.String getBasePath()
public org.dom4j.Document getDocument(java.lang.String xmlFilename) throws CmsXmlException
It can be new read or come from the document cache.
xmlFilename
- the filename to readCmsXmlException
- if something goes wrong while readingpublic java.lang.String getValue(java.lang.String xmlFilename, java.lang.String xPath) throws CmsXmlException
xmlFilename
- the xml config file (could be relative to the base path)xPath
- the xpath to read (should select a single node or attribute)null
if no matching nodeCmsXmlException
- if something goes wrong while readingpublic boolean setAttribute(java.lang.String xmlFilename, java.lang.String xPath, java.lang.String attribute, java.lang.String value) throws CmsXmlException
xmlFilename
- the xml file name to get the document fromxPath
- the xPath to the nodeattribute
- the attribute to replace the value ofvalue
- the new value to settrue
if successful false
otherwiseCmsXmlException
- if the xml document coudn't be readpublic int setValue(java.lang.String xmlFilename, java.lang.String xPath, java.lang.String value) throws CmsXmlException
If value is null
, all nodes identified by the given xpath will be deleted.
If the node identified by the given xpath does not exists, the missing nodes will be created
(if value
not null
).
xmlFilename
- the xml config file (could be relative to the base path)xPath
- the xpath to setvalue
- the value to set (can be null
for deletion)CmsXmlException
- if something goes wrongpublic int setValue(java.lang.String xmlFilename, java.lang.String xPath, java.lang.String value, java.lang.String nodeToInsert) throws CmsXmlException
If value is null
, all nodes identified by the given xpath will be deleted.
If the node identified by the given xpath does not exists, the missing nodes will be created
(if value
not null
).
xmlFilename
- the xml config file (could be relative to the base path)xPath
- the xpath to setvalue
- the value to set (can be null
for deletion)nodeToInsert
- optional, if given it will be inserted after xPath with the given valueCmsXmlException
- if something goes wrongpublic void write(java.lang.String xmlFilename) throws CmsXmlException
xmlFilename
- the xml config file (could be relative to the base path)CmsXmlException
- if something wrong while writingpublic void writeAll() throws CmsXmlException
CmsXmlException
- if something wrong while writing