@SuppressWarnings("rawtypes") private Attribute getAttribute(int index) { if (!this.event.isStartElement()) { throw new IllegalStateException(); } int count = 0; Iterator attributes = this.event.asStartElement().getAttributes(); while (attributes.hasNext()) { Attribute attribute = (Attribute) attributes.next(); if (count == index) { return attribute; } else { count++; } } throw new IllegalArgumentException(); }
private StartElement withNamespace(StartElement startElement) { // otherwise, wrap the start element event to provide a default namespace mapping final List<Namespace> namespaces = new ArrayList<Namespace>(); namespaces.add( xmlEventFactory.createNamespace( "", namespaceUri ) ); Iterator<?> originalNamespaces = startElement.getNamespaces(); while ( originalNamespaces.hasNext() ) { namespaces.add( (Namespace) originalNamespaces.next() ); } return xmlEventFactory.createStartElement( new QName( namespaceUri, startElement.getName().getLocalPart() ), startElement.getAttributes(), namespaces.iterator() ); }
@Override public Object unmarshal(Source source) throws XmlMappingException, IOException { Attribute attr = null ; try { XMLEventReader eventReader = StaxTestUtils.getXmlEventReader( source); assertTrue(eventReader.nextEvent().isStartDocument()); StartElement event = eventReader.nextEvent().asStartElement(); attr = (Attribute) event.getAttributes().next(); } catch (Exception e) { throw new RuntimeException(e); } Foo foo = new Foo(); foo.setValue(Integer.parseInt(attr.getValue())); return foo; }
/** * Gets a value indicating whether this instance has attribute. * * @return boolean */ public boolean hasAttributes() { if (this.presentEvent.isStartElement()) { StartElement startElement = this.presentEvent.asStartElement(); return startElement.getAttributes().hasNext(); } else { return false; } }
private static boolean isEmptyBlockRunPropertiesElement(BlockProperty blockProperty) { return LOCAL_RUN_PROPERTIES.equals(blockProperty.getName().getLocalPart()) && 2 == blockProperty.getEvents().size() && !blockProperty.getEvents().get(0).asStartElement().getAttributes().hasNext(); }
private Element copyAttributes(StartElement source, Element destination) { for (Attribute attribute : forwardOnly(Unchecked.<Iterator<Attribute>>cast(source.getAttributes()))) { destination.setAttribute(attribute.getName().getLocalPart(), attribute.getValue()); } return destination; }
private Attributes getAttributes(StartElement event) { AttributesImpl attributes = new AttributesImpl(); for (Iterator i = event.getAttributes(); i.hasNext();) { Attribute attribute = (Attribute) i.next(); QName qName = attribute.getName(); String namespace = qName.getNamespaceURI(); if (namespace == null || !hasNamespacesFeature()) { type = "CDATA"; attributes.addAttribute(namespace, qName.getLocalPart(), toQualifiedName(qName), type, attribute.getValue()); for (Iterator i = event.getNamespaces(); i.hasNext();) { Namespace namespace = (Namespace) i.next(); String prefix = namespace.getPrefix(); String namespaceUri = namespace.getNamespaceURI();
@SuppressWarnings("rawtypes") private Attribute getAttribute(int index) { if (!this.event.isStartElement()) { throw new IllegalStateException(); } int count = 0; Iterator attributes = this.event.asStartElement().getAttributes(); while (attributes.hasNext()) { Attribute attribute = (Attribute) attributes.next(); if (count == index) { return attribute; } else { count++; } } throw new IllegalArgumentException(); }
@Override public Object unmarshal(Source source) throws XmlMappingException, IOException { Attribute attr; try { XMLEventReader eventReader = StaxTestUtils.getXmlEventReader(source ); assertTrue(eventReader.nextEvent().isStartDocument()); StartElement event = eventReader.nextEvent().asStartElement(); attr = (Attribute) event.getAttributes().next(); } catch ( Exception e) { throw new RuntimeException(e); } Foo foo = new Foo(); foo.setValue(Integer.parseInt(attr.getValue())); return foo; }
private List<Attribute> updateElementAttributes(StartElement startElement) { // adjust the version attribute List<Attribute> newElementAttributeList = new ArrayList<Attribute>(); Iterator<?> existingAttributesIterator = startElement.getAttributes(); while ( existingAttributesIterator.hasNext() ) { Attribute attribute = (Attribute) existingAttributesIterator.next(); if ( VERSION_ATTRIBUTE_NAME.equals( attribute.getName().getLocalPart() ) ) { if ( !DEFAULT_VERSION.equals( attribute.getName().getPrefix() ) ) { newElementAttributeList.add( xmlEventFactory.createAttribute( attribute.getName(), DEFAULT_VERSION ) ); } } else { newElementAttributeList.add( attribute ); } } return newElementAttributeList; } }
/** * Returns the next XML event for the document being parsed. * * @return The next XML event for the document being parsed. * * @throws XMLStreamException */ public XMLEvent nextEvent() throws XMLStreamException { if (attributeIterator != null && attributeIterator.hasNext()) { currentEvent = (XMLEvent)attributeIterator.next(); } else { currentEvent = eventReader.nextEvent(); } if (currentEvent.isStartElement()) { attributeIterator = currentEvent.asStartElement().getAttributes(); } updateContext(currentEvent); if (eventReader.hasNext()) { XMLEvent nextEvent = eventReader.peek(); if (nextEvent != null && nextEvent.isCharacters()) { for (MetadataExpression metadataExpression : metadataExpressions) { if (testExpression(metadataExpression.expression, metadataExpression.targetDepth)) { metadata.put(metadataExpression.key, nextEvent.asCharacters().getData()); } } } } return currentEvent; }
private void handleStartElement(StartElement startElement) throws SAXException { if (getContentHandler() != null) { QName qName = startElement.getName(); if (hasNamespacesFeature()) { for (Iterator i = startElement.getNamespaces(); i.hasNext();) { Namespace namespace = (Namespace) i.next(); startPrefixMapping(namespace.getPrefix(), namespace.getNamespaceURI()); } for (Iterator i = startElement.getAttributes(); i.hasNext();){ Attribute attribute = (Attribute) i.next(); QName attributeName = attribute.getName(); startPrefixMapping(attributeName.getPrefix(), attributeName.getNamespaceURI()); } getContentHandler().startElement(qName.getNamespaceURI(), qName.getLocalPart(), toQualifiedName(qName), getAttributes(startElement)); } else { getContentHandler().startElement("", "", toQualifiedName(qName), getAttributes(startElement)); } } }
@SuppressWarnings( "unchecked" ) private Object[] parseAttributes( Object[] outputRowData, XMLEvent e ) throws KettleValueException, KettleStepException { Iterator<Attribute> iter = e.asStartElement().getAttributes(); if ( iter.hasNext() ) { Object[] outputRowDataAttribute = data.outputRowMeta.cloneRow( outputRowData ); putRowOut( outputRowDataAttribute ); // first put the element name (or namespace) info out // change data_type to ATTRIBUTE if ( data.pos_xml_data_type_numeric != -1 ) { outputRowData[data.pos_xml_data_type_numeric] = new Long( XMLStreamConstants.ATTRIBUTE ); } if ( data.pos_xml_data_type_description != -1 ) { outputRowData[data.pos_xml_data_type_description] = eventDescription[XMLStreamConstants.ATTRIBUTE]; } } while ( iter.hasNext() ) { Object[] outputRowDataAttribute = data.outputRowMeta.cloneRow( outputRowData ); Attribute a = iter.next(); parseAttribute( outputRowDataAttribute, a, meta.isEnableNamespaces() ); if ( iter.hasNext() ) { // send out the Attribute row putRowOut( outputRowDataAttribute ); } else { // last row: this will be sent out by the outer loop outputRowData = outputRowDataAttribute; } } return outputRowData; }
private Attributes getAttributes(StartElement event) { AttributesImpl attributes = new AttributesImpl(); for (Iterator i = event.getAttributes(); i.hasNext();) { Attribute attribute = (Attribute) i.next(); QName qName = attribute.getName(); String namespace = qName.getNamespaceURI(); if (namespace == null || !hasNamespacesFeature()) { type = "CDATA"; attributes.addAttribute(namespace, qName.getLocalPart(), toQualifiedName(qName), type, attribute.getValue()); for (Iterator i = event.getNamespaces(); i.hasNext();) { Namespace namespace = (Namespace) i.next(); String prefix = namespace.getPrefix(); String namespaceUri = namespace.getNamespaceURI();
private Attribute getAttribute(int index) { if (!event.isStartElement()) { throw new IllegalStateException(); } int count = 0; Iterator attributes = event.asStartElement().getAttributes(); while (attributes.hasNext()) { Attribute attribute = (Attribute) attributes.next(); if (count == index) { return attribute; } else { count++; } } throw new IllegalArgumentException(); }
for (Iterator i = event.getAttributes(); i.hasNext();) { Attribute staxAttr = (Attribute)i.next(); QName name = staxAttr.getName(); String uri = fixNull(name.getNamespaceURI()); String localName = name.getLocalPart(); String prefix = name.getPrefix(); String qName; qName = prefix + ':' + localName; String type = staxAttr.getDTDType(); String value = staxAttr.getValue();
/** * Returns the next XML event for the document being parsed. * * @return The next XML event for the document being parsed. * * @throws XMLStreamException */ public XMLEvent nextEvent() throws XMLStreamException { if (attributeIterator != null && attributeIterator.hasNext()) { currentEvent = (XMLEvent)attributeIterator.next(); } else { currentEvent = eventReader.nextEvent(); } if (currentEvent.isStartElement()) { attributeIterator = currentEvent.asStartElement().getAttributes(); } updateContext(currentEvent); if (eventReader.hasNext()) { XMLEvent nextEvent = eventReader.peek(); if (nextEvent != null && nextEvent.isCharacters()) { for (MetadataExpression metadataExpression : metadataExpressions) { if (testExpression(metadataExpression.expression, metadataExpression.targetDepth)) { metadata.put(metadataExpression.key, nextEvent.asCharacters().getData()); } } } } return currentEvent; }
private void handleStartElement(StartElement startElement) throws SAXException { if (getContentHandler() != null) { QName qName = startElement.getName(); if (hasNamespacesFeature()) { for (Iterator i = startElement.getNamespaces(); i.hasNext();) { Namespace namespace = (Namespace) i.next(); startPrefixMapping(namespace.getPrefix(), namespace.getNamespaceURI()); } for (Iterator i = startElement.getAttributes(); i.hasNext();){ Attribute attribute = (Attribute) i.next(); QName attributeName = attribute.getName(); startPrefixMapping(attributeName.getPrefix(), attributeName.getNamespaceURI()); } getContentHandler().startElement(qName.getNamespaceURI(), qName.getLocalPart(), toQualifiedName(qName), getAttributes(startElement)); } else { getContentHandler().startElement("", "", toQualifiedName(qName), getAttributes(startElement)); } } }
final List<Namespace> targetNamespaces = new ArrayList<Namespace>(); if ( "".equals( startElement.getName().getNamespaceURI() ) ) { while ( originalNamespaces.hasNext() ) { Namespace namespace = originalNamespaces.next(); if ( NAMESPACE_URIS_TO_MAP.contains( namespace.getNamespaceURI() ) ) { new QName( MappingXsdSupport.INSTANCE.hbmXsd().getNamespaceUri(), startElement.getName().getLocalPart() ), startElement.getAttributes(), targetNamespaces.iterator() );
NodeInfo currentNode = new NodeInfo(currentElement); if (parsed.isEmpty()) { if (!currentElement.getName().equals(configuration)) { return null; QName parentName = parentNode.getStartElement().getName(); if (parentName.equals(configuration) && currentNode.getStartElement().getName().equals(property)) { @SuppressWarnings("unchecked") Iterator<Attribute> it = currentElement.getAttributes(); while (it.hasNext()) { currentNode.addAttribute(it.next());