}
public static void populateSchemaMapping(XMPMetadata meta) throws XmpParsingException
{
List<XMPSchema> schems = meta.getAllSchemas();
TypeMapping tm = meta.getTypeMapping();
StructuredType stPdfaExt = PDFAExtensionSchema.class.getAnnotation(StructuredType.class);
for (XMPSchema xmpSchema : schems)
{
if (xmpSchema.getNamespace().equals(stPdfaExt.namespace()))
{
// ensure the prefix is the preferred one (cannot use other
// definition)
if (!xmpSchema.getPrefix().equals(stPdfaExt.preferedPrefix()))
{
throw new XmpParsingException(ErrorType.InvalidPrefix,
"Found invalid prefix for PDF/A extension, found '" + xmpSchema.getPrefix()
+ "', should be '" + stPdfaExt.preferedPrefix() + "'");
}
// 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().trim();
String prefix = st.getPrefixValue();
ArrayProperty properties = st.getProperty();
ArrayProperty valueTypes = st.getValueType();
XMPSchemaFactory xsf = tm.getSchemaFactory(namespaceUri);
// retrieve namespaces
if (xsf == null)
{
// create namespace with no field
tm.addNewNameSpace(namespaceUri, prefix);
xsf = tm.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.getPrefixValue();
String tdescription = type.getDescription();
ArrayProperty fields = type.getFields();
if (ttype == null || tns == null || tprefix == null || tdescription == null)
{
// all fields are mandatory
throw new XmpParsingException(ErrorType.RequiredProperty,
"Missing field in type definition");
}
// create the structured type
DefinedStructuredType structuredType = new DefinedStructuredType(meta, tns,
tprefix, null); // TODO
// maybe
// a name
// exists
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 XmpParsingException(ErrorType.RequiredProperty,
"Missing field in field definition");
}
try
{
Types fValue = Types.valueOf(fValueType);
structuredType.addProperty(fName,
TypeMapping.createPropertyType(fValue, Cardinality.Simple));
}
catch (IllegalArgumentException e)
{
throw new XmpParsingException(ErrorType.NoValueType,
"Type not defined : " + fValueType, e);
// TODO could fValueType be
// a structured type ?
}
} // else TODO
}
}
// add the structured type to list
PropertiesDescription pm = new PropertiesDescription();
for (Map.Entry<String, PropertyType> entry : structuredType.getDefinedProperties()
.entrySet())
{
pm.addNewProperty(entry.getKey(), entry.getValue());
}
tm.addToDefinedStructuredTypes(ttype, tns, pm);
}
}
}
// populate properties
if (properties == null)