@Override public boolean standaloneSet() { if (this.event.isStartDocument()) { return ((StartDocument) this.event).standaloneSet(); } else { throw new IllegalStateException(); } }
@Override @Nullable public String getVersion() { if (this.event.isStartDocument()) { return ((StartDocument) this.event).getVersion(); } else { return null; } }
@Override public boolean isStandalone() { if (this.event.isStartDocument()) { return ((StartDocument) this.event).isStandalone(); } else { throw new IllegalStateException(); } }
/** * Constructs a new instance of the {@code StaxEventXmlReader} that reads from * the given {@code XMLEventReader}. The supplied event reader must be in * {@code XMLStreamConstants.START_DOCUMENT} or {@code XMLStreamConstants.START_ELEMENT} state. * @param reader the {@code XMLEventReader} to read from * @throws IllegalStateException if the reader is not at the start of a document or element */ StaxEventXMLReader(XMLEventReader reader) { try { XMLEvent event = reader.peek(); if (event != null && !(event.isStartDocument() || event.isStartElement())) { throw new IllegalStateException("XMLEventReader not at start of document or element"); } } catch (XMLStreamException ex) { throw new IllegalStateException("Could not read first element: " + ex.getMessage()); } this.reader = reader; }
@Override public boolean standaloneSet() { if (this.event.isStartDocument()) { return ((StartDocument) this.event).standaloneSet(); } else { throw new IllegalStateException(); } }
@Override public boolean isStandalone() { if (this.event.isStartDocument()) { return ((StartDocument) this.event).isStandalone(); } else { throw new IllegalStateException(); } }
@Override @Nullable public String getVersion() { if (this.event.isStartDocument()) { return ((StartDocument) this.event).getVersion(); } else { return null; } }
/** * Returns true if this unmarshaller context is at the very beginning of a * source document (i.e. no data has been parsed from the document yet). * * @return true if this unmarshaller context is at the very beginning of a * source document (i.e. no data has been parsed from the document * yet). */ public boolean isStartOfDocument() throws XMLStreamException { return eventReader.peek().isStartDocument(); }
/** * Constructs a new instance of the {@code StaxEventXmlReader} that reads from * the given {@code XMLEventReader}. The supplied event reader must be in * {@code XMLStreamConstants.START_DOCUMENT} or {@code XMLStreamConstants.START_ELEMENT} state. * @param reader the {@code XMLEventReader} to read from * @throws IllegalStateException if the reader is not at the start of a document or element */ StaxEventXMLReader(XMLEventReader reader) { try { XMLEvent event = reader.peek(); if (event != null && !(event.isStartDocument() || event.isStartElement())) { throw new IllegalStateException("XMLEventReader not at start of document or element"); } } catch (XMLStreamException ex) { throw new IllegalStateException("Could not read first element: " + ex.getMessage()); } this.reader = reader; }
@Override public void add(XMLEvent event) throws XMLStreamException { if ((!event.isStartDocument()) && (!event.isEndDocument())) { wrappedEventWriter.add(event); } }
private void handleStartDocument(final XMLEvent event) throws SAXException { if (event.isStartDocument()) { StartDocument startDocument = (StartDocument) event; String xmlVersion = startDocument.getVersion();
private Object unmarshal0(XMLEventReader reader,JaxBeanInfo expectedType) throws JAXBException { if (reader == null) { throw new IllegalArgumentException( Messages.format(Messages.NULL_READER)); } try { XMLEvent event = reader.peek(); if (!event.isStartElement() && !event.isStartDocument()) { // TODO: convert event into event name throw new IllegalStateException( Messages.format( Messages.ILLEGAL_READER_STATE,event.getEventType())); } // Quick hack until SJSXP fixes 6270116 boolean isZephyr = reader.getClass().getName().equals("com.sun.xml.stream.XMLReaderImpl"); XmlVisitor h = createUnmarshallerHandler(null,false,expectedType); if(!isZephyr) { h = new InterningXmlVisitor(h); } new StAXEventConnector(reader,h).bridge(); return h.getContext().getResult(); } catch (XMLStreamException e) { throw handleStreamException(e); } }
private void handleStartDocument(final XMLEvent event) throws SAXException { if (event.isStartDocument()) { StartDocument startDocument = (StartDocument) event; String xmlVersion = startDocument.getVersion();
@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; }
while (this.reader.hasNext() && elementDepth >= 0) { XMLEvent event = this.reader.nextEvent(); if (!event.isStartDocument() && !event.isEndDocument() && !documentStarted) { handleStartDocument(event); documentStarted = true;
@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; }
@Test public void decodeErrorAalto() { Flux<DataBuffer> source = Flux.concat( stringBuffer("<pojo>"), Flux.error(new RuntimeException())); Flux<XMLEvent> events = this.decoder.decode(source, null, null, Collections.emptyMap()); StepVerifier.create(events) .consumeNextWith(e -> assertTrue(e.isStartDocument())) .consumeNextWith(e -> assertStartElement(e, "pojo")) .expectError(RuntimeException.class) .verify(); }
/** * When fragment is marked as processed the cursor is moved after the end of * the fragment. */ public void testMarkFragmentProcessed() throws XMLStreamException { moveCursorBeforeFragmentStart(); fragmentReader.markStartFragment(); // mark the fragment start // read only one event to move inside the fragment XMLEvent startFragment = fragmentReader.nextEvent(); assertTrue(startFragment.isStartDocument()); fragmentReader.markFragmentProcessed(); // mark fragment as processed fragmentReader.nextEvent(); // skip whitespace // the next element after fragment end is <misc2/> XMLEvent misc2 = fragmentReader.nextEvent(); assertTrue(EventHelper.startElementName(misc2).equals("misc2")); }
@Test public void toXMLEventsAalto() { Flux<XMLEvent> events = this.decoder.decode(stringBuffer(XML), null, null, Collections.emptyMap()); StepVerifier.create(events) .consumeNextWith(e -> assertTrue(e.isStartDocument())) .consumeNextWith(e -> assertStartElement(e, "pojo")) .consumeNextWith(e -> assertStartElement(e, "foo")) .consumeNextWith(e -> assertCharacters(e, "foofoo")) .consumeNextWith(e -> assertEndElement(e, "foo")) .consumeNextWith(e -> assertStartElement(e, "bar")) .consumeNextWith(e -> assertCharacters(e, "barbar")) .consumeNextWith(e -> assertEndElement(e, "bar")) .consumeNextWith(e -> assertEndElement(e, "pojo")) .expectComplete() .verify(); }
@Test public void toXMLEventsNonAalto() { decoder.useAalto = false; Flux<XMLEvent> events = this.decoder.decode(stringBuffer(XML), null, null, Collections.emptyMap()); StepVerifier.create(events) .consumeNextWith(e -> assertTrue(e.isStartDocument())) .consumeNextWith(e -> assertStartElement(e, "pojo")) .consumeNextWith(e -> assertStartElement(e, "foo")) .consumeNextWith(e -> assertCharacters(e, "foofoo")) .consumeNextWith(e -> assertEndElement(e, "foo")) .consumeNextWith(e -> assertStartElement(e, "bar")) .consumeNextWith(e -> assertCharacters(e, "barbar")) .consumeNextWith(e -> assertEndElement(e, "bar")) .consumeNextWith(e -> assertEndElement(e, "pojo")) .consumeNextWith(e -> assertTrue(e.isEndDocument())) .expectComplete() .verify(); }