You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by gb...@apache.org on 2012/08/07 18:40:49 UTC
svn commit: r1370356 [1/2] - in /pdfbox/branches/xmpbox-refactoring:
preflight/src/main/java/org/apache/padaf/preflight/helpers/
preflight/src/main/java/org/apache/pdfbox/preflight/process/
preflight/src/test/resources/ xmpbox/src/main/java/org/apache/...
Author: gbailleul
Date: Tue Aug 7 16:40:47 2012
New Revision: 1370356
URL: http://svn.apache.org/viewvc?rev=1370356&view=rev
Log:
PDFBOX-1388: replace previous specific PDF/A xmp parser by usage of structured type parser
Added:
pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/DefinedStructuredType.java
pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/PDFAFieldType.java
pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/PDFAPropertyType.java
pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/PDFASchemaType.java
pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/PDFATypeType.java
Removed:
pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/parser/PDFAExtentionSchemaPreprocessor.java
pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/parser/XMLValueTypeDescriptionManager.java
pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/parser/XMPDocumentPreprocessor.java
pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/schema/FieldDescription.java
pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/schema/PDFAFieldDescription.java
pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/schema/PDFAPropertyDescription.java
pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/schema/PDFAValueTypeDescription.java
pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/schema/SchemaDescription.java
pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/schema/ValueTypeDescription.java
pdfbox/branches/xmpbox-refactoring/xmpbox/src/test/java/org/apache/padaf/xmpbox/BuildPDFAExtensionSchemaDescriptionTest.java
pdfbox/branches/xmpbox-refactoring/xmpbox/src/test/java/org/apache/padaf/xmpbox/parser/XMLValueTypeDescriptionManagerTest.java
pdfbox/branches/xmpbox-refactoring/xmpbox/src/test/java/org/apache/padaf/xmpbox/schema/PDFAExtensionTest.java
pdfbox/branches/xmpbox-refactoring/xmpbox/src/test/java/org/apache/padaf/xmpbox/schema/PDFAPropertyDescriptionTest.java
pdfbox/branches/xmpbox-refactoring/xmpbox/src/test/java/org/apache/padaf/xmpbox/schema/PDFAValueTypeDescriptionTest.java
Modified:
pdfbox/branches/xmpbox-refactoring/preflight/src/main/java/org/apache/padaf/preflight/helpers/MetadataValidationHelper.java
pdfbox/branches/xmpbox-refactoring/preflight/src/main/java/org/apache/pdfbox/preflight/process/MetadataValidationProcess.java
pdfbox/branches/xmpbox-refactoring/preflight/src/test/resources/ (props changed)
pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/BuildPDFExtensionSchemaHelper.java
pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/XMPMetadata.java
pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/XmpConstants.java
pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/parser/StructuredPropertyParser.java
pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/parser/XMPDocumentBuilder.java
pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/parser/XMPSchemaFactory.java
pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/schema/NSMapping.java
pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/schema/PDFAExtensionSchema.java
pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/schema/SchemaMapping.java
pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/AbstractField.java
pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/AbstractStructuredType.java
pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/ArrayProperty.java
pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/ComplexPropertyContainer.java
pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/JobType.java
pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/TypeDescription.java
pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/TypeMapping.java
pdfbox/branches/xmpbox-refactoring/xmpbox/src/test/java/org/apache/padaf/xmpbox/BirthCertificateSchemaWithXMLDescriptions.java
pdfbox/branches/xmpbox-refactoring/xmpbox/src/test/java/org/apache/padaf/xmpbox/parser/DeserializationTest.java
pdfbox/branches/xmpbox-refactoring/xmpbox/src/test/java/org/apache/padaf/xmpbox/schema/BasicJobTicketSchemaTest.java
pdfbox/branches/xmpbox-refactoring/xmpbox/src/test/java/org/apache/padaf/xmpbox/type/TestJobType.java
Modified: pdfbox/branches/xmpbox-refactoring/preflight/src/main/java/org/apache/padaf/preflight/helpers/MetadataValidationHelper.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/xmpbox-refactoring/preflight/src/main/java/org/apache/padaf/preflight/helpers/MetadataValidationHelper.java?rev=1370356&r1=1370355&r2=1370356&view=diff
==============================================================================
--- pdfbox/branches/xmpbox-refactoring/preflight/src/main/java/org/apache/padaf/preflight/helpers/MetadataValidationHelper.java (original)
+++ pdfbox/branches/xmpbox-refactoring/preflight/src/main/java/org/apache/padaf/preflight/helpers/MetadataValidationHelper.java Tue Aug 7 16:40:47 2012
@@ -42,7 +42,6 @@ import org.apache.padaf.preflight.xmp.Sy
import org.apache.padaf.preflight.xmp.XpacketParsingException;
import org.apache.padaf.preflight.xmp.RDFAboutAttributeConcordanceValidation.DifferentRDFAboutException;
import org.apache.padaf.xmpbox.XMPMetadata;
-import org.apache.padaf.xmpbox.parser.PDFAExtentionSchemaPreprocessor;
import org.apache.padaf.xmpbox.parser.XMPDocumentBuilder;
import org.apache.padaf.xmpbox.parser.XmpExpectedRdfAboutAttribute;
import org.apache.padaf.xmpbox.parser.XmpParsingException;
@@ -115,7 +114,6 @@ public class MetadataValidationHelper ex
XMPDocumentBuilder builder;
try {
builder = new XMPDocumentBuilder();
- builder.addPreprocessor(new PDFAExtentionSchemaPreprocessor());
} catch (XmpSchemaException e1) {
throw new ValidationException(e1.getMessage(), e1);
}
Modified: pdfbox/branches/xmpbox-refactoring/preflight/src/main/java/org/apache/pdfbox/preflight/process/MetadataValidationProcess.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/xmpbox-refactoring/preflight/src/main/java/org/apache/pdfbox/preflight/process/MetadataValidationProcess.java?rev=1370356&r1=1370355&r2=1370356&view=diff
==============================================================================
--- pdfbox/branches/xmpbox-refactoring/preflight/src/main/java/org/apache/pdfbox/preflight/process/MetadataValidationProcess.java (original)
+++ pdfbox/branches/xmpbox-refactoring/preflight/src/main/java/org/apache/pdfbox/preflight/process/MetadataValidationProcess.java Tue Aug 7 16:40:47 2012
@@ -28,7 +28,6 @@ import java.util.ArrayList;
import java.util.List;
import org.apache.padaf.xmpbox.XMPMetadata;
-import org.apache.padaf.xmpbox.parser.PDFAExtentionSchemaPreprocessor;
import org.apache.padaf.xmpbox.parser.XMPDocumentBuilder;
import org.apache.padaf.xmpbox.parser.XmpExpectedRdfAboutAttribute;
import org.apache.padaf.xmpbox.parser.XmpParsingException;
@@ -73,7 +72,6 @@ public class MetadataValidationProcess e
XMPDocumentBuilder builder;
try {
builder = new XMPDocumentBuilder();
- builder.addPreprocessor(new PDFAExtentionSchemaPreprocessor());
} catch (XmpSchemaException e1) {
throw new ValidationException(e1.getMessage(), e1);
}
Propchange: pdfbox/branches/xmpbox-refactoring/preflight/src/test/resources/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Tue Aug 7 16:40:47 2012
@@ -0,0 +1,2 @@
+Isartor testsuite
+Isartor testsuite.list
Modified: pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/BuildPDFExtensionSchemaHelper.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/BuildPDFExtensionSchemaHelper.java?rev=1370356&r1=1370355&r2=1370356&view=diff
==============================================================================
--- pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/BuildPDFExtensionSchemaHelper.java (original)
+++ pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/BuildPDFExtensionSchemaHelper.java Tue Aug 7 16:40:47 2012
@@ -21,21 +21,7 @@
package org.apache.padaf.xmpbox;
-import java.lang.reflect.Field;
-import java.util.Iterator;
-import java.util.List;
-
-import org.apache.padaf.xmpbox.parser.XMLPropertiesDescriptionManager;
-import org.apache.padaf.xmpbox.parser.XMLValueTypeDescriptionManager;
-import org.apache.padaf.xmpbox.schema.PDFAExtensionSchema;
-import org.apache.padaf.xmpbox.schema.PropertyExtensionDefinition;
-import org.apache.padaf.xmpbox.schema.SchemaDescription;
-import org.apache.padaf.xmpbox.schema.SchemaExtensionDefinition;
-import org.apache.padaf.xmpbox.schema.ValueTypeDescription;
import org.apache.padaf.xmpbox.schema.XMPSchema;
-import org.apache.padaf.xmpbox.type.BadFieldValueException;
-import org.apache.padaf.xmpbox.type.PropertyDescription;
-import org.apache.padaf.xmpbox.type.PropertyType;
/**
@@ -48,6 +34,8 @@ import org.apache.padaf.xmpbox.type.Prop
*/
public class BuildPDFExtensionSchemaHelper {
+ // TODO re impl?menter
+
/**
* According to check-style, Utility classes should not have a public or
* default constructor.
@@ -73,119 +61,8 @@ public class BuildPDFExtensionSchemaHelp
public static void includePDFAExtensionDefinition(XMPMetadata metadata,
XMPSchema schema)
throws BuildPDFAExtensionSchemaDescriptionException {
- PDFAExtensionSchema ext = metadata.getPDFExtensionSchema();
- Class<? extends XMPSchema> classSchem = schema.getClass();
- if (ext == null) {
- ext = metadata.createAndAddPDFAExtensionSchemaWithDefaultNS();
- }
- Field[] fields;
- fields = classSchem.getFields();
- SchemaExtensionDefinition schemDefAnnot;
- PropertyExtensionDefinition propExtDefAnnot;
- PropertyType propTypeAnnot;
- String propName = null;
- String propDesc;
- List<PropertyDescription> xmlPropDesc = null;
- if (classSchem.isAnnotationPresent(SchemaExtensionDefinition.class)) {
- schemDefAnnot = classSchem
- .getAnnotation(SchemaExtensionDefinition.class);
- // Try to find and load XML Properties Descriptions file path
- if (!schemDefAnnot.property_descriptions().equals("")) {
- XMLPropertiesDescriptionManager propManag = new XMLPropertiesDescriptionManager();
- propManag.loadListFromXML(classSchem, schemDefAnnot
- .property_descriptions());
- xmlPropDesc = propManag.getPropertiesDescriptionList();
- }
- SchemaDescription desc = ext.createSchemaDescription();
- desc.setSchemaValue(schemDefAnnot.schema());
- desc.setNameSpaceURIValue(schema.getNamespaceValue());
- desc.setPrefixValue(schema.getPrefix());
- ext.addSchemaDescription(desc);
- // Try to find and load XML ValueType Description file path
- if (!schemDefAnnot.valueType_description().equals("")) {
- XMLValueTypeDescriptionManager valTypesManag = new XMLValueTypeDescriptionManager();
- valTypesManag.loadListFromXML(classSchem, schemDefAnnot
- .valueType_description());
- addValueTypesToSchem(metadata, desc, valTypesManag
- .getValueTypesDescriptionList());
- }
- for (Field field : fields) {
- if (field
- .isAnnotationPresent(PropertyExtensionDefinition.class)
- && field.isAnnotationPresent(PropertyType.class)) {
- try {
- propName = (String) field.get(propName);
- } catch (Exception e) {
- throw propertyDescriptionError(
- classSchem.getName(),
- field.getName(),
- "Couldn't read content, please check accessibility and declaration of field associated",
- e);
- }
- propExtDefAnnot = field
- .getAnnotation(PropertyExtensionDefinition.class);
- propTypeAnnot = field.getAnnotation(PropertyType.class);
- try {
- if (xmlPropDesc != null) {
- Iterator<PropertyDescription> it = xmlPropDesc
- .iterator();
- PropertyDescription tmp;
- propDesc = null;
- while (it.hasNext() && (propDesc == null)) {
- tmp = it.next();
- if (tmp.getPropertyName().equals(propName)) {
- propDesc = tmp.getDescription();
- }
- }
-
- } else {
- propDesc = propExtDefAnnot.propertyDescription();
- }
- if ((propDesc == null) || propDesc.equals("")) {
- propDesc = "Not documented description";
- }
- desc.addProperty(propName,
- propTypeAnnot.propertyType(), propExtDefAnnot
- .propertyCategory(), propDesc);
- } catch (BadFieldValueException e) {
- throw propertyDescriptionError(classSchem.getName(),
- propName, "Wrong value for property Category",
- e);
- }
- }
- }
- } else {
- throw schemaDescriptionError(classSchem.getName(),
- "Couldn't find SchemaExtensionDefinition annotation.");
- }
- /*
- * try { SaveMetadataHelper.serialize(ext, System.out); } catch
- * (TransformException e) { e.printStackTrace(); }
- */
}
- /**
- * Add Value Types description which must be associated to the Schema
- * Description
- *
- * @param metadata
- * Metadata concerned by this Schema Declaration
- * @param desc
- * The Description Schema under construction
- * @param vTypes
- * The Value Types list which must be added
- */
- protected static void addValueTypesToSchem(XMPMetadata metadata,
- SchemaDescription desc, List<ValueTypeDescription> vTypes) {
- for (ValueTypeDescription valueTypeDescription : vTypes) {
- desc.addValueType(valueTypeDescription.getType(),
- valueTypeDescription.getNamespaceURI(),
- valueTypeDescription.getPrefix(), valueTypeDescription
- .getDescription(), valueTypeDescription
- .getPDFAFieldsAssocied(metadata));
-
- }
- }
/**
* An helper to build a formated error message for schema Description errors
Modified: pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/XMPMetadata.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/XMPMetadata.java?rev=1370356&r1=1370355&r2=1370356&view=diff
==============================================================================
--- pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/XMPMetadata.java (original)
+++ pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/XMPMetadata.java Tue Aug 7 16:40:47 2012
@@ -321,7 +321,7 @@ public class XMPMetadata {
*/
public PDFAExtensionSchema createAndAddPDFAExtensionSchemaWithNS(
Map<String, String> namespaces) throws XmpSchemaException {
- PDFAExtensionSchema pdfAExt = new PDFAExtensionSchema(this, namespaces);
+ PDFAExtensionSchema pdfAExt = new PDFAExtensionSchema(this);
pdfAExt.setAboutAsSimple("");
addSchema(pdfAExt);
return pdfAExt;
Modified: pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/XmpConstants.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/XmpConstants.java?rev=1370356&r1=1370355&r2=1370356&view=diff
==============================================================================
--- pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/XmpConstants.java (original)
+++ pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/XmpConstants.java Tue Aug 7 16:40:47 2012
@@ -20,7 +20,7 @@
package org.apache.padaf.xmpbox;
-public class XmpConstants {
+public final class XmpConstants {
public static final String RDF_NAMESPACE = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
Modified: pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/parser/StructuredPropertyParser.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/parser/StructuredPropertyParser.java?rev=1370356&r1=1370355&r2=1370356&view=diff
==============================================================================
--- pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/parser/StructuredPropertyParser.java (original)
+++ pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/parser/StructuredPropertyParser.java Tue Aug 7 16:40:47 2012
@@ -37,10 +37,11 @@ import org.apache.padaf.xmpbox.XMPMetada
import org.apache.padaf.xmpbox.type.AbstractField;
import org.apache.padaf.xmpbox.type.AbstractSimpleProperty;
import org.apache.padaf.xmpbox.type.AbstractStructuredType;
+import org.apache.padaf.xmpbox.type.ArrayProperty;
import org.apache.padaf.xmpbox.type.ComplexPropertyContainer;
+import org.apache.padaf.xmpbox.type.DefinedStructuredType;
import org.apache.padaf.xmpbox.type.PropertyType;
import org.apache.padaf.xmpbox.type.TypeDescription;
-import org.apache.padaf.xmpbox.type.TypeMapping;
public class StructuredPropertyParser {
@@ -52,12 +53,10 @@ public class StructuredPropertyParser {
private Map<String,PropertyDescription> propDesc = null;
- // private static Class<?> [] propertyConstructorParams = new Class [] {XMPMetadata.class,String.class};
private static Class<?> [] propertyConstructorParams = new Class [] {XMPMetadata.class};
public StructuredPropertyParser(XMPDocumentBuilder builder,Class<? extends AbstractStructuredType> propertyTypeClass)
- throws XmpPropertyFormatException
- {
+ throws XmpPropertyFormatException {
this.builder = builder;
this.typeClass = propertyTypeClass;
this.propDesc = new HashMap<String, PropertyDescription>();
@@ -79,15 +78,21 @@ public class StructuredPropertyParser {
}
}
// retrieve constructor
- try {
- typeConstructor = typeClass.getConstructor(propertyConstructorParams);
- } catch (SecurityException e) {
- throw new XmpPropertyFormatException("Failed to initialize structured type parser : "+typeClass.getName(),e);
- } catch (NoSuchMethodException e) {
- throw new XmpPropertyFormatException("Failed to initialize structured type parser : "+typeClass.getName(),e);
+ if (DefinedStructuredType.class.isAssignableFrom(typeClass)) {
+ // specific case from DefinedStructured type
+ typeConstructor = null;
+ } else {
+ // reflection to find constructor
+ try {
+ typeConstructor = typeClass.getConstructor(propertyConstructorParams);
+ } catch (SecurityException e) {
+ throw new XmpPropertyFormatException("Failed to initialize structured type parser : "+typeClass.getName(),e);
+ } catch (NoSuchMethodException e) {
+ throw new XmpPropertyFormatException("Failed to initialize structured type parser : "+typeClass.getName(),e);
+ }
}
- }
+ }
private AbstractStructuredType instanciateProperty (XMPMetadata metadata) throws XmpParsingException {
try {
@@ -107,30 +112,24 @@ public class StructuredPropertyParser {
private boolean isParseTypeResource (XMLStreamReader reader) {
-// XMLStreamReader reader = builder.getReader();
+ // XMLStreamReader reader = builder.getReader();
int count = reader.getAttributeCount();
for (int i=0; i < count ; i++) {
if ("parseType".equals(reader.getAttributeLocalName(i))) {
- if ("Resource".equals(reader.getAttributeValue(i))) {
- return true;
- } else {
- return false;
- }
+ return "Resource".equals(reader.getAttributeValue(i));
}
}
return false;
}
-
+
public void parse(XMPMetadata metadata, QName altName,
ComplexPropertyContainer container)
- throws XmpUnexpectedTypeException, XmpParsingException,
- XMLStreamException, XmpUnknownPropertyTypeException,
- XmpPropertyFormatException {
+ throws XmpParsingException, XMLStreamException {
builder.expectCurrentLocalName("li");
// check if parseType is defined
boolean skipDescription = isParseTypeResource(builder.getReader());
-
+
builder.getReader().nextTag();
parseSimple(metadata, altName, container, skipDescription,"li");
if (!skipDescription) {
@@ -138,12 +137,10 @@ public class StructuredPropertyParser {
}
}
-
+
public void parseSimple(XMPMetadata metadata, QName altName,
ComplexPropertyContainer container, boolean skipDescription, String limiter)
- throws XmpUnexpectedTypeException, XmpParsingException,
- XMLStreamException, XmpUnknownPropertyTypeException,
- XmpPropertyFormatException {
+ throws XmpParsingException, XMLStreamException {
XMLStreamReader reader = builder.getReader();
int elmtType = reader.getEventType();
@@ -153,8 +150,13 @@ public class StructuredPropertyParser {
builder.expectCurrentLocalName("Description");
elmtType = reader.nextTag();
}
- AbstractStructuredType property = instanciateProperty(metadata);
-
+ AbstractStructuredType property = null;
+ if (typeConstructor==null) {
+ // defined type
+ property = new DefinedStructuredType(metadata, null, null);// TODO
+ } else {
+ property = instanciateProperty(metadata);
+ }
QName eltName;
String structuredEndName = skipDescription?limiter:"Description";
while (!((elmtType == XMLStreamReader.END_ELEMENT) && reader.getName().getLocalPart().equals(structuredEndName))) {
@@ -223,6 +225,10 @@ public class StructuredPropertyParser {
if (reader.getEventType()==XMLStreamConstants.START_ELEMENT) {
TypeDescription td = builder.getTypeMapping().getStructuredTypeName(eltName.getNamespaceURI());
+ if (td==null) {
+ throw new XmpUnexpectedNamespaceURIException("No namespace defined with name "+eltName.getNamespaceURI());
+ }
+
String ptype = td.getProperties().getPropertyType(eltName.getLocalPart());
if (builder.getTypeMapping().isStructuredType(ptype)) {
TypeDescription tclass = builder.getTypeMapping().getTypeDescription(ptype);
@@ -236,25 +242,33 @@ public class StructuredPropertyParser {
TypeDescription tclass = builder.getTypeMapping().getTypeDescription(typeInArray);
Class<? extends AbstractStructuredType> tcn = (Class<? extends AbstractStructuredType>)tclass.getTypeClass();
+
+ ArrayProperty cp = new ArrayProperty(metadata,null,
+ eltName.getPrefix(), eltName.getLocalPart(),
+ arrayType);
+ property.getContainer().addProperty(cp);
+
// array element starting
builder.expectCurrentLocalName(arrayType);
- builder.expectNextSpecificTag(XMLStreamConstants.START_ELEMENT, "li", "Should be starting a 'li'");
- // array elements
- while (reader.getEventType()==XMLStreamConstants.START_ELEMENT && reader.getName().getLocalPart().equals("li")) {
- StructuredPropertyParser sp = new StructuredPropertyParser(builder, tcn);
- sp.parse(metadata, reader.getName(), property.getContainer());
- reader.nextTag();
- }
- // array element ending
- builder.expectCurrentLocalName(arrayType);
reader.nextTag();
+ if (reader.getLocalName().equals("li")) {
+ // array elements
+ while (reader.getEventType()==XMLStreamConstants.START_ELEMENT && reader.getName().getLocalPart().equals("li")) {
+ StructuredPropertyParser sp = new StructuredPropertyParser(builder, tcn);
+ sp.parse(metadata, reader.getName(), cp.getContainer());
+ reader.nextTag();
+ }
+ // array element ending
+ builder.expectCurrentLocalName(arrayType);
+ reader.nextTag();
+ } // else, it was an empty array
}
-
-
+
+
elmtType = reader.nextTag();
} else {
// end element
-// reader.nextTag();
+ // reader.nextTag();
elmtType = reader.getEventType();
}
}
@@ -262,7 +276,7 @@ public class StructuredPropertyParser {
if (!skipDescription) {
// closing rdf:Description element
builder.expectCurrentLocalName("Description");
-// reader.nextTag();
+ // reader.nextTag();
}
container.addProperty(property);
Modified: pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/parser/XMPDocumentBuilder.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/parser/XMPDocumentBuilder.java?rev=1370356&r1=1370355&r2=1370356&view=diff
==============================================================================
--- pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/parser/XMPDocumentBuilder.java (original)
+++ pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/parser/XMPDocumentBuilder.java Tue Aug 7 16:40:47 2012
@@ -44,17 +44,20 @@ import org.apache.padaf.xmpbox.XMPMetada
import org.apache.padaf.xmpbox.XmpConstants;
import org.apache.padaf.xmpbox.schema.NSMapping;
import org.apache.padaf.xmpbox.schema.PDFAExtensionSchema;
-import org.apache.padaf.xmpbox.schema.PDFAFieldDescription;
-import org.apache.padaf.xmpbox.schema.SchemaDescription;
import org.apache.padaf.xmpbox.schema.SchemaMapping;
import org.apache.padaf.xmpbox.schema.XMPSchema;
import org.apache.padaf.xmpbox.type.AbstractField;
import org.apache.padaf.xmpbox.type.AbstractSimpleProperty;
import org.apache.padaf.xmpbox.type.AbstractStructuredType;
+import org.apache.padaf.xmpbox.type.ArrayProperty;
import org.apache.padaf.xmpbox.type.Attribute;
import org.apache.padaf.xmpbox.type.BadFieldValueException;
-import org.apache.padaf.xmpbox.type.ArrayProperty;
import org.apache.padaf.xmpbox.type.ComplexPropertyContainer;
+import org.apache.padaf.xmpbox.type.DefinedStructuredType;
+import org.apache.padaf.xmpbox.type.PDFAFieldType;
+import org.apache.padaf.xmpbox.type.PDFAPropertyType;
+import org.apache.padaf.xmpbox.type.PDFASchemaType;
+import org.apache.padaf.xmpbox.type.PDFATypeType;
import org.apache.padaf.xmpbox.type.TextType;
import org.apache.padaf.xmpbox.type.TypeDescription;
import org.apache.padaf.xmpbox.type.TypeMapping;
@@ -70,17 +73,15 @@ import org.apache.pdfbox.io.IOUtils;
public class XMPDocumentBuilder {
private NSMapping nsMap;
-
+
private TypeMapping typeMapping = null;
-
+
private SchemaMapping schemaMapping = null;
private ThreadLocal<XMLStreamReader> reader = new ThreadLocal<XMLStreamReader>();
- private List<XMPDocumentPreprocessor> preprocessors = new ArrayList<XMPDocumentPreprocessor>();
-
public static final String VALUE_TYPE_NAME = "valueType";
-
+
/**
* RDF namespace constant
*/
@@ -101,7 +102,7 @@ public class XMPDocumentBuilder {
public XMPMetadata createXMPMetadata () throws CreateXMPMetadataException {
return new WrappedXMPMetadata(this);
}
-
+
public XMPMetadata createXMPMetadata (String begin, String id, String bytes, String encoding) throws CreateXMPMetadataException {
return new WrappedXMPMetadata(this,begin, id, bytes, encoding);
@@ -114,15 +115,14 @@ public class XMPDocumentBuilder {
public WrappedXMPMetadata(XMPDocumentBuilder builder, String xpacketBegin, String xpacketId,
String xpacketBytes, String xpacketEncoding)
- throws CreateXMPMetadataException {
+ throws CreateXMPMetadataException {
super(builder, xpacketBegin, xpacketId, xpacketBytes, xpacketEncoding);
- // TODO Auto-generated constructor stub
}
-
-
+
+
}
-
-
+
+
/**
* Parsing method. Return a XMPMetadata object with all elements read
*
@@ -152,12 +152,19 @@ public class XMPDocumentBuilder {
XmpExpectedRdfAboutAttribute, XmpXpacketEndException,
BadFieldValueException {
- if (!(this instanceof XMPDocumentPreprocessor)) {
- for (XMPDocumentPreprocessor processor : preprocessors) {
- NSMapping additionalNSMapping = processor.process(xmp);
- this.nsMap.importNSMapping(additionalNSMapping);
- }
- }
+ XMPDocumentBuilder preproc = new XMPDocumentBuilder();
+ XMPMetadata xmpPreproc = preproc.doParsingParsing(xmp,true);
+ populateSchemaMapping(schemaMapping, xmpPreproc);
+
+
+ return doParsingParsing(xmp,false);
+ }
+
+ public XMPMetadata doParsingParsing(byte[] xmp, boolean parseExtension) throws XmpParsingException,
+ XmpSchemaException, XmpUnknownValueTypeException,
+ XmpExpectedRdfAboutAttribute, XmpXpacketEndException,
+ BadFieldValueException {
+
ByteArrayInputStream is = new ByteArrayInputStream(xmp);
try {
@@ -183,6 +190,7 @@ public class XMPDocumentBuilder {
// add all namespaces which could declare nsURI of a basicValueType
// all others declarations are ignored
int nsCount = reader.get().getNamespaceCount();
+ // TODO MUTUALIZE namespace list loading
for (int i = 0; i < nsCount; i++) {
if (typeMapping.isStructuredTypeNamespace(reader.get().getNamespaceURI(i))) {
nsMap.setComplexBasicTypesDeclarationForLevelXMP(
@@ -194,7 +202,7 @@ public class XMPDocumentBuilder {
// now work on each rdf:Description
int type = reader.get().nextTag();
while (type == XMLStreamReader.START_ELEMENT) {
- parseDescription(metadata);
+ parseDescription(metadata,parseExtension);
type = reader.get().nextTag();
}
@@ -243,6 +251,109 @@ public class XMPDocumentBuilder {
}
}
+ private void populateSchemaMapping (SchemaMapping sm, XMPMetadata meta)
+ throws XmpRequiredPropertyException,XmpUnknownValueTypeException,XmpUnexpectedNamespacePrefixException {
+ List<XMPSchema> schems = meta.getAllSchemas();
+ for (XMPSchema xmpSchema : schems) {
+ if (xmpSchema.getNamespaceValue().equals(PDFAExtensionSchema.PDFAEXTENSIONURI)) {
+ // ensure the prefix is the preferred one (cannot use other definition)
+ if (!xmpSchema.getPrefix().equals(PDFAExtensionSchema.PDFAEXTENSION)) {
+ throw new XmpUnexpectedNamespacePrefixException("Found invalid prefix for PDF/A extension, found '"+
+ xmpSchema.getPrefix()+"', should be '"+PDFAExtensionSchema.PDFAEXTENSION+"'"
+ );
+ }
+ // create schema and types
+ PDFAExtensionSchema pes = (PDFAExtensionSchema)xmpSchema;
+ ArrayProperty sp = pes.getSchemasProperty();
+ for (AbstractField af: sp.getAllProperties()) {
+ if (af instanceof PDFASchemaType) {
+ PDFASchemaType st = (PDFASchemaType)af;
+ String namespaceUri = st.getNamespaceURI();
+ ArrayProperty properties = st.getProperty();
+ ArrayProperty valueTypes = st.getValueType();
+ XMPSchemaFactory xsf = schemaMapping.getSchemaFactory(namespaceUri);
+ // retrieve namespaces
+ if (xsf==null) {
+ // create namespace with no field
+ schemaMapping.addNewNameSpace(namespaceUri);
+ xsf = schemaMapping.getSchemaFactory(namespaceUri);
+ }
+ // populate value type
+ if (valueTypes!=null) {
+ for (AbstractField af2 : valueTypes.getAllProperties()) {
+ if (af2 instanceof PDFATypeType) {
+ PDFATypeType type = (PDFATypeType)af2;
+ String ttype= type.getType();
+ String tns = type.getNamespaceURI();
+ String tprefix = type.getPrefix();
+ String tdescription = type.getDescription();
+ ArrayProperty fields = type.getFields();
+ if (ttype==null || tns==null || tprefix==null || tdescription==null) {
+ // all fields are mandatory
+ throw new XmpRequiredPropertyException("Missing field in type definition");
+ }
+ // create the structured type
+ DefinedStructuredType structuredType = new DefinedStructuredType(meta, tns, tprefix);
+ if (fields!=null) {
+ List<AbstractField> definedFields = fields.getAllProperties();
+ for (AbstractField af3 : definedFields) {
+ if (af3 instanceof PDFAFieldType) {
+ PDFAFieldType field = (PDFAFieldType)af3;
+ String fName = field.getName();
+ String fDescription = field.getDescription();
+ String fValueType = field.getValueType();
+ if (fName==null || fDescription==null || fValueType==null) {
+ throw new XmpRequiredPropertyException("Missing field in field definition");
+ }
+ // create the type
+ TypeDescription vtd = typeMapping.getTypeDescription(fValueType);
+ if (vtd!=null) {
+ // a type is found
+ String ftype = vtd.getType();
+ structuredType.addProperty(fName, ftype);
+ } else {
+ // unknown type
+ throw new XmpUnknownValueTypeException("Type not defined : "+fValueType);
+ }
+ } // else TODO
+ }
+ }
+ // add the structured type to list
+ TypeDescription td = new TypeDescription(ttype, null, DefinedStructuredType.class);
+ typeMapping.addToStructuredMaps(td,tns);
+ }
+ }
+ }
+ // populate properties
+ for (AbstractField af2 : properties.getAllProperties()) {
+ if (af2 instanceof PDFAPropertyType) {
+ PDFAPropertyType property = (PDFAPropertyType)af2;
+ String pname = property.getName();
+ String ptype = property.getValueType();
+ String pdescription = property.getDescription();
+ String pCategory = property.getCategory();
+ // check all mandatory fields are OK
+ if (pname==null || ptype==null || pdescription==null || pCategory==null) {
+ // all fields are mandatory
+ throw new XmpRequiredPropertyException("Missing field in property definition");
+ }
+ // check ptype existance
+ TypeDescription td = typeMapping.getTypeDescription(ptype);
+ if (td==null) {
+ // type not defined
+ throw new XmpUnknownValueTypeException("Type not defined : "+ptype);
+ }
+ // load the property
+ xsf.getPropertyDefinition().addNewProperty(pname, ptype, null);
+ } // TODO unmanaged ?
+ }
+ } // TODO unmanaged ?
+ }
+ }
+ }
+ }
+
+
/**
* Parsing method using serialized xmp read from a stream
*
@@ -289,10 +400,6 @@ public class XMPDocumentBuilder {
return bos.toByteArray();
}
- public void addPreprocessor(XMPDocumentPreprocessor processor) {
- this.preprocessors.add(processor);
- }
-
/**
* Check InitialXPacket and build metadata object with these information
*
@@ -518,7 +625,7 @@ public class XMPDocumentBuilder {
String schemaNamespace = schema.getNamespaceValue();
String prefix = attr.getPrefix() != null ? attr.getPrefix() : schema.getPrefix();
String type = this.nsMap.getSpecifiedPropertyType(schemaNamespace, new QName(schemaNamespace, attr.getLocalName(), prefix));
-
+
if (type != null) {
AbstractSimpleProperty prop = typeMapping.instanciateSimpleProperty(metadata, null, prefix, attr.getLocalName(), attr.getValue(), type);
schema.getContent().addProperty(prop);
@@ -548,80 +655,53 @@ public class XMPDocumentBuilder {
* @throws BadFieldValueException
* When a bad value found in Schema description content
*/
- protected void parseDescription(XMPMetadata metadata)
+ protected void parseDescription(XMPMetadata metadata, boolean parseExtension)
throws XmpParsingException, XMLStreamException, XmpSchemaException,
XmpUnknownValueTypeException, XmpExpectedRdfAboutAttribute,
BadFieldValueException {
nsMap.resetComplexBasicTypesDeclarationInSchemaLevel();
int cptNS = reader.get().getNamespaceCount();
HashMap<String, String> namespaces = new HashMap<String, String>();
+ // TODO MUTUALIZE namespace list loading
for (int i = 0; i < cptNS; i++) {
namespaces.put(reader.get().getNamespacePrefix(i), reader.get()
.getNamespaceURI(i));
if (typeMapping.isStructuredTypeNamespace(reader.get().getNamespaceURI(i))) {
- // System.out.println("in parseDesc method: prefix:"+reader.get().getNamespacePrefix(i)+", nsURI:"+reader.get().getNamespaceURI(i));
nsMap.setComplexBasicTypesDeclarationForLevelSchema(reader
.get().getNamespaceURI(i), reader.get()
.getNamespacePrefix(i));
}
}
- // Different treatment for PDF/A Extension schema
- // System.out.println(PDFAExtensionSchema.PDFAEXTENSION+";"+PDFAExtensionSchema.PDFAPROPERTY+";"+PDFAExtensionSchema.PDFASCHEMA);
- if (namespaces.containsKey(PDFAExtensionSchema.PDFAEXTENSION)) {
- if (namespaces.containsKey(PDFAExtensionSchema.PDFAPROPERTY)
- && namespaces.containsKey(PDFAExtensionSchema.PDFASCHEMA)) {
- if (namespaces
- .containsValue(PDFAExtensionSchema.PDFAEXTENSIONURI)
- && namespaces
- .containsValue(PDFAExtensionSchema.PDFAPROPERTYURI)
- && namespaces
- .containsValue(PDFAExtensionSchema.PDFASCHEMAURI)) {
- PDFAExtensionSchema schema = metadata
- .createAndAddPDFAExtensionSchemaWithNS(namespaces);
- treatDescriptionAttributes(metadata, schema);
- parseExtensionSchema(schema, metadata);
-
- } else {
- throw new XmpUnexpectedNamespaceURIException(
- "Unexpected namespaceURI in PDFA Extension Schema encountered");
- }
- } else {
- throw new XmpUnexpectedNamespacePrefixException(
- "Unexpected namespace Prefix in PDFA Extension Schema");
- }
-
- } else {
- int c = 0;
- String namespaceUri = reader.get().getNamespaceURI(c);
- String namespacePrefix = reader.get().getNamespacePrefix(c);
+ int c = 0;
+ String namespaceUri = reader.get().getNamespaceURI(c);
+ String namespacePrefix = reader.get().getNamespacePrefix(c);
+ c++;
+ XMPSchema schema = nsMap.getAssociatedSchemaObject(metadata, namespaceUri, namespacePrefix);
+ while (c<reader.get().getNamespaceCount() && schema==null) {
+ // try next
+ namespaceUri = reader.get().getNamespaceURI(c);
+ namespacePrefix = reader.get().getNamespacePrefix(c);
+ schema = nsMap.getAssociatedSchemaObject(metadata, namespaceUri, namespacePrefix);
c++;
- XMPSchema schema = nsMap.getAssociatedSchemaObject(metadata, namespaceUri, namespacePrefix);
- while (c<reader.get().getNamespaceCount() && schema==null) {
- // try next
- namespaceUri = reader.get().getNamespaceURI(c);
- namespacePrefix = reader.get().getNamespacePrefix(c);
- schema = nsMap.getAssociatedSchemaObject(metadata, namespaceUri, namespacePrefix);
- c++;
- }
-
- if (schema != null) {
- namespaces.remove(namespacePrefix);
- } else {
- schema = metadata.createAndAddDefaultSchema(namespacePrefix,namespaceUri);
- }
+ }
- for (int i = 1; i < cptNS; i++) {
- schema.setAttribute(new Attribute(XMPSchema.NS_NAMESPACE,
- "xmlns", reader.get().getNamespacePrefix(i), reader.get().getNamespaceURI(i)));
- }
- treatDescriptionAttributes(metadata, schema);
- while (reader.get().nextTag() == XMLStreamReader.START_ELEMENT) {
- parseProperty(schema);
- }
+ if (schema != null) {
+ namespaces.remove(namespacePrefix);
+ } else {
+ schema = metadata.createAndAddDefaultSchema(namespacePrefix,namespaceUri);
}
+ for (int i = 1; i < cptNS; i++) {
+ schema.setAttribute(new Attribute(XMPSchema.NS_NAMESPACE,
+ "xmlns", reader.get().getNamespacePrefix(i), reader.get().getNamespaceURI(i)));
+ }
+ treatDescriptionAttributes(metadata, schema);
+ while (reader.get().nextTag() == XMLStreamReader.START_ELEMENT) {
+ parseProperty(schema,parseExtension);
+ }
}
+
/**
* Check the next element type and its expected value
*
@@ -663,309 +743,6 @@ public class XMPDocumentBuilder {
}
/**
- * Treat a PDFAExtension schema
- *
- * @param schema
- * PDFA/Extension schema where save information found
- * @param metadata
- * Metadata to attach new elements
- * @throws XmpParsingException
- * When element expected not found
- * @throws XMLStreamException
- * When error during reading the rest of xmp stream
- * @throws XmpUnknownValueTypeException
- * When ValueType found not correspond to basic type and not has
- * been declared in current schema
- * @throws BadFieldValueException
- * When one of a field property include to describe a property
- * in Schema Description contain an incorrect value
- */
- protected final void parseExtensionSchema(PDFAExtensionSchema schema,
- XMPMetadata metadata) throws XmpParsingException,
- XMLStreamException, XmpUnknownValueTypeException,
- BadFieldValueException {
- // <pdfaExtension:schemas>
- expectNextSpecificTag(XMLStreamReader.START_ELEMENT, "schemas",
- "Cannot find container declaration of schemas descriptions ");
- // <rdf:Bag>
- expectNextSpecificTag(XMLStreamReader.START_ELEMENT, ArrayProperty.UNORDERED_ARRAY,
- "Cannot find bag declaration for container of schemas descriptions");
- // now work on each rdf:li corresponding to each schema description
- int type = reader.get().nextTag();
- while (type == XMLStreamReader.START_ELEMENT) {
- parseSchemaDescription(schema, metadata);
- type = reader.get().nextTag();
- }
- expectNextSpecificTag(XMLStreamReader.END_ELEMENT, "schemas",
- "Cannot find end of container declaration in schemas descriptions ");
- expectNextSpecificTag(XMLStreamReader.END_ELEMENT, "Description",
- "Cannot find end of PDF/A Extension definition ");
-
- }
-
- /**
- * Treat one Schema description defined in the extension Schema found
- *
- * @param schema
- * PDFA/Extension schema where save information found
- * @param metadata
- * Metadata to attach new elements
- * @throws XMLStreamException
- * When error during reading the rest of xmp stream
- * @throws XmpParsingException
- * When element expected not found
- * @throws XmpUnknownValueTypeException
- * When ValueType found not correspond to basic type and not has
- * been declared in current schema
- * @throws BadFieldValueException
- * When one of a field property contain an incorrect value
- */
- private void parseSchemaDescription(PDFAExtensionSchema schema,
- XMPMetadata metadata) throws XMLStreamException,
- XmpParsingException, XmpUnknownValueTypeException,
- BadFieldValueException {
- expectCurrentLocalName("li");
- SchemaDescription desc = schema.createSchemaDescription();
- if ("Resource".equals(reader.get().getAttributeValue(XmpConstants.RDF_NAMESPACE, "parseType"))) {
- fillSchemaDescription(desc, metadata);
- } else {
- int type = reader.get().nextTag();
- if (type == XMLStreamReader.START_ELEMENT && reader.get().getLocalName().equals("Description")) {
- fillSchemaDescription(desc, metadata);
- // read the end tag
- reader.get().nextTag();
- }
- }
-
- schema.addSchemaDescription(desc);
- nsMap.setNamespaceDefinition(desc);
-
- }
-
- protected void fillSchemaDescription(SchemaDescription desc, XMPMetadata metadata)
- throws XMLStreamException, XmpParsingException,
- XmpUnknownValueTypeException, BadFieldValueException {
- int type = reader.get().nextTag();
- while (type == XMLStreamReader.START_ELEMENT) {
- if (reader.get().getLocalName().equals("schema")
- || reader.get().getLocalName().equals("namespaceURI")
- || reader.get().getLocalName().equals("prefix")) {
- try {
- // System.out.println(reader.get().getPrefix()+";"+reader.get().getLocalName()+";"+reader.get().getElementText());
- desc.addProperty(new TextType(metadata, null, reader.get()
- .getPrefix(), reader.get().getLocalName(), reader
- .get().getElementText()));
- } catch (IllegalArgumentException e) {
- StringBuilder message = new StringBuilder(50);
- message.append("Unexpected value for '");
- message.append(reader.get().getLocalName()).append("' property");
- throw new XmpPropertyFormatException(
- message.toString(),e
- );
- }
- } else if (reader.get().getLocalName().equals("property")) {
- parsePropertyDefinition(desc);
- } else if (reader.get().getLocalName().equals(VALUE_TYPE_NAME)) {
- parseValueTypeDefinition(desc, metadata);
- } else {
- throw new XmpUnexpectedElementException(
- "Unexpected property definition in one of PDF/A Extension schemas description");
- }
- type = reader.get().nextTag();
- }
- }
-
- /**
- * Treat value type definition for a specific Schema Description
- *
- * @param desc
- * the current Schema Description analyzed
- * @param metadata
- * Metadata to attach new elements
- * @throws XmpParsingException
- * When element expected not found
- * @throws XMLStreamException
- * When error during reading the rest of xmp stream
- */
- private void parseValueTypeDefinition(SchemaDescription desc,
- XMPMetadata metadata) throws XmpParsingException,
- XMLStreamException {
- // <rdf:Seq>
- expectNextSpecificTag(XMLStreamReader.START_ELEMENT, ArrayProperty.ORDERED_ARRAY,
- "Expected Seq Declaration");
- int elmtType = reader.get().nextTag();
- String type, namespaceURI, prefix, description;
- List<PDFAFieldDescription> fields;
- while (elmtType == XMLStreamReader.START_ELEMENT) {
- type = null;
- namespaceURI = null;
- prefix = null;
- description = null;
- fields = null;
- expectCurrentLocalName("li");
- elmtType = reader.get().nextTag();
- while (elmtType == XMLStreamReader.START_ELEMENT) {
- if (reader.get().getLocalName().equals("type")) {
- type = reader.get().getElementText();
- } else if (reader.get().getLocalName().equals("namespaceURI")) {
- namespaceURI = reader.get().getElementText();
- } else if (reader.get().getLocalName().equals("prefix")) {
- prefix = reader.get().getElementText();
- } else if (reader.get().getLocalName().equals("description")) {
- description = reader.get().getElementText();
- } else if (reader.get().getLocalName().equals("field")) {
- fields = parseFieldDescription(metadata);
-
- } else {
- throw new XmpUnexpectedElementException(
- "Unexpected property definition in one of ValueType Descriptions of PDF/A Extension schemas description");
- }
- elmtType = reader.get().nextTag();
- }
- if ((type != null) && (namespaceURI != null) && (prefix != null)
- && (description != null)) {
- desc.addValueType(type, namespaceURI, prefix, description,
- fields);
- } else {
- throw new XmpRequiredPropertyException(
- "one property declaration in PDF/A Extension is not complete");
- }
- elmtType = reader.get().nextTag();
- }
- expectNextSpecificTag(XMLStreamReader.END_ELEMENT, VALUE_TYPE_NAME,
- "Expected End of ValueType Declaration");
-
- }
-
- /**
- * Treat field description on the current analyzed value type description
- *
- * @param metadata
- * Metadata to attach new elements
- * @return A list of parsed fields
- * @throws XMLStreamException
- * When error during reading the rest of xmp stream
- * @throws XmpParsingException
- * When element expected not found
- */
- private List<PDFAFieldDescription> parseFieldDescription(
- XMPMetadata metadata) throws XmpParsingException,
- XMLStreamException {
- List<PDFAFieldDescription> fields = new ArrayList<PDFAFieldDescription>();
- // <rdf:Seq>
- expectNextSpecificTag(XMLStreamReader.START_ELEMENT, ArrayProperty.ORDERED_ARRAY,
- "Expected Seq Declaration");
- int elmtType = reader.get().nextTag();
- String name, type, description;
- while (elmtType == XMLStreamReader.START_ELEMENT) {
- expectCurrentLocalName("li");
- elmtType = reader.get().nextTag();
- name = null;
- type = null;
- description = null;
-
- while (elmtType == XMLStreamReader.START_ELEMENT) {
- if (reader.get().getLocalName().equals("name")) {
- name = reader.get().getElementText();
- } else if (reader.get().getLocalName().equals(VALUE_TYPE_NAME)) {
- type = reader.get().getElementText();
- } else if (reader.get().getLocalName().equals("description")) {
- description = reader.get().getElementText();
- } else {
- throw new XmpUnexpectedElementException(
- "Unexpected property definition in one of ValueType Field Descriptions of PDF/A Extension schemas description");
- }
- elmtType = reader.get().nextTag();
- }
- if ((name != null) && (type != null) && (description != null)) {
- PDFAFieldDescription tmp = new PDFAFieldDescription(metadata);
- tmp.setNameValue(name);
- tmp.setValueTypeValue(type);
- tmp.setDescriptionValue(description);
- fields.add(tmp);
- } else {
- throw new XmpRequiredPropertyException(
- "One valuetype field declaration in PDF/A Extension is not complete");
- }
- // expectNextTag(XMLStreamReader.END_ELEMENT,"Expected element end");
- elmtType = reader.get().nextTag();
- }
- expectNextSpecificTag(XMLStreamReader.END_ELEMENT, "field",
- "Expected End of Properties Declaration");
- if (fields.size() != 0) {
- return fields;
- }
- return null;
- }
-
- /**
- * Treat a property definition for a specific Schema Description
- *
- * @param desc
- * the current Schema Description analyzed
- * @throws XmpParsingException
- * When element expected not found
- * @throws XMLStreamException
- * When error during reading the rest of xmp stream
- * @throws BadFieldValueException
- * When one of a field property contain an incorrect value
- */
- private void parsePropertyDefinition(SchemaDescription desc)
- throws XmpParsingException, XMLStreamException, BadFieldValueException {
- // <rdf:Seq>
- expectNextSpecificTag(XMLStreamReader.START_ELEMENT, ArrayProperty.ORDERED_ARRAY, "Expected Seq Declaration");
- // Each property definition
- int elmtType = reader.get().nextTag();
- while (elmtType == XMLStreamReader.START_ELEMENT) {
- expectCurrentLocalName("li");
- if ("Resource".equals(reader.get().getAttributeValue(XmpConstants.RDF_NAMESPACE, "parseType"))) {
- fillDescription(desc);
- } else {
- elmtType = reader.get().nextTag();
- if (elmtType == XMLStreamReader.START_ELEMENT && reader.get().getLocalName().equals("Description")) {
- fillDescription(desc);
- // read the end tag
- reader.get().nextTag();
- }
- }
- // expectNextTag(XMLStreamReader.END_ELEMENT,"Expected element end");
- elmtType = reader.get().nextTag();
- }
- expectNextSpecificTag(XMLStreamReader.END_ELEMENT, "property",
- "Expected End of Properties Declaration");
- }
-
- protected void fillDescription(SchemaDescription desc)
- throws XmpParsingException, XMLStreamException, BadFieldValueException {
- int elmtType = reader.get().nextTag();
- String name = null;
- String type = null;
- String category = null;
- String description = null;
-
- while (elmtType == XMLStreamReader.START_ELEMENT) {
- if (reader.get().getLocalName().equals("name")) {
- name = reader.get().getElementText();
- } else if (reader.get().getLocalName().equals(VALUE_TYPE_NAME)) {
- type = reader.get().getElementText();
- } else if (reader.get().getLocalName().equals("category")) {
- category = reader.get().getElementText();
- } else if (reader.get().getLocalName().equals("description")) {
- description = reader.get().getElementText();
- } else {
- throw new XmpUnexpectedElementException(
- "Unexpected property definition in one of Properties Descriptions of PDF/A Extension schemas description");
- }
- elmtType = reader.get().nextTag();
- }
- if ((name != null) && (type != null) && (category != null)&& (description != null)) {
- desc.addProperty(name, type, category, description);
- } else {
- throw new XmpRequiredPropertyException("one property declaration in PDF/A Extension is not complete");
- }
- }
-
- /**
* Check for all namespaces declared for the specified schema if the
* property searched exists and return its type or null
*
@@ -979,7 +756,6 @@ public class XMPDocumentBuilder {
*/
private String getPropertyDeclarationInNamespaces(XMPSchema schema,
QName prop) throws XmpParsingException {
-
Iterator<Attribute> it = schema.getAllAttributes().iterator();
Attribute tmp;
ArrayList<Attribute> list = new ArrayList<Attribute>();
@@ -1019,7 +795,7 @@ public class XMPDocumentBuilder {
private void parseSimpleProperty(XMPMetadata metadata, QName propertyName,
Class<? extends AbstractSimpleProperty> typeclass, ComplexPropertyContainer container)
- throws XmpUnknownPropertyTypeException, XmpPropertyFormatException, XMLStreamException {
+ throws XmpUnknownPropertyTypeException, XmpPropertyFormatException, XMLStreamException {
Class<? extends AbstractSimpleProperty> tclass = (Class<? extends AbstractSimpleProperty>)typeclass;
try {
AbstractSimpleProperty prop = null;
@@ -1033,7 +809,7 @@ public class XMPDocumentBuilder {
}
Class<?> [] constParams = new Class<?> [] {XMPMetadata.class,String.class,String.class,String.class,Object.class};
Constructor<? extends AbstractSimpleProperty> constructor = tclass.getConstructor(constParams);
-
+
prop = constructor.newInstance(metadata, null,propertyName.getPrefix(),
propertyName.getLocalPart(), reader.get()
.getElementText());
@@ -1064,7 +840,7 @@ public class XMPDocumentBuilder {
}
}
-
+
protected void parseStructuredPropertyArray(XMPMetadata metadata, QName name, String ctype, StructuredPropertyParser complexParser,
ComplexPropertyContainer container)
throws XmpUnexpectedTypeException, XmpParsingException,
@@ -1090,7 +866,7 @@ public class XMPDocumentBuilder {
}
-
+
private void parseSimplePropertyArray(XMPMetadata metadata, QName name, String ctype,
@@ -1117,114 +893,6 @@ public class XMPDocumentBuilder {
expectNextSpecificTag(XMLStreamReader.END_ELEMENT, name
.getLocalPart(), "Expected end of '"+ctype+"' property");
}
-
-
- private boolean createAndAddPropertyToContainer(XMPMetadata metadata,
- String type, ComplexPropertyContainer container)
- throws XmpParsingException, XmpUnexpectedTypeException,
- XmpUnknownPropertyTypeException, XmpPropertyFormatException,
- XMLStreamException {
- TypeDescription typeDesc = typeMapping.getTypeDescription(type);
-
- if (type.equals("Lang alt")) {
- parseSimplePropertyArray(metadata, reader.get().getName(),
- ArrayProperty.ALTERNATIVE_ARRAY, TextType.class, container);
- } else if (typeMapping.isSimpleType(typeDesc.getType())) {
- Class<? extends AbstractSimpleProperty> tcn = (Class<? extends AbstractSimpleProperty>)typeDesc.getTypeClass();
- parseSimpleProperty(metadata, reader.get().getName(),
- tcn, container);
- } else if (typeMapping.isStructuredType(type)) {
- QName propertyName = reader.get().getName();
- TypeDescription tclass = typeMapping.getTypeDescription(type);
- StructuredPropertyParser parser = new StructuredPropertyParser(
- this, (Class<? extends AbstractStructuredType>)tclass.getTypeClass());
- parseStructuredProperty(metadata, parser, container);
- } else if (typeMapping.getArrayType(type)!=null) {
- QName propertyName = reader.get().getName();
- // retrieve array type and content type
- int pos = type.indexOf(' ');
- String arrayType = typeMapping.getArrayType(type);
- String typeInArray = type.substring(pos+1);
- TypeDescription tclass = typeMapping.getTypeDescription(typeInArray);
- Class<? extends AbstractField> tcn = tclass.getTypeClass();
-
- if (AbstractSimpleProperty.class.isAssignableFrom(tcn)) {
- // array of simple
- parseSimplePropertyArray(
- metadata,
- propertyName,
- arrayType,
- (Class<? extends AbstractSimpleProperty>)tcn,
- container);
- } else if (AbstractStructuredType.class.isAssignableFrom(tcn)) {
- // array of structured
- StructuredPropertyParser parser = new StructuredPropertyParser(
- this, (Class<? extends AbstractStructuredType>)tcn);
- parseStructuredPropertyArray(metadata, propertyName, arrayType, parser, container);
- } else {
- // invalid case
- throw new XmpUnexpectedTypeException("Unknown type : "+type);
- }
- } else {
- return false;
- }
- return true;
- }
-
- /**
- * Parse a specific field
- *
- * @param metadata
- * Metadata to attach new elements
- * @param propertyName
- * the full qualified name of this property
- * @param schema
- * The schema where save this property
- * @throws XmpUnexpectedTypeException
- * When DOM Element type found unexpected
- * @throws XmpParsingException
- * When element expected not found
- * @throws XMLStreamException
- * When error during reading the rest of xmp stream
- * @throws XmpUnknownPropertyTypeException
- * Value Type property is incorrect or the basic value type
- * can't be treat at the moment
- * @throws XmpPropertyFormatException
- * Unexpected type found (IllegalArgumentException)
- */
- protected void parseFieldProperty(XMPMetadata metadata, QName propertyName,
- XMPSchema schema) throws XmpUnexpectedTypeException,
- XmpPropertyFormatException, XmpParsingException,
- XMLStreamException, XmpUnknownPropertyTypeException {
- ComplexPropertyContainer field = new ComplexPropertyContainer(metadata,null,
- propertyName.getPrefix(), propertyName.getLocalPart());
- schema.addProperty(field);
- field.setAttribute(new Attribute(null, "rdf", "parseType", "Resource"));
- String type;
- int elmtType = reader.get().nextTag();
- while ((elmtType != XMLStreamReader.END_ELEMENT)
- && !reader.get().getName().getLocalPart().equals(ArrayProperty.ORDERED_ARRAY)) {
-
- type = getPropertyDeclarationInNamespaces(schema, reader.get()
- .getName());
- if (!createAndAddPropertyToContainer(metadata, type, field)) {
- if (type.equals("Field")) {
- String stype = getPropertyDeclarationInNamespaces(schema,
- reader.get().getName());
- createAndAddPropertyToContainer(metadata, stype, field);
- } else {
- throw new XmpUnknownPropertyTypeException("Unknown type : "
- + type);
- }
- }
- elmtType = reader.get().nextTag();
- }
- expectCurrentLocalName(propertyName.getLocalPart());
-
- // expectNextSpecificTag(XMLStreamReader.END_ELEMENT,
- // propertyName.getLocalPart(), "Expected end of field declaration");
-
- }
/**
* analyze one property in the stream, retrieve its type according to the
@@ -1246,14 +914,23 @@ public class XMPDocumentBuilder {
* @throws XmpPropertyFormatException
* Unexpected type found (IllegalArgumentException)
*/
- protected void parseProperty(XMPSchema schema)
+ protected void parseProperty(XMPSchema schema, boolean parsingExtension)
throws XmpParsingException, XmpPropertyFormatException,
XmpUnexpectedTypeException, XMLStreamException,
XmpUnknownPropertyTypeException {
XMPMetadata metadata = schema.getMetadata();
QName propertyName = reader.get().getName();
+ if (parsingExtension) {
+ if (!propertyName.getNamespaceURI().equals(PDFAExtensionSchema.PDFAEXTENSIONURI)) {
+ // this schema won't be parsed as extension, skip
+ // XXX skip to end of element
+ skipCurrentElement();
+ return;
+ }
+ }
nsMap.resetComplexBasicTypesDeclarationInPropertyLevel();
int cptNs = reader.get().getNamespaceCount();
+ // TODO MUTUALIZE namespace list loading
for (int i = 0; i < cptNs; i++) {
if (typeMapping.isStructuredTypeNamespace(reader.get().getNamespaceURI(i))) {
nsMap.setComplexBasicTypesDeclarationForLevelSchema(reader
@@ -1282,7 +959,7 @@ public class XMPDocumentBuilder {
String typeInArray = type.substring(pos+1);
TypeDescription tclass = typeMapping.getTypeDescription(typeInArray);
Class<? extends AbstractField> tcn = tclass.getTypeClass();
-
+
if (AbstractSimpleProperty.class.isAssignableFrom(tcn)) {
// array of simple
parseSimplePropertyArray(
@@ -1300,24 +977,13 @@ public class XMPDocumentBuilder {
// invalid case
throw new XmpUnknownPropertyTypeException("Unknown type : "+type);
}
- } else if (type.equals("Field")) {
- parseFieldProperty(metadata, propertyName, schema);
+ // } else if (type.equals("Field")) {
+ // parseFieldProperty(metadata, propertyName, schema);
} else {
throw new XmpUnknownPropertyTypeException("Unknown type : " + type);
}
} catch (XmpUnknownPropertyException e) {
-// // this property is not managed in the workspace
-// // do not parse the property, no validation, no reserialization
-// boolean cont = true;
-// while (cont) {
-// int t = reader.get().next();
-// if (t==XMLStreamReader.END_ELEMENT) {
-// if (propertyName.equals(reader.get().getName())) {
-// cont = false;
-// }
-// }
-// }
throw e;
}
@@ -1354,5 +1020,21 @@ public class XMPDocumentBuilder {
return schemaMapping;
}
-
+ public void skipCurrentElement () throws XmpParsingException,XMLStreamException {
+ if (!reader.get().isStartElement()) {
+ throw new XmpParsingException("SkipElement only start on Start element event");
+ }
+ // on start element
+ int openedTag = 1;
+ do {
+ int tag = reader.get().next();
+ if (tag == XMLStreamReader.START_ELEMENT) {
+ openedTag++;
+ } else if (tag == XMLStreamReader.END_ELEMENT) {
+ openedTag--;
+ }
+ } while (openedTag>0);
+ }
+
+
}
Modified: pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/parser/XMPSchemaFactory.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/parser/XMPSchemaFactory.java?rev=1370356&r1=1370355&r2=1370356&view=diff
==============================================================================
--- pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/parser/XMPSchemaFactory.java (original)
+++ pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/parser/XMPSchemaFactory.java Tue Aug 7 16:40:47 2012
@@ -45,8 +45,6 @@ public class XMPSchemaFactory {
private String nsName;
- private boolean isDeclarative;
-
private List<PropMapping> importedPropertyMapping = new ArrayList<PropMapping>();
/**
@@ -61,31 +59,9 @@ public class XMPSchemaFactory {
*/
public XMPSchemaFactory(String namespace,
Class<? extends XMPSchema> schemaClass, PropMapping propDef) {
- this.isDeclarative = false;
- this.namespace = namespace;
- this.schemaClass = schemaClass;
- this.propDef = propDef;
- }
-
- /**
- * Factory constructor for declarative XMP Schemas
- *
- * @param nsName
- * namespace name to treat
- * @param namespace
- * namespace URI to treat
- * @param schemaClass
- * Class representation associated to this URI
- * @param propDef
- * Properties Types list associated
- */
- public XMPSchemaFactory(String nsName, String namespace,
- Class<? extends XMPSchema> schemaClass, PropMapping propDef) {
- this.isDeclarative = true;
this.namespace = namespace;
this.schemaClass = schemaClass;
this.propDef = propDef;
- this.nsName = nsName;
}
public void importXMPSchemaFactory(XMPSchemaFactory externalFactory)
@@ -163,7 +139,7 @@ public class XMPSchemaFactory {
Class<?>[] argsClass;
Object[] schemaArgs;
- if (isDeclarative) {
+ if (schemaClass == XMPSchema.class) {
argsClass = new Class[] { XMPMetadata.class, String.class, String.class };
schemaArgs = new Object[] { metadata, nsName, namespace };
} else if (prefix != null && !"".equals(prefix)) {
@@ -188,4 +164,8 @@ public class XMPSchemaFactory {
}
}
+ public PropMapping getPropertyDefinition () {
+ return this.propDef;
+ }
+
}
Modified: pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/schema/NSMapping.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/schema/NSMapping.java?rev=1370356&r1=1370355&r2=1370356&view=diff
==============================================================================
--- pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/schema/NSMapping.java (original)
+++ pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/schema/NSMapping.java Tue Aug 7 16:40:47 2012
@@ -22,18 +22,16 @@
package org.apache.padaf.xmpbox.schema;
import java.util.HashMap;
-import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import javax.xml.namespace.QName;
import org.apache.padaf.xmpbox.XMPMetadata;
-import org.apache.padaf.xmpbox.parser.PropMapping;
import org.apache.padaf.xmpbox.parser.XMPDocumentBuilder;
import org.apache.padaf.xmpbox.parser.XMPSchemaFactory;
import org.apache.padaf.xmpbox.parser.XmpSchemaException;
-import org.apache.padaf.xmpbox.parser.XmpUnknownValueTypeException;
+import org.apache.padaf.xmpbox.type.TypeMapping;
/**
@@ -46,9 +44,6 @@ public class NSMapping {
private XMPDocumentBuilder builder = null;
- private Map<String, XMPSchemaFactory> definedNamespaces;
-
-
private Map<String, String> complexBasicTypesDeclarationEntireXMPLevel;
private Map<String, String> complexBasicTypesDeclarationSchemaLevel;
@@ -66,7 +61,7 @@ public class NSMapping {
complexBasicTypesDeclarationEntireXMPLevel = new HashMap<String, String>();
complexBasicTypesDeclarationSchemaLevel = new HashMap<String, String>();
complexBasicTypesDeclarationPropertyLevel = new HashMap<String, String>();
- definedNamespaces = new HashMap<String, XMPSchemaFactory>();
+// definedNamespaces = new HashMap<String, XMPSchemaFactory>();
}
@@ -76,13 +71,6 @@ public class NSMapping {
*/
public void importNSMapping(NSMapping imp) throws XmpSchemaException {
// merge name sapce maps
- for (Entry<String, XMPSchemaFactory> entry : imp.definedNamespaces.entrySet() ) {
- if (this.definedNamespaces.containsKey(entry.getKey())) {
- this.definedNamespaces.get(entry.getKey()).importXMPSchemaFactory(entry.getValue());
- } else {
- this.definedNamespaces.put(entry.getKey(), entry.getValue());
- }
- }
// merge complex basic types declaration entire xmp level
for (Entry<String, String> entry : imp.complexBasicTypesDeclarationEntireXMPLevel.entrySet()) {
if(!complexBasicTypesDeclarationEntireXMPLevel.containsKey(entry.getKey())) {
@@ -115,7 +103,9 @@ public class NSMapping {
public boolean isContainedNamespace(String namespace) {
boolean found = builder.getSchemaMapping().isContainedNamespace(namespace);
if (!found) {
- found = definedNamespaces.containsKey(namespace);
+// found = definedNamespaces.containsKey(namespace);
+ TypeMapping tm = builder.getTypeMapping();
+ found = tm.isStructuredTypeNamespace(namespace);
}
return found;
}
@@ -132,9 +122,6 @@ public class NSMapping {
*/
public String getSpecifiedPropertyType(String namespace, QName prop) {
XMPSchemaFactory factory = builder.getSchemaMapping().getSchemaFactory(namespace);
- if (factory==null) {
- factory = definedNamespaces.get(namespace);
- }
if (factory!=null) {
return factory.getPropertyType(prop.getLocalPart());
} else {
@@ -144,104 +131,6 @@ public class NSMapping {
}
/**
- * Check if a non basic value type used is describes in the schema which
- * inlude a property with a such type
- *
- * @param desc
- * The schema description associated to the schema which declare
- * a property with specific value type
- * @param definedValueType
- * The value type name to find in value types descriptions
- * @return The description of this specific value type
- * @throws XmpUnknownValueTypeException
- * If no declaration found
- */
- private PDFAValueTypeDescription findValueTypeDescription(
- SchemaDescription desc, String definedValueType)
- throws XmpUnknownValueTypeException {
- List<PDFAValueTypeDescription> values = desc.getValueTypes();
- for (PDFAValueTypeDescription val : values) {
- if (definedValueType.equals(val.getTypeNameValue())) {
- return val;
- }
- }
- throw new XmpUnknownValueTypeException("ValueType '" + definedValueType
- + "' is unknown. no declaration found in this schema");
- }
-
- /**
- * Check if valueType used for a specified property description is known (in
- * case where it's a normal value type or if a value type which has been
- * defined in PDF/A Extension schema)
- *
- * @param desc
- * The schema description associated to the schema which declare
- * a property with specific value type
- * @param definedValueType
- * The value type name to find in value types descriptions
- * @return value type equivalence (value type which can be treat (orginal
- * basic value type or specific value type decomposed to find basic
- * types)
- * @throws XmpUnknownValueTypeException
- * When Value Type is unknown
- *
- */
- private String getValueTypeEquivalence(SchemaDescription desc,
- String definedValueType) throws XmpUnknownValueTypeException {
- if (builder.getTypeMapping().isSimpleType(definedValueType) || builder.getTypeMapping().isArrayOfSimpleType(definedValueType)) {
- return definedValueType;
- }
- PDFAValueTypeDescription val = findValueTypeDescription(desc,
- definedValueType);
- if (val.getFields().isEmpty()) {
- // if fields value are note defined we suppose the property is a
- // Text type
- return "Text";
- }
- return "Field";
- }
-
-
- /**
- * Add a new namespace Mapping for specific schema declared in PDF/A
- * Extension schema
- *
- * @param desc
- * The schemaDescription associated to the schema
- * @throws XmpUnknownValueTypeException
- * When a Value Type associated is unknown
- */
- public void setNamespaceDefinition(SchemaDescription desc)
- throws XmpUnknownValueTypeException {
- PropMapping propMap = new PropMapping(desc.getNameSpaceURI());
- List<PDFAPropertyDescription> props = desc.getProperties();
- for (int i = 0; i < props.size(); i++) {
- String type = getValueTypeEquivalence(desc, props.get(i).getValueTypeValue());
- propMap.addNewProperty(props.get(i).getNameValue(), type, null);
- if (type.equals("Field")) {
- String valueType = props.get(i).getValueTypeValue();
- PDFAValueTypeDescription val = findValueTypeDescription(desc, valueType);
- for (PDFAFieldDescription field : val.getFields()) {
- // XXX case where a field call another nspace property ???
- String fieldType = getValueTypeEquivalence(desc, field
- .getValueTypeValue());
- if (fieldType.equals("Field")) {
- throw new XmpUnknownValueTypeException(
- "ValueType Field reference a valuetype unknown");
- }
- propMap.addNewProperty(field.getNameValue(), fieldType, null);
-
- }
-
-
- }
- }
- String nsName = desc.getPrefix();
- String ns = desc.getNameSpaceURI();
- definedNamespaces.put(ns, new XMPSchemaFactory(nsName, ns, XMPSchema.class, propMap));
- }
-
- /**
* Check if a namespace declaration for a complex basic type has been found
* and if its valid for the entire XMP stream
*
@@ -358,10 +247,10 @@ public class NSMapping {
return found;
} else {
// look in local
- if (!definedNamespaces.containsKey(namespace)) {
+ XMPSchemaFactory factory = builder.getSchemaMapping().getSchemaFactory(namespace);
+ if (factory==null) {
return null;
}
- XMPSchemaFactory factory = definedNamespaces.get(namespace);
return factory.createXMPSchema(metadata, prefix);
}
}
Modified: pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/schema/PDFAExtensionSchema.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/schema/PDFAExtensionSchema.java?rev=1370356&r1=1370355&r2=1370356&view=diff
==============================================================================
--- pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/schema/PDFAExtensionSchema.java (original)
+++ pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/schema/PDFAExtensionSchema.java Tue Aug 7 16:40:47 2012
@@ -21,19 +21,9 @@
package org.apache.padaf.xmpbox.schema;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-
import org.apache.padaf.xmpbox.XMPMetadata;
-import org.apache.padaf.xmpbox.parser.XmpSchemaException;
-import org.apache.padaf.xmpbox.type.Attribute;
-import org.apache.padaf.xmpbox.type.Elementable;
+import org.apache.padaf.xmpbox.type.ArrayProperty;
import org.apache.padaf.xmpbox.type.PropertyType;
-import org.w3c.dom.Element;
/**
* Representation of a PDF/A Extension schema description schema
@@ -46,38 +36,11 @@ public class PDFAExtensionSchema extends
public static final String PDFAEXTENSION = "pdfaExtension";
public static final String PDFAEXTENSIONURI = "http://www.aiim.org/pdfa/ns/extension/";
- public static final String PDFASCHEMA = "pdfaSchema";
- public static final String PDFASCHEMASEP = "pdfaSchema:";
- public static final String PDFASCHEMAURI = "http://www.aiim.org/pdfa/ns/schema#";
-
- public static final String PDFAPROPERTY = "pdfaProperty";
- public static final String PDFAPROPERTYSEP = "pdfaProperty:";
- public static final String PDFAPROPERTYURI = "http://www.aiim.org/pdfa/ns/property#";
-
- public static final String PDFATYPE = "pdfaType";
- public static final String PDFATYPESEP = "pdfaType:";
- public static final String PDFATYPEURI = "http://www.aiim.org/pdfa/ns/type#";
-
- public static final String PDFAFIELD = "pdfaField";
- public static final String PDFAFIELDSEP = "pdfaField:";
- public static final String PDFAFIELDURI = "http://www.aiim.org/pdfa/ns/field#";
-
- @PropertyType(propertyType = "Text")
- public static final String SCHEMA = "schema";
-
- @PropertyType(propertyType = "URI")
- public static final String NS_URI = "namespaceURI";
- @PropertyType(propertyType = "Text")
- public static final String PREFIX = "prefix";
+ @PropertyType(propertyType = "bag PDFASchema")
+ public static final String SCHEMAS = "schemas";
- @PropertyType(propertyType = "Seq Property")
- public static final String PROPERTY = "property";
- @PropertyType(propertyType = "Seq ValueType")
- public static final String VALUETYPE = "valueType";
-
- private SchemaDescriptionContainer descriptions;
/**
* Build a new PDFExtension schema
@@ -91,44 +54,6 @@ public class PDFAExtensionSchema extends
public PDFAExtensionSchema(XMPMetadata metadata, String prefix) {
super(metadata, prefix, PDFAEXTENSIONURI);
- setAttribute(new Attribute(NS_NAMESPACE, "xmlns", PDFASCHEMA,
- PDFASCHEMAURI));
- setAttribute(new Attribute(NS_NAMESPACE, "xmlns", PDFAPROPERTY,
- PDFAPROPERTYURI));
- setAttribute(new Attribute(NS_NAMESPACE, "xmlns", PDFATYPE, PDFATYPEURI));
- setAttribute(new Attribute(NS_NAMESPACE, "xmlns", PDFAFIELD,
- PDFAFIELDURI));
-
- descriptions = new SchemaDescriptionContainer();
- getElement().appendChild(descriptions.getElement());
-
- }
- /**
- * Build a new PDFExtension schema with specified namespaces declaration
- *
- * @param metadata
- * The metadata to attach this schema
- * @param namespaces
- * List of namespaces to define
- * @throws XmpSchemaException
- * The namespace URI of PDF/A Extension schema missing
- */
- public PDFAExtensionSchema(XMPMetadata metadata,
- Map<String, String> namespaces) throws XmpSchemaException {
- super(metadata, PDFAEXTENSION, PDFAEXTENSIONURI);
- if (!namespaces.containsKey(PDFAEXTENSION)) {
- throw new XmpSchemaException(
- "Extension schema is declared without the pdfaSchema namespace specification");
- }
- namespaces.remove(PDFAEXTENSION);
-
- for (Entry<String, String> entry : namespaces.entrySet()) {
- setAttribute(new Attribute(NS_NAMESPACE, "xmlns", entry.getKey(),
- entry.getValue()));
- }
- descriptions = new SchemaDescriptionContainer();
- getElement().appendChild(descriptions.getElement());
-
}
/**
@@ -150,174 +75,13 @@ public class PDFAExtensionSchema extends
return PDFAEXTENSIONURI;
}
- /**
- * Add to the Extension Schema a new description schema param desc the
- * schema description
- *
- * @param desc
- * the new schema description
- * @return the previous schema with same prefix, null otherwise
- */
- public SchemaDescription addSchemaDescription(SchemaDescription desc) {
- return descriptions.addSchemaDescription(desc);
- }
-
- /**
- * create Extension Schema a new description schema
- *
- * @return a new empty description schema
- */
- public SchemaDescription createSchemaDescription() {
- return new SchemaDescription(getMetadata());
- }
-
- /**
- * Give a list of all description declared
- *
- * @return List of all schemaDescriptions declared
- */
- public List<SchemaDescription> getDescriptionSchema() {
- return Collections.unmodifiableList(descriptions.schemaDescriptions);
- }
-
- /**
- * Give an iterator of all description declared
- *
- * @return a SchemaDescription Iterator
- */
- public Iterator<SchemaDescription> getIteratorOfDescriptions() {
- return descriptions.getAllSchemasDescription();
- }
-
- /**
- * Container of Description Schema embedded in PDF/A Extension Schema
- *
- * @author a183132
- *
- */
- public class SchemaDescriptionContainer implements Elementable {
-
- private Element element, content;
- private List<SchemaDescription> schemaDescriptions;
-
- /**
- *
- * SchemasDescription Container constructor
- */
- public SchemaDescriptionContainer() {
- element = getMetadata().getFuturOwner().createElement(
- PDFAEXTENSION + ":schemas");
- content = getMetadata().getFuturOwner().createElement("rdf:Bag");
- element.appendChild(content);
-
- schemaDescriptions = new ArrayList<SchemaDescription>();
- }
-
- /**
- * Add a SchemaDescription to the current structure
- *
- * @param obj
- * the property to add
- * @return the old SchemaDescription corresponding to the same namespace
- * prefix if exist, else null
- */
- public SchemaDescription addSchemaDescription(SchemaDescription obj) {
- SchemaDescription sd = getSameSchemaDescription(obj);
- if (sd != null) {
- schemaDescriptions.remove(sd);
- content.removeChild(sd.getContent().getElement());
- }
- // if(containsSchemaDescription(obj)){
- // removeSchemaDescription(obj);
- // }
- schemaDescriptions.add(obj);
- content.appendChild(obj.getContent().getElement());
- return sd;
- }
-
- /**
- * Get Schema Description embedded with the same prefix as that given in
- * parameters
- *
- * @param obj
- * Schema Description with same prefix
- * @return The schema Description contained
- */
- protected SchemaDescription getSameSchemaDescription(
- SchemaDescription obj) {
- String oPrefix = obj.getPrefix();
- for (SchemaDescription existing : schemaDescriptions) {
- if (oPrefix.equals(existing.getPrefix())) {
- return existing;
- }
- }
- // else not found
- return null;
- }
-
- /**
- * Return all SchemaDescription
- *
- * @return SchemaDescriptions Iterator in order to be use in PDF/A
- * Extension Schema class
- */
- public Iterator<SchemaDescription> getAllSchemasDescription() {
- return schemaDescriptions.iterator();
- }
-
- // /**
- // * Check if two SchemaDescription are similar
- // * @param prop1
- // * @param prop2
- // * @return
- // */
- // public boolean isSameSchemaDescription(SchemaDescription prop1,
- // SchemaDescription prop2){
- // if(prop1.getClass().equals(prop2.getClass()) ){
- // if(prop1.content.getElement().getTextContent().equals(prop2.content.getElement().getTextContent())){
- // return true;
- // }
- // }
- // return false;
- // }
-
- // /**
- // * Check if a specified SchemaDescription is embedded
- // * @param schema
- // * @return
- // */
- // public boolean containsSchemaDescription(SchemaDescription schema){
- // Iterator<SchemaDescription> it=getAllSchemasDescription();
- // SchemaDescription tmp;
- // while(it.hasNext()){
- // tmp=it.next();
- // if(isSameSchemaDescription(tmp, schema) ){
- // return true;
- // }
- // }
- // return false;
- // }
-
- // /**
- // * Remove a schema
- // * @param schema
- // */
- // public void removeSchemaDescription(SchemaDescription schema){
- // if(containsSchemaDescription(schema)){
- // schemaDescriptions.remove(schema);
- // content.removeChild(schema.content.getElement());
- // }
- // }
-
- /**
- * Get Dom Element for xml/rdf serialization
- *
- * @return the DOM Element
- */
- public Element getElement() {
- return element;
- }
-
- }
+ /**
+ *
+ * @return the list of subject values
+ */
+ public ArrayProperty getSchemasProperty() {
+ return (ArrayProperty) getUnqualifiedProperty(SCHEMAS);
+ }
+
}
Modified: pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/schema/SchemaMapping.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/schema/SchemaMapping.java?rev=1370356&r1=1370355&r2=1370356&view=diff
==============================================================================
--- pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/schema/SchemaMapping.java (original)
+++ pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/schema/SchemaMapping.java Tue Aug 7 16:40:47 2012
@@ -52,7 +52,6 @@ public final class SchemaMapping {
}
public SchemaMapping () {
- // hide constructor
}
@@ -70,6 +69,13 @@ public final class SchemaMapping {
nsMaps.put(ns, new XMPSchemaFactory(ns, classSchem, initializePropMapping(ns, classSchem)));
}
+ public void addNewNameSpace(String ns) {
+ PropMapping mapping = new PropMapping(ns);
+ nsMaps.put(ns, new XMPSchemaFactory(ns, XMPSchema.class, mapping));
+ }
+
+
+
/**
* Initialize the Property Mapping for a given schema
Modified: pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/AbstractField.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/AbstractField.java?rev=1370356&r1=1370355&r2=1370356&view=diff
==============================================================================
--- pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/AbstractField.java (original)
+++ pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/AbstractField.java Tue Aug 7 16:40:47 2012
@@ -49,8 +49,6 @@ public abstract class AbstractField impl
private Element element;
- private Document parent;
-
private XMPMetadata metadata;
private String namespaceURI, prefix, propertyName;
@@ -90,7 +88,7 @@ public abstract class AbstractField impl
this.prefix = prefix;
qualifiedName = prefix + ":" + propertyName;
this.metadata = metadata;
- this.parent = metadata.getFuturOwner();
+ Document parent = metadata.getFuturOwner();
this.namespaceURI = namespaceURI;
this.propertyName = propertyName;
if (this.namespaceURI!=null) {
Modified: pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/AbstractStructuredType.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/AbstractStructuredType.java?rev=1370356&r1=1370355&r2=1370356&view=diff
==============================================================================
--- pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/AbstractStructuredType.java (original)
+++ pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/AbstractStructuredType.java Tue Aug 7 16:40:47 2012
@@ -85,6 +85,16 @@ public abstract class AbstractStructured
return (AbstractSimpleProperty)list.get(0);
}
+ protected ArrayProperty getArrayProperty (String fieldName) {
+ List<AbstractField> list = container.getPropertiesByLocalName(fieldName);
+ // return null if no property
+ if (list==null) {
+ return null;
+ }
+ // return the first element of the list
+ return (ArrayProperty)list.get(0);
+ }
+
protected String getPropertyValueAsString (String fieldName) {
AbstractSimpleProperty absProp = getProperty(fieldName);
Modified: pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/ArrayProperty.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/ArrayProperty.java?rev=1370356&r1=1370355&r2=1370356&view=diff
==============================================================================
--- pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/ArrayProperty.java (original)
+++ pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/ArrayProperty.java Tue Aug 7 16:40:47 2012
@@ -21,6 +21,8 @@
package org.apache.padaf.xmpbox.type;
+import java.util.List;
+
import org.apache.padaf.xmpbox.XMPMetadata;
/**
@@ -88,4 +90,9 @@ public class ArrayProperty extends Abstr
return false;
}
+ public List<AbstractField> getAllProperties() {
+ return container.getAllProperties();
+ }
+
+
}