-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #102 from openpreserve/feat/odf-2/compiance
FEAT: ODF_2 Compliance testing
- Loading branch information
Showing
7 changed files
with
112 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
odf-core/src/main/java/org/openpreservation/odf/validation/Rule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package org.openpreservation.odf.validation; | ||
|
||
import java.io.IOException; | ||
|
||
import org.openpreservation.messages.MessageLog; | ||
import org.openpreservation.odf.pkg.OdfPackage; | ||
import org.openpreservation.odf.xml.OdfXmlDocument; | ||
|
||
public interface Rule { | ||
public String getId(); | ||
public String getName(); | ||
public String getDescription(); | ||
public MessageLog check(final OdfXmlDocument document) throws IOException; | ||
public MessageLog check(final OdfPackage odfPackage) throws IOException; | ||
} |
31 changes: 31 additions & 0 deletions
31
odf-core/src/main/java/org/openpreservation/odf/validation/rules/AbstractRule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package org.openpreservation.odf.validation.rules; | ||
|
||
import org.openpreservation.odf.validation.Rule; | ||
|
||
abstract class AbstractRule implements Rule { | ||
final String id; | ||
final String name; | ||
final String description; | ||
|
||
AbstractRule(final String id, final String name, final String description) { | ||
super(); | ||
this.id = id; | ||
this.name = name; | ||
this.description = description; | ||
} | ||
|
||
@Override | ||
public String getId() { | ||
return this.id; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return this.name; | ||
} | ||
|
||
@Override | ||
public String getDescription() { | ||
return this.description; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
odf-core/src/main/java/org/openpreservation/odf/validation/rules/Rules.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package org.openpreservation.odf.validation.rules; | ||
|
||
import javax.xml.parsers.ParserConfigurationException; | ||
|
||
import org.xml.sax.SAXException; | ||
|
||
public class Rules { | ||
private Rules() { | ||
throw new AssertionError("Utility class must not be instantiated"); | ||
} | ||
|
||
public static final ValidPackageRule odf2() throws ParserConfigurationException, SAXException { | ||
return ValidPackageRule.getInstance(); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
odf-core/src/main/java/org/openpreservation/odf/validation/rules/ValidPackageRule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package org.openpreservation.odf.validation.rules; | ||
|
||
import java.io.IOException; | ||
import java.util.Objects; | ||
|
||
import javax.xml.parsers.ParserConfigurationException; | ||
|
||
import org.openpreservation.messages.Message; | ||
import org.openpreservation.messages.MessageLog; | ||
import org.openpreservation.messages.Messages; | ||
import org.openpreservation.odf.pkg.OdfPackage; | ||
import org.openpreservation.odf.validation.ValidatingParser; | ||
import org.openpreservation.odf.validation.ValidationReport; | ||
import org.openpreservation.odf.validation.Validators; | ||
import org.openpreservation.odf.xml.OdfXmlDocument; | ||
import org.xml.sax.SAXException; | ||
|
||
class ValidPackageRule extends AbstractRule { | ||
private final ValidatingParser validatingParser = Validators.getValidatingParser(); | ||
|
||
private ValidPackageRule(String id, String name, String description) throws ParserConfigurationException, SAXException { | ||
super(id, name, description); | ||
} | ||
|
||
@Override | ||
public MessageLog check(OdfXmlDocument document) { | ||
throw new UnsupportedOperationException("Unimplemented method 'check'"); | ||
} | ||
|
||
@Override | ||
public MessageLog check(OdfPackage odfPackage) throws IOException { | ||
Objects.requireNonNull(odfPackage, "odfPackage must not be null"); | ||
MessageLog messageLog = Messages.messageLogInstance(); | ||
ValidationReport validationReport = validatingParser.validatePackage(odfPackage); | ||
if (!validationReport.isValid()) { | ||
messageLog.add(validationReport.getMessages()); | ||
messageLog.add(Messages.getMessageInstance(this.id, Message.Severity.ERROR, this.getName(), this.getDescription())); | ||
} | ||
return messageLog; | ||
} | ||
|
||
static final ValidPackageRule getInstance() throws ParserConfigurationException, SAXException { | ||
return new ValidPackageRule("ODF_2", "Standard Compliance", "The file MUST comply with the standard \"OASIS Open Document Format for Office Applications (OpenDocument) v1.3\"."); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters