Java Code Examples for javax.xml.stream.XMLStreamReader#nextTag()
The following examples show how to use
javax.xml.stream.XMLStreamReader#nextTag() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EndpointArgumentsBuilder.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
protected void readWrappedRequest(Message msg, Object[] args) throws JAXBException, XMLStreamException { if (!msg.hasPayload()) { throw new WebServiceException("No payload. Expecting payload with "+wrapperName+" element"); } XMLStreamReader reader = msg.readPayload(); XMLStreamReaderUtil.verifyTag(reader,wrapperName); reader.nextTag(); while(reader.getEventType()==XMLStreamReader.START_ELEMENT) { // TODO: QName has a performance issue QName name = reader.getName(); WrappedPartBuilder part = wrappedParts.get(name); if(part==null) { // no corresponding part found. ignore XMLStreamReaderUtil.skipElement(reader); reader.nextTag(); } else { part.readRequest(args,reader, msg.getAttachments()); } XMLStreamReaderUtil.toNextTag(reader, name); } // we are done with the body reader.close(); XMLStreamReaderFactory.recycle(reader); }
Example 2
Source File: OutboundReferenceParameterHeader.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
/** * We don't really expect this to be used, but just to satisfy * the {@link Header} contract. * * So this is rather slow. */ private void parseAttributes() { try { XMLStreamReader reader = readHeader(); reader.nextTag(); // move to the first element, which is the header element attributes = new FinalArrayList<Attribute>(); boolean refParamAttrWritten = false; for (int i = 0; i < reader.getAttributeCount(); i++) { final String attrLocalName = reader.getAttributeLocalName(i); final String namespaceURI = reader.getAttributeNamespace(i); final String value = reader.getAttributeValue(i); if (namespaceURI.equals(AddressingVersion.W3C.nsUri)&& attrLocalName.equals("IS_REFERENCE_PARAMETER")) { refParamAttrWritten = true; } attributes.add(new Attribute(namespaceURI,attrLocalName,value)); } // we are adding one more attribute "wsa:IsReferenceParameter", if its not alrady there if (!refParamAttrWritten) { attributes.add(new Attribute(AddressingVersion.W3C.nsUri,IS_REFERENCE_PARAMETER,TRUE_VALUE)); } } catch (XMLStreamException e) { throw new WebServiceException("Unable to read the attributes for {"+nsUri+"}"+localName+" header",e); } }
Example 3
Source File: OutboundReferenceParameterHeader.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
/** * We don't really expect this to be used, but just to satisfy * the {@link Header} contract. * * So this is rather slow. */ private void parseAttributes() { try { XMLStreamReader reader = readHeader(); reader.nextTag(); // move to the first element, which is the header element attributes = new FinalArrayList<Attribute>(); boolean refParamAttrWritten = false; for (int i = 0; i < reader.getAttributeCount(); i++) { final String attrLocalName = reader.getAttributeLocalName(i); final String namespaceURI = reader.getAttributeNamespace(i); final String value = reader.getAttributeValue(i); if (namespaceURI.equals(AddressingVersion.W3C.nsUri)&& attrLocalName.equals("IS_REFERENCE_PARAMETER")) { refParamAttrWritten = true; } attributes.add(new Attribute(namespaceURI,attrLocalName,value)); } // we are adding one more attribute "wsa:IsReferenceParameter", if its not alrady there if (!refParamAttrWritten) { attributes.add(new Attribute(AddressingVersion.W3C.nsUri,IS_REFERENCE_PARAMETER,TRUE_VALUE)); } } catch (XMLStreamException e) { throw new WebServiceException("Unable to read the attributes for {"+nsUri+"}"+localName+" header",e); } }
Example 4
Source File: EndpointArgumentsBuilder.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
protected void readWrappedRequest(Message msg, Object[] args) throws JAXBException, XMLStreamException { if (!msg.hasPayload()) { throw new WebServiceException("No payload. Expecting payload with "+wrapperName+" element"); } XMLStreamReader reader = msg.readPayload(); XMLStreamReaderUtil.verifyTag(reader,wrapperName); reader.nextTag(); while(reader.getEventType()==XMLStreamReader.START_ELEMENT) { // TODO: QName has a performance issue QName name = reader.getName(); WrappedPartBuilder part = wrappedParts.get(name); if(part==null) { // no corresponding part found. ignore XMLStreamReaderUtil.skipElement(reader); reader.nextTag(); } else { part.readRequest(args,reader, msg.getAttachments()); } XMLStreamReaderUtil.toNextTag(reader, name); } // we are done with the body reader.close(); XMLStreamReaderFactory.recycle(reader); }
Example 5
Source File: XmlEntryConsumer.java From cloud-odata-java with Apache License 2.0 | 6 votes |
private void readContent(final XMLStreamReader reader, final EntityInfoAggregator eia) throws EntityProviderException, XMLStreamException, EdmException { reader.require(XMLStreamConstants.START_ELEMENT, Edm.NAMESPACE_ATOM_2005, FormatXml.ATOM_CONTENT); extractNamespacesFromTag(reader); checkAllMandatoryNamespacesAvailable(); final String contentType = reader.getAttributeValue(null, FormatXml.ATOM_TYPE); final String sourceLink = reader.getAttributeValue(null, FormatXml.ATOM_SRC); reader.nextTag(); if (reader.isStartElement() && reader.getLocalName().equals(FormatXml.M_PROPERTIES)) { readProperties(reader, eia); } else if (reader.isEndElement()) { reader.require(XMLStreamConstants.END_ELEMENT, Edm.NAMESPACE_ATOM_2005, FormatXml.ATOM_CONTENT); } else { throw new EntityProviderException(EntityProviderException.INVALID_STATE .addContent("Expected closing 'content' or starting 'properties' but found '" + reader.getLocalName() + "'.")); } mediaMetadata.setContentType(contentType); mediaMetadata.setSourceLink(sourceLink); }
Example 6
Source File: OutboundReferenceParameterHeader.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
/** * We don't really expect this to be used, but just to satisfy * the {@link Header} contract. * * So this is rather slow. */ private void parseAttributes() { try { XMLStreamReader reader = readHeader(); reader.nextTag(); // move to the first element, which is the header element attributes = new FinalArrayList<Attribute>(); boolean refParamAttrWritten = false; for (int i = 0; i < reader.getAttributeCount(); i++) { final String attrLocalName = reader.getAttributeLocalName(i); final String namespaceURI = reader.getAttributeNamespace(i); final String value = reader.getAttributeValue(i); if (namespaceURI.equals(AddressingVersion.W3C.nsUri)&& attrLocalName.equals("IS_REFERENCE_PARAMETER")) { refParamAttrWritten = true; } attributes.add(new Attribute(namespaceURI,attrLocalName,value)); } // we are adding one more attribute "wsa:IsReferenceParameter", if its not alrady there if (!refParamAttrWritten) { attributes.add(new Attribute(AddressingVersion.W3C.nsUri,IS_REFERENCE_PARAMETER,TRUE_VALUE)); } } catch (XMLStreamException e) { throw new WebServiceException("Unable to read the attributes for {"+nsUri+"}"+localName+" header",e); } }
Example 7
Source File: JBossDeploymentStructureParser12.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
private static Set<String> parseSet(final XMLStreamReader reader) throws XMLStreamException { final Set<String> set = new HashSet<String>(); // xsd:choice while (reader.hasNext()) { switch (reader.nextTag()) { case END_ELEMENT: { return set; } case START_ELEMENT: { switch (Element.of(reader.getName())) { case PATH: parsePathName(reader, set); break; } } } } return set; }
Example 8
Source File: XmlIOUtil.java From protostuff with Apache License 2.0 | 6 votes |
/** * Merges the {@code message} from the {@link XMLStreamReader} using the given {@code schema}. */ public static <T> void mergeFrom(XMLStreamReader parser, T message, Schema<T> schema) throws IOException, XMLStreamException, XmlInputException { // final String simpleName = schema.messageName(); if (parser.nextTag() != START_ELEMENT || !schema.messageName().equals(parser.getLocalName())) { throw new XmlInputException("Expected token START_ELEMENT: " + schema.messageName()); } if (parser.nextTag() == END_ELEMENT) { // if(!simpleName.equals(parser.getLocalName())) // throw new XmlInputException("Expecting token END_ELEMENT: " + simpleName); // empty message; return; } schema.mergeFrom(new XmlInput(parser), message); // if(!simpleName.equals(parser.getLocalName())) // throw new XmlInputException("Expecting token END_ELEMENT: " + simpleName); }
Example 9
Source File: OutboundReferenceParameterHeader.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
/** * We don't really expect this to be used, but just to satisfy * the {@link Header} contract. * * So this is rather slow. */ private void parseAttributes() { try { XMLStreamReader reader = readHeader(); reader.nextTag(); // move to the first element, which is the header element attributes = new FinalArrayList<Attribute>(); boolean refParamAttrWritten = false; for (int i = 0; i < reader.getAttributeCount(); i++) { final String attrLocalName = reader.getAttributeLocalName(i); final String namespaceURI = reader.getAttributeNamespace(i); final String value = reader.getAttributeValue(i); if (namespaceURI.equals(AddressingVersion.W3C.nsUri)&& attrLocalName.equals("IS_REFERENCE_PARAMETER")) { refParamAttrWritten = true; } attributes.add(new Attribute(namespaceURI,attrLocalName,value)); } // we are adding one more attribute "wsa:IsReferenceParameter", if its not alrady there if (!refParamAttrWritten) { attributes.add(new Attribute(AddressingVersion.W3C.nsUri,IS_REFERENCE_PARAMETER,TRUE_VALUE)); } } catch (XMLStreamException e) { throw new WebServiceException("Unable to read the attributes for {"+nsUri+"}"+localName+" header",e); } }
Example 10
Source File: JBossDeploymentStructureParser12.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
private static void parseDependencies(final XMLStreamReader reader, final ModuleStructureSpec specBuilder, final ModuleLoader moduleLoader) throws XMLStreamException { // xsd:choice while (reader.hasNext()) { switch (reader.nextTag()) { case XMLStreamConstants.END_ELEMENT: { return; } case XMLStreamConstants.START_ELEMENT: { switch (Element.of(reader.getName())) { case MODULE: parseModuleDependency(reader, specBuilder, moduleLoader); break; case SYSTEM: parseSystemDependency(reader, specBuilder); break; default: throw unexpectedContent(reader); } break; } default: { throw unexpectedContent(reader); } } } throw endOfDocument(reader.getLocation()); }
Example 11
Source File: JBossDeploymentStructureParser12.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
private static void parseFilterList(final XMLStreamReader reader, final List<FilterSpecification> filters) throws XMLStreamException { // xsd:choice while (reader.hasNext()) { switch (reader.nextTag()) { case XMLStreamConstants.END_ELEMENT: { return; } case XMLStreamConstants.START_ELEMENT: { switch (Element.of(reader.getName())) { case INCLUDE: parsePath(reader, true, filters); break; case EXCLUDE: parsePath(reader, false, filters); break; case INCLUDE_SET: parseSet(reader, true, filters); break; case EXCLUDE_SET: parseSet(reader, false, filters); break; default: throw unexpectedContent(reader); } break; } default: { throw unexpectedContent(reader); } } } throw endOfDocument(reader.getLocation()); }
Example 12
Source File: StaxBasedConfigParser.java From lams with GNU General Public License v2.0 | 5 votes |
public void parse2(InputStream configStream) throws XMLStreamException { Configuration config = Configuration.getConfiguration(); if (!(config instanceof ApplicationPolicyRegistration)) { throw PicketBoxMessages.MESSAGES.invalidType(ApplicationPolicyRegistration.class.getName()); } ApplicationPolicyRegistration appPolicyRegistration = (ApplicationPolicyRegistration) config; XMLStreamReader reader = getXMLStreamReader(configStream); while (reader.hasNext() && reader.nextTag() != END_ELEMENT) { final Element element = Element.forName(reader.getLocalName()); if (element.equals(Element.POLICY)) { ApplicationPolicyParser appPolicyParser = new ApplicationPolicyParser(); List<ApplicationPolicy> appPolicies = appPolicyParser.parse(reader); for(ApplicationPolicy appPolicy: appPolicies) { appPolicyRegistration.addApplicationPolicy(appPolicy.getName(), appPolicy); } } else throw StaxParserUtil.unexpectedElement(reader); if (reader.isEndElement()) break; } }
Example 13
Source File: JBossDeploymentStructureParser11.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
private static void parseModuleExclusion(final XMLStreamReader reader, final ModuleStructureSpec specBuilder) throws XMLStreamException { String name = null; String slot = "main"; final Set<Attribute> required = EnumSet.of(Attribute.NAME); final int count = reader.getAttributeCount(); for (int i = 0; i < count; i++) { final Attribute attribute = Attribute.of(reader.getAttributeName(i)); required.remove(attribute); switch (attribute) { case NAME: name = reader.getAttributeValue(i); break; case SLOT: slot = reader.getAttributeValue(i); break; default: throw unexpectedContent(reader); } } if (!required.isEmpty()) { throw missingAttributes(reader.getLocation(), required); } specBuilder.getExclusions().add(ModuleIdentifier.create(name, slot)); if (reader.hasNext()) { switch (reader.nextTag()) { case XMLStreamConstants.END_ELEMENT: return; default: throw unexpectedContent(reader); } } }
Example 14
Source File: XmlEntryConsumer.java From olingo-odata2 with Apache License 2.0 | 5 votes |
private void validateEntryTags(final XMLStreamReader reader, final ContentType cType) throws XMLStreamException, EntityProviderException { if (FormatXml.ATOM_ENTRY.equals(cType.getParameters().get(FormatXml.ATOM_TYPE))) { int next = reader.nextTag(); if (XMLStreamConstants.START_ELEMENT == next) { reader.require(XMLStreamConstants.START_ELEMENT, Edm.NAMESPACE_ATOM_2005, FormatXml.ATOM_ENTRY); } else { reader.require(XMLStreamConstants.END_ELEMENT, Edm.NAMESPACE_M_2007_08, FormatXml.M_INLINE); } } else { throw new EntityProviderException(EntityProviderException.INVALID_INLINE_CONTENT.addContent("entry")); } }
Example 15
Source File: AbstractHeaderImpl.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
public String getStringContent() { try { XMLStreamReader xsr = readHeader(); xsr.nextTag(); return xsr.getElementText(); } catch (XMLStreamException e) { return null; } }
Example 16
Source File: JBossDeploymentStructureParser12.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
private static void parseExcludeSubsystem(final XMLStreamReader reader, final ModuleStructureSpec specBuilder) throws XMLStreamException { final Set<String> subsystems = new HashSet<String>(); specBuilder.setExcludedSubsystems(subsystems); // xsd:choice while (reader.hasNext()) { switch (reader.nextTag()) { case XMLStreamConstants.END_ELEMENT: { return; } case XMLStreamConstants.START_ELEMENT: { switch (Element.of(reader.getName())) { case SUBSYSTEM: parseSubsystem(reader, subsystems); break; default: throw unexpectedContent(reader); } break; } default: { throw unexpectedContent(reader); } } } throw endOfDocument(reader.getLocation()); }
Example 17
Source File: XmlEntryConsumer.java From cloud-odata-java with Apache License 2.0 | 5 votes |
private void validateEntryTags(final XMLStreamReader reader, final ContentType cType) throws XMLStreamException, EntityProviderException { if (FormatXml.ATOM_ENTRY.equals(cType.getParameters().get(FormatXml.ATOM_TYPE))) { int next = reader.nextTag(); if (XMLStreamConstants.START_ELEMENT == next) { reader.require(XMLStreamConstants.START_ELEMENT, Edm.NAMESPACE_ATOM_2005, FormatXml.ATOM_ENTRY); } else { reader.require(XMLStreamConstants.END_ELEMENT, Edm.NAMESPACE_M_2007_08, FormatXml.M_INLINE); } } else { throw new EntityProviderException(EntityProviderException.INVALID_INLINE_CONTENT.addContent("entry")); } }
Example 18
Source File: TestCharacterLimits.java From woodstox with Apache License 2.0 | 5 votes |
public void testLongWhitespaceNextTag() throws Exception { try { Reader reader = createLongReader("", "", true); XMLInputFactory factory = getNewInputFactory(); factory.setProperty(WstxInputProperties.P_MAX_TEXT_LENGTH, Integer.valueOf(1000)); XMLStreamReader xmlreader = factory.createXMLStreamReader(reader); while (xmlreader.next() != XMLStreamReader.START_ELEMENT) { } xmlreader.nextTag(); fail("Should have failed"); } catch (XMLStreamException ex) { _verifyTextLimitException(ex); } }
Example 19
Source File: PayloadNameRequestWrapper.java From javamelody with Apache License 2.0 | 4 votes |
/** * Try to parse SOAP method name from request body stream. Does not close the stream. * * @param stream SOAP request body stream @nonnull * @param charEncoding character encoding of stream, or null for platform default @null * @return SOAP method name, or null if unable to parse @null */ private static String parseSoapMethodName(InputStream stream, String charEncoding) { try { // newInstance() et pas newFactory() pour java 1.5 (issue 367) final XMLInputFactory factory = XMLInputFactory.newInstance(); factory.setProperty(XMLInputFactory.SUPPORT_DTD, false); // disable DTDs entirely for that factory factory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false); // disable external entities final XMLStreamReader xmlReader; if (charEncoding != null) { xmlReader = factory.createXMLStreamReader(stream, charEncoding); } else { xmlReader = factory.createXMLStreamReader(stream); } //best-effort parsing //start document, go to first tag xmlReader.nextTag(); //expect first tag to be "Envelope" if (!"Envelope".equals(xmlReader.getLocalName())) { LOG.debug("Unexpected first tag of SOAP request: '" + xmlReader.getLocalName() + "' (expected 'Envelope')"); return null; //failed } //scan for body tag if (!scanForChildTag(xmlReader, "Body")) { LOG.debug("Unable to find SOAP 'Body' tag"); return null; //failed } xmlReader.nextTag(); //tag is method name return "." + xmlReader.getLocalName(); } catch (final XMLStreamException e) { LOG.debug("Unable to parse SOAP request", e); //failed return null; } }
Example 20
Source File: JBossDeploymentStructureParser12.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
private static void parseSystemDependency(final XMLStreamReader reader, final ModuleStructureSpec specBuilder) throws XMLStreamException { boolean export = false; final int count = reader.getAttributeCount(); for (int i = 0; i < count; i++) { final Attribute attribute = Attribute.of(reader.getAttributeName(i)); switch (attribute) { case EXPORT: export = Boolean.parseBoolean(reader.getAttributeValue(i)); break; default: throw unexpectedContent(reader); } } Set<String> paths = Collections.emptySet(); final MultiplePathFilterBuilder exportBuilder = PathFilters.multiplePathFilterBuilder(export); while (reader.hasNext()) { switch (reader.nextTag()) { case END_ELEMENT: { if (export) { // If re-exported, add META-INF/** -> false at the end of the list (require explicit override) exportBuilder.addFilter(PathFilters.getMetaInfSubdirectoriesFilter(), false); exportBuilder.addFilter(PathFilters.getMetaInfFilter(), false); } final PathFilter exportFilter = exportBuilder.create(); specBuilder.addSystemDependency(DependencySpec.createSystemDependencySpec(PathFilters.getDefaultImportFilter(), exportFilter, paths)); return; } case START_ELEMENT: { switch (Element.of(reader.getName())) { case PATHS: { paths = parseSet(reader); break; } case EXPORTS: { parseFilterList(reader, exportBuilder); break; } default: { throw unexpectedContent(reader); } } } } } }