commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ra...@apache.org
Subject svn commit: r653173 - in /commons/proper/scxml/branches/J6/src: main/java/org/apache/commons/scxml/io/SCXMLParser.java test/java/org/apache/commons/scxml/issues/issue64-02.xml
Date Sun, 04 May 2008 02:50:21 GMT
Author: rahul
Date: Sat May  3 19:50:19 2008
New Revision: 653173

URL: http://svn.apache.org/viewvc?rev=653173&view=rev
Log:
Port r653172 from trunk.
Better error reporting for ignored / misplaced elements by parser.
SCXML-64


Modified:
    commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/io/SCXMLParser.java
    commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/issues/issue64-02.xml

Modified: commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/io/SCXMLParser.java
URL: http://svn.apache.org/viewvc/commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/io/SCXMLParser.java?rev=653173&r1=653172&r2=653173&view=diff
==============================================================================
--- commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/io/SCXMLParser.java
(original)
+++ commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/io/SCXMLParser.java
Sat May  3 19:50:19 2008
@@ -33,6 +33,7 @@
 import org.apache.commons.digester.Rule;
 import org.apache.commons.digester.SetNextRule;
 import org.apache.commons.digester.SetPropertiesRule;
+import org.apache.commons.digester.WithDefaultsRulesWrapper;
 import org.apache.commons.logging.LogFactory;
 import org.apache.commons.scxml.PathResolver;
 import org.apache.commons.scxml.SCXMLHelper;
@@ -75,6 +76,7 @@
 import org.xml.sax.Attributes;
 import org.xml.sax.ErrorHandler;
 import org.xml.sax.InputSource;
+import org.xml.sax.Locator;
 import org.xml.sax.SAXException;
 
 /**
@@ -486,7 +488,10 @@
         digester.setNamespaceAware(true);
         //Uncomment next line after SCXML DTD is available
         //digester.setValidating(true);
-        digester.setRules(initRules(scxml, pr, customActions));
+        WithDefaultsRulesWrapper rules =
+            new WithDefaultsRulesWrapper(initRules(scxml, pr, customActions));
+        rules.addDefault(new IgnoredElementRule());
+        digester.setRules(rules);
         return digester;
     }
 
@@ -1639,5 +1644,32 @@
         }
     }
 
+    /**
+     * Custom digestion rule logging ignored elements.
+     */
+    private static class IgnoredElementRule extends Rule {
+
+        /**
+         * @see Rule#begin(String, String, Attributes)
+         */
+        public final void begin(final String namespace, final String name,
+                final Attributes attributes) {
+            org.apache.commons.logging.Log log = LogFactory.
+                getLog(SCXMLParser.class);
+            Locator l = digester.getDocumentLocator();
+            String identifier = l.getSystemId();
+            if (identifier == null) {
+                identifier = l.getPublicId();
+            }
+            StringBuffer sb = new StringBuffer();
+            sb.append("Ignoring element <").append(name).
+                append("> in namespace \"").append(namespace).
+                append("\" at ").append(identifier).append(":").
+                append(l.getLineNumber()).append(":").
+                append(l.getColumnNumber()).append(" and digester match \"").
+                append(digester.getMatch()).append("\"");
+            log.warn(sb.toString());
+        }
+    }
 }
 

Modified: commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/issues/issue64-02.xml
URL: http://svn.apache.org/viewvc/commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/issues/issue64-02.xml?rev=653173&r1=653172&r2=653173&view=diff
==============================================================================
--- commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/issues/issue64-02.xml
(original)
+++ commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/issues/issue64-02.xml
Sat May  3 19:50:19 2008
@@ -15,17 +15,29 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
 -->
-<!-- Bad SCXML document -->
+<!-- Bad SCXML document, many elements will be ignored with warnings from parser -->
 <scxml xmlns="http://www.w3.org/2005/07/scxml"
+       xmlns:my="http://my.foo.example/"
        version="1.0"
        initialstate="tranbug">
 
+    <datamodel>
+        <data name="foo">
+            <alpha xmlns="">
+                <beta/>
+            </alpha>
+        </data>
+        <misplaced/>
+    </datamodel>
+
     <state id="tranbug">
         <onentry>
             <log expr="'Begin transition bug test ...'" />
+            <foo/>
+            <my:bar/>
         </onentry>
         <transition event="show.bug" target="end">
-         <!-- FOLLOWING datamodel IS MISPLACED -->
+         <!-- For example, FOLLOWING datamodel IS MISPLACED -->
          <datamodel>
  			<data name="dummy" expr="'somedata'"/>
          </datamodel>
@@ -34,6 +46,8 @@
         </transition>
     </state>
     
+    <my:baz/>
+
     <state id="end" final="true" />
 
 </scxml>



Mime
View raw message