Package 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 SummaryConstructors Constructor Description StaxParserUtil()
 - 
Method SummaryAll Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static XMLEventadvance(XMLEventReader xmlEventReader)Consume the next eventstatic XMLEventbypassElementBlock(XMLEventReader xmlEventReader)Bypass an entire XML element block.static voidbypassElementBlock(XMLEventReader xmlEventReader, String tag)Bypass an entire XML element block from startElement to endElement.static voidbypassElementBlock(XMLEventReader xmlEventReader, QName tag)Bypass an entire XML element block from startElement to endElement.static StringgetAttributeValue(Attribute attribute)Given anAttribute, get its trimmed valuestatic StringgetAttributeValue(StartElement startElement, String tag)Deprecated.static StringgetAttributeValue(StartElement startElement, QName attrQName)Get the Attribute valuestatic StringgetAttributeValue(StartElement startElement, HasQName attrName)Get the Attribute valuestatic StringgetAttributeValueRP(Attribute attribute)Given anAttribute, get its trimmed value, replacing every occurrence of ${..} by corresponding system property valuestatic StringgetAttributeValueRP(StartElement startElement, HasQName attrName)Get the Attribute value, replacing every occurrence of ${..} by corresponding system property valuestatic booleangetBooleanAttributeValue(StartElement startElement, String tag)Deprecated.static booleangetBooleanAttributeValue(StartElement startElement, String tag, boolean defaultValue)Deprecated.static BooleangetBooleanAttributeValue(StartElement startElement, HasQName attrName)Get the Attribute valuestatic BooleangetBooleanAttributeValueRP(StartElement startElement, HasQName attrName)Get the Attribute value, replacing every occurrence of ${..} by corresponding system property valuestatic ElementgetDOMElement(XMLEventReader xmlEventReader)Given that theXMLEventReaderis inXMLStreamConstants.START_ELEMENTmode, we parse into a DOM Elementstatic StringgetElementName(EndElement endElement)Return the name of the end elementstatic StringgetElementName(StartElement startElement)Return the name of the start elementstatic StringgetElementText(XMLEventReader xmlEventReader)Get the element text.static StringgetElementTextRP(XMLEventReader xmlEventReader)Get the element text, replacing every occurrence of ${..} by corresponding system property valuestatic IntegergetIntegerAttributeValue(StartElement startElement, HasQName attrName)Get the Attribute valuestatic IntegergetIntegerAttributeValueRP(StartElement startElement, HasQName attrName)Get the Attribute value, replacing every occurrence of ${..} by corresponding system property valuestatic StringgetLineColumnNumber(Location location)Given aLocation, return a formatted string [lineNum,colNum]static LonggetLongAttributeValue(StartElement startElement, HasQName attrName)Get the Attribute valuestatic LonggetLongAttributeValueRP(StartElement startElement, HasQName attrName)Get the Attribute valuestatic EndElementgetNextEndElement(XMLEventReader xmlEventReader)Get the nextEndElementstatic XMLEventgetNextEvent(XMLEventReader xmlEventReader)Get the next xml eventstatic StartElementgetNextStartElement(XMLEventReader xmlEventReader)Get the nextStartElementstatic StringgetRequiredAttributeValue(StartElement startElement, HasQName attrName)static StringgetRequiredAttributeValueRP(StartElement startElement, HasQName attrName)static List<String>getRequiredStringListAttributeValue(StartElement startElement, HasQName attrName)Parse a space delimited list of stringsstatic URIgetUriAttributeValue(StartElement startElement, HasQName attrName)Get the Attribute valuestatic DurationgetXmlDurationAttributeValue(StartElement startElement, HasQName attrName)Get the Attribute valuestatic XMLEventReadergetXMLEventReader(InputStream is)Get the XML event readerstatic XMLEventReadergetXMLEventReader(Source source)Get the XML event readerstatic XMLGregorianCalendargetXmlTimeAttributeValue(StartElement startElement, HasQName attrName)Get the Attribute valuestatic StringgetXSITypeValue(StartElement startElement)Given a start element, obtain the xsi:type definedstatic booleanhasTextAhead(XMLEventReader xmlEventReader)Return whether the next event is going to be textstatic booleanmatches(EndElement endElement, String tag)Match that the end element with the expected tagstatic booleanmatches(StartElement startElement, String tag)Match that the start element with the expected tagstatic XMLEventpeek(XMLEventReader xmlEventReader)Peek at the next eventstatic EndElementpeekNextEndElement(XMLEventReader xmlEventReader)Peek the nextEndElementstatic StartElementpeekNextStartElement(XMLEventReader xmlEventReader)Peek the nextStartElementstatic XMLEventpeekNextTag(XMLEventReader xmlEventReader)Peek the nextStartElementorEndElement.static Stringtrim(String str)Given a string, trim itstatic voidvalidate(InputStream doc, InputStream sch)static voidvalidate(EndElement endElement, String tag)Validate that the end element has the expected tagstatic voidvalidate(StartElement startElement, String tag)Deprecated.static voidvalidate(StartElement startElement, QName tag)Validate that the start element has the expected tagstatic booleanwasWhitespacePeeked(XMLEventReader xmlEventReader, XMLEvent xmlEvent)Advances reader if character whitespace encountered
 
- 
- 
- 
Method Detail- 
validatepublic static void validate(InputStream doc, InputStream sch) throws ParsingException - Throws:
- ParsingException
 
 - 
bypassElementBlockpublic static void bypassElementBlock(XMLEventReader xmlEventReader, String tag) throws ParsingException Bypass an entire XML element block from startElement to endElement. It is expected that thexmlEventReaderis 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
 
 - 
bypassElementBlockpublic static void bypassElementBlock(XMLEventReader xmlEventReader, QName tag) throws ParsingException Bypass an entire XML element block from startElement to endElement. It is expected that thexmlEventReaderis 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
 
 - 
bypassElementBlockpublic static XMLEvent bypassElementBlock(XMLEventReader xmlEventReader) throws ParsingException Bypass an entire XML element block. It is expected that thexmlEventReaderis positioned at (has not yet read) the start element of the block it should bypass.- Parameters:
- xmlEventReader-
- Throws:
- ParsingException
 
 - 
wasWhitespacePeekedpublic static boolean wasWhitespacePeeked(XMLEventReader xmlEventReader, XMLEvent xmlEvent) Advances reader if character whitespace encountered- Parameters:
- xmlEventReader-
- xmlEvent-
- Returns:
 
 - 
getAttributeValuepublic static String getAttributeValue(Attribute attribute) Given anAttribute, get its trimmed value- Parameters:
- attribute-
- Returns:
 
 - 
getAttributeValueRPpublic static String getAttributeValueRP(Attribute attribute) Given anAttribute, 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:
 
 - 
getAttributeValuepublic static String getAttributeValue(StartElement startElement, HasQName attrName) Get the Attribute value- Parameters:
- startElement-
- tag- localpart of the qname of the attribute
- Returns:
 
 - 
getAttributeValueRPpublic 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)
 
 - 
getAttributeValuepublic static String getAttributeValue(StartElement startElement, QName attrQName) Get the Attribute value- Parameters:
- startElement-
- tag- localpart of the qname of the attribute
- Returns:
 
 - 
getUriAttributeValuepublic static URI getUriAttributeValue(StartElement startElement, HasQName attrName) Get the Attribute value- Parameters:
- startElement-
- tag- localpart of the qname of the attribute
- Returns:
 
 - 
getXmlTimeAttributeValuepublic 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
 
 - 
getXmlDurationAttributeValuepublic 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
 
 - 
getIntegerAttributeValuepublic static Integer getIntegerAttributeValue(StartElement startElement, HasQName attrName) Get the Attribute value- Parameters:
- startElement-
- tag- localpart of the qname of the attribute
- Returns:
 
 - 
getIntegerAttributeValueRPpublic 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:
 
 - 
getLongAttributeValuepublic static Long getLongAttributeValue(StartElement startElement, HasQName attrName) Get the Attribute value- Parameters:
- startElement-
- attrName-
 
 - 
getLongAttributeValueRPpublic static Long getLongAttributeValueRP(StartElement startElement, HasQName attrName) Get the Attribute value- Parameters:
- startElement-
- attrName-
 
 - 
getBooleanAttributeValuepublic static Boolean getBooleanAttributeValue(StartElement startElement, HasQName attrName) Get the Attribute value- Parameters:
- startElement-
- tag- localpart of the qname of the attribute
- Returns:
 
 - 
getBooleanAttributeValueRPpublic 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
 
 - 
getRequiredAttributeValuepublic static String getRequiredAttributeValue(StartElement startElement, HasQName attrName) throws ParsingException - Throws:
- ParsingException
 
 - 
getRequiredAttributeValueRPpublic static String getRequiredAttributeValueRP(StartElement startElement, HasQName attrName) throws ParsingException - Throws:
- ParsingException
 
 - 
getRequiredStringListAttributeValuepublic static List<String> getRequiredStringListAttributeValue(StartElement startElement, HasQName attrName) throws ParsingException Parse a space delimited list of strings- Parameters:
- startElement-
- attrName-
- Returns:
- Throws:
- ParsingException
 
 - 
getDOMElementpublic static Element getDOMElement(XMLEventReader xmlEventReader) throws ParsingException Given that theXMLEventReaderis inXMLStreamConstants.START_ELEMENTmode, we parse into a DOM Element- Parameters:
- xmlEventReader-
- Returns:
- Throws:
- ParsingException
 
 - 
getElementTextpublic static String getElementText(XMLEventReader xmlEventReader) throws ParsingException Get the element text. FollowingXMLEventReader.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
 
 - 
getElementTextRPpublic 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
 
 - 
getXMLEventReaderpublic static XMLEventReader getXMLEventReader(InputStream is) Get the XML event reader- Parameters:
- is-
- Returns:
 
 - 
getXMLEventReaderpublic static XMLEventReader getXMLEventReader(Source source) Get the XML event reader- Parameters:
- source-
- Returns:
 
 - 
getLineColumnNumberpublic static String getLineColumnNumber(Location location) Given aLocation, return a formatted string [lineNum,colNum]- Parameters:
- location-
- Returns:
 
 - 
getNextEventpublic static XMLEvent getNextEvent(XMLEventReader xmlEventReader) throws ParsingException Get the next xml event- Parameters:
- xmlEventReader-
- Returns:
- Throws:
- ParsingException
 
 - 
getNextStartElementpublic static StartElement getNextStartElement(XMLEventReader xmlEventReader) throws ParsingException Get the nextStartElement- Parameters:
- xmlEventReader-
- Returns:
- Throws:
- ParsingException
 
 - 
getNextEndElementpublic static EndElement getNextEndElement(XMLEventReader xmlEventReader) throws ParsingException Get the nextEndElement- Parameters:
- xmlEventReader-
- Returns:
- Throws:
- ParsingException
 
 - 
getElementNamepublic static String getElementName(StartElement startElement) Return the name of the start element- Parameters:
- startElement-
- Returns:
 
 - 
getElementNamepublic static String getElementName(EndElement endElement) Return the name of the end element- Parameters:
- endElement-
- Returns:
 
 - 
getXSITypeValuepublic static String getXSITypeValue(StartElement startElement) Given a start element, obtain the xsi:type defined- Parameters:
- startElement-
- Returns:
- Throws:
- RuntimeException- if xsi:type is missing
 
 - 
hasTextAheadpublic static boolean hasTextAhead(XMLEventReader xmlEventReader) throws ParsingException Return whether the next event is going to be text- Parameters:
- xmlEventReader-
- Returns:
- Throws:
- ParsingException
 
 - 
matchespublic 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
 
 - 
matchespublic 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
 
 - 
peekpublic static XMLEvent peek(XMLEventReader xmlEventReader) throws ParsingException Peek at the next event- Parameters:
- xmlEventReader-
- Returns:
- Throws:
- ParsingException
 
 - 
advancepublic static XMLEvent advance(XMLEventReader xmlEventReader) throws ParsingException Consume the next event- Parameters:
- xmlEventReader-
- Returns:
- Throws:
- ParsingException
 
 - 
peekNextStartElementpublic static StartElement peekNextStartElement(XMLEventReader xmlEventReader) throws ParsingException Peek the nextStartElement- Parameters:
- xmlEventReader-
- Returns:
- Throws:
- ParsingException
 
 - 
peekNextTagpublic static XMLEvent peekNextTag(XMLEventReader xmlEventReader) throws ParsingException Peek the nextStartElementorEndElement.- Parameters:
- xmlEventReader-
- Returns:
- Throws:
- ParsingException
 
 - 
peekNextEndElementpublic static EndElement peekNextEndElement(XMLEventReader xmlEventReader) throws ParsingException Peek the nextEndElement- Parameters:
- xmlEventReader-
- Returns:
- Throws:
- ParsingException
 
 - 
trimpublic static final String trim(String str) Given a string, trim it- Parameters:
- str-
- Returns:
 
 - 
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
 
 - 
validatepublic static void validate(StartElement startElement, QName tag) Validate that the start element has the expected tag- Parameters:
- startElement-
- tag-
- Throws:
- RuntimeException- mismatch
 
 - 
validatepublic static void validate(EndElement endElement, String tag) Validate that the end element has the expected tag- Parameters:
- endElement-
- tag-
- Throws:
- RuntimeException- mismatch
 
 
- 
 
-