org.keycloak.saml.common.util

## Class StaxParserUtil

- java.lang.Object
- - org.keycloak.saml.common.util.StaxParserUtil

-     public class StaxParserUtil
      extends Object

  Utility for the stax based parser
  Since:
    Feb 8, 2010
  Author:
    Anil.Saldhana@redhat.com

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `StaxParserUtil()`

  - ### Method Summary

    All Methods Static Methods Concrete Methods Deprecated Methods
    Modifier and Type | Method and Description
    --- | ---
    `static XMLEvent` | `advance(XMLEventReader xmlEventReader)` Consume the next event
    `static XMLEvent` | `bypassElementBlock(XMLEventReader xmlEventReader)` Bypass an entire XML element block.
    `static void` | `bypassElementBlock(XMLEventReader xmlEventReader, QName tag)` Bypass an entire XML element block from startElement to endElement.
    `static void` | `bypassElementBlock(XMLEventReader xmlEventReader, String tag)` Bypass an entire XML element block from startElement to endElement.
    `static String` | `getAttributeValue(Attribute attribute)` Given an `Attribute`, get its trimmed value
    `static String` | `getAttributeValue(StartElement startElement, HasQName attrName)` Get the Attribute value
    `static String` | `getAttributeValue(StartElement startElement, QName attrQName)` Get the Attribute value
    `static String` | `getAttributeValue(StartElement startElement, String tag)` Deprecated.
    `static String` | `getAttributeValueRP(Attribute attribute)` Given an `Attribute`, get its trimmed value, replacing every occurrence of ${..} by corresponding system property value
    `static String` | `getAttributeValueRP(StartElement startElement, HasQName attrName)` Get the Attribute value, replacing every occurrence of ${..} by corresponding system property value
    `static Boolean` | `getBooleanAttributeValue(StartElement startElement, HasQName attrName)` Get the Attribute value
    `static boolean` | `getBooleanAttributeValue(StartElement startElement, String tag)` Deprecated.
    `static boolean` | `getBooleanAttributeValue(StartElement startElement, String tag, boolean defaultValue)` Deprecated.
    `static Boolean` | `getBooleanAttributeValueRP(StartElement startElement, HasQName attrName)` Get the Attribute value, replacing every occurrence of ${..} by corresponding system property value
    `static Element` | `getDOMElement(XMLEventReader xmlEventReader)` Given that the `XMLEventReader` is in `XMLStreamConstants.START_ELEMENT` mode, we parse into a DOM Element
    `static String` | `getElementName(EndElement endElement)` Return the name of the end element
    `static String` | `getElementName(StartElement startElement)` Return the name of the start element
    `static String` | `getElementText(XMLEventReader xmlEventReader)` Get the element text.
    `static String` | `getElementTextRP(XMLEventReader xmlEventReader)` Get the element text, replacing every occurrence of ${..} by corresponding system property value
    `static Integer` | `getIntegerAttributeValue(StartElement startElement, HasQName attrName)` Get the Attribute value
    `static Integer` | `getIntegerAttributeValueRP(StartElement startElement, HasQName attrName)` Get the Attribute value, replacing every occurrence of ${..} by corresponding system property value
    `static String` | `getLineColumnNumber(Location location)` Given a `Location`, return a formatted string [lineNum,colNum]
    `static Long` | `getLongAttributeValue(StartElement startElement, HasQName attrName)` Get the Attribute value
    `static Long` | `getLongAttributeValueRP(StartElement startElement, HasQName attrName)` Get the Attribute value
    `static EndElement` | `getNextEndElement(XMLEventReader xmlEventReader)` Get the next `EndElement`
    `static XMLEvent` | `getNextEvent(XMLEventReader xmlEventReader)` Get the next xml event
    `static StartElement` | `getNextStartElement(XMLEventReader xmlEventReader)` Get the next `StartElement`
    `static String` | `getRequiredAttributeValue(StartElement startElement, HasQName attrName)`
    `static String` | `getRequiredAttributeValueRP(StartElement startElement, HasQName attrName)`
    `static List<String>` | `getRequiredStringListAttributeValue(StartElement startElement, HasQName attrName)` Parse a space delimited list of strings
    `static URI` | `getUriAttributeValue(StartElement startElement, HasQName attrName)` Get the Attribute value
    `static Duration` | `getXmlDurationAttributeValue(StartElement startElement, HasQName attrName)` Get the Attribute value
    `static XMLEventReader` | `getXMLEventReader(InputStream is)` Get the XML event reader
    `static XMLEventReader` | `getXMLEventReader(Source source)` Get the XML event reader
    `static XMLGregorianCalendar` | `getXmlTimeAttributeValue(StartElement startElement, HasQName attrName)` Get the Attribute value
    `static String` | `getXSITypeValue(StartElement startElement)` Given a start element, obtain the xsi:type defined
    `static boolean` | `hasTextAhead(XMLEventReader xmlEventReader)` Return whether the next event is going to be text
    `static boolean` | `matches(EndElement endElement, String tag)` Match that the end element with the expected tag
    `static boolean` | `matches(StartElement startElement, String tag)` Match that the start element with the expected tag
    `static XMLEvent` | `peek(XMLEventReader xmlEventReader)` Peek at the next event
    `static EndElement` | `peekNextEndElement(XMLEventReader xmlEventReader)` Peek the next `EndElement`
    `static StartElement` | `peekNextStartElement(XMLEventReader xmlEventReader)` Peek the next `StartElement`
    `static XMLEvent` | `peekNextTag(XMLEventReader xmlEventReader)` Peek the next `StartElement` or `EndElement`.
    `static String` | `trim(String str)` Given a string, trim it
    `static void` | `validate(EndElement endElement, String tag)` Validate that the end element has the expected tag
    `static void` | `validate(InputStream doc, InputStream sch)`
    `static void` | `validate(StartElement startElement, QName tag)` Validate that the start element has the expected tag
    `static void` | `validate(StartElement startElement, String tag)` Deprecated.
    `static boolean` | `wasWhitespacePeeked(XMLEventReader xmlEventReader, XMLEvent xmlEvent)` Advances reader if character whitespace encountered

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### StaxParserUtil

          public StaxParserUtil()

  - ### Method Detail

    - #### validate

          public static void validate(InputStream doc,
                                      InputStream sch)
                               throws ParsingException

      Throws:
        `ParsingException`

    - #### bypassElementBlock

          public static void bypassElementBlock(XMLEventReader xmlEventReader,
                                                String tag)
                                         throws ParsingException

      Bypass an entire XML element block from startElement to endElement. It is expected that the `xmlEventReader` is positioned at (has not yet read) the start element of the block it should bypass.
      Parameters:
        `xmlEventReader` -
        `tag` - Tag of the XML element that we need to bypass
      Throws:
        `ParsingException`

    - #### bypassElementBlock

          public static void bypassElementBlock(XMLEventReader xmlEventReader,
                                                QName tag)
                                         throws ParsingException

      Bypass an entire XML element block from startElement to endElement. It is expected that the `xmlEventReader` is positioned at (has not yet read) the start element of the block it should bypass.
      Parameters:
        `xmlEventReader` -
        `tag` - Tag of the XML element that we need to bypass
      Throws:
        `ParsingException`

    - #### bypassElementBlock

          public static XMLEvent bypassElementBlock(XMLEventReader xmlEventReader)
                                             throws ParsingException

      Bypass an entire XML element block. It is expected that the `xmlEventReader` is positioned at (has not yet read) the start element of the block it should bypass.
      Parameters:
        `xmlEventReader` -
      Throws:
        `ParsingException`

    - #### wasWhitespacePeeked

          public static boolean wasWhitespacePeeked(XMLEventReader xmlEventReader,
                                                    XMLEvent xmlEvent)

      Advances reader if character whitespace encountered
      Parameters:
        `xmlEventReader` -
        `xmlEvent` -
      Returns:

    - #### getAttributeValue

          public static String getAttributeValue(Attribute attribute)

      Given an `Attribute`, get its trimmed value
      Parameters:
        `attribute` -
      Returns:

    - #### getAttributeValueRP

          public static String getAttributeValueRP(Attribute attribute)

      Given an `Attribute`, get its trimmed value, replacing every occurrence of ${..} by corresponding system property value
      Parameters:
        `attribute` -
      Returns:

    - #### getAttributeValue

          @Deprecated
          public static String getAttributeValue(StartElement startElement,
                                                             String tag)

      Deprecated.
      Get the Attribute value
      Parameters:
        `startElement` -
        `tag` - localpart of the qname of the attribute
      Returns:

    - #### getAttributeValue

          public static String getAttributeValue(StartElement startElement,
                                                 HasQName attrName)

      Get the Attribute value
      Parameters:
        `startElement` -
        `tag` - localpart of the qname of the attribute
      Returns:

    - #### getAttributeValueRP

          public static String getAttributeValueRP(StartElement startElement,
                                                   HasQName attrName)

      Get the Attribute value, replacing every occurrence of ${..} by corresponding system property value
      Parameters:
        `startElement` -
        `tag` - localpart of the qname of the attribute
      Returns:
      See Also:
        `StringPropertyReplacer.replaceProperties(java.lang.String)`

    - #### getAttributeValue

          public static String getAttributeValue(StartElement startElement,
                                                 QName attrQName)

      Get the Attribute value
      Parameters:
        `startElement` -
        `tag` - localpart of the qname of the attribute
      Returns:

    - #### getUriAttributeValue

          public static URI getUriAttributeValue(StartElement startElement,
                                                 HasQName attrName)

      Get the Attribute value
      Parameters:
        `startElement` -
        `tag` - localpart of the qname of the attribute
      Returns:

    - #### getXmlTimeAttributeValue

          public static XMLGregorianCalendar getXmlTimeAttributeValue(StartElement startElement,
                                                                      HasQName attrName)
                                                               throws ParsingException

      Get the Attribute value
      Parameters:
        `startElement` -
        `tag` - localpart of the qname of the attribute
      Returns:
      Throws:
        `ParsingException`

    - #### getXmlDurationAttributeValue

          public static Duration getXmlDurationAttributeValue(StartElement startElement,
                                                              HasQName attrName)
                                                       throws ParsingException

      Get the Attribute value
      Parameters:
        `startElement` -
        `tag` - localpart of the qname of the attribute
      Returns:
      Throws:
        `ParsingException`

    - #### getIntegerAttributeValue

          public static Integer getIntegerAttributeValue(StartElement startElement,
                                                         HasQName attrName)

      Get the Attribute value
      Parameters:
        `startElement` -
        `tag` - localpart of the qname of the attribute
      Returns:

    - #### getIntegerAttributeValueRP

          public static Integer getIntegerAttributeValueRP(StartElement startElement,
                                                           HasQName attrName)

      Get the Attribute value, replacing every occurrence of ${..} by corresponding system property value
      Parameters:
        `startElement` -
        `tag` - localpart of the qname of the attribute
      Returns:

    - #### getLongAttributeValue

          public static Long getLongAttributeValue(StartElement startElement,
                                                   HasQName attrName)

      Get the Attribute value
      Parameters:
        `startElement` -
        `attrName` -

    - #### getLongAttributeValueRP

          public static Long getLongAttributeValueRP(StartElement startElement,
                                                     HasQName attrName)

      Get the Attribute value
      Parameters:
        `startElement` -
        `attrName` -

    - #### getBooleanAttributeValue

          public static Boolean getBooleanAttributeValue(StartElement startElement,
                                                         HasQName attrName)

      Get the Attribute value
      Parameters:
        `startElement` -
        `tag` - localpart of the qname of the attribute
      Returns:

    - #### getBooleanAttributeValueRP

          public static Boolean getBooleanAttributeValueRP(StartElement startElement,
                                                           HasQName attrName)

      Get the Attribute value, replacing every occurrence of ${..} by corresponding system property value
      Parameters:
        `startElement` -
        `tag` - localpart of the qname of the attribute
      Returns:

    - #### getBooleanAttributeValue

          @Deprecated
          public static boolean getBooleanAttributeValue(StartElement startElement,
                                                                     String tag)

      Deprecated.
      Get the Attribute value
      Parameters:
        `startElement` -
        `tag` - localpart of the qname of the attribute
      Returns:
        false if attribute not set

    - #### getBooleanAttributeValue

          @Deprecated
          public static boolean getBooleanAttributeValue(StartElement startElement,
                                                                     String tag,
                                                                     boolean defaultValue)

      Deprecated.
      Get the Attribute value
      Parameters:
        `startElement` -
        `tag` - localpart of the qname of the attribute
      Returns:
        false if attribute not set

    - #### getRequiredAttributeValue

          public static String getRequiredAttributeValue(StartElement startElement,
                                                         HasQName attrName)
                                                  throws ParsingException

      Throws:
        `ParsingException`

    - #### getRequiredAttributeValueRP

          public static String getRequiredAttributeValueRP(StartElement startElement,
                                                           HasQName attrName)
                                                    throws ParsingException

      Throws:
        `ParsingException`

    - #### getRequiredStringListAttributeValue

          public static List<String> getRequiredStringListAttributeValue(StartElement startElement,
                                                                         HasQName attrName)
                                                                  throws ParsingException

      Parse a space delimited list of strings
      Parameters:
        `startElement` -
        `attrName` -
      Returns:
      Throws:
        `ParsingException`

    - #### getDOMElement

          public static Element getDOMElement(XMLEventReader xmlEventReader)
                                       throws ParsingException

      Given that the `XMLEventReader` is in `XMLStreamConstants.START_ELEMENT` mode, we parse into a DOM Element
      Parameters:
        `xmlEventReader` -
      Returns:
      Throws:
        `ParsingException`

    - #### getElementText

          public static String getElementText(XMLEventReader xmlEventReader)
                                       throws ParsingException

      Get the element text. Following `XMLEventReader.getElementText()`: Precondition: the current event is START_ELEMENT. Postcondition: The current event is the corresponding END_ELEMENT.
      Parameters:
        `xmlEventReader` -
      Returns:
        A trimmed string value
      Throws:
        `ParsingException`

    - #### getElementTextRP

          public static String getElementTextRP(XMLEventReader xmlEventReader)
                                         throws ParsingException

      Get the element text, replacing every occurrence of ${..} by corresponding system property value
      Parameters:
        `xmlEventReader` -
      Returns:
        A trimmed string value with all property references replaced if any. If there are no valid references the input string will be returned
      Throws:
        `ParsingException`

    - #### getXMLEventReader

          public static XMLEventReader getXMLEventReader(InputStream is)

      Get the XML event reader
      Parameters:
        `is` -
      Returns:

    - #### getXMLEventReader

          public static XMLEventReader getXMLEventReader(Source source)

      Get the XML event reader
      Parameters:
        `source` -
      Returns:

    - #### getLineColumnNumber

          public static String getLineColumnNumber(Location location)

      Given a `Location`, return a formatted string [lineNum,colNum]
      Parameters:
        `location` -
      Returns:

    - #### getNextEvent

          public static XMLEvent getNextEvent(XMLEventReader xmlEventReader)
                                       throws ParsingException

      Get the next xml event
      Parameters:
        `xmlEventReader` -
      Returns:
      Throws:
        `ParsingException`

    - #### getNextStartElement

          public static StartElement getNextStartElement(XMLEventReader xmlEventReader)
                                                  throws ParsingException

      Get the next `StartElement`
      Parameters:
        `xmlEventReader` -
      Returns:
      Throws:
        `ParsingException`

    - #### getNextEndElement

          public static EndElement getNextEndElement(XMLEventReader xmlEventReader)
                                              throws ParsingException

      Get the next `EndElement`
      Parameters:
        `xmlEventReader` -
      Returns:
      Throws:
        `ParsingException`

    - #### getElementName

          public static String getElementName(StartElement startElement)

      Return the name of the start element
      Parameters:
        `startElement` -
      Returns:

    - #### getElementName

          public static String getElementName(EndElement endElement)

      Return the name of the end element
      Parameters:
        `endElement` -
      Returns:

    - #### getXSITypeValue

          public static String getXSITypeValue(StartElement startElement)

      Given a start element, obtain the xsi:type defined
      Parameters:
        `startElement` -
      Returns:
      Throws:
        `RuntimeException` - if xsi:type is missing

    - #### hasTextAhead

          public static boolean hasTextAhead(XMLEventReader xmlEventReader)
                                      throws ParsingException

      Return whether the next event is going to be text
      Parameters:
        `xmlEventReader` -
      Returns:
      Throws:
        `ParsingException`

    - #### matches

          public static boolean matches(StartElement startElement,
                                        String tag)

      Match that the start element with the expected tag
      Parameters:
        `startElement` -
        `tag` -
      Returns:
        boolean if the tags match

    - #### matches

          public static boolean matches(EndElement endElement,
                                        String tag)

      Match that the end element with the expected tag
      Parameters:
        `endElement` -
        `tag` -
      Returns:
        boolean if the tags match

    - #### peek

          public static XMLEvent peek(XMLEventReader xmlEventReader)
                               throws ParsingException

      Peek at the next event
      Parameters:
        `xmlEventReader` -
      Returns:
      Throws:
        `ParsingException`

    - #### advance

          public static XMLEvent advance(XMLEventReader xmlEventReader)
                                  throws ParsingException

      Consume the next event
      Parameters:
        `xmlEventReader` -
      Returns:
      Throws:
        `ParsingException`

    - #### peekNextStartElement

          public static StartElement peekNextStartElement(XMLEventReader xmlEventReader)
                                                   throws ParsingException

      Peek the next `StartElement`
      Parameters:
        `xmlEventReader` -
      Returns:
      Throws:
        `ParsingException`

    - #### peekNextTag

          public static XMLEvent peekNextTag(XMLEventReader xmlEventReader)
                                      throws ParsingException

      Peek the next `StartElement` or `EndElement`.
      Parameters:
        `xmlEventReader` -
      Returns:
      Throws:
        `ParsingException`

    - #### peekNextEndElement

          public static EndElement peekNextEndElement(XMLEventReader xmlEventReader)
                                               throws ParsingException

      Peek the next `EndElement`
      Parameters:
        `xmlEventReader` -
      Returns:
      Throws:
        `ParsingException`

    - #### trim

          public static final String trim(String str)

      Given a string, trim it
      Parameters:
        `str` -
      Returns:
      Throws:
        `{@code` - IllegalArgumentException} if the passed str is null

    - #### validate

          @Deprecated
          public static void validate(StartElement startElement,
                                                  String tag)

      Deprecated.
      Validate that the start element has the expected tag
      Parameters:
        `startElement` -
        `tag` -
      Throws:
        `RuntimeException` - mismatch

    - #### validate

          public static void validate(StartElement startElement,
                                      QName tag)

      Validate that the start element has the expected tag
      Parameters:
        `startElement` -
        `tag` -
      Throws:
        `RuntimeException` - mismatch

    - #### validate

          public static void validate(EndElement endElement,
                                      String tag)

      Validate that the end element has the expected tag
      Parameters:
        `endElement` -
        `tag` -
      Throws:
        `RuntimeException` - mismatch

Copyright © 2021 JBoss by Red Hat. All rights reserved.