Top Description Constructors Methods
org.apache.pdfbox.preflight.metadata

public Class SynchronizedMetaDataValidation

extends Object
Class Inheritance
Imports
java.util.ArrayList, .Calendar, .Iterator, .List, java.util.regex.Pattern, org.apache.pdfbox.cos.COSBase, .COSName, .COSString, org.apache.pdfbox.pdmodel.PDDocument, .PDDocumentInformation, org.apache.pdfbox.preflight.PreflightConstants, .ValidationResult.ValidationError, org.apache.pdfbox.preflight.exception.ValidationException, org.apache.xmpbox.XMPMetadata, org.apache.xmpbox.schema.AdobePDFSchema, .DublinCoreSchema, .XMPBasicSchema, org.apache.xmpbox.type.AbstractField, .BadFieldValueException, .TextType

Class which checks if document information available in a document is synchronized with XMP
Author
Germain Costenobel

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected ValidationResult.ValidationError

Returns:

the generated validation error
absentSchemaMetaDataError
(String
the concerned property
target
,
String
the XMP schema which can't be found
schema
)

Return a formatted validation error when a specific metadata schema can't be found

protected ValidationResult.ValidationError

Returns:

the generated validation error
absentXMPPropertyError
(String
the concerned property
target
,
String
comments about the XMP property
details
)

Return a formatted validation error when a specific XMP property can't be found

protected void
analyzeAuthorProperty(PDDocumentInformation
Document Information Dictionary
dico
,
DublinCoreSchema
Dublin Core Schema
dc
,
List<ValidationResult.ValidationError>
The list of validation errors
ve
)

Analyze if Author(s) embedded in Document Information dictionary and in XMP properties are synchronized

protected void
analyzeCreationDateProperty(PDDocumentInformation
Document Information Dictionary
dico
,
XMPBasicSchema
XMP Basic Schema
xmp
,
List<ValidationResult.ValidationError>
The list of validation errors
ve
)

Analyze if the CreationDate embedded in Document Information dictionary and in XMP properties are synchronized

protected void
analyzeCreatorToolProperty(PDDocumentInformation
Document Information Dictionary
dico
,
XMPBasicSchema
XMP Basic Schema
xmp
,
List<ValidationResult.ValidationError>
The list of validation errors
ve
)

Analyze if the creator tool embedded in Document Information dictionary and in XMP properties are synchronized

protected void
analyzeKeywordsProperty(PDDocumentInformation
Document Information Dictionary
dico
,
AdobePDFSchema
PDF Schema
pdf
,
List<ValidationResult.ValidationError>
The list of validation errors
ve
)

Analyze if Keyword(s) embedded in Document Information dictionary and in XMP properties are synchronized

protected void
analyzeModifyDateProperty(PDDocumentInformation
Document Information Dictionary
dico
,
XMPBasicSchema
XMP Basic Schema
xmp
,
List<ValidationResult.ValidationError>
The list of validation errors
ve
)

Analyze if the ModifyDate embedded in Document Information dictionary and in XMP properties are synchronized

protected void
analyzeProducerProperty(PDDocumentInformation
Document Information Dictionary
dico
,
AdobePDFSchema
PDF Schema
pdf
,
List<ValidationResult.ValidationError>
The list of validation errors
ve
)

Analyze if Producer embedded in Document Information dictionary and in XMP properties are synchronized

protected void
analyzeSubjectProperty(PDDocumentInformation
Document Information Dictionary
dico
,
DublinCoreSchema
Dublin Core Schema
dc
,
List<ValidationResult.ValidationError>
The list of validation errors
ve
)

Analyze if Subject(s) embedded in Document Information dictionary and in XMP properties are synchronized

protected void
analyzeTitleProperty(PDDocumentInformation
the Document Information Dictionary.
dico
,
DublinCoreSchema
the Dublin Core Schema.
dc
,
List<ValidationResult.ValidationError>
the list of validation errors.
ve
)

Analyze if Title embedded in Document Information dictionary and in XMP properties are synchronized

protected ValidationResult.ValidationError

Returns:

the generated validation error
badFieldXMPPropertyError
(String
the concerned property
target
,
String
comments about the XMP property
details
)

Return a formatted validation error when a specific XMP property has the wrong type.

private boolean

Returns:

the validation result
hasTimeZone
(Object date)

Verify if the date string has time zone information.

private boolean

Returns:

true if the date format is assumed to be valid, false if not.
isValidPDFDateFormat
(COSBase
the date item that is to be checked.
item
)

Verifies that a date item is a COSString and has the format "D:YYYYMMDDHHmmSSOHH'mm'", where D:YYYY is mandatory and the next fields optional, but only if all of their preceding fields are also present.

private String

Returns:

the stripped string
removeTrailingNul
(String
to be stripped
string
)

A given string from the DocumentInformation dictionary may have some trailing Nul values which have to be stripped.

protected ValidationException

Returns:

the generated exception
schemaAccessException
(String
the name of the schema
target
,
Throwable
the raised IOException
cause
)

Return an exception formatted on IOException when accessing on metadata schema

protected ValidationResult.ValidationError

Returns:

the generated validation error.
unexpectedPrefixFoundError
(String prefFound, String prefExpected, String schema)

Return a validationError formatted when a schema has not the expected prefix

protected ValidationResult.ValidationError

Returns:

the generated validation error
unsynchronizedMetaDataError
(String
the concerned property
target
)

Return a formatted validation error when metadata are not synchronized

public List<ValidationResult.ValidationError>

Returns:

List of validation errors
validateMetadataSynchronization
(PDDocument
the PDF Document
document
,
XMPMetadata
the XMP MetaData
metadata
)

Check if document information entries and XMP information are synchronized

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

SynchronizedMetaDataValidationback to summary
public SynchronizedMetaDataValidation()

Method Detail

absentSchemaMetaDataErrorback to summary
protected ValidationResult.ValidationError absentSchemaMetaDataError(String target, String schema)

Return a formatted validation error when a specific metadata schema can't be found

Parameters
target:String

the concerned property

schema:String

the XMP schema which can't be found

Returns:ValidationResult.ValidationError

the generated validation error

absentXMPPropertyErrorback to summary
protected ValidationResult.ValidationError absentXMPPropertyError(String target, String details)

Return a formatted validation error when a specific XMP property can't be found

Parameters
target:String

the concerned property

details:String

comments about the XMP property

Returns:ValidationResult.ValidationError

the generated validation error

analyzeAuthorPropertyback to summary
protected void analyzeAuthorProperty(PDDocumentInformation dico, DublinCoreSchema dc, List<ValidationResult.ValidationError> ve)

Analyze if Author(s) embedded in Document Information dictionary and in XMP properties are synchronized

Parameters
dico:PDDocumentInformation

Document Information Dictionary

dc:DublinCoreSchema

Dublin Core Schema

ve:List<ValidationResult.ValidationError>

The list of validation errors

analyzeCreationDatePropertyback to summary
protected void analyzeCreationDateProperty(PDDocumentInformation dico, XMPBasicSchema xmp, List<ValidationResult.ValidationError> ve) throws ValidationException

Analyze if the CreationDate embedded in Document Information dictionary and in XMP properties are synchronized

Parameters
dico:PDDocumentInformation

Document Information Dictionary

xmp:XMPBasicSchema

XMP Basic Schema

ve:List<ValidationResult.ValidationError>

The list of validation errors

analyzeCreatorToolPropertyback to summary
protected void analyzeCreatorToolProperty(PDDocumentInformation dico, XMPBasicSchema xmp, List<ValidationResult.ValidationError> ve)

Analyze if the creator tool embedded in Document Information dictionary and in XMP properties are synchronized

Parameters
dico:PDDocumentInformation

Document Information Dictionary

xmp:XMPBasicSchema

XMP Basic Schema

ve:List<ValidationResult.ValidationError>

The list of validation errors

analyzeKeywordsPropertyback to summary
protected void analyzeKeywordsProperty(PDDocumentInformation dico, AdobePDFSchema pdf, List<ValidationResult.ValidationError> ve)

Analyze if Keyword(s) embedded in Document Information dictionary and in XMP properties are synchronized

Parameters
dico:PDDocumentInformation

Document Information Dictionary

pdf:AdobePDFSchema

PDF Schema

ve:List<ValidationResult.ValidationError>

The list of validation errors

analyzeModifyDatePropertyback to summary
protected void analyzeModifyDateProperty(PDDocumentInformation dico, XMPBasicSchema xmp, List<ValidationResult.ValidationError> ve) throws ValidationException

Analyze if the ModifyDate embedded in Document Information dictionary and in XMP properties are synchronized

Parameters
dico:PDDocumentInformation

Document Information Dictionary

xmp:XMPBasicSchema

XMP Basic Schema

ve:List<ValidationResult.ValidationError>

The list of validation errors

analyzeProducerPropertyback to summary
protected void analyzeProducerProperty(PDDocumentInformation dico, AdobePDFSchema pdf, List<ValidationResult.ValidationError> ve)

Analyze if Producer embedded in Document Information dictionary and in XMP properties are synchronized

Parameters
dico:PDDocumentInformation

Document Information Dictionary

pdf:AdobePDFSchema

PDF Schema

ve:List<ValidationResult.ValidationError>

The list of validation errors

analyzeSubjectPropertyback to summary
protected void analyzeSubjectProperty(PDDocumentInformation dico, DublinCoreSchema dc, List<ValidationResult.ValidationError> ve)

Analyze if Subject(s) embedded in Document Information dictionary and in XMP properties are synchronized

Parameters
dico:PDDocumentInformation

Document Information Dictionary

dc:DublinCoreSchema

Dublin Core Schema

ve:List<ValidationResult.ValidationError>

The list of validation errors

analyzeTitlePropertyback to summary
protected void analyzeTitleProperty(PDDocumentInformation dico, DublinCoreSchema dc, List<ValidationResult.ValidationError> ve)

Analyze if Title embedded in Document Information dictionary and in XMP properties are synchronized

Parameters
dico:PDDocumentInformation

the Document Information Dictionary.

dc:DublinCoreSchema

the Dublin Core Schema.

ve:List<ValidationResult.ValidationError>

the list of validation errors.

badFieldXMPPropertyErrorback to summary
protected ValidationResult.ValidationError badFieldXMPPropertyError(String target, String details)

Return a formatted validation error when a specific XMP property has the wrong type.

Parameters
target:String

the concerned property

details:String

comments about the XMP property

Returns:ValidationResult.ValidationError

the generated validation error

hasTimeZoneback to summary
private boolean hasTimeZone(Object date)

Verify if the date string has time zone information.

This method doesn't do a complete parsing as this is a helper AFTER a date has proven to be valid

Returns:boolean

the validation result

isValidPDFDateFormatback to summary
private boolean isValidPDFDateFormat(COSBase item)

Verifies that a date item is a COSString and has the format "D:YYYYMMDDHHmmSSOHH'mm'", where D:YYYY is mandatory and the next fields optional, but only if all of their preceding fields are also present. This needs to be done because the other date utilities are too lenient.

Parameters
item:COSBase

the date item that is to be checked.

Returns:boolean

true if the date format is assumed to be valid, false if not.

removeTrailingNulback to summary
private String removeTrailingNul(String string)

A given string from the DocumentInformation dictionary may have some trailing Nul values which have to be stripped.

Parameters
string:String

to be stripped

Returns:String

the stripped string

schemaAccessExceptionback to summary
protected ValidationException schemaAccessException(String target, Throwable cause)

Return an exception formatted on IOException when accessing on metadata schema

Parameters
target:String

the name of the schema

cause:Throwable

the raised IOException

Returns:ValidationException

the generated exception

unexpectedPrefixFoundErrorback to summary
protected ValidationResult.ValidationError unexpectedPrefixFoundError(String prefFound, String prefExpected, String schema)

Return a validationError formatted when a schema has not the expected prefix

Returns:ValidationResult.ValidationError

the generated validation error.

unsynchronizedMetaDataErrorback to summary
protected ValidationResult.ValidationError unsynchronizedMetaDataError(String target)

Return a formatted validation error when metadata are not synchronized

Parameters
target:String

the concerned property

Returns:ValidationResult.ValidationError

the generated validation error

validateMetadataSynchronizationback to summary
public List<ValidationResult.ValidationError> validateMetadataSynchronization(PDDocument document, XMPMetadata metadata) throws ValidationException

Check if document information entries and XMP information are synchronized

Parameters
document:PDDocument

the PDF Document

metadata:XMPMetadata

the XMP MetaData

Returns:List<ValidationResult.ValidationError>

List of validation errors