Skip to content

Commit

Permalink
Merge pull request #1476 from veraPDF/javadoc_classes
Browse files Browse the repository at this point in the history
Complete javadocs documentation for some classes
  • Loading branch information
nikitakovaliov92 authored Aug 26, 2024
2 parents 9ec5e1b + 66c1e6d commit f5ecc1b
Show file tree
Hide file tree
Showing 5 changed files with 172 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -311,25 +311,20 @@ public static Rule ruleFromValues(final RuleId id, final String object, final St
/**
* Returns a {@link Rule} instance initialised with the passed values.
*
* @param id
* the {@link RuleId} id for the {@link Rule}
* @param object
* a String that identifies the Object that the rule applies to
* @param deferred
* a Boolean that identifies the deferred property of the rule
* @param description
* a textual description of the {@link Rule}.
* @param test
* a JavaScript expression that is the test carried out on a
* model instance
* @param error
* the {@link ErrorDetails} associated with the{@link Rule}.
* @param references
* a list of further {@link Reference}s for this rule
* @param id the {@link RuleId} id for the {@link Rule}
* @param object a String that identifies the Object that the rule applies to
* @param deferred a Boolean that identifies the deferred property of the rule
* @param tags a String that contains comma-separated list of tags associated with this rule
* @param description a textual description of the {@link Rule}.
* @param test a JavaScript expression that is the test carried out on a
* model instance
* @param error the {@link ErrorDetails} associated with the{@link Rule}.
* @param references a list of further {@link Reference}s for this rule
*
* @return a {@link Rule} instance.
* @throws IllegalArgumentException
* if any of the parameters are null or the test, object, or
* description is empty
*
* @throws IllegalArgumentException if any of the parameters are null or the test, object, or
* description is empty
*/
public static Rule ruleFromValues(final RuleId id, final String object, final Boolean deferred, String tags,
final String description, final String test,
Expand Down Expand Up @@ -409,6 +404,7 @@ public static Variable variableFromValues(final String name, final String object
* @param toConvert a {@link ValidationProfile} to convert to an XML String
* @param format set to Boolean.TRUE for pretty formatted XML, Boolean.FALSE
* for no space formatting
* @param fragment a flag to generate document level events
*
* @return a String xml representation of toConvert
*
Expand All @@ -427,18 +423,15 @@ public static String profileToXml(final ValidationProfile toConvert, boolean for
* Convert a {@link ValidationProfile} instance to XML and serialise to the
* {@link OutputStream} <code>forXMLOutput</code>.
*
* @param toConvert
* a {@link ValidationProfile} to convert to an XML String
* @param dest
* an OutputStream used to write the generated XML to
* @param format
* set to Boolean.TRUE for pretty formatted XML, Boolean.FALSE
* for no space formatting
* @throws JAXBException
* thrown by JAXB marshaller if there's an error converting the
* object
* @throws IllegalArgumentException
* if toConvert is null
* @param toConvert a {@link ValidationProfile} to convert to an XML String
* @param dest an OutputStream used to write the generated XML to
* @param format set to Boolean.TRUE for pretty formatted XML, Boolean.FALSE
* for no space formatting
* @param fragment a flag to generate document level events
*
* @throws JAXBException thrown by JAXB marshaller if there's an error converting the
* object
* @throws IllegalArgumentException if toConvert is null
*/
public static void profileToXml(final ValidationProfile toConvert, final OutputStream dest, boolean format,
boolean fragment) throws JAXBException {
Expand Down Expand Up @@ -470,18 +463,15 @@ public static ValidationProfile profileFromXml(final InputStream source) throws
* Convert a {@link ValidationProfile} instance to XML and serialise to the
* {@link Writer} <code>forXMLOutput</code>.
*
* @param toConvert
* a {@link ValidationProfile} to convert to an XML String
* @param dest
* a Writer used to write the generated XML to
* @param format
* set to Boolean.TRUE for pretty formatted XML, Boolean.FALSE
* for no space formatting
* @throws JAXBException
* thrown by JAXB marshaller if there's an error converting the
* object
* @throws IllegalArgumentException
* if toConvert is null
* @param toConvert a {@link ValidationProfile} to convert to an XML String
* @param dest a Writer used to write the generated XML to
* @param format set to Boolean.TRUE for pretty formatted XML, Boolean.FALSE
* for no space formatting
* @param fragment a flag to generate document level events
*
* @throws JAXBException thrown by JAXB marshaller if there's an error converting the
* object
* @throws IllegalArgumentException if toConvert is null
*/
public static void profileToXml(final ValidationProfile toConvert, Writer dest, boolean format, boolean fragment)
throws JAXBException {
Expand Down
68 changes: 43 additions & 25 deletions core/src/main/java/org/verapdf/processor/plugins/Attribute.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,29 +29,47 @@
@XmlRootElement(name = "attribute")
public class Attribute {

@XmlAttribute
private final String key;
@XmlAttribute
private final String value;

private Attribute(String key, String value) {
this.key = key;
this.value = value;
}

private Attribute() {
this("", "");
}

public static Attribute fromValues(String key, String value) {
return new Attribute(key, value);
}

public String getKey() {
return key;
}

public String getValue() {
return value;
}
@XmlAttribute
private final String key;
@XmlAttribute
private final String value;

private Attribute(String key, String value) {
this.key = key;
this.value = value;
}

private Attribute() {
this("", "");
}

/**
* Creates attribute key and value.
*
* @param key an attribute key
* @param value an attribute value
*
* @return an attribute a pair of key and value
*/
public static Attribute fromValues(String key, String value) {
return new Attribute(key, value);
}

/**
* Gets attribute key.
*
* @return an attribute key
*/
public String getKey() {
return key;
}

/**
* Gets attribute value.
*
* @return an attribute value
*/
public String getValue() {
return value;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.verapdf.xmp.containers;

import java.util.*;
import java.util.HashMap;
import java.util.Map;

public class StaticXmpCoreContainers {

Expand All @@ -14,23 +15,46 @@ public class StaticXmpCoreContainers {
*/
private static final ThreadLocal<Map<String, String>> prefixToNamespaceMap = new ThreadLocal<>();

/**
* Clears all namespaces and prefixes.
*/
public static void clearAllContainers() {
namespaceToPrefixMap.set(new HashMap<>());
prefixToNamespaceMap.set(new HashMap<>());
}

/**
* Gets namespaces map.
*
* @return a map of namespaces
*/
public static Map<String, String> getNamespaceToPrefixMap() {
return namespaceToPrefixMap.get();
}

/**
* Gets prefixes map.
*
* @return a map of prefixes
*/
public static Map<String, String> getPrefixToNamespaceMap() {
return prefixToNamespaceMap.get();
}

/**
* Sets namespaces.
*
* @param namespaceToPrefixMap a map of namespaces
*/
public static void setNamespaceToPrefixMap(Map<String, String> namespaceToPrefixMap) {
StaticXmpCoreContainers.namespaceToPrefixMap.set(namespaceToPrefixMap);
}

/**
* Sets prefixes.
*
* @param prefixToNamespaceMap a map of prefixes
*/
public static void setPrefixToNamespaceMap(Map<String, String> prefixToNamespaceMap) {
StaticXmpCoreContainers.prefixToNamespaceMap.set(prefixToNamespaceMap);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,36 @@
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;
import org.verapdf.xmp.XMPConst;
import org.verapdf.xmp.XMPException;
import org.verapdf.xmp.options.PropertyOptions;

public class VeraPDFExtensionSchemaDefinition {

private static final String PROPERTY = "property";
public static final String NAMESPACE_URI = "namespaceURI";
private 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;

/**
* VeraPDF extension schema.
*
* @param xmpNode a metadata node
*/
public VeraPDFExtensionSchemaDefinition(VeraPDFXMPNode xmpNode) {
this.xmpNode = xmpNode;
}

/**
* Gets schema properties.
*
* @return schema properties
*/
public List<VeraPDFExtensionSchemaProperty> getExtensionSchemaProperties() {
if (this.xmpNode != null) {
List<VeraPDFExtensionSchemaProperty> res = new ArrayList<>();
Expand All @@ -39,7 +48,12 @@ public List<VeraPDFExtensionSchemaProperty> getExtensionSchemaProperties() {
}
return Collections.emptyList();
}


/**
* Gets property of xmp node.
*
* @return xmp node property value
*/
public VeraPDFXMPNode getPropertiesNode() {
if (this.xmpNode != null) {
for (VeraPDFXMPNode child : this.xmpNode.getChildren()) {
Expand All @@ -51,12 +65,25 @@ public VeraPDFXMPNode getPropertiesNode() {
return null;
}

public void addExtensionSchemaProperty(VeraPDFExtensionSchemaProperty propertyDefinitionXMPNode) throws XMPException {
/**
* Adds extension schema property.
*
* @param propertyDefinitionXMPNode a property of xmp node
*
* @throws XMPException exceptions from the metadata processing
*/
public void addExtensionSchemaProperty(VeraPDFExtensionSchemaProperty propertyDefinitionXMPNode)
throws XMPException {
if (this.xmpNode != null) {
getPropertiesNode().getOriginalNode().addChild(propertyDefinitionXMPNode.getXmpNode());
}
}

/**
* Gets namespaces URI of xmp node.
*
* @return xmp node namespace value
*/
public String getNamespaceURI() {
for (VeraPDFXMPNode child : this.xmpNode.getChildren()) {
if (XMPConst.NS_PDFA_SCHEMA.equals(child.getNamespaceURI()) && NAMESPACE_URI.equals(child.getName())) {
Expand All @@ -66,6 +93,11 @@ public String getNamespaceURI() {
return null;
}

/**
* Gets prefix of xmp node.
*
* @return xmp node prefix value
*/
public String getPrefix() {
for (VeraPDFXMPNode child : this.xmpNode.getChildren()) {
if (XMPConst.NS_PDFA_SCHEMA.equals(child.getNamespaceURI()) && PREFIX.equals(child.getName())) {
Expand All @@ -75,19 +107,36 @@ public String getPrefix() {
return null;
}

/**
* Gets xmp node.
*
* @return original xmp node from metadata
*/
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");
/**
* Creates schema definition node.
*
* @param schema a xmp schema definition
* @param namespaceURI a namespace URI of the node
* @param prefix a prefix of the node
*
* @return xmp extension schema
*
* @throws XMPException exceptions from the metadata processing
*/
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,"",
node.addChild(new XMPNode(PDFA_SCHEMA_PREFIX + ":" + PROPERTY, "",
new PropertyOptions(PropertyOptions.ARRAY + PropertyOptions.ARRAY_ORDERED), PDFA_SCHEMA_PREFIX));
return new VeraPDFExtensionSchemaDefinition(VeraPDFXMPNode.fromXMPNode(node));
}
Expand Down
Loading

0 comments on commit f5ecc1b

Please sign in to comment.