Small Stax fixes.

This commit is contained in:
Arjen Poutsma 2010-09-08 09:45:18 +00:00
parent f92f295055
commit 449337a544
4 changed files with 10 additions and 2 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2009 the original author or authors. * Copyright 2002-2010 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -32,6 +32,7 @@ import javax.xml.stream.util.XMLEventConsumer;
import org.xml.sax.Attributes; import org.xml.sax.Attributes;
import org.xml.sax.Locator; import org.xml.sax.Locator;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
/** /**
@ -58,6 +59,7 @@ class StaxEventContentHandler extends AbstractStaxContentHandler {
* @param consumer the consumer to write events to * @param consumer the consumer to write events to
*/ */
StaxEventContentHandler(XMLEventConsumer consumer) { StaxEventContentHandler(XMLEventConsumer consumer) {
Assert.notNull(consumer, "'consumer' must not be null");
eventFactory = XMLEventFactory.newInstance(); eventFactory = XMLEventFactory.newInstance();
eventConsumer = consumer; eventConsumer = consumer;
} }

View File

@ -43,6 +43,7 @@ import org.xml.sax.SAXException;
import org.xml.sax.ext.Locator2; import org.xml.sax.ext.Locator2;
import org.xml.sax.helpers.AttributesImpl; import org.xml.sax.helpers.AttributesImpl;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
/** /**
@ -78,6 +79,7 @@ class StaxEventXMLReader extends AbstractStaxXMLReader {
* @throws IllegalStateException if the reader is not at the start of a document or element * @throws IllegalStateException if the reader is not at the start of a document or element
*/ */
StaxEventXMLReader(XMLEventReader reader) { StaxEventXMLReader(XMLEventReader reader) {
Assert.notNull(reader, "'reader' must not be null");
try { try {
XMLEvent event = reader.peek(); XMLEvent event = reader.peek();
if (event != null && !(event.isStartDocument() || event.isStartElement())) { if (event != null && !(event.isStartDocument() || event.isStartElement())) {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2009 the original author or authors. * Copyright 2002-2010 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -24,6 +24,7 @@ import javax.xml.stream.XMLStreamWriter;
import org.xml.sax.Attributes; import org.xml.sax.Attributes;
import org.xml.sax.Locator; import org.xml.sax.Locator;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
/** /**
@ -44,6 +45,7 @@ class StaxStreamContentHandler extends AbstractStaxContentHandler {
* @param streamWriter the stream writer to write to * @param streamWriter the stream writer to write to
*/ */
StaxStreamContentHandler(XMLStreamWriter streamWriter) { StaxStreamContentHandler(XMLStreamWriter streamWriter) {
Assert.notNull(streamWriter, "'streamWriter' must not be null");
this.streamWriter = streamWriter; this.streamWriter = streamWriter;
} }

View File

@ -27,6 +27,7 @@ import org.xml.sax.SAXException;
import org.xml.sax.ext.Locator2; import org.xml.sax.ext.Locator2;
import org.xml.sax.helpers.AttributesImpl; import org.xml.sax.helpers.AttributesImpl;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
/** /**
@ -60,6 +61,7 @@ class StaxStreamXMLReader extends AbstractStaxXMLReader {
* @throws IllegalStateException if the reader is not at the start of a document or element * @throws IllegalStateException if the reader is not at the start of a document or element
*/ */
StaxStreamXMLReader(XMLStreamReader reader) { StaxStreamXMLReader(XMLStreamReader reader) {
Assert.notNull(reader, "'reader' must not be null");
int event = reader.getEventType(); int event = reader.getEventType();
if (!(event == XMLStreamConstants.START_DOCUMENT || event == XMLStreamConstants.START_ELEMENT)) { if (!(event == XMLStreamConstants.START_DOCUMENT || event == XMLStreamConstants.START_ELEMENT)) {
throw new IllegalStateException("XMLEventReader not at start of document or element"); throw new IllegalStateException("XMLEventReader not at start of document or element");