validator: fix bugs in checking character content in foreign elements

See ODF 1.2 section 3.17 Foreign Elements and Attributes.

In particular, for ODF 1.2 it was not actually checked whether an
ancestor is a <text:p>/<text:h> element (which is where it differs from
ODF 1.1).

git-svn-id: https://svn.apache.org/repos/asf/incubator/odf/trunk@1643200 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/validator/src/main/java/org/odftoolkit/odfvalidator/ForeignContentFilter.java b/validator/src/main/java/org/odftoolkit/odfvalidator/ForeignContentFilter.java
index fd7a6b0..58fb76a 100644
--- a/validator/src/main/java/org/odftoolkit/odfvalidator/ForeignContentFilter.java
+++ b/validator/src/main/java/org/odftoolkit/odfvalidator/ForeignContentFilter.java
@@ -106,7 +106,10 @@
         else
         {
             if( isProcessContent() )
+            {
+                m_aParagraphAncestorElements.removeElementAt(m_aParagraphAncestorElements.size()-1);
                 super.endElement(aUri,aLocalName,aQName);
+            }
         }
     }
 
@@ -123,7 +126,9 @@
                 String aProcessContentValue = aAtts.getValue( OFFICE_NAMESPACE_URI, PROCESS_CONTENT );
                 if( m_aVersion.compareTo( OdfVersion.V1_2 ) >= 0 )
                 {
-                    bProcessContent = aProcessContentValue != null ? aProcessContentValue.equals(TRUE) : true;
+                    bProcessContent = aProcessContentValue != null
+                                        ? aProcessContentValue.equals(TRUE)
+                                        : hasParagraphAncestorElement();
                 }
                 else
                 {
diff --git a/validator/src/test/java/org/odftoolkit/odfvalidator/ValidTest.java b/validator/src/test/java/org/odftoolkit/odfvalidator/ValidTest.java
index dc89ee4..ddaddcf 100644
--- a/validator/src/test/java/org/odftoolkit/odfvalidator/ValidTest.java
+++ b/validator/src/test/java/org/odftoolkit/odfvalidator/ValidTest.java
@@ -84,5 +84,62 @@
 		}
         //Assert.assertTrue(output.contains("dummy.odt:Info:no errors, no warnings"));
     }	
-	
+
+    @Test
+    public void validateForeignElementCharacterContentStrict() {
+        String output = "";
+        try {
+            String name = "extnumberstyle.ods";
+            output = doValidation(name, OdfVersion.V1_2, OdfValidatorMode.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.assertTrue(output.contains("Error:"));
+        Assert.assertTrue(output.contains("styles.xml[32,19]:"));
+    }
+
+    @Test
+    public void validateForeignElementCharacterContentExtended() {
+        String output = "";
+        try {
+            String name = "extnumberstyle.ods";
+            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:"));
+    }
+
+    @Test
+    public void validateForeignElementCharacterContentExtendedProcessContent() {
+        String output = "";
+        try {
+            String name = "extnumberstyle-processcontent.ods";
+            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.assertTrue(output.contains("unexpected character literal"));
+        Assert.assertTrue(output.contains("styles.xml[34,79]:"));
+    }
+
 }
diff --git a/validator/src/test/resources/extnumberstyle-processcontent.ods b/validator/src/test/resources/extnumberstyle-processcontent.ods
new file mode 100644
index 0000000..5b556bf
--- /dev/null
+++ b/validator/src/test/resources/extnumberstyle-processcontent.ods
Binary files differ
diff --git a/validator/src/test/resources/extnumberstyle.ods b/validator/src/test/resources/extnumberstyle.ods
new file mode 100644
index 0000000..52a2bc4
--- /dev/null
+++ b/validator/src/test/resources/extnumberstyle.ods
Binary files differ