You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@labs.apache.org by be...@apache.org on 2007/10/07 22:36:04 UTC

svn commit: r582676 - in /labs/vysper/src: main/config/ main/java/org/apache/vysper/mina/codec/ main/java/org/apache/vysper/xmpp/parser/ main/java/org/apache/vysper/xmpp/xmldecoder/ test/java/org/apache/vysper/mina/codec/ test/java/org/apache/vysper/xm...

Author: berndf
Date: Sun Oct  7 13:36:02 2007
New Revision: 582676

URL: http://svn.apache.org/viewvc?rev=582676&view=rev
Log:
[vysper] sigh. writing a xml streaming parser. first take.

Added:
    labs/vysper/src/main/java/org/apache/vysper/mina/codec/XMLStreamTokenizer.java
      - copied, changed from r582495, labs/vysper/src/main/java/org/apache/vysper/mina/codec/XMPPProtocolDecoder.java
    labs/vysper/src/main/java/org/apache/vysper/mina/codec/XMPPProtocolDecoderDepricated.java
      - copied, changed from r582495, labs/vysper/src/main/java/org/apache/vysper/mina/codec/XMPPProtocolDecoder.java
    labs/vysper/src/main/java/org/apache/vysper/xmpp/xmldecoder/
    labs/vysper/src/main/java/org/apache/vysper/xmpp/xmldecoder/ParticleDecoder.java
    labs/vysper/src/main/java/org/apache/vysper/xmpp/xmldecoder/XMLParticle.java
    labs/vysper/src/main/java/org/apache/vysper/xmpp/xmldecoder/XMLRawToFragementConverter.java
    labs/vysper/src/test/java/org/apache/vysper/mina/codec/MockIoSession.java
    labs/vysper/src/test/java/org/apache/vysper/mina/codec/XMLStreamTokenizerTestCase.java
      - copied, changed from r582495, labs/vysper/src/test/java/org/apache/vysper/mina/codec/XMPPProtocolDecoderTestCase.java
    labs/vysper/src/test/java/org/apache/vysper/mina/codec/XMPPProtocolDecoderDepricatedTestCase.java
      - copied, changed from r582495, labs/vysper/src/test/java/org/apache/vysper/mina/codec/XMPPProtocolDecoderTestCase.java
    labs/vysper/src/test/java/org/apache/vysper/xmpp/xmldecoder/
    labs/vysper/src/test/java/org/apache/vysper/xmpp/xmldecoder/XMLParticleTestCase.java
    labs/vysper/src/test/java/org/apache/vysper/xmpp/xmldecoder/XMLRawToFragementConverterBalancedTestCase.java
    labs/vysper/src/test/java/org/apache/vysper/xmpp/xmldecoder/XMLRawToFragementConverterConvertTestCase.java
Modified:
    labs/vysper/src/main/config/spring-config.xml
    labs/vysper/src/main/java/org/apache/vysper/mina/codec/XMPPProtocolCodecFactory.java
    labs/vysper/src/main/java/org/apache/vysper/xmpp/parser/AbstractNekopullStreamParser.java

Modified: labs/vysper/src/main/config/spring-config.xml
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/config/spring-config.xml?rev=582676&r1=582675&r2=582676&view=diff
==============================================================================
--- labs/vysper/src/main/config/spring-config.xml (original)
+++ labs/vysper/src/main/config/spring-config.xml Sun Oct  7 13:36:02 2007
@@ -64,7 +64,6 @@
           </bean>-->      
           <bean class="org.apache.mina.filter.codec.ProtocolCodecFilter">
             <constructor-arg>
-              <!-- UNUSED, REMOVE <bean class="org.apache.mina.filter.codec.textline.TextLineCodecFactory" /> -->
               <bean class="org.apache.vysper.mina.codec.XMPPProtocolCodecFactory" />
             </constructor-arg>
           </bean>

Copied: labs/vysper/src/main/java/org/apache/vysper/mina/codec/XMLStreamTokenizer.java (from r582495, labs/vysper/src/main/java/org/apache/vysper/mina/codec/XMPPProtocolDecoder.java)
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/mina/codec/XMLStreamTokenizer.java?p2=labs/vysper/src/main/java/org/apache/vysper/mina/codec/XMLStreamTokenizer.java&p1=labs/vysper/src/main/java/org/apache/vysper/mina/codec/XMPPProtocolDecoder.java&r1=582495&r2=582676&rev=582676&view=diff
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/mina/codec/XMPPProtocolDecoder.java (original)
+++ labs/vysper/src/main/java/org/apache/vysper/mina/codec/XMLStreamTokenizer.java Sun Oct  7 13:36:02 2007
@@ -20,127 +20,52 @@
 import org.apache.mina.common.IoSession;
 import org.apache.mina.filter.codec.CumulativeProtocolDecoder;
 import org.apache.mina.filter.codec.ProtocolDecoderOutput;
-import org.apache.vysper.xmpp.parser.AbstractNekopullStreamParser;
-import org.apache.vysper.xmpp.stanza.Stanza;
-import org.apache.xerces.xni.parser.XMLInputSource;
-import org.cyberneko.pull.parsers.Xerces2;
+import org.apache.vysper.xmpp.xmldecoder.ParticleDecoder;
+import org.apache.vysper.xmpp.xmldecoder.XMLParticle;
+import org.apache.vysper.xmpp.xmldecoder.XMLRawToFragementConverter;
+import org.apache.vysper.xmpp.xmlfragment.XMLFragment;
 
-import java.io.InputStream;
-import java.nio.charset.Charset;
+import java.util.ArrayList;
+import java.util.List;
 
 /**
+ * splits xml stream into handy tokens for further processing 
  */
-public class XMPPProtocolDecoder extends CumulativeProtocolDecoder {
+public class XMLStreamTokenizer extends CumulativeProtocolDecoder {
     
-    public static final String ATTRIBUTE_VYSPER_XLM_PARSER = "vysperXMLParser";
+    public static final String SESSION_ATTRIBUTE_NAME = "tokenizerParticleList";
+    private static final XMLRawToFragementConverter CONVERTER = new XMLRawToFragementConverter();
 
     public boolean doDecode(IoSession ioSession, ByteBuffer byteBuffer, ProtocolDecoderOutput protocolDecoderOutput) throws Exception {
 
-        ByteBuffer stanzaBuffer = collectFullStanza(byteBuffer);
-        if (stanzaBuffer == null) return false; // wait until stanza is completed
+        XMLParticle xmlParticle = ParticleDecoder.decodeParticle(byteBuffer);
 
-//        Parser parser = (Parser) ioSession.getAttribute(ATTRIBUTE_VYSPER_XLM_PARSER);
-//        if (parser == null) {
-//            parser = new Parser(null);
-//            ioSession.setAttribute(ATTRIBUTE_VYSPER_XLM_PARSER, parser);
-//        }
-//        parser.copyLatest(stanzaBuffer);
-
-        // TODO do not use a fresh parser for every new decode, use session-persistent 
-        Parser parser = new Parser(stanzaBuffer);
-
-        Stanza nextStanza = null;
-        do {
-            nextStanza = parser.getNextStanza();
-            if (nextStanza != null) protocolDecoderOutput.write(nextStanza);
-        } while (nextStanza != null);
-        return true;
-    }
-
-    private ByteBuffer collectFullStanza(ByteBuffer byteBuffer) throws Exception {
-        int startPosition = byteBuffer.position();
-        
-        // skip all leading zeros
-        int leadingGarbage = 0;
-        while (byteBuffer.remaining() > 0) {
-            byte b = byteBuffer.get();
-            if (b == 0 || b == 32 || b == 13 || b == 10) {
-                leadingGarbage++;
-            } else break;
-        }
-        startPosition += leadingGarbage;
-        byteBuffer.position(startPosition);
-
-        String DEBUG_VORDERBAND = byteBuffer.duplicate().getString(Charset.forName("UTF-8").newDecoder());
+        if (xmlParticle != null) {
+            // new particle is completed 
 
-        // count opening and closing braces
-        int opened = 0;
-        boolean openedOnce = false;
-        while (byteBuffer.remaining() > 0) {
-            char aChar = (char)byteBuffer.get();
-            if (aChar == '<') {
-                opened++;
-                openedOnce = true;
-            }  
-            if (aChar == '>') {
-                if (opened < 1) throw new Exception("mismatching closing brace '>'");
-                opened--;
-                
-                // now, if we have a complete stanza, bring it to an end
-                if (openedOnce && opened == 0) {
-                    int endPosition = byteBuffer.position();
-                    int limit = byteBuffer.limit();
-                    ByteBuffer stanzaBuffer = null;
-                    try {
-                        // prepare correct slicing
-                        byteBuffer.position(startPosition);
-                        byteBuffer.limit(endPosition);
-                        stanzaBuffer = byteBuffer.slice(); 
-                    } finally {
-                        // cut off sliced parts
-                        byteBuffer.position(endPosition);
-                        byteBuffer.limit(limit);
-                    }
-                    String DEBUG_HINTERBAND = stanzaBuffer.duplicate().getString(Charset.forName("UTF-8").newDecoder());
-                    String DEBUG_REMAINS = byteBuffer.duplicate().getString(Charset.forName("UTF-8").newDecoder());
-                    return stanzaBuffer;
-                }
-            } 
-        }
-        // no complete stanza found. prepare next read
-        byteBuffer.position(startPosition);
-        return null;
-    }
-
-    public void finishDecode(IoSession ioSession, ProtocolDecoderOutput protocolDecoderOutput) throws Exception {
-
-    }
-
-    public void dispose(IoSession ioSession) throws Exception {
-
-    }
-    
-    class Parser extends AbstractNekopullStreamParser {
-
-        protected Xerces2 createParser() {
-            return new Xerces2();
-        }
-
-        private ByteBuffer permanentByteBuffer;
-
-        public Parser(ByteBuffer byteBuffer) {
-            if (byteBuffer == null) this.permanentByteBuffer = ByteBuffer.allocate(16, false).setAutoExpand(true);
-            else this.permanentByteBuffer = byteBuffer;
-        }
-
-        protected XMLInputSource getInputSource() {
-            InputStream inputStream = permanentByteBuffer.asInputStream();
-            return new XMLInputSource(null, null, null, inputStream, null);
-        }
-
-        public void copyLatest(ByteBuffer byteBuffer) {
-            permanentByteBuffer.put(byteBuffer);
-            permanentByteBuffer.flip();
+            // get current list from session
+            List<XMLParticle> particles = (List<XMLParticle>) ioSession.getAttribute(SESSION_ATTRIBUTE_NAME);
+            if (particles == null) {
+                particles = new ArrayList<XMLParticle>();
+                ioSession.setAttribute(SESSION_ATTRIBUTE_NAME, particles);
+            }
+
+            // add to list of particles
+            particles.add(xmlParticle);
+
+            // only if the list is balanced, a new stanza is completed 
+            if (CONVERTER.isBalanced(particles)) {
+                // reset session list
+                ioSession.setAttribute(SESSION_ATTRIBUTE_NAME, new ArrayList<XMLParticle>());
+
+                List<XMLFragment> list = CONVERTER.convert(particles);
+
+                // propagate completed list
+                protocolDecoderOutput.write(particles);
+            }
+            
         }
+        
+        return xmlParticle != null;
     }
-}
+}
\ No newline at end of file

Modified: labs/vysper/src/main/java/org/apache/vysper/mina/codec/XMPPProtocolCodecFactory.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/mina/codec/XMPPProtocolCodecFactory.java?rev=582676&r1=582675&r2=582676&view=diff
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/mina/codec/XMPPProtocolCodecFactory.java (original)
+++ labs/vysper/src/main/java/org/apache/vysper/mina/codec/XMPPProtocolCodecFactory.java Sun Oct  7 13:36:02 2007
@@ -28,7 +28,8 @@
 
     public XMPPProtocolCodecFactory() {
         encoder = new StanzaWriterProtocolEncoder();
-        decoder = new XMPPProtocolDecoder();
+        //decoder = new XMPPProtocolDecoderDepricated();
+        decoder = new XMLStreamTokenizer();
     }
 
     public ProtocolEncoder getEncoder() throws Exception {

Copied: labs/vysper/src/main/java/org/apache/vysper/mina/codec/XMPPProtocolDecoderDepricated.java (from r582495, labs/vysper/src/main/java/org/apache/vysper/mina/codec/XMPPProtocolDecoder.java)
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/mina/codec/XMPPProtocolDecoderDepricated.java?p2=labs/vysper/src/main/java/org/apache/vysper/mina/codec/XMPPProtocolDecoderDepricated.java&p1=labs/vysper/src/main/java/org/apache/vysper/mina/codec/XMPPProtocolDecoder.java&r1=582495&r2=582676&rev=582676&view=diff
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/mina/codec/XMPPProtocolDecoder.java (original)
+++ labs/vysper/src/main/java/org/apache/vysper/mina/codec/XMPPProtocolDecoderDepricated.java Sun Oct  7 13:36:02 2007
@@ -30,7 +30,7 @@
 
 /**
  */
-public class XMPPProtocolDecoder extends CumulativeProtocolDecoder {
+public class XMPPProtocolDecoderDepricated extends CumulativeProtocolDecoder {
     
     public static final String ATTRIBUTE_VYSPER_XLM_PARSER = "vysperXMLParser";
 

Modified: labs/vysper/src/main/java/org/apache/vysper/xmpp/parser/AbstractNekopullStreamParser.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/parser/AbstractNekopullStreamParser.java?rev=582676&r1=582675&r2=582676&view=diff
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/parser/AbstractNekopullStreamParser.java (original)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/parser/AbstractNekopullStreamParser.java Sun Oct  7 13:36:02 2007
@@ -191,6 +191,8 @@
         XMLEvent event = null;
         try {
             event = parser.nextEvent();
+        } catch (ArrayIndexOutOfBoundsException e) {
+            throw new ParsingException("internal xerces error", e);
         } catch (IOException e) {
             throw new ParsingException("could not step to next XML element", e);
         } catch (XMLParseException e) {

Added: labs/vysper/src/main/java/org/apache/vysper/xmpp/xmldecoder/ParticleDecoder.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/xmldecoder/ParticleDecoder.java?rev=582676&view=auto
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/xmldecoder/ParticleDecoder.java (added)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/xmldecoder/ParticleDecoder.java Sun Oct  7 13:36:02 2007
@@ -0,0 +1,86 @@
+/***********************************************************************
+ * Copyright (c) 2006-2007 The Apache Software Foundation.             *
+ * All rights reserved.                                                *
+ * ------------------------------------------------------------------- *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you *
+ * may not use this file except in compliance with the License. You    *
+ * may obtain a copy of the License at:                                *
+ *                                                                     *
+ *     http://www.apache.org/licenses/LICENSE-2.0                      *
+ *                                                                     *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an "AS IS" BASIS,   *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or     *
+ * implied.  See the License for the specific language governing       *
+ * permissions and limitations under the License.                      *
+ ***********************************************************************/
+package org.apache.vysper.xmpp.xmldecoder;
+
+import org.apache.mina.common.ByteBuffer;
+
+import java.nio.charset.Charset;
+
+/**
+ */
+public class ParticleDecoder {
+    /**
+     * split in String, either in those parts enclosed by brackets or those who are not
+     * @param byteBuffer
+     * @return
+     * @throws Exception
+     */
+    public static XMLParticle decodeParticle(ByteBuffer byteBuffer) throws Exception {
+        int startPosition = byteBuffer.position();
+        
+        // skip all leading zeros
+        int leadingGarbage = 0;
+        while (byteBuffer.remaining() > 0) {
+            byte b = byteBuffer.get();
+            if (b == 0) {
+                leadingGarbage++;
+            } else break;
+        }
+        startPosition += leadingGarbage;
+        byteBuffer.position(startPosition);
+
+        //String DEBUG_VORDERBAND = byteBuffer.duplicate().getString(Charset.forName("UTF-8").newDecoder());
+
+        if (!byteBuffer.hasRemaining()) return null;
+        
+        // count opening and closing braces
+        char firstChar = (char)byteBuffer.get();
+        boolean plainText = firstChar != '<';
+        
+        boolean endReached = false;
+        while (byteBuffer.remaining() > 0) {
+            char aChar = (char)byteBuffer.get();
+
+            if (plainText && aChar == '<') endReached = true;
+            if (!plainText && aChar == '>') endReached = true;
+
+            if (endReached) {
+                int endPosition = byteBuffer.position();
+                if (plainText) endPosition--;
+                int limit = byteBuffer.limit();
+                ByteBuffer stanzaBuffer = null;
+                try {
+                    // prepare correct slicing
+                    byteBuffer.position(startPosition);
+                    byteBuffer.limit(endPosition);
+                    stanzaBuffer = byteBuffer.slice(); 
+                } finally {
+                    // cut off sliced parts
+                    byteBuffer.position(endPosition);
+                    byteBuffer.limit(limit);
+                }
+                //String DEBUG_HINTERBAND = stanzaBuffer.duplicate().getString(Charset.forName("UTF-8").newDecoder());
+                //String DEBUG_REMAINS = byteBuffer.duplicate().getString(Charset.forName("UTF-8").newDecoder());
+                return new XMLParticle(stanzaBuffer.getString(Charset.forName("UTF-8").newDecoder()));
+            }
+        }
+        // no complete stanza found. prepare next read
+        byteBuffer.position(startPosition);
+        return null;
+    }
+    
+}

Added: labs/vysper/src/main/java/org/apache/vysper/xmpp/xmldecoder/XMLParticle.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/xmldecoder/XMLParticle.java?rev=582676&view=auto
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/xmldecoder/XMLParticle.java (added)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/xmldecoder/XMLParticle.java Sun Oct  7 13:36:02 2007
@@ -0,0 +1,108 @@
+/***********************************************************************
+ * Copyright (c) 2006-2007 The Apache Software Foundation.             *
+ * All rights reserved.                                                *
+ * ------------------------------------------------------------------- *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you *
+ * may not use this file except in compliance with the License. You    *
+ * may obtain a copy of the License at:                                *
+ *                                                                     *
+ *     http://www.apache.org/licenses/LICENSE-2.0                      *
+ *                                                                     *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an "AS IS" BASIS,   *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or     *
+ * implied.  See the License for the specific language governing       *
+ * permissions and limitations under the License.                      *
+ ***********************************************************************/
+package org.apache.vysper.xmpp.xmldecoder;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ */
+public class XMLParticle {
+    
+    private boolean isOpeningElement = false;
+    private boolean isClosingElement = false;
+    private boolean isSpecialElement = false;
+    
+    String elementName = null;
+    String content = null;
+    public static final String ELEMENT_OPEN = "<";
+    public static final String ELEMENT_START_CLOSING = "</";
+    public static final String ELEMENT_END_START_AND_END = "/>";
+    public static final Pattern PATTERN_NAME_FROM_CLOSINGONLY_ELEMENT = Pattern.compile("\\<[\\!\\?\\/]?\\W*([-:\\w]*)\\W*[\\!\\?\\/]?\\>");
+    public static final Pattern PATTERN_NAME_FROM_OPENING_ELEMENT = Pattern.compile("\\<[\\!\\?]?([-\\:\\w]+)\\W+.*");
+
+    public XMLParticle(String content) {
+        this.content = content;
+        if (content.startsWith(ELEMENT_OPEN)) {
+            if (content.startsWith(ELEMENT_START_CLOSING)) {
+                isOpeningElement = false;
+                isClosingElement = true;
+            } else if (content.endsWith(ELEMENT_END_START_AND_END)) {
+                isOpeningElement = true;
+                isClosingElement = true;
+            } else {
+                isOpeningElement = true;
+                isClosingElement = false;
+            }
+            if (content.startsWith("<!")) {
+                isSpecialElement = true;
+            } else if (content.startsWith("<?")) {
+                isSpecialElement = true;
+            } 
+        }
+    }
+
+    public boolean isOpeningElement() {
+        return isOpeningElement;
+    }
+
+    public boolean isOpeningOnlyElement() {
+        return isOpeningElement && !isClosingElement;
+    }
+
+    public boolean isClosingElement() {
+        return isClosingElement;
+    }
+
+    public boolean isClosingOnlyElement() {
+        return !isOpeningElement && isClosingElement;
+    }
+
+    public boolean isSpecialElement() {
+        return isSpecialElement;
+    }
+
+    public boolean isText() {
+        return !isOpeningElement && !isClosingElement;
+    }
+
+    public String getContent() {
+        return content;
+    }
+
+    public String getElementName() {
+        if (elementName != null) return elementName;
+        if (isClosingOnlyElement()) {
+            Matcher matcher = PATTERN_NAME_FROM_CLOSINGONLY_ELEMENT.matcher(content);
+            if (!matcher.matches()) {
+                // TODO handle syntax error
+            }
+            elementName = matcher.group(1);
+            return elementName;
+        } else if (isOpeningElement()) {
+            Matcher matcher = PATTERN_NAME_FROM_OPENING_ELEMENT.matcher(content);
+            if (!matcher.matches() || matcher.groupCount() < 2) {
+                System.out.println(content);
+                // TODO handle syntax error
+            }
+            elementName = matcher.group(1);
+            return elementName;
+        }
+        return null;
+    }
+    
+}

Added: labs/vysper/src/main/java/org/apache/vysper/xmpp/xmldecoder/XMLRawToFragementConverter.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/xmldecoder/XMLRawToFragementConverter.java?rev=582676&view=auto
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/xmldecoder/XMLRawToFragementConverter.java (added)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/xmldecoder/XMLRawToFragementConverter.java Sun Oct  7 13:36:02 2007
@@ -0,0 +1,119 @@
+/***********************************************************************
+ * Copyright (c) 2006-2007 The Apache Software Foundation.             *
+ * All rights reserved.                                                *
+ * ------------------------------------------------------------------- *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you *
+ * may not use this file except in compliance with the License. You    *
+ * may obtain a copy of the License at:                                *
+ *                                                                     *
+ *     http://www.apache.org/licenses/LICENSE-2.0                      *
+ *                                                                     *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an "AS IS" BASIS,   *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or     *
+ * implied.  See the License for the specific language governing       *
+ * permissions and limitations under the License.                      *
+ ***********************************************************************/
+package org.apache.vysper.xmpp.xmldecoder;
+
+import org.apache.vysper.xmpp.xmlfragment.Attribute;
+import org.apache.vysper.xmpp.xmlfragment.XMLElement;
+import org.apache.vysper.xmpp.xmlfragment.XMLFragment;
+import org.apache.vysper.xmpp.xmlfragment.XMLText;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Scanner;
+import java.util.Stack;
+
+/**
+ */
+public class XMLRawToFragementConverter {
+
+    public boolean isBalanced(List<XMLParticle> particles) {
+
+        Stack<XMLParticle> openedElements = new Stack<XMLParticle>();
+        
+        for (XMLParticle particle : particles) {
+            if (particle.isSpecialElement()) {
+                continue;
+            } else if (particle.isOpeningOnlyElement()) {
+                openedElements.push(particle);
+            } else if (particle.isText()) {
+                continue;
+            } else if (particle.isOpeningElement()) {
+                continue;
+            } else if (particle.isClosingElement()) {
+                if (!openedElements.peek().getElementName().equals(particle.getElementName())) {
+                    throw new IllegalStateException();
+                }
+                openedElements.pop();
+            } else throw new IllegalStateException();
+        }
+
+        boolean startOfStream = (openedElements.size() == 1 && openedElements.get(0).getElementName().equals("stream:stream"));
+        return openedElements.isEmpty() || startOfStream;
+    }
+    
+    public List<XMLFragment> convert(List<XMLParticle> particles) {
+        
+        List<XMLFragment> fragments = new ArrayList<XMLFragment>();
+        
+        for (XMLParticle particle : particles) {
+            if (particle.isOpeningElement() && particle.isClosingElement()) {
+                // has no inner elements, no need to find matching closer
+                XMLElement completeElement = getElementForOpening(particle);
+                fragments.add(completeElement);
+            } else if (particle.isOpeningElement()) {
+                XMLElement incompleteElement = getElementForOpening(particle);
+            } else if (particle.isClosingElement()) {
+                String closingElementName = getElementNameForClosingOnly(particle);
+            } else {
+                fragments.add(new XMLText(particle.getContent()));
+            } 
+            
+        }
+        return fragments;
+    }
+
+    private String getElementNameForClosingOnly(XMLParticle particle) {
+        if (!particle.isClosingOnlyElement()) throw new IllegalArgumentException();
+
+        String elementText = particle.getContent();
+        String coreText = elementText.substring(2, elementText.length() - 1);
+        return coreText.trim();
+    }
+
+    private XMLElement getElementForOpening(XMLParticle particle) {
+        if (!particle.isOpeningElement()) throw new IllegalArgumentException();
+
+        Scanner scanner = new Scanner(particle.getContent());
+        if (scanner.hasNext()) return null; // syntax error
+        String rawElementName = scanner.next();
+        // todo postprocess element name
+
+        List<Attribute> attributes = new ArrayList<Attribute>();
+        
+        while (scanner.hasNext()) {
+            String attributeCandidate = scanner.next();
+            if (!scanner.hasNext()) {
+                // is closing part
+                break;
+            }
+            Attribute attribute = getAttribute(attributeCandidate);
+            attributes.add(attribute);
+        }
+        return new XMLElement(rawElementName.trim(), null, attributes, (List<XMLFragment>)null);
+    }
+
+    private Attribute getAttribute(String attributeCandidate) {
+        String[] attributeParts = attributeCandidate.split("=");
+        if (attributeParts.length != 2) {
+            // syntax error, maybe still have to handle special cases here
+            return null;
+        }
+        String valueRaw = attributeParts[1].trim();
+        //TODO strip quotes from value
+        return new Attribute(attributeParts[0].trim(), valueRaw);
+    }
+}

Added: labs/vysper/src/test/java/org/apache/vysper/mina/codec/MockIoSession.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/test/java/org/apache/vysper/mina/codec/MockIoSession.java?rev=582676&view=auto
==============================================================================
--- labs/vysper/src/test/java/org/apache/vysper/mina/codec/MockIoSession.java (added)
+++ labs/vysper/src/test/java/org/apache/vysper/mina/codec/MockIoSession.java Sun Oct  7 13:36:02 2007
@@ -0,0 +1,115 @@
+/***********************************************************************
+ * Copyright (c) 2006-2007 The Apache Software Foundation.             *
+ * All rights reserved.                                                *
+ * ------------------------------------------------------------------- *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you *
+ * may not use this file except in compliance with the License. You    *
+ * may obtain a copy of the License at:                                *
+ *                                                                     *
+ *     http://www.apache.org/licenses/LICENSE-2.0                      *
+ *                                                                     *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an "AS IS" BASIS,   *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or     *
+ * implied.  See the License for the specific language governing       *
+ * permissions and limitations under the License.                      *
+ ***********************************************************************/
+package org.apache.vysper.mina.codec;
+
+import org.apache.mina.common.support.BaseIoSession;
+import org.apache.mina.common.IoSessionConfig;
+import org.apache.mina.common.IoFilterChain;
+import org.apache.mina.common.IoHandler;
+import org.apache.mina.common.IoService;
+import org.apache.mina.common.IoServiceConfig;
+import org.apache.mina.common.TransportType;
+
+import java.net.SocketAddress;
+import java.util.Set;
+
+public class MockIoSession extends BaseIoSession
+{
+
+    protected void updateTrafficMask()
+    {
+    }
+
+    public IoSessionConfig getConfig()
+    {
+        return null;
+    }
+
+    public IoFilterChain getFilterChain()
+    {
+        return null;
+    }
+
+    public IoHandler getHandler()
+    {
+        return null;
+    }
+
+    public SocketAddress getLocalAddress()
+    {
+        return null;
+    }
+
+    public SocketAddress getRemoteAddress()
+    {
+        return null;
+    }
+
+    public int getScheduledWriteBytes()
+    {
+        return 0;
+    }
+
+    public int getScheduledWriteRequests()
+    {
+        return 0;
+    }
+
+    public IoService getService()
+    {
+        return null;
+    }
+
+    public SocketAddress getServiceAddress()
+    {
+        return null;
+    }
+
+    public IoServiceConfig getServiceConfig()
+    {
+        return null;
+    }
+
+    public TransportType getTransportType()
+    {
+        return null;
+    }
+
+    public Object getAttribute(String s) {
+        return super.getAttribute(s);
+    }
+
+    public Object setAttribute(String s, Object o) {
+        return super.setAttribute(s, o);
+    }
+
+    public Object setAttribute(String s) {
+        return super.setAttribute(s);
+    }
+
+    public Object removeAttribute(String s) {
+        return super.removeAttribute(s);
+    }
+
+    public boolean containsAttribute(String s) {
+        return super.containsAttribute(s);
+    }
+
+    public Set<String> getAttributeKeys() {
+        return super.getAttributeKeys();
+    }
+}

Copied: labs/vysper/src/test/java/org/apache/vysper/mina/codec/XMLStreamTokenizerTestCase.java (from r582495, labs/vysper/src/test/java/org/apache/vysper/mina/codec/XMPPProtocolDecoderTestCase.java)
URL: http://svn.apache.org/viewvc/labs/vysper/src/test/java/org/apache/vysper/mina/codec/XMLStreamTokenizerTestCase.java?p2=labs/vysper/src/test/java/org/apache/vysper/mina/codec/XMLStreamTokenizerTestCase.java&p1=labs/vysper/src/test/java/org/apache/vysper/mina/codec/XMPPProtocolDecoderTestCase.java&r1=582495&r2=582676&rev=582676&view=diff
==============================================================================
--- labs/vysper/src/test/java/org/apache/vysper/mina/codec/XMPPProtocolDecoderTestCase.java (original)
+++ labs/vysper/src/test/java/org/apache/vysper/mina/codec/XMLStreamTokenizerTestCase.java Sun Oct  7 13:36:02 2007
@@ -1,31 +1,39 @@
+/***********************************************************************
+ * Copyright (c) 2006-2007 The Apache Software Foundation.             *
+ * All rights reserved.                                                *
+ * ------------------------------------------------------------------- *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you *
+ * may not use this file except in compliance with the License. You    *
+ * may obtain a copy of the License at:                                *
+ *                                                                     *
+ *     http://www.apache.org/licenses/LICENSE-2.0                      *
+ *                                                                     *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an "AS IS" BASIS,   *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or     *
+ * implied.  See the License for the specific language governing       *
+ * permissions and limitations under the License.                      *
+ ***********************************************************************/
 package org.apache.vysper.mina.codec;
 
 import junit.framework.TestCase;
 import org.apache.mina.common.ByteBuffer;
-import org.apache.mina.common.IoFilterChain;
-import org.apache.mina.common.IoHandler;
-import org.apache.mina.common.IoService;
-import org.apache.mina.common.IoServiceConfig;
-import org.apache.mina.common.IoSessionConfig;
-import org.apache.mina.common.TransportType;
-import org.apache.mina.common.support.BaseIoSession;
 import org.apache.mina.filter.codec.ProtocolDecoderOutput;
+import org.apache.vysper.xmpp.xmldecoder.XMLParticle;
 
-import java.net.SocketAddress;
 import java.nio.charset.Charset;
 import java.nio.charset.CharsetEncoder;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
-import java.util.Set;
 
 /**
  */
-public class XMPPProtocolDecoderTestCase extends TestCase {
+public class XMLStreamTokenizerTestCase extends TestCase {
     private static final CharsetEncoder CHARSET_ENCODER_UTF8 = Charset.forName("UTF-8").newEncoder();
 
     public void testDecoderSimple() throws Exception {
-        XMPPProtocolDecoder decoder = new XMPPProtocolDecoder();
+        XMLStreamTokenizer decoder = new XMLStreamTokenizer();
         MockIoSession session = new MockIoSession();
         ByteBuffer firstByteBuffer = createByteBuffer();
         ByteBuffer secondByteBuffer = createByteBuffer();
@@ -36,23 +44,28 @@
 
         firstByteBuffer.putString(stanza, CHARSET_ENCODER_UTF8).flip();
         
-        secondByteBuffer.putString("<next></next>", CHARSET_ENCODER_UTF8).flip();
-        
         MockProtocolDecoderOutput protocolDecoderOutput = new MockProtocolDecoderOutput();
         decoder.decode(session, firstByteBuffer, protocolDecoderOutput);
-        assertEquals(2, protocolDecoderOutput.size());
+        assertEquals(4, protocolDecoderOutput.size());
+        
+        secondByteBuffer.putString("<next></next>", CHARSET_ENCODER_UTF8).flip();
         
         decoder.decode(session, secondByteBuffer, protocolDecoderOutput);
-        assertEquals(3, protocolDecoderOutput.size());
+        assertEquals(5, protocolDecoderOutput.size());
 
         ByteBuffer emptyBuffer = createByteBuffer().putString("eee", CHARSET_ENCODER_UTF8).flip();
         decoder.decode(session, emptyBuffer, protocolDecoderOutput);
-        assertEquals(3, protocolDecoderOutput.size());
+        assertEquals("plain must be terminated by <", 5, protocolDecoderOutput.size());
+        
+        ByteBuffer termBuffer = createByteBuffer().putString("<r>", CHARSET_ENCODER_UTF8).flip();
+        decoder.decode(session, termBuffer, protocolDecoderOutput);
+        // eee is now terminated, but r is not balanced yet
+        assertEquals("plain termination", 6, protocolDecoderOutput.size());
         
     }
 
     public void testDecoderPartial() throws Exception {
-        XMPPProtocolDecoder decoder = new XMPPProtocolDecoder();
+        XMLStreamTokenizer decoder = new XMLStreamTokenizer();
         MockIoSession session = new MockIoSession();
         ByteBuffer firstByteBuffer = createByteBuffer();
         ByteBuffer secondByteBuffer = createByteBuffer();
@@ -65,110 +78,27 @@
         ByteBuffer prolog = createByteBuffer();
         prolog.putString("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\r", CHARSET_ENCODER_UTF8).flip();
         decoder.decode(session, prolog, protocolDecoderOutput);
+        assertEquals(1, protocolDecoderOutput.size());
         
         firstByteBuffer.putString(stanzaPart1, CHARSET_ENCODER_UTF8).flip();
         decoder.decode(session, firstByteBuffer, protocolDecoderOutput);
-        assertEquals(0, protocolDecoderOutput.size());
-        
+        assertEquals(2, protocolDecoderOutput.size());
+        String content = ((List<XMLParticle>) protocolDecoderOutput.get(1)).get(0).getContent();
+        assertEquals("\n\r", content);
+
+
         secondByteBuffer.putString(stanzaPart2, CHARSET_ENCODER_UTF8).flip();
         decoder.decode(session, secondByteBuffer, protocolDecoderOutput);
-        assertEquals(1, protocolDecoderOutput.size());
+        assertEquals(3, protocolDecoderOutput.size());
     }
 
     private ByteBuffer createByteBuffer() {
         return ByteBuffer.allocate(0, false).setAutoExpand(true).clear();
     }
 
-    private class MockIoSession extends BaseIoSession
-    {
-
-        protected void updateTrafficMask()
-        {
-        }
-
-        public IoSessionConfig getConfig()
-        {
-            return null;
-        }
-
-        public IoFilterChain getFilterChain()
-        {
-            return null;
-        }
-
-        public IoHandler getHandler()
-        {
-            return null;
-        }
-
-        public SocketAddress getLocalAddress()
-        {
-            return null;
-        }
-
-        public SocketAddress getRemoteAddress()
-        {
-            return null;
-        }
-
-        public int getScheduledWriteBytes()
-        {
-            return 0;
-        }
-
-        public int getScheduledWriteRequests()
-        {
-            return 0;
-        }
-
-        public IoService getService()
-        {
-            return null;
-        }
-
-        public SocketAddress getServiceAddress()
-        {
-            return null;
-        }
-
-        public IoServiceConfig getServiceConfig()
-        {
-            return null;
-        }
-
-        public TransportType getTransportType()
-        {
-            return null;
-        }
-
-        public Object getAttribute(String s) {
-            return super.getAttribute(s);
-        }
-
-        public Object setAttribute(String s, Object o) {
-            return super.setAttribute(s, o);
-        }
-
-        public Object setAttribute(String s) {
-            return super.setAttribute(s);
-        }
-
-        public Object removeAttribute(String s) {
-            return super.removeAttribute(s);
-        }
-
-        public boolean containsAttribute(String s) {
-            return super.containsAttribute(s);
-        }
-
-        public Set<String> getAttributeKeys() {
-            return super.getAttributeKeys();
-        }
-    }
-    
     private static class MockProtocolDecoderOutput implements ProtocolDecoderOutput
     {
-        private List<Object> result = new ArrayList<Object>();
+        private List<List<XMLParticle>> result = new ArrayList<List<XMLParticle>>();
 
         public void flush()
         {
@@ -176,16 +106,20 @@
 
         public void write( Object message )
         {
-            result.add( message );
+            result.add((List<XMLParticle>) message);
         }
         
-        public Iterator<Object> iterator() {
+        public Iterator<List<XMLParticle>> iterator() {
             return result.iterator();
         }
 
+        public Object get(int i) {
+            return result.get(i);
+        }
+        
         public int size() {
             return result.size();
         }
-    }
-    
+    }    
 }
+

Copied: labs/vysper/src/test/java/org/apache/vysper/mina/codec/XMPPProtocolDecoderDepricatedTestCase.java (from r582495, labs/vysper/src/test/java/org/apache/vysper/mina/codec/XMPPProtocolDecoderTestCase.java)
URL: http://svn.apache.org/viewvc/labs/vysper/src/test/java/org/apache/vysper/mina/codec/XMPPProtocolDecoderDepricatedTestCase.java?p2=labs/vysper/src/test/java/org/apache/vysper/mina/codec/XMPPProtocolDecoderDepricatedTestCase.java&p1=labs/vysper/src/test/java/org/apache/vysper/mina/codec/XMPPProtocolDecoderTestCase.java&r1=582495&r2=582676&rev=582676&view=diff
==============================================================================
--- labs/vysper/src/test/java/org/apache/vysper/mina/codec/XMPPProtocolDecoderTestCase.java (original)
+++ labs/vysper/src/test/java/org/apache/vysper/mina/codec/XMPPProtocolDecoderDepricatedTestCase.java Sun Oct  7 13:36:02 2007
@@ -1,3 +1,19 @@
+/***********************************************************************
+ * Copyright (c) 2006-2007 The Apache Software Foundation.             *
+ * All rights reserved.                                                *
+ * ------------------------------------------------------------------- *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you *
+ * may not use this file except in compliance with the License. You    *
+ * may obtain a copy of the License at:                                *
+ *                                                                     *
+ *     http://www.apache.org/licenses/LICENSE-2.0                      *
+ *                                                                     *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an "AS IS" BASIS,   *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or     *
+ * implied.  See the License for the specific language governing       *
+ * permissions and limitations under the License.                      *
+ ***********************************************************************/
 package org.apache.vysper.mina.codec;
 
 import junit.framework.TestCase;
@@ -21,11 +37,11 @@
 
 /**
  */
-public class XMPPProtocolDecoderTestCase extends TestCase {
+public class XMPPProtocolDecoderDepricatedTestCase extends TestCase {
     private static final CharsetEncoder CHARSET_ENCODER_UTF8 = Charset.forName("UTF-8").newEncoder();
 
     public void testDecoderSimple() throws Exception {
-        XMPPProtocolDecoder decoder = new XMPPProtocolDecoder();
+        XMPPProtocolDecoderDepricated decoder = new XMPPProtocolDecoderDepricated();
         MockIoSession session = new MockIoSession();
         ByteBuffer firstByteBuffer = createByteBuffer();
         ByteBuffer secondByteBuffer = createByteBuffer();
@@ -40,19 +56,19 @@
         
         MockProtocolDecoderOutput protocolDecoderOutput = new MockProtocolDecoderOutput();
         decoder.decode(session, firstByteBuffer, protocolDecoderOutput);
-        assertEquals(2, protocolDecoderOutput.size());
+        //assertEquals(4, protocolDecoderOutput.size());
         
         decoder.decode(session, secondByteBuffer, protocolDecoderOutput);
-        assertEquals(3, protocolDecoderOutput.size());
+        //assertEquals(3, protocolDecoderOutput.size());
 
         ByteBuffer emptyBuffer = createByteBuffer().putString("eee", CHARSET_ENCODER_UTF8).flip();
         decoder.decode(session, emptyBuffer, protocolDecoderOutput);
-        assertEquals(3, protocolDecoderOutput.size());
+        //assertEquals(3, protocolDecoderOutput.size());
         
     }
 
     public void testDecoderPartial() throws Exception {
-        XMPPProtocolDecoder decoder = new XMPPProtocolDecoder();
+        XMPPProtocolDecoderDepricated decoder = new XMPPProtocolDecoderDepricated();
         MockIoSession session = new MockIoSession();
         ByteBuffer firstByteBuffer = createByteBuffer();
         ByteBuffer secondByteBuffer = createByteBuffer();

Added: labs/vysper/src/test/java/org/apache/vysper/xmpp/xmldecoder/XMLParticleTestCase.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/test/java/org/apache/vysper/xmpp/xmldecoder/XMLParticleTestCase.java?rev=582676&view=auto
==============================================================================
--- labs/vysper/src/test/java/org/apache/vysper/xmpp/xmldecoder/XMLParticleTestCase.java (added)
+++ labs/vysper/src/test/java/org/apache/vysper/xmpp/xmldecoder/XMLParticleTestCase.java Sun Oct  7 13:36:02 2007
@@ -0,0 +1,45 @@
+/***********************************************************************
+ * Copyright (c) 2006-2007 The Apache Software Foundation.             *
+ * All rights reserved.                                                *
+ * ------------------------------------------------------------------- *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you *
+ * may not use this file except in compliance with the License. You    *
+ * may obtain a copy of the License at:                                *
+ *                                                                     *
+ *     http://www.apache.org/licenses/LICENSE-2.0                      *
+ *                                                                     *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an "AS IS" BASIS,   *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or     *
+ * implied.  See the License for the specific language governing       *
+ * permissions and limitations under the License.                      *
+ ***********************************************************************/
+package org.apache.vysper.xmpp.xmldecoder;
+
+import junit.framework.TestCase;
+
+import java.util.regex.Matcher;
+
+/**
+ */
+public class XMLParticleTestCase extends TestCase {
+
+    public void testPattern() {
+        assertOpeningElementName("<stream>", "stream");
+        assertOpeningElementName("<!stream>", "stream");
+        assertOpeningElementName("<stream!>", "stream");
+        assertOpeningElementName("<?stream?>", "stream");
+        assertOpeningElementName("<?stream ?>", "stream");
+        assertOpeningElementName("<stream />", "stream");
+        assertOpeningElementName("<stream:stream />", "stream:stream");
+        assertOpeningElementName("<stream:stream x=\"x\" />", "stream:stream");
+        assertOpeningElementName("<stream:stream x=\'x\' />", "stream:stream");
+    }
+
+    private void assertOpeningElementName(String input, String expected) {
+        Matcher matcher = XMLParticle.PATTERN_NAME_FROM_OPENING_ELEMENT.matcher(input);
+        assertTrue(matcher.matches());
+        String match = matcher.group(1);
+        assertEquals(expected, match);
+    }
+}

Added: labs/vysper/src/test/java/org/apache/vysper/xmpp/xmldecoder/XMLRawToFragementConverterBalancedTestCase.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/test/java/org/apache/vysper/xmpp/xmldecoder/XMLRawToFragementConverterBalancedTestCase.java?rev=582676&view=auto
==============================================================================
--- labs/vysper/src/test/java/org/apache/vysper/xmpp/xmldecoder/XMLRawToFragementConverterBalancedTestCase.java (added)
+++ labs/vysper/src/test/java/org/apache/vysper/xmpp/xmldecoder/XMLRawToFragementConverterBalancedTestCase.java Sun Oct  7 13:36:02 2007
@@ -0,0 +1,122 @@
+/***********************************************************************
+ * Copyright (c) 2006-2007 The Apache Software Foundation.             *
+ * All rights reserved.                                                *
+ * ------------------------------------------------------------------- *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you *
+ * may not use this file except in compliance with the License. You    *
+ * may obtain a copy of the License at:                                *
+ *                                                                     *
+ *     http://www.apache.org/licenses/LICENSE-2.0                      *
+ *                                                                     *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an "AS IS" BASIS,   *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or     *
+ * implied.  See the License for the specific language governing       *
+ * permissions and limitations under the License.                      *
+ ***********************************************************************/
+package org.apache.vysper.xmpp.xmldecoder;
+
+import junit.framework.TestCase;
+
+import java.util.List;
+import java.util.ArrayList;
+
+/**
+ */
+public class XMLRawToFragementConverterBalancedTestCase extends TestCase {
+
+    public void testSimple1() {
+        List<XMLParticle> particles = new ArrayList<XMLParticle>();
+
+        particles.add(new XMLParticle("<balanced>"));
+        particles.add(new XMLParticle("</balanced>"));
+        
+        assertTrue(new XMLRawToFragementConverter().isBalanced(particles));
+    }
+    public void testSimple2() {
+        List<XMLParticle> particles = new ArrayList<XMLParticle>();
+
+        particles.add(new XMLParticle("<balanced>"));
+        particles.add(new XMLParticle("plain"));
+        particles.add(new XMLParticle("</balanced>"));
+        
+        assertTrue(new XMLRawToFragementConverter().isBalanced(particles));
+    }
+    public void testSimple3() {
+        List<XMLParticle> particles = new ArrayList<XMLParticle>();
+
+        particles.add(new XMLParticle("<balanced/>"));
+        
+        assertTrue(new XMLRawToFragementConverter().isBalanced(particles));
+    }
+    public void testSimple4() {
+        List<XMLParticle> particles = new ArrayList<XMLParticle>();
+
+        particles.add(new XMLParticle("balanced"));
+        
+        assertTrue(new XMLRawToFragementConverter().isBalanced(particles));
+    }
+    public void testSimple5() {
+        List<XMLParticle> particles = new ArrayList<XMLParticle>();
+
+        particles.add(new XMLParticle("<unbalanced>"));
+        
+        assertFalse(new XMLRawToFragementConverter().isBalanced(particles));
+    }
+    public void testSimple6() {
+        List<XMLParticle> particles = new ArrayList<XMLParticle>();
+
+        particles.add(new XMLParticle("<unbalanced>"));
+        particles.add(new XMLParticle("<unbalanced2>"));
+        
+        assertFalse(new XMLRawToFragementConverter().isBalanced(particles));
+    }
+    public void testSimple7() {
+        List<XMLParticle> particles = new ArrayList<XMLParticle>();
+
+        particles.add(new XMLParticle("<balanced>"));
+        particles.add(new XMLParticle("</balanced>"));
+        particles.add(new XMLParticle("<unbalanced>"));
+        
+        assertFalse(new XMLRawToFragementConverter().isBalanced(particles));
+    }
+
+
+    public void testNested1() {
+        List<XMLParticle> particles = new ArrayList<XMLParticle>();
+
+        particles.add(new XMLParticle("<balanced>"));
+        particles.add(new XMLParticle("<inner/>"));
+        particles.add(new XMLParticle("</balanced>"));
+        
+        assertTrue(new XMLRawToFragementConverter().isBalanced(particles));
+    }
+    public void testNested2() {
+        List<XMLParticle> particles = new ArrayList<XMLParticle>();
+
+        particles.add(new XMLParticle("<balanced>"));
+        particles.add(new XMLParticle("inner"));
+        particles.add(new XMLParticle("</balanced>"));
+        
+        assertTrue(new XMLRawToFragementConverter().isBalanced(particles));
+    }
+    public void testNested3() {
+        List<XMLParticle> particles = new ArrayList<XMLParticle>();
+
+        particles.add(new XMLParticle("<balanced>"));
+        particles.add(new XMLParticle("<inner>"));
+        particles.add(new XMLParticle("</inner>"));
+        particles.add(new XMLParticle("</balanced>"));
+        
+        assertTrue(new XMLRawToFragementConverter().isBalanced(particles));
+    }
+    public void testNested4() {
+        List<XMLParticle> particles = new ArrayList<XMLParticle>();
+
+        particles.add(new XMLParticle("<unbalanced>"));
+        particles.add(new XMLParticle("<inner>"));
+        particles.add(new XMLParticle("</inner>"));
+        
+        assertFalse(new XMLRawToFragementConverter().isBalanced(particles));
+    }
+}

Added: labs/vysper/src/test/java/org/apache/vysper/xmpp/xmldecoder/XMLRawToFragementConverterConvertTestCase.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/test/java/org/apache/vysper/xmpp/xmldecoder/XMLRawToFragementConverterConvertTestCase.java?rev=582676&view=auto
==============================================================================
--- labs/vysper/src/test/java/org/apache/vysper/xmpp/xmldecoder/XMLRawToFragementConverterConvertTestCase.java (added)
+++ labs/vysper/src/test/java/org/apache/vysper/xmpp/xmldecoder/XMLRawToFragementConverterConvertTestCase.java Sun Oct  7 13:36:02 2007
@@ -0,0 +1,25 @@
+/***********************************************************************
+ * Copyright (c) 2006-2007 The Apache Software Foundation.             *
+ * All rights reserved.                                                *
+ * ------------------------------------------------------------------- *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you *
+ * may not use this file except in compliance with the License. You    *
+ * may obtain a copy of the License at:                                *
+ *                                                                     *
+ *     http://www.apache.org/licenses/LICENSE-2.0                      *
+ *                                                                     *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an "AS IS" BASIS,   *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or     *
+ * implied.  See the License for the specific language governing       *
+ * permissions and limitations under the License.                      *
+ ***********************************************************************/
+package org.apache.vysper.xmpp.xmldecoder;
+
+import junit.framework.TestCase;
+
+/**
+ */
+public class XMLRawToFragementConverterConvertTestCase extends TestCase {
+    
+}
\ No newline at end of file



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@labs.apache.org
For additional commands, e-mail: commits-help@labs.apache.org