Example usage for javax.xml.stream XMLStreamReader getVersion

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

Introduction

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

Prototype

public String getVersion();

Source Link

Document

Get the xml version declared on the xml declaration Returns null if none was declared

Usage

From source file:org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder.java

/**
 * Constructor.//from w  ww  .  java2s  . c  om
 *
 * @param metaFactory the meta factory used to get the appropriate {@link SOAPFactory}
 *                    implementation
 * @param parser the parser to read the SOAP message from
 * @param soapVersion the namespace URI corresponding to the expected SOAP version
 *                    of the message
 */
public StAXSOAPModelBuilder(OMMetaFactory metaFactory, XMLStreamReader parser, String soapVersion) {
    super(metaFactory.getOMFactory(), parser);
    this.metaFactory = metaFactory;
    parserVersion = parser.getVersion();
    identifySOAPVersion(soapVersion);
}

From source file:org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder.java

/**
 * Constructor.//from   w  w  w . j  a  v  a  2 s. co m
 * 
 * @param metaFactory the meta factory used to get the appropriate {@link SOAPFactory}
 *                    implementation
 * @param parser the parser to read the SOAP message from
 */
public StAXSOAPModelBuilder(OMMetaFactory metaFactory, XMLStreamReader parser) {
    super(metaFactory.getOMFactory(), parser);
    this.metaFactory = metaFactory;
    parserVersion = parser.getVersion();
    SOAPEnvelope soapEnvelope = getSOAPEnvelope();
    envelopeNamespace = soapEnvelope.getNamespace();
}

From source file:org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder.java

/**
 * Constructor./*from w  ww.j  a  va2s. com*/
 * 
 * @param parser the parser to read the SOAP message from
 * @param factory the SOAP factory to use
 * @param soapVersion the namespace URI corresponding to the expected SOAP version
 *                    of the message
 */
public StAXSOAPModelBuilder(XMLStreamReader parser, SOAPFactory factory, String soapVersion) {
    super(factory, parser);
    soapFactory = factory;
    parserVersion = parser.getVersion();
    identifySOAPVersion(soapVersion);
}

From source file:org.jetbrains.tfsIntegration.webservice.compatibility.CustomStAXSOAPModelBuilder.java

/**
 * Constructor StAXSOAPModelBuilder soapVersion parameter is to give the soap version from the
 * transport. For example, in HTTP case you can identify the version of the soap message u have
 * recd by looking at the HTTP headers. It is used to check whether the actual soap message
 * contained is of that version. If one is creates the builder from the transport, then can just
 * pass null for version.//from www. ja  va  2s . c  o  m
 *
 * @param parser
 * @param soapVersion parameter is to give the soap version for the transport.
 */
public CustomStAXSOAPModelBuilder(XMLStreamReader parser, String soapVersion) {
    super(parser);
    parserVersion = parser.getVersion();
    identifySOAPVersion(soapVersion);
}

From source file:org.jetbrains.tfsIntegration.webservice.compatibility.CustomStAXSOAPModelBuilder.java

/**
 * Constructor StAXSOAPModelBuilder Users of this constructor needs to externally take care
 * validating the transport level soap version with the Envelope version.
 *
 * @param parser/*from w w w .  j  a  va  2  s.c o  m*/
 */
public CustomStAXSOAPModelBuilder(XMLStreamReader parser) {
    super(parser);
    parserVersion = parser.getVersion();
    SOAPEnvelope soapEnvelope = getSOAPEnvelope();
    envelopeNamespace = soapEnvelope.getNamespace();
}

From source file:org.jetbrains.tfsIntegration.webservice.compatibility.CustomStAXSOAPModelBuilder.java

/**
 * @param parser//from www  .  j av a 2 s.c o m
 * @param factory
 * @param soapVersion parameter is to give the soap version from the transport. For example, in
 *                    HTTP case you can identify the version of the soap message u have recd by
 *                    looking at the HTTP headers. It is used to check whether the actual soap
 *                    message contained is of that version.If one is creates the builder from
 *                    the transport, then can just pass null for version.
 */
public CustomStAXSOAPModelBuilder(XMLStreamReader parser, SOAPFactory factory, String soapVersion) {
    super(factory, parser);
    soapFactory = factory;
    parserVersion = parser.getVersion();
    identifySOAPVersion(soapVersion);
}

From source file:org.netbeans.jbatch.modeler.spec.core.Definitions.java

static void transformXMLStream(XMLStreamReader xmlStreamReader, XMLStreamWriter xmlStreamWriter) {
    try {//from  w  w w. java  2 s. c om
        //            TransformerFactory tf = TransformerFactory.newInstance();
        //            Transformer t = tf.newTransformer();
        //            StAXSource source = new StAXSource(xmlStreamReader);
        //            StAXResult result = new StAXResult(xmlStreamWriter);
        //            t.transform(source, result);
        System.out.println("Defnition Id : " + xmlStreamReader.getAttributeValue(null, "id"));
        boolean finish = false;
        while (xmlStreamReader.hasNext() && !finish) {
            switch (xmlStreamReader.getEventType()) {
            case XMLEvent.START_ELEMENT:
                String prefix = xmlStreamReader.getPrefix();
                String namespaceURI = xmlStreamReader.getNamespaceURI();
                if (namespaceURI != null) {
                    if (prefix != null) {
                        xmlStreamWriter.writeStartElement(xmlStreamReader.getPrefix(),
                                xmlStreamReader.getLocalName(), xmlStreamReader.getNamespaceURI());
                    } else {
                        xmlStreamWriter.writeStartElement(xmlStreamReader.getNamespaceURI(),
                                xmlStreamReader.getLocalName());
                    }
                } else {
                    xmlStreamWriter.writeStartElement(xmlStreamReader.getLocalName());
                }

                for (int i = 0; i < xmlStreamReader.getNamespaceCount(); i++) {
                    xmlStreamWriter.writeNamespace(xmlStreamReader.getNamespacePrefix(i),
                            xmlStreamReader.getNamespaceURI(i));
                }
                int count = xmlStreamReader.getAttributeCount();
                for (int i = 0; i < count; i++) {
                    //                            xmlStreamWriter.writeAttribute(xmlStreamReader.getAttributePrefix(i),
                    //                                    xmlStreamReader.getAttributeNamespace(i),
                    //                                    xmlStreamReader.getAttributeLocalName(i),
                    //                                    xmlStreamReader.getAttributeValue(i));

                    String attrNamespaceURI = xmlStreamReader.getAttributeNamespace(i),
                            attrPrefix = xmlStreamReader.getAttributePrefix(i);
                    if (attrNamespaceURI != null) {
                        if (attrPrefix != null) {
                            xmlStreamWriter.writeAttribute(attrPrefix, attrNamespaceURI,
                                    xmlStreamReader.getAttributeLocalName(i),
                                    xmlStreamReader.getAttributeValue(i));
                        } else {
                            xmlStreamWriter.writeAttribute(attrNamespaceURI,
                                    xmlStreamReader.getAttributeLocalName(i),
                                    xmlStreamReader.getAttributeValue(i));
                        }
                    } else {
                        xmlStreamWriter.writeAttribute(xmlStreamReader.getAttributeLocalName(i),
                                xmlStreamReader.getAttributeValue(i));
                    }

                }
                break;
            case XMLEvent.END_ELEMENT:
                xmlStreamWriter.writeEndElement();
                if (xmlStreamReader.getLocalName().equals("definitions")) {
                    finish = true;
                }
                break;
            case XMLEvent.SPACE:
            case XMLEvent.CHARACTERS:
                xmlStreamWriter.writeCharacters(xmlStreamReader.getTextCharacters(),
                        xmlStreamReader.getTextStart(), xmlStreamReader.getTextLength());
                break;
            case XMLEvent.PROCESSING_INSTRUCTION:
                xmlStreamWriter.writeProcessingInstruction(xmlStreamReader.getPITarget(),
                        xmlStreamReader.getPIData());
                break;
            case XMLEvent.CDATA:
                xmlStreamWriter.writeCData(xmlStreamReader.getText());
                break;

            case XMLEvent.COMMENT:
                xmlStreamWriter.writeComment(xmlStreamReader.getText());
                break;
            case XMLEvent.ENTITY_REFERENCE:
                xmlStreamWriter.writeEntityRef(xmlStreamReader.getLocalName());
                break;
            case XMLEvent.START_DOCUMENT:
                String encoding = xmlStreamReader.getCharacterEncodingScheme();
                String version = xmlStreamReader.getVersion();

                if (encoding != null && version != null) {
                    xmlStreamWriter.writeStartDocument(encoding, version);
                } else if (version != null) {
                    xmlStreamWriter.writeStartDocument(xmlStreamReader.getVersion());
                }
                break;
            case XMLEvent.END_DOCUMENT:
                xmlStreamWriter.writeEndDocument();
                break;
            case XMLEvent.DTD:
                xmlStreamWriter.writeDTD(xmlStreamReader.getText());
                break;

            }
            if (!finish) {
                xmlStreamReader.next();
            }
        }
    } catch (XMLStreamException ex) {
        Exceptions.printStackTrace(ex);
    }
}

From source file:org.netbeans.jbatch.modeler.specification.model.job.util.JobUtil.java

void transformXMLStream(XMLStreamReader xmlStreamReader, XMLStreamWriter xmlStreamWriter) {
    try {//from   www.  jav a  2 s.  c  o m
        //            TransformerFactory tf = TransformerFactory.newInstance();
        //            Transformer t = tf.newTransformer();
        //            StAXSource source = new StAXSource(xmlStreamReader);
        //            StAXResult result = new StAXResult(xmlStreamWriter);
        //            t.transform(source, result);

        boolean finish = false;
        while (xmlStreamReader.hasNext() && !finish) {
            switch (xmlStreamReader.getEventType()) {
            case XMLEvent.START_ELEMENT:
                String prefix = xmlStreamReader.getPrefix();
                String namespaceURI = xmlStreamReader.getNamespaceURI();
                if (namespaceURI != null) {
                    if (prefix != null) {
                        xmlStreamWriter.writeStartElement(xmlStreamReader.getPrefix(),
                                xmlStreamReader.getLocalName(), xmlStreamReader.getNamespaceURI());
                    } else {
                        xmlStreamWriter.writeStartElement(xmlStreamReader.getNamespaceURI(),
                                xmlStreamReader.getLocalName());
                    }
                } else {
                    xmlStreamWriter.writeStartElement(xmlStreamReader.getLocalName());
                }

                for (int i = 0; i < xmlStreamReader.getNamespaceCount(); i++) {
                    xmlStreamWriter.writeNamespace(xmlStreamReader.getNamespacePrefix(i),
                            xmlStreamReader.getNamespaceURI(i));
                }
                int count = xmlStreamReader.getAttributeCount();
                for (int i = 0; i < count; i++) {
                    //                            xmlStreamWriter.writeAttribute(xmlStreamReader.getAttributePrefix(i),
                    //                                    xmlStreamReader.getAttributeNamespace(i),
                    //                                    xmlStreamReader.getAttributeLocalName(i),
                    //                                    xmlStreamReader.getAttributeValue(i));

                    String attrNamespaceURI = xmlStreamReader.getAttributeNamespace(i),
                            attrPrefix = xmlStreamReader.getAttributePrefix(i);
                    if (attrNamespaceURI != null) {
                        if (attrPrefix != null) {
                            xmlStreamWriter.writeAttribute(attrPrefix, attrNamespaceURI,
                                    xmlStreamReader.getAttributeLocalName(i),
                                    xmlStreamReader.getAttributeValue(i));
                        } else {
                            xmlStreamWriter.writeAttribute(attrNamespaceURI,
                                    xmlStreamReader.getAttributeLocalName(i),
                                    xmlStreamReader.getAttributeValue(i));
                        }
                    } else {
                        xmlStreamWriter.writeAttribute(xmlStreamReader.getAttributeLocalName(i),
                                xmlStreamReader.getAttributeValue(i));
                    }

                }
                break;
            case XMLEvent.END_ELEMENT:
                xmlStreamWriter.writeEndElement();
                if (xmlStreamReader.getLocalName().equals("definitions")) {
                    finish = true;
                }
                break;
            case XMLEvent.SPACE:
            case XMLEvent.CHARACTERS:
                xmlStreamWriter.writeCharacters(xmlStreamReader.getTextCharacters(),
                        xmlStreamReader.getTextStart(), xmlStreamReader.getTextLength());
                break;
            case XMLEvent.PROCESSING_INSTRUCTION:
                xmlStreamWriter.writeProcessingInstruction(xmlStreamReader.getPITarget(),
                        xmlStreamReader.getPIData());
                break;
            case XMLEvent.CDATA:
                xmlStreamWriter.writeCData(xmlStreamReader.getText());
                break;

            case XMLEvent.COMMENT:
                xmlStreamWriter.writeComment(xmlStreamReader.getText());
                break;
            case XMLEvent.ENTITY_REFERENCE:
                xmlStreamWriter.writeEntityRef(xmlStreamReader.getLocalName());
                break;
            case XMLEvent.START_DOCUMENT:
                String encoding = xmlStreamReader.getCharacterEncodingScheme();
                String version = xmlStreamReader.getVersion();

                if (encoding != null && version != null) {
                    xmlStreamWriter.writeStartDocument(encoding, version);
                } else if (version != null) {
                    xmlStreamWriter.writeStartDocument(xmlStreamReader.getVersion());
                }
                break;
            case XMLEvent.END_DOCUMENT:
                xmlStreamWriter.writeEndDocument();
                break;
            case XMLEvent.DTD:
                xmlStreamWriter.writeDTD(xmlStreamReader.getText());
                break;

            }
            if (!finish) {
                xmlStreamReader.next();
            }
        }
    } catch (XMLStreamException ex) {
        Exceptions.printStackTrace(ex);
    }
}

From source file:org.ut.biolab.medsavant.client.plugin.PluginIndex.java

public PluginIndex(URL url) throws IOException {
    urls = new HashMap<String, URL>();
    try {/* w w  w.  j  a va2s .  c  om*/

        XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(
                ClientNetworkUtils.openStream(url, ClientNetworkUtils.NONCRITICAL_CONNECT_TIMEOUT,
                        ClientNetworkUtils.NONCRITICAL_READ_TIMEOUT));
        if (reader.getVersion() == null) {
            throw new XMLStreamException("Invalid XML at URL " + url);
        }
        boolean done = false;
        String id = null;
        do {
            if (reader.hasNext()) {
                int t = reader.next();
                switch (t) {
                case XMLStreamConstants.START_ELEMENT:
                    String elemName = reader.getLocalName();
                    if (elemName.equals("leaf")) {
                        id = reader.getAttributeValue(null, "id");
                    } else if (elemName.equals("url")) {
                        if (id != null) {
                            try {
                                urls.put(id, new URL(reader.getElementText()));
                            } catch (MalformedURLException x) {
                                LOG.warn(String.format("Unable to parse \"%s\" as a plugin URL.",
                                        reader.getElementText()));
                            }
                            id = null;
                        }
                    }
                    break;
                case XMLStreamConstants.END_DOCUMENT:
                    reader.close();
                    done = true;
                    break;
                }
            } else {
                throw new XMLStreamException("Malformed XML at " + url);
            }
        } while (!done);
    } catch (XMLStreamException x) {
        throw new IOException("Unable to get version number from web-site.", x);
    }
}