com.atlassian.core.util
Class XMLUtils

java.lang.Object
  extended by com.atlassian.core.util.XMLUtils

public class XMLUtils
extends Object


Nested Class Summary
static class XMLUtils.ReplacePolicy
           
static interface XMLUtils.TransformPolicy
           
 
Constructor Summary
XMLUtils()
           
 
Method Summary
static String escape(char ch)
          If there is a suitable entity reference for this character, return it.
static String escape(char ch, XMLUtils.TransformPolicy policy)
          Escape XML characters with a user specified transformation policy for invalid characters.
static String escape(String source)
          Escape an XML string using a default policy of replacing invalid XML characters.
static String escape(String source, XMLUtils.TransformPolicy policy)
          Escapes a string so it may be returned as text content or attribute value.
static String escapeForCdata(String source)
           
static String getAttributeWithDefault(Element element, String attributeName, String defaultValue)
          Get an attribute of a given element, with a default value if the attribute is not present or blank.
static String getContainedText(Node parent, String childTagName)
          With a given parent XML Element, find the text contents of the child element with supplied name.
static Element getSingleChildElement(Element el, String name)
          Given one element, get a single named child element of it.
static boolean validXml(char ch)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XMLUtils

public XMLUtils()
Method Detail

getContainedText

public static String getContainedText(Node parent,
                                      String childTagName)
With a given parent XML Element, find the text contents of the child element with supplied name.


getSingleChildElement

public static Element getSingleChildElement(Element el,
                                            String name)
Given one element, get a single named child element of it.


getAttributeWithDefault

public static String getAttributeWithDefault(Element element,
                                             String attributeName,
                                             String defaultValue)
Get an attribute of a given element, with a default value if the attribute is not present or blank.


escape

public static String escape(String source,
                            XMLUtils.TransformPolicy policy)
Escapes a string so it may be returned as text content or attribute value. Non printable characters are escaped using character references. Where the format specifies a deault entity reference, that reference is used (e.g. <).

Parameters:
source - the string to escape or "" for null.
policy - how to handle invalid XML characters
Since:
3.19 / 3.10.1

escape

public static String escape(String source)
Escape an XML string using a default policy of replacing invalid XML characters.


escapeForCdata

public static String escapeForCdata(String source)

escape

public static String escape(char ch)
If there is a suitable entity reference for this character, return it. The list of available entity references is almost but not identical between XML and HTML. This uses a default transformation policy of replacing invalid XML characters.


escape

public static String escape(char ch,
                            XMLUtils.TransformPolicy policy)
Escape XML characters with a user specified transformation policy for invalid characters.

Since:
3.19 / 3.10.1

validXml

public static boolean validXml(char ch)
Since:
3.19 / 3.10.1


Copyright © 2015 Atlassian. All rights reserved.