Package org.codehaus.cargo.util
Class DefaultXmlFileBuilder
- java.lang.Object
-
- org.codehaus.cargo.util.DefaultXmlFileBuilder
-
- All Implemented Interfaces:
XmlFileBuilder
public class DefaultXmlFileBuilder extends Object implements XmlFileBuilder
This implementation uses theXmlUtils
class to manipulate XML files.
-
-
Constructor Summary
Constructors Constructor Description DefaultXmlFileBuilder(FileHandler fileHandler)
creates the instance, which will use the specified @{link FileHandler fileHandler} to read or write the xml file.DefaultXmlFileBuilder(FileHandler fileHandler, boolean namespaceAware)
creates the instance, which will use the specified @{link FileHandler fileHandler} to read or write the xml file.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
insertElementsUnderXPath(String elementsToParse, String xpath)
this will parse one or more elements from elementToParse and insert them under the xpath.void
insertElementUnderXPath(Element elementToInsert, String xpath)
This will take element from elementToInsert and insert it under the xpath.Document
loadFile()
load the current xml file into a Document.void
setFile(String path)
sets the name of the file we will read and write.void
setNamespaces(Map<String,String> namespaces)
assign prefix to namespace mappings used for xpath and other xml operations.void
writeFile()
write the current xml to disk.
-
-
-
Constructor Detail
-
DefaultXmlFileBuilder
public DefaultXmlFileBuilder(FileHandler fileHandler)
creates the instance, which will use the specified @{link FileHandler fileHandler} to read or write the xml file.- Parameters:
fileHandler
- used for file i/o.
-
DefaultXmlFileBuilder
public DefaultXmlFileBuilder(FileHandler fileHandler, boolean namespaceAware)
creates the instance, which will use the specified @{link FileHandler fileHandler} to read or write the xml file.- Parameters:
fileHandler
- used for file i/o.namespaceAware
- true if builder should be namespace aware.
-
-
Method Detail
-
setFile
public void setFile(String path)
sets the name of the file we will read and write.- Specified by:
setFile
in interfaceXmlFileBuilder
- Parameters:
path
- - where the xml file will be read from or written to.
-
insertElementsUnderXPath
public void insertElementsUnderXPath(String elementsToParse, String xpath)
this will parse one or more elements from elementToParse and insert them under the xpath. note: elementsToParse may not be well formed, but only in one way. The elements may be missing a parent. Example: the following is acceptable by this method elementsToParse = <child1 /> <child2 /> xpath = //parent In this case, both elements child1 and child2 would be placed under the first match for parent. s- Specified by:
insertElementsUnderXPath
in interfaceXmlFileBuilder
- Parameters:
elementsToParse
- String containing one or more elements in textual formatxpath
- where to place the above elements.
-
insertElementUnderXPath
public void insertElementUnderXPath(Element elementToInsert, String xpath)
This will take element from elementToInsert and insert it under the xpath.- Specified by:
insertElementUnderXPath
in interfaceXmlFileBuilder
- Parameters:
elementToInsert
- Element to insertxpath
- where to place the above element.
-
loadFile
public Document loadFile()
load the current xml file into a Document.- Specified by:
loadFile
in interfaceXmlFileBuilder
- Returns:
- loaded file, represented as a Document.
-
writeFile
public void writeFile()
write the current xml to disk.- Specified by:
writeFile
in interfaceXmlFileBuilder
-
setNamespaces
public void setNamespaces(Map<String,String> namespaces)
assign prefix to namespace mappings used for xpath and other xml operations. Leave alone, or set to null, if you have no namespaces.- Specified by:
setNamespaces
in interfaceXmlFileBuilder
- Parameters:
namespaces
- - key is prefix value is url
-
-