Java Code Examples for javax.xml.stream.XMLStreamReader#getAttributeCount()
The following examples show how to use
javax.xml.stream.XMLStreamReader#getAttributeCount() .
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: XsdRestriction.java From gs-xsd2bean with Apache License 2.0 | 6 votes |
private void parseAttributes(XMLStreamReader xmlStreamReader, String diagnosticMessage) throws XMLStreamException { int attributes = xmlStreamReader.getAttributeCount(); for (int i = 0; i < attributes; i++) { String attributeName = xmlStreamReader.getAttributeName(i).getLocalPart(); String attributeValue = xmlStreamReader.getAttributeValue(i); if (attributeName.equals("base")) { this.base = attributeValue; } else { XsdSchemaUnmarshaller.throwException("unexpected attribute for 'attribute': " + attributeName, xmlStreamReader, diagnosticMessage); } } }
Example 2
Source File: OutboundReferenceParameterHeader.java From openjdk-jdk8u-backup 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: StaxJobFactory.java From scheduling with GNU Affero General Public License v3.0 | 6 votes |
/** * Get the INPUT/OUTPUT space URL of the job. * Leave the method with the cursor at the end of 'ELEMENT_DS_INPUT/OUTPUTSPACE' tag. * * @param cursorVariables the streamReader with the cursor on the 'ELEMENT_DS_INPUT/OUTPUTSPACE' tag. * @return the INPUT/OUTPUT space URL of this tag. */ private String getIOSpace(XMLStreamReader cursorVariables, Map<String, String> variables) throws JobCreationException { try { String url = replace(cursorVariables.getAttributeValue(0), variables); //go to the END_ELEMENT while (cursorVariables.next() != XMLEvent.END_ELEMENT) ; return url; } catch (JobCreationException jce) { throw jce; } catch (Exception e) { String temporaryAttribute = null; if (cursorVariables.isStartElement() && cursorVariables.getAttributeCount() == 1) { temporaryAttribute = cursorVariables.getAttributeLocalName(0); } throw new JobCreationException((String) null, temporaryAttribute, e); } }
Example 4
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 5
Source File: OutboundStreamHeader.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(); attributes = new FinalArrayList<Attribute>(); for (int i = 0; i < reader.getAttributeCount(); i++) { final String localName = reader.getAttributeLocalName(i); final String namespaceURI = reader.getAttributeNamespace(i); final String value = reader.getAttributeValue(i); attributes.add(new Attribute(namespaceURI,localName,value)); } } catch (XMLStreamException e) { throw new WebServiceException("Unable to read the attributes for {"+nsUri+"}"+localName+" header",e); } }
Example 6
Source File: JAXBChunkReader.java From citygml4j with Apache License 2.0 | 6 votes |
private void setXLink(XMLStreamReader reader) { setXLink = false; // check whether the new chunk has a gml:id String gmlId = null; for (int i = 0; i < reader.getAttributeCount(); i++) { if (reader.getAttributeLocalName(i).equals("id")) { gmlId = reader.getAttributeValue(i); break; } } // set gml:id if not present if (gmlId == null) { gmlId = factory.getGMLIdManager().generateUUID(); chunk.addAttribute(GMLCoreModule.v3_1_1.getNamespaceURI(), "id", "id", "CDATA", gmlId); } // set xlink:href property on previous chunk chunks.peek().addAttribute(XLinkModule.v3_1_1.getNamespaceURI(), "href", "href", "CDATA", '#' + gmlId); }
Example 7
Source File: StreamReaderBufferCreator.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
private void storeAttributes(XMLStreamReader reader) { int count = reader.getAttributeCount(); for (int i = 0; i < count; i++) { storeAttribute(reader.getAttributePrefix(i), reader.getAttributeNamespace(i), reader.getAttributeLocalName(i), reader.getAttributeType(i), reader.getAttributeValue(i)); } }
Example 8
Source File: XsdAttribute.java From gs-xsd2bean with Apache License 2.0 | 5 votes |
private void parseAttributes(XMLStreamReader xmlStreamReader, String diagnosticMessage) throws XMLStreamException { int attributes = xmlStreamReader.getAttributeCount(); for(int i=0;i<attributes;i++) { String attributeName = xmlStreamReader.getAttributeName(i).getLocalPart(); String attributeValue = xmlStreamReader.getAttributeValue(i); if (attributeName.equals("name")) { this.name = attributeValue; } else if (attributeName.equals("type")) { this.type = attributeValue; } else if (attributeName.equals("default")) { this.defaultValue = attributeValue; } else if (attributeName.equals("use")) { this.isOptional = !attributeValue.equals("required"); } else { XsdSchemaUnmarshaller.throwException("unexpected attribute for 'attribute': "+attributeName, xmlStreamReader, diagnosticMessage); } } }
Example 9
Source File: StreamHeader11.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
protected final FinalArrayList<Attribute> processHeaderAttributes(XMLStreamReader reader) { FinalArrayList<Attribute> atts = null; _role = SOAPConstants.URI_SOAP_ACTOR_NEXT; for (int i = 0; i < reader.getAttributeCount(); i++) { final String localName = reader.getAttributeLocalName(i); final String namespaceURI = reader.getAttributeNamespace(i); final String value = reader.getAttributeValue(i); if (SOAPConstants.URI_NS_SOAP_1_1_ENVELOPE.equals(namespaceURI)) { if (SOAP_1_1_MUST_UNDERSTAND.equals(localName)) { _isMustUnderstand = Util.parseBool(value); } else if (SOAP_1_1_ROLE.equals(localName)) { if (value != null && value.length() > 0) { _role = value; } } } if(atts==null) { atts = new FinalArrayList<Attribute>(); } atts.add(new Attribute(namespaceURI,localName,value)); } return atts; }
Example 10
Source File: StreamReaderBufferCreator.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
private void storeElement(XMLStreamReader reader) { storeQualifiedName(T_ELEMENT_LN, reader.getPrefix(), reader.getNamespaceURI(), reader.getLocalName()); if (reader.getNamespaceCount() > 0) { storeNamespaceAttributes(reader); } if (reader.getAttributeCount() > 0) { storeAttributes(reader); } }
Example 11
Source File: StAXStream2SAX.java From citygml4j with Apache License 2.0 | 5 votes |
private void handleStartElement(XMLStreamReader reader) throws XMLStreamException { for (int i = 0; i < reader.getNamespaceCount(); i++) buffer.addNamespacePrefixMapping(reader.getNamespaceURI(i), reader.getNamespacePrefix(i)); buffer.addStartElement(reader.getNamespaceURI(), reader.getLocalName(), reader.getPrefix()); for (int i = 0; i < reader.getAttributeCount(); i++) buffer.addAttribute(reader.getAttributeNamespace(i), reader.getAttributeLocalName(i), reader.getAttributePrefix(i), reader.getAttributeType(i), reader.getAttributeValue(i)); }
Example 12
Source File: StreamReaderBufferCreator.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
private void storeElement(XMLStreamReader reader) { storeQualifiedName(T_ELEMENT_LN, reader.getPrefix(), reader.getNamespaceURI(), reader.getLocalName()); if (reader.getNamespaceCount() > 0) { storeNamespaceAttributes(reader); } if (reader.getAttributeCount() > 0) { storeAttributes(reader); } }
Example 13
Source File: StreamReaderBufferCreator.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
private void storeElement(XMLStreamReader reader) { storeQualifiedName(T_ELEMENT_LN, reader.getPrefix(), reader.getNamespaceURI(), reader.getLocalName()); if (reader.getNamespaceCount() > 0) { storeNamespaceAttributes(reader); } if (reader.getAttributeCount() > 0) { storeAttributes(reader); } }
Example 14
Source File: BpmnXMLUtil.java From flowable-engine with Apache License 2.0 | 5 votes |
public static ExtensionElement parseExtensionElement(XMLStreamReader xtr) throws Exception { ExtensionElement extensionElement = new ExtensionElement(); extensionElement.setName(xtr.getLocalName()); if (StringUtils.isNotEmpty(xtr.getNamespaceURI())) { extensionElement.setNamespace(xtr.getNamespaceURI()); } if (StringUtils.isNotEmpty(xtr.getPrefix())) { extensionElement.setNamespacePrefix(xtr.getPrefix()); } for (int i = 0; i < xtr.getAttributeCount(); i++) { ExtensionAttribute extensionAttribute = new ExtensionAttribute(); extensionAttribute.setName(xtr.getAttributeLocalName(i)); extensionAttribute.setValue(xtr.getAttributeValue(i)); if (StringUtils.isNotEmpty(xtr.getAttributeNamespace(i))) { extensionAttribute.setNamespace(xtr.getAttributeNamespace(i)); } if (StringUtils.isNotEmpty(xtr.getAttributePrefix(i))) { extensionAttribute.setNamespacePrefix(xtr.getAttributePrefix(i)); } extensionElement.addAttribute(extensionAttribute); } boolean readyWithExtensionElement = false; while (!readyWithExtensionElement && xtr.hasNext()) { xtr.next(); if (xtr.isCharacters() || XMLStreamReader.CDATA == xtr.getEventType()) { if (StringUtils.isNotEmpty(xtr.getText().trim())) { extensionElement.setElementText(xtr.getText().trim()); } } else if (xtr.isStartElement()) { ExtensionElement childExtensionElement = parseExtensionElement(xtr); extensionElement.addChildElement(childExtensionElement); } else if (xtr.isEndElement() && extensionElement.getName().equalsIgnoreCase(xtr.getLocalName())) { readyWithExtensionElement = true; } } return extensionElement; }
Example 15
Source File: JBossDeploymentStructureParser13.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
private static void parseModule(XMLStreamReader reader, ParseResult result) throws XMLStreamException { final int count = reader.getAttributeCount(); String name = null; String slot = null; final Set<Attribute> required = EnumSet.of(Attribute.NAME); 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); } if (!name.startsWith(MODULE_PREFIX)) { throw ServerLogger.ROOT_LOGGER.invalidModuleName(name); } final ModuleStructureSpec moduleSpecification = new ModuleStructureSpec(); moduleSpecification.setModuleIdentifier(ModuleIdentifier.create(name, slot)); result.getAdditionalModules().add(moduleSpecification); parseModuleStructureSpec(result.getDeploymentUnit(), reader, moduleSpecification, result.getModuleLoader()); }
Example 16
Source File: IdentityTrustConfigParser.java From lams with GNU General Public License v2.0 | 5 votes |
private IdentityTrustModuleEntry getEntry(XMLStreamReader reader) throws XMLStreamException { Map<String, Object> options = new HashMap<String, Object>(); String codeName = null; ControlFlag flag = ControlFlag.REQUIRED; final int count = reader.getAttributeCount(); if (count == 0) { throw StaxParserUtil.missingRequired(reader, Collections.singleton(org.jboss.security.config.Attribute.CODE)); } for (int i = 0; i < count; i++) { final String value = reader.getAttributeValue(i); final org.jboss.security.config.Attribute attribute = org.jboss.security.config.Attribute.forName(reader .getAttributeLocalName(i)); switch (attribute) { case CODE : { codeName = value; break; } case FLAG : { flag = ControlFlag.valueOf(value); break; } default : throw StaxParserUtil.unexpectedAttribute(reader, i); } } if (codeName == null) throw StaxParserUtil.missingRequired(reader, Collections.singleton(org.jboss.security.config.Attribute.CODE)); //See if there are options ModuleOptionParser moParser = new ModuleOptionParser(); options.putAll(moParser.parse(reader)); IdentityTrustModuleEntry entry = new IdentityTrustModuleEntry(codeName, options); entry.setControlFlag(flag); return entry; }
Example 17
Source File: StreamReaderBufferCreator.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
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); } }
Example 18
Source File: AbstractParser.java From ironjacamar with Eclipse Public License 1.0 | 4 votes |
/** * * Parse recovery tag * * @param reader reader * @return the parsed recovery object * @throws XMLStreamException in case of error * @throws ParserException in case of error * @throws ValidateException in case of error */ protected Recovery parseRecovery(XMLStreamReader reader) throws XMLStreamException, ParserException, ValidateException { Boolean noRecovery = Defaults.NO_RECOVERY; Credential security = null; Extension plugin = null; Map<String, String> expressions = new HashMap<String, String>(); for (int i = 0; i < reader.getAttributeCount(); i++) { switch (reader.getAttributeLocalName(i)) { case CommonXML.ATTRIBUTE_NO_RECOVERY : { noRecovery = attributeAsBoolean(reader, CommonXML.ATTRIBUTE_NO_RECOVERY, Boolean.FALSE, expressions); break; } default : break; } } while (reader.hasNext()) { switch (reader.nextTag()) { case END_ELEMENT : { switch (reader.getLocalName()) { case CommonXML.ELEMENT_RECOVERY : return new RecoveryImpl(security, plugin, noRecovery, !expressions.isEmpty() ? expressions : null); case CommonXML.ELEMENT_RECOVERY_CREDENTIAL : case CommonXML.ELEMENT_RECOVERY_PLUGIN : break; default : throw new ParserException(bundle.unexpectedEndTag(reader.getLocalName())); } } case START_ELEMENT : { switch (reader.getLocalName()) { case CommonXML.ELEMENT_RECOVERY_CREDENTIAL : { security = parseCredential(reader); break; } case CommonXML.ELEMENT_RECOVERY_PLUGIN : { plugin = parseExtension(reader, CommonXML.ELEMENT_RECOVERY_PLUGIN); break; } default : throw new ParserException(bundle.unexpectedElement(reader.getLocalName())); } break; } } } throw new ParserException(bundle.unexpectedEndOfDocument()); }
Example 19
Source File: XMLResponseParser.java From lucene-solr with Apache License 2.0 | 4 votes |
protected NamedList<Object> readNamedList( XMLStreamReader parser ) throws XMLStreamException { if( XMLStreamConstants.START_ELEMENT != parser.getEventType() ) { throw new RuntimeException( "must be start element, not: "+parser.getEventType() ); } StringBuilder builder = new StringBuilder(); NamedList<Object> nl = new SimpleOrderedMap<>(); KnownType type = null; String name = null; // just eat up the events... int depth = 0; while( true ) { switch (parser.next()) { case XMLStreamConstants.START_ELEMENT: depth++; builder.setLength( 0 ); // reset the text type = KnownType.get( parser.getLocalName() ); if( type == null ) { throw new RuntimeException( "this must be known type! not: "+parser.getLocalName() ); } name = null; int cnt = parser.getAttributeCount(); for( int i=0; i<cnt; i++ ) { if( "name".equals( parser.getAttributeLocalName( i ) ) ) { name = parser.getAttributeValue( i ); break; } } /** The name in a NamedList can actually be null if( name == null ) { throw new XMLStreamException( "requires 'name' attribute: "+parser.getLocalName(), parser.getLocation() ); } **/ if( !type.isLeaf ) { switch( type ) { case LST: nl.add( name, readNamedList( parser ) ); depth--; continue; case ARR: nl.add( name, readArray( parser ) ); depth--; continue; case RESULT: nl.add( name, readDocuments( parser ) ); depth--; continue; case DOC: nl.add( name, readDocument( parser ) ); depth--; continue; case BOOL: case DATE: case DOUBLE: case FLOAT: case INT: case LONG: case NULL: case STR: break; } throw new XMLStreamException( "branch element not handled!", parser.getLocation() ); } break; case XMLStreamConstants.END_ELEMENT: if( --depth < 0 ) { return nl; } //System.out.println( "NL:ELEM:"+type+"::"+name+"::"+builder ); nl.add( name, type.read( builder.toString().trim() ) ); break; case XMLStreamConstants.SPACE: // TODO? should this be trimmed? make sure it only gets one/two space? case XMLStreamConstants.CDATA: case XMLStreamConstants.CHARACTERS: builder.append( parser.getText() ); break; } } }
Example 20
Source File: XmlMetadataConsumer.java From olingo-odata2 with Apache License 2.0 | 4 votes |
private AnnotationElement readAnnotationElement(final XMLStreamReader reader) throws XMLStreamException { AnnotationElement aElement = new AnnotationElement(); List<AnnotationElement> annotationElements = new ArrayList<AnnotationElement>(); List<AnnotationAttribute> annotationAttributes = new ArrayList<AnnotationAttribute>(); aElement.setName(reader.getLocalName()); String elementNamespace = reader.getNamespaceURI(); if (!edmNamespaces.contains(elementNamespace)) { aElement.setPrefix(reader.getPrefix()); aElement.setNamespace(elementNamespace); } for (int i = 0; i < reader.getAttributeCount(); i++) { AnnotationAttribute annotationAttribute = new AnnotationAttribute(); annotationAttribute.setText(reader.getAttributeValue(i)); annotationAttribute.setName(reader.getAttributeLocalName(i)); annotationAttribute.setPrefix(reader.getAttributePrefix(i)); String namespace = reader.getAttributeNamespace(i); if (namespace != null && !isDefaultNamespace(namespace)) { annotationAttribute.setNamespace(namespace); } annotationAttributes.add(annotationAttribute); } if (!annotationAttributes.isEmpty()) { aElement.setAttributes(annotationAttributes); } boolean justRead = false; if (reader.hasNext()) { reader.next(); justRead = true; } while (justRead && !(reader.isEndElement() && aElement.getName() != null && aElement.getName().equals(reader.getLocalName()))) { justRead = false; if (reader.isStartElement()) { annotationElements.add(readAnnotationElement(reader)); if (reader.hasNext()) { reader.next(); justRead = true; } } else if (reader.isCharacters()) { String elementText = ""; do { justRead = false; elementText = elementText + reader.getText(); if (reader.hasNext()) { reader.next(); justRead = true; } } while (justRead && reader.isCharacters()); aElement.setText(elementText); } } if (!annotationElements.isEmpty()) { aElement.setChildElements(annotationElements); } return aElement; }