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/10/24 18:07:15 UTC

svn commit: r1401751 [1/2] - in /pdfbox/branches/xmpbox-refactoring/xmpbox: ./ src/main/java/org/apache/padaf/xmpbox/ src/main/java/org/apache/padaf/xmpbox/parser/ src/main/java/org/apache/padaf/xmpbox/schema/ src/main/java/org/apache/padaf/xmpbox/type...

Author: gbailleul
Date: Wed Oct 24 16:07:13 2012
New Revision: 1401751

URL: http://svn.apache.org/viewvc?rev=1401751&view=rev
Log:
PDFBOX-1388: 
xmpbox no more has dependency on stax, a dom parser is used. 
Parser is lighter
Refactoring removed about 1000 lines of code and reduced complexity

Added:
    pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/xml/
    pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/xml/DomHelper.java
    pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/xml/DomXmpParser.java
    pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/xml/PdfaExtensionHelper.java
    pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/xml/XmpParsingException.java
      - copied, changed from r1370327, pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/parser/XmpParsingException.java
    pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/xml/XmpSerializationException.java
      - copied, changed from r1376996, pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/parser/TransformException.java
    pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/xml/XmpSerializer.java
      - copied, changed from r1380021, pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/parser/XmpSerializer.java
    pdfbox/branches/xmpbox-refactoring/xmpbox/src/test/resources/org/apache/padaf/xmpbox/parser/empty_list.xml
Removed:
    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/parser/
Modified:
    pdfbox/branches/xmpbox-refactoring/xmpbox/pom.xml
    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/schema/AdobePDFSchema.java
    pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/schema/PDFAIdentificationSchema.java
    pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/schema/XMPBasicJobTicketSchema.java
    pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/schema/XMPMediaManagementSchema.java
    pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/schema/XMPRightsManagementSchema.java
    pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/schema/XMPSchema.java
    pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/AbstractComplexProperty.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/ComplexPropertyContainer.java
    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/PropMapping.java
    pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/ReflectHelper.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/DoubleSameTypeSchemaTest.java
    pdfbox/branches/xmpbox-refactoring/xmpbox/src/test/java/org/apache/padaf/xmpbox/SaveMetadataHelperTest.java
    pdfbox/branches/xmpbox-refactoring/xmpbox/src/test/java/org/apache/padaf/xmpbox/TestXMPWithDefinedSchemas.java
    pdfbox/branches/xmpbox-refactoring/xmpbox/src/test/java/org/apache/padaf/xmpbox/XMPMetaDataTest.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/parser/PropMappingTest.java
    pdfbox/branches/xmpbox-refactoring/xmpbox/src/test/java/org/apache/padaf/xmpbox/schema/AbstractSchemaTester.java
    pdfbox/branches/xmpbox-refactoring/xmpbox/src/test/java/org/apache/padaf/xmpbox/schema/AbstractXMPSchemaTest.java
    pdfbox/branches/xmpbox-refactoring/xmpbox/src/test/java/org/apache/padaf/xmpbox/schema/AdobePDFErrorsTest.java
    pdfbox/branches/xmpbox-refactoring/xmpbox/src/test/java/org/apache/padaf/xmpbox/schema/AdobePDFTest.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/schema/DublinCoreTest.java
    pdfbox/branches/xmpbox-refactoring/xmpbox/src/test/java/org/apache/padaf/xmpbox/schema/XMPBasicTest.java
    pdfbox/branches/xmpbox-refactoring/xmpbox/src/test/java/org/apache/padaf/xmpbox/schema/XMPMediaManagementTest.java
    pdfbox/branches/xmpbox-refactoring/xmpbox/src/test/java/org/apache/padaf/xmpbox/schema/XMPSchemaTest.java
    pdfbox/branches/xmpbox-refactoring/xmpbox/src/test/java/org/apache/padaf/xmpbox/schema/XmpRightsSchemaTest.java
    pdfbox/branches/xmpbox-refactoring/xmpbox/src/test/java/org/apache/padaf/xmpbox/type/AbstractStructuredTypeTester.java
    pdfbox/branches/xmpbox-refactoring/xmpbox/src/test/java/org/apache/padaf/xmpbox/type/TestAbstractStructuredType.java
    pdfbox/branches/xmpbox-refactoring/xmpbox/src/test/java/org/apache/padaf/xmpbox/type/TestResourceRefType.java
    pdfbox/branches/xmpbox-refactoring/xmpbox/src/test/java/org/apache/padaf/xmpbox/type/TestSimpleMetadataProperties.java
    pdfbox/branches/xmpbox-refactoring/xmpbox/src/test/resources/org/apache/padaf/xmpbox/parser/structured_recursive.xml
    pdfbox/branches/xmpbox-refactoring/xmpbox/src/test/resources/validxmp/ghost2.xmp
    pdfbox/branches/xmpbox-refactoring/xmpbox/src/test/resources/validxmp/override_ns.rdf

Modified: pdfbox/branches/xmpbox-refactoring/xmpbox/pom.xml
URL: http://svn.apache.org/viewvc/pdfbox/branches/xmpbox-refactoring/xmpbox/pom.xml?rev=1401751&r1=1401750&r2=1401751&view=diff
==============================================================================
--- pdfbox/branches/xmpbox-refactoring/xmpbox/pom.xml (original)
+++ pdfbox/branches/xmpbox-refactoring/xmpbox/pom.xml Wed Oct 24 16:07:13 2012
@@ -1,166 +1,133 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<!--
-  Licensed to the Apache Software Foundation (ASF) under one or more
-  contributor license agreements.  See the NOTICE file distributed with
-  this work for additional information regarding copyright ownership.
-  The ASF licenses this file to You under the Apache License, Version 2.0
-  (the "License"); you may not use this file except in compliance with
-  the License.  You may obtain a copy of the License at
-
-       http://www.apache.org/licenses/LICENSE-2.0
-
-  Unless required by applicable law or agreed to in writing, software
-  distributed under the License is distributed on an "AS IS" BASIS,
-  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-  See the License for the specific language governing permissions and
-  limitations under the License.
--->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
-
-  <modelVersion>4.0.0</modelVersion>
-
-  <artifactId>xmpbox</artifactId>
-  <packaging>bundle</packaging>
-  <name>Apache XmpBox</name>
+<!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor 
+	license agreements. See the NOTICE file distributed with this work for additional 
+	information regarding copyright ownership. The ASF licenses this file to 
+	You under the Apache License, Version 2.0 (the "License"); you may not use 
+	this file except in compliance with the License. You may obtain a copy of 
+	the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required 
+	by applicable law or agreed to in writing, software distributed under the 
+	License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS 
+	OF ANY KIND, either express or implied. See the License for the specific 
+	language governing permissions and limitations under the License. -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+	<modelVersion>4.0.0</modelVersion>
+
+	<artifactId>xmpbox</artifactId>
+	<packaging>bundle</packaging>
+	<name>Apache XmpBox</name>
 
-  <description>
+	<description>
     The Apache XmpBox library is an open source Java tool that implements Adobe's XMP(TM)
     specification. It can be used to parse, validate and create xmp contents.
     It is mainly used by subproject preflight of Apache PDFBox. 
     XmpBox is a subproject of Apache PDFBox.
   </description>
 
-  <parent>
-    <groupId>org.apache.pdfbox</groupId>
-    <artifactId>pdfbox-parent</artifactId>
-    <version>1.8.0-SNAPSHOT</version>
-    <relativePath>../parent/pom.xml</relativePath>
-  </parent>
-
-
-  <dependencies>
-    <dependency>
-       <groupId>junit</groupId>
-       <artifactId>junit</artifactId>
-       <version>4.8.1</version>
-       <scope>test</scope>
-    </dependency>
-    <dependency>
-      <groupId>commons-io</groupId>
-      <artifactId>commons-io</artifactId>
-      <version>1.4</version>
-      <scope>test</scope>
-    </dependency>
-
-
-    <dependency>
-      <groupId>com.thoughtworks.xstream</groupId>
-      <artifactId>xstream</artifactId>
-      <version>1.4.2</version>
-    </dependency>
-    <dependency>
-    	<groupId>javax.activation</groupId>
-    	<artifactId>activation</artifactId>
-    	<version>1.1.1</version>
-    	<type>jar</type>
-    	<scope>compile</scope>
-    </dependency>
-    <dependency>
-    	<groupId>stax</groupId>
-    	<artifactId>stax</artifactId>
-    	<version>1.2.0</version>
-    	<type>jar</type>
-    	<scope>compile</scope>
-    </dependency>
-    <dependency>
-    	<groupId>org.apache.pdfbox</groupId>
-    	<artifactId>pdfbox</artifactId>
-    	<version>${project.version}</version>
-    	<type>bundle</type>
-    	<scope>compile</scope>
-    </dependency>
-  </dependencies>
-
-  <build>
-    <plugins>
-      <plugin>
-        <groupId>org.apache.felix</groupId>
-        <artifactId>maven-bundle-plugin</artifactId>
-        <extensions>true</extensions>
-      </plugin>
-    </plugins>
-  </build>
-
-  <reporting>
-    <plugins>
-      <plugin>
-        <groupId>org.codehaus.mojo</groupId>
-        <artifactId>taglist-maven-plugin</artifactId>
-        <version>2.4</version>
-        <configuration>
-        <encoding>UTF-8</encoding>
-        <sourceFileLocale>en</sourceFileLocale>
-        <emptyComments>false</emptyComments>
-        <tagListOptions>
-          <tagClasses>
-            <tagClass>
-              <displayName>TODO List</displayName>
-                <tags>
-                  <tag>
-                    <matchString>TODO</matchString>
-                    <matchType>exact</matchType>
-                  </tag>
-                  <tag>
-                    <matchString>FIXME</matchString>
-                    <matchType>exact</matchType>
-                  </tag>
-                </tags>
-              </tagClass>
-            </tagClasses>
-          </tagListOptions>
-        </configuration>
-      </plugin>
-
-      <plugin>
-        <groupId>org.apache.maven.plugins</groupId>
-        <artifactId>maven-checkstyle-plugin</artifactId>
-        <version>2.2</version>
-        <configuration>
-          <configLocation>edoc-checkstyle.xml</configLocation>
-        </configuration>
-      </plugin>
-
-      <plugin>
-        <groupId>org.codehaus.mojo</groupId>
-        <artifactId>cobertura-maven-plugin</artifactId>
-        <version>2.3</version>
-      </plugin>
-
-      <plugin>
-        <groupId>org.apache.maven.plugins</groupId>
-        <artifactId>maven-surefire-report-plugin</artifactId>
-        <version>2.6</version>
-        <configuration>
-          <showSuccess>true</showSuccess>
-          <aggregate>true</aggregate>
-          <outputDirectory>${project.reporting.outputDirectory}/surefire-report</outputDirectory>
-        </configuration>
-        <reportSets>
-          <reportSet>
-            <id />
-          </reportSet>
-        </reportSets>
-      </plugin>
-
-      <plugin>
-        <groupId>org.codehaus.mojo</groupId>
-        <artifactId>findbugs-maven-plugin</artifactId>
-        <version>2.0.1</version>
-        <configuration>
-          <excludeFilterFile>findbugs-exclude.xml</excludeFilterFile>
-        </configuration>
-      </plugin>
-    </plugins>
-  </reporting>
+	<parent>
+		<groupId>org.apache.pdfbox</groupId>
+		<artifactId>pdfbox-parent</artifactId>
+		<version>1.8.0-SNAPSHOT</version>
+		<relativePath>../parent/pom.xml</relativePath>
+	</parent>
+
+
+	<dependencies>
+		<dependency>
+			<groupId>junit</groupId>
+			<artifactId>junit</artifactId>
+			<version>4.8.1</version>
+			<scope>test</scope>
+		</dependency>
+		<dependency>
+			<groupId>commons-io</groupId>
+			<artifactId>commons-io</artifactId>
+			<version>1.4</version>
+			<scope>test</scope>
+		</dependency>
+	</dependencies>
+
+	<build>
+		<plugins>
+			<plugin>
+				<groupId>org.apache.felix</groupId>
+				<artifactId>maven-bundle-plugin</artifactId>
+				<extensions>true</extensions>
+			</plugin>
+		</plugins>
+	</build>
+
+	<reporting>
+		<plugins>
+			<plugin>
+				<groupId>org.codehaus.mojo</groupId>
+				<artifactId>taglist-maven-plugin</artifactId>
+				<version>2.4</version>
+				<configuration>
+					<encoding>UTF-8</encoding>
+					<sourceFileLocale>en</sourceFileLocale>
+					<emptyComments>false</emptyComments>
+					<tagListOptions>
+						<tagClasses>
+							<tagClass>
+								<displayName>TODO List</displayName>
+								<tags>
+									<tag>
+										<matchString>TODO</matchString>
+										<matchType>exact</matchType>
+									</tag>
+									<tag>
+										<matchString>FIXME</matchString>
+										<matchType>exact</matchType>
+									</tag>
+								</tags>
+							</tagClass>
+						</tagClasses>
+					</tagListOptions>
+				</configuration>
+			</plugin>
+
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-checkstyle-plugin</artifactId>
+				<version>2.2</version>
+				<configuration>
+					<configLocation>edoc-checkstyle.xml</configLocation>
+				</configuration>
+			</plugin>
+
+			<plugin>
+				<groupId>org.codehaus.mojo</groupId>
+				<artifactId>cobertura-maven-plugin</artifactId>
+				<version>2.3</version>
+			</plugin>
+
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-surefire-report-plugin</artifactId>
+				<version>2.6</version>
+				<configuration>
+					<showSuccess>true</showSuccess>
+					<aggregate>true</aggregate>
+					<outputDirectory>${project.reporting.outputDirectory}/surefire-report</outputDirectory>
+				</configuration>
+				<reportSets>
+					<reportSet>
+						<id />
+					</reportSet>
+				</reportSets>
+			</plugin>
+
+			<plugin>
+				<groupId>org.codehaus.mojo</groupId>
+				<artifactId>findbugs-maven-plugin</artifactId>
+				<version>2.0.1</version>
+				<configuration>
+					<excludeFilterFile>findbugs-exclude.xml</excludeFilterFile>
+				</configuration>
+			</plugin>
+		</plugins>
+	</reporting>
 
 </project>

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=1401751&r1=1401750&r2=1401751&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 Wed Oct 24 16:07:13 2012
@@ -25,7 +25,6 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
-import org.apache.padaf.xmpbox.parser.CreateXMPMetadataException;
 import org.apache.padaf.xmpbox.schema.AdobePDFSchema;
 import org.apache.padaf.xmpbox.schema.DublinCoreSchema;
 import org.apache.padaf.xmpbox.schema.PDFAExtensionSchema;
@@ -212,6 +211,7 @@ public class XMPMetadata {
 		return null;
 	}
 
+	
 	public XMPSchema getSchema (Class<? extends XMPSchema> clz) {
 		StructuredType st = clz.getAnnotation(StructuredType.class);
 		return getSchema(st.namespace());

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=1401751&r1=1401750&r2=1401751&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 Wed Oct 24 16:07:13 2012
@@ -33,6 +33,10 @@ public final class XmpConstants {
 	public static final String DEFAULT_XPACKET_BYTES = null;
 	
 	public static final String DEFAULT_XPACKET_END = "w";
+	
+	public static final String DEFAULT_RDF_PREFIX = "rdf";
+
+	public static final String DEFAULT_RDF_LOCAL_NAME = "RDF";
 
 	private XmpConstants () {
 		// hide constructor

Modified: pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/schema/AdobePDFSchema.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/schema/AdobePDFSchema.java?rev=1401751&r1=1401750&r2=1401751&view=diff
==============================================================================
--- pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/schema/AdobePDFSchema.java (original)
+++ pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/schema/AdobePDFSchema.java Wed Oct 24 16:07:13 2012
@@ -141,10 +141,8 @@ public class AdobePDFSchema extends XMPS
 	 */
 	public TextType getKeywordsProperty() {
 		AbstractField tmp = getProperty(KEYWORDS);
-		if (tmp != null) {
-			if (tmp instanceof TextType) {
-				return (TextType) tmp;
-			}
+		if (tmp instanceof TextType) {
+			return (TextType) tmp;
 		}
 		return null;
 	}
@@ -156,10 +154,8 @@ public class AdobePDFSchema extends XMPS
 	 */
 	public String getKeywords() {
 		AbstractField tmp = getProperty(KEYWORDS);
-		if (tmp != null) {
-			if (tmp instanceof TextType) {
-				return ((TextType) tmp).getStringValue();
-			}
+		if (tmp instanceof TextType) {
+			return ((TextType) tmp).getStringValue();
 		}
 		return null;
 	}
@@ -171,10 +167,8 @@ public class AdobePDFSchema extends XMPS
 	 */
 	public TextType getPDFVersionProperty() {
 		AbstractField tmp = getProperty(PDF_VERSION);
-		if (tmp != null) {
-			if (tmp instanceof TextType) {
-				return (TextType) tmp;
-			}
+		if (tmp instanceof TextType) {
+			return (TextType) tmp;
 		}
 		return null;
 	}
@@ -186,10 +180,8 @@ public class AdobePDFSchema extends XMPS
 	 */
 	public String getPDFVersion() {
 		AbstractField tmp = getProperty(PDF_VERSION);
-		if (tmp != null) {
-			if (tmp instanceof TextType) {
-				return ((TextType) tmp).getStringValue();
-			}
+		if (tmp instanceof TextType) {
+			return ((TextType) tmp).getStringValue();
 		}
 		return null;
 	}
@@ -201,10 +193,8 @@ public class AdobePDFSchema extends XMPS
 	 */
 	public TextType getProducerProperty() {
 		AbstractField tmp = getProperty(PRODUCER);
-		if (tmp != null) {
-			if (tmp instanceof TextType) {
-				return (TextType) tmp;
-			}
+		if (tmp instanceof TextType) {
+			return (TextType) tmp;
 		}
 		return null;
 	}
@@ -216,10 +206,8 @@ public class AdobePDFSchema extends XMPS
 	 */
 	public String getProducer() {
 		AbstractField tmp = getProperty(PRODUCER);
-		if (tmp != null) {
-			if (tmp instanceof TextType) {
-				return ((TextType) tmp).getStringValue();
-			}
+		if (tmp instanceof TextType) {
+			return ((TextType) tmp).getStringValue();
 		}
 		return null;
 	}

Modified: pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/schema/PDFAIdentificationSchema.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/schema/PDFAIdentificationSchema.java?rev=1401751&r1=1401750&r2=1401751&view=diff
==============================================================================
--- pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/schema/PDFAIdentificationSchema.java (original)
+++ pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/schema/PDFAIdentificationSchema.java Wed Oct 24 16:07:13 2012
@@ -178,11 +178,8 @@ public class PDFAIdentificationSchema ex
 	 */
 	public Integer getPart() {
 		AbstractField tmp = getPartProperty();
-		if (tmp != null) {
-			if (tmp instanceof IntegerType) {
-				return ((IntegerType) tmp).getValue();
-			}
-			return null;
+		if (tmp instanceof IntegerType) {
+			return ((IntegerType) tmp).getValue();
 		} else {
 			for (Attribute attribute : getAllAttributes()) {
 				if (attribute.getName().equals(PART)) {
@@ -190,7 +187,6 @@ public class PDFAIdentificationSchema ex
 				}
 			}
 			return null;
-			
 		}
 	}
 
@@ -201,10 +197,8 @@ public class PDFAIdentificationSchema ex
 	 */
 	public IntegerType getPartProperty() {
 		AbstractField tmp = getProperty(PART);
-		if (tmp != null) {
-			if (tmp instanceof IntegerType) {
-				return (IntegerType) tmp;
-			}
+		if (tmp instanceof IntegerType) {
+			return (IntegerType) tmp;
 		}
 		return null;
 	}
@@ -216,10 +210,8 @@ public class PDFAIdentificationSchema ex
 	 */
 	public String getAmendment() {
 		AbstractField tmp = getProperty(AMD);
-		if (tmp != null) {
-			if (tmp instanceof TextType) {
-				return ((TextType) tmp).getStringValue();
-			}
+		if (tmp instanceof TextType) {
+			return ((TextType) tmp).getStringValue();
 		}
 		return null;
 	}
@@ -231,10 +223,8 @@ public class PDFAIdentificationSchema ex
 	 */
 	public TextType getAmdProperty() {
 		AbstractField tmp = getProperty(AMD);
-		if (tmp != null) {
-			if (tmp instanceof TextType) {
-				return (TextType) tmp;
-			}
+		if (tmp instanceof TextType) {
+			return (TextType) tmp;
 		}
 		return null;
 	}
@@ -265,10 +255,8 @@ public class PDFAIdentificationSchema ex
 	 */
 	public TextType getConformanceProperty() {
 		AbstractField tmp = getProperty(CONFORMANCE);
-		if (tmp != null) {
-			if (tmp instanceof TextType) {
-				return (TextType) tmp;
-			}
+		if (tmp instanceof TextType) {
+			return (TextType) tmp;
 		}
 		return null;
 	}

Modified: pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/schema/XMPBasicJobTicketSchema.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/schema/XMPBasicJobTicketSchema.java?rev=1401751&r1=1401750&r2=1401751&view=diff
==============================================================================
--- pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/schema/XMPBasicJobTicketSchema.java (original)
+++ pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/schema/XMPBasicJobTicketSchema.java Wed Oct 24 16:07:13 2012
@@ -47,9 +47,6 @@ public class XMPBasicJobTicketSchema ext
 
     public XMPBasicJobTicketSchema(XMPMetadata metadata, String ownPrefix) {
         super(metadata, ownPrefix);
-        // TODO why add this ns ?
-        StructuredType st = JobType.class.getAnnotation(StructuredType.class);
-        addNamespace(st.namespace(), st.preferedPrefix());
     }
 
     public void addJob(String id , String name, String url) {
@@ -65,6 +62,14 @@ public class XMPBasicJobTicketSchema ext
     }
 
     public void addJob (JobType job) {
+    	String prefix = getNamespacePrefix(job.getNamespace());
+    	if (prefix!=null) {
+    		// use same prefix for all jobs
+    		job.setPrefix(prefix);
+    	} else {
+    		// add prefix
+    		addNamespace(job.getNamespace(), job.getPrefix());
+    	}
     	// create bag if not existing
         if (bagJobs == null) {
             bagJobs = createArrayProperty(JOB_REF, ArrayProperty.UNORDERED_ARRAY);

Modified: pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/schema/XMPMediaManagementSchema.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/schema/XMPMediaManagementSchema.java?rev=1401751&r1=1401750&r2=1401751&view=diff
==============================================================================
--- pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/schema/XMPMediaManagementSchema.java (original)
+++ pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/schema/XMPMediaManagementSchema.java Wed Oct 24 16:07:13 2012
@@ -429,7 +429,7 @@ public class XMPMediaManagementSchema ex
 	 *            OriginalDocumentId value to set
 	 */
 	public void setOriginalDocumentID(String url) {
-		URIType tt = (URIType)instanciateSimple(ORIGINALDOCUMENTID, url);
+		TextType tt = (TextType)instanciateSimple(ORIGINALDOCUMENTID, url);
 		setOriginalDocumentIDProperty(tt);
 	}
 
@@ -439,7 +439,7 @@ public class XMPMediaManagementSchema ex
 	 * @param tt
 	 *            OriginalDocumentId property to set
 	 */
-	public void setOriginalDocumentIDProperty(URIType tt) {
+	public void setOriginalDocumentIDProperty(TextType tt) {
 		addProperty(tt);
 	}
 
@@ -606,16 +606,11 @@ public class XMPMediaManagementSchema ex
 	@PropertyType(propertyType = "seq Version")
 	public static final String VERSIONS = "Versions";
 
-	/**
-	 * Add a version value
-	 * 
-	 * @param version
-	 *            version value to set
-	 */
-	public void addVersions(VersionType version) {
-		addUnqualifiedSequenceValue(VERSIONS, version);
-	}
 
+	public void addVersions(String value) {
+		addQualifiedBagValue(VERSIONS, value);
+	}
+	
 	/**
 	 * Get Versions property
 	 * 
@@ -625,6 +620,11 @@ public class XMPMediaManagementSchema ex
 		return (ArrayProperty) getProperty(VERSIONS);
 	}
 
+	public List<String> getVersions() {
+		return getUnqualifiedBagValueList(VERSIONS);
+	}
+
+	
 	// --------------------------------------- History
 	// ----------------------------
 

Modified: pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/schema/XMPRightsManagementSchema.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/schema/XMPRightsManagementSchema.java?rev=1401751&r1=1401750&r2=1401751&view=diff
==============================================================================
--- pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/schema/XMPRightsManagementSchema.java (original)
+++ pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/schema/XMPRightsManagementSchema.java Wed Oct 24 16:07:13 2012
@@ -259,7 +259,7 @@ public class XMPRightsManagementSchema e
 	 * @param url
 	 *            WebStatemen url property to set
 	 */
-	public void setWebStatementProperty(TextType url) {
+	public void setWebStatementProperty(URLType url) {
 		addProperty(url);
 	}
 
@@ -344,7 +344,7 @@ public class XMPRightsManagementSchema e
 	 * @param url
 	 *            certificate url property to set
 	 */
-	public void setCertificateProperty(TextType url) {
+	public void setCertificateProperty(URLType url) {
 		addProperty(url);
 	}
 }

Modified: pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/schema/XMPSchema.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/schema/XMPSchema.java?rev=1401751&r1=1401750&r2=1401751&view=diff
==============================================================================
--- pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/schema/XMPSchema.java (original)
+++ pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/schema/XMPSchema.java Wed Oct 24 16:07:13 2012
@@ -66,19 +66,22 @@ public class XMPSchema extends AbstractS
 	 *            The URI of the namespace, ie "http://ns.adobe.com/pdf/1.3/"
 	 * 
 	 */
-	public XMPSchema(XMPMetadata metadata, String namespaceURI, String prefix) {
-		super(metadata, namespaceURI, prefix);
+	public XMPSchema(XMPMetadata metadata, String namespaceURI, String prefix, String name) {
+		super(metadata, namespaceURI, prefix,name);
 		addNamespace(getNamespace(), getPrefix());
 	}
 
 	public XMPSchema(XMPMetadata metadata) {
-		this(metadata, null, null);
+		this(metadata, null, null,null);
 	}
 
 	public XMPSchema(XMPMetadata metadata, String prefix) {
-		this(metadata, null, prefix);
+		this(metadata, null, prefix,null);
 	}
 
+	public XMPSchema(XMPMetadata metadata, String namespaceURI, String prefix) {
+		this(metadata, namespaceURI, prefix,null);
+	}
 	
 	/**
 	 * Retrieve a generic simple type property
@@ -1077,7 +1080,6 @@ public class XMPSchema extends AbstractS
 	 */
 	public List<String> getUnqualifiedLanguagePropertyLanguagesValue(String name) {
 		List<String> retval = new ArrayList<String>();
-
 		AbstractField property = getAbstractProperty(name);
 		if (property != null) {
 			if (property instanceof ArrayProperty) {

Modified: pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/AbstractComplexProperty.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/AbstractComplexProperty.java?rev=1401751&r1=1401750&r2=1401751&view=diff
==============================================================================
--- pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/AbstractComplexProperty.java (original)
+++ pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/AbstractComplexProperty.java Wed Oct 24 16:07:13 2012
@@ -43,7 +43,7 @@ public abstract class AbstractComplexPro
 	public void addNamespace (String namespace, String prefix) {
 		this.namespaceToPrefix.put(namespace, prefix);
 	}
-	
+		
 	public String getNamespacePrefix (String namespace) {
 		return this.namespaceToPrefix.get(namespace);
 	}

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=1401751&r1=1401750&r2=1401751&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 Wed Oct 24 16:07:13 2012
@@ -72,10 +72,14 @@ public abstract class AbstractField {
 	 * 
 	 * @return the local Name
 	 */
-	public String getPropertyName() {
+	public final String getPropertyName() {
 		return propertyName;
 	}
 
+	public final void setPropertyName (String value) {
+		this.propertyName = value;
+	}
+	
 	/**
 	 * Set a new attribute for this entity
 	 * 
@@ -83,10 +87,6 @@ public abstract class AbstractField {
 	 *            The Attribute property to add
 	 */
 	public final void setAttribute(Attribute value) {
-		// TODO remove when test are OK
-		if (XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(value.getNamespace())) {
-			throw new Error ("Should not call setAttribute for this "+value.getValue());
-		}
 		if (attributes.containsKey(value.getName())) {
 			// if same name in element, attribute will be replaced
 			attributes.remove(value.getName());

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=1401751&r1=1401750&r2=1401751&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 Wed Oct 24 16:07:13 2012
@@ -37,16 +37,25 @@ public abstract class AbstractStructured
 	private String prefix;
 
 	public AbstractStructuredType(XMPMetadata metadata) {
-		this(metadata,null,null);
+		this(metadata,null,null,null);
 	}
 
 	public AbstractStructuredType(XMPMetadata metadata, String namespaceURI) {
-		this(metadata,namespaceURI,null);
+		this(metadata, namespaceURI,null,null);
+		StructuredType st = this.getClass().getAnnotation(StructuredType.class);
+		if (st!=null) {
+			// init with annotation
+			this.namespace = st.namespace();
+			this.preferedPrefix = st.preferedPrefix();
+		} else {
+			throw new IllegalArgumentException(" StructuredType annotation cannot be null");
+		}
+		this.prefix = this.preferedPrefix;
 	}
 	
 	public AbstractStructuredType(XMPMetadata metadata, String namespaceURI,
-			String fieldPrefix) {
-		super(metadata, STRUCTURE_ARRAY_NAME);
+			String fieldPrefix, String propertyName) {
+		super(metadata, propertyName);
 		StructuredType st = this.getClass().getAnnotation(StructuredType.class);
 		if (st!=null) {
 			// init with annotation
@@ -73,6 +82,10 @@ public abstract class AbstractStructured
 		return namespace;
 	}
 
+	public final void setNamespace (String ns) {
+		this.namespace = ns;
+	}
+	
 	/**
 	 * Get the prefix of this entity
 	 * 
@@ -82,6 +95,10 @@ public abstract class AbstractStructured
 		return prefix;
 	}
 
+	public final void setPrefix (String pf) {
+		this.prefix = pf;
+	}
+	
 	public final String getPreferedPrefix() {
 		return prefix;
 	}

Modified: pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/ComplexPropertyContainer.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/ComplexPropertyContainer.java?rev=1401751&r1=1401750&r2=1401751&view=diff
==============================================================================
--- pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/ComplexPropertyContainer.java (original)
+++ pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/ComplexPropertyContainer.java Wed Oct 24 16:07:13 2012
@@ -200,9 +200,17 @@ public class ComplexPropertyContainer /*
 	 * @return True if these properties are equals
 	 */
 	public boolean isSameProperty(AbstractField prop1, AbstractField prop2) {
-		if (prop1.getClass().equals(prop2.getClass())
-				&& prop1.getPropertyName().equals(prop2.getPropertyName())) {
-			return prop1.equals(prop2);
+
+		if (prop1.getClass().equals(prop2.getClass())) {
+			String pn1 = prop1.getPropertyName();
+			String pn2 = prop2.getPropertyName();
+			if (pn1==null) {
+				return pn2==null;
+			} else {
+				if (pn1.equals(pn2)) {
+					return prop1.equals(prop2);
+				}
+			}
 		}
 		return false;
 	}

Modified: pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/DefinedStructuredType.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/DefinedStructuredType.java?rev=1401751&r1=1401750&r2=1401751&view=diff
==============================================================================
--- pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/DefinedStructuredType.java (original)
+++ pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/DefinedStructuredType.java Wed Oct 24 16:07:13 2012
@@ -31,16 +31,22 @@ public class DefinedStructuredType exten
 	private Map<String, String> definedProperties = null;
 	
 	public DefinedStructuredType(XMPMetadata metadata, String namespaceURI,
-			String fieldPrefix) {
-		super(metadata, namespaceURI, fieldPrefix);
+			String fieldPrefix, String propertyName) {
+		super(metadata, namespaceURI, fieldPrefix, propertyName);
 		this.definedProperties = new HashMap<String, String>();
 	}
 
+	public DefinedStructuredType(XMPMetadata metadata) {
+		super(metadata);
+		this.definedProperties = new HashMap<String, String>();
+	}
+
+	
 	public void addProperty (String name, String type) {
 		definedProperties.put(name, type);
 	}
 
-	protected Map<String, String> getDefinedProperties() {
+	public Map<String, String> getDefinedProperties() {
 		return definedProperties;
 	}
 

Modified: pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/PropMapping.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/PropMapping.java?rev=1401751&r1=1401750&r2=1401751&view=diff
==============================================================================
--- pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/PropMapping.java (original)
+++ pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/PropMapping.java Wed Oct 24 16:07:13 2012
@@ -95,6 +95,7 @@ public class PropMapping {
 	 * @return Type of property or null
 	 */
 	public String getPropertyType(String name) {
+//		System.err.println("## >> getPropertyType in "+namespace+" >> "+name);
 		return types.get(name);
 	}
 

Modified: pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/ReflectHelper.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/ReflectHelper.java?rev=1401751&r1=1401750&r2=1401751&view=diff
==============================================================================
--- pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/ReflectHelper.java (original)
+++ pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/ReflectHelper.java Wed Oct 24 16:07:13 2012
@@ -23,9 +23,6 @@ package org.apache.padaf.xmpbox.type;
 
 import java.lang.reflect.Field;
 
-import org.apache.padaf.xmpbox.schema.XmpSchemaException;
-
-
 public final class ReflectHelper {
 
 	private ReflectHelper () {

Modified: pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/TypeDescription.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/TypeDescription.java?rev=1401751&r1=1401750&r2=1401751&view=diff
==============================================================================
--- pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/TypeDescription.java (original)
+++ pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/TypeDescription.java Wed Oct 24 16:07:13 2012
@@ -58,7 +58,7 @@ public class TypeDescription<T> {
 		return properties;
 	}
 
-	protected void setProperties(PropMapping properties) {
+	public void setProperties(PropMapping properties) {
 		this.properties = properties;
 	}
 		

Modified: pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/TypeMapping.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/TypeMapping.java?rev=1401751&r1=1401750&r2=1401751&view=diff
==============================================================================
--- pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/TypeMapping.java (original)
+++ pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/TypeMapping.java Wed Oct 24 16:07:13 2012
@@ -26,7 +26,6 @@ import java.lang.reflect.InvocationTarge
 import java.util.Calendar;
 import java.util.HashMap;
 import java.util.Map;
-import java.util.Map.Entry;
 
 import javax.xml.namespace.QName;
 
@@ -49,19 +48,19 @@ public final class TypeMapping {
 
 
 
-	private Map<String,TypeDescription<AbstractSimpleProperty>> BASIC_TYPES;
+	private Map<String,TypeDescription<AbstractSimpleProperty>> basicTypes;
 
-	private Map<Class<? extends AbstractField>,TypeDescription<AbstractSimpleProperty>> BASIC_CLASSES;
+	private Map<Class<? extends AbstractField>,TypeDescription<AbstractSimpleProperty>> basicClasses;
 
-	private Map<String,TypeDescription<AbstractSimpleProperty>> DERIVED_TYPES;
+	private Map<String,TypeDescription<AbstractSimpleProperty>> derivedTypes;
 
-	private Map<Class<? extends AbstractField>,TypeDescription<AbstractSimpleProperty>> DERIVED_CLASSES;
+	private Map<Class<? extends AbstractField>,TypeDescription<AbstractSimpleProperty>> derivedClasses;
 
-	private Map<String, TypeDescription<AbstractStructuredType>> STRUCTURED_TYPES;
+	private Map<String, TypeDescription<AbstractStructuredType>> structuredTypes;
 
-	private Map<Class<? extends AbstractField>,TypeDescription<AbstractStructuredType>> STRUCTURED_CLASSES;
+	private Map<Class<? extends AbstractField>,TypeDescription<AbstractStructuredType>> structuredClasses;
 
-	private Map<String,TypeDescription<AbstractStructuredType>> STRUCTURED_NAMESPACES;
+	private Map<String,TypeDescription<AbstractStructuredType>> structuredNamespaces;
 
 	private Map<String, String> schemaUriToPrefered;
 
@@ -86,8 +85,8 @@ public final class TypeMapping {
 
 	private void initialize () {
 		// basic
-		BASIC_TYPES = new HashMap<String,TypeDescription<AbstractSimpleProperty>>();
-		BASIC_CLASSES = new HashMap<Class<? extends AbstractField>, TypeDescription<AbstractSimpleProperty>>();
+		basicTypes = new HashMap<String,TypeDescription<AbstractSimpleProperty>>();
+		basicClasses = new HashMap<Class<? extends AbstractField>, TypeDescription<AbstractSimpleProperty>>();
 		addToBasicMaps(new TypeDescription<AbstractSimpleProperty>("Text",BasicType.Text,TextType.class));
 		addToBasicMaps(new TypeDescription<AbstractSimpleProperty>("Date",BasicType.Date,DateType.class));
 		addToBasicMaps(new TypeDescription<AbstractSimpleProperty>("Boolean",BasicType.Boolean,BooleanType.class));
@@ -95,8 +94,8 @@ public final class TypeMapping {
 		addToBasicMaps(new TypeDescription<AbstractSimpleProperty>("Real",BasicType.Real,RealType.class));
 
 		// derived
-		DERIVED_TYPES = new HashMap<String,TypeDescription<AbstractSimpleProperty>>();
-		DERIVED_CLASSES = new HashMap<Class<? extends AbstractField>, TypeDescription<AbstractSimpleProperty>>();
+		derivedTypes = new HashMap<String,TypeDescription<AbstractSimpleProperty>>();
+		derivedClasses = new HashMap<Class<? extends AbstractField>, TypeDescription<AbstractSimpleProperty>>();
 		addToDerivedMaps(new TypeDescription<AbstractSimpleProperty>("AgentName",BasicType.Text,AgentNameType.class));
 		addToDerivedMaps(new TypeDescription<AbstractSimpleProperty>("Choice",BasicType.Text,ChoiceType.class));
 		addToDerivedMaps(new TypeDescription<AbstractSimpleProperty>("GUID",BasicType.Text,GUIDType.class));
@@ -111,9 +110,9 @@ public final class TypeMapping {
 		addToDerivedMaps(new TypeDescription<AbstractSimpleProperty>("Part",BasicType.Text,PartType.class));
 
 		// structured types
-		STRUCTURED_TYPES = new HashMap<String, TypeDescription<AbstractStructuredType>>();
-		STRUCTURED_CLASSES = new HashMap<Class<? extends AbstractField>, TypeDescription<AbstractStructuredType>>();
-		STRUCTURED_NAMESPACES = new HashMap<String, TypeDescription<AbstractStructuredType>>();
+		structuredTypes = new HashMap<String, TypeDescription<AbstractStructuredType>>();
+		structuredClasses = new HashMap<Class<? extends AbstractField>, TypeDescription<AbstractStructuredType>>();
+		structuredNamespaces = new HashMap<String, TypeDescription<AbstractStructuredType>>();
 		addToStructuredMaps(new TypeDescription<AbstractStructuredType>("Thumbnail",null,ThumbnailType.class));
 		addToStructuredMaps(new TypeDescription<AbstractStructuredType>("Layer",null,LayerType.class));
 		addToStructuredMaps(new TypeDescription<AbstractStructuredType>("ResourceEvent",null,ResourceEventType.class));
@@ -142,104 +141,77 @@ public final class TypeMapping {
 	}
 
 	private void addToBasicMaps (TypeDescription<AbstractSimpleProperty> td) {
-		BASIC_TYPES.put(td.getType(),td);
-		BASIC_CLASSES.put(td.getTypeClass(), td);
+		basicTypes.put(td.getType(),td);
+		basicClasses.put(td.getTypeClass(), td);
 	}
 
 	public void addToDerivedMaps (TypeDescription<AbstractSimpleProperty> td) {
-		DERIVED_TYPES.put(td.getType(),td);
-		DERIVED_CLASSES.put(td.getTypeClass(), td);
+		derivedTypes.put(td.getType(),td);
+		derivedClasses.put(td.getTypeClass(), td);
 	}
 
 	private void addToStructuredMaps (TypeDescription<AbstractStructuredType> td) {
 		Class<? extends AbstractStructuredType> clz = td.getTypeClass();
 		StructuredType st = clz.getAnnotation(StructuredType.class);
-		if (st==null) {
-			System.err.println(">> "+clz);
-		}
 		String ns = st.namespace();
-//		if (clz!=null) {
-			PropMapping pm = ReflectHelper.initializePropMapping(ns, clz);
-			td.setProperties(pm);
-//		} else {
-//			PropMapping pm = initializePropMapping(ns, null);
-//			td.setProperties(pm);
-//		}
+		PropMapping pm = ReflectHelper.initializePropMapping(ns, clz);
+		td.setProperties(pm);
 		addToStructuredMaps(td, ns);
 	}
 
 	public void addToStructuredMaps (TypeDescription<AbstractStructuredType> td, String ns) {
-		STRUCTURED_TYPES.put(td.getType(),td);
-		STRUCTURED_CLASSES.put(td.getTypeClass(), td);
-		STRUCTURED_NAMESPACES.put(ns, td);
+		structuredTypes.put(td.getType(),td);
+		structuredClasses.put(td.getTypeClass(), td);
+		structuredNamespaces.put(ns, td);
 	}
 
 
 	public String getType (Class<?> clz) {
 		// search in basic
-		TypeDescription<AbstractSimpleProperty> td = BASIC_CLASSES.get(clz);
+		TypeDescription<AbstractSimpleProperty> td = basicClasses.get(clz);
 		// search in derived
 		if (td==null) {
-			td = DERIVED_CLASSES.get(clz);
+			td = derivedClasses.get(clz);
 		}
 		// return simple
 		if (td!=null) {
 			return td.getType();
 		} else {
 			// search in structured
-			TypeDescription<AbstractStructuredType> td2 = STRUCTURED_CLASSES.get(clz);
+			TypeDescription<AbstractStructuredType> td2 = structuredClasses.get(clz);
 			// return type if exists
 			return (td2!=null)?td2.getType():null;
 		}
 	}
 
-	/**
-	 * Return the type description linked the specified paramater. If the type
-	 * parameter is an array, the TypeDescription of the elements of the array
-	 * will be returned
-	 * 
-	 * @param type
-	 * @return
-	 */
-	public TypeDescription<?> getTypeDescription (String type) {
-		if (BASIC_TYPES.containsKey(type)) {
-			return BASIC_TYPES.get(type);
-		} else if (DERIVED_TYPES.containsKey(type)) {
-			return DERIVED_TYPES.get(type);
-		} else if (STRUCTURED_TYPES.containsKey(type)) { 
-			return STRUCTURED_TYPES.get(type);
-		} else {
-			int pos = type.indexOf(' ');
-			if (pos>0) {
-				return getTypeDescription(type.substring(pos+1));
-			} else {
-				// unknown type
-				return null;
-			}
-		}
-	}
-
-	// TODO ces deux methodes doivent remplacer la précédente
 	public TypeDescription<AbstractSimpleProperty> getSimpleDescription (String type) {
-		if (BASIC_TYPES.containsKey(type)) {
-			return BASIC_TYPES.get(type);
-		} else if (DERIVED_TYPES.containsKey(type)) {
-			return DERIVED_TYPES.get(type);
+		if (basicTypes.containsKey(type)) {
+			return basicTypes.get(type);
+		} else if (derivedTypes.containsKey(type)) {
+			return derivedTypes.get(type);
 		} else {
 			return null;
 		}
 	}
 
 	public TypeDescription<AbstractStructuredType> getStructuredDescription (String type) {
-		return STRUCTURED_TYPES.get(type);
+		return structuredTypes.get(type);
 	}
 
 
-	public AbstractStructuredType instanciateStructuredType (TypeDescription<AbstractStructuredType> td) throws BadFieldValueException {
+	public AbstractStructuredType instanciateStructuredType (TypeDescription<AbstractStructuredType> td, String propertyName) throws BadFieldValueException {
 		try {
 			Class<? extends AbstractStructuredType> propertyTypeClass = td.getTypeClass();
-			Constructor<? extends AbstractStructuredType> construct = propertyTypeClass.getConstructor(new Class<?> [] {XMPMetadata.class});
-			return construct.newInstance(metadata);
+			if (propertyTypeClass.equals(DefinedStructuredType.class)) {
+				PropMapping pm = td.getProperties();
+				return new DefinedStructuredType(metadata, pm.getConcernedNamespace(), null, propertyName);
+			} else {
+				Constructor<? extends AbstractStructuredType> construct = propertyTypeClass.getConstructor(new Class<?> [] {
+						XMPMetadata.class});
+				AbstractStructuredType tmp = construct.newInstance(metadata);
+				tmp.setPropertyName(propertyName);
+				return tmp;
+			}
 		} catch (InvocationTargetException e) {
 			throw new BadFieldValueException("Failed to instanciate structured type : "+td.getType(),e);
 		} catch (IllegalArgumentException e) {
@@ -291,7 +263,7 @@ public final class TypeMapping {
 		PropMapping pm = ReflectHelper.initializePropMapping(null, clz);
 		String simpleType = pm.getPropertyType(propertyName);
 		if (isArrayOfSimpleType(simpleType)) {
-			simpleType = simpleType.substring(simpleType.indexOf(" ")+1);
+			simpleType = simpleType.substring(simpleType.indexOf(' ')+1);
 			return instanciateSimpleProperty(nsuri, prefix, propertyName, value, simpleType);
 		} else {
 			return instanciateSimpleProperty(nsuri, prefix, propertyName, value, simpleType);
@@ -299,7 +271,7 @@ public final class TypeMapping {
 	}
 
 	public TypeDescription<AbstractStructuredType> getStructuredTypeName (String namespace) {
-		return STRUCTURED_NAMESPACES.get(namespace);
+		return structuredNamespaces.get(namespace);
 	}
 
 	/**
@@ -311,7 +283,7 @@ public final class TypeMapping {
 	 * @return True if namespace URI is a reference for a complex basic type
 	 */
 	public boolean isStructuredTypeNamespace(String namespace) {
-		return STRUCTURED_NAMESPACES.containsKey(namespace);
+		return structuredNamespaces.containsKey(namespace);
 	}
 
 
@@ -324,9 +296,14 @@ public final class TypeMapping {
 			String second = type.substring(pos+1);
 			return isSimpleType(second);
 		}
+	}
 
+	public boolean isArrayType (String type) {
+		int pos = type.indexOf(' ');
+		return pos>=0;
 	}
 
+	
 	public String  getArrayType (String type) {
 		int pos = type.indexOf(' ');
 		if (pos<0) {
@@ -347,12 +324,22 @@ public final class TypeMapping {
 		}
 	}
 
+	public String getTypeInArray (String type) {
+		int pos = type.indexOf(' ');
+		if (pos<0) {
+			// not array
+			return null;
+		} else {
+			return type.substring(pos+1);
+		}
+	}
+	
 	public boolean isSimpleType(String type) {
-		return (BASIC_TYPES.containsKey(type) || DERIVED_TYPES.containsKey(type));
+		return (basicTypes.containsKey(type) || derivedTypes.containsKey(type));
 	}
 
 	public boolean isStructuredType(String type) {
-		return STRUCTURED_TYPES.containsKey(type);
+		return structuredTypes.containsKey(type);
 	}
 
 //	private static PropMapping initializePropMapping(String ns,
@@ -411,35 +398,32 @@ public final class TypeMapping {
 	 *            The namespace URI checked
 	 * @return True if namespace URI is known
 	 */
-	public boolean isContainedNamespace(String namespace) {
-		boolean found = schemaMap.containsKey(namespace);
-		if (!found) {
-			found = isStructuredTypeNamespace(namespace);
-		}
-		return found;
+	public boolean isDefinedSchema(String namespace) {
+		return schemaMap.containsKey(namespace);
 	}
 
 	/**
 	 * Give type of specified property in specified schema (given by its
 	 * namespaceURI)
 	 * 
-	 * @param namespace
-	 *            The namespaceURI to explore
 	 * @param prop
 	 *            the property Qualified Name
 	 * @return Property type declared for namespace specified, null if unknown
 	 */
-	public String getSpecifiedPropertyType(String namespace, QName prop) {
-		XMPSchemaFactory factory =getSchemaFactory(namespace);
+	public String getSpecifiedPropertyType (QName name) {
+		XMPSchemaFactory factory =getSchemaFactory(name.getNamespaceURI());
+		String result;
 		if (factory!=null) {
 			// found in schema
-			return factory.getPropertyType(prop.getLocalPart());
+			result =  factory.getPropertyType(name.getLocalPart());
 		} else {
-			TypeDescription<AbstractStructuredType> td = getStructuredTypeName(prop.getPrefix());
-			return td==null?null:td.getType();
+			TypeDescription<AbstractStructuredType> td = getStructuredTypeName(name.getNamespaceURI());
+			result =  td==null?null:td.getType();
 		}
-	}
+		return result;
 
+	}
+	
 	public BooleanType createBoolean (String namespaceURI, String prefix,
 			String propertyName, boolean value) {
 		return new BooleanType(metadata, namespaceURI, prefix,propertyName, value);
@@ -524,4 +508,5 @@ public final class TypeMapping {
 		return new ArrayProperty(metadata, namespace, prefix, propertyName, type);
 	}
 
+		
 }

Added: pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/xml/DomHelper.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/xml/DomHelper.java?rev=1401751&view=auto
==============================================================================
--- pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/xml/DomHelper.java (added)
+++ pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/xml/DomHelper.java Wed Oct 24 16:07:13 2012
@@ -0,0 +1,75 @@
+package org.apache.padaf.xmpbox.xml;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.namespace.QName;
+
+import org.apache.padaf.xmpbox.XmpConstants;
+import org.apache.padaf.xmpbox.xml.XmpParsingException.ErrorType;
+import org.w3c.dom.Attr;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+
+public final class DomHelper {
+
+	private DomHelper () {}
+
+	public static Element getUniqueElementChild (Element description) throws XmpParsingException {
+		NodeList nl = description.getChildNodes();
+		int pos = -1;
+		for (int i=0; i < nl.getLength(); i++) {
+			if (nl.item(i) instanceof Element) {
+				if (pos>=0) {
+					// invalid : found two child elements
+					throw new XmpParsingException(ErrorType.Undefined,"Found two child elements in "+description);
+				} else {
+					pos = i;
+				}
+			}
+		}
+		return (Element)nl.item(pos);
+	}
+
+	public static Element getFirstChildElement (Element description) throws XmpParsingException {
+		NodeList nl = description.getChildNodes();
+		for (int i=0; i < nl.getLength(); i++) {
+			if (nl.item(i) instanceof Element) {
+				return (Element)nl.item(i);
+			}
+		}
+		throw new XmpParsingException(ErrorType.Undefined,"Does not contain element");
+	}
+
+
+	public static List<Element> getElementChildren (Element description) throws XmpParsingException {
+		NodeList nl = description.getChildNodes();
+		List<Element> ret = new ArrayList<Element>(nl.getLength());
+		for (int i=0; i < nl.getLength(); i++) {
+			if (nl.item(i) instanceof Element) {
+				ret.add((Element)nl.item(i));
+			}
+		}
+		return ret;
+	}
+
+	public static QName getQName (Element element) {
+		return new QName(element.getNamespaceURI(), element.getLocalName(), element.getPrefix());
+	}
+
+	public static boolean isRdfDescription (Element element) {
+		return ("rdf".equals(element.getPrefix()) && "Description".equals(element.getLocalName()));
+	}
+
+	public static boolean isParseTypeResource (Element element) {
+		Attr parseType = element.getAttributeNodeNS(XmpConstants.RDF_NAMESPACE, "parseType");
+		if (parseType!=null && "Resource".equals(parseType.getValue())) {
+			// parseType resourc
+			return true;
+		}
+		// else
+		return false;
+	}
+
+
+}

Added: pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/xml/DomXmpParser.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/xml/DomXmpParser.java?rev=1401751&view=auto
==============================================================================
--- pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/xml/DomXmpParser.java (added)
+++ pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/xml/DomXmpParser.java Wed Oct 24 16:07:13 2012
@@ -0,0 +1,606 @@
+package org.apache.padaf.xmpbox.xml;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Stack;
+import java.util.StringTokenizer;
+
+import javax.xml.XMLConstants;
+import javax.xml.namespace.QName;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.apache.padaf.xmpbox.XMPMetadata;
+import org.apache.padaf.xmpbox.XmpConstants;
+import org.apache.padaf.xmpbox.schema.XMPSchema;
+import org.apache.padaf.xmpbox.schema.XmpSchemaException;
+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.BadFieldValueException;
+import org.apache.padaf.xmpbox.type.ComplexPropertyContainer;
+import org.apache.padaf.xmpbox.type.PropMapping;
+import org.apache.padaf.xmpbox.type.TypeDescription;
+import org.apache.padaf.xmpbox.type.TypeMapping;
+import org.apache.padaf.xmpbox.xml.XmpParsingException.ErrorType;
+import org.w3c.dom.Attr;
+import org.w3c.dom.Comment;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.w3c.dom.ProcessingInstruction;
+import org.w3c.dom.Text;
+import org.xml.sax.SAXException;
+
+public class DomXmpParser {
+
+	private DocumentBuilder dBuilder;
+
+	private NamespaceFinder nsFinder;
+
+	private boolean strictParsing = true;
+
+	public DomXmpParser () throws XmpParsingException {
+		try {
+			DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
+			dbFactory.setNamespaceAware(true);
+			dBuilder = dbFactory.newDocumentBuilder();
+			nsFinder = new NamespaceFinder();
+		} catch (ParserConfigurationException e) {
+			throw new XmpParsingException(ErrorType.Configuration,"Failed to initilalize",e);
+		}
+
+	}
+
+	public boolean isStrictParsing() {
+		return strictParsing;
+	}
+
+	public void setStrictParsing(boolean strictParsing) {
+		this.strictParsing = strictParsing;
+	}
+
+
+
+	public XMPMetadata parse(byte[] xmp) throws XmpParsingException {
+		ByteArrayInputStream input = new ByteArrayInputStream(xmp);
+		return parse(input);
+	}
+
+	public XMPMetadata parse(InputStream input ) throws XmpParsingException {
+		Document document = null;
+		try {
+			document = dBuilder.parse(input);
+		} catch (SAXException e) {
+			throw new XmpParsingException(ErrorType.Undefined,"Failed to parse", e);
+		} catch (IOException e) {
+			throw new XmpParsingException(ErrorType.Undefined,"Failed to parse", e);
+		}
+		//		document.normalizeDocument();
+		XMPMetadata xmp = null; 
+
+		// Start reading
+		removeComments(document.getFirstChild());
+		Node node = document.getFirstChild();
+
+		// expect xpacket processing instruction
+		if (!(node instanceof ProcessingInstruction)) {
+			throw new XmpParsingException(ErrorType.XpacketBadStart,"xmp should start with a processing instruction");
+		} else {
+			xmp = parseInitialXpacket((ProcessingInstruction)node);
+			node = node.getNextSibling();
+		}
+		// expect root element
+		Element root = null;
+		if (!(node instanceof Element)) {
+			throw new XmpParsingException(ErrorType.NoRootElement,"xmp should contain a root element");
+		} else {
+			// use this element as root
+			root = (Element)node;
+			node = node.getNextSibling();
+		}
+		// expect xpacket end
+		if (!(node instanceof ProcessingInstruction)) {
+			throw new XmpParsingException(ErrorType.XpacketBadEnd,"xmp should end with a processing instruction");
+		} else {
+			parseEndPacket(xmp, (ProcessingInstruction)node);
+			node = node.getNextSibling();
+		}
+		// should be null
+		if (node!=null) {
+			throw new XmpParsingException(ErrorType.XpacketBadEnd,"xmp should end after xpacket end processing instruction");
+		}
+		// xpacket is OK and the is no more nodes
+		// Now, parse the content of root
+		Element rdfRdf = findDescriptionsParent(root);
+		List<Element> descriptions = DomHelper.getElementChildren(rdfRdf);
+		List<Element> dataDescriptions = new ArrayList<Element>(descriptions.size());
+		for (Element description : descriptions) {
+			Element first = DomHelper.getFirstChildElement(description);
+			if ("pdfaExtension".equals(first.getPrefix())) {
+				PdfaExtensionHelper.validateNaming(xmp, description);
+				parseDescriptionRoot(xmp, description);
+			} else {
+				dataDescriptions.add(description);
+			}
+		}
+		// find schema description
+		PdfaExtensionHelper.populateSchemaMapping(xmp);
+		// parse data description
+		for (Element description : dataDescriptions) {
+			parseDescriptionRoot(xmp, description);
+		}
+
+
+		return xmp;
+	}
+
+	private void parseDescriptionRoot (XMPMetadata xmp, Element description) throws XmpParsingException {
+		nsFinder.push(description);
+		TypeMapping tm = xmp.getTypeMapping();
+		try {
+			List<Element> properties = DomHelper.getElementChildren(description);
+			for (Element property : properties) {
+				String prefix = property.getPrefix();
+				String name = property.getLocalName();
+				String namespace = property.getNamespaceURI();
+				String type = checkPropertyDefinition(xmp, DomHelper.getQName(property));
+				// create the container 
+				if (!tm.isDefinedSchema(namespace)) {
+					throw new XmpParsingException(ErrorType.NoSchema,"This namespace is not a schema or a structured type : "+namespace);
+				} 
+				XMPSchema schema = xmp.getSchema(namespace);
+				if (schema==null) {
+					schema = tm.getSchemaFactory(namespace).createXMPSchema(xmp, prefix);
+				}
+				ComplexPropertyContainer container = schema.getContainer();
+
+				// create property
+				nsFinder.push(property);
+				try {
+					if (type==null) {
+						if (strictParsing) {
+							throw new XmpParsingException(ErrorType.NoType, "No type defined for {"+namespace+"}"+name);
+						} else {
+							// use it as string
+							manageSimpleType (xmp, property, "Text", container);
+						}
+					} else if (type.equals("Lang Alt")) {
+						manageLangAlt (xmp, property, container);
+					} else if (tm.isSimpleType(type)) {
+						manageSimpleType (xmp, property, type, container);
+					} else if (tm.isArrayType(type)) {
+						manageArray(xmp,property,type,container);
+					} else if (tm.isStructuredType(type)) {
+						if (DomHelper.isParseTypeResource(property)) {
+							AbstractStructuredType ast = parseLiDescription(xmp, DomHelper.getQName(property), property);
+							ast.setPrefix(prefix);
+							container.addProperty(ast);
+						} else {
+							Element inner = DomHelper.getFirstChildElement(property);
+							AbstractStructuredType ast = parseLiDescription(xmp, DomHelper.getQName(property), inner);
+							ast.setPrefix(prefix);
+							container.addProperty(ast);
+						}
+					}
+				} finally {
+					nsFinder.pop();
+				}
+			}
+		} catch (BadFieldValueException e) {
+			throw new XmpParsingException(ErrorType.InvalidType, "Parsing failed", e);
+		} catch (XmpSchemaException e) {
+			throw new XmpParsingException(ErrorType.Undefined,"Parsing failed", e);
+		} finally {
+			nsFinder.pop();
+		}
+	}
+
+	private void manageSimpleType (XMPMetadata xmp, Element property, String type, ComplexPropertyContainer container) throws XmpParsingException {
+		TypeMapping tm = xmp.getTypeMapping();
+		String prefix = property.getPrefix();
+		String name = property.getLocalName();
+		String namespace = property.getNamespaceURI();
+		AbstractSimpleProperty sp = tm.instanciateSimpleProperty(
+				namespace, 
+				prefix, 
+				name, 
+				property.getTextContent(),
+				type);
+		container.addProperty(sp);
+	}
+
+	private void manageArray (XMPMetadata xmp, Element property, String type, ComplexPropertyContainer container) throws XmpParsingException, BadFieldValueException {
+		//		nsFinder.push(property);
+		try {
+			TypeMapping tm = xmp.getTypeMapping();
+			String prefix = property.getPrefix();
+			String name = property.getLocalName();
+			String namespace = property.getNamespaceURI();
+			String at = tm.getArrayType(type);
+			Element bagOrSeq = DomHelper.getUniqueElementChild(property);
+			// ensure this is the good type of array
+			if (bagOrSeq==null) {
+				// not an array
+				throw new XmpParsingException(ErrorType.Format,"Invalid array definition, expecting "+at+" and found nothing");
+			}
+			if (!bagOrSeq.getLocalName().equals(at)) {
+				// not the good array type
+				throw new XmpParsingException(ErrorType.Format,"Invalid array type, expecting "+at+" and found "+bagOrSeq.getLocalName());
+			}
+			ArrayProperty array = tm.createArrayProperty(namespace, prefix, name, at);
+			container.addProperty(array);
+			List<Element> lis=  DomHelper.getElementChildren(bagOrSeq);
+
+			for (Element element : lis) {
+				QName propertyQName = DomHelper.getQName(property);
+				AbstractField ast = parseLiElement(xmp, propertyQName, element);
+				if (ast!=null) {
+					array.addProperty(ast);
+				}
+			}
+		} finally {
+			//			nsFinder.pop();
+		}
+
+	}
+
+	private void manageLangAlt (XMPMetadata xmp, Element property, ComplexPropertyContainer container) throws XmpParsingException, BadFieldValueException {
+		manageArray(xmp,property,"Alt Lang",container);
+	}
+
+
+	private void parseDescriptionInner (XMPMetadata xmp, Element description, ComplexPropertyContainer parentContainer) throws XmpParsingException {
+		nsFinder.push(description);
+		TypeMapping tm = xmp.getTypeMapping();
+		try {
+			List<Element> properties = DomHelper.getElementChildren(description);
+			for (Element property : properties) {
+				String prefix = property.getPrefix();
+				String name = property.getLocalName();
+				String namespace = property.getNamespaceURI();
+				String dtype = checkPropertyDefinition(xmp, DomHelper.getQName(property));
+				TypeDescription<AbstractStructuredType> td = tm.getStructuredDescription(dtype);
+				String ptype = td.getProperties().getPropertyType(name);
+				// create property
+				nsFinder.push(property);
+				try {
+					if (ptype==null) {
+						if (strictParsing) {
+							throw new XmpParsingException(ErrorType.NoType, "No type defined for {"+namespace+"}"+name);
+						} else {
+							// use it as string
+							manageSimpleType (xmp, property, "Text", parentContainer);
+						}
+					} else if (ptype.equals("Lang Alt")) {
+						manageLangAlt (xmp, property, parentContainer);
+					} else if (tm.isSimpleType(ptype)) {
+						manageSimpleType (xmp, property, ptype, parentContainer);
+					} else if (tm.isArrayType(ptype)) {
+						manageArray(xmp,property,ptype,parentContainer);
+					} else if (tm.isStructuredType(ptype)) {
+						if (DomHelper.isParseTypeResource(property)) {
+							AbstractStructuredType ast = parseLiDescription(xmp, DomHelper.getQName(property), property);
+							ast.setPrefix(prefix);
+							parentContainer.addProperty(ast);
+						} else {
+							Element inner = DomHelper.getFirstChildElement(property);
+							AbstractStructuredType ast = parseLiDescription(xmp, DomHelper.getQName(property), inner);
+							ast.setPrefix(prefix);
+							parentContainer.addProperty(ast);
+						}
+					} 
+				} finally {
+					nsFinder.pop();
+				}
+			}
+		} catch (BadFieldValueException e) {
+			throw new XmpParsingException(ErrorType.InvalidType, "Parsing failed", e);
+		} finally {
+			nsFinder.pop();
+		}
+	}
+
+
+
+	private AbstractField parseLiElement (XMPMetadata xmp, QName descriptor, Element liElement) throws XmpParsingException, BadFieldValueException {
+		//		nsFinder.push(liElement);
+		try {
+			if (DomHelper.isParseTypeResource(liElement)) {
+				return parseLiDescription(xmp, descriptor,liElement);
+			} 
+			// will find rdf:Description
+			Element liChild = DomHelper.getUniqueElementChild(liElement);
+			if (liChild!=null) {
+				return parseLiDescription(xmp, descriptor, liChild);
+			} else {
+				// no child, so consider as simple text
+				String text = liElement.getTextContent();
+				TypeMapping tm = xmp.getTypeMapping();
+				AbstractSimpleProperty sp = tm.instanciateSimpleProperty(
+						descriptor.getNamespaceURI(), 
+						descriptor.getPrefix(), 
+						descriptor.getLocalPart(), 
+						text,
+						"Text");
+				return sp;
+			}
+		} finally {
+			//			nsFinder.pop();
+		}
+	}
+
+	private AbstractStructuredType parseLiDescription (XMPMetadata xmp, QName descriptor, Element liElement) throws XmpParsingException, BadFieldValueException {
+		//		nsFinder.push(liElement);
+		try {
+			TypeMapping tm = xmp.getTypeMapping();
+			List<Element> elements = DomHelper.getElementChildren(liElement);
+			if (elements.size()==0) {
+				// The list is empty
+				return null;
+			}
+			// Instantiate abstract structured type with hint from first element
+			Element first = elements.get(0);
+			String ctype = checkPropertyDefinition(xmp, DomHelper.getQName(first));
+			AbstractStructuredType ast = instanciateStructured(tm, ctype, descriptor.getLocalPart());
+			ast.setNamespace(descriptor.getNamespaceURI());
+			ast.setPrefix(descriptor.getPrefix());
+
+			TypeDescription<AbstractStructuredType> td = tm.getStructuredDescription(ctype);
+			PropMapping pm = td.getProperties();
+			for (Element element : elements) {
+				String prefix = element.getPrefix();
+				String name = element.getLocalName();
+				String namespace = element.getNamespaceURI();
+				String type = pm.getPropertyType(name);
+				if (tm.isSimpleType(type)) {
+					AbstractSimpleProperty sp = tm.instanciateSimpleProperty(
+							namespace, 
+							prefix, 
+							name, 
+							element.getTextContent(),
+							type);
+					ast.getContainer().addProperty(sp);
+				} else if (tm.isStructuredType(type)) {
+					// create a new structured type
+					AbstractStructuredType inner = instanciateStructured(tm, type, name);
+					inner.setNamespace(namespace);
+					inner.setPrefix(prefix);
+					ast.getContainer().addProperty(inner);
+					ComplexPropertyContainer cpc = inner.getContainer();
+					if (DomHelper.isParseTypeResource(element)) {
+						parseDescriptionInner(xmp, element, cpc);
+					} else {
+						Element descElement = DomHelper.getFirstChildElement(element);
+						parseDescriptionInner(xmp,descElement,cpc);
+					}
+				} else if (tm.getArrayType(type)!=null) {
+					String at = tm.getArrayType(type);
+					ArrayProperty array = tm.createArrayProperty(namespace, prefix, name, at);
+					ast.getContainer().addProperty(array);
+
+
+					Element bagOrSeq = DomHelper.getUniqueElementChild(element);
+					List<Element> lis=  DomHelper.getElementChildren(bagOrSeq);
+					for (Element element2 : lis) {
+						AbstractField ast2 = parseLiElement(xmp, descriptor, element2);
+						if (ast2!=null) {
+							array.addProperty(ast2);
+						}
+					}
+				} else {
+					throw new XmpParsingException(ErrorType.NoType, "Unidentified element to parse "+element+" (type="+type+")");
+				}
+
+			}
+			return ast;
+		} finally {
+			//			nsFinder.pop();
+		}
+	}
+
+
+	private XMPMetadata parseInitialXpacket(ProcessingInstruction pi)
+			throws XmpParsingException {
+		if (!"xpacket".equals(pi.getNodeName())) {
+			throw new XmpParsingException(ErrorType.XpacketBadStart, "Bad processing instruction name : "+pi.getNodeName());
+		}
+		String data = pi.getData();
+		StringTokenizer tokens = new StringTokenizer(data, " ");
+		String id = null;
+		String begin = null;
+		String bytes = null;
+		String encoding = null;
+		while (tokens.hasMoreTokens()) {
+			String token = tokens.nextToken();
+			if (!token.endsWith("\"") && !token.endsWith("\'")) {
+				throw new XmpParsingException(ErrorType.XpacketBadStart,
+						"Cannot understand PI data part : '" + token + "'");
+			}
+			String quote = token.substring(token.length()-1);
+			int pos = token.indexOf("="+quote);
+			if (pos <= 0) {
+				throw new XmpParsingException(ErrorType.XpacketBadStart,
+						"Cannot understand PI data part : '" + token + "'");
+			}
+			String name = token.substring(0, pos);
+			String value = token.substring(pos + 2, token.length() - 1);
+			if ("id".equals(name)) {
+				id = value;
+			} else if ("begin".equals(name)) {
+				begin = value;
+			} else if ("bytes".equals(name)) {
+				bytes = value;
+			} else if ("encoding".equals(name)) {
+				encoding = value;
+			} else {
+				throw new XmpParsingException(ErrorType.XpacketBadStart,
+						"Unknown attribute in xpacket PI : '" + token + "'");
+			}
+		}
+		return XMPMetadata.createXMPMetadata(begin, id, bytes, encoding);
+	}
+
+	private void parseEndPacket (XMPMetadata metadata, ProcessingInstruction pi) throws XmpParsingException {
+		String xpackData = pi.getData();
+		// end attribute must be present and placed in first
+		// xmp spec says Other unrecognized attributes can follow, but
+		// should be ignored
+		if (xpackData.startsWith("end=")) {
+			char end = xpackData.charAt(5);
+			// check value (5 for end='X')
+			if (end!='r' && end!='w') {
+				throw new XmpParsingException(ErrorType.XpacketBadEnd,
+						"Excepted xpacket 'end' attribute with value 'r' or 'w' ");
+			} else {
+				metadata.setEndXPacket(Character.toString(end));
+			}
+		} else {
+			// should find end='r/w'
+			throw new XmpParsingException(ErrorType.XpacketBadEnd,
+					"Excepted xpacket 'end' attribute (must be present and placed in first)");
+		}
+	}
+
+	private Element findDescriptionsParent (Element root) throws XmpParsingException {
+		// always <x:xmpmeta xmlns:x="adobe:ns:meta/">
+		expectNaming(root,"adobe:ns:meta/","x","xmpmeta");
+		// should only have one child
+		NodeList nl = root.getChildNodes();
+		if (nl.getLength()==0) {
+			// empty description 
+			throw new XmpParsingException(ErrorType.Format, "No rdf description found in xmp");
+		} else if (nl.getLength()>1) {
+			// only expect one element
+			throw new XmpParsingException(ErrorType.Format, "More than one element found in x:xmpmeta");
+		} else if (!(root.getFirstChild() instanceof Element)) {
+			// should be an element
+			throw new XmpParsingException(ErrorType.Format, "x:xmpmeta does not contains rdf:RDF element");
+		} // else let's parse
+		Element rdfRdf = (Element)root.getFirstChild();
+		// always <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
+		expectNaming(rdfRdf,XmpConstants.RDF_NAMESPACE,XmpConstants.DEFAULT_RDF_PREFIX,XmpConstants.DEFAULT_RDF_LOCAL_NAME);
+		// return description parent
+		return rdfRdf;
+	}
+
+	private void expectNaming (Element element, String ns, String prefix, String ln) throws XmpParsingException {
+		if ((ns!=null) && !(ns.equals(element.getNamespaceURI()))) {
+			throw new XmpParsingException(ErrorType.Format, "Expecting namespace '"+ns+"' and found '"+element.getNamespaceURI()+"'");
+		} else if ((prefix!=null) && !(prefix.equals(element.getPrefix()))) {
+			throw new XmpParsingException(ErrorType.Format, "Expecting prefix '"+prefix+"' and found '"+element.getPrefix()+"'");
+		} else if ((ln!=null) && !(ln.equals(element.getLocalName()))) {
+			throw new XmpParsingException(ErrorType.Format, "Expecting local name '"+ln+"' and found '"+element.getLocalName()+"'");
+		} // else OK
+	}
+
+	/**
+	 * Remove all the comments node in the parent element of the parameter
+	 * @param node the first node of an element or document to clear
+	 */
+	private void removeComments (Node root) {
+		Node node = root;
+		while (node!=null) {
+			Node next = node.getNextSibling();
+			if (node instanceof Comment) {
+				// remove the comment
+				node.getParentNode().removeChild(node);
+			} else if (node instanceof Text) {
+				Text t = (Text)node;
+				if (t.getTextContent().trim().length()==0) {
+					// XXX is there a better way to remove useless Text ?
+					node.getParentNode().removeChild(node);
+				}
+			} else if (node instanceof Element) {
+				// clean child
+				removeComments(node.getFirstChild());
+			} // else do nothing
+			node = next;
+		}
+		// end of document
+	}
+
+	private AbstractStructuredType instanciateStructured (TypeMapping tm, String type, String name) throws BadFieldValueException {
+		TypeDescription<AbstractStructuredType> td = null;
+		td = tm.getStructuredDescription(type);
+		return tm.instanciateStructuredType(td,name);
+	}
+
+	private String checkPropertyDefinition (XMPMetadata xmp, QName prop) throws XmpParsingException {
+		TypeMapping tm = xmp.getTypeMapping();
+		// test if namespace is set in xml
+		if (!nsFinder.containsNamespace(prop.getNamespaceURI())) {
+			throw new XmpParsingException(ErrorType.NoSchema, "Schema is not set in this document : "+prop.getNamespaceURI());
+		}
+		// test if namespace is defined
+		if (!tm.isDefinedSchema(prop.getNamespaceURI())) {
+			if (!tm.isStructuredTypeNamespace(prop.getNamespaceURI())) {
+				throw new XmpParsingException(ErrorType.NoSchema, "Cannot find a definition for the namespace "+prop.getNamespaceURI());
+			} // else structured exists
+		}
+		String type = xmp.getTypeMapping().getSpecifiedPropertyType(prop);
+		if (type==null) {
+			throw new XmpParsingException(ErrorType.InvalidType,"No descriptor found for "+prop);
+		}
+		return type;
+	}
+
+
+
+	protected class NamespaceFinder {
+
+		private Stack<Map<String, String>> stack = new Stack<Map<String,String>>();
+
+		protected void push (Element description) {
+			NamedNodeMap nnm = description.getAttributes();
+			Map<String, String> map = new HashMap<String, String>(nnm.getLength());
+			for (int j=0; j < nnm.getLength() ; j++) {
+				Attr no = (Attr)nnm.item(j);
+				// if ns definition add it
+				if (XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(no.getNamespaceURI())) {
+					map.put(no.getLocalName(),no.getValue());
+				}
+			}
+			stack.push(map);
+		}
+
+		protected Map<String, String> pop () {
+			return stack.pop();
+		}
+
+		protected String getNamespaceURI (String prefix) throws XmpParsingException {
+			for (int i=stack.size()-1; i>=0; i--) {
+				Map<String,String> map = stack.get(i);
+				if (map.containsKey(prefix)) {
+					// found the namespace 
+					return map.get(prefix);
+				}
+			}
+			throw new XmpParsingException (ErrorType.NoSchema, "No namespace linked with prefix '"+prefix+"'");
+		}
+
+		protected boolean containsNamespace (String namespace) {
+			for (int i=stack.size()-1; i>=0; i--) {
+				Map<String,String> map = stack.get(i);
+				if (map.containsValue(namespace)) {
+					return true;
+				}
+			}
+			// else namespace not found
+			return false;
+		}
+
+	}
+
+
+
+}

Added: pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/xml/PdfaExtensionHelper.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/xml/PdfaExtensionHelper.java?rev=1401751&view=auto
==============================================================================
--- pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/xml/PdfaExtensionHelper.java (added)
+++ pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/xml/PdfaExtensionHelper.java Wed Oct 24 16:07:13 2012
@@ -0,0 +1,173 @@
+package org.apache.padaf.xmpbox.xml;
+
+import java.util.List;
+import java.util.Map;
+
+import org.apache.padaf.xmpbox.XMPMetadata;
+import org.apache.padaf.xmpbox.schema.PDFAExtensionSchema;
+import org.apache.padaf.xmpbox.schema.XMPSchema;
+import org.apache.padaf.xmpbox.schema.XMPSchemaFactory;
+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.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.PropMapping;
+import org.apache.padaf.xmpbox.type.StructuredType;
+import org.apache.padaf.xmpbox.type.TypeDescription;
+import org.apache.padaf.xmpbox.type.TypeMapping;
+import org.apache.padaf.xmpbox.xml.XmpParsingException.ErrorType;
+import org.w3c.dom.Attr;
+import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
+
+public final class PdfaExtensionHelper {
+
+	private PdfaExtensionHelper() {}
+
+	public static void validateNaming (XMPMetadata meta, Element description) throws XmpParsingException {
+		NamedNodeMap nnm = description.getAttributes();
+		for (int i=0; i < nnm.getLength(); i++) {
+			Attr attr = (Attr)nnm.item(i);
+			checkNamespaceDeclaration(attr,PDFAExtensionSchema.class);
+			checkNamespaceDeclaration(attr,PDFAFieldType.class);
+			checkNamespaceDeclaration(attr,PDFAPropertyType.class);
+			checkNamespaceDeclaration(attr,PDFASchemaType.class);
+			checkNamespaceDeclaration(attr,PDFATypeType.class);
+		}
+	}
+
+	private static void checkNamespaceDeclaration (Attr attr, Class<? extends AbstractStructuredType> clz) throws XmpParsingException {
+		String prefix = attr.getLocalName();
+		String namespace = attr.getValue();
+		String cprefix = clz.getAnnotation(StructuredType.class).preferedPrefix();
+		String cnamespace = clz.getAnnotation(StructuredType.class).namespace();
+		// check extension 
+		if (cprefix.equals(prefix) && !cnamespace.equals(namespace)) {
+			throw new XmpParsingException(ErrorType.InvalidPdfaSchema, "Invalid PDF/A namespace definition");
+		} // else good match
+		if (cnamespace.equals(namespace) && !cprefix.equals(prefix)) {
+			throw new XmpParsingException(ErrorType.InvalidPdfaSchema, "Invalid PDF/A namespace definition");
+		} // else good match
+
+	}
+
+
+
+	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();
+						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");
+												}
+												// create the type
+												TypeDescription<AbstractSimpleProperty> vtd = tm.getSimpleDescription(fValueType);
+												if (vtd!=null) {
+													// a type is found
+													String ftype = vtd.getType();
+													structuredType.addProperty(fName, ftype);
+												} else {
+													// TODO could fValueType be a structured type ?
+													// unknown type
+													throw new XmpParsingException(ErrorType.NoValueType, "Type not defined : "+fValueType);
+												}
+											} // else TODO
+										}
+									}
+									// add the structured type to list
+									TypeDescription<AbstractStructuredType> td = new TypeDescription<AbstractStructuredType>(ttype, null, DefinedStructuredType.class);
+									PropMapping pm = new PropMapping(structuredType.getNamespace());
+									for (Map.Entry<String, String> entry : structuredType.getDefinedProperties().entrySet()) {
+										pm.addNewProperty(entry.getKey(), entry.getValue());
+									}
+									td.setProperties(pm);
+									meta.getTypeMapping().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 XmpParsingException(ErrorType.RequiredProperty,"Missing field in property definition");
+								}
+								// check ptype existance
+								String etype = ptype.equals("Lang Alt")?ptype:tm.isArrayType(ptype)?tm.getTypeInArray(ptype):ptype;
+								if (tm.isSimpleType(etype) || tm.isStructuredType(etype) ) {
+									xsf.getPropertyDefinition().addNewProperty(pname, ptype);
+								} else {
+									throw new XmpParsingException(ErrorType.NoValueType, "Type not defined : "+ptype+" ("+etype+")");
+								}
+								
+							} // TODO unmanaged ?
+						}
+					} // TODO unmanaged ?
+				}
+			}
+		}
+	}
+
+
+}