/** * @param namespaceURI * @param localName * @return */ public String getAttributeValue(String namespaceURI, String localName) { //State should be either START_ELEMENT or ATTRIBUTE if( fEventType == XMLEvent.START_ELEMENT || fEventType == XMLEvent.ATTRIBUTE) { XMLAttributesImpl attributes = fScanner.getAttributeIterator(); if (namespaceURI == null) { //sjsxp issue 70 return attributes.getValue(attributes.getIndexByLocalName(localName)) ; } else { return fScanner.getAttributeIterator().getValue( namespaceURI.length() == 0 ? null : namespaceURI, localName) ; } } else{ throw new java.lang.IllegalStateException("Current state is not among the states " + getEventTypeString(XMLEvent.START_ELEMENT) + " , " + getEventTypeString(XMLEvent.ATTRIBUTE) + "valid for getAttributeValue()") ; } }
public static TsoFrequencySecurityIndex fromXml(String contingencyId, XMLStreamReader xmlsr) throws XMLStreamException { String text = null; while (xmlsr.hasNext()) { int eventType = xmlsr.next(); switch (eventType) { case XMLEvent.CHARACTERS: text = xmlsr.getText(); break; case XMLEvent.END_ELEMENT: if ("freq-out-count".equals(xmlsr.getLocalName())) { return new TsoFrequencySecurityIndex(contingencyId, Integer.parseInt(text)); } break; default: break; } } throw new AssertionError("freq-out-count element not found"); }
public void eventReaderTest(XMLInputFactory xif) { XMLEventReader eventReader = null; try { eventReader = xif.createXMLEventReader(this.getClass().getResourceAsStream(INPUT_FILE)); XMLEventReader filteredEventReader = xif.createFilteredReader(eventReader, new EventFilter() { public boolean accept(XMLEvent event) { if (!event.isStartElement()) { return false; } QName elementQName = event.asStartElement().getName(); if ((elementQName.getLocalPart().equals(ATTACHMENT_NAME.getLocalPart()) || elementQName.getLocalPart().equals("Attachment")) && elementQName.getNamespaceURI().equals(VF_GENERIC_TT_NAMESPACE)) { return true; } return false; } }); if (filteredEventReader.hasNext()) { System.out.println("containsAttachments() returns true"); } } catch (Exception e) { e.printStackTrace(); Assert.fail(e.getMessage()); } finally { if (eventReader != null) { try { eventReader.close(); } catch (XMLStreamException xse) { // Ignored by intention } } } }
@Override public final XMLEvent nextTag() throws XMLStreamException { XMLEvent event = this.nextEvent(); while ((event.isCharacters() && event.asCharacters().isWhiteSpace()) || event.isProcessingInstruction() || event.getEventType() == XMLStreamConstants.COMMENT) { event = this.nextEvent(); } if (!event.isStartElement() && event.isEndElement()) { throw new XMLStreamException("Unexpected event type '" + XMLStreamConstantsUtils.getEventName(event.getEventType()) + "' encountered. Found event: " + event, event.getLocation()); } return event; }
public void reset(PropertyManager propertyManager) { super.reset(propertyManager); // other settings fDoctypeName = null; fDoctypePublicId = null; fDoctypeSystemId = null; fSeenDoctypeDecl = false; fNamespaceContext.reset(); fSupportDTD = ((Boolean)propertyManager.getProperty(XMLInputFactory.SUPPORT_DTD)).booleanValue(); // xerces features fLoadExternalDTD = !((Boolean)propertyManager.getProperty(Constants.ZEPHYR_PROPERTY_PREFIX + Constants.IGNORE_EXTERNAL_DTD)).booleanValue(); setScannerState(XMLEvent.START_DOCUMENT); setDriver(fXMLDeclDriver); fSeenInternalSubset = false; if(fDTDScanner != null){ ((XMLDTDScannerImpl)fDTDScanner).reset(propertyManager); } fEndPos = 0; fStartPos = 0; if(fDTDDecl != null){ fDTDDecl.clear(); } }
private Document toDom4jDocument(XMLEventReader staxEventReader, Origin origin) { STAXEventReader dom4jStaxEventReader = new STAXEventReader(); try { // the dom4j converter class is touchy about comments (aka, comments make it implode) // so wrap the event stream in a filtering stream to filter out comment events staxEventReader = new FilteringXMLEventReader( staxEventReader ) { @Override protected XMLEvent filterEvent(XMLEvent event, boolean peek) { return event.getEventType() == XMLStreamConstants.COMMENT ? null : event; } }; return dom4jStaxEventReader.readDocument( staxEventReader ); } catch (XMLStreamException e) { throw new InvalidMappingException( "Unable to read StAX source as dom4j Document for processing", origin, e ); } }
public String getElementText() throws XMLStreamException { StringBuffer buffer = new StringBuffer(); XMLEvent e = nextEvent(); if (!e.isStartElement()) throw new XMLStreamException( CommonResourceBundle.getInstance().getString("message.mustBeOnSTART_ELEMENT")); while(hasNext()) { e = nextEvent(); if(e.isStartElement()) throw new XMLStreamException( CommonResourceBundle.getInstance().getString("message.getElementTextExpectTextOnly")); if(e.isCharacters()) buffer.append(((Characters) e).getData()); if(e.isEndElement()) return buffer.toString(); } throw new XMLStreamException(CommonResourceBundle.getInstance().getString("message.END_ELEMENTnotFound")); }
/** * Returns the text contents of the current element being parsed. * * @return The text contents of the current element being parsed. * @throws XMLStreamException */ public String readText() throws XMLStreamException { if (isInsideResponseHeader()) { return getHeader(currentHeader); } if (currentEvent.isAttribute()) { Attribute attribute = (Attribute)currentEvent; return attribute.getValue(); } StringBuilder sb = new StringBuilder(); while (true) { XMLEvent event = eventReader.peek(); if (event.getEventType() == XMLStreamConstants.CHARACTERS) { eventReader.nextEvent(); sb.append(event.asCharacters().getData()); } else if (event.getEventType() == XMLStreamConstants.END_ELEMENT) { return sb.toString(); } else { throw new RuntimeException("Encountered unexpected event: " + event.toString()); } } }
private void handleStartDocument(final XMLEvent event) throws SAXException { _sax.setDocumentLocator(new Locator2() { public int getColumnNumber() { return event.getLocation().getColumnNumber(); } public int getLineNumber() { return event.getLocation().getLineNumber(); } public String getPublicId() { return event.getLocation().getPublicId(); } public String getSystemId() { return event.getLocation().getSystemId(); } public String getXMLVersion(){ return version; } public String getEncoding(){ return encoding; } }); _sax.startDocument(); }
@Test public void testLocation() { String XML = "<?xml version='1.0' ?>" + "<!DOCTYPE root [\n" + "<!ENTITY intEnt 'internal'>\n" + "<!ENTITY extParsedEnt SYSTEM 'url:dummy'>\n" + "<!NOTATION notation PUBLIC 'notation-public-id'>\n" + "<!NOTATION notation2 SYSTEM 'url:dummy'>\n" + "<!ENTITY extUnparsedEnt SYSTEM 'url:dummy2' NDATA notation>\n" + "]>\n" + "<root />"; try { XMLEventReader er = getReader(XML); XMLEvent evt = er.nextEvent(); // StartDocument Location loc1 = evt.getLocation(); System.out.println("Location 1: " + loc1.getLineNumber() + "," + loc1.getColumnNumber()); evt = er.nextEvent(); // DTD // loc1 should not change so its line number should still be 1 Assert.assertTrue(loc1.getLineNumber() == 1); Location loc2 = evt.getLocation(); System.out.println("Location 2: " + loc2.getLineNumber() + "," + loc2.getColumnNumber()); evt = er.nextEvent(); // root System.out.println("Location 1: " + loc1.getLineNumber() + "," + loc1.getColumnNumber()); Assert.assertTrue(loc1.getLineNumber() == 1); Assert.assertTrue(loc2.getLineNumber() == 7); } catch (Exception e) { Assert.fail(e.getMessage()); } }
/** * Test: 6419687 NPE in XMLEventWriterImpl. */ @Test public void testCR6419687() { try { InputStream in = getClass().getResourceAsStream("ReaderToWriterTest.wsdl"); OutputStream out = new FileOutputStream(USER_DIR + "ReaderToWriterTest-out.xml"); XMLEventReader reader = XML_INPUT_FACTORY.createXMLEventReader(in); XMLEventWriter writer = XML_OUTPUT_FACTORY.createXMLEventWriter(out, "UTF-8"); while (reader.hasNext()) { XMLEvent event = reader.nextEvent(); writer.add(event); } reader.close(); writer.close(); } catch (XMLStreamException xmlStreamException) { xmlStreamException.printStackTrace(); Assert.fail(xmlStreamException.toString()); } catch (FileNotFoundException fileNotFoundException) { fileNotFoundException.printStackTrace(); Assert.fail(fileNotFoundException.toString()); } }
/** * @param namespaceURI * @param localName * @return */ public String getAttributeValue(String namespaceURI, String localName) { //State should be either START_ELEMENT or ATTRIBUTE if (fEventType == XMLEvent.START_ELEMENT || fEventType == XMLEvent.ATTRIBUTE) { XMLAttributesImpl attributes = fScanner.getAttributeIterator(); if (namespaceURI == null) { //sjsxp issue 70 return attributes.getValue(attributes.getIndexByLocalName(localName)); } else { return fScanner.getAttributeIterator().getValue( namespaceURI.length() == 0 ? null : namespaceURI, localName); } } else { throw new java.lang.IllegalStateException("Current state is not among the states " + getEventTypeString(XMLEvent.START_ELEMENT) + " , " + getEventTypeString(XMLEvent.ATTRIBUTE) + "valid for getAttributeValue()"); } }
private void switchToXML11Scanner() throws IOException{ int oldEntityDepth = fScanner.fEntityDepth; com.sun.org.apache.xerces.internal.xni.NamespaceContext oldNamespaceContext = fScanner.fNamespaceContext; fScanner = new XML11NSDocumentScannerImpl(); //get the new scanner state to old scanner's previous state fScanner.reset(fPropertyManager); fScanner.setPropertyManager(fPropertyManager); fEntityScanner = (XMLEntityScanner)fEntityManager.getEntityScanner() ; fEntityManager.fCurrentEntity.mayReadChunks = true; fScanner.setScannerState(XMLEvent.START_DOCUMENT); fScanner.fEntityDepth = oldEntityDepth; fScanner.fNamespaceContext = oldNamespaceContext; fEventType = fScanner.next(); }
/** * @bug 8139584 * Verifies that the resulting XML contains the standalone setting. */ @Test public void testCreateStartDocument_DOMWriter() throws ParserConfigurationException, XMLStreamException { XMLOutputFactory xof = XMLOutputFactory.newInstance(); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document doc = db.newDocument(); XMLEventWriter eventWriter = xof.createXMLEventWriter(new DOMResult(doc)); XMLEventFactory eventFactory = XMLEventFactory.newInstance(); XMLEvent event = eventFactory.createStartDocument("iso-8859-15", "1.0", true); eventWriter.add(event); eventWriter.flush(); Assert.assertEquals(doc.getXmlEncoding(), "iso-8859-15"); Assert.assertEquals(doc.getXmlVersion(), "1.0"); Assert.assertTrue(doc.getXmlStandalone()); }
/** * Reads the data from the {@link XMLEvent} and returns it. CData * will be handled special. * @param event {@link XMLEvent} * @param eventReader Reader for Reading {@link XMLEvent} * @return Character data from element * @throws XMLStreamException */ private String getCharacterData(XMLEvent event, final XMLEventReader eventReader) throws XMLStreamException { String result = ""; event = eventReader.nextEvent(); if (event instanceof Characters) { result = event.asCharacters().getData(); } return result; }
/** * Creates a new Parser Object. * @param contentSource - {@link ContentSource} to parse * @param inputStream - Created {@link InputStream} providing the RSS feed to parse. */ public DefaultRssParser(final ContentSource contentSource, final InputStream inputStream) { super(contentSource, inputStream); availableSetters = new String [] {"setTitle", "setDescription", "setLink", "setImage", "setWidth", "setHeight", "setPubDate", "setEnclosure", "setLastBuildDate"}; try { startElementMethods.put(RSS, ObjectUtil.assertNotNull(getDeclaredMethod("createParsingElement", String.class, XMLEvent.class, XMLEventReader.class), RSS)); startElementMethods.put(CHANNEL, ObjectUtil.assertNotNull(getDeclaredMethod("pushElementIntoMap", String.class, XMLEvent.class, XMLEventReader.class), CHANNEL)); startElementMethods.put(ITEM, ObjectUtil.assertNotNull(getDeclaredMethod("pushElementIntoMap", String.class, XMLEvent.class, XMLEventReader.class), ITEM)); // used for the channel startElementMethods.put(LAST_BUILD_DATE, ObjectUtil.assertNotNull(getDeclaredMethod("parseStandardElement", String.class, XMLEvent.class, XMLEventReader.class), LAST_BUILD_DATE)); // used only in item startElementMethods.put(TITLE, ObjectUtil.assertNotNull(getDeclaredMethod("parseStandardElement", String.class, XMLEvent.class, XMLEventReader.class), TITLE)); startElementMethods.put(LINK, ObjectUtil.assertNotNull(getDeclaredMethod("parseStandardElement", String.class, XMLEvent.class, XMLEventReader.class), LINK)); startElementMethods.put(DESCRIPTION, ObjectUtil.assertNotNull(getDeclaredMethod("parseStandardElement", String.class, XMLEvent.class, XMLEventReader.class), DESCRIPTION)); startElementMethods.put(LANGUAGE, ObjectUtil.assertNotNull(getDeclaredMethod("parseStandardElement", String.class, XMLEvent.class, XMLEventReader.class), LANGUAGE)); startElementMethods.put(PUB_DATE, ObjectUtil.assertNotNull(getDeclaredMethod("parseStandardElement", String.class, XMLEvent.class, XMLEventReader.class), PUB_DATE)); startElementMethods.put(IMAGE, ObjectUtil.assertNotNull(getDeclaredMethod("parseStandardElement", String.class, XMLEvent.class, XMLEventReader.class), IMAGE)); startElementMethods.put(ENCLOSURE, ObjectUtil.assertNotNull(getDeclaredMethod("parseStandardElement", String.class, XMLEvent.class, XMLEventReader.class), ENCLOSURE)); endElementMehods.put(CHANNEL, ObjectUtil.assertNotNull(getDeclaredMethod("popElementFromStack"), CHANNEL)); endElementMehods.put(ITEM, ObjectUtil.assertNotNull(getDeclaredMethod("popElementFromStack"), ITEM)); specialMethods.put(ITEM, ObjectUtil.assertNotNull(getDeclaredMethod("createItemObject"), ITEM)); } catch (final SecurityException e) { LOGGER.error("Failed creating {} because", getClass(), e ); } }
/** Returns the value of the attribute at the * index * @param index the position of the attribute * @return the attribute value * @throws IllegalStateException if this is not a START_ELEMENT or ATTRIBUTE */ public String getAttributeValue(int index) { //State should be either START_ELEMENT or ATTRIBUTE if( fEventType == XMLEvent.START_ELEMENT || fEventType == XMLEvent.ATTRIBUTE) { return fScanner.getAttributeIterator().getValue(index) ; } else{ throw new java.lang.IllegalStateException("Current state is not among the states " + getEventTypeString(XMLEvent.START_ELEMENT) + " , " + getEventTypeString(XMLEvent.ATTRIBUTE) + "valid for getAttributeValue()") ; } }
/** * @return */ public String getNamespaceURI() { //doesn't take care of Attribute as separte event if (fEventType == XMLEvent.START_ELEMENT || fEventType == XMLEvent.END_ELEMENT) { return fScanner.getElementQName().uri; } return null; }
/** * @return */ public char[] getTextCharacters() { if (fEventType == XMLEvent.CHARACTERS || fEventType == XMLEvent.COMMENT || fEventType == XMLEvent.CDATA || fEventType == XMLEvent.SPACE) { return fScanner.getCharacterData().ch; } else { throw new IllegalStateException("Current state = " + getEventTypeString(fEventType) + " is not among the states " + getEventTypeString(XMLEvent.CHARACTERS) + " , " + getEventTypeString(XMLEvent.COMMENT) + " , " + getEventTypeString(XMLEvent.CDATA) + " , " + getEventTypeString(XMLEvent.SPACE) + " valid for getTextCharacters() "); } }
private static void testNextEvent(int max) throws IOException, XMLStreamException { System.out.println("\nTest nextEvent (" + max + ")..."); XMLEventReader reader = createXmlReader(max); XMLEvent event; do { event = reader.nextEvent(); System.out.println(event); } while (event.getEventType() != XMLEvent.END_DOCUMENT); System.out.println("nextEvent passed\n"); }
@Override public void add(XMLEvent event) throws XMLStreamException { XMLEvent newEvent = null; if (event.isStartElement()) { StartElement startElement = event.asStartElement(); newEvent = anonymizeStartElement(startElement); } else if (event.isCharacters()) { Characters characters = event.asCharacters(); newEvent = anonymizeCharacters(characters); } super.add(newEvent != null ? newEvent : event); }
private T verwerkChildElementenEnElementEinde(final String elementNaam, final ParserContext context) throws ParseException { while (context.heeftVolgendeEvent()) { final int event = context.volgendeEvent(); if (XMLEvent.START_ELEMENT == event) { verwerkChildElement(context); } else if (XMLEvent.END_ELEMENT == event) { if (!elementNaam.equals(context.getEventNaam())) { throw new ParseException( String.format("Onverwacht element einde '%s'. Verwacht einde element is '%s'.", context.getEventNaam(), elementNaam)); } return verwerkEindeElement(context); } } throw new ParseException(String.format("Er is geen einde tag gevonden voor element '%s'", elementNaam)); }
@Test public void testEventReader() { try { XMLInputFactory ifac = XMLInputFactory.newInstance(); XMLEventReader read = ifac.createXMLEventReader(this.getClass().getResource(INPUT_FILE).toExternalForm(), this.getClass().getResourceAsStream(INPUT_FILE)); while (read.hasNext()) { XMLEvent event = read.nextEvent(); if (event.isStartElement()) { StartElement startElement = event.asStartElement(); if (startElement.getName().getLocalPart().equals("bookurn")) { Iterator iterator = startElement.getNamespaces(); int count = 0; while (iterator.hasNext()) { iterator.next(); count++; } Assert.assertTrue(count == 2, "Two namespaces are expected for <bookurn> "); Iterator attributes = startElement.getAttributes(); count = 0; while (attributes.hasNext()) { iterator.next(); count++; } Assert.assertTrue(count == 0, "Zero attributes are expected for <bookurn> "); } } } } catch (Exception e) { e.printStackTrace(); Assert.fail("Exception occured: " + e.getMessage()); } }
/** * Returns the value of the attribute at the index * * @param index the position of the attribute * @return the attribute value * @throws IllegalStateException if this is not a START_ELEMENT or ATTRIBUTE */ public String getAttributeValue(int index) { //State should be either START_ELEMENT or ATTRIBUTE if (fEventType == XMLEvent.START_ELEMENT || fEventType == XMLEvent.ATTRIBUTE) { return fScanner.getAttributeIterator().getValue(index); } else { throw new java.lang.IllegalStateException("Current state is not among the states " + getEventTypeString(XMLEvent.START_ELEMENT) + " , " + getEventTypeString(XMLEvent.ATTRIBUTE) + "valid for getAttributeValue()"); } }
public TypeFilter createFilter() { TypeFilter f = new TypeFilter(); f.addType(XMLEvent.START_ELEMENT); f.addType(XMLEvent.END_ELEMENT); f.addType(XMLEvent.PROCESSING_INSTRUCTION); f.addType(XMLEvent.CHARACTERS); f.addType(XMLEvent.COMMENT); f.addType(XMLEvent.SPACE); f.addType(XMLEvent.START_DOCUMENT); f.addType(XMLEvent.END_DOCUMENT); return f; }
public static TsoDisconnectedGenerator fromXml(String contingencyId, XMLStreamReader xmlsr) throws XMLStreamException { String text = null; Map<String, Float> disconnectedGenerators = new HashMap<>(); String id = null; while (xmlsr.hasNext()) { int eventType = xmlsr.next(); switch (eventType) { case XMLEvent.CHARACTERS: text = xmlsr.getText(); break; case XMLEvent.START_ELEMENT: if ("generator".equals(xmlsr.getLocalName())) { id = xmlsr.getAttributeValue(null, "id"); } break; case XMLEvent.END_ELEMENT: switch (xmlsr.getLocalName()) { case "generator": if (id == null) { throw new AssertionError(); } float p = Float.parseFloat(text); disconnectedGenerators.put(id, p); id = null; break; case "index": return new TsoDisconnectedGenerator(contingencyId, disconnectedGenerators); default: throw new AssertionError("Unexpected element: " + xmlsr.getLocalName()); } break; default: break; } } throw new AssertionError("Should not happen"); }
@Test public void test1() { try { XMLInputFactory xif = XMLInputFactory.newInstance(); XMLStreamReader xsr = xif.createXMLStreamReader(getClass().getResource("sgml.xml").toString(), getClass().getResourceAsStream("sgml.xml")); XMLEventReader xer = xif.createXMLEventReader(xsr); Assert.assertTrue(xer.nextEvent().getEventType() == XMLEvent.START_DOCUMENT); xsr.close(); } catch (Exception e) { Assert.fail(e.getMessage()); } }
/** Skips any insignificant space events until a START_ELEMENT or * END_ELEMENT is reached. If anything other than space characters are * encountered, an exception is thrown. This method should * be used when processing element-only content because * the parser is not able to recognize ignorable whitespace if * the DTD is missing or not interpreted. * @throws XMLStreamException if anything other than space characters are encountered */ public XMLEvent nextTag() throws XMLStreamException { //its really a pain if there is peeked event before calling nextTag() if(fPeekedEvent != null){ //check the peeked event first. XMLEvent event = fPeekedEvent; fPeekedEvent = null ; int eventType = event.getEventType(); //if peeked event is whitespace move to the next event //if peeked event is PI or COMMENT move to the next event if( (event.isCharacters() && event.asCharacters().isWhiteSpace()) || eventType == XMLStreamConstants.PROCESSING_INSTRUCTION || eventType == XMLStreamConstants.COMMENT || eventType == XMLStreamConstants.START_DOCUMENT){ event = nextEvent(); eventType = event.getEventType(); } //we have to have the while loop because there can be many PI or comment event in sucession while((event.isCharacters() && event.asCharacters().isWhiteSpace()) || eventType == XMLStreamConstants.PROCESSING_INSTRUCTION || eventType == XMLStreamConstants.COMMENT){ event = nextEvent(); eventType = event.getEventType(); } if (eventType != XMLStreamConstants.START_ELEMENT && eventType != XMLStreamConstants.END_ELEMENT) { throw new XMLStreamException("expected start or end tag", event.getLocation()); } return event; } //if there is no peeked event -- delegate the work of getting next event to fXMLReader fXMLReader.nextTag(); return (fLastEvent = fXMLEventAllocator.allocate(fXMLReader)); }
public int next() throws IOException, XNIException{ dispatch(true); //xxx: remove this hack and align this with reusing DTD components //currently this routine will only be executed from Stax if(fPropertyManager != null){ dtdGrammarUtil = new DTDGrammarUtil(((XMLDTDScannerImpl)fDTDScanner).getGrammar(),fSymbolTable, fNamespaceContext); } return XMLEvent.DTD ; }
/** * DTDEvent instances constructed via event reader are missing the notation * and entity declaration information */ @Test public void testDTDEvent() { String XML = "<?xml version='1.0' ?>" + "<!DOCTYPE root [\n" + "<!ENTITY intEnt 'internal'>\n" + "<!ENTITY extParsedEnt SYSTEM 'url:dummy'>\n" + "<!NOTATION notation PUBLIC 'notation-public-id'>\n" + "<!NOTATION notation2 SYSTEM 'url:dummy'>\n" + "<!ENTITY extUnparsedEnt SYSTEM 'url:dummy2' NDATA notation>\n" + "]>" + "<root />"; try { XMLEventReader er = getReader(XML); XMLEvent evt = er.nextEvent(); // StartDocument evt = er.nextEvent(); // DTD if (evt.getEventType() != XMLStreamConstants.DTD) { Assert.fail("Expected DTD event"); } DTD dtd = (DTD) evt; writeAsEncodedUnicode(dtd); List entities = dtd.getEntities(); if (entities == null) { Assert.fail("No entity found. Expected 3."); } else { writeAsEncodedUnicode((XMLEvent) entities.get(0)); writeAsEncodedUnicode((XMLEvent) entities.get(1)); writeAsEncodedUnicode((XMLEvent) entities.get(2)); } List notations = dtd.getNotations(); if (notations == null) { Assert.fail("No notation found. Expected 2."); } else { writeAsEncodedUnicode((XMLEvent) notations.get(0)); writeAsEncodedUnicode((XMLEvent) notations.get(1)); } } catch (Exception e) { Assert.fail(e.getMessage()); } }
private void readGraph(XMLStreamReader reader) throws XMLStreamException { while (reader.hasNext()) { int eventType = reader.next(); if (eventType != XMLEvent.START_ELEMENT) { continue; } String elementName = reader.getLocalName(); if (elementName.equals("node")) { readNodeElement(reader); } else if (elementName.equals("way")) { readWayElement(reader); } } }
@Override public XMLEvent nextEvent() throws XMLStreamException { XMLEvent event = super.nextEvent(); if ( event.isStartElement() ) { return withNamespace( event.asStartElement() ); } return event; }
/** Returns the qname of the attribute at the provided index * * @param index the position of the attribute * @return the QName of the attribute * @throws IllegalStateException if this is not a START_ELEMENT or ATTRIBUTE */ public javax.xml.namespace.QName getAttributeQName(int index) { //State should be either START_ELEMENT or ATTRIBUTE if( fEventType == XMLEvent.START_ELEMENT || fEventType == XMLEvent.ATTRIBUTE) { // create new object at runtime.. String localName = fScanner.getAttributeIterator().getLocalName(index) ; String uri = fScanner.getAttributeIterator().getURI(index) ; return new javax.xml.namespace.QName(uri, localName) ; } else{ throw new java.lang.IllegalStateException("Current state is not among the states " + getEventTypeString(XMLEvent.START_ELEMENT) + " , " + getEventTypeString(XMLEvent.ATTRIBUTE) + "valid for getAttributeQName()") ; } }
@Override public XMLEvent peek() throws XMLStreamException { if (this.bufferReader != null) { final XMLEvent event = this.bufferReader.next(); this.bufferReader.previous(); //move the iterator back return event; } return super.peek(); }
@Override public final XMLEvent peek() throws XMLStreamException { if (peekedEvent != null) { return peekedEvent; } peekedEvent = internalNext(true); return peekedEvent; }
private void writeEvents(XMLEventReader reader, XMLEventWriter writer) throws XMLStreamException { while (reader.hasNext()) { XMLEvent event = reader.nextEvent(); writer.add(event); } reader.close(); writer.close(); }
@Override public S3KeyFilter unmarshall(StaxUnmarshallerContext context) throws Exception { int originalDepth = context.getCurrentDepth(); int targetDepth = originalDepth + 1; if (context.isStartOfDocument()) { targetDepth += 1; } S3KeyFilter filter = new S3KeyFilter(); while (true) { XMLEvent xmlEvent = context.nextEvent(); if (xmlEvent.isEndDocument()) { return filter; } if (xmlEvent.isAttribute() || xmlEvent.isStartElement()) { if (context.testExpression("FilterRule", targetDepth)) { filter.addFilterRule(FilterRuleStaxUnmarshaller.getInstance().unmarshall(context)); } } else if (xmlEvent.isEndElement()) { if (context.getCurrentDepth() < originalDepth) { return filter; } } } }
/** Returns the prefix of this attribute at the * provided index * @param index the position of the attribute * @return the prefix of the attribute * @throws IllegalStateException if this is not a START_ELEMENT or ATTRIBUTE */ public String getAttributePrefix(int index) { //State should be either START_ELEMENT or ATTRIBUTE if( fEventType == XMLEvent.START_ELEMENT || fEventType == XMLEvent.ATTRIBUTE) { return fScanner.getAttributeIterator().getPrefix(index); } else{ throw new java.lang.IllegalStateException("Current state is not among the states " + getEventTypeString(XMLEvent.START_ELEMENT) + " , " + getEventTypeString(XMLEvent.ATTRIBUTE) + "valid for getAttributePrefix()") ; } }