jetbrains.buildServer.util
Class XmlUtil

java.lang.Object
  extended by jetbrains.buildServer.util.XmlUtil

public class XmlUtil
extends java.lang.Object

Some XML-related utilities

Author:
kir

Field Summary
static java.lang.String PARAMETER_ELEMENT_NAME
          Name of element that is used to save parameter by writeParameter(org.jdom.Element, String, String)
 
Constructor Summary
XmlUtil()
           
 
Method Summary
static org.jdom.Element addTextChild(org.jdom.Element element, java.lang.String childName, java.lang.String childText)
           
static
<C extends java.util.Collection<java.lang.String>>
C
collectValuesByXPath(org.jdom.Element element, java.lang.String xpath, C collection)
           
static
<C extends java.util.Collection<java.lang.String>>
C
collectValuesByXPath(org.jdom.Element element, org.jdom.xpath.XPath xpath, C collection)
           
static
<C extends java.util.Collection<java.lang.String>>
C
collectValuesFromFileByXPath(java.io.File xmlFile, java.lang.String xpath, C collection)
           
static org.jdom.xpath.XPath compileXPath(java.lang.String xpath)
           
static java.lang.String formatXml(java.lang.String xmlString)
          Reformats given valid xml string with pretty formatter
static org.jdom.Element from_s(java.lang.String xmlString)
          Simple helper method to parse XML and return root JDOM element.
static org.jdom.Element getElement(org.jdom.Element element, java.lang.String xpath)
          Looks for the first element specified by the given XPath.
static boolean isSecureParameter(java.lang.String parameterName)
          Returns true if the property is secure, i.e.
static org.jdom.Element makeElement(java.lang.String name, java.lang.String... attributes)
           
static com.intellij.openapi.util.Pair<java.lang.String,java.lang.String> readParameter(org.jdom.Element paramElement)
          Reads single parameter from specified parameter element
static java.util.Map<java.lang.String,java.lang.String> readParameters(org.jdom.Element parametersElement)
           
static void saveDocument(org.jdom.Document document, java.io.OutputStream os)
           
static org.jdom.Element selectElement(org.jdom.Element element, java.lang.String xpath)
          Looks for the first element specified by the given XPath.
static org.jdom.Element selectElement(org.jdom.Element element, org.jdom.xpath.XPath xpath)
          Looks for the first element specified by the given XPath.
static java.util.List<org.jdom.Element> selectElements(org.jdom.Element element, java.lang.String xpath)
          Looks for the all elements specified by the given XPath.
static java.util.List<org.jdom.Element> selectElements(org.jdom.Element element, org.jdom.xpath.XPath xpath)
          Looks for the all elements specified by the given XPath.
static java.lang.String selectValue(org.jdom.Element element, java.lang.String xpath)
           
static java.lang.String selectValue(org.jdom.Element element, org.jdom.xpath.XPath xpath)
           
static java.lang.String to_s(org.jdom.Element el)
          Simple helper method to format JDOM element as a String
static org.jdom.Element writeParameter(org.jdom.Element parentElement, java.lang.String name, java.lang.String value)
          Write param tag under parentElement with name 'name' and value 'value' Parameter element name is PARAMETER_ELEMENT_NAME.
static void writeParameters(org.jdom.Element parentElement, java.util.Map<java.lang.String,java.lang.String> params)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PARAMETER_ELEMENT_NAME

public static final java.lang.String PARAMETER_ELEMENT_NAME
Name of element that is used to save parameter by writeParameter(org.jdom.Element, String, String)

Since:
6.0
See Also:
Constant Field Values
Constructor Detail

XmlUtil

public XmlUtil()
Method Detail

saveDocument

public static void saveDocument(org.jdom.Document document,
                                java.io.OutputStream os)
                         throws java.io.IOException
Throws:
java.io.IOException

isSecureParameter

public static boolean isSecureParameter(java.lang.String parameterName)
Returns true if the property is secure, i.e. its value should be scrambled when property persisted.

Parameters:
propertyName - property name.
Returns:
true if property value should be scrambled.

writeParameter

public static org.jdom.Element writeParameter(org.jdom.Element parentElement,
                                              java.lang.String name,
                                              java.lang.String value)
Write param tag under parentElement with name 'name' and value 'value' Parameter element name is PARAMETER_ELEMENT_NAME.

Parameters:
name - name of parameter
parentElement - parent element for param tag
value - value to be saved in param tag. If contains LF, value will be saved as CDATA
Returns:
created parameter element

readParameter

@NotNull
public static com.intellij.openapi.util.Pair<java.lang.String,java.lang.String> readParameter(@NotNull
                                                                                                      org.jdom.Element paramElement)
Reads single parameter from specified parameter element

Parameters:
paramElement - parameter element, must have name attribute
Returns:
name and value

writeParameters

public static void writeParameters(org.jdom.Element parentElement,
                                   java.util.Map<java.lang.String,java.lang.String> params)

readParameters

@NotNull
public static java.util.Map<java.lang.String,java.lang.String> readParameters(@NotNull
                                                                                      org.jdom.Element parametersElement)

to_s

public static java.lang.String to_s(org.jdom.Element el)
Simple helper method to format JDOM element as a String

Parameters:
el - element to format
Returns:
formatted XML
Since:
4.5

from_s

public static org.jdom.Element from_s(java.lang.String xmlString)
Simple helper method to parse XML and return root JDOM element. Upon any error, throws RuntimeException.

Parameters:
xmlString - XML to parse
Returns:
root JDOM element for the XML string
Since:
5.0

formatXml

@NotNull
public static java.lang.String formatXml(@NotNull
                                                 java.lang.String xmlString)
Reformats given valid xml string with pretty formatter

Parameters:
xmlString - valid xml text
Returns:
formatted xml
Since:
8.0

selectElement

@Nullable
public static org.jdom.Element selectElement(@NotNull
                                                      org.jdom.Element element,
                                                      @NotNull
                                                      org.jdom.xpath.XPath xpath)
Looks for the first element specified by the given XPath.

Parameters:
element -
xpath - XPath denoting Element (not an attribute).
Returns:
first found element, or null if not found.
Since:
8.0

selectElement

@Nullable
public static org.jdom.Element selectElement(@NotNull
                                                      org.jdom.Element element,
                                                      @NotNull
                                                      java.lang.String xpath)
Looks for the first element specified by the given XPath.

Parameters:
element -
xpath - XPath denoting Element (not an attribute).
Returns:
first found element, or null if not found.
Since:
8.0
See Also:
getElement(org.jdom.Element, String)

getElement

@NotNull
public static org.jdom.Element getElement(@NotNull
                                                  org.jdom.Element element,
                                                  @NotNull
                                                  java.lang.String xpath)
                                   throws java.util.NoSuchElementException
Looks for the first element specified by the given XPath. The element MUST exist.

Parameters:
element -
xpath - XPath denoting Element (not an attribute).
Returns:
found element. Always not null.
Throws:
java.util.NoSuchElementException - when the requested element is not found.
Since:
8.0
See Also:
selectElement(org.jdom.Element, String)

selectValue

@Nullable
public static java.lang.String selectValue(@NotNull
                                                    org.jdom.Element element,
                                                    @NotNull
                                                    java.lang.String xpath)
Since:
8.0

selectValue

@Nullable
public static java.lang.String selectValue(@NotNull
                                                    org.jdom.Element element,
                                                    @NotNull
                                                    org.jdom.xpath.XPath xpath)
Since:
8.0

selectElements

@NotNull
public static java.util.List<org.jdom.Element> selectElements(@NotNull
                                                                      org.jdom.Element element,
                                                                      @NotNull
                                                                      org.jdom.xpath.XPath xpath)
Looks for the all elements specified by the given XPath.

Parameters:
element -
xpath - XPath denoting Element (not an attribute).
Returns:
found elements in the order occurred in the given XML.
Since:
8.0

selectElements

@NotNull
public static java.util.List<org.jdom.Element> selectElements(@NotNull
                                                                      org.jdom.Element element,
                                                                      @NotNull
                                                                      java.lang.String xpath)
Looks for the all elements specified by the given XPath.

Parameters:
element -
xpath - XPath denoting Element (not an attribute).
Returns:
found elements in the order occurred in the given XML.
Since:
8.0

collectValuesFromFileByXPath

@NotNull
public static <C extends java.util.Collection<java.lang.String>> C collectValuesFromFileByXPath(@NotNull
                                                                                                        java.io.File xmlFile,
                                                                                                        @NotNull
                                                                                                        java.lang.String xpath,
                                                                                                        @NotNull
                                                                                                        C collection)
Since:
8.0

collectValuesByXPath

@NotNull
public static <C extends java.util.Collection<java.lang.String>> C collectValuesByXPath(@NotNull
                                                                                                org.jdom.Element element,
                                                                                                @NotNull
                                                                                                java.lang.String xpath,
                                                                                                @NotNull
                                                                                                C collection)
                                                                             throws org.jdom.JDOMException
Throws:
org.jdom.JDOMException
Since:
8.0

collectValuesByXPath

@NotNull
public static <C extends java.util.Collection<java.lang.String>> C collectValuesByXPath(@NotNull
                                                                                                org.jdom.Element element,
                                                                                                @NotNull
                                                                                                org.jdom.xpath.XPath xpath,
                                                                                                @NotNull
                                                                                                C collection)
                                                                             throws org.jdom.JDOMException
Throws:
org.jdom.JDOMException
Since:
8.0

compileXPath

@NotNull
public static org.jdom.xpath.XPath compileXPath(java.lang.String xpath)
Since:
8.0

addTextChild

@NotNull
public static org.jdom.Element addTextChild(@NotNull
                                                    org.jdom.Element element,
                                                    @NotNull
                                                    java.lang.String childName,
                                                    @Nullable
                                                    java.lang.String childText)

makeElement

@NotNull
public static org.jdom.Element makeElement(@NotNull
                                                   java.lang.String name,
                                                   java.lang.String... attributes)