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/07/01 12:17:27 UTC

svn commit: r1355867 - in /pdfbox/trunk/xmpbox/src: main/java/org/apache/padaf/xmpbox/parser/ main/java/org/apache/padaf/xmpbox/type/ test/java/org/apache/padaf/xmpbox/schema/

Author: gbailleul
Date: Sun Jul  1 10:17:25 2012
New Revision: 1355867

URL: http://svn.apache.org/viewvc?rev=1355867&view=rev
Log:
PDFBOX-1343: added some xmp types
* added Version
* added ResourceEvent
* fixed some code violation on exception stack trace

Added:
    pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/ResourceEventType.java
    pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/VersionType.java
Modified:
    pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/parser/DateConverter.java
    pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/parser/XMLPropertiesDescriptionManager.java
    pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/parser/XMLUtil.java
    pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/parser/XMLValueTypeDescriptionManager.java
    pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/parser/XMPDocumentBuilder.java
    pdfbox/trunk/xmpbox/src/test/java/org/apache/padaf/xmpbox/schema/AbstractXMPSchemaTest.java

Modified: pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/parser/DateConverter.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/parser/DateConverter.java?rev=1355867&r1=1355866&r2=1355867&view=diff
==============================================================================
--- pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/parser/DateConverter.java (original)
+++ pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/parser/DateConverter.java Sun Jul  1 10:17:25 2012
@@ -179,7 +179,9 @@ public class DateConverter {
 				}
 				if (retval == null) {
 					// we didn't find a valid date format so throw an exception
-					throw new IOException("Error converting date:" + date);
+					IOException ioe = new IOException("Error converting date:" + date);
+					ioe.initCause(e);
+					throw ioe;
 				}
 			}
 		}

Modified: pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/parser/XMLPropertiesDescriptionManager.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/parser/XMLPropertiesDescriptionManager.java?rev=1355867&r1=1355866&r2=1355867&view=diff
==============================================================================
--- pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/parser/XMLPropertiesDescriptionManager.java (original)
+++ pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/parser/XMLPropertiesDescriptionManager.java Sun Jul  1 10:17:25 2012
@@ -134,7 +134,7 @@ public class XMLPropertiesDescriptionMan
 		} catch (Exception e) {
 			throw new BuildPDFAExtensionSchemaDescriptionException(
 					"Failed to get correct properties descriptions from specified XML stream",
-					e.getCause());
+					e);
 		} finally {
 			IOUtils.closeQuietly(is);
 		}

Modified: pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/parser/XMLUtil.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/parser/XMLUtil.java?rev=1355867&r1=1355866&r2=1355867&view=diff
==============================================================================
--- pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/parser/XMLUtil.java (original)
+++ pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/parser/XMLUtil.java Sun Jul  1 10:17:25 2012
@@ -78,8 +78,7 @@ public final class XMLUtil {
             DocumentBuilder builder = builderFactory.newDocumentBuilder();
             return builder.parse(is);
         } catch (Exception e) {
-            IOException thrown = new IOException(e.getMessage());
-            throw thrown;
+        	throw prepareIOException("Failed to create document", e);
         }
     }
 
@@ -99,8 +98,7 @@ public final class XMLUtil {
             DocumentBuilder builder = builderFactory.newDocumentBuilder();
             return builder.parse(is);
         } catch (Exception e) {
-            IOException thrown = new IOException(e.getMessage());
-            throw thrown;
+        	throw prepareIOException("Failed to create document", e);
         }
     }
 
@@ -120,8 +118,7 @@ public final class XMLUtil {
             DocumentBuilder builder = builderFactory.newDocumentBuilder();
             return builder.parse(fileName);
         } catch (Exception e) {
-            IOException thrown = new IOException(e.getMessage());
-            throw thrown;
+        	throw prepareIOException("Failed to create document", e);
         }
     }
 
@@ -140,8 +137,7 @@ public final class XMLUtil {
             DocumentBuilder builder = builderFactory.newDocumentBuilder();
             return builder.newDocument();
         } catch (Exception e) {
-            IOException thrown = new IOException(e.getMessage());
-            throw thrown;
+        	throw prepareIOException("Failed to create document", e);
         }
     }
 
@@ -404,4 +400,11 @@ public final class XMLUtil {
         transformer.transform(source, result);
         return writer.getBuffer().toString().getBytes();
     }
+    
+    // TODO : remove this in java 6 (when constructor with message and cause will be added)
+    private static IOException prepareIOException (String message, Throwable cause) {
+    	IOException e = new IOException(message);
+    	e.initCause(cause);
+    	return e;
+    }
 }

Modified: pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/parser/XMLValueTypeDescriptionManager.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/parser/XMLValueTypeDescriptionManager.java?rev=1355867&r1=1355866&r2=1355867&view=diff
==============================================================================
--- pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/parser/XMLValueTypeDescriptionManager.java (original)
+++ pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/parser/XMLValueTypeDescriptionManager.java Sun Jul  1 10:17:25 2012
@@ -168,7 +168,7 @@ public class XMLValueTypeDescriptionMana
 		} catch (Exception e) {
 			throw new BuildPDFAExtensionSchemaDescriptionException(
 					"Failed to get correct valuetypes descriptions from specified XML stream",
-					e.getCause());
+					e);
 		} finally {
 			IOUtils.closeQuietly(is);
 		}

Modified: pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/parser/XMPDocumentBuilder.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/parser/XMPDocumentBuilder.java?rev=1355867&r1=1355866&r2=1355867&view=diff
==============================================================================
--- pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/parser/XMPDocumentBuilder.java (original)
+++ pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/parser/XMPDocumentBuilder.java Sun Jul  1 10:17:25 2012
@@ -340,7 +340,7 @@ public class XMPDocumentBuilder {
 		} catch (NoSuchElementException e) {
 			// unexpected end of stream
 			throw new XmpParsingException(
-					"XMP Stream did not end in a good way, invalid content");
+					"XMP Stream did not end in a good way, invalid content",e);
 		}
 	}
 
@@ -369,7 +369,7 @@ public class XMPDocumentBuilder {
 		} catch (NoSuchElementException e) {
 			// unexpected end of stream
 			throw new XmpParsingException(
-					"XMP Stream did not end in a good way, invalid content");
+					"XMP Stream did not end in a good way, invalid content",e);
 		}
 	}
 
@@ -715,8 +715,6 @@ public class XMPDocumentBuilder {
 				fillSchemaDescription(desc, metadata);  
 				// read the end tag
 				reader.get().nextTag();
-			} else {
-				// ?? TODO
 			}
 		}
 
@@ -739,10 +737,12 @@ public class XMPDocumentBuilder {
 							.getPrefix(), reader.get().getLocalName(), reader
 							.get().getElementText()));
 				} catch (IllegalArgumentException e) {
+					StringBuilder message = new StringBuilder(50);
+					message.append("Unexpected value for '");
+					message.append(reader.get().getLocalName()).append("' property");
 					throw new XmpPropertyFormatException(
-							"Unexpected value for '"
-									+ reader.get().getLocalName()
-									+ "' property");
+							message.toString(),e
+							);
 				}
 			} else if (reader.get().getLocalName().equals("property")) {
 				parsePropertyDefinition(desc);
@@ -907,8 +907,6 @@ public class XMPDocumentBuilder {
 					fillDescription(desc);  
 					// read the end tag
 					reader.get().nextTag();
-				} else {
-					// ?? TODO
 				}
 			}
 			// expectNextTag(XMLStreamReader.END_ELEMENT,"Expected element end");
@@ -1021,7 +1019,7 @@ public class XMPDocumentBuilder {
 	 *             When error during reading the rest of xmp stream
 	 */
 	protected void parseXmpSimpleProperty(XMPMetadata metadata,	QName propertyName, XmpPropertyType stype, ComplexPropertyContainer container)	
-					throws XmpUnknownPropertyTypeException, XmpPropertyFormatException,	XMLStreamException {
+			throws XmpUnknownPropertyTypeException, XmpPropertyFormatException,	XMLStreamException {
 		try {
 			AbstractSimpleProperty prop = null;
 			ArrayList<Attribute> attributes = new ArrayList<Attribute>();

Added: pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/ResourceEventType.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/ResourceEventType.java?rev=1355867&view=auto
==============================================================================
--- pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/ResourceEventType.java (added)
+++ pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/ResourceEventType.java Sun Jul  1 10:17:25 2012
@@ -0,0 +1,151 @@
+/*****************************************************************************
+ * 
+ * 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.type;
+
+import java.util.Calendar;
+
+import org.apache.padaf.xmpbox.XMPMetadata;
+import org.apache.padaf.xmpbox.schema.XMPSchema;
+
+public class ResourceEventType extends ComplexPropertyContainer {
+
+	public static final String ELEMENT_NS = "http://ns.adobe.com/xap/1.0/sType/ResourceEvent#";
+
+	public static final String PREFERRED_PREFIX = "stEvt";
+	
+	protected XMPMetadata metadata;
+	
+	public static final String ACTION = "action";
+
+	public static final String CHANGED = "changed";
+
+	public static final String INSTANCE_ID = "instanceID";
+	
+	public static final String PARAMETERS = "parameters";
+	
+	public static final String SOFTWARE_AGENT = "softwareAgent";
+
+	public static final String WHEN = "when";
+	
+
+	/**
+	 * 
+	 * @param metadata
+	 *            The metadata to attach to this property
+	 * @param namespace
+	 *            the namespace URI to associate to this property
+	 * @param prefix
+	 *            The prefix to set for this property
+	 * @param propertyName
+	 *            The local Name of this thumbnail type
+	 */
+	public ResourceEventType(XMPMetadata metadata, String namespace, String prefix,
+			String propertyName) {
+		super(metadata, namespace, prefix, propertyName);
+		this.metadata = metadata;
+		setAttribute(new Attribute(XMPSchema.NS_NAMESPACE, "xmlns", PREFERRED_PREFIX, ELEMENT_NS));
+	}
+	
+	
+	public String getInstanceID () {
+		TextType absProp = (TextType)getFirstEquivalentProperty(INSTANCE_ID,TextType.class);
+		if (absProp != null) {
+			return absProp.getStringValue();
+		} else {
+			return null;
+		}
+	}
+
+	public void setInstanceID (String value) {
+		this.addProperty(new TextType(metadata, PREFERRED_PREFIX, INSTANCE_ID, value));
+	}
+
+	public String getSoftwareAgent () {
+		TextType absProp = (TextType)getFirstEquivalentProperty(SOFTWARE_AGENT,TextType.class);
+		if (absProp != null) {
+			return absProp.getStringValue();
+		} else {
+			return null;
+		}
+	}
+
+	public void setSoftwareAgent (String value) {
+		this.addProperty(new TextType(metadata, PREFERRED_PREFIX, SOFTWARE_AGENT, value));
+	}
+
+	public Calendar getWhen () {
+		DateType absProp = (DateType)getFirstEquivalentProperty(WHEN,DateType.class);
+		if (absProp != null) {
+			return absProp.getValue();
+		} else {
+			return null;
+		}
+	}
+
+	public void setWhen (Calendar value) {
+		this.addProperty(new DateType(metadata, PREFERRED_PREFIX, WHEN, value));
+	}
+
+	public String getAction () {
+		TextType absProp = (TextType)getFirstEquivalentProperty(ACTION,TextType.class);
+		if (absProp != null) {
+			return absProp.getStringValue();
+		} else {
+			return null;
+		}
+	}
+
+	public void setAction (String value) {
+		this.addProperty(new TextType(metadata, PREFERRED_PREFIX, ACTION, value));
+	}
+
+	
+	public String getChanged () {
+		TextType absProp = (TextType)getFirstEquivalentProperty(CHANGED,TextType.class);
+		if (absProp != null) {
+			return absProp.getStringValue();
+		} else {
+			return null;
+		}
+	}
+
+	public void setChanged (String value) {
+		this.addProperty(new TextType(metadata, PREFERRED_PREFIX, CHANGED, value));
+	}
+
+	public String getParameters () {
+		TextType absProp = (TextType)getFirstEquivalentProperty(PARAMETERS,TextType.class);
+		if (absProp != null) {
+			return absProp.getStringValue();
+		} else {
+			return null;
+		}
+	}
+
+	public void setParameters (String value) {
+		this.addProperty(new TextType(metadata, PREFERRED_PREFIX, PARAMETERS, value));
+	}
+
+
+
+	
+}

Added: pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/VersionType.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/VersionType.java?rev=1355867&view=auto
==============================================================================
--- pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/VersionType.java (added)
+++ pdfbox/trunk/xmpbox/src/main/java/org/apache/padaf/xmpbox/type/VersionType.java Sun Jul  1 10:17:25 2012
@@ -0,0 +1,130 @@
+/*****************************************************************************
+ * 
+ * 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.type;
+
+import java.util.Calendar;
+
+import org.apache.padaf.xmpbox.XMPMetadata;
+import org.apache.padaf.xmpbox.schema.XMPSchema;
+
+public class VersionType extends ComplexPropertyContainer {
+
+	public static final String ELEMENT_NS = "http://ns.adobe.com/xap/1.0/sType/Version#";
+
+	public static final String PREFERRED_PREFIX = "stVer";
+	
+	protected XMPMetadata metadata;
+	
+	public static final String COMMENTS = "comments";
+
+	public static final String EVENT = "event";
+
+	public static final String MODIFIER = "modifier";
+	
+	public static final String MODIFY_DATE = "modifyDate";
+	
+	public static final String VERSION = "version";
+
+
+	/**
+	 * 
+	 * @param metadata
+	 *            The metadata to attach to this property
+	 * @param namespace
+	 *            the namespace URI to associate to this property
+	 * @param prefix
+	 *            The prefix to set for this property
+	 * @param propertyName
+	 *            The local Name of this thumbnail type
+	 */
+	public VersionType(XMPMetadata metadata, String namespace, String prefix,
+			String propertyName) {
+		super(metadata, namespace, prefix, propertyName);
+		this.metadata = metadata;
+		setAttribute(new Attribute(XMPSchema.NS_NAMESPACE, "xmlns", PREFERRED_PREFIX, ELEMENT_NS));
+	}
+	
+	
+	public String getComments() {
+		TextType absProp = (TextType)getFirstEquivalentProperty(COMMENTS,TextType.class);
+		if (absProp != null) {
+			return absProp.getStringValue();
+		} else {
+			return null;
+		}
+	}
+
+	public void setComments (String value) {
+		this.addProperty(new TextType(metadata, PREFERRED_PREFIX, COMMENTS, value));
+	}
+
+	public ResourceEventType getEvent () {
+//		ResourceEventType event = (ResourceEventType)getPropertiesByLocalName(EVENT);
+		return (ResourceEventType)getFirstEquivalentProperty(EVENT,ResourceEventType.class);
+	}
+
+	public void setEvent (ResourceEventType value) {
+		this.addProperty(value);
+	}
+
+	public Calendar getModifyDate () {
+		DateType absProp = (DateType)getFirstEquivalentProperty(MODIFY_DATE,DateType.class);
+		if (absProp != null) {
+			return absProp.getValue();
+		} else {
+			return null;
+		}
+	}
+
+	public void setModifyDate (Calendar value) {
+		this.addProperty(new DateType(metadata, PREFERRED_PREFIX, MODIFY_DATE, value));
+	}
+
+	public String getVersion () {
+		TextType absProp = (TextType)getFirstEquivalentProperty(VERSION,TextType.class);
+		if (absProp != null) {
+			return absProp.getStringValue();
+		} else {
+			return null;
+		}
+	}
+
+	public void setVersion (String value) {
+		this.addProperty(new TextType(metadata, PREFERRED_PREFIX, VERSION, value));
+	}
+
+	public String getModifier () {
+		TextType absProp = (TextType)getFirstEquivalentProperty(MODIFIER,TextType.class);
+		if (absProp != null) {
+			return absProp.getStringValue();
+		} else {
+			return null;
+		}
+	}
+
+	public void setModifier (String value) {
+		this.addProperty(new TextType(metadata, PREFERRED_PREFIX, MODIFIER, value));
+	}
+
+
+	
+}

Modified: pdfbox/trunk/xmpbox/src/test/java/org/apache/padaf/xmpbox/schema/AbstractXMPSchemaTest.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/xmpbox/src/test/java/org/apache/padaf/xmpbox/schema/AbstractXMPSchemaTest.java?rev=1355867&r1=1355866&r2=1355867&view=diff
==============================================================================
--- pdfbox/trunk/xmpbox/src/test/java/org/apache/padaf/xmpbox/schema/AbstractXMPSchemaTest.java (original)
+++ pdfbox/trunk/xmpbox/src/test/java/org/apache/padaf/xmpbox/schema/AbstractXMPSchemaTest.java Sun Jul  1 10:17:25 2012
@@ -301,7 +301,7 @@ public abstract class AbstractXMPSchemaT
 		String getName = getMethod(property);
 
 		TextType tt = new TextType(metadata, schema.getLocalPrefix(), property,
-				value);
+				(String)value);
 		Method setMethod = schemaClass.getMethod(setName, TextType.class);
 		Method getMethod = schemaClass.getMethod(getName);