commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ra...@apache.org
Subject svn commit: r964979 - /commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/SCXMLTestHelper.java
Date Fri, 16 Jul 2010 23:22:31 GMT
Author: rahul
Date: Fri Jul 16 23:22:30 2010
New Revision: 964979

URL: http://svn.apache.org/viewvc?rev=964979&view=rev
Log:
Add a String to namespace aware Document utility method for tests.

Modified:
    commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/SCXMLTestHelper.java

Modified: commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/SCXMLTestHelper.java
URL: http://svn.apache.org/viewvc/commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/SCXMLTestHelper.java?rev=964979&r1=964978&r2=964979&view=diff
==============================================================================
--- commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/SCXMLTestHelper.java
(original)
+++ commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/SCXMLTestHelper.java
Fri Jul 16 23:22:30 2010
@@ -21,12 +21,15 @@ import java.io.FileInputStream;
 import java.io.FileOutputStream;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
+import java.io.StringReader;
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 import java.util.Set;
 
+import javax.xml.parsers.DocumentBuilderFactory;
+
 import junit.framework.Assert;
 
 import org.apache.commons.scxml.env.SimpleDispatcher;
@@ -38,6 +41,8 @@ import org.apache.commons.scxml.model.Cu
 import org.apache.commons.scxml.model.ModelException;
 import org.apache.commons.scxml.model.SCXML;
 import org.apache.commons.scxml.model.TransitionTarget;
+import org.w3c.dom.Document;
+import org.xml.sax.InputSource;
 /**
  * Helper methods for running SCXML unit tests.
  */
@@ -286,6 +291,22 @@ public class SCXMLTestHelper {
     }
 
     /**
+     * Parses a String containing XML source into a {@link Document}.
+     *
+     * @param xml The XML source as a String.
+     * @return The parsed {@link Document}.
+     */
+    public static Document stringToXMLDocument(final String xml) {
+        try {
+            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+            dbf.setNamespaceAware(true);
+            return dbf.newDocumentBuilder().parse(new InputSource(new StringReader(xml)));
+        } catch (Exception e) {
+            throw new RuntimeException("Exception parsing String to Node:\n" + xml);
+        }
+    }
+
+    /**
      * Get the active leaf state for this executor instance.
      * Assumes no usage of <parallel>.
      *



Mime
View raw message