Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Reverting commit to the wrong branch

git-svn-id: https://svn.apache.org/repos/asf/mina/vysper/branches/xep0114@1068202 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information...
commit f130a1d9ee8262c0c737c0a08822458d23783b27 1 parent 758bf2d
Niklas Gustavsson authored
1  nbxml/src/main/java/org/apache/vysper/xml/sax/impl/XMLParser.java
View
@@ -335,7 +335,6 @@ private void restart() {
elements.clear();
nsResolver = new ParserNamespaceResolver();
sentStartDocument = false;
- tokenizer.restart();
}
private void xmlDeclaration() {
37 nbxml/src/main/java/org/apache/vysper/xml/sax/impl/XMLTokenizer.java
View
@@ -38,7 +38,7 @@
START, IN_TAG, IN_STRING, IN_DOUBLE_ATTRIBUTE_VALUE, IN_SINGLE_ATTRIBUTE_VALUE, IN_TEXT, CLOSED
}
- private final IoBuffer buffer = IoBuffer.allocate(16).setAutoExpand(true);
+ private int lastPosition = 0;
private State state = State.START;
@@ -59,6 +59,8 @@ public XMLTokenizer(TokenListener listeners) {
* @throws Exception
*/
public void parse(IoBuffer byteBuffer, CharsetDecoder decoder) throws SAXException {
+ lastPosition = byteBuffer.position();
+
while (byteBuffer.hasRemaining() && state != State.CLOSED) {
char c = (char) byteBuffer.get();
@@ -68,7 +70,6 @@ public void parse(IoBuffer byteBuffer, CharsetDecoder decoder) throws SAXExcepti
state = State.IN_TAG;
} else {
state = State.IN_TEXT;
- buffer.put((byte) c);
}
} else if (state == State.IN_TEXT) {
if (c == '<') {
@@ -91,10 +92,9 @@ public void parse(IoBuffer byteBuffer, CharsetDecoder decoder) throws SAXExcepti
} else if (isControlChar(c)) {
emit(c, byteBuffer);
} else if (Character.isWhitespace(c)) {
- buffer.clear();
+ lastPosition = byteBuffer.position();
} else {
state = State.IN_STRING;
- buffer.put((byte) c);
}
} else if (state == State.IN_STRING) {
if (c == '>') {
@@ -109,36 +109,28 @@ public void parse(IoBuffer byteBuffer, CharsetDecoder decoder) throws SAXExcepti
emit(byteBuffer, CharsetUtil.UTF8_DECODER);
state = State.IN_TAG;
} else {
- buffer.put((byte) c);
+ // do nothing
}
} else if (state == State.IN_DOUBLE_ATTRIBUTE_VALUE) {
if (c == '"') {
emit(byteBuffer, decoder);
emit(c, byteBuffer);
state = State.IN_TAG;
- } else {
- buffer.put((byte) c);
}
} else if (state == State.IN_SINGLE_ATTRIBUTE_VALUE) {
if (c == '\'') {
emit(byteBuffer, decoder);
emit(c, byteBuffer);
state = State.IN_TAG;
- } else {
- buffer.put((byte) c);
}
}
}
+
+ byteBuffer.position(lastPosition);
}
public void close() {
state = State.CLOSED;
- buffer.clear();
- }
-
- public void restart() {
- state = State.START;
- buffer.clear();
}
private boolean isControlChar(char c) {
@@ -147,15 +139,24 @@ private boolean isControlChar(char c) {
private void emit(char token, IoBuffer byteBuffer) throws SAXException {
listener.token(token, null);
+
+ lastPosition = byteBuffer.position();
}
private void emit(IoBuffer byteBuffer, CharsetDecoder decoder) throws SAXException {
+ int endPosition = byteBuffer.position();
+ int oldLimit = byteBuffer.limit();
+ byteBuffer.position(lastPosition);
+ byteBuffer.limit(endPosition - 1);
+
try {
- buffer.flip();
- listener.token(NO_CHAR, buffer.getString(decoder));
- buffer.clear();
+ listener.token(NO_CHAR, byteBuffer.getString(decoder));
} catch (CharacterCodingException e) {
throw new SAXException(e);
}
+ byteBuffer.limit(oldLimit);
+ byteBuffer.position(endPosition);
+ lastPosition = byteBuffer.position();
+
}
}
28 nbxml/src/test/java/org/apache/vysper/xml/sax/impl/ParseElementsTestCase.java
View
@@ -20,11 +20,7 @@
package org.apache.vysper.xml.sax.impl;
import java.util.Iterator;
-import java.util.Map.Entry;
-import org.apache.mina.core.buffer.IoBuffer;
-import org.apache.vysper.charset.CharsetUtil;
-import org.apache.vysper.xml.sax.NonBlockingXMLReader;
import org.apache.vysper.xml.sax.impl.TestHandler.TestEvent;
/**
@@ -170,28 +166,4 @@ public void testMixedXmlBeginName() throws Exception {
assertNoMoreevents(events);
}
-
- public void testSplitBuffers() throws Exception {
- TestHandler handler = new TestHandler();
- NonBlockingXMLReader reader = new DefaultNonBlockingXMLReader();
-
- reader.setContentHandler(handler);
- reader.setErrorHandler(handler);
-
- String xml1 = "<root></r";
- String xml2 = "oot>";
-
- reader.parse(IoBuffer.wrap(xml1.getBytes("UTF-8")), CharsetUtil.UTF8_DECODER);
- reader.parse(IoBuffer.wrap(xml2.getBytes("UTF-8")), CharsetUtil.UTF8_DECODER);
-
- Iterator<TestEvent> events = handler.getEvents().iterator();
-
- assertStartDocument(events.next());
- assertStartElement("", "root", "root", events.next());
- assertEndElement("", "root", "root", events.next());
- assertEndDocument(events.next());
-
- assertNoMoreevents(events);
- }
-
}
Please sign in to comment.
Something went wrong with that request. Please try again.