You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ra...@apache.org on 2009/07/13 00:38:46 UTC

svn commit: r793422 - in /commons/proper/scxml/branches/J6/src: main/java/org/apache/commons/scxml/io/SCXMLReader.java test/java/org/apache/commons/scxml/io/SCXMLReaderTest.java

Author: rahul
Date: Sun Jul 12 22:38:45 2009
New Revision: 793422

URL: http://svn.apache.org/viewvc?rev=793422&view=rev
Log:
Add <script> parsing to the SCXMLReader, and also improve <data> parsing.
Changed SCXMLReader test names to better match the suite they are in.

Modified:
    commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/io/SCXMLReader.java
    commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/io/SCXMLReaderTest.java

Modified: commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/io/SCXMLReader.java
URL: http://svn.apache.org/viewvc/commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/io/SCXMLReader.java?rev=793422&r1=793421&r2=793422&view=diff
==============================================================================
--- commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/io/SCXMLReader.java (original)
+++ commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/io/SCXMLReader.java Sun Jul 12 22:38:45 2009
@@ -1061,6 +1061,8 @@
 
         Data datum = new Data();
         datum.setId(readAV(reader, ATTR_ID));
+        datum.setExpr(readAV(reader, ATTR_EXPR));
+        readNamespaces(configuration, datum);
         datum.setNode(readNode(reader, configuration, XMLNS_SCXML, ELEM_DATA, new String[] {"id"}));
         dm.addData(datum);
 
@@ -1710,6 +1712,7 @@
 
         Script script = new Script();
         readNamespaces(configuration, script);
+        script.setBody(readBody(reader, configuration, XMLNS_SCXML, ELEM_SCRIPT));
         script.setParent(executable);
         if (iff != null) {
             iff.addAction(script);
@@ -1970,6 +1973,60 @@
     }
 
     /**
+     * Read the following body contents into a String.
+     *
+     * @param reader The {@link XMLStreamReader} providing the SCXML document to parse.
+     * @param configuration The {@link Configuration} to use while parsing.
+     * @param namespaceURI The namespace URI of the parent element (we will stop reading content when we reach
+     *                     the corresponding end tag)
+     * @param localName The local name of the parent element (we will stop reading content when we reach the
+     *                  corresponding end tag)
+     *
+     * @return The body content read into a String.
+     *
+     * @throws XMLStreamException An exception processing the underlying {@link XMLStreamReader}.
+     */
+    private static String readBody(final XMLStreamReader reader, final Configuration configuration,
+            final String namespaceURI, final String localName)
+    throws XMLStreamException {
+
+        StringBuffer body = new StringBuffer();
+        org.apache.commons.logging.Log log;
+
+        // Add all body content to StringBuffer
+        loop : while (reader.hasNext()) {
+            String name, nsURI;
+            switch (reader.next()) {
+                case XMLStreamConstants.START_ELEMENT:
+                    log = LogFactory.getLog(SCXMLReader.class);
+                    log.warn("Ignoring XML content in <script> element, encountered start tag with local name: "
+                        + reader.getLocalName());
+                    break;
+                case XMLStreamConstants.SPACE:
+                case XMLStreamConstants.CHARACTERS:
+                case XMLStreamConstants.ENTITY_REFERENCE:
+                case XMLStreamConstants.CDATA:
+                case XMLStreamConstants.COMMENT:
+                    body.append(reader.getText());
+                    break;
+                case XMLStreamConstants.END_ELEMENT:
+                    nsURI = reader.getNamespaceURI();
+                    name = reader.getLocalName();
+                    if (namespaceURI.equals(nsURI) && localName.equals(name)) {
+                        popNamespaces(reader, configuration);
+                        break loop;
+                    }
+                    log = LogFactory.getLog(SCXMLReader.class);
+                    log.warn("Ignoring XML content in <script> element, encountered end tag with local name: "
+                        + reader.getLocalName());
+                    break;
+                default: // rest is ignored
+            }
+        }
+        return body.toString();
+    }
+
+    /**
      * Get the attribute value at the current reader location.
      *
      * @param reader The {@link XMLStreamReader} providing the SCXML document to parse.

Modified: commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/io/SCXMLReaderTest.java
URL: http://svn.apache.org/viewvc/commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/io/SCXMLReaderTest.java?rev=793422&r1=793421&r2=793422&view=diff
==============================================================================
--- commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/io/SCXMLReaderTest.java (original)
+++ commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/io/SCXMLReaderTest.java Sun Jul 12 22:38:45 2009
@@ -108,49 +108,49 @@
     /**
      * Test the implementation
      */
-    public void testSCXMLParserMicrowave01Sample() throws Exception {
+    public void testSCXMLReaderMicrowave01Sample() throws Exception {
         scxml = SCXMLTestHelper.parse(microwave01);
         assertNotNull(scxml);
         scxmlAsString = serialize(scxml);
         assertNotNull(scxmlAsString);
     }
 
-    public void testSCXMLParserMicrowave02Sample() throws Exception {
+    public void testSCXMLReaderMicrowave02Sample() throws Exception {
         scxml = SCXMLTestHelper.parse(microwave02);
         assertNotNull(scxml);
         scxmlAsString = serialize(scxml);
         assertNotNull(scxmlAsString);
     }
 
-    public void testSCXMLParserMicrowave03Sample() throws Exception {
+    public void testSCXMLReaderMicrowave03Sample() throws Exception {
         scxml = SCXMLTestHelper.parse(microwave03);
         assertNotNull(scxml);
         scxmlAsString = serialize(scxml);
         assertNotNull(scxmlAsString);
     }
 
-    public void testSCXMLParserMicrowave04Sample() throws Exception {
+    public void testSCXMLReaderMicrowave04Sample() throws Exception {
         scxml = SCXMLTestHelper.parse(microwave04);
         assertNotNull(scxml);
         scxmlAsString = serialize(scxml);
         assertNotNull(scxmlAsString);
     }
 
-    public void testSCXMLParserTransitions01Sample() throws Exception {
+    public void testSCXMLReaderTransitions01Sample() throws Exception {
         scxml = SCXMLTestHelper.parse(transitions01);
         assertNotNull(scxml);
         scxmlAsString = serialize(scxml);
         assertNotNull(scxmlAsString);
     }
 
-    public void testSCXMLParserPrefix01Sample() throws Exception {
+    public void testSCXMLReaderPrefix01Sample() throws Exception {
         scxml = SCXMLTestHelper.parse(prefix01);
         assertNotNull(scxml);
         scxmlAsString = serialize(scxml);
         assertNotNull(scxmlAsString);
     }
 
-    public void testSCXMLParserSend01Sample() throws Exception {
+    public void testSCXMLReaderSend01Sample() throws Exception {
         // Digest
         scxml = SCXMLTestHelper.parse(send01);
         State ten = (State) scxml.getInitialTarget();
@@ -173,7 +173,7 @@
         */
     }
 
-    public void testSCXMLParserInitialAttr() throws Exception {
+    public void testSCXMLReaderInitialAttr() throws Exception {
         scxml = SCXMLTestHelper.parse(scxmlinitialattr);
         assertNotNull(scxml);
         scxmlAsString = serialize(scxml);
@@ -182,7 +182,7 @@
         assertEquals("foo", foo.getId());
     }
 
-    public void testSCXMLParserCustomActionWithBodyTextSample() throws Exception {
+    public void testSCXMLReaderCustomActionWithBodyTextSample() throws Exception {
         List<CustomAction> cas = new ArrayList<CustomAction>();
         CustomAction ca = new CustomAction("http://my.custom-actions.domain",
             "action", MyAction.class);