Java 类javax.xml.stream.XMLStreamReader 实例源码

项目:OpenJSharp    文件:PolicyWSDLParserExtension.java   
private void processReferenceUri(
        final String policyUri,
        final WSDLObject element,
        final XMLStreamReader reader,
        final Map<WSDLObject, Collection<PolicyRecordHandler>> map) {

    if (null == policyUri || policyUri.length() == 0) {
        return;
    }
    if ('#' != policyUri.charAt(0)) { // external uri (already)
        getUnresolvedUris(false).add(policyUri);
    }

    addHandlerToMap(map, element,
            new PolicyRecordHandler(
            HandlerType.PolicyUri,
            SafePolicyReader.relativeToAbsoluteUrl(policyUri, reader.getLocation().getSystemId())));
}
项目:openjdk-jdk10    文件:Bug6481678.java   
@Test
public void testNamespaceContext() {
    is = new java.io.ByteArrayInputStream(getXML().getBytes());
    try {
        XMLStreamReader sr = factory.createFilteredReader(factory.createXMLStreamReader(is), (StreamFilter) filter);
        while (sr.hasNext()) {
            int eventType = sr.next();
            if (eventType == XMLStreamConstants.START_ELEMENT) {
                if (sr.getLocalName().equals(childElement)) {
                    NamespaceContext context = sr.getNamespaceContext();
                    Assert.assertTrue(context.getPrefix(namespaceURIApple).equals(prefixApple));
                }
            }
        }
    } catch (Exception ex) {
        Assert.fail("Exception: " + ex.getMessage());
    }
}
项目:OpenJSharp    文件:FastInfosetUtil.java   
/**
 * Returns the FI parser allocated for this thread.
 */
public static XMLStreamReader createFIStreamReader(InputStream in) {
    // Check if compatible implementation of FI was found
    if (FastInfosetReflection.fiStAXDocumentParser_new == null) {
        throw new XMLReaderException("fastinfoset.noImplementation");
    }

    try {
        // Do not use StAX pluggable layer for FI
        Object sdp = FastInfosetReflection.fiStAXDocumentParser_new.newInstance();
        FastInfosetReflection.fiStAXDocumentParser_setStringInterning.invoke(sdp, Boolean.TRUE);
        FastInfosetReflection.fiStAXDocumentParser_setInputStream.invoke(sdp, in);
        return (XMLStreamReader) sdp;
    } catch (Exception e) {
        throw new XMLStreamReaderException(e);
    }
}
项目:OpenJSharp    文件:SDDocumentSource.java   
/**
 * Creates a {@link SDDocumentSource} from {@link XMLStreamBuffer}.
 */
public static SDDocumentSource create(final URL systemId, final XMLStreamBuffer xsb) {
    return new SDDocumentSource() {
        public XMLStreamReader read(XMLInputFactory xif) throws XMLStreamException {
            return xsb.readAsXMLStreamReader();
        }

        public XMLStreamReader read() throws XMLStreamException {
            return xsb.readAsXMLStreamReader();
        }

        public URL getSystemId() {
            return systemId;
        }
    };
}
项目:openjdk-jdk10    文件:Bug6481678.java   
@Test
public void testChildElementNamespace() {
    is = new java.io.ByteArrayInputStream(getXML().getBytes());
    try {
        XMLStreamReader sr = factory.createFilteredReader(factory.createXMLStreamReader(is), (StreamFilter) filter);
        while (sr.hasNext()) {
            int eventType = sr.next();
            if (eventType == XMLStreamConstants.START_ELEMENT) {
                if (sr.getLocalName().equals(childElement)) {
                    QName qname = sr.getName();
                    Assert.assertTrue(qname.getPrefix().equals(prefixApple) && qname.getNamespaceURI().equals(namespaceURIApple)
                            && qname.getLocalPart().equals(childElement));
                }
            }
        }
    } catch (Exception ex) {
        Assert.fail("Exception: " + ex.getMessage());
    }
}
项目:openjdk-jdk10    文件:StAXSourceTest.java   
/**
 * @bug 8152530
 * Verifies that StAXSource handles empty namespace properly. NPE was thrown
 * before the fix.
 * @throws Exception if the test fails
 */
@Test
public final void testStAXSourceWEmptyNS() throws Exception {
    String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
        + "<EntityList>\n"
        + "  <Entity xmlns=\"\">\n"
        + "  </Entity>\n"
        + "  <Entity xmlns=\"\">\n"
        + "  </Entity>\n"
        + "</EntityList> ";

    XMLInputFactory xif = XMLInputFactory.newInstance();
    XMLStreamReader xsr = xif.createXMLStreamReader(new StringReader(xml));
    xsr.nextTag();
    TransformerFactory tf = TransformerFactory.newInstance();
    Transformer t = tf.newTransformer();
    while (xsr.nextTag() == XMLStreamConstants.START_ELEMENT && xsr.getLocalName().equals("Entity")) {
        StringWriter stringResult = new StringWriter();
        t.transform(new StAXSource(xsr), new StreamResult(stringResult));
        System.out.println("result: \n" + stringResult.toString());
    }
}
项目:openjdk-jdk10    文件:ResponseBuilder.java   
final Object readResponse(Object[] args, XMLStreamReader r, AttachmentSet att) throws JAXBException {
    Object obj;
    AttachmentUnmarshallerImpl au = (att != null)?new AttachmentUnmarshallerImpl(att):null;
    if (bridge instanceof RepeatedElementBridge) {
        RepeatedElementBridge rbridge = (RepeatedElementBridge)bridge;
        ArrayList list = new ArrayList();
        QName name = r.getName();
        while (r.getEventType()==XMLStreamReader.START_ELEMENT && name.equals(r.getName())) {
            list.add(rbridge.unmarshal(r, au));
            XMLStreamReaderUtil.toNextTag(r, name);
        }
        obj = rbridge.collectionHandler().convert(list);
    } else {
        obj = bridge.unmarshal(r, au);
    }
    return setter.put(obj,args);
}
项目:gate-core    文件:DocumentStaxUtils.java   
/**
 * Processes a GateDocumentFeatures or Annotation element to build a
 * feature map. The element is expected to contain Feature children,
 * each with a Name and Value. The reader will be returned positioned
 * on the closing GateDocumentFeatures or Annotation tag.
 * 
 * @throws XMLStreamException
 */
public static FeatureMap readFeatureMap(XMLStreamReader xsr)
        throws XMLStreamException {
  FeatureMap fm = Factory.newFeatureMap();
  while(xsr.nextTag() == XMLStreamConstants.START_ELEMENT) {
    xsr.require(XMLStreamConstants.START_ELEMENT, null, "Feature");
    Object featureName = null;
    Object featureValue = null;
    while(xsr.nextTag() == XMLStreamConstants.START_ELEMENT) {
      if("Name".equals(xsr.getLocalName())) {
        featureName = readFeatureNameOrValue(xsr);
      }
      else if("Value".equals(xsr.getLocalName())) {
        featureValue = readFeatureNameOrValue(xsr);
      }
      else {
        throw new XMLStreamException("Feature element should contain "
                + "only Name and Value children", xsr.getLocation());
      }
    }
    fm.put(featureName, featureValue);
  }
  return fm;
}
项目:openjdk-jdk10    文件:Jsr173MR1Req8Test.java   
@Test
public void testDefaultAttrNS() {
    XMLInputFactory ifac = XMLInputFactory.newInstance();

    try {
        XMLStreamReader re = ifac.createXMLStreamReader(getClass().getResource(INPUT_FILE1).toExternalForm(),
                this.getClass().getResourceAsStream(INPUT_FILE1));
        while (re.hasNext()) {
            int event = re.next();
            if (event == XMLStreamConstants.START_ELEMENT) {
                // System.out.println("#attrs = " + re.getAttributeCount());
                Assert.assertTrue(re.getAttributeCount() == 2);
                // This works if "" is replaced by null too
                // System.out.println("attr1 = " + re.getAttributeValue("",
                // "attr1"));
                Assert.assertTrue(re.getAttributeValue("", "attr1").equals("pass"));
            }
        }
        re.close();
    } catch (Exception e) {
        e.printStackTrace();
        Assert.fail("Exception occured: " + e.getMessage());
    }
}
项目:openjdk-jdk10    文件:NamespaceTest.java   
@Test
public void testNamespaceContext() {
    try {
        XMLInputFactory xif = XMLInputFactory.newInstance();
        xif.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, Boolean.TRUE);
        InputStream is = new java.io.ByteArrayInputStream(getXML().getBytes());
        XMLStreamReader sr = xif.createXMLStreamReader(is);
        while (sr.hasNext()) {
            int eventType = sr.next();
            if (eventType == XMLStreamConstants.START_ELEMENT) {
                if (sr.getLocalName().equals(childElement)) {
                    NamespaceContext context = sr.getNamespaceContext();
                    Assert.assertTrue(context.getPrefix(namespaceURI).equals(prefix));
                }
            }
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
项目:OpenJSharp    文件:FastInfosetStreamSOAPCodec.java   
private XMLStreamReader getXMLStreamReader(InputStream in) {
    // If the _retainState is true (FI stateful) then pick up Codec assiciated XMLStreamReader
    if (_retainState) {
        if (_statefulParser != null) {
            _statefulParser.setInputStream(in);
            return _statefulParser;
        } else {
            return _statefulParser = FastInfosetCodec.createNewStreamReader(in, _retainState);
        }
    }

    // Otherwise thread assiciated XMLStreamReader
    return READER_FACTORY.doCreate(null, in, false);
}
项目:powsybl-core    文件:CIMProgressiveParser.java   
/**
 * Utility to use when we meet a startElement in the CIM XML Document.
 * Only the startElement that contains the CIMURI is used.
 *
 * @param xmlsr
 *            The XMLStreamReader used to read the CIM XML Document
 */
public void startElement(final XMLStreamReader xmlsr) {

    // if null, the element is not interpreted

    // We search for a <cim:...> element or for the <md:Model.profile> element
    if(xmlsr.getPrefix().equals("cim")) {
        hasGoodVersion = (xmlsr.getNamespaceURI().equals(CIMURI.CIMURI));
        done = true;
    }
    else if(xmlsr.getPrefix().equals("md") && xmlsr.getName().equals("Model.profile")){
        profileElement = true;
    }

}
项目:OpenJSharp    文件:WSDLParserExtensionFacade.java   
public boolean messageElements(EditableWSDLMessage msg, XMLStreamReader reader) {
    for (WSDLParserExtension e : extensions) {
        if (e.messageElements(msg, reader)) {
            return true;
        }
    }
    XMLStreamReaderUtil.skipElement(reader);
    return true;
}
项目:openjdk-jdk10    文件:WSDLParserExtensionFacade.java   
public boolean messageElements(EditableWSDLMessage msg, XMLStreamReader reader) {
    for (WSDLParserExtension e : extensions) {
        if (e.messageElements(msg, reader)) {
            return true;
        }
    }
    XMLStreamReaderUtil.skipElement(reader);
    return true;
}
项目:openjdk-jdk10    文件:UnmarshallerImpl.java   
@Override
public <T> JAXBElement<T> unmarshal(XMLStreamReader reader, Class<T> expectedType) throws JAXBException {
    if (expectedType==null) {
        throw new IllegalArgumentException();
    }
    return (JAXBElement)unmarshal0(reader,getBeanInfo(expectedType));
}
项目:OpenJSharp    文件:StAXEventAllocatorBase.java   
protected void addAttributes(StartElementEvent event,XMLStreamReader streamReader){
    AttributeBase attr = null;
    for(int i=0; i<streamReader.getAttributeCount() ;i++){
        attr = (AttributeBase)factory.createAttribute(streamReader.getAttributeName(i),
                                streamReader.getAttributeValue(i));
        attr.setAttributeType(streamReader.getAttributeType(i));
        attr.setSpecified(streamReader.isAttributeSpecified(i));
        event.addAttribute(attr);
    }
}
项目:cuttlefish    文件:GraphMLImporter.java   
private void readGraph(XMLStreamReader xmlReader) {
    String edgeDefault = "";

    for (int i = 0; i < xmlReader.getAttributeCount(); ++i) {
        String attr = xmlReader.getAttributeLocalName(i);

        if (attr.equalsIgnoreCase(GRAPH_EDGEDEFAULT)) {
            edgeDefault = xmlReader.getAttributeValue(i);
        }
    }

    network.setDirected(edgeDefault.equalsIgnoreCase(EDGE_DIRECTED));
}
项目:OpenJSharp    文件:StreamReaderBufferCreator.java   
private void storeElementWithInScopeNamespaces(XMLStreamReader reader) {
    storeQualifiedName(T_ELEMENT_LN,
            reader.getPrefix(), reader.getNamespaceURI(), reader.getLocalName());

    if (reader.getNamespaceCount() > 0) {
        storeNamespaceAttributes(reader);
    }

    if (reader.getAttributeCount() > 0) {
        storeAttributes(reader);
    }
}
项目:OpenJSharp    文件:PolicyWSDLParserExtension.java   
@Override
public boolean bindingOperationFaultElements(final EditableWSDLBoundFault fault, final XMLStreamReader reader) {
    LOGGER.entering();
    final boolean result = processSubelement(fault, reader, getHandlers4BindingFaultOpMap());
    LOGGER.exiting(result);
    return result;
}
项目:openjdk-jdk10    文件:WSDLParserExtensionFacade.java   
public boolean definitionsElements(XMLStreamReader reader){
    for (WSDLParserExtension e : extensions) {
        if (e.definitionsElements(reader)) {
            return true;
        }
    }
    XMLStreamReaderUtil.skipElement(reader);
    return true;
}
项目:OpenJSharp    文件:PolicyWSDLParserExtension.java   
@Override
public boolean serviceElements(final EditableWSDLService service, final XMLStreamReader reader) {
    LOGGER.entering();
    final boolean result = processSubelement(service, reader, getHandlers4ServiceMap());
    LOGGER.exiting();
    return result;
}
项目:OpenJSharp    文件:XMLStreamReaderUtil.java   
public static int nextElementContent(XMLStreamReader reader) {
    int state = nextContent(reader);
    if (state == CHARACTERS) {
        throw new XMLStreamReaderException(
            "xmlreader.unexpectedCharacterContent", reader.getText());
    }
    return state;
}
项目:openjdk-jdk10    文件:Sources.java   
/**
 * Returns an instance of XMLStreamReader.
 *
 * @return an instance of XMLStreamReader.
 */
private XMLStreamReader getXMLStreamReader() {
    XMLStreamReader r = null;
    try {
        XMLInputFactory xif = XMLInputFactory.newInstance();
        r = xif.createXMLStreamReader(new ByteArrayInputStream("".getBytes()));
    } catch (XMLStreamException ex) {}

    return r;
}
项目:OpenJSharp    文件:DeploymentDescriptorParser.java   
protected String getMandatoryAttribute(XMLStreamReader reader, Attributes attrs, String name) {
    String value = getAttribute(attrs, name);
    if (value == null) {
        failWithLocalName("runtime.parser.missing.attribute", reader, name);
    }
    return value;
}
项目:openjdk-jdk10    文件:WSDLParserExtensionFacade.java   
public boolean portTypeOperationFaultElements(EditableWSDLFault fault, XMLStreamReader reader) {
    for (WSDLParserExtension e : extensions) {
        if (e.portTypeOperationFaultElements(fault, reader)) {
            return true;
        }
    }
    XMLStreamReaderUtil.skipElement(reader);
    return true;
}
项目:OpenJSharp    文件:UnmarshallerImpl.java   
public Object unmarshal0(XMLStreamReader reader, JaxBeanInfo expectedType) throws JAXBException {
    if (reader == null) {
        throw new IllegalArgumentException(
            Messages.format(Messages.NULL_READER));
    }

    int eventType = reader.getEventType();
    if (eventType != XMLStreamConstants.START_ELEMENT
        && eventType != XMLStreamConstants.START_DOCUMENT) {
        // TODO: convert eventType into event name
        throw new IllegalStateException(
            Messages.format(Messages.ILLEGAL_READER_STATE,eventType));
    }

    XmlVisitor h = createUnmarshallerHandler(null,false,expectedType);
    StAXConnector connector=StAXStreamConnector.create(reader,h);

    try {
        connector.bridge();
    } catch (XMLStreamException e) {
        throw handleStreamException(e);
    }

    Object retVal = h.getContext().getResult();
    h.getContext().clearResult();
    return retVal;
}
项目:OpenJSharp    文件:WSDLParserExtensionFacade.java   
public boolean portTypeElements(EditableWSDLPortType portType, XMLStreamReader reader) {
    for (WSDLParserExtension e : extensions) {
        if (e.portTypeElements(portType, reader)) {
            return true;
        }
    }
    XMLStreamReaderUtil.skipElement(reader);
    return true;
}
项目:openjdk-jdk10    文件:JAXBHeader.java   
public XMLStreamReader readHeader() throws XMLStreamException {
    if(infoset==null) {
        MutableXMLStreamBuffer buffer = new MutableXMLStreamBuffer();
        writeTo(buffer.createFromXMLStreamWriter());
        infoset = buffer;
    }
    return infoset.readAsXMLStreamReader();
}
项目:openjdk-jdk10    文件:XMLStreamReaderUtil.java   
public static int nextElementContent(XMLStreamReader reader) {
    int state = nextContent(reader);
    if (state == CHARACTERS) {
        throw new XMLStreamReaderException(
            "xmlreader.unexpectedCharacterContent", reader.getText());
    }
    return state;
}
项目:OpenJSharp    文件:PolicyUtils.java   
/**
 * If the {@code reader} is not {@code null}, this method will try to close the
 * {@code reader} instance and log warning about any unexpected
 * {@link IOException} that may occur.
 *
 * @param reader resource to be closed
 */
public static void closeResource(XMLStreamReader reader) {
    if (reader != null) {
        try {
            reader.close();
        } catch (XMLStreamException e) {
            LOGGER.warning(LocalizationMessages.WSP_0023_UNEXPECTED_ERROR_WHILE_CLOSING_RESOURCE(reader.toString()), e);
        }
    }
}
项目:nifi-registry    文件:XmlUtils.java   
public static XMLStreamReader createSafeReader(StreamSource source) throws XMLStreamException {
    if (source == null) {
        throw new IllegalArgumentException("The provided source cannot be null");
    }

    XMLInputFactory xif = XMLInputFactory.newFactory();
    xif.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false);
    xif.setProperty(XMLInputFactory.SUPPORT_DTD, false);
    return xif.createXMLStreamReader(source);
}
项目:openjdk-jdk10    文件:AbstractHeaderImpl.java   
/**
 * Default implementation that copies the infoset. Not terribly efficient.
 */
public WSEndpointReference readAsEPR(AddressingVersion expected) throws XMLStreamException {
    XMLStreamReader xsr = readHeader();
    WSEndpointReference epr = new WSEndpointReference(xsr, expected);
    XMLStreamReaderFactory.recycle(xsr);
    return epr;
}
项目:OpenJSharp    文件:DeploymentDescriptorParser.java   
/**
 * Loads the class of the given name.
 *
 * @param xsr Used to report the source location information if there's any error.
 */
private Class getImplementorClass(String name, XMLStreamReader xsr) {
    try {
        return Class.forName(name, true, classLoader);
    } catch (ClassNotFoundException e) {
        logger.log(Level.SEVERE, e.getMessage(), e);
        throw new LocatableWebServiceException(
                ServerMessages.RUNTIME_PARSER_CLASS_NOT_FOUND(name), e, xsr);
    }
}
项目:OpenJSharp    文件:XMLStreamReaderFactory.java   
@Override
public XMLStreamReader doCreate(String systemId, InputStream in, boolean rejectDTDs) {
    try {
        return xif.get().createXMLStreamReader(systemId,in);
    } catch (XMLStreamException e) {
        throw new XMLReaderException("stax.cantCreate",e);
    }
}
项目:openjdk-jdk10    文件:W3CAddressingWSDLParserExtension.java   
@Override
public boolean bindingOperationElements(EditableWSDLBoundOperation operation, XMLStreamReader reader) {
    EditableWSDLBoundOperation edit = (EditableWSDLBoundOperation) operation;

    QName anon = reader.getName();
    if (anon.equals(AddressingVersion.W3C.wsdlAnonymousTag)) {
        try {
            String value = reader.getElementText();
            if (value == null || value.trim().equals("")) {
                throw new WebServiceException("Null values not permitted in wsaw:Anonymous.");
                // TODO: throw exception only if wsdl:required=true
                // TODO: is this the right exception ?
            } else if (value.equals("optional")) {
                edit.setAnonymous(ANONYMOUS.optional);
            } else if (value.equals("required")) {
                edit.setAnonymous(ANONYMOUS.required);
            } else if (value.equals("prohibited")) {
                edit.setAnonymous(ANONYMOUS.prohibited);
            } else {
                throw new WebServiceException("wsaw:Anonymous value \"" + value + "\" not understood.");
                // TODO: throw exception only if wsdl:required=true
                // TODO: is this the right exception ?
            }
        } catch (XMLStreamException e) {
            throw new WebServiceException(e);       // TODO: is this the correct behavior ?
        }

        return true;        // consumed the element
    }

    return false;
}
项目:ProyectoPacientes    文件:JDBC4MysqlSQLXML.java   
private Reader binaryInputStreamStreamToReader(ByteArrayOutputStream out) {

        try {
            // There's got to be an easier way to do this, but I don't feel like coding up Appendix F of the XML Spec myself, when there's a reusable way to do
            // it, and we can warn folks away from BINARY xml streams that have to be parsed to determine the character encoding :P

            String encoding = "UTF-8";

            try {
                ByteArrayInputStream bIn = new ByteArrayInputStream(out.toByteArray());
                XMLStreamReader reader = this.inputFactory.createXMLStreamReader(bIn);

                int eventType = 0;

                while ((eventType = reader.next()) != XMLStreamReader.END_DOCUMENT) {
                    if (eventType == XMLStreamReader.START_DOCUMENT) {
                        String possibleEncoding = reader.getEncoding();

                        if (possibleEncoding != null) {
                            encoding = possibleEncoding;
                        }

                        break;
                    }
                }
            } catch (Throwable t) {
                // ignore, dealt with later when the string can't be parsed into valid XML
            }

            return new StringReader(new String(out.toByteArray(), encoding));
        } catch (UnsupportedEncodingException badEnc) {
            throw new RuntimeException(badEnc);
        }
    }
项目:openjdk-jdk10    文件:W3CAddressingWSDLParserExtension.java   
public void portTypeOperationOutputAttributes(EditableWSDLOutput output, XMLStreamReader reader) {
   String action = ParserUtil.getAttribute(reader, getWsdlActionTag());
   if (action != null) {
        output.setAction(action);
        output.setDefaultAction(false);
    }
}
项目:openjdk-jdk10    文件:XMLStreamReaderUtil.java   
public static void verifyTag(XMLStreamReader reader, QName name) {
    verifyTag(reader, name.getNamespaceURI(), name.getLocalPart());
}
项目:openjdk-jdk10    文件:Bug6688002Test.java   
public static/* synchronized */XMLStreamReader getReader(InputStream is) throws Exception {
    return inputFactory.createXMLStreamReader(is);
    // return XMLStreamReaderFactory.create(null, is, true);
}
项目:openjdk-jdk10    文件:FastInfosetStreamSOAP11Codec.java   
protected final StreamHeader createHeader(XMLStreamReader reader, XMLStreamBuffer mark) {
    return new StreamHeader11(reader, mark);
}