Repository: commons-scxml Updated Branches: refs/heads/master 8175510d7 -> 8847e59f6
SCXML-251: Parse src attribute of data elements Also: reject data elements which have src and data defined. According to the scmxl standard only src or data are allowed. Project: http://git-wip-us.apache.org/repos/asf/commons-scxml/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-scxml/commit/6f6f0f69 Tree: http://git-wip-us.apache.org/repos/asf/commons-scxml/tree/6f6f0f69 Diff: http://git-wip-us.apache.org/repos/asf/commons-scxml/diff/6f6f0f69 Branch: refs/heads/master Commit: 6f6f0f698dd81a0220cc74d6c10f545f23374bf4 Parents: 8175510 Author: Tobias Lippert <[email protected]> Authored: Sun Jul 31 19:41:22 2016 +0200 Committer: Tobias Lippert <[email protected]> Committed: Sun Jul 31 19:53:07 2016 +0200 ---------------------------------------------------------------------- .../apache/commons/scxml2/io/SCXMLReader.java | 16 ++++++++++- .../commons/scxml2/io/SCXMLReaderTest.java | 17 ++++++++++++ .../scxml2/io/data-with-src-and-expr.xml | 29 ++++++++++++++++++++ .../apache/commons/scxml2/io/data-with-src.xml | 29 ++++++++++++++++++++ 4 files changed, 90 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/commons-scxml/blob/6f6f0f69/src/main/java/org/apache/commons/scxml2/io/SCXMLReader.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/scxml2/io/SCXMLReader.java b/src/main/java/org/apache/commons/scxml2/io/SCXMLReader.java index bd44c19..99fa563 100644 --- a/src/main/java/org/apache/commons/scxml2/io/SCXMLReader.java +++ b/src/main/java/org/apache/commons/scxml2/io/SCXMLReader.java @@ -1094,7 +1094,21 @@ public final class SCXMLReader { Data datum = new Data(); datum.setId(readRequiredAV(reader, ELEM_DATA, ATTR_ID)); - datum.setExpr(readAV(reader, ATTR_EXPR)); + final String expr = readAV(reader, ATTR_EXPR); + final String src = readAV(reader, ATTR_SRC); + + if (expr != null && src != null) { + LogFactory.getLog(SCXMLReader.class).error( + "Found src and expr attributes for data node '" + datum.getId() + "', which is not valid SCXML."); + throw new ModelException(); + } + if (expr != null) { + datum.setExpr(expr); + } + if (src != null) { + datum.setSrc(src); + } + readNamespaces(configuration, datum); Node node = readNode(reader, configuration, XMLNS_SCXML, ELEM_DATA, new String[]{"id"}); datum.setNode(node); http://git-wip-us.apache.org/repos/asf/commons-scxml/blob/6f6f0f69/src/test/java/org/apache/commons/scxml2/io/SCXMLReaderTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/scxml2/io/SCXMLReaderTest.java b/src/test/java/org/apache/commons/scxml2/io/SCXMLReaderTest.java index d935bb5..415e66c 100644 --- a/src/test/java/org/apache/commons/scxml2/io/SCXMLReaderTest.java +++ b/src/test/java/org/apache/commons/scxml2/io/SCXMLReaderTest.java @@ -278,6 +278,23 @@ public class SCXMLReaderTest { Assert.assertNotNull(scxml.getGlobalScript()); } + @Test(expected=org.apache.commons.scxml2.model.ModelException.class) + public void dataWithSrcAndExprIsRejected() throws Exception { + SCXMLTestHelper.parse("org/apache/commons/scxml2/io/data-with-src-and-expr.xml"); + } + + @Test + public void srcAttributeOfDataIsParsed() throws Exception { + SCXML scxml = SCXMLTestHelper.parse("org/apache/commons/scxml2/io/data-with-src.xml"); + Assert.assertNotNull(scxml); + Assert.assertNotNull(scxml.getDatamodel()); + Assert.assertNotNull(scxml.getDatamodel().getData()); + Assert.assertEquals("Exactly one data element parsed.", 1, scxml.getDatamodel().getData().size()); + Data data = scxml.getDatamodel().getData().get(0); + Assert.assertNotNull(data); + Assert.assertEquals("http://www.w3.org/TR/sxcml", data.getSrc()); + } + private String serialize(final SCXML scxml) throws IOException, XMLStreamException { String scxmlAsString = SCXMLWriter.write(scxml); Assert.assertNotNull(scxmlAsString); http://git-wip-us.apache.org/repos/asf/commons-scxml/blob/6f6f0f69/src/test/java/org/apache/commons/scxml2/io/data-with-src-and-expr.xml ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/scxml2/io/data-with-src-and-expr.xml b/src/test/java/org/apache/commons/scxml2/io/data-with-src-and-expr.xml new file mode 100644 index 0000000..9dad4e5 --- /dev/null +++ b/src/test/java/org/apache/commons/scxml2/io/data-with-src-and-expr.xml @@ -0,0 +1,29 @@ +<?xml version="1.0"?> +<!-- + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. +--> +<!-- Used for SrcTest.java in io package --> +<scxml xmlns="http://www.w3.org/2005/07/scxml" + version="1.0" + initial="foo"> + + <datamodel> + <data id="theData" src="http://www.w3.org/TR/sxcml" expr="'a value'" /> + </datamodel> + + <final id="foo"/> + +</scxml> http://git-wip-us.apache.org/repos/asf/commons-scxml/blob/6f6f0f69/src/test/java/org/apache/commons/scxml2/io/data-with-src.xml ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/scxml2/io/data-with-src.xml b/src/test/java/org/apache/commons/scxml2/io/data-with-src.xml new file mode 100644 index 0000000..cc044fe --- /dev/null +++ b/src/test/java/org/apache/commons/scxml2/io/data-with-src.xml @@ -0,0 +1,29 @@ +<?xml version="1.0"?> +<!-- + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. +--> +<!-- Used for SrcTest.java in io package --> +<scxml xmlns="http://www.w3.org/2005/07/scxml" + version="1.0" + initial="foo"> + + <datamodel> + <data id="theData" src="http://www.w3.org/TR/sxcml" /> + </datamodel> + + <final id="foo"/> + +</scxml>
