Skip to content

Commit

Permalink
Merge pull request #180 from openpreserve/integration
Browse files Browse the repository at this point in the history
REL: Update main to v0.13.1
  • Loading branch information
carlwilson authored Aug 30, 2024
2 parents 4f40d4b + 8c3b574 commit 3b9836b
Show file tree
Hide file tree
Showing 54 changed files with 727 additions and 235 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ pom.xml.next
release.properties
**/pom.xml.versionsBackup

# Ignore generated project documentation folders
odf-*/docs

# Ignore Eclipse artefacts
**/.settings
**/.project
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# ODF Validator

Latest version is 0.12.0.
Latest version is 0.13.0.

## About

Expand Down
2 changes: 1 addition & 1 deletion docs/developer/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ To include the core validation library in your project, add the following depend
<dependency>
<groupId>org.openpreservation.odf</groupId>
<artifactId>odf-core</artifactId>
<version>0.12.0</version>
<version>0.13.0</version>
</dependency>
```

Expand Down
2 changes: 1 addition & 1 deletion odf-apps/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.openpreservation.odf</groupId>
<artifactId>odf-validator</artifactId>
<version>0.12.0</version>
<version>0.13.1</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Collection;
Expand Down
2 changes: 1 addition & 1 deletion odf-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.openpreservation.odf</groupId>
<artifactId>odf-validator</artifactId>
<version>0.12.0</version>
<version>0.13.1</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

final class NamespaceImpl implements Namespace {
private static final String STRING = "String";

static NamespaceImpl of(final URI id, final String prefix, final URL schemalocation) {
Objects.requireNonNull(id, String.format(Checks.NOT_NULL, "id", "URI"));
Objects.requireNonNull(prefix, String.format(Checks.NOT_NULL, "prefix", STRING));
Expand All @@ -19,11 +20,13 @@ static NamespaceImpl of(final URI id, final String prefix, final URL schemalocat
throw new IllegalArgumentException("Parameter id MUST be a legal URI.", e);
}
}

static NamespaceImpl of(final String id, final String prefix) {
Objects.requireNonNull(id, String.format(Checks.NOT_NULL, "id", STRING));
Objects.requireNonNull(prefix, String.format(Checks.NOT_NULL, "prefix", STRING));
return NamespaceImpl.of(URI.create(id), prefix, null);
}

private final URI id;

private final String prefix;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.openpreservation.format.xml;

import java.util.List;
import java.util.Set;

import org.openpreservation.messages.Message;

Expand Down Expand Up @@ -29,9 +30,16 @@ public interface ParseResult {
/**
* Get all of the declared <code>Namespace</code>s in the document
*
* @return the <code>List<Namespace></code> of the document's namespaces
* @return the <code>Set<Namespace></code> of the document's namespaces
*/
public List<Namespace> getNamespaces();
public Set<Namespace> getDeclaredNamespaces();

/**
* Get all of the declared <code>Namespace</code>s in the document
*
* @return the <code>Set<Namespace></code> of the document's namespaces
*/
public Set<Namespace> getUsedNamespaces();

/**
* Get the root element namespace prefix
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package org.openpreservation.format.xml;

import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;

import org.openpreservation.messages.Message;
import org.openpreservation.messages.Message.Severity;
Expand All @@ -11,28 +14,36 @@
final class ParseResultImpl implements ParseResult {
private static final String MESSAGES_NAME = "messages";
private static final String MESSAGES_TYPE = "List<Message>";
static ParseResult of(final boolean isWellFormed, final Namespace rootNamespace, final List<Namespace> namespaces,

static ParseResult of(final boolean isWellFormed, final Namespace rootNamespace,
final Collection<Namespace> declaredNamespaces, final Collection<Namespace> usedNamespaces,
final String rootPrefix, final String rootName,
final List<Attribute> rootAttributes, final List<Message> messages) {
Objects.requireNonNull(namespaces, String.format(Checks.NOT_NULL, "namespaces", "List<Namespace>"));
Objects.requireNonNull(declaredNamespaces,
String.format(Checks.NOT_NULL, "declaredNamespaces", "List<Namespace>"));
Objects.requireNonNull(usedNamespaces, String.format(Checks.NOT_NULL, "usedNamespaces", "List<Namespace>"));
Objects.requireNonNull(messages, String.format(Checks.NOT_NULL, MESSAGES_NAME, MESSAGES_TYPE));
return new ParseResultImpl(isWellFormed, rootNamespace, namespaces, rootPrefix, rootName, rootAttributes,
return new ParseResultImpl(isWellFormed, rootNamespace, declaredNamespaces, usedNamespaces, rootPrefix,
rootName, rootAttributes,
messages);
}

static ParseResult of(final Namespace rootNamespace, final List<Namespace> namespaces,
static ParseResult of(final Namespace rootNamespace, final Collection<Namespace> declaredNamespaces,
final Collection<Namespace> usedNamespaces,
final String rootPrefix, final String rootName,
final List<Attribute> rootAttributes, final List<Message> messages) {
Objects.requireNonNull(messages, String.format(Checks.NOT_NULL, MESSAGES_NAME, MESSAGES_TYPE));
return ParseResultImpl.of(isWellFormed(messages), rootNamespace, namespaces, rootPrefix, rootName,
return ParseResultImpl.of(isWellFormed(messages), rootNamespace, declaredNamespaces, usedNamespaces, rootPrefix,
rootName,
rootAttributes,
messages);
}

static ParseResult invertWellFormed(final ParseResult parseResult) {
Objects.requireNonNull(parseResult, String.format(Checks.NOT_NULL, "parseResult", "ParseResult"));
return new ParseResultImpl(!parseResult.isWellFormed(), parseResult.getRootNamespace(),
parseResult.getNamespaces(), parseResult.getRootPrefix(), parseResult.getRootName(),
parseResult.getDeclaredNamespaces(), parseResult.getUsedNamespaces(), parseResult.getRootPrefix(),
parseResult.getRootName(),
parseResult.getRootAttributes(),
parseResult.getMessages());
}
Expand All @@ -48,19 +59,22 @@ private static final boolean isWellFormed(final List<Message> messages) {

private final boolean isWF;
private final Namespace rootNamespace;
private final List<Namespace> namespaces;
private final Set<Namespace> usedNamespaces;
private final Set<Namespace> declaredNamespaces;
private final String rootPrefix;
private final String rootName;
private final List<Attribute> rootAttributes;

private final List<Message> messages;

private ParseResultImpl(final boolean isWellFormed, final Namespace rootNamespace, final List<Namespace> namespaces,
private ParseResultImpl(final boolean isWellFormed, final Namespace rootNamespace,
final Collection<Namespace> declaredNamespaces, final Collection<Namespace> usedNamespaces,
final String rootPrefix, final String rootName, final List<Attribute> rootAttributes,
final List<Message> messages) {
this.isWF = isWellFormed;
this.rootNamespace = rootNamespace;
this.namespaces = Collections.unmodifiableList(namespaces);
this.declaredNamespaces = Collections.unmodifiableSet(new HashSet<>(declaredNamespaces));
this.usedNamespaces = Collections.unmodifiableSet(new HashSet<>(usedNamespaces));
this.rootPrefix = rootPrefix;
this.rootName = rootName;
this.rootAttributes = Collections.unmodifiableList(rootAttributes);
Expand All @@ -78,8 +92,13 @@ public Namespace getRootNamespace() {
}

@Override
public List<Namespace> getNamespaces() {
return this.namespaces;
public Set<Namespace> getDeclaredNamespaces() {
return this.declaredNamespaces;
}

@Override
public Set<Namespace> getUsedNamespaces() {
return this.usedNamespaces;
}

@Override
Expand All @@ -93,7 +112,8 @@ public boolean isRootName(final String name) {
if (this.rootName == null || (name.contains(":") && this.rootPrefix == null)) {
return false;
}
final String match = (name.contains(":")) ? String.format("%s:%s", this.rootPrefix, this.rootName) : this.rootName;
final String match = (name.contains(":")) ? String.format("%s:%s", this.rootPrefix, this.rootName)
: this.rootName;
return match.equals(name);
}

Expand All @@ -118,7 +138,8 @@ public int hashCode() {
int result = 1;
result = prime * result + (isWF ? 1231 : 1237);
result = prime * result + ((rootNamespace == null) ? 0 : rootNamespace.hashCode());
result = prime * result + ((namespaces == null) ? 0 : namespaces.hashCode());
result = prime * result + ((declaredNamespaces == null) ? 0 : declaredNamespaces.hashCode());
result = prime * result + ((usedNamespaces == null) ? 0 : usedNamespaces.hashCode());
result = prime * result + ((rootPrefix == null) ? 0 : rootPrefix.hashCode());
result = prime * result + ((rootName == null) ? 0 : rootName.hashCode());
result = prime * result + ((rootAttributes == null) ? 0 : rootAttributes.hashCode());
Expand All @@ -142,10 +163,15 @@ public boolean equals(final Object obj) {
return false;
} else if (!rootNamespace.equals(other.rootNamespace))
return false;
if (namespaces == null) {
if (other.namespaces != null)
if (declaredNamespaces == null) {
if (other.declaredNamespaces != null)
return false;
} else if (!declaredNamespaces.equals(other.declaredNamespaces))
return false;
if (usedNamespaces == null) {
if (other.usedNamespaces != null)
return false;
} else if (!namespaces.equals(other.namespaces))
} else if (!usedNamespaces.equals(other.usedNamespaces))
return false;
if (rootPrefix == null) {
if (other.rootPrefix != null)
Expand All @@ -172,7 +198,8 @@ public boolean equals(final Object obj) {

@Override
public String toString() {
return "ParseResultImpl [isWF=" + isWF + ", rootNamespace=" + rootNamespace + ", namespaces=" + namespaces
return "ParseResultImpl [isWF=" + isWF + ", rootNamespace=" + rootNamespace + ", namespaces="
+ declaredNamespaces
+ ", rootPrefix=" + rootPrefix + ", rootName=" + rootName + ", rootAttributes=" + rootAttributes
+ ", messages=" + messages + "]";
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
package org.openpreservation.format.xml;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.openpreservation.messages.Message;
import org.xml.sax.Attributes;
import org.xml.sax.helpers.DefaultHandler;

public class ParsingHandler extends DefaultHandler {
private Namespace rootNamespace = null;
private List<Namespace> namespaces = new ArrayList<>();
private Set<Namespace> declaredNamespaces = new HashSet<>();
private Set<Namespace> usedNamespaces = new HashSet<>();
private String rootPrefix = "";
private String rootLocalName = "";
private List<Attribute> attributes = new ArrayList<>();
Expand All @@ -19,22 +22,34 @@ public ParsingHandler() {
}

public ParseResult getResult(final boolean isWellFormed, final List<Message> messages) {
return ParseResultImpl.of(isWellFormed, this.rootNamespace, this.namespaces, this.rootPrefix,
return ParseResultImpl.of(isWellFormed, this.rootNamespace, this.declaredNamespaces, this.usedNamespaces,
this.rootPrefix,
this.rootLocalName, this.attributes, messages);
}

@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) {
if (this.rootLocalName.isEmpty()) {
this.rootLocalName = localName;
this.rootPrefix = qName.contains(":") ? qName.split(":")[0] : "";
this.rootPrefix = splitNamespace(qName);
this.attributes = AttributeImpl.of(attributes);
this.rootNamespace = NamespaceImpl.of(uri, this.rootPrefix);
this.usedNamespaces.add(NamespaceImpl.of(uri, this.rootPrefix));
} else {
this.usedNamespaces.add(NamespaceImpl.of(uri, splitNamespace(qName)));
}
for (int index = 0; index < attributes.getLength(); index++) {
this.usedNamespaces
.add(NamespaceImpl.of(attributes.getURI(index), splitNamespace(attributes.getQName(index))));
}
}

private static final String splitNamespace(final String qName) {
return qName.contains(":") ? qName.split(":")[0] : "";
}

@Override
public void startPrefixMapping(String prefix, String uri) {
this.namespaces.add(NamespaceImpl.of(uri, prefix));
this.declaredNamespaces.add(NamespaceImpl.of(uri, prefix));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Set;

import org.openpreservation.messages.Message;
import org.openpreservation.utils.Checks;
Expand All @@ -13,16 +14,19 @@ final class ValidationResultImpl implements ValidationResult {
private static final String PARSE_RESULT_TYPE = "ParseResult";
private static final String MESSAGES_NAME = "messages";
private static final String MESSAGES_TYPE = "List<Message>";

static final ValidationResult of(final ParseResult parseResult, final boolean valid, final List<Message> messages) {
Objects.requireNonNull(parseResult, String.format(Checks.NOT_NULL, PARSE_RESULT_NAME, PARSE_RESULT_TYPE));
Objects.requireNonNull(messages, String.format(Checks.NOT_NULL, MESSAGES_NAME, MESSAGES_TYPE));
return new ValidationResultImpl(parseResult, valid, messages);
}

static final ValidationResult valid(final ParseResult parseResult, final List<Message> messages) {
Objects.requireNonNull(parseResult, String.format(Checks.NOT_NULL, PARSE_RESULT_NAME, PARSE_RESULT_TYPE));
Objects.requireNonNull(messages, String.format(Checks.NOT_NULL, MESSAGES_NAME, MESSAGES_TYPE));
return of(parseResult, true, messages);
}

static final ValidationResult notValid(final ParseResult parseResult, final List<Message> messages) {
Objects.requireNonNull(parseResult, String.format(Checks.NOT_NULL, PARSE_RESULT_NAME, PARSE_RESULT_TYPE));
Objects.requireNonNull(messages, String.format(Checks.NOT_NULL, MESSAGES_NAME, MESSAGES_TYPE));
Expand Down Expand Up @@ -58,8 +62,13 @@ public Namespace getRootNamespace() {
}

@Override
public List<Namespace> getNamespaces() {
return this.parseResult.getNamespaces();
public Set<Namespace> getDeclaredNamespaces() {
return this.parseResult.getDeclaredNamespaces();
}

@Override
public Set<Namespace> getUsedNamespaces() {
return this.parseResult.getUsedNamespaces();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ public final class ValidationResults {
* values
*/
public static final ParseResult parseResultOf(final boolean valid, final Namespace namespace,
final List<Namespace> namespaces,
final List<Namespace> declareNamespaces, final List<Namespace> usedNamespaces,
final String prefix, final String name, final List<Attribute> attributes, final List<Message> messages) {
return ParseResultImpl.of(valid, namespace, namespaces, prefix, name, attributes, messages);
return ParseResultImpl.of(valid, namespace, declareNamespaces, usedNamespaces, prefix, name, attributes,
messages);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import java.util.function.Function;
import java.util.stream.Collectors;

import org.apache.commons.compress.archivers.zip.UnsupportedZipFeatureException;
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
import org.apache.commons.compress.archivers.zip.ZipFile;
import org.openpreservation.utils.Checks;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import java.util.Date;

import org.openpreservation.messages.Message.Severity;

/**
* Defines behaviour of validation messages.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,4 +223,11 @@ public interface OdfPackage {
* otherwise <code>false</code>.
*/
public boolean hasDsigEntries();

/**
* Discover if the file uses any namespaces outside of the ODF specification.
*
* @return true if the file uses any namespaces outside of the ODF
*/
public boolean isExtended();
}
Loading

0 comments on commit 3b9836b

Please sign in to comment.