|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.opencms.setup.xml.CmsSetupXmlHelper
Helper class to modify xml files.
For more info about xpath see:
Constructor Summary | |
CmsSetupXmlHelper()
Default constructor. |
|
CmsSetupXmlHelper(java.lang.String basePath)
Uses an optional base file path. |
Method Summary | |
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 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. |
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. |
void |
write(java.lang.String xmlFilename)
Writes the given file back to disk. |
void |
writeAll()
Flushes all cached documents. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public CmsSetupXmlHelper()
Uses no base path.
public CmsSetupXmlHelper(java.lang.String basePath)
basePath
- the base file path to use;Method Detail |
public static java.lang.String format(java.lang.String xml) throws CmsXmlException
xml
- the XML code to unmarshal
CmsXmlException
- 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 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 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 read
CmsXmlException
- 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 node
CmsXmlException
- if something goes wrong while readingpublic 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 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
|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |