public class Util
extends Object
Modifier and Type | Method and Description |
---|---|
static void |
addAttribute(nu.xom.Element element,
String prefix,
String attributeName,
String namespaceURI,
String attributeValue)
Helper method to add an attribute to an element.
|
static void |
addDDMSAttribute(nu.xom.Element element,
String attributeName,
String attributeValue)
Helper method to add a ddms attribute to an element.
|
static void |
addDDMSChildElement(nu.xom.Element element,
String childName,
String childValue)
Helper method to add a ddms child element to an element.
|
static void |
addNonEmptyJsonProperty(com.google.gson.JsonObject object,
String name,
Object value)
Adds a value to a JSON object, but only if it is not empty and not null.
|
static int |
booleanHashCode(boolean b)
Returns an int value for a boolean, for use in a hashCode function.
|
static nu.xom.Attribute |
buildAttribute(String prefix,
String name,
String namespaceURI,
String value)
Convenience method to create an attribute in a namespace.
|
static nu.xom.Attribute |
buildDDMSAttribute(String name,
String value)
Convenience method to create an attribute in the default DDMS namespace.
|
static nu.xom.Element |
buildDDMSElement(String name,
String childText)
Convenience method to create an element in the default DDMS namespace with some child text.
|
static nu.xom.Element |
buildElement(String prefix,
String name,
String namespaceURI,
String childText)
Convenience method to create an element in a namespace with some child text.
|
static nu.xom.xslt.XSLTransform |
buildSchematronTransform(File schematronFile)
Takes a Schematron file and transforms it with the ISO Schematron skeleton files.
|
static nu.xom.Document |
buildXmlDocument(InputStream inputStream)
Loads a XOM object tree from an input stream.
|
static String |
capitalize(String string)
Capitalizes the first letter of a String.
|
static nu.xom.Element |
commitXml(String xml)
Attempts to convert arbitrary XML into an Element.
|
static boolean |
containsOnlyEmptyValues(List<String> list)
Checks if all of the entries in a list of Strings is empty or null.
|
static String |
decapitalize(String string)
Lowers the first letter of a String.
|
static javax.xml.datatype.DatatypeFactory |
getDataTypeFactory()
Accessor for the datatype factory, which is cached as a thread-local variable.
|
static List<String> |
getDDMSChildValues(nu.xom.Element parent,
String name)
Gets the child text of any child elements in the DDMS namespace and returns them as a list.
|
static String |
getFirstDDMSChildValue(nu.xom.Element parent,
String name)
Gets the child text of the first child element matching the name in the DDMS namespace.
|
static com.google.gson.JsonArray |
getJSONArray(List<?> values)
Converts a list of items into a JSON Array.
|
static String |
getNonNullString(String string)
Returns an empty string in place of a null one.
|
static String |
getSchematronQueryBinding(nu.xom.Document schDocument)
Locates the queryBinding attribute in an ISO Schematron file and returns it.
|
static String |
getXsList(List<?> list)
Converts a list of objects into a space-delimited xs:list, using the object's toString() implementation
|
static List<String> |
getXsListAsList(String value)
Helper method to convert an xs:NMTOKENS data type into a List of Strings.
|
static boolean |
isBounded(int testCount,
int lowBound,
int highBound)
Checks that a number is between two values, inclusive
|
static boolean |
isEmpty(String value)
Checks if a String value is empty.
|
static boolean |
listEquals(List<?> list1,
List<?> list2)
Checks if two lists of Objects are identical.
|
static boolean |
nullEquals(Object obj1,
Object obj2)
Checks object equality when the objects could possible be null.
|
static void |
requireBoundedChildCount(nu.xom.Element parent,
String childName,
int lowBound,
int highBound)
Checks that the number of child elements with the given name in the same namespace as the parent are bounded.
|
static void |
requireCompatibleVersion(IDDMSComponent parent,
IDDMSComponent child)
Validates that a child component has a compatible DDMS version as the parent.
|
static void |
requireDDMSDateFormat(String date,
String ddmsNamespace)
Asserts that a date format is one of the 5 types accepted by DDMS.
|
static void |
requireDDMSQName(nu.xom.Element element,
String localName)
Asserts that the qualified name of an element matches the expected name and a supported version of the
DDMS XML namespace
|
static void |
requireDDMSValidURI(String uri)
Checks that a string is a valid URI.
|
static void |
requireDDMSValue(String description,
Object value)
Asserts that a value required for DDMS is not null or empty.
|
static void |
requireHTMLText(OutputFormat format)
Asserts that the format is either HTML or Text.
|
static void |
requireQName(nu.xom.Element element,
String namespaceURI,
String localName)
Asserts that the qualified name of an element matches the expected name and namespace URI
|
static void |
requireValidLatitude(Double value)
Validates a latitude value
|
static void |
requireValidLongitude(Double value)
Validates a longitude value
|
static void |
requireValidNCName(String name)
Validates that a string is an NCName.
|
static void |
requireValidNCNames(List<String> names)
Validates that a list of strings contains NCNames.
|
static void |
requireValidNMToken(String name)
Validates that a string is an NMTOKEN.
|
static void |
requireValue(String description,
Object value)
Asserts that a value required, for general cases.
|
static javax.xml.datatype.XMLGregorianCalendar |
toXMLGregorianCalendar(String date)
Helper method for DDMS components that use the DDMS custom date.
|
static String |
xmlEscape(String input)
Replaces XML special characters - '&', '<', '>', '\'', '"'
|
public static javax.xml.datatype.DatatypeFactory getDataTypeFactory()
public static javax.xml.datatype.XMLGregorianCalendar toXMLGregorianCalendar(String date)
date
- the raw date stringpublic static com.google.gson.JsonArray getJSONArray(List<?> values)
values
- the valuespublic static void addNonEmptyJsonProperty(com.google.gson.JsonObject object, String name, Object value)
object
- the object to add toname
- the name of the array, if addedvalue
- the value to addpublic static String getNonNullString(String string)
string
- the string to convert, if nullpublic static List<String> getXsListAsList(String value)
The number of items returned is based on the normalization of the whitespace first. So, an xs:list defined as "a b" will return a List of 2 Strings ("a", "b"), and not a List of 4 String ("a", "", "", "b")
value
- the xs:list style String to parsepublic static String getXsList(List<?> list)
list
- the list to convertpublic static int booleanHashCode(boolean b)
b
- the booleanpublic static boolean isEmpty(String value)
value
- the value to check.public static boolean containsOnlyEmptyValues(List<String> list)
list
- the list containing stringspublic static String getFirstDDMSChildValue(nu.xom.Element parent, String name)
parent
- the parent elementname
- the name of the child elementpublic static List<String> getDDMSChildValues(nu.xom.Element parent, String name)
parent
- the parent elementname
- the name of the child elementpublic static void requireHTMLText(OutputFormat format)
format
- the output format to testIllegalArgumentException
- if the format is incorrectpublic static void requireDDMSValue(String description, Object value) throws InvalidDDMSException
description
- a descriptive name of the valuevalue
- the value to checkInvalidDDMSException
- if the value is null or emptypublic static void requireDDMSDateFormat(String date, String ddmsNamespace) throws InvalidDDMSException
date
- the date in its raw XML formatddmsNamespace
- the DDMS namespace of this date (DDM 4.0.1 and earlier only support 4 types).InvalidDDMSException
- if the value is invalid. Does nothing if value is null.public static void requireDDMSQName(nu.xom.Element element, String localName) throws InvalidDDMSException
element
- the element to checklocalName
- the local name to compare toInvalidDDMSException
- if the name is incorrectpublic static void requireQName(nu.xom.Element element, String namespaceURI, String localName) throws InvalidDDMSException
element
- the element to checknamespaceURI
- the namespace to checklocalName
- the local name to compare toIllegalArgumentException
- if the name is incorrectInvalidDDMSException
public static void requireValue(String description, Object value)
description
- a descriptive name of the valuevalue
- the value to checkIllegalArgumentException
- if the value is null or emptypublic static void requireBoundedChildCount(nu.xom.Element parent, String childName, int lowBound, int highBound) throws InvalidDDMSException
parent
- the parent elementchildName
- the local name of the childlowBound
- the lowest value the number can behighBound
- the highest value the number can beInvalidDDMSException
- if the number is out of boundspublic static void requireValidNCNames(List<String> names) throws InvalidDDMSException
names
- a list of names to checkInvalidDDMSException
- if any name is not an NCName.public static void requireCompatibleVersion(IDDMSComponent parent, IDDMSComponent child) throws InvalidDDMSException
parent
- the parent componentchild
- the child componentInvalidDDMSException
- ifpublic static void requireValidNCName(String name) throws InvalidDDMSException
name
- the name to checkInvalidDDMSException
- if the name is not an NCName.public static void requireValidNMToken(String name) throws InvalidDDMSException
name
- the name to checkInvalidDDMSException
- if the name is not an NMTOKEN.public static void requireDDMSValidURI(String uri) throws InvalidDDMSException
uri
- the string to testInvalidDDMSException
- if the string cannot be built into a URIpublic static void requireValidLongitude(Double value) throws InvalidDDMSException
value
- the value to testInvalidDDMSException
public static void requireValidLatitude(Double value) throws InvalidDDMSException
value
- the value to testInvalidDDMSException
public static boolean isBounded(int testCount, int lowBound, int highBound)
testCount
- the number to evaluatelowBound
- the lowest value the number can behighBound
- the highest value the number can beIllegalArgumentException
- if the range is invalid.public static boolean listEquals(List<?> list1, List<?> list2)
list1
- the first listlist2
- the second listIllegalArgumentException
- if one of the lists is nullpublic static boolean nullEquals(Object obj1, Object obj2)
obj1
- the first objectobj2
- the second objectpublic static String xmlEscape(String input)
input
- the string to escape.public static String capitalize(String string)
string
- the string to capitalizepublic static String decapitalize(String string)
string
- the string to changepublic static void addDDMSAttribute(nu.xom.Element element, String attributeName, String attributeValue)
element
- the element to decorateattributeName
- the name of the attribute (will be within the DDMS namespace)attributeValue
- the value of the attributepublic static void addAttribute(nu.xom.Element element, String prefix, String attributeName, String namespaceURI, String attributeValue)
element
- the element to decorateprefix
- the prefix to use (without a trailing colon)attributeName
- the name of the attributenamespaceURI
- the namespace this attribute is inattributeValue
- the value of the attributepublic static void addDDMSChildElement(nu.xom.Element element, String childName, String childValue)
element
- the element to decoratechildName
- the name of the child (will be within the DDMS namespace)childValue
- the value of the attributepublic static nu.xom.Element buildDDMSElement(String name, String childText)
name
- the local name of the elementchildText
- the text of the elementpublic static nu.xom.Element buildElement(String prefix, String name, String namespaceURI, String childText)
prefix
- the prefix to use (without a trailing colon)name
- the local name of the elementnamespaceURI
- the namespace this element is inchildText
- the text of the elementpublic static nu.xom.Attribute buildDDMSAttribute(String name, String value)
name
- the local name of the attributevalue
- the value of the attributepublic static nu.xom.Attribute buildAttribute(String prefix, String name, String namespaceURI, String value)
prefix
- the prefix to use (without a trailing colon)name
- the local name of the attributenamespaceURI
- the namespace this attribute is invalue
- the value of the attributepublic static nu.xom.Document buildXmlDocument(InputStream inputStream) throws IOException
inputStream
- the input stream containing the XML documentIOException
- if there are problems loading or parsing the input streampublic static nu.xom.Element commitXml(String xml) throws InvalidDDMSException
xml
- the XML stringInvalidDDMSException
- if the element could not be created.public static String getSchematronQueryBinding(nu.xom.Document schDocument) throws IOException
schDocument
- the Schematron file as an XML DocumentIOException
- if there are file-related problems with looking up the attributepublic static nu.xom.xslt.XSLTransform buildSchematronTransform(File schematronFile) throws IOException, nu.xom.xslt.XSLException
The XSLTransform instance using the result of the processing is returned. This XSLTransform can then be used to validate DDMS components.
schematronFile
- the Schematron fileIOException
- if there are file-related problems with preparing the stylesheetsnu.xom.xslt.XSLException
- if stylesheet transformation failsCopyright 2010 - 2019 by Brian Uri!
Generated on 09/15/2016 12:36 PM
https://ddmsence.urizone.net/