-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add extension schema methods (#1402)
- Loading branch information
1 parent
2bcf60a
commit c2b2b7c
Showing
5 changed files
with
221 additions
and
1 deletion.
There are no files selected for viewing
94 changes: 94 additions & 0 deletions
94
xmp-core/src/main/java/org/verapdf/xmp/impl/VeraPDFExtensionSchemaDefinition.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,94 @@ | ||
package org.verapdf.xmp.impl; | ||
|
||
import org.verapdf.xmp.XMPConst; | ||
import org.verapdf.xmp.XMPException; | ||
import org.verapdf.xmp.options.PropertyOptions; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
public class VeraPDFExtensionSchemaDefinition { | ||
|
||
private static final String PROPERTY = "property"; | ||
public static final String NAMESPACE_URI = "namespaceURI"; | ||
private static final String PREFIX = "prefix"; | ||
private static final String SCHEMA = "schema"; | ||
private static final String PDFA_SCHEMA_PREFIX = "pdfaSchema"; | ||
|
||
private final VeraPDFXMPNode xmpNode; | ||
|
||
public VeraPDFExtensionSchemaDefinition(VeraPDFXMPNode xmpNode) { | ||
this.xmpNode = xmpNode; | ||
} | ||
|
||
public List<VeraPDFExtensionSchemaProperty> getExtensionSchemaProperties() { | ||
if (this.xmpNode != null) { | ||
List<VeraPDFExtensionSchemaProperty> res = new ArrayList<>(); | ||
for (VeraPDFXMPNode child : this.xmpNode.getChildren()) { | ||
if (XMPConst.NS_PDFA_SCHEMA.equals(child.getNamespaceURI()) && PROPERTY.equals(child.getName())) { | ||
if (child.getOptions().isArray()) { | ||
for (VeraPDFXMPNode node : child.getChildren()) { | ||
res.add(new VeraPDFExtensionSchemaProperty(node)); | ||
} | ||
} | ||
break; | ||
} | ||
} | ||
return res; | ||
} | ||
return Collections.emptyList(); | ||
} | ||
|
||
public VeraPDFXMPNode getPropertiesNode() { | ||
if (this.xmpNode != null) { | ||
for (VeraPDFXMPNode child : this.xmpNode.getChildren()) { | ||
if (XMPConst.NS_PDFA_SCHEMA.equals(child.getNamespaceURI()) && PROPERTY.equals(child.getName())) { | ||
return child; | ||
} | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
public void addExtensionSchemaProperty(VeraPDFExtensionSchemaProperty propertyDefinitionXMPNode) throws XMPException { | ||
if (this.xmpNode != null) { | ||
getPropertiesNode().getOriginalNode().addChild(propertyDefinitionXMPNode.getXmpNode()); | ||
} | ||
} | ||
|
||
public String getNamespaceURI() { | ||
for (VeraPDFXMPNode child : this.xmpNode.getChildren()) { | ||
if (XMPConst.NS_PDFA_SCHEMA.equals(child.getNamespaceURI()) && NAMESPACE_URI.equals(child.getName())) { | ||
return child.getValue(); | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
public String getPrefix() { | ||
for (VeraPDFXMPNode child : this.xmpNode.getChildren()) { | ||
if (XMPConst.NS_PDFA_SCHEMA.equals(child.getNamespaceURI()) && PREFIX.equals(child.getName())) { | ||
return child.getValue(); | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
public XMPNode getXmpNode() { | ||
return xmpNode.getOriginalNode(); | ||
} | ||
|
||
public static VeraPDFExtensionSchemaDefinition createExtensionSchemaDefinitionNode(String schema, String namespaceURI, String prefix) throws XMPException { | ||
XMPNode node = new XMPNode(XMPConst.ARRAY_ITEM_NAME,"", new PropertyOptions(PropertyOptions.STRUCT), "rdf"); | ||
node.addChild(new XMPNode(PDFA_SCHEMA_PREFIX + ":" + SCHEMA, schema, | ||
new PropertyOptions(PropertyOptions.NO_OPTIONS), PDFA_SCHEMA_PREFIX)); | ||
node.addChild(new XMPNode(PDFA_SCHEMA_PREFIX + ":" + NAMESPACE_URI, namespaceURI, | ||
new PropertyOptions(PropertyOptions.NO_OPTIONS), PDFA_SCHEMA_PREFIX)); | ||
node.addChild(new XMPNode(PDFA_SCHEMA_PREFIX + ":" + PREFIX, prefix, | ||
new PropertyOptions(PropertyOptions.NO_OPTIONS), PDFA_SCHEMA_PREFIX)); | ||
node.addChild(new XMPNode(PDFA_SCHEMA_PREFIX + ":" + PROPERTY,"", | ||
new PropertyOptions(PropertyOptions.ARRAY + PropertyOptions.ARRAY_ORDERED), PDFA_SCHEMA_PREFIX)); | ||
return new VeraPDFExtensionSchemaDefinition(VeraPDFXMPNode.fromXMPNode(node)); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
xmp-core/src/main/java/org/verapdf/xmp/impl/VeraPDFExtensionSchemaProperty.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,46 @@ | ||
package org.verapdf.xmp.impl; | ||
|
||
import org.verapdf.xmp.XMPConst; | ||
import org.verapdf.xmp.XMPException; | ||
import org.verapdf.xmp.options.PropertyOptions; | ||
|
||
public class VeraPDFExtensionSchemaProperty { | ||
|
||
private static final String NAME = "name"; | ||
private static final String VALUE_TYPE = "valueType"; | ||
private static final String CATEGORY = "category"; | ||
private static final String DESCRIPTION = "description"; | ||
private static final String PDFA_PROPERTY_PREFIX = "pdfaProperty"; | ||
|
||
private final VeraPDFXMPNode xmpNode; | ||
|
||
public VeraPDFExtensionSchemaProperty(VeraPDFXMPNode xmpNode) { | ||
this.xmpNode = xmpNode; | ||
} | ||
|
||
public String getName() { | ||
for (VeraPDFXMPNode child : this.xmpNode.getChildren()) { | ||
if (XMPConst.NS_PDFA_PROPERTY.equals(child.getNamespaceURI()) && NAME.equals(child.getName())) { | ||
return child.getValue(); | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
public XMPNode getXmpNode() { | ||
return xmpNode.getOriginalNode(); | ||
} | ||
|
||
public static VeraPDFExtensionSchemaProperty createPropertyDefinitionNode(String name, String valueType, String category, String description) throws XMPException { | ||
XMPNode node = new XMPNode(XMPConst.ARRAY_ITEM_NAME,"", new PropertyOptions(PropertyOptions.STRUCT), "rdf"); | ||
node.addChild(new XMPNode(PDFA_PROPERTY_PREFIX + ":" + NAME, name, | ||
new PropertyOptions(PropertyOptions.NO_OPTIONS), PDFA_PROPERTY_PREFIX)); | ||
node.addChild(new XMPNode(PDFA_PROPERTY_PREFIX + ":" + VALUE_TYPE, valueType, | ||
new PropertyOptions(PropertyOptions.NO_OPTIONS), PDFA_PROPERTY_PREFIX)); | ||
node.addChild(new XMPNode(PDFA_PROPERTY_PREFIX + ":" + CATEGORY, category, | ||
new PropertyOptions(PropertyOptions.NO_OPTIONS), PDFA_PROPERTY_PREFIX)); | ||
node.addChild(new XMPNode(PDFA_PROPERTY_PREFIX + ":" + DESCRIPTION, description, | ||
new PropertyOptions(PropertyOptions.NO_OPTIONS), PDFA_PROPERTY_PREFIX)); | ||
return new VeraPDFExtensionSchemaProperty(VeraPDFXMPNode.fromXMPNode(node)); | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
xmp-core/src/main/java/org/verapdf/xmp/impl/VeraPDFExtensionSchemasContainer.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,57 @@ | ||
package org.verapdf.xmp.impl; | ||
|
||
import org.verapdf.xmp.XMPException; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
public class VeraPDFExtensionSchemasContainer { | ||
|
||
public static final String PDFA_SCHEMA_PREFIX = "pdfaSchema"; | ||
public static final String PDFA_PROPERTY_PREFIX = "pdfaProperty"; | ||
public static final String NAMESPACE_URI = "namespaceURI"; | ||
|
||
private final VeraPDFXMPNode veraPDFXMPNode; | ||
|
||
public VeraPDFExtensionSchemasContainer(VeraPDFXMPNode veraPDFXMPNode) { | ||
this.veraPDFXMPNode = veraPDFXMPNode; | ||
} | ||
|
||
public void addExtensionSchemaDefinition(VeraPDFExtensionSchemaDefinition veraPDFExtensionSchemaDefinition) throws XMPException { | ||
veraPDFXMPNode.getOriginalNode().addChild(veraPDFExtensionSchemaDefinition.getXmpNode()); | ||
} | ||
|
||
public VeraPDFExtensionSchemaProperty getPropertyDefinition(String namespaceURI, String prefix, String name) { | ||
VeraPDFExtensionSchemaDefinition definition = getExtensionSchemaDefinitionXMPNode(namespaceURI, prefix); | ||
if (definition != null) { | ||
for (VeraPDFExtensionSchemaProperty propertyDefinitionXMPNode : definition.getExtensionSchemaProperties()) { | ||
if (Objects.equals(propertyDefinitionXMPNode.getName(), name)) { | ||
return propertyDefinitionXMPNode; | ||
} | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
public VeraPDFExtensionSchemaDefinition getExtensionSchemaDefinitionXMPNode(String namespaceURI, String prefix) { | ||
for (VeraPDFExtensionSchemaDefinition definition : getExtensionSchemaDefinitions()) { | ||
if (Objects.equals(definition.getNamespaceURI(), namespaceURI) && Objects.equals(definition.getPrefix(), prefix)) { | ||
return definition; | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
private List<VeraPDFExtensionSchemaDefinition> getExtensionSchemaDefinitions() { | ||
if (this.veraPDFXMPNode != null && this.veraPDFXMPNode.getOptions().isArray()) { | ||
List<VeraPDFExtensionSchemaDefinition> res = new ArrayList<>(); | ||
for (VeraPDFXMPNode node : this.veraPDFXMPNode.getChildren()) { | ||
res.add(new VeraPDFExtensionSchemaDefinition(node)); | ||
} | ||
return Collections.unmodifiableList(res); | ||
} | ||
return Collections.emptyList(); | ||
} | ||
} |
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