Skip to content

Commit

Permalink
changeset: 34:8805ccf2d478
Browse files Browse the repository at this point in the history
user:        michael.brauer
date:        Fri Mar 25 13:16:07 2011 +0100
- Optimized schema extraction
- Adapted tests to ODFDOM 0.8.7

git-svn-id: https://svn.apache.org/repos/asf/incubator/odf/trunk@1172465 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
Biao Han committed Sep 19, 2011
1 parent b9557b1 commit 9e51462
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 73 deletions.
18 changes: 10 additions & 8 deletions validator/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -167,22 +167,23 @@
<target name="-extract-v10-schema" depends="init" if="opendocument.v10.schema.extract">
<property file="ant.properties"/>
<taskdef name="odfxslt" classname="org.odftoolkit.odfxsltrunnertask.ODFXSLTRunnerTask" classpath="${reference.odfxsltrunner-task.jar}:${reference.odfxsltrunner.jar}"/>
<property name="v10.target.dir" value="${build.classes.dir}/schema/odf10"/>
<odfxslt in="${opendocument.v10.schema.dir}/${opendocument.v10.spec}"
outfile="${build.classes.dir}/schema/odf10/${opendocument.v10.schema}"
outfile="${v10.target.dir}/${opendocument.v10.schema}"
style="xslt/extract_schema.xsl">
<param name="mode" expression="schema"/>
</odfxslt>
<odfxslt in="${opendocument.v10.schema.dir}/${opendocument.v10.spec}"
outfile="${build.classes.dir}/schema/odf10/${opendocument.v10.schema.strict}"
outfile="${v10.target.dir}/${opendocument.v10.schema.strict}"
style="xslt/extract_schema.xsl">
<param name="mode" expression="strict-schema"/>
</odfxslt>
<odfxslt in="${opendocument.v10.schema.dir}/${opendocument.v10.spec}"
outfile="${build.classes.dir}/schema/odf10/${opendocument.v10.schema.manifest}"
outfile="${v10.target.dir}/${opendocument.v10.schema.manifest}"
style="xslt/extract_schema.xsl">
<param name="mode" expression="manifest-schema"/>
</odfxslt>
<fixcrlf srcdir="${build.classes.dir}/schema/odf10" eol="lf"/>
<fixcrlf srcdir="${v10.target.dir}" eol="lf"/>
</target>

<target name="-copy-v11-schema" depends="init" unless="opendocument.v11.schema.extract">
Expand All @@ -195,22 +196,23 @@
<target name="-extract-v11-schema" depends="init" if="opendocument.v11.schema.extract">
<property file="ant.properties"/>
<taskdef name="odfxslt" classname="org.odftoolkit.odfxsltrunnertask.ODFXSLTRunnerTask" classpath="${reference.odfxsltrunner-task.jar}:${reference.odfxsltrunner.jar}"/>
<property name="v11.target.dir" value="${build.classes.dir}/schema/odf11"/>
<odfxslt in="${opendocument.v11.schema.dir}/${opendocument.v11.spec}"
outfile="${build.classes.dir}/schema/odf11/${opendocument.v11.schema}"
outfile="${v11.target.dir}/${opendocument.v11.schema}"
style="xslt/extract_schema.xsl">
<param name="mode" expression="schema"/>
</odfxslt>
<odfxslt in="${opendocument.v11.schema.dir}/${opendocument.v11.spec}"
outfile="${build.classes.dir}/schema/odf11/${opendocument.v11.schema.strict}"
outfile="${v11.target.dir}/${opendocument.v11.schema.strict}"
style="xslt/extract_schema.xsl">
<param name="mode" expression="strict-schema"/>
</odfxslt>
<odfxslt in="${opendocument.v11.schema.dir}/${opendocument.v11.spec}"
outfile="${build.classes.dir}/schema/odf11/${opendocument.v11.schema.manifest}"
outfile="${v11.target.dir}/${opendocument.v11.schema.manifest}"
style="xslt/extract_schema.xsl">
<param name="mode" expression="manifest-schema"/>
</odfxslt>
<fixcrlf srcdir="${build.classes.dir}/schema/odf11" eol="lf"/>
<fixcrlf srcdir="${v11.target.dir}" eol="lf"/>
</target>

<target name="-copy-v12-schema" depends="init">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void validatePackage1_V1_1() {
Assert.assertTrue(output.contains("testInvalidPkg1.odt/mimetype:Error:The file 'mimetype' shall not be compressed"));
Assert.assertTrue(output.contains("testInvalidPkg1.odt/mimetype:Error:There shall be no extra field for the 'mimetype' file"));
Assert.assertTrue(output.contains("testInvalidPkg1.odt/META-INF/manifest.xml:Error:The file 'Configurations2/accelerator/current.xml' shall not be listed in the 'META-INF/manifest.xml' file as it does not exist in the ODF package"));
Assert.assertTrue(output.contains("testInvalidPkg1.odt:Info:9 errors, 11 warnings"));
Assert.assertTrue(output.contains("testInvalidPkg1.odt:Info:10 errors, 11 warnings"));
}

@Test
Expand Down Expand Up @@ -92,7 +92,7 @@ public void validatePackage2_V1_1() {
Assert.assertTrue(output.contains("testInvalidPkg2.odt/mimetype:Warning:The ODF package 'testInvalidPkg2.odt' contains no 'mimetype' file"));
Assert.assertTrue(output.contains("testInvalidPkg2.odt/META-INF/manifest.xml:Error:The file 'Configurations2/accelerator/current.xml' shall not be listed in the 'META-INF/manifest.xml' file as it does not exist in the ODF package"));
Assert.assertTrue(output.contains("testInvalidPkg2.odt/META-INF/manifest.xml:Warning:The file 'not_in_manifest' shall be listed in the 'META-INF/manifest.xml' file as it exists in the ODF package"));
Assert.assertTrue(output.contains("testInvalidPkg2.odt:Info:6 errors, 12 warnings"));
Assert.assertTrue(output.contains("testInvalidPkg2.odt:Info:7 errors, 12 warnings"));
}

@Test
Expand Down
78 changes: 15 additions & 63 deletions validator/xslt/extract_schema.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
Copyright 2008, 2010 Oracle and/or its affiliates. All rights reserved.
Copyright 2011 Oracle and/or its affiliates. All rights reserved.
Use is subject to license terms.
Expand Down Expand Up @@ -37,92 +37,44 @@
<!-- 'manifest-schema': Extracts the manifest schema -->
<xsl:param name="mode" select="'schema'"/>

<!-- map mode paramater to style names -->
<!-- map mode parameter to style names -->
<!-- which paragraph styles do we wish to extract? -->
<xsl:param name="style">
<xsl:variable name="extract-style-name">
<xsl:choose>
<xsl:when test="$mode='strict-schema'">
<xsl:value-of select="'RelaxNG_20_Strict'"/>
</xsl:when>
<xsl:when test="$mode='manifest-schema'">
<xsl:value-of select="'RelaxNG_20_Manifest'"/>
</xsl:when>
<xsl:when test="$mode='dsig-schema'">
<xsl:value-of select="'RelaxNG_20_DSig'"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="'RelaxNG'"/>
</xsl:otherwise>
</xsl:choose>
</xsl:param>
<xsl:param name="style2">
<xsl:choose>
<xsl:when test="$mode='strict-schema'">
<xsl:value-of select="'Changed_20_Relax_20_NG_20_Strict'"/>
</xsl:when>
<xsl:when test="$mode='manifest-schema'">
<xsl:value-of select="'Changed_20_Relax_20_NG_20_Manifest'"/>
</xsl:when>
<xsl:when test="$mode='dsig-schema'">
<xsl:value-of select="'Changed_20_Relax_20_NG_20_DSig'"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="'Changed_20_Relax_20_NG'"/>
</xsl:otherwise>
</xsl:choose>
</xsl:param>
<xsl:param name="style3">
<xsl:choose>
<xsl:when test="$mode='strict-schema'">
<xsl:value-of select="'RelaxNG_20_Strict_Linenumber_20_Correction'"/>
</xsl:when>
<xsl:when test="$mode='manifest-schema'">
<xsl:value-of select="'RelaxNG_20_Manifest_Linenumber_20_Correction'"/>
</xsl:when>
<xsl:when test="$mode='dsig-schema'">
<xsl:value-of select="'RelaxNG_20_DSig_20_Linenumber_20_Correction'"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="'RelaxNG_20_Linenumber_20_Correction'"/>
</xsl:otherwise>
</xsl:choose>
</xsl:param>
<xsl:param name="style4">
<xsl:choose>
<xsl:when test="$mode='strict-schema'">
<xsl:value-of select="'RelaxNG_20_Strict_20_Start'"/>
</xsl:when>
<xsl:when test="$mode='manifest-schema'">
<xsl:value-of select="'RelaxNG_20_Manifest_20_Start'"/>
</xsl:when>
<xsl:when test="$mode='dsig-schema'">
<xsl:value-of select="'RelaxNG_20_DSig_20_Start'"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="'RelaxNG_20_Start'"/>
</xsl:otherwise>
</xsl:choose>
</xsl:param>
</xsl:variable>

<!-- define 'styles' key. It selects all style:style element with a certain name -->
<xsl:key name="styles"
match="style:style"
use="@style:name" />

<!-- Look only at paragraphs -->
<xsl:template match="office:document-content">
<xsl:apply-templates select="office:body/office:text//text:p"/>
</xsl:template>

<!-- analyze paragraphs -->
<!-- Analyze paragraphs -->
<xsl:template match="text:p">

<!-- determine all parent styles of this paragraph; use key 'parents' -->
<xsl:variable name="parent-styles"
select="@text:style-name |
key('styles',@text:style-name)/@style:parent-style-name"/>

<xsl:variable name="content-style-names" select="@text:style-name|key('styles',@text:style-name)/@style:parent-style-name"/>
<xsl:variable name="styles-style-names">
<xsl:for-each select="document('styles.xml',.)">
<xsl:value-of select="key('styles',$content-style-names)/@style:parent-style-name"/>
</xsl:for-each>
</xsl:variable>

<!-- if schema parent style is found, generate output -->
<xsl:if test="$parent-styles = $style or $parent-styles = $style2 or $parent-styles = $style3 or $parent-styles = $style4">
<xsl:if test="$content-style-names = $extract-style-name or $styles-style-names = $extract-style-name">
<xsl:apply-templates mode="output"/>
<xsl:text>
</xsl:text>
Expand Down Expand Up @@ -165,4 +117,4 @@
</xsl:if>
</xsl:template>

</xsl:stylesheet>
</xsl:stylesheet>

0 comments on commit 9e51462

Please sign in to comment.