incubator-odf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From m..@apache.org
Subject [odftoolkit] 02/02: ODFTOOLKIT-475 validator: fix checking character content in foreign elements
Date Mon, 14 May 2018 13:13:47 GMT
This is an automated email from the ASF dual-hosted git repository.

mst pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/odftoolkit.git

commit 536201d92c7f65f5be8923762069add053e4aca9
Author: Michael Stahl <Michael.Stahl@cib.de>
AuthorDate: Tue May 8 14:03:54 2018 +0200

    ODFTOOLKIT-475 validator: fix checking character content in foreign elements
    
    ... below text:p.
    
    If the ODF element does not allow character content itself,
    then for any child foreign element the character content should be
    ignored.
    
    See ODF 1.2 part 1 section 3.17 Foreign Elements and Attributes.
    
    It's apparently not possible to ask the RelaxNG validator if an element
    allows character content, so add a hard-coded list.
---
 .../odfvalidator/ForeignContentFilter.java         |  63 ++++++++++++++++++++-
 .../org/odftoolkit/odfvalidator/ValidTest.java     |  20 +++++++
 validator/src/test/resources/sender-initials.odt   | Bin 0 -> 8647 bytes
 3 files changed, 82 insertions(+), 1 deletion(-)

diff --git a/validator/src/main/java/org/odftoolkit/odfvalidator/ForeignContentFilter.java
b/validator/src/main/java/org/odftoolkit/odfvalidator/ForeignContentFilter.java
index 58fb76a..6f61d04 100644
--- a/validator/src/main/java/org/odftoolkit/odfvalidator/ForeignContentFilter.java
+++ b/validator/src/main/java/org/odftoolkit/odfvalidator/ForeignContentFilter.java
@@ -34,6 +34,9 @@ class ForeignContentFilter extends XMLFilterImpl {
 
     private static final String OFFICE_NAMESPACE_URI = OdfDocumentNamespace.OFFICE.getUri();
     private static final String TEXT_NAMESPACE_URI = OdfDocumentNamespace.TEXT.getUri();
+    private static final String DRAW_NAMESPACE_URI = OdfDocumentNamespace.DRAW.getUri();
+    private static final String DR3D_NAMESPACE_URI = OdfDocumentNamespace.DR3D.getUri();
+    private static final String PRESENTATION_NAMESPACE_URI = OdfDocumentNamespace.PRESENTATION.getUri();
 
     private static final String H = "h";
     private static final String P = "p";
@@ -163,7 +166,65 @@ class ForeignContentFilter extends XMLFilterImpl {
             }
 
             boolean bParagraphAncestor = hasParagraphAncestorElement();
-            bParagraphAncestor |= ((aLocalName.equals(P) || aLocalName.equals(H)) &&
aUri.equals(TEXT_NAMESPACE_URI));
+            if ((aLocalName.equals(P) || aLocalName.equals(H)) && aUri.equals(TEXT_NAMESPACE_URI))
+                bParagraphAncestor = true;
+            else if ((aUri.equals(TEXT_NAMESPACE_URI) && (
+                       aLocalName.equals("s")
+                    || aLocalName.equals("tab")
+                    || aLocalName.equals("line-break")
+                    || aLocalName.equals("soft-page-break")
+                    || aLocalName.equals("bookmark")
+                    || aLocalName.equals("bookmark-start")
+                    || aLocalName.equals("bookmark-end")
+                    || aLocalName.equals("reference-mark")
+                    || aLocalName.equals("reference-mark-start")
+                    || aLocalName.equals("reference-mark-end")
+                    || aLocalName.equals("note")
+                    || aLocalName.equals("change")
+                    || aLocalName.equals("change-start")
+                    || aLocalName.equals("change-end")
+                    || aLocalName.equals("toc-mark")
+                    || aLocalName.equals("toc-mark-start")
+                    || aLocalName.equals("toc-mark-end")
+                    || aLocalName.equals("alphabetical-index-mark")
+                    || aLocalName.equals("alphabetical-index-mark-start")
+                    || aLocalName.equals("alphabetical-index-mark-end")
+                    || aLocalName.equals("user-index-mark")
+                    || aLocalName.equals("user-index-mark-start")
+                    || aLocalName.equals("user-index-mark-end")))
+                || (aUri.equals(OFFICE_NAMESPACE_URI) && (
+                       aLocalName.equals("annotation")
+                    || aLocalName.equals("annotation-end")))
+                || (aUri.equals(DRAW_NAMESPACE_URI) && (
+                       aLocalName.equals("a")
+                    || aLocalName.equals("rect")
+                    || aLocalName.equals("line")
+                    || aLocalName.equals("polyline")
+                    || aLocalName.equals("polygon")
+                    || aLocalName.equals("regular-polygon")
+                    || aLocalName.equals("path")
+                    || aLocalName.equals("circle")
+                    || aLocalName.equals("g")
+                    || aLocalName.equals("page-thumbnail")
+                    || aLocalName.equals("frame")
+                    || aLocalName.equals("measure")
+                    || aLocalName.equals("caption")
+                    || aLocalName.equals("connector")
+                    || aLocalName.equals("control")
+                    || aLocalName.equals("custom-shape")))
+                || (aUri.equals(DR3D_NAMESPACE_URI) && (
+                       aLocalName.equals("scene")))
+                || (aUri.equals(PRESENTATION_NAMESPACE_URI) && (
+                       aLocalName.equals("header")
+                    || aLocalName.equals("footer")
+                    || aLocalName.equals("date-time"))))
+            {
+                // elements that do not contain character data - by ODF 1.2
+                // part 1 3.17, the character data in foreign elements
+                // below these should be ignored by default
+                bParagraphAncestor = false;
+            }
+
             m_aParagraphAncestorElements.add(bParagraphAncestor);
 
             super.startElement(aUri, aLocalName, aQName, aAtts);
diff --git a/validator/src/test/java/org/odftoolkit/odfvalidator/ValidTest.java b/validator/src/test/java/org/odftoolkit/odfvalidator/ValidTest.java
index 8d63d1e..c6e4633 100644
--- a/validator/src/test/java/org/odftoolkit/odfvalidator/ValidTest.java
+++ b/validator/src/test/java/org/odftoolkit/odfvalidator/ValidTest.java
@@ -142,4 +142,24 @@ public class ValidTest extends OdfValidatorTestBase {
         Assert.assertTrue(output.contains("styles.xml[34,79]:"));
     }
 
+    @Test
+    public void validateForeignElementCharacterContentExtendedInNonCharacterElement() {
+        String output = "";
+        try {
+            String name = "sender-initials.odt";
+            output = doValidation(name, OdfVersion.V1_2, OdfValidatorMode.EXTENDED_CONFORMANCE,
true);
+        } catch (Throwable t) {
+            t.printStackTrace();
+            Assert.fail(t.toString());
+        }
+        if(output.contains("Exception")){
+            System.out.println("OUTPUT:" + output);
+            Assert.fail("An exception occurred during validation!");
+        }
+        System.out.println("OUTPUT:" + output);
+        Assert.assertFalse(output.contains("unexpected character literal"));
+        Assert.assertFalse(output.contains("Error:"));
+    }
+
+
 }
diff --git a/validator/src/test/resources/sender-initials.odt b/validator/src/test/resources/sender-initials.odt
new file mode 100644
index 0000000..61097ac
Binary files /dev/null and b/validator/src/test/resources/sender-initials.odt differ

-- 
To stop receiving notification emails like this one, please contact
mst@apache.org.

Mime
View raw message