pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gbaill...@apache.org
Subject svn commit: r1374657 - in /pdfbox/branches/xmpbox-refactoring/xmpbox/src: main/java/org/apache/padaf/xmpbox/ main/java/org/apache/padaf/xmpbox/parser/ main/java/org/apache/padaf/xmpbox/schema/ main/java/org/apache/padaf/xmpbox/type/ test/java/org/apach...
Date Sat, 18 Aug 2012 21:14:19 GMT
Author: gbailleul
Date: Sat Aug 18 21:14:18 2012
New Revision: 1374657

URL: http://svn.apache.org/viewvc?rev=1374657&view=rev
Log:
PDFBOX-1388: removed dom element from types and schema, only used in serialization and deserialization

Added:
    pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/XmpSerializer.java
Removed:
    pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/SaveMetadataHelper.java
    pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/Elementable.java
Modified:
    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/parser/XMLUtil.java
    pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/parser/XMPDocumentBuilder.java
    pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/schema/XMPSchema.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/AbstractSimpleProperty.java
    pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/AbstractStructuredType.java
    pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/ArrayProperty.java
    pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/BooleanType.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/DateType.java
    pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/IntegerType.java
    pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/RealType.java
    pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/TextType.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/schema/BasicJobTicketSchemaTest.java
    pdfbox/branches/xmpbox-refactoring/xmpbox/src/test/java/org/apache/padaf/xmpbox/type/TestSimpleMetadataProperties.java

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=1374657&r1=1374656&r2=1374657&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 Sat Aug 18 21:14:18 2012
@@ -20,7 +20,6 @@
  ****************************************************************************/
 package org.apache.padaf.xmpbox;
 
-import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
@@ -38,9 +37,6 @@ import org.apache.padaf.xmpbox.schema.XM
 import org.apache.padaf.xmpbox.schema.XMPMediaManagementSchema;
 import org.apache.padaf.xmpbox.schema.XMPRightsManagementSchema;
 import org.apache.padaf.xmpbox.schema.XMPSchema;
-import org.apache.padaf.xmpbox.type.Elementable;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
 
 /**
  * Object representation of XMPMetaData Be CAREFUL: typically, metadata should
@@ -59,7 +55,7 @@ public class XMPMetadata {
     
     private String xpacketBegin = "\uFEFF";
 
-    // DEPRECATED (SHOULD STAY NULL (Default value))
+    // TODO DEPRECATED (SHOULD STAY NULL (Default value))
     private String xpacketBytes;
     
     private String xpacketEncoding;
@@ -68,8 +64,6 @@ public class XMPMetadata {
 
     private SchemasContainer schemas;
 
-    private Document xmpDocument;
-    
     private XMPDocumentBuilder builder;
 
     /**
@@ -79,15 +73,8 @@ public class XMPMetadata {
      *             If DOM Document associated could not be created
      */
     protected XMPMetadata(XMPDocumentBuilder builder) throws CreateXMPMetadataException {
-        try {
-        	this.builder = builder;
-            xmpDocument = org.apache.padaf.xmpbox.parser.XMLUtil.newDocument();
-            schemas = new SchemasContainer();
-        } catch (IOException e) {
-            throw new CreateXMPMetadataException(
-            "Failed to create Dom Document",e);
-        }
-
+      	this.builder = builder;
+        schemas = new SchemasContainer();
     }
 
     /**
@@ -113,13 +100,7 @@ public class XMPMetadata {
         this.xpacketId = xpacketId;
         this.xpacketBytes = xpacketBytes;
         this.xpacketEncoding = xpacketEncoding;
-        try {
-            xmpDocument = org.apache.padaf.xmpbox.parser.XMLUtil.newDocument();
-            schemas = new SchemasContainer();
-        } catch (IOException e) {
-            throw new CreateXMPMetadataException(
-            "Failed to create Dom Document",e);
-        }
+        schemas = new SchemasContainer();
     }
 
     /**
@@ -202,24 +183,6 @@ public class XMPMetadata {
     }
 
     /**
-     * Get element associated to all schemas contained in this Metadata
-     * 
-     * @return Dom Element representing serialized metadata
-     */
-    public Element getContainerElement() {
-        return schemas.getElement();
-    }
-
-    /**
-     * Give the DOM Document to build metadata content
-     * 
-     * @return The XML Document which is serialized metadata
-     */
-    public Document getFuturOwner() {
-        return xmpDocument;
-    }
-
-    /**
      * Return the schema corresponding to this nsURI BE CAREFUL: typically,
      * Metadata should contains one schema for each type this method return the
      * first schema encountered corresponding to this NSURI Return null if
@@ -514,10 +477,8 @@ public class XMPMetadata {
      * @author a183132
      * 
      */
-    public class SchemasContainer implements Elementable {
+    public class SchemasContainer {
 
-        private Element element;
-        
         private List<XMPSchema> schemas;
 
         /**
@@ -525,9 +486,6 @@ public class XMPMetadata {
          * Schemas Container constructor
          */
         public SchemasContainer() {
-            element = xmpDocument.createElement("rdf:RDF");
-            element.setAttributeNS(XMPSchema.NS_NAMESPACE, "xmlns:rdf",
-            "http://www.w3.org/1999/02/22-rdf-syntax-ns#");
             schemas = new ArrayList<XMPSchema>();
         }
 
@@ -539,7 +497,6 @@ public class XMPMetadata {
          */
         public void addSchema(XMPSchema obj) {
             schemas.add(obj);
-            element.appendChild(obj.getElement());
         }
 
         /**
@@ -549,18 +506,7 @@ public class XMPMetadata {
          *            The schema to remove
          */
         public void removeSchema(XMPSchema schema) {
-            if (schemas.remove(schema)) {
-                element.removeChild(schema.getElement());
-            }
-        }
-
-        /**
-         * Get The Dom Element in order to build serialized metadata
-         * 
-         * @return Dom Element
-         */
-        public Element getElement() {
-            return element;
+        	schemas.remove(schema);
         }
 
     }

Added: pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/XmpSerializer.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/XmpSerializer.java?rev=1374657&view=auto
==============================================================================
--- pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/XmpSerializer.java (added)
+++ pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/XmpSerializer.java Sat Aug 18 21:14:18 2012
@@ -0,0 +1,171 @@
+ /*****************************************************************************
+ * 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.
+ * 
+ ****************************************************************************/
+
+package org.apache.padaf.xmpbox;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.List;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.apache.padaf.xmpbox.parser.XMLUtil;
+import org.apache.padaf.xmpbox.schema.XMPSchema;
+import org.apache.padaf.xmpbox.type.AbstractField;
+import org.apache.padaf.xmpbox.type.AbstractSimpleProperty;
+import org.apache.padaf.xmpbox.type.AbstractStructuredType;
+import org.apache.padaf.xmpbox.type.ArrayProperty;
+import org.apache.padaf.xmpbox.type.Attribute;
+import org.apache.padaf.xmpbox.type.ComplexPropertyContainer;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.ProcessingInstruction;
+
+public class XmpSerializer {
+
+	private DocumentBuilder documentBuilder = null;
+	
+	public XmpSerializer () throws TransformException {
+		// xml init
+        DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
+        try {
+			documentBuilder = builderFactory.newDocumentBuilder();
+		} catch (ParserConfigurationException e) {
+			throw new TransformException("Failed to init XmpSerializer", e);
+		}
+		
+	}
+	
+	
+	public void serialize(XMPMetadata metadata, OutputStream os, boolean withXpacket) throws TransformException {
+		// TODO rewrite serialization
+		try {
+			Document doc = documentBuilder.newDocument();
+			// fill document
+			Element rdf = createRdfElement(doc,metadata, withXpacket);
+			for (XMPSchema schema : metadata.getAllSchemas()) {
+				rdf.appendChild(createSchemaElement(doc, schema));
+			}
+			// save
+			XMLUtil.save(doc, os, "UTF-8");
+		} catch (Exception e) {
+			// TODO supprimer
+			throw new TransformException(
+					"Failed to create Document to contain Schema representation ",
+					e);
+		}
+
+	}
+
+	protected Element createSchemaElement (Document doc, XMPSchema schema) {
+		// prepare schema
+		Element selem = doc.createElement("rdf:Description");
+		selem.setAttribute("rdf:about", schema.getAboutValue()); 
+		selem.setAttributeNS(XMPSchema.NS_NAMESPACE, "xmlns:"+schema.getPrefix(), schema.getNamespaceValue());
+		// the other attributes
+//		List<Attribute> attributes = schema.getAllAttributes();
+		fillElementWithAttributes(selem, schema.getAllAttributes());
+//		for (Attribute attribute : attributes) {
+//			selem.setAttribute(attribute.getQualifiedName(), attribute.getValue());
+//		}
+//		selem.setAttribute("rdf:about", schema.getClass().getName()); // TODO remove already done 6 lines before
+		// the content
+		List<AbstractField> fields = schema.getAllProperties();
+		xxxxxxx(doc, selem, fields);
+		// return created schema
+		return selem;
+	}
+
+	public void xxxxxxx (Document doc, Element parent, List<AbstractField> fields) {
+		for (AbstractField field : fields) {
+			if (field instanceof AbstractSimpleProperty) {
+				AbstractSimpleProperty simple = (AbstractSimpleProperty)field;
+				Element esimple = doc.createElement(simple.getPrefix()+":"+simple.getPropertyName());
+				esimple.setTextContent(simple.getStringValue());
+				parent.appendChild(esimple);
+			} else if (field instanceof ArrayProperty) {
+				ArrayProperty array = (ArrayProperty)field;
+				Element asimple = doc.createElement(array.getPrefix()+":"+array.getPropertyName());
+				parent.appendChild(asimple);
+				// attributes
+				fillElementWithAttributes(asimple, array.getAllAttributes());
+				// the array definition
+				ComplexPropertyContainer container = array.getContainer();
+				Element econtainer = doc.createElement("rdf"+":"+"Bag"); // TODO 
+				asimple.appendChild(econtainer);
+				// for each element of the array
+				List<AbstractField> innerFields = container.getAllProperties();
+				xxxxxxx(doc, econtainer, innerFields);
+			} else if (field instanceof AbstractStructuredType) {
+				AbstractStructuredType structured = (AbstractStructuredType)field;
+				// element li
+				Element estructured = doc.createElement(structured.getPrefix()+":"+structured.getPropertyName());
+				parent.appendChild(estructured);
+				// element description
+				Element econtainer = doc.createElement("rdf"+":"+"Description");
+				estructured.appendChild(econtainer);
+				// all properties
+				List<AbstractField> innerFields = structured.getAllProperties();
+				xxxxxxx(doc, econtainer, innerFields);
+			} else {
+				System.err.println(">> TODO >> "+field.getClass());
+			}
+		}
+		
+	}
+	
+	protected void fillElementWithAttributes (Element target, List<Attribute> attributes) {
+		for (Attribute attribute : attributes) {
+			target.setAttribute(attribute.getQualifiedName(), attribute.getValue());
+		}
+	}
+	
+	protected Element createRdfElement (Document doc, XMPMetadata metadata, boolean withXpacket) {
+		// starting xpacket
+		if (withXpacket) {
+			ProcessingInstruction beginXPacket = doc
+					.createProcessingInstruction("xpacket", "begin=\""
+							+ metadata.getXpacketBegin() + "\" id=\""
+							+ metadata.getXpacketId() + "\"");
+			doc.appendChild(beginXPacket);
+		}
+		// meta element
+		Element xmpmeta = doc.createElementNS("adobe:ns:meta/", "x:xmpmeta");
+		xmpmeta.setAttributeNS(XMPSchema.NS_NAMESPACE, "xmlns:x","adobe:ns:meta/");
+		doc.appendChild(xmpmeta);
+		// ending xpacket
+		if (withXpacket) {
+			ProcessingInstruction endXPacket = doc
+					.createProcessingInstruction("xpacket", metadata
+							.getEndXPacket());
+			doc.appendChild(endXPacket);
+		}
+		// rdf element
+		Element rdf = doc.createElementNS(XmpConstants.RDF_NAMESPACE, "rdf:RDF");
+//		rdf.setAttributeNS(XMPSchema.NS_NAMESPACE, qualifiedName, value)
+		xmpmeta.appendChild(rdf);
+		// return the rdf element where all will be put
+		return rdf;
+	}
+  
+	
+}

Modified: pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/parser/XMLUtil.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/parser/XMLUtil.java?rev=1374657&r1=1374656&r2=1374657&view=diff
==============================================================================
--- pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/parser/XMLUtil.java (original)
+++ pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/parser/XMLUtil.java Sat Aug 18 21:14:18 2012
@@ -38,7 +38,6 @@ import javax.xml.transform.dom.DOMSource
 import javax.xml.transform.stream.StreamResult;
 
 
-import org.apache.padaf.xmpbox.type.Elementable;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
@@ -286,66 +285,6 @@ public final class XMLUtil {
     }
 
     /**
-     * Set an XML element document.
-     * 
-     * @param parent
-     *            The parent document to set the value in.
-     * @param name
-     *            The name of the XML element to set.
-     * @param node
-     *            The node to set or clear.
-     */
-    public static void setElementableValue(Element parent, String name,
-            Elementable node) {
-        NodeList nodes = parent.getElementsByTagName(name);
-        if (node == null) {
-            for (int i = 0; i < nodes.getLength(); i++) {
-                parent.removeChild(nodes.item(i));
-            }
-        } else {
-            if (nodes.getLength() == 0) {
-                if (parent.hasChildNodes()) {
-                    Node firstChild = parent.getChildNodes().item(0);
-                    parent.insertBefore(node.getElement(), firstChild);
-                } else {
-                    parent.appendChild(node.getElement());
-                }
-            } else {
-                Node oldNode = nodes.item(0);
-                parent.replaceChild(node.getElement(), oldNode);
-            }
-        }
-    }
-
-    /**
-     * Save the XML document to a file.
-     * 
-     * @param doc
-     *            The XML document to save.
-     * @param file
-     *            The file to save the document to.
-     * @param encoding
-     *            The encoding to save the file as.
-     * 
-     * @throws TransformerException
-     *             If there is an error while saving the XML.
-     */
-    public static void save(Document doc, String file, String encoding)
-    throws TransformerException {
-        Transformer transformer = TransformerFactory.newInstance()
-        .newTransformer();
-        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
-        transformer.setOutputProperty(OutputKeys.ENCODING, encoding);
-        transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION,
-        "yes");
-        // initialize StreamResult with File object to save to file
-
-        Result result = new StreamResult(new File(file));
-        DOMSource source = new DOMSource(doc);
-        transformer.transform(source, result);
-    }
-
-    /**
      * Save the XML document to an output stream.
      * 
      * @param doc

Modified: pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/parser/XMPDocumentBuilder.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/parser/XMPDocumentBuilder.java?rev=1374657&r1=1374656&r2=1374657&view=diff
==============================================================================
--- pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/parser/XMPDocumentBuilder.java (original)
+++ pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/parser/XMPDocumentBuilder.java Sat Aug 18 21:14:18 2012
@@ -169,7 +169,7 @@ public class XMPDocumentBuilder {
 		ByteArrayInputStream is = new ByteArrayInputStream(xmp);
 		try {
 			XMLInputFactory factory = XMLInputFactory.newInstance();
-			reader.set(factory.createXMLStreamReader(is));
+			reader.set(factory.createXMLStreamReader(is,"UTF8"));
 
 			// expect xpacket processing instruction
 			expectNext(XMLStreamReader.PROCESSING_INSTRUCTION,

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=1374657&r1=1374656&r2=1374657&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 Sat Aug 18 21:14:18 2012
@@ -37,12 +37,10 @@ import org.apache.padaf.xmpbox.type.Bool
 import org.apache.padaf.xmpbox.type.ArrayProperty;
 import org.apache.padaf.xmpbox.type.ComplexPropertyContainer;
 import org.apache.padaf.xmpbox.type.DateType;
-import org.apache.padaf.xmpbox.type.Elementable;
 import org.apache.padaf.xmpbox.type.IntegerType;
 import org.apache.padaf.xmpbox.type.TextType;
 import org.apache.padaf.xmpbox.type.TypeMapping;
 import org.apache.padaf.xmpbox.type.TypeUtil;
-import org.w3c.dom.Element;
 
 /**
  * This class represents a metadata schema that can be stored in an XMP
@@ -51,7 +49,7 @@ import org.w3c.dom.Element;
  * REPRESENTATION
  * 
  */
-public class XMPSchema implements Elementable {
+public class XMPSchema {
 	/**
 	 * The standard xmlns namespace.
 	 */
@@ -63,8 +61,6 @@ public class XMPSchema implements Elemen
 	
 	private String localNSUri;
 	
-//	private String localPrefixSep;
-	
 	private XMPMetadata metadata;
 	
 	private ComplexPropertyContainer content;
@@ -765,7 +761,7 @@ public class XMPSchema implements Elemen
 	 *            the elementable field value
 	 */
 	public void removeUnqualifiedArrayValue(String arrayName,
-			Elementable fieldValue) {
+			AbstractField fieldValue) {
 		String qualifiedArrayName = getQualifiedName(arrayName);
 		ArrayProperty array = (ArrayProperty) getAbstractProperty(qualifiedArrayName);
 		if (array != null) {
@@ -797,7 +793,7 @@ public class XMPSchema implements Elemen
 	 *            The value to remove from the list.
 	 */
 	public void removeUnqualifiedSequenceValue(String qualifiedSeqName,
-			Elementable seqValue) {
+			AbstractField seqValue) {
 		removeUnqualifiedArrayValue(qualifiedSeqName, seqValue);
 	}
 
@@ -1369,15 +1365,6 @@ public class XMPSchema implements Elemen
 	}
 
 	/**
-	 * Get DOM Element for rdf/xml serialization
-	 * 
-	 * @return the DOM Element
-	 */
-	public Element getElement() {
-		return content.getElement();
-	}
-
-	/**
 	 * get a Property with its name, using the current prefix
 	 * 
 	 * @param simpleName

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=1374657&r1=1374656&r2=1374657&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 Sat Aug 18 21:14:18 2012
@@ -26,10 +26,7 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
-
 import org.apache.padaf.xmpbox.XMPMetadata;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
 
 /**
  * Astract Object representation of a XMP 'field' (-> Properties and specific
@@ -38,17 +35,8 @@ import org.w3c.dom.Element;
  * @author a183132
  * 
  */
-public abstract class AbstractField implements Elementable {
-
-	/**
-	 * ALL PROPERTIES MUST NOT BE USED MORE THAN ONE TIME BECAUSE THE SAME
-	 * ELEMENT CANNOT BE MORE THAN ONE TIME IN THE SAME DOM DOCUMENT (if you
-	 * choose to use the same property in different places in the same document,
-	 * the element associated will not appear)
-	 */
+public abstract class AbstractField {
 
-	private Element element;
-	
 	private XMPMetadata metadata;
 
 	private String namespaceURI, prefix, propertyName;
@@ -84,31 +72,14 @@ public abstract class AbstractField impl
 	 */
 	public AbstractField(XMPMetadata metadata, String namespaceURI,
 			String prefix, String propertyName) {
-		String qualifiedName;
 		this.prefix = prefix;
-		qualifiedName = prefix + ":" + propertyName;
 		this.metadata = metadata;
-		Document parent = metadata.getFuturOwner();
 		this.namespaceURI = namespaceURI;
 		this.propertyName = propertyName;
-		if (this.namespaceURI!=null) {
-			element = parent.createElementNS(namespaceURI, qualifiedName);
-		} else {
-			element = parent.createElement(qualifiedName);
-		}
 		attributes = new HashMap<String, Attribute>();
 	}
 
 	/**
-	 * Get the DOM element for rdf/xml serialization
-	 * 
-	 * @return The DOM Element
-	 */
-	public Element getElement() {
-		return element;
-	}
-
-	/**
 	 * Get the namespace URI of this entity
 	 * 
 	 * @return the namespace URI
@@ -158,11 +129,8 @@ public abstract class AbstractField impl
 		}
 		if (value.getNamespace() == null) {
 			attributes.put(value.getQualifiedName(), value);
-			element.setAttribute(value.getQualifiedName(), value.getValue());
 		} else {
 			attributes.put(value.getQualifiedName(), value);
-			element.setAttributeNS(value.getNamespace(), value
-					.getQualifiedName(), value.getValue());
 		}
 	}
 
@@ -205,7 +173,6 @@ public abstract class AbstractField impl
 	 */
 	public void removeAttribute(String qualifiedName) {
 		if (containsAttribute(qualifiedName)) {
-			element.removeAttribute(qualifiedName);
 			attributes.remove(qualifiedName);
 		}
 

Modified: pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/AbstractSimpleProperty.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/AbstractSimpleProperty.java?rev=1374657&r1=1374656&r2=1374657&view=diff
==============================================================================
--- pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/AbstractSimpleProperty.java (original)
+++ pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/AbstractSimpleProperty.java Sat Aug 18 21:14:18 2012
@@ -72,9 +72,7 @@ public abstract class AbstractSimpleProp
 	 * 
 	 * @return a string
 	 */
-	public String getStringValue() {
-		return getElement().getTextContent();
-	}
+	public abstract String getStringValue();
 
 	public Object getObjectValue () {
 		return objValue;

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=1374657&r1=1374656&r2=1374657&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 Sat Aug 18 21:14:18 2012
@@ -44,7 +44,6 @@ public abstract class AbstractStructured
 		super(metadata, namespaceURI, STRUCTURE_ARRAY_PREFIX, STRUCTURE_ARRAY_NAME);
 		this.container = new ComplexPropertyContainer(metadata, namespaceURI, STRUCTURE_ARRAY_PREFIX, "Description");
 		this.fieldPrefix = fieldPrefix;
-		getElement().appendChild(container.getElement());
 	}
 
 	public abstract String getFieldsNamespace();

Modified: pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/ArrayProperty.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/ArrayProperty.java?rev=1374657&r1=1374656&r2=1374657&view=diff
==============================================================================
--- pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/ArrayProperty.java (original)
+++ pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/ArrayProperty.java Sat Aug 18 21:14:18 2012
@@ -60,7 +60,6 @@ public class ArrayProperty extends Abstr
 			String prefix, String propertyName, String type) {
 		super(metadata, namespace, prefix, propertyName);
 		container = new ComplexPropertyContainer(metadata,null, "rdf", type);
-		getElement().appendChild(container.getElement());
 	}
 
 	/**
@@ -73,23 +72,6 @@ public class ArrayProperty extends Abstr
 		return container;
 	}
 
-	/**
-	 * Check if this complex property equals to another
-	 * 
-	 * @param prop2
-	 *            The Complex property to compare
-	 * @return True if properties are equals
-	 */
-	public boolean isSameProperty(AbstractField prop2) {
-		if (this.getQualifiedName().equals(prop2.getQualifiedName())) {
-			if (this.getElement().getTextContent().equals(
-					prop2.getElement().getTextContent())) {
-				return true;
-			}
-		}
-		return false;
-	}
-
 	public List<AbstractField> getAllProperties() {
 		return container.getAllProperties();
 	}

Modified: pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/BooleanType.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/BooleanType.java?rev=1374657&r1=1374656&r2=1374657&view=diff
==============================================================================
--- pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/BooleanType.java (original)
+++ pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/BooleanType.java Sat Aug 18 21:14:18 2012
@@ -79,10 +79,8 @@ public class BooleanType extends Abstrac
 			String s = value.toString().trim().toUpperCase();
 			if ("TRUE".equals(s)) {
 				setObjectValue(Boolean.TRUE);
-				getElement().setTextContent(TRUE);
 			} else if ("FALSE".equals(s)) {
 				setObjectValue(Boolean.FALSE);
-				getElement().setTextContent(FALSE);
 			} else {
 				// unknown value
 				throw new IllegalArgumentException("Not a valid boolean value : '"+value+"'");
@@ -94,5 +92,11 @@ public class BooleanType extends Abstrac
 	}
 
 
+	@Override
+	public String getStringValue() {
+		return ((Boolean)getObjectValue()).booleanValue()?TRUE:FALSE;
+	}
+
+
 
 }

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=1374657&r1=1374656&r2=1374657&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 Sat Aug 18 21:14:18 2012
@@ -28,9 +28,6 @@ import java.util.List;
 import java.util.Map;
 
 import org.apache.padaf.xmpbox.XMPMetadata;
-import org.w3c.dom.Element;
-import org.w3c.dom.NodeList;
-
 
 /**
  * Object representation for arrays content This Class could be used to define
@@ -41,15 +38,13 @@ import org.w3c.dom.NodeList;
  */
 public class ComplexPropertyContainer /*extends AbstractField*/ {
 
-	
+
 	private List<AbstractField> properties;
 
-	private Element element;
-	
 	private Map<String, Attribute> attributes;
 
 
-	
+
 	/**
 	 * Complex Property type constructor (namespaceURI is given)
 	 * 
@@ -64,22 +59,10 @@ public class ComplexPropertyContainer /*
 	 */
 	public ComplexPropertyContainer(XMPMetadata metadata, String namespaceURI,
 			String prefix, String propertyName) {
-		String qualifiedName = prefix + ":" + propertyName;
-		if (namespaceURI!=null) {
-			element = metadata.getFuturOwner().createElementNS(namespaceURI, qualifiedName);
-		} else {
-			element = metadata.getFuturOwner().createElement(qualifiedName);
-		}
 		properties = new ArrayList<AbstractField>();
 		attributes = new HashMap<String, Attribute>();
 	}
 
-	
-	
-	public Element getElement() {
-		return element;
-	}
-
 	/**
 	 * Get an attribute with its name in this entity
 	 * 
@@ -113,11 +96,8 @@ public class ComplexPropertyContainer /*
 		}
 		if (value.getNamespace() == null) {
 			attributes.put(value.getQualifiedName(), value);
-			element.setAttribute(value.getQualifiedName(), value.getValue());
 		} else {
 			attributes.put(value.getQualifiedName(), value);
-			element.setAttributeNS(value.getNamespace(), value
-					.getQualifiedName(), value.getValue());
 		}
 	}
 
@@ -129,12 +109,11 @@ public class ComplexPropertyContainer /*
 	 */
 	public void removeAttribute(String qualifiedName) {
 		if (containsAttribute(qualifiedName)) {
-			element.removeAttribute(qualifiedName);
 			attributes.remove(qualifiedName);
 		}
 
 	}
-	
+
 	/**
 	 * Check if an attribute is declared for this entity
 	 * 
@@ -179,12 +158,6 @@ public class ComplexPropertyContainer /*
 			removeProperty(obj);
 		}
 		properties.add(obj);
-		// COMMENTS REPRESENTS CLUES TO USE SAME PROPERTY AT MORE THAN ONE PLACE
-		// BUT IT CREATE PROBLEM TO FIND AND ERASE CLONED ELEMENT
-		// Node cloned = obj.getElement().cloneNode(true);
-		// parent.adoptNode(cloned);
-		element.appendChild(obj.getElement());
-		// element.appendChild(cloned);
 	}
 
 	/**
@@ -233,11 +206,8 @@ public class ComplexPropertyContainer /*
 	 */
 	public boolean isSameProperty(AbstractField prop1, AbstractField prop2) {
 		if (prop1.getClass().equals(prop2.getClass())
-				&& prop1.getQualifiedName().equals(prop2.getQualifiedName())) {
-			if (prop1.getElement().getTextContent().equals(
-					prop2.getElement().getTextContent())) {
-				return true;
-			}
+				&& prop1.getPropertyName().equals(prop2.getPropertyName())) {
+			return prop1.equals(prop2);
 		}
 		return false;
 	}
@@ -270,19 +240,6 @@ public class ComplexPropertyContainer /*
 	public void removeProperty(AbstractField property) {
 		if (containsProperty(property)) {
 			properties.remove(property);
-			if (element.hasChildNodes()) {
-				NodeList nodes = element.getChildNodes();
-				boolean canRemove = false;
-				for (int i = 0; i < nodes.getLength(); ++i) {
-					if (nodes.item(i).equals(property.getElement())) {
-						canRemove = true;
-					}
-				}
-				// remove out of the loop to avoid concurrent exception
-				if (canRemove) {
-					element.removeChild(property.getElement());
-				}
-			}
 		}
 	}
 

Modified: pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/DateType.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/DateType.java?rev=1374657&r1=1374656&r2=1374657&view=diff
==============================================================================
--- pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/DateType.java (original)
+++ pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/DateType.java Sat Aug 18 21:14:18 2012
@@ -65,8 +65,6 @@ public class DateType extends AbstractSi
      */
     private void setValueFromCalendar(Calendar value) {
         setObjectValue(value);
-        getElement().setTextContent(DateConverter.toISO8601(value));
-
     }
 
     /**
@@ -122,6 +120,12 @@ public class DateType extends AbstractSi
 
     }
 
+    public String getStringValue() {
+		return DateConverter.toISO8601((Calendar)getObjectValue());
+	} // TODO should be abstract
+
+	
+    
     /**
      * Set the property value with a String
      * 

Modified: pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/IntegerType.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/IntegerType.java?rev=1374657&r1=1374656&r2=1374657&view=diff
==============================================================================
--- pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/IntegerType.java (original)
+++ pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/IntegerType.java Sat Aug 18 21:14:18 2012
@@ -77,26 +77,14 @@ public class IntegerType extends Abstrac
 			// invalid type of value
 			throw new IllegalArgumentException("Value given is not allowed for the Integer type.");
 		}
-		// set value
-		getElement().setTextContent(getObjectValue().toString());
 	}
-//
-//	public void setValue(Object value) {
-//		if (!isGoodType(value)) {
-//			throw new IllegalArgumentException(
-//					"Value given is not allowed for the Integer type.");
-//		} else {
-//			// if string object
-//			if (value instanceof String) {
-//				setValueFromString((String) value);
-//			} else {
-//				// if Integer
-//				setValueFromInt((Integer) value);
-//			}
-//
-//		}
-//
-//	}
 
+	@Override
+	public String getStringValue() {
+		return ((Integer)getObjectValue()).toString();
+	}
+	
+	
+	
 
 }

Modified: pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/RealType.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/RealType.java?rev=1374657&r1=1374656&r2=1374657&view=diff
==============================================================================
--- pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/RealType.java (original)
+++ pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/RealType.java Sat Aug 18 21:14:18 2012
@@ -77,10 +77,12 @@ public class RealType extends AbstractSi
 			// invalid type of value
 			throw new IllegalArgumentException("Value given is not allowed for the Real type.");
 		}
-		// set value
-		getElement().setTextContent(getObjectValue().toString());
 	}
 
+	@Override
+	public String getStringValue() {
+		return ((Float)getObjectValue()).toString();
+	}
 
 
 }

Modified: pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/TextType.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/TextType.java?rev=1374657&r1=1374656&r2=1374657&view=diff
==============================================================================
--- pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/TextType.java (original)
+++ pdfbox/branches/xmpbox-refactoring/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/TextType.java Sat Aug 18 21:14:18 2012
@@ -65,9 +65,14 @@ public class TextType extends AbstractSi
 							+ "'");
 		} else {
 			setObjectValue((String) value);
-			getElement().setTextContent((String) value);
 		}
 
 	}
 
+	@Override
+	public String getStringValue() {
+		return ((String)getObjectValue());
+	}
+
+	
 }

Modified: pdfbox/branches/xmpbox-refactoring/xmpbox/src/test/java/org/apache/padaf/xmpbox/SaveMetadataHelperTest.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/xmpbox-refactoring/xmpbox/src/test/java/org/apache/padaf/xmpbox/SaveMetadataHelperTest.java?rev=1374657&r1=1374656&r2=1374657&view=diff
==============================================================================
--- pdfbox/branches/xmpbox-refactoring/xmpbox/src/test/java/org/apache/padaf/xmpbox/SaveMetadataHelperTest.java (original)
+++ pdfbox/branches/xmpbox-refactoring/xmpbox/src/test/java/org/apache/padaf/xmpbox/SaveMetadataHelperTest.java Sat Aug 18 21:14:18 2012
@@ -38,15 +38,16 @@ public class SaveMetadataHelperTest {
 		dc.addContributor("contributor1");
 		dc.addContributor("contributor2");
 		dc.addDescription("x-default", "Description");
-		ByteArrayOutputStream bos = new ByteArrayOutputStream();
-		SaveMetadataHelper.serialize(dc, bos);
-		byte[] tmp = SaveMetadataHelper.serialize(dc);
-		Assert.assertArrayEquals(bos.toByteArray(), tmp);
+//		ByteArrayOutputStream bos = new ByteArrayOutputStream();
+//		SaveMetadataHelper.serialize(dc, bos);
+//		byte[] tmp = SaveMetadataHelper.serialize(dc);
+//		Assert.assertArrayEquals(bos.toByteArray(), tmp);
 	}
 
 	@Test
 	public void testMetadataParsing() throws Exception {
 		XMPMetadata meta = new XMPDocumentBuilder().createXMPMetadata();
+		XmpSerializer serializer = new XmpSerializer();
 
 		DublinCoreSchema dc = meta.createAndAddDublinCoreSchema();
 		dc.setCoverage("coverage");
@@ -58,16 +59,7 @@ public class SaveMetadataHelperTest {
 		pdf.setProducer("Producer");
 		pdf.setPDFVersion("1.4");
 
-		ByteArrayOutputStream bos = new ByteArrayOutputStream();
-		byte[] tmp = SaveMetadataHelper.serialize(meta);
-		SaveMetadataHelper.serialize(meta, bos);
-
-		Assert.assertArrayEquals(bos.toByteArray(), tmp);
-
-		ByteArrayOutputStream bosWithoutPI = new ByteArrayOutputStream();
-		SaveMetadataHelper.serialize(meta, false, bosWithoutPI);
-		byte[] tmpWithoutPI = SaveMetadataHelper.serialize(meta, false);
-		Assert.assertArrayEquals(bosWithoutPI.toByteArray(), tmpWithoutPI);
+
 	}
 
 }

Modified: pdfbox/branches/xmpbox-refactoring/xmpbox/src/test/java/org/apache/padaf/xmpbox/schema/BasicJobTicketSchemaTest.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/xmpbox-refactoring/xmpbox/src/test/java/org/apache/padaf/xmpbox/schema/BasicJobTicketSchemaTest.java?rev=1374657&r1=1374656&r2=1374657&view=diff
==============================================================================
--- pdfbox/branches/xmpbox-refactoring/xmpbox/src/test/java/org/apache/padaf/xmpbox/schema/BasicJobTicketSchemaTest.java (original)
+++ pdfbox/branches/xmpbox-refactoring/xmpbox/src/test/java/org/apache/padaf/xmpbox/schema/BasicJobTicketSchemaTest.java Sat Aug 18 21:14:18 2012
@@ -27,15 +27,9 @@ import java.io.InputStream;
 import junit.framework.Assert;
 
 import org.apache.commons.io.IOUtils;
-import org.apache.padaf.xmpbox.SaveMetadataHelper;
 import org.apache.padaf.xmpbox.XMPMetadata;
+import org.apache.padaf.xmpbox.XmpSerializer;
 import org.apache.padaf.xmpbox.parser.XMPDocumentBuilder;
-import org.apache.padaf.xmpbox.parser.XmpExpectedRdfAboutAttribute;
-import org.apache.padaf.xmpbox.parser.XmpParsingException;
-import org.apache.padaf.xmpbox.parser.XmpSchemaException;
-import org.apache.padaf.xmpbox.parser.XmpUnknownValueTypeException;
-import org.apache.padaf.xmpbox.parser.XmpXpacketEndException;
-import org.apache.padaf.xmpbox.type.BadFieldValueException;
 import org.apache.padaf.xmpbox.type.JobType;
 import org.junit.Before;
 import org.junit.BeforeClass;
@@ -46,6 +40,8 @@ public class BasicJobTicketSchemaTest {
 	protected static XMPDocumentBuilder builder;
 
 	protected XMPMetadata metadata;
+	
+	protected XmpSerializer serializer;
 
 	
 	@BeforeClass
@@ -56,6 +52,7 @@ public class BasicJobTicketSchemaTest {
 	@Before
 	public void initTempMetaData() throws Exception {
 		metadata = builder.createXMPMetadata();
+		serializer = new XmpSerializer();
 	}
 
 	private InputStream transfer(ByteArrayOutputStream out) {
@@ -64,29 +61,21 @@ public class BasicJobTicketSchemaTest {
 		return bis;
 	}
 	
-	private XMPMetadata parse (InputStream is ) throws BadFieldValueException, XmpParsingException, XmpSchemaException, XmpUnknownValueTypeException, XmpExpectedRdfAboutAttribute, XmpXpacketEndException {
-		return builder.parse(is);
-	}
-	
-	private XMPMetadata parse (ByteArrayOutputStream os ) throws Exception {
-		InputStream is = transfer(os);
-		return builder.parse(is);
-		
-	}
-	
 	@Test
 	public void testAddTwoJobs() throws Exception {
 		
 		XMPBasicJobTicketSchema basic = metadata.createAndAddBasicJobTicketSchema();
 
-		basic.addJob("zeid1", "zename1", "zeurl1","aaa");
+//		basic.addJob("zeid1", "zename1", "zeurl1","aaa"); FIXME the prefix is not used
+		basic.addJob("zeid1", "zename1", "zeurl1");
 		basic.addJob("zeid2", "zename2", "zeurl2");
 		
-		SaveMetadataHelper.serialize(metadata, System.out);
+		serializer.serialize(metadata, System.out, true);
 		
 		ByteArrayOutputStream bos = new ByteArrayOutputStream();
-		SaveMetadataHelper.serialize(metadata, bos);
-		XMPMetadata rxmp = parse(bos);
+		serializer.serialize(metadata, bos, true);
+		InputStream is = transfer(bos);
+		XMPMetadata rxmp = builder.parse(is);
 
 		XMPBasicJobTicketSchema jt = rxmp.getBasicJobTicketSchema();
 		Assert.assertNotNull(jt);
@@ -102,8 +91,10 @@ public class BasicJobTicketSchemaTest {
 		basic.addJob("zeid2", "zename2", "zeurl2");
 		
 		ByteArrayOutputStream bos = new ByteArrayOutputStream();
-		SaveMetadataHelper.serialize(metadata, bos);
-		XMPMetadata rxmp = parse(bos);
+		
+		serializer.serialize(metadata, bos, true);
+		InputStream is = transfer(bos);
+		XMPMetadata rxmp = builder.parse(is);
 
 		XMPBasicJobTicketSchema jt = rxmp.getBasicJobTicketSchema();
 		Assert.assertNotNull(jt);
@@ -125,11 +116,14 @@ public class BasicJobTicketSchemaTest {
 
 		basic.addJob("zeid2", "zename2", "zeurl2","aaa");
 		
-		SaveMetadataHelper.serialize(metadata, System.out);
+//		SaveMetadataHelper.serialize(metadata, System.out);
+		
+		serializer.serialize(metadata, System.out, true);
 		
 		ByteArrayOutputStream bos = new ByteArrayOutputStream();
-		SaveMetadataHelper.serialize(metadata, bos);
-		XMPMetadata rxmp = parse(bos);
+		serializer.serialize(metadata, bos, true);
+		InputStream is = transfer(bos);
+		XMPMetadata rxmp = builder.parse(is);
 
 		XMPBasicJobTicketSchema jt = rxmp.getBasicJobTicketSchema();
 		Assert.assertNotNull(jt);

Modified: pdfbox/branches/xmpbox-refactoring/xmpbox/src/test/java/org/apache/padaf/xmpbox/type/TestSimpleMetadataProperties.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/xmpbox-refactoring/xmpbox/src/test/java/org/apache/padaf/xmpbox/type/TestSimpleMetadataProperties.java?rev=1374657&r1=1374656&r2=1374657&view=diff
==============================================================================
--- pdfbox/branches/xmpbox-refactoring/xmpbox/src/test/java/org/apache/padaf/xmpbox/type/TestSimpleMetadataProperties.java (original)
+++ pdfbox/branches/xmpbox-refactoring/xmpbox/src/test/java/org/apache/padaf/xmpbox/type/TestSimpleMetadataProperties.java Sat Aug 18 21:14:18 2012
@@ -122,12 +122,12 @@ public class TestSimpleMetadataPropertie
 		RealType real = new RealType(parent, null, "test", "real", realv);
 		TextType text = new TextType(parent, null,"test", "text", textv);
 
-		Assert.assertEquals(bool.getNamespace(), bool.getElement()
-				.getNamespaceURI());
-		Assert.assertEquals(bool.getPrefix() + ":" + bool.getPropertyName(),
-				bool.getElement().getNodeName());
-		Assert.assertEquals(bool.getQualifiedName(), bool.getElement()
-				.getNodeName());
+//		Assert.assertEquals(bool.getNamespace(), bool.getElement()
+//				.getNamespaceURI());
+//		Assert.assertEquals(bool.getPrefix() + ":" + bool.getPropertyName(),
+//				bool.getElement().getNodeName());
+//		Assert.assertEquals(bool.getQualifiedName(), bool.getElement()
+//				.getNodeName());
 		Assert.assertEquals(boolv, bool.getValue());
 		Assert.assertEquals(datev, date.getValue());
 		Assert.assertEquals(integerv, integer.getValue());
@@ -136,31 +136,31 @@ public class TestSimpleMetadataPropertie
 
 	}
 
-	/**
-	 * Check Object creation from corresponding Java type
-	 * 
-	 * @throws Exception
-	 */
-	@Test
-	public void testObjectCreationFromJavaType() throws Exception {
-		BooleanType bool = new BooleanType(parent, null,"test", "booleen", true);
-		DateType date = new DateType(parent, null, "test", "date", Calendar
-				.getInstance());
-		IntegerType integer = new IntegerType(parent,null, "test", "integer", 1);
-		RealType real = new RealType(parent, null,"test", "real", (float) 1.6);
-		TextType text = new TextType(parent, null,"test", "text", "TEST");
-
-		Element e = parent.getFuturOwner().createElement("TEST");
-		parent.getFuturOwner().appendChild(e);
-		e.appendChild(bool.getElement());
-		e.appendChild(date.getElement());
-		e.appendChild(integer.getElement());
-		e.appendChild(real.getElement());
-		e.appendChild(text.getElement());
-
-		// XMLUtil.save(parent.getFuturOwner(), System.out, "UTF-8");
-
-	}
+//	/**
+//	 * Check Object creation from corresponding Java type
+//	 * 
+//	 * @throws Exception
+//	 */
+//	@Test
+//	public void testObjectCreationFromJavaType() throws Exception {
+//		BooleanType bool = new BooleanType(parent, null,"test", "booleen", true);
+//		DateType date = new DateType(parent, null, "test", "date", Calendar
+//				.getInstance());
+//		IntegerType integer = new IntegerType(parent,null, "test", "integer", 1);
+//		RealType real = new RealType(parent, null,"test", "real", (float) 1.6);
+//		TextType text = new TextType(parent, null,"test", "text", "TEST");
+//
+//		Element e = parent.getFuturOwner().createElement("TEST");
+//		parent.getFuturOwner().appendChild(e);
+//		e.appendChild(bool.getElement());
+//		e.appendChild(date.getElement());
+//		e.appendChild(integer.getElement());
+//		e.appendChild(real.getElement());
+//		e.appendChild(text.getElement());
+//
+//		// XMLUtil.save(parent.getFuturOwner(), System.out, "UTF-8");
+//
+//	}
 
 	/**
 	 * Check the creation from string attributes
@@ -210,13 +210,13 @@ public class TestSimpleMetadataPropertie
 		Assert.assertEquals(ns, real.getNamespace());
 		Assert.assertEquals(ns, text.getNamespace());
 
-		Element e = parent.getFuturOwner().createElement("TEST");
-		parent.getFuturOwner().appendChild(e);
-		e.appendChild(bool.getElement());
-		e.appendChild(date.getElement());
-		e.appendChild(integer.getElement());
-		e.appendChild(real.getElement());
-		e.appendChild(text.getElement());
+//		Element e = parent.getFuturOwner().createElement("TEST");
+//		parent.getFuturOwner().appendChild(e);
+//		e.appendChild(bool.getElement());
+//		e.appendChild(date.getElement());
+//		e.appendChild(integer.getElement());
+//		e.appendChild(real.getElement());
+//		e.appendChild(text.getElement());
 
 		// XMLUtil.save(parent.getFuturOwner(), System.out, "UTF-8");
 
@@ -281,7 +281,7 @@ public class TestSimpleMetadataPropertie
 		Assert.assertFalse(atts.contains(valueNS));
 		Assert.assertTrue(atts.contains(valueNS2));
 
-		parent.getFuturOwner().appendChild(integer.getElement());
+//		parent.getFuturOwner().appendChild(integer.getElement());
 		// XMLUtil.save(parent.getFuturOwner(), System.out, "UTF-8");
 	}
 



Mime
View raw message