public final class StaxUtils extends Object
Constructor and Description |
---|
StaxUtils() |
Modifier and Type | Method and Description |
---|---|
static void |
closeQuietly(XMLEventReader xmlEventReader) |
static void |
closeQuietly(XMLEventWriter xmlEventWriter) |
static void |
closeQuietly(XMLStreamReader xmlStreamReader) |
static void |
closeQuietly(XMLStreamWriter xmlStreamWriter) |
static StringBuilder |
collectWhitespace(StringBuilder builder,
XMLEventReader reader)
Collect whitespace from the given reader, into the given builder.
|
static String |
collectWhitespace(XMLEventReader reader)
Collect whitespace from the given reader.
|
static XhtmlException |
convertToXhtmlException(com.ctc.wstx.exc.WstxLazyException ex)
Take a WstxLazyException as a parameter and return the appropriate XhtmlException for the Woodstox exception supplied.
|
static void |
flushEventWriter(XMLEventWriter eventWriter)
Ensure all xml events that have been added to the event buffer of the writer are flushed.
|
static String |
getAttributeValue(StartElement startElement,
QName attributeQName) |
static String |
getAttributeValue(StartElement startElement,
QName attributeQName,
String defaultValue)
Retrieves the value of the specified attribute name on the specified start element.
|
static String |
getAttributeValue(StartElement startElement,
String attributeName) |
static String |
getAttributeValue(StartElement startElement,
String attributeName,
String defaultValue)
Retrieves the value of the specified attribute name on the specified start element.
|
static boolean |
hasAttributes(StartElement startElement,
String... attributeNames)
Returns true if start element has all the specified attributes.
|
static boolean |
hasClass(StartElement startElement,
String className) |
static boolean |
isHTML5RawTextlement(QName name) |
static boolean |
isHTML5VoidElement(QName name) |
static String |
readCharactersAndEntities(XMLEventReader reader)
Read all characters and entities from the supplied reader until a non-character or non-entity event is read.
|
static void |
skipWhitespace(XMLEventReader reader)
Skip whitespace from the given reader.
|
static List<String> |
splitCData(String data)
Take a String and split into multiple substrings where each substring is suitable to be written as CData.
|
static CharSequence |
stripIllegalControlChars(CharSequence unclean)
Removes control characters from a CharSequence so that it can be parsed by a Stax parser.
|
static String |
toString(XMLEventReader reader)
Deprecated.
|
static String |
toXmlString(XMLEventReader reader,
XmlOutputFactory xmlOutputFactory) |
static String |
toXmlStringWithoutTag(XMLEventReader reader,
XmlOutputFactory xmlOutputFactory,
Set<QName> ignoredElements)
Reads an XML stream and turns it into a string while removing any tags matched in ignoredElements
|
static void |
writeAttribute(XMLStreamWriter writer,
QName attribute,
String value)
Write an attribute and its value on the provided XMLStreamWriter
|
static void |
writeRawXML(XMLStreamWriter writer,
Writer out,
Streamable streamable)
Write raw XML properly on the provided Writer, which is wrapped by a XMLStreamWriter
|
static void |
writeStartElement(XMLStreamWriter writer,
QName element)
Write the element start on the provided XMLStreamWriter
|
public static boolean isHTML5VoidElement(QName name)
public static boolean isHTML5RawTextlement(QName name)
public static void writeStartElement(XMLStreamWriter writer, QName element) throws XMLStreamException
XMLStreamException
public static void writeAttribute(XMLStreamWriter writer, QName attribute, String value) throws XMLStreamException
XMLStreamException
public static void writeRawXML(XMLStreamWriter writer, Writer out, Streamable streamable) throws IOException, XMLStreamException
IOException
XMLStreamException
public static void closeQuietly(@Nullable XMLEventReader xmlEventReader)
public static void closeQuietly(XMLStreamReader xmlStreamReader)
public static void closeQuietly(@Nullable XMLEventWriter xmlEventWriter)
public static void closeQuietly(XMLStreamWriter xmlStreamWriter)
public static String getAttributeValue(StartElement startElement, String attributeName)
public static String getAttributeValue(StartElement startElement, QName attributeQName)
public static String getAttributeValue(StartElement startElement, String attributeName, String defaultValue)
startElement
- start elementattributeName
- attribute namepublic static String getAttributeValue(StartElement startElement, QName attributeQName, String defaultValue)
startElement
- start elementattributeQName
- attribute QNamepublic static boolean hasAttributes(StartElement startElement, String... attributeNames)
startElement
- start elementattributeNames
- attribute namespublic static boolean hasClass(StartElement startElement, String className)
startElement
- className
- public static String collectWhitespace(XMLEventReader reader) throws XMLStreamException
reader
- the readerXMLStreamException
- if there are problems reading from the supplied readerpublic static StringBuilder collectWhitespace(StringBuilder builder, XMLEventReader reader) throws XMLStreamException
builder
- the builderreader
- the readerXMLStreamException
- if there are problems reading from the supplied readerpublic static void skipWhitespace(XMLEventReader reader) throws XMLStreamException
reader
- the readerXMLStreamException
- if there are problems reading from the supplied readerpublic static String readCharactersAndEntities(XMLEventReader reader) throws XMLStreamException
reader
- the reader to read from, with the current event being either a character or an entityXMLStreamException
- if there are problems reading from the supplied reader@Deprecated public static String toString(XMLEventReader reader)
toXmlString(javax.xml.stream.XMLEventReader, XmlOutputFactory)
public static String toXmlString(XMLEventReader reader, XmlOutputFactory xmlOutputFactory)
public static String toXmlStringWithoutTag(XMLEventReader reader, XmlOutputFactory xmlOutputFactory, Set<QName> ignoredElements)
reader
- The XML event readerxmlOutputFactory
- The XML output factoryignoredElements
- A set of tags that should be stripped from the outputpublic static void flushEventWriter(XMLEventWriter eventWriter) throws XMLStreamException
You want to be using this instead of XMLEventWriter.flush()
when:
If you want to do this, you need this method to append the closing angle bracket of the start element.
You want to do in preparation for writing to the underlying writer directly.
eventWriter
- the event writerXMLStreamException
public static List<String> splitCData(String data)
Take a String and split into multiple substrings where each substring is suitable to be written as CData.
You would use this method when you want to write CDATA to an XML document and you need to be sure that the content you are writing doesn't contain a CDATA closing triad (]]>) which would cause a premature closing of the CDATA.
So as an example if you supply a String like <![CDATA[stuff]]> then the returned Strings would be
If the supplied String is already safe for writing to a CDATA section then a single item List will be returned containing the supplied String.
data
- the data to be made safe for writing to a CDATA section.public static XhtmlException convertToXhtmlException(com.ctc.wstx.exc.WstxLazyException ex)
ex
- the Woodstox exception to be converted to an XhtmlException.@Nonnull public static CharSequence stripIllegalControlChars(@Nonnull CharSequence unclean)
Legal characters are tab, carriage return, line feed, and the legal characters of Unicode and ISO/IEC 10646XML Charsets.
This method only removes illegal control chars, and doesn't attempt to remove illegal Unicode characters.
unclean
- Copyright © 2003–2016 Atlassian. All rights reserved.