Example usage for javax.xml.stream XMLStreamReader getProperty

List of usage examples for javax.xml.stream XMLStreamReader getProperty

Introduction

In this page you can find the example usage for javax.xml.stream XMLStreamReader getProperty.

Prototype

public Object getProperty(java.lang.String name) throws java.lang.IllegalArgumentException;

Source Link

Document

Get the value of a feature/property from the underlying implementation

Usage

From source file:org.apache.axiom.util.stax.XMLStreamReaderUtils.java

/**
 * Get the {@link DataHandlerReader} extension for a given {@link XMLStreamReader}, if
 * available. If the {@link XMLStreamReader} only supports the legacy extension (as described
 * above), then this method will return a compatibility wrapper. Note that this wrapper doesn't
 * support deferred loading of the binary content.
 * /* w  ww.ja  v a2s  .  c  o  m*/
 * @param reader
 *            the stream reader to get the {@link DataHandlerReader} extension from
 * @return the implementation of the extension, or <code>null</code> if the
 *         {@link XMLStreamReader} doesn't expose base64 encoded binary content as
 *         {@link DataHandler} objects.
 */
public static DataHandlerReader getDataHandlerReader(final XMLStreamReader reader) {
    try {
        DataHandlerReader dhr = (DataHandlerReader) reader.getProperty(DataHandlerReader.PROPERTY);
        if (dhr != null) {
            return dhr;
        }
    } catch (IllegalArgumentException ex) {
        // Just continue
    }
    Boolean isDataHandlerAware;
    try {
        isDataHandlerAware = (Boolean) reader.getProperty(IS_DATA_HANDLERS_AWARE);
    } catch (IllegalArgumentException ex) {
        return null;
    }
    if (isDataHandlerAware != null && isDataHandlerAware.booleanValue()) {
        return new DataHandlerReader() {
            public boolean isBinary() {
                return ((Boolean) reader.getProperty(IS_BINARY)).booleanValue();
            }

            public boolean isOptimized() {
                // This is compatible with the old StAXBuilder implementation
                return true;
            }

            public boolean isDeferred() {
                return false;
            }

            public String getContentID() {
                return null;
            }

            public DataHandler getDataHandler() {
                return (DataHandler) reader.getProperty(DATA_HANDLER);
            }

            public DataHandlerProvider getDataHandlerProvider() {
                throw new UnsupportedOperationException();
            }
        };
    } else {
        return null;
    }
}

From source file:org.apache.axiom.util.stax.XMLStreamReaderUtils.java

/**
 * Get the character data for the current event from the given reader and
 * write it to the given writer. The method will try to figure out the most
 * efficient way to copy the data without unnecessary buffering or
 * conversions between strings and character arrays.
 * /*w w  w.j  av  a  2s  . co m*/
 * @param reader
 *            the reader to get the character data from
 * @param writer
 *            the writer to write the character data to
 * @throws XMLStreamException
 *             if the underlying XML source is not well-formed
 * @throws IOException
 *             if an I/O error occurs when writing the character data
 * @throws IllegalStateException
 *             if this state is not a valid text state.
 * @see CharacterDataReader
 */
public static void writeTextTo(XMLStreamReader reader, Writer writer) throws XMLStreamException, IOException {
    CharacterDataReader cdataReader;
    try {
        cdataReader = (CharacterDataReader) reader.getProperty(CharacterDataReader.PROPERTY);
    } catch (IllegalArgumentException ex) {
        cdataReader = null;
    }
    if (cdataReader != null) {
        cdataReader.writeTextTo(writer);
    } else {
        writer.write(reader.getText());
    }
}