Package com.atlassian.bamboo.upgrade
Class XpathXmlUpgrader
- java.lang.Object
-
- com.atlassian.bamboo.upgrade.XpathXmlUpgrader
-
public class XpathXmlUpgrader extends Object
Helper class to perform transformation of an XML file on nodes matching given XPath expression.
-
-
Constructor Summary
Constructors Constructor Description XpathXmlUpgrader()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Optional<Document>
read(File inputFile)
Read an XML document from afile
.static Optional<Document>
read(InputStream input)
Read an XML document from aninput
stream.static void
transform(File file, String xPathExpression, Consumer<Node> transformation)
Read XML fromfile
, applytransformation
on nodes matchingxPathExpression
and write results back to the same file.static void
visit(File file, String xPathExpression, Consumer<Node> visitor)
Read XML fromfile
, performing actions on each visited node matchingxPathExpression
.static Document
visit(Document document, String xPathExpression, Consumer<Node> visitor)
Iterate over elements ofdocument
, performing actions on each visited node matchingxPathExpression
.static void
write(Document dom, File outputFile)
Write an XML document to afile
.static void
write(Document dom, OutputStream output)
Write an XML document to anoutput
stream.
-
-
-
Method Detail
-
visit
public static void visit(File file, String xPathExpression, Consumer<Node> visitor)
Read XML fromfile
, performing actions on each visited node matchingxPathExpression
. Thevisitor
should not perform transformation on acceptednodes
, as the modifications will not be persisted.- Parameters:
file
- XML file to transformxPathExpression
- nodes to be modifiedvisitor
- action to execute on each matching node- See Also:
transform(File, String, Consumer)
-
transform
public static void transform(File file, String xPathExpression, Consumer<Node> transformation)
Read XML fromfile
, applytransformation
on nodes matchingxPathExpression
and write results back to the same file. Note: transformation is performed in-place, i.e. node is not being replaced by a new one.- Parameters:
file
- XML file to transformxPathExpression
- nodes to be modifiedtransformation
- how to modify nodes- See Also:
visit(File, String, Consumer)
-
visit
public static Document visit(Document document, String xPathExpression, Consumer<Node> visitor)
Iterate over elements ofdocument
, performing actions on each visited node matchingxPathExpression
. Thevisitor
may apply in-place transformation.- Parameters:
document
- document transformxPathExpression
- nodes to be modifiedvisitor
- action to execute on each matching node
-
read
public static Optional<Document> read(File inputFile)
Read an XML document from afile
.- Parameters:
inputFile
- XML file- Returns:
- Optional<Document>
-
read
public static Optional<Document> read(InputStream input)
Read an XML document from aninput
stream.- Parameters:
input
- input stream- Returns:
- Optional<Document>
-
write
public static void write(Document dom, File outputFile)
Write an XML document to afile
.- Parameters:
dom
- documentoutputFile
- XML file
-
write
public static void write(Document dom, OutputStream output)
Write an XML document to anoutput
stream.- Parameters:
dom
- documentoutput
- output stream
-
-