Class ParseUtils


  • public final class ParseUtils
    extends java.lang.Object
    Author:
    David M. Lloyd
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static javax.xml.stream.XMLStreamException duplicateAttribute​(javax.xml.stream.XMLStreamReader reader, java.lang.String name)
      Get an exception reporting that an attribute of a given name has already been declared in this scope.
      static javax.xml.stream.XMLStreamException duplicateNamedElement​(javax.xml.stream.XMLStreamReader reader, java.lang.String name)
      Get an exception reporting that an element of a given type and name has already been declared in this scope.
      static java.lang.String[] getListAttributeValue​(java.lang.String value)  
      static Namespace[] getNamespaceAnnotations​(java.lang.Class<?> cls)  
      static java.lang.String getWarningMessage​(java.lang.String msg, javax.xml.stream.Location location)  
      static javax.xml.stream.XMLStreamException invalidAttributeValue​(javax.xml.stream.XMLStreamReader reader, int index)
      Get an exception reporting an invalid XML attribute value.
      static boolean isNoNamespaceAttribute​(javax.xml.stream.XMLStreamReader reader, int index)  
      static javax.xml.stream.XMLStreamException missingRequired​(javax.xml.stream.XMLStreamReader reader, java.util.Set<?> required)
      Get an exception reporting a missing, required XML attribute.
      static javax.xml.stream.XMLStreamException missingRequiredElement​(javax.xml.stream.XMLStreamReader reader, java.util.Set<?> required)
      Get an exception reporting a missing, required XML child element.
      static Element nextElement​(javax.xml.stream.XMLStreamReader reader)  
      static boolean readBooleanAttributeElement​(javax.xml.stream.XMLStreamReader reader, java.lang.String attributeName)
      Read an element which contains only a single boolean attribute.
      static java.lang.String readStringAttributeElement​(javax.xml.stream.XMLStreamReader reader, java.lang.String attributeName)
      Read an element which contains only a single string attribute.
      static java.lang.String requireAttributeProperty​(javax.xml.stream.XMLStreamReader reader, int i)  
      static java.lang.String[] requireAttributes​(javax.xml.stream.XMLStreamReader reader, boolean replace, java.lang.String... attributeNames)
      Require all the named attributes, returning their values in order.
      static java.lang.String[] requireAttributes​(javax.xml.stream.XMLStreamReader reader, java.lang.Enum<?>... attributes)  
      static java.lang.String[] requireAttributes​(javax.xml.stream.XMLStreamReader reader, java.lang.String... attributeNames)  
      static void requireNoAttributes​(javax.xml.stream.XMLStreamReader reader)
      Checks that the current element has no attributes, throwing an XMLStreamException if one is found.
      static void requireNoContent​(javax.xml.stream.XMLStreamReader reader)
      Consumes the remainder of the current element, throwing an XMLStreamException if it contains any child elements.
      static void requireNoNamespaceAttribute​(javax.xml.stream.XMLStreamReader reader, int index)  
      static java.lang.String requireSingleAttribute​(javax.xml.stream.XMLStreamReader reader, java.lang.Enum<?> attribute)  
      static java.lang.String requireSingleAttribute​(javax.xml.stream.XMLStreamReader reader, java.lang.String attributeName)
      Require that the current element have only a single attribute with the given name.
      static java.lang.String resolvePath​(java.lang.String path, java.lang.String relativeTo)  
      static javax.xml.stream.XMLStreamException unexpectedAttribute​(javax.xml.stream.XMLStreamReader reader, int index)
      Get an exception reporting an unexpected XML attribute.
      static javax.xml.stream.XMLStreamException unexpectedAttribute​(javax.xml.stream.XMLStreamReader reader, java.lang.String name)
      Get an exception reporting an unexpected XML attribute.
      static javax.xml.stream.XMLStreamException unexpectedElement​(javax.xml.stream.XMLStreamReader reader)
      Get an exception reporting an unexpected XML element.
      static <T extends java.lang.Enum<T>>
      javax.xml.stream.XMLStreamException
      unexpectedElement​(javax.xml.stream.XMLStreamReader reader, T element)  
      static javax.xml.stream.XMLStreamException unexpectedEndElement​(javax.xml.stream.XMLStreamReader reader)
      Get an exception reporting an unexpected end tag for an XML element.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • nextElement

        public static Element nextElement​(javax.xml.stream.XMLStreamReader reader)
                                   throws javax.xml.stream.XMLStreamException
        Throws:
        javax.xml.stream.XMLStreamException
      • unexpectedElement

        public static javax.xml.stream.XMLStreamException unexpectedElement​(javax.xml.stream.XMLStreamReader reader)
        Get an exception reporting an unexpected XML element.
        Parameters:
        reader - the stream reader
        Returns:
        the exception
      • unexpectedElement

        public static <T extends java.lang.Enum<T>> javax.xml.stream.XMLStreamException unexpectedElement​(javax.xml.stream.XMLStreamReader reader,
                                                                                                          T element)
      • unexpectedEndElement

        public static javax.xml.stream.XMLStreamException unexpectedEndElement​(javax.xml.stream.XMLStreamReader reader)
        Get an exception reporting an unexpected end tag for an XML element.
        Parameters:
        reader - the stream reader
        Returns:
        the exception
      • unexpectedAttribute

        public static javax.xml.stream.XMLStreamException unexpectedAttribute​(javax.xml.stream.XMLStreamReader reader,
                                                                              int index)
        Get an exception reporting an unexpected XML attribute.
        Parameters:
        reader - the stream reader
        index - the attribute index
        Returns:
        the exception
      • unexpectedAttribute

        public static javax.xml.stream.XMLStreamException unexpectedAttribute​(javax.xml.stream.XMLStreamReader reader,
                                                                              java.lang.String name)
        Get an exception reporting an unexpected XML attribute.
        Parameters:
        reader - the stream reader
        name - the attribute name
        Returns:
        the exception
      • invalidAttributeValue

        public static javax.xml.stream.XMLStreamException invalidAttributeValue​(javax.xml.stream.XMLStreamReader reader,
                                                                                int index)
        Get an exception reporting an invalid XML attribute value.
        Parameters:
        reader - the stream reader
        index - the attribute index
        Returns:
        the exception
      • missingRequired

        public static javax.xml.stream.XMLStreamException missingRequired​(javax.xml.stream.XMLStreamReader reader,
                                                                          java.util.Set<?> required)
        Get an exception reporting a missing, required XML attribute.
        Parameters:
        reader - the stream reader
        required - a set of enums whose toString method returns the attribute name
        Returns:
        the exception
      • missingRequiredElement

        public static javax.xml.stream.XMLStreamException missingRequiredElement​(javax.xml.stream.XMLStreamReader reader,
                                                                                 java.util.Set<?> required)
        Get an exception reporting a missing, required XML child element.
        Parameters:
        reader - the stream reader
        required - a set of enums whose toString method returns the attribute name
        Returns:
        the exception
      • requireNoAttributes

        public static void requireNoAttributes​(javax.xml.stream.XMLStreamReader reader)
                                        throws javax.xml.stream.XMLStreamException
        Checks that the current element has no attributes, throwing an XMLStreamException if one is found.
        Parameters:
        reader - the reader
        Throws:
        javax.xml.stream.XMLStreamException - if an error occurs
      • requireNoContent

        public static void requireNoContent​(javax.xml.stream.XMLStreamReader reader)
                                     throws javax.xml.stream.XMLStreamException
        Consumes the remainder of the current element, throwing an XMLStreamException if it contains any child elements.
        Parameters:
        reader - the reader
        Throws:
        javax.xml.stream.XMLStreamException - if an error occurs
      • duplicateAttribute

        public static javax.xml.stream.XMLStreamException duplicateAttribute​(javax.xml.stream.XMLStreamReader reader,
                                                                             java.lang.String name)
        Get an exception reporting that an attribute of a given name has already been declared in this scope.
        Parameters:
        reader - the stream reader
        name - the name that was redeclared
        Returns:
        the exception
      • duplicateNamedElement

        public static javax.xml.stream.XMLStreamException duplicateNamedElement​(javax.xml.stream.XMLStreamReader reader,
                                                                                java.lang.String name)
        Get an exception reporting that an element of a given type and name has already been declared in this scope.
        Parameters:
        reader - the stream reader
        name - the name that was redeclared
        Returns:
        the exception
      • readBooleanAttributeElement

        public static boolean readBooleanAttributeElement​(javax.xml.stream.XMLStreamReader reader,
                                                          java.lang.String attributeName)
                                                   throws javax.xml.stream.XMLStreamException
        Read an element which contains only a single boolean attribute.
        Parameters:
        reader - the reader
        attributeName - the attribute name, usually "value"
        Returns:
        the boolean value
        Throws:
        javax.xml.stream.XMLStreamException - if an error occurs or if the element does not contain the specified attribute, contains other attributes, or contains child elements.
      • readStringAttributeElement

        public static java.lang.String readStringAttributeElement​(javax.xml.stream.XMLStreamReader reader,
                                                                  java.lang.String attributeName)
                                                           throws javax.xml.stream.XMLStreamException
        Read an element which contains only a single string attribute.
        Parameters:
        reader - the reader
        attributeName - the attribute name, usually "value" or "name"
        Returns:
        the string value
        Throws:
        javax.xml.stream.XMLStreamException - if an error occurs or if the element does not contain the specified attribute, contains other attributes, or contains child elements.
      • requireSingleAttribute

        public static java.lang.String requireSingleAttribute​(javax.xml.stream.XMLStreamReader reader,
                                                              java.lang.String attributeName)
                                                       throws javax.xml.stream.XMLStreamException
        Require that the current element have only a single attribute with the given name.
        Parameters:
        reader - the reader
        attributeName - the attribute name
        Throws:
        javax.xml.stream.XMLStreamException - if an error occurs
      • requireSingleAttribute

        public static java.lang.String requireSingleAttribute​(javax.xml.stream.XMLStreamReader reader,
                                                              java.lang.Enum<?> attribute)
                                                       throws javax.xml.stream.XMLStreamException
        Throws:
        javax.xml.stream.XMLStreamException
      • requireAttributes

        public static java.lang.String[] requireAttributes​(javax.xml.stream.XMLStreamReader reader,
                                                           boolean replace,
                                                           java.lang.String... attributeNames)
                                                    throws javax.xml.stream.XMLStreamException
        Require all the named attributes, returning their values in order.
        Parameters:
        reader - the reader
        attributeNames - the attribute names
        Returns:
        the attribute values in order
        Throws:
        javax.xml.stream.XMLStreamException - if an error occurs
      • requireAttributes

        public static java.lang.String[] requireAttributes​(javax.xml.stream.XMLStreamReader reader,
                                                           java.lang.String... attributeNames)
                                                    throws javax.xml.stream.XMLStreamException
        Throws:
        javax.xml.stream.XMLStreamException
      • requireAttributes

        public static java.lang.String[] requireAttributes​(javax.xml.stream.XMLStreamReader reader,
                                                           java.lang.Enum<?>... attributes)
                                                    throws javax.xml.stream.XMLStreamException
        Throws:
        javax.xml.stream.XMLStreamException
      • isNoNamespaceAttribute

        public static boolean isNoNamespaceAttribute​(javax.xml.stream.XMLStreamReader reader,
                                                     int index)
      • requireNoNamespaceAttribute

        public static void requireNoNamespaceAttribute​(javax.xml.stream.XMLStreamReader reader,
                                                       int index)
                                                throws javax.xml.stream.XMLStreamException
        Throws:
        javax.xml.stream.XMLStreamException
      • getWarningMessage

        public static java.lang.String getWarningMessage​(java.lang.String msg,
                                                         javax.xml.stream.Location location)
      • getNamespaceAnnotations

        public static Namespace[] getNamespaceAnnotations​(java.lang.Class<?> cls)
      • getListAttributeValue

        public static java.lang.String[] getListAttributeValue​(java.lang.String value)
      • resolvePath

        public static java.lang.String resolvePath​(java.lang.String path,
                                                   java.lang.String relativeTo)
      • requireAttributeProperty

        public static java.lang.String requireAttributeProperty​(javax.xml.stream.XMLStreamReader reader,
                                                                int i)
                                                         throws javax.xml.stream.XMLStreamException
        Throws:
        javax.xml.stream.XMLStreamException