Skip to content

Commit a8ed669

Browse files
Michael StahlMichael Stahl
authored andcommitted
validator: fix ODFRootPackageValidator::validateMimetype()
Mike Kaganski reported that presentation templates were causing odfvalidator.org to report "The document is NOT conformant ODF1.3!". It turns out there were several problems: * presentation template was missing/not checked * wrong media types cause logInfo, but an error will be reported to the caller, which is confusing, as it's not obvious to the user what caused the error * database (new in ODF 1.2) and text master template media types were also missing
1 parent 7dd2584 commit a8ed669

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

validator/src/main/java/org/odftoolkit/odfvalidator/ODFMediaTypes.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,8 @@ public abstract class ODFMediaTypes {
5151
"application/vnd.oasis.opendocument.formula-template";
5252
public static final String TEXT_MASTER_MEDIA_TYPE =
5353
"application/vnd.oasis.opendocument.text-master";
54+
public static final String TEXT_MASTER_TEMPLATE_MEDIA_TYPE =
55+
"application/vnd.oasis.opendocument.text-master";
5456
public static final String TEXT_WEB_MEDIA_TYPE = "application/vnd.oasis.opendocument.text-web";
57+
public static final String DATABASE_MEDIA_TYPE = "application/vnd.oasis.opendocument.base";
5558
}

validator/src/main/java/org/odftoolkit/odfvalidator/ODFRootPackageValidator.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ private boolean validateMimetype(Logger aLogger, OdfVersion aVersion) {
165165
|| aMimetype.equals(ODFMediaTypes.GRAPHICS_MEDIA_TYPE)
166166
|| aMimetype.equals(ODFMediaTypes.GRAPHICS_TEMPLATE_MEDIA_TYPE)
167167
|| aMimetype.equals(ODFMediaTypes.PRESENTATION_MEDIA_TYPE)
168+
|| aMimetype.equals(ODFMediaTypes.PRESENTATION_TEMPLATE_MEDIA_TYPE)
168169
|| aMimetype.equals(ODFMediaTypes.SPREADSHEET_MEDIA_TYPE)
169170
|| aMimetype.equals(ODFMediaTypes.SPREADSHEET_TEMPLATE_MEDIA_TYPE)
170171
|| aMimetype.equals(ODFMediaTypes.CHART_MEDIA_TYPE)
@@ -173,9 +174,11 @@ private boolean validateMimetype(Logger aLogger, OdfVersion aVersion) {
173174
|| aMimetype.equals(ODFMediaTypes.IMAGE_TEMPLATE_MEDIA_TYPE)
174175
|| aMimetype.equals(ODFMediaTypes.FORMULA_MEDIA_TYPE)
175176
|| aMimetype.equals(ODFMediaTypes.FORMULA_TEMPLATE_MEDIA_TYPE)
177+
|| aMimetype.equals(ODFMediaTypes.DATABASE_MEDIA_TYPE)
176178
|| aMimetype.equals(ODFMediaTypes.TEXT_MASTER_MEDIA_TYPE)
179+
|| aMimetype.equals(ODFMediaTypes.TEXT_MASTER_TEMPLATE_MEDIA_TYPE)
177180
|| aMimetype.equals(ODFMediaTypes.TEXT_WEB_MEDIA_TYPE))) {
178-
aLogger.logInfo("mimetype is not an ODFMediaTypes mimetype.", false);
181+
aLogger.logError("mimetype is not an ODFMediaTypes mimetype.");
179182
bHasErrors = true;
180183
}
181184

validator/src/test/java/org/odftoolkit/odfvalidator/InvalidPackageTest.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ public void validatePackage1() {
4242
t.printStackTrace();
4343
Assert.fail(t.toString());
4444
}
45+
Assert.assertTrue(
46+
output.contains(
47+
"testInvalidPkg1.odt/mimetype: Error: mimetype is not an ODFMediaTypes mimetype"));
4548
Assert.assertTrue(
4649
output.contains(
4750
"testInvalidPkg1.odt/mimetype: Error: The file 'mimetype' is not the first file in the ODF package"));
@@ -54,7 +57,7 @@ public void validatePackage1() {
5457
Assert.assertTrue(
5558
output.contains(
5659
"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"));
57-
Assert.assertTrue(output.contains("testInvalidPkg1.odt: Info: 7 errors, 10 warnings"));
60+
Assert.assertTrue(output.contains("testInvalidPkg1.odt: Info: 8 errors, 10 warnings"));
5861
}
5962

6063
@Test
@@ -67,6 +70,9 @@ public void validatePackage1_V1_1() {
6770
t.printStackTrace();
6871
Assert.fail(t.toString());
6972
}
73+
Assert.assertTrue(
74+
output.contains(
75+
"testInvalidPkg1.odt/mimetype: Error: mimetype is not an ODFMediaTypes mimetype"));
7076
Assert.assertTrue(
7177
output.contains(
7278
"testInvalidPkg1.odt/mimetype: Warning: The file 'mimetype' is not the first file in the ODF package"));
@@ -79,7 +85,7 @@ public void validatePackage1_V1_1() {
7985
Assert.assertTrue(
8086
output.contains(
8187
"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"));
82-
Assert.assertTrue(output.contains("testInvalidPkg1.odt: Info: 10 errors, 11 warnings"));
88+
Assert.assertTrue(output.contains("testInvalidPkg1.odt: Info: 11 errors, 11 warnings"));
8389
}
8490

8591
@Test

0 commit comments

Comments
 (0)