poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r776607 [4/7] - in /poi/trunk/src/ooxml/java/org/apache/poi: ./ openxml4j/exceptions/ openxml4j/opc/ openxml4j/opc/internal/ openxml4j/opc/internal/marshallers/ openxml4j/opc/internal/signature/ openxml4j/opc/internal/unmarshallers/ openxml...
Date Wed, 20 May 2009 08:02:37 GMT
Modified: poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/marshallers/PackagePropertiesMarshaller.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/marshallers/PackagePropertiesMarshaller.java?rev=776607&r1=776606&r2=776607&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/marshallers/PackagePropertiesMarshaller.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/marshallers/PackagePropertiesMarshaller.java Wed May 20 08:02:35 2009
@@ -1,434 +1,433 @@
-/* ====================================================================
-   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.poi.openxml4j.opc.internal.marshallers;
-
-import java.io.OutputStream;
-
-import org.dom4j.Document;
-import org.dom4j.DocumentHelper;
-import org.dom4j.Element;
-import org.dom4j.Namespace;
-import org.dom4j.QName;
-import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
-import org.apache.poi.openxml4j.opc.PackagePart;
-import org.apache.poi.openxml4j.opc.internal.PackagePropertiesPart;
-import org.apache.poi.openxml4j.opc.internal.PartMarshaller;
-
-/**
- * Package properties marshaller.
- * 
- * @author CDubet, Julien Chable
- * @version 1.0
- */
-public class PackagePropertiesMarshaller implements PartMarshaller {
-
-	private final static Namespace namespaceDC = new Namespace("dc",
-			PackagePropertiesPart.NAMESPACE_DC_URI);
-
-	private final static Namespace namespaceCoreProperties = new Namespace("",
-			PackagePropertiesPart.NAMESPACE_CP_URI);
-
-	private final static Namespace namespaceDcTerms = new Namespace("dcterms",
-			PackagePropertiesPart.NAMESPACE_DCTERMS_URI);
-
-	private final static Namespace namespaceXSI = new Namespace("xsi",
-			PackagePropertiesPart.NAMESPACE_XSI_URI);
-
-	protected static final String KEYWORD_CATEGORY = "category";
-
-	protected static final String KEYWORD_CONTENT_STATUS = "contentStatus";
-
-	protected static final String KEYWORD_CONTENT_TYPE = "contentType";
-
-	protected static final String KEYWORD_CREATED = "created";
-
-	protected static final String KEYWORD_CREATOR = "creator";
-
-	protected static final String KEYWORD_DESCRIPTION = "description";
-
-	protected static final String KEYWORD_IDENTIFIER = "identifier";
-
-	protected static final String KEYWORD_KEYWORDS = "keywords";
-
-	protected static final String KEYWORD_LANGUAGE = "language";
-
-	protected static final String KEYWORD_LAST_MODIFIED_BY = "lastModifiedBy";
-
-	protected static final String KEYWORD_LAST_PRINTED = "lastPrinted";
-
-	protected static final String KEYWORD_MODIFIED = "modified";
-
-	protected static final String KEYWORD_REVISION = "revision";
-
-	protected static final String KEYWORD_SUBJECT = "subject";
-
-	protected static final String KEYWORD_TITLE = "title";
-
-	protected static final String KEYWORD_VERSION = "version";
-
-	PackagePropertiesPart propsPart;
-
-	// The document
-	Document xmlDoc = null;
-
-	/**
-	 * Marshall package core properties to an XML document. Always return
-	 * <code>true</code>.
-	 */
-	public boolean marshall(PackagePart part, OutputStream out)
-			throws OpenXML4JException {
-		if (!(part instanceof PackagePropertiesPart))
-			throw new IllegalArgumentException(
-					"'part' must be a PackagePropertiesPart instance.");
-		propsPart = (PackagePropertiesPart) part;
-
-		// Configure the document
-		xmlDoc = DocumentHelper.createDocument();
-		Element rootElem = xmlDoc.addElement(new QName("coreProperties",
-				namespaceCoreProperties));
-		rootElem.addNamespace("cp", PackagePropertiesPart.NAMESPACE_CP_URI);
-		rootElem.addNamespace("dc", PackagePropertiesPart.NAMESPACE_DC_URI);
-		rootElem.addNamespace("dcterms",
-				PackagePropertiesPart.NAMESPACE_DCTERMS_URI);
-		rootElem.addNamespace("xsi", PackagePropertiesPart.NAMESPACE_XSI_URI);
-
-		addCategory();
-		addContentStatus();
-		addContentType();
-		addCreated();
-		addCreator();
-		addDescription();
-		addIdentifier();
-		addKeywords();
-		addLanguage();
-		addLastModifiedBy();
-		addLastPrinted();
-		addModified();
-		addRevision();
-		addSubject();
-		addTitle();
-		addVersion();
-		return true;
-	}
-
-	/**
-	 * Add category property element if needed.
-	 */
-	private void addCategory() {
-		if (!propsPart.getCategoryProperty().hasValue())
-			return;
-
-		Element elem = xmlDoc.getRootElement().element(
-				new QName(KEYWORD_CATEGORY, namespaceCoreProperties));
-		if (elem == null) {
-			// Missing, we add it
-			elem = xmlDoc.getRootElement().addElement(
-					new QName(KEYWORD_CATEGORY, namespaceCoreProperties));
-		} else {
-			elem.clearContent();// clear the old value
-		}
-		elem.addText(propsPart.getCategoryProperty().getValue());
-	}
-
-	/**
-	 * Add content status property element if needed.
-	 */
-	private void addContentStatus() {
-		if (!propsPart.getContentStatusProperty().hasValue())
-			return;
-
-		Element elem = xmlDoc.getRootElement().element(
-				new QName(KEYWORD_CONTENT_STATUS, namespaceCoreProperties));
-		if (elem == null) {
-			// Missing, we add it
-			elem = xmlDoc.getRootElement().addElement(
-					new QName(KEYWORD_CONTENT_STATUS, namespaceCoreProperties));
-		} else {
-			elem.clearContent();// clear the old value
-		}
-		elem.addText(propsPart.getContentStatusProperty().getValue());
-	}
-
-	/**
-	 * Add content type property element if needed.
-	 */
-	private void addContentType() {
-		if (!propsPart.getContentTypeProperty().hasValue())
-			return;
-
-		Element elem = xmlDoc.getRootElement().element(
-				new QName(KEYWORD_CONTENT_TYPE, namespaceCoreProperties));
-		if (elem == null) {
-			// Missing, we add it
-			elem = xmlDoc.getRootElement().addElement(
-					new QName(KEYWORD_CONTENT_TYPE, namespaceCoreProperties));
-		} else {
-			elem.clearContent();// clear the old value
-		}
-		elem.addText(propsPart.getContentTypeProperty().getValue());
-	}
-
-	/**
-	 * Add created property element if needed.
-	 */
-	private void addCreated() {
-		if (!propsPart.getCreatedProperty().hasValue())
-			return;
-
-		Element elem = xmlDoc.getRootElement().element(
-				new QName(KEYWORD_CREATED, namespaceDcTerms));
-		if (elem == null) {
-			// missing, we add it
-			elem = xmlDoc.getRootElement().addElement(
-					new QName(KEYWORD_CREATED, namespaceDcTerms));
-		} else {
-			elem.clearContent();// clear the old value
-		}
-		elem.addAttribute(new QName("type", namespaceXSI), "dcterms:W3CDTF");
-		elem.addText(propsPart.getCreatedPropertyString());
-	}
-
-	/**
-	 * Add creator property element if needed.
-	 */
-	private void addCreator() {
-		if (!propsPart.getCreatorProperty().hasValue())
-			return;
-
-		Element elem = xmlDoc.getRootElement().element(
-				new QName(KEYWORD_CREATOR, namespaceDC));
-		if (elem == null) {
-			// missing, we add it
-			elem = xmlDoc.getRootElement().addElement(
-					new QName(KEYWORD_CREATOR, namespaceDC));
-		} else {
-			elem.clearContent();// clear the old value
-		}
-		elem.addText(propsPart.getCreatorProperty().getValue());
-	}
-
-	/**
-	 * Add description property element if needed.
-	 */
-	private void addDescription() {
-		if (!propsPart.getDescriptionProperty().hasValue())
-			return;
-
-		Element elem = xmlDoc.getRootElement().element(
-				new QName(KEYWORD_DESCRIPTION, namespaceDC));
-		if (elem == null) {
-			// missing, we add it
-			elem = xmlDoc.getRootElement().addElement(
-					new QName(KEYWORD_DESCRIPTION, namespaceDC));
-		} else {
-			elem.clearContent();// clear the old value
-		}
-		elem.addText(propsPart.getDescriptionProperty().getValue());
-	}
-
-	/**
-	 * Add identifier property element if needed.
-	 */
-	private void addIdentifier() {
-		if (!propsPart.getIdentifierProperty().hasValue())
-			return;
-
-		Element elem = xmlDoc.getRootElement().element(
-				new QName(KEYWORD_IDENTIFIER, namespaceDC));
-		if (elem == null) {
-			// missing, we add it
-			elem = xmlDoc.getRootElement().addElement(
-					new QName(KEYWORD_IDENTIFIER, namespaceDC));
-		} else {
-			elem.clearContent();// clear the old value
-		}
-		elem.addText(propsPart.getIdentifierProperty().getValue());
-	}
-
-	/**
-	 * Add keywords property element if needed.
-	 */
-	private void addKeywords() {
-		if (!propsPart.getKeywordsProperty().hasValue())
-			return;
-
-		Element elem = xmlDoc.getRootElement().element(
-				new QName(KEYWORD_KEYWORDS, namespaceCoreProperties));
-		if (elem == null) {
-			// missing, we add it
-			elem = xmlDoc.getRootElement().addElement(
-					new QName(KEYWORD_KEYWORDS, namespaceCoreProperties));
-		} else {
-			elem.clearContent();// clear the old value
-		}
-		elem.addText(propsPart.getKeywordsProperty().getValue());
-	}
-
-	/**
-	 * Add language property element if needed.
-	 */
-	private void addLanguage() {
-		if (!propsPart.getLanguageProperty().hasValue())
-			return;
-
-		Element elem = xmlDoc.getRootElement().element(
-				new QName(KEYWORD_LANGUAGE, namespaceDC));
-		if (elem == null) {
-			// missing, we add it
-			elem = xmlDoc.getRootElement().addElement(
-					new QName(KEYWORD_LANGUAGE, namespaceDC));
-		} else {
-			elem.clearContent();// clear the old value
-		}
-		elem.addText(propsPart.getLanguageProperty().getValue());
-	}
-
-	/**
-	 * Add 'last modified by' property if needed.
-	 */
-	private void addLastModifiedBy() {
-		if (!propsPart.getLastModifiedByProperty().hasValue())
-			return;
-
-		Element elem = xmlDoc.getRootElement().element(
-				new QName(KEYWORD_LAST_MODIFIED_BY, namespaceCoreProperties));
-		if (elem == null) {
-			// missing, we add it
-			elem = xmlDoc.getRootElement()
-					.addElement(
-							new QName(KEYWORD_LAST_MODIFIED_BY,
-									namespaceCoreProperties));
-		} else {
-			elem.clearContent();// clear the old value
-		}
-		elem.addText(propsPart.getLastModifiedByProperty().getValue());
-	}
-
-	/**
-	 * Add 'last printed' property if needed.
-	 * 
-	 */
-	private void addLastPrinted() {
-		if (!propsPart.getLastPrintedProperty().hasValue())
-			return;
-
-		Element elem = xmlDoc.getRootElement().element(
-				new QName(KEYWORD_LAST_PRINTED, namespaceCoreProperties));
-		if (elem == null) {
-			// missing, we add it
-			elem = xmlDoc.getRootElement().addElement(
-					new QName(KEYWORD_LAST_PRINTED, namespaceCoreProperties));
-		} else {
-			elem.clearContent();// clear the old value
-		}
-		elem.addText(propsPart.getLastPrintedPropertyString());
-	}
-
-	/**
-	 * Add modified property element if needed.
-	 */
-	private void addModified() {
-		if (!propsPart.getModifiedProperty().hasValue())
-			return;
-
-		Element elem = xmlDoc.getRootElement().element(
-				new QName(KEYWORD_MODIFIED, namespaceDcTerms));
-		if (elem == null) {
-			// missing, we add it
-			elem = xmlDoc.getRootElement().addElement(
-					new QName(KEYWORD_MODIFIED, namespaceDcTerms));
-		} else {
-			elem.clearContent();// clear the old value
-		}
-		elem.addAttribute(new QName("type", namespaceXSI), "dcterms:W3CDTF");
-		elem.addText(propsPart.getModifiedPropertyString());
-	}
-
-	/**
-	 * Add revision property if needed.
-	 */
-	private void addRevision() {
-		if (!propsPart.getRevisionProperty().hasValue())
-			return;
-
-		Element elem = xmlDoc.getRootElement().element(
-				new QName(KEYWORD_REVISION, namespaceCoreProperties));
-		if (elem == null) {
-			// missing, we add it
-			elem = xmlDoc.getRootElement().addElement(
-					new QName(KEYWORD_REVISION, namespaceCoreProperties));
-		} else {
-			elem.clearContent();// clear the old value
-		}
-		elem.addText(propsPart.getRevisionProperty().getValue());
-	}
-
-	/**
-	 * Add subject property if needed.
-	 */
-	private void addSubject() {
-		if (!propsPart.getSubjectProperty().hasValue())
-			return;
-
-		Element elem = xmlDoc.getRootElement().element(
-				new QName(KEYWORD_SUBJECT, namespaceDC));
-		if (elem == null) {
-			// missing, we add it
-			elem = xmlDoc.getRootElement().addElement(
-					new QName(KEYWORD_SUBJECT, namespaceDC));
-		} else {
-			elem.clearContent();// clear the old value
-		}
-		elem.addText(propsPart.getSubjectProperty().getValue());
-	}
-
-	/**
-	 * Add title property if needed.
-	 */
-	private void addTitle() {
-		if (!propsPart.getTitleProperty().hasValue())
-			return;
-
-		Element elem = xmlDoc.getRootElement().element(
-				new QName(KEYWORD_TITLE, namespaceDC));
-		if (elem == null) {
-			// missing, we add it
-			elem = xmlDoc.getRootElement().addElement(
-					new QName(KEYWORD_TITLE, namespaceDC));
-		} else {
-			elem.clearContent();// clear the old value
-		}
-		elem.addText(propsPart.getTitleProperty().getValue());
-	}
-
-	private void addVersion() {
-		if (!propsPart.getVersionProperty().hasValue())
-			return;
-
-		Element elem = xmlDoc.getRootElement().element(
-				new QName(KEYWORD_VERSION, namespaceCoreProperties));
-		if (elem == null) {
-			// missing, we add it
-			elem = xmlDoc.getRootElement().addElement(
-					new QName(KEYWORD_VERSION, namespaceCoreProperties));
-		} else {
-			elem.clearContent();// clear the old value
-		}
-		elem.addText(propsPart.getVersionProperty().getValue());
-	}
-}
+/* ====================================================================
+   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.poi.openxml4j.opc.internal.marshallers;
+
+import java.io.OutputStream;
+
+import org.dom4j.Document;
+import org.dom4j.DocumentHelper;
+import org.dom4j.Element;
+import org.dom4j.Namespace;
+import org.dom4j.QName;
+import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
+import org.apache.poi.openxml4j.opc.PackagePart;
+import org.apache.poi.openxml4j.opc.internal.PackagePropertiesPart;
+import org.apache.poi.openxml4j.opc.internal.PartMarshaller;
+
+/**
+ * Package properties marshaller.
+ *
+ * @author CDubet, Julien Chable
+ */
+public class PackagePropertiesMarshaller implements PartMarshaller {
+
+	private final static Namespace namespaceDC = new Namespace("dc",
+			PackagePropertiesPart.NAMESPACE_DC_URI);
+
+	private final static Namespace namespaceCoreProperties = new Namespace("",
+			PackagePropertiesPart.NAMESPACE_CP_URI);
+
+	private final static Namespace namespaceDcTerms = new Namespace("dcterms",
+			PackagePropertiesPart.NAMESPACE_DCTERMS_URI);
+
+	private final static Namespace namespaceXSI = new Namespace("xsi",
+			PackagePropertiesPart.NAMESPACE_XSI_URI);
+
+	protected static final String KEYWORD_CATEGORY = "category";
+
+	protected static final String KEYWORD_CONTENT_STATUS = "contentStatus";
+
+	protected static final String KEYWORD_CONTENT_TYPE = "contentType";
+
+	protected static final String KEYWORD_CREATED = "created";
+
+	protected static final String KEYWORD_CREATOR = "creator";
+
+	protected static final String KEYWORD_DESCRIPTION = "description";
+
+	protected static final String KEYWORD_IDENTIFIER = "identifier";
+
+	protected static final String KEYWORD_KEYWORDS = "keywords";
+
+	protected static final String KEYWORD_LANGUAGE = "language";
+
+	protected static final String KEYWORD_LAST_MODIFIED_BY = "lastModifiedBy";
+
+	protected static final String KEYWORD_LAST_PRINTED = "lastPrinted";
+
+	protected static final String KEYWORD_MODIFIED = "modified";
+
+	protected static final String KEYWORD_REVISION = "revision";
+
+	protected static final String KEYWORD_SUBJECT = "subject";
+
+	protected static final String KEYWORD_TITLE = "title";
+
+	protected static final String KEYWORD_VERSION = "version";
+
+	PackagePropertiesPart propsPart;
+
+	// The document
+	Document xmlDoc = null;
+
+	/**
+	 * Marshall package core properties to an XML document. Always return
+	 * <code>true</code>.
+	 */
+	public boolean marshall(PackagePart part, OutputStream out)
+			throws OpenXML4JException {
+		if (!(part instanceof PackagePropertiesPart))
+			throw new IllegalArgumentException(
+					"'part' must be a PackagePropertiesPart instance.");
+		propsPart = (PackagePropertiesPart) part;
+
+		// Configure the document
+		xmlDoc = DocumentHelper.createDocument();
+		Element rootElem = xmlDoc.addElement(new QName("coreProperties",
+				namespaceCoreProperties));
+		rootElem.addNamespace("cp", PackagePropertiesPart.NAMESPACE_CP_URI);
+		rootElem.addNamespace("dc", PackagePropertiesPart.NAMESPACE_DC_URI);
+		rootElem.addNamespace("dcterms",
+				PackagePropertiesPart.NAMESPACE_DCTERMS_URI);
+		rootElem.addNamespace("xsi", PackagePropertiesPart.NAMESPACE_XSI_URI);
+
+		addCategory();
+		addContentStatus();
+		addContentType();
+		addCreated();
+		addCreator();
+		addDescription();
+		addIdentifier();
+		addKeywords();
+		addLanguage();
+		addLastModifiedBy();
+		addLastPrinted();
+		addModified();
+		addRevision();
+		addSubject();
+		addTitle();
+		addVersion();
+		return true;
+	}
+
+	/**
+	 * Add category property element if needed.
+	 */
+	private void addCategory() {
+		if (!propsPart.getCategoryProperty().hasValue())
+			return;
+
+		Element elem = xmlDoc.getRootElement().element(
+				new QName(KEYWORD_CATEGORY, namespaceCoreProperties));
+		if (elem == null) {
+			// Missing, we add it
+			elem = xmlDoc.getRootElement().addElement(
+					new QName(KEYWORD_CATEGORY, namespaceCoreProperties));
+		} else {
+			elem.clearContent();// clear the old value
+		}
+		elem.addText(propsPart.getCategoryProperty().getValue());
+	}
+
+	/**
+	 * Add content status property element if needed.
+	 */
+	private void addContentStatus() {
+		if (!propsPart.getContentStatusProperty().hasValue())
+			return;
+
+		Element elem = xmlDoc.getRootElement().element(
+				new QName(KEYWORD_CONTENT_STATUS, namespaceCoreProperties));
+		if (elem == null) {
+			// Missing, we add it
+			elem = xmlDoc.getRootElement().addElement(
+					new QName(KEYWORD_CONTENT_STATUS, namespaceCoreProperties));
+		} else {
+			elem.clearContent();// clear the old value
+		}
+		elem.addText(propsPart.getContentStatusProperty().getValue());
+	}
+
+	/**
+	 * Add content type property element if needed.
+	 */
+	private void addContentType() {
+		if (!propsPart.getContentTypeProperty().hasValue())
+			return;
+
+		Element elem = xmlDoc.getRootElement().element(
+				new QName(KEYWORD_CONTENT_TYPE, namespaceCoreProperties));
+		if (elem == null) {
+			// Missing, we add it
+			elem = xmlDoc.getRootElement().addElement(
+					new QName(KEYWORD_CONTENT_TYPE, namespaceCoreProperties));
+		} else {
+			elem.clearContent();// clear the old value
+		}
+		elem.addText(propsPart.getContentTypeProperty().getValue());
+	}
+
+	/**
+	 * Add created property element if needed.
+	 */
+	private void addCreated() {
+		if (!propsPart.getCreatedProperty().hasValue())
+			return;
+
+		Element elem = xmlDoc.getRootElement().element(
+				new QName(KEYWORD_CREATED, namespaceDcTerms));
+		if (elem == null) {
+			// missing, we add it
+			elem = xmlDoc.getRootElement().addElement(
+					new QName(KEYWORD_CREATED, namespaceDcTerms));
+		} else {
+			elem.clearContent();// clear the old value
+		}
+		elem.addAttribute(new QName("type", namespaceXSI), "dcterms:W3CDTF");
+		elem.addText(propsPart.getCreatedPropertyString());
+	}
+
+	/**
+	 * Add creator property element if needed.
+	 */
+	private void addCreator() {
+		if (!propsPart.getCreatorProperty().hasValue())
+			return;
+
+		Element elem = xmlDoc.getRootElement().element(
+				new QName(KEYWORD_CREATOR, namespaceDC));
+		if (elem == null) {
+			// missing, we add it
+			elem = xmlDoc.getRootElement().addElement(
+					new QName(KEYWORD_CREATOR, namespaceDC));
+		} else {
+			elem.clearContent();// clear the old value
+		}
+		elem.addText(propsPart.getCreatorProperty().getValue());
+	}
+
+	/**
+	 * Add description property element if needed.
+	 */
+	private void addDescription() {
+		if (!propsPart.getDescriptionProperty().hasValue())
+			return;
+
+		Element elem = xmlDoc.getRootElement().element(
+				new QName(KEYWORD_DESCRIPTION, namespaceDC));
+		if (elem == null) {
+			// missing, we add it
+			elem = xmlDoc.getRootElement().addElement(
+					new QName(KEYWORD_DESCRIPTION, namespaceDC));
+		} else {
+			elem.clearContent();// clear the old value
+		}
+		elem.addText(propsPart.getDescriptionProperty().getValue());
+	}
+
+	/**
+	 * Add identifier property element if needed.
+	 */
+	private void addIdentifier() {
+		if (!propsPart.getIdentifierProperty().hasValue())
+			return;
+
+		Element elem = xmlDoc.getRootElement().element(
+				new QName(KEYWORD_IDENTIFIER, namespaceDC));
+		if (elem == null) {
+			// missing, we add it
+			elem = xmlDoc.getRootElement().addElement(
+					new QName(KEYWORD_IDENTIFIER, namespaceDC));
+		} else {
+			elem.clearContent();// clear the old value
+		}
+		elem.addText(propsPart.getIdentifierProperty().getValue());
+	}
+
+	/**
+	 * Add keywords property element if needed.
+	 */
+	private void addKeywords() {
+		if (!propsPart.getKeywordsProperty().hasValue())
+			return;
+
+		Element elem = xmlDoc.getRootElement().element(
+				new QName(KEYWORD_KEYWORDS, namespaceCoreProperties));
+		if (elem == null) {
+			// missing, we add it
+			elem = xmlDoc.getRootElement().addElement(
+					new QName(KEYWORD_KEYWORDS, namespaceCoreProperties));
+		} else {
+			elem.clearContent();// clear the old value
+		}
+		elem.addText(propsPart.getKeywordsProperty().getValue());
+	}
+
+	/**
+	 * Add language property element if needed.
+	 */
+	private void addLanguage() {
+		if (!propsPart.getLanguageProperty().hasValue())
+			return;
+
+		Element elem = xmlDoc.getRootElement().element(
+				new QName(KEYWORD_LANGUAGE, namespaceDC));
+		if (elem == null) {
+			// missing, we add it
+			elem = xmlDoc.getRootElement().addElement(
+					new QName(KEYWORD_LANGUAGE, namespaceDC));
+		} else {
+			elem.clearContent();// clear the old value
+		}
+		elem.addText(propsPart.getLanguageProperty().getValue());
+	}
+
+	/**
+	 * Add 'last modified by' property if needed.
+	 */
+	private void addLastModifiedBy() {
+		if (!propsPart.getLastModifiedByProperty().hasValue())
+			return;
+
+		Element elem = xmlDoc.getRootElement().element(
+				new QName(KEYWORD_LAST_MODIFIED_BY, namespaceCoreProperties));
+		if (elem == null) {
+			// missing, we add it
+			elem = xmlDoc.getRootElement()
+					.addElement(
+							new QName(KEYWORD_LAST_MODIFIED_BY,
+									namespaceCoreProperties));
+		} else {
+			elem.clearContent();// clear the old value
+		}
+		elem.addText(propsPart.getLastModifiedByProperty().getValue());
+	}
+
+	/**
+	 * Add 'last printed' property if needed.
+	 *
+	 */
+	private void addLastPrinted() {
+		if (!propsPart.getLastPrintedProperty().hasValue())
+			return;
+
+		Element elem = xmlDoc.getRootElement().element(
+				new QName(KEYWORD_LAST_PRINTED, namespaceCoreProperties));
+		if (elem == null) {
+			// missing, we add it
+			elem = xmlDoc.getRootElement().addElement(
+					new QName(KEYWORD_LAST_PRINTED, namespaceCoreProperties));
+		} else {
+			elem.clearContent();// clear the old value
+		}
+		elem.addText(propsPart.getLastPrintedPropertyString());
+	}
+
+	/**
+	 * Add modified property element if needed.
+	 */
+	private void addModified() {
+		if (!propsPart.getModifiedProperty().hasValue())
+			return;
+
+		Element elem = xmlDoc.getRootElement().element(
+				new QName(KEYWORD_MODIFIED, namespaceDcTerms));
+		if (elem == null) {
+			// missing, we add it
+			elem = xmlDoc.getRootElement().addElement(
+					new QName(KEYWORD_MODIFIED, namespaceDcTerms));
+		} else {
+			elem.clearContent();// clear the old value
+		}
+		elem.addAttribute(new QName("type", namespaceXSI), "dcterms:W3CDTF");
+		elem.addText(propsPart.getModifiedPropertyString());
+	}
+
+	/**
+	 * Add revision property if needed.
+	 */
+	private void addRevision() {
+		if (!propsPart.getRevisionProperty().hasValue())
+			return;
+
+		Element elem = xmlDoc.getRootElement().element(
+				new QName(KEYWORD_REVISION, namespaceCoreProperties));
+		if (elem == null) {
+			// missing, we add it
+			elem = xmlDoc.getRootElement().addElement(
+					new QName(KEYWORD_REVISION, namespaceCoreProperties));
+		} else {
+			elem.clearContent();// clear the old value
+		}
+		elem.addText(propsPart.getRevisionProperty().getValue());
+	}
+
+	/**
+	 * Add subject property if needed.
+	 */
+	private void addSubject() {
+		if (!propsPart.getSubjectProperty().hasValue())
+			return;
+
+		Element elem = xmlDoc.getRootElement().element(
+				new QName(KEYWORD_SUBJECT, namespaceDC));
+		if (elem == null) {
+			// missing, we add it
+			elem = xmlDoc.getRootElement().addElement(
+					new QName(KEYWORD_SUBJECT, namespaceDC));
+		} else {
+			elem.clearContent();// clear the old value
+		}
+		elem.addText(propsPart.getSubjectProperty().getValue());
+	}
+
+	/**
+	 * Add title property if needed.
+	 */
+	private void addTitle() {
+		if (!propsPart.getTitleProperty().hasValue())
+			return;
+
+		Element elem = xmlDoc.getRootElement().element(
+				new QName(KEYWORD_TITLE, namespaceDC));
+		if (elem == null) {
+			// missing, we add it
+			elem = xmlDoc.getRootElement().addElement(
+					new QName(KEYWORD_TITLE, namespaceDC));
+		} else {
+			elem.clearContent();// clear the old value
+		}
+		elem.addText(propsPart.getTitleProperty().getValue());
+	}
+
+	private void addVersion() {
+		if (!propsPart.getVersionProperty().hasValue())
+			return;
+
+		Element elem = xmlDoc.getRootElement().element(
+				new QName(KEYWORD_VERSION, namespaceCoreProperties));
+		if (elem == null) {
+			// missing, we add it
+			elem = xmlDoc.getRootElement().addElement(
+					new QName(KEYWORD_VERSION, namespaceCoreProperties));
+		} else {
+			elem.clearContent();// clear the old value
+		}
+		elem.addText(propsPart.getVersionProperty().getValue());
+	}
+}

Modified: poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/marshallers/ZipPackagePropertiesMarshaller.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/marshallers/ZipPackagePropertiesMarshaller.java?rev=776607&r1=776606&r2=776607&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/marshallers/ZipPackagePropertiesMarshaller.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/marshallers/ZipPackagePropertiesMarshaller.java Wed May 20 08:02:35 2009
@@ -1,64 +1,63 @@
-/* ====================================================================
-   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.poi.openxml4j.opc.internal.marshallers;
-
-import java.io.IOException;
-import java.io.OutputStream;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipOutputStream;
-
-import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
-import org.apache.poi.openxml4j.opc.PackagePart;
-import org.apache.poi.openxml4j.opc.StreamHelper;
-import org.apache.poi.openxml4j.opc.internal.ZipHelper;
-
-/**
- * Package core properties marshaller specialized for zipped package.
- * 
- * @author Julien Chable
- * @version 1.0
- */
-public class ZipPackagePropertiesMarshaller extends PackagePropertiesMarshaller {
-
-	@Override
-	public boolean marshall(PackagePart part, OutputStream out)
-			throws OpenXML4JException {
-		if (!(out instanceof ZipOutputStream)) {
-			throw new IllegalArgumentException("ZipOutputStream expected!");
-		}
-		ZipOutputStream zos = (ZipOutputStream) out;
-
-		// Saving the part in the zip file
-		ZipEntry ctEntry = new ZipEntry(ZipHelper
-				.getZipItemNameFromOPCName(part.getPartName().getURI()
-						.toString()));
-		try {
-			// Save in ZIP
-			zos.putNextEntry(ctEntry); // Add entry in ZIP
-			super.marshall(part, out); // Marshall the properties inside a XML
-			// Document
-			if (!StreamHelper.saveXmlInStream(xmlDoc, out)) {
-				return false;
-			}
-			zos.closeEntry();
-		} catch (IOException e) {
-			throw new OpenXML4JException(e.getLocalizedMessage());
-		}
-		return true;
-	}
-}
+/* ====================================================================
+   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.poi.openxml4j.opc.internal.marshallers;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipOutputStream;
+
+import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
+import org.apache.poi.openxml4j.opc.PackagePart;
+import org.apache.poi.openxml4j.opc.StreamHelper;
+import org.apache.poi.openxml4j.opc.internal.ZipHelper;
+
+/**
+ * Package core properties marshaller specialized for zipped package.
+ *
+ * @author Julien Chable
+ */
+public final class ZipPackagePropertiesMarshaller extends PackagePropertiesMarshaller {
+
+	@Override
+	public boolean marshall(PackagePart part, OutputStream out)
+			throws OpenXML4JException {
+		if (!(out instanceof ZipOutputStream)) {
+			throw new IllegalArgumentException("ZipOutputStream expected!");
+		}
+		ZipOutputStream zos = (ZipOutputStream) out;
+
+		// Saving the part in the zip file
+		ZipEntry ctEntry = new ZipEntry(ZipHelper
+				.getZipItemNameFromOPCName(part.getPartName().getURI()
+						.toString()));
+		try {
+			// Save in ZIP
+			zos.putNextEntry(ctEntry); // Add entry in ZIP
+			super.marshall(part, out); // Marshall the properties inside a XML
+			// Document
+			if (!StreamHelper.saveXmlInStream(xmlDoc, out)) {
+				return false;
+			}
+			zos.closeEntry();
+		} catch (IOException e) {
+			throw new OpenXML4JException(e.getLocalizedMessage());
+		}
+		return true;
+	}
+}

Modified: poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/marshallers/ZipPartMarshaller.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/marshallers/ZipPartMarshaller.java?rev=776607&r1=776606&r2=776607&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/marshallers/ZipPartMarshaller.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/marshallers/ZipPartMarshaller.java Wed May 20 08:02:35 2009
@@ -1,193 +1,191 @@
-/* ====================================================================
-   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.poi.openxml4j.opc.internal.marshallers;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.net.URI;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipOutputStream;
-
-import org.dom4j.Document;
-import org.dom4j.DocumentHelper;
-import org.dom4j.Element;
-import org.dom4j.Namespace;
-import org.dom4j.QName;
-import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
-import org.apache.poi.openxml4j.opc.PackageNamespaces;
-import org.apache.poi.openxml4j.opc.PackagePart;
-import org.apache.poi.openxml4j.opc.PackagePartName;
-import org.apache.poi.openxml4j.opc.PackageRelationship;
-import org.apache.poi.openxml4j.opc.PackageRelationshipCollection;
-import org.apache.poi.openxml4j.opc.PackagingURIHelper;
-import org.apache.poi.openxml4j.opc.StreamHelper;
-import org.apache.poi.openxml4j.opc.TargetMode;
-import org.apache.poi.openxml4j.opc.internal.PartMarshaller;
-import org.apache.poi.openxml4j.opc.internal.ZipHelper;
-import org.apache.poi.util.POILogger;
-import org.apache.poi.util.POILogFactory;
-
-/**
- * Zip part marshaller. This marshaller is use to save any part in a zip stream.
- * 
- * @author Julien Chable
- * @version 0.1
- */
-public class ZipPartMarshaller implements PartMarshaller {
-    private static POILogger logger = POILogFactory.getLogger(ZipPartMarshaller.class);
-
-	/**
-	 * Save the specified part.
-	 * 
-	 * @throws OpenXML4JException
-	 *             Throws if an internal exception is thrown.
-	 */
-	public boolean marshall(PackagePart part, OutputStream os)
-			throws OpenXML4JException {
-		if (!(os instanceof ZipOutputStream)) {
-			logger.log(POILogger.ERROR,"Unexpected class " + os.getClass().getName());
-			throw new OpenXML4JException("ZipOutputStream expected !");
-			// Normally should happen only in developpement phase, so just throw
-			// exception
-		}
-
-		ZipOutputStream zos = (ZipOutputStream) os;
-		ZipEntry partEntry = new ZipEntry(ZipHelper
-				.getZipItemNameFromOPCName(part.getPartName().getURI()
-						.getPath()));
-		try {
-			// Create next zip entry
-			zos.putNextEntry(partEntry);
-
-			// Saving data in the ZIP file
-			InputStream ins = part.getInputStream();
-			byte[] buff = new byte[ZipHelper.READ_WRITE_FILE_BUFFER_SIZE];
-			while (ins.available() > 0) {
-				int resultRead = ins.read(buff);
-				if (resultRead == -1) {
-					// End of file reached
-					break;
-				} else {
-					zos.write(buff, 0, resultRead);
-				}
-			}
-			zos.closeEntry();
-		} catch (IOException ioe) {
-			logger.log(POILogger.ERROR,"Cannot write: " + part.getPartName() + ": in ZIP",
-					ioe);
-			return false;
-		}
-
-		// Saving relationship part
-		if (part.hasRelationships()) {
-			PackagePartName relationshipPartName = PackagingURIHelper
-					.getRelationshipPartName(part.getPartName());
-
-			marshallRelationshipPart(part.getRelationships(),
-					relationshipPartName, zos);
-
-		}
-		return true;
-	}
-
-	/**
-	 * Save relationships into the part.
-	 * 
-	 * @param rels
-	 *            The relationships collection to marshall.
-	 * @param relPartName
-	 *            Part name of the relationship part to marshall.
-	 * @param zos
-	 *            Zip output stream in which to save the XML content of the
-	 *            relationships serialization.
-	 */
-	public static boolean marshallRelationshipPart(
-			PackageRelationshipCollection rels, PackagePartName relPartName,
-			ZipOutputStream zos) {
-		// Building xml
-		Document xmlOutDoc = DocumentHelper.createDocument();
-		// make something like <Relationships
-		// xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
-		Namespace dfNs = Namespace.get("", PackageNamespaces.RELATIONSHIPS);
-		Element root = xmlOutDoc.addElement(new QName(
-				PackageRelationship.RELATIONSHIPS_TAG_NAME, dfNs));
-
-		// <Relationship
-		// TargetMode="External"
-		// Id="rIdx"
-		// Target="http://www.custom.com/images/pic1.jpg"
-		// Type="http://www.custom.com/external-resource"/>
-
-		URI sourcePartURI = PackagingURIHelper
-				.getSourcePartUriFromRelationshipPartUri(relPartName.getURI());
-
-		for (PackageRelationship rel : rels) {
-			// the relationship element
-			Element relElem = root
-					.addElement(PackageRelationship.RELATIONSHIP_TAG_NAME);
-
-			// the relationship ID
-			relElem.addAttribute(PackageRelationship.ID_ATTRIBUTE_NAME, rel
-					.getId());
-
-			// the relationship Type
-			relElem.addAttribute(PackageRelationship.TYPE_ATTRIBUTE_NAME, rel
-					.getRelationshipType());
-
-			// the relationship Target
-			String targetValue;
-			URI uri = rel.getTargetURI();
-			if (rel.getTargetMode() == TargetMode.EXTERNAL) {
-				// Save the target as-is - we don't need to validate it,
-				//  alter it etc
-                targetValue = uri.toString();
-
-				// add TargetMode attribute (as it is external link external)
-				relElem.addAttribute(
-						PackageRelationship.TARGET_MODE_ATTRIBUTE_NAME,
-						"External");
-			} else {
-				targetValue = PackagingURIHelper.relativizeURI(
-						sourcePartURI, rel.getTargetURI()).getPath();
-			}
-			relElem.addAttribute(PackageRelationship.TARGET_ATTRIBUTE_NAME,
-					targetValue);
-		}
-
-		xmlOutDoc.normalize();
-
-		// String schemaFilename = Configuration.getPathForXmlSchema()+
-		// File.separator + "opc-relationships.xsd";
-
-		// Save part in zip
-		ZipEntry ctEntry = new ZipEntry(ZipHelper.getZipURIFromOPCName(
-				relPartName.getURI().toASCIIString()).getPath());
-		try {
-			zos.putNextEntry(ctEntry);
-			if (!StreamHelper.saveXmlInStream(xmlOutDoc, zos)) {
-				return false;
-			}
-			zos.closeEntry();
-		} catch (IOException e) {
-			logger.log(POILogger.ERROR,"Cannot create zip entry " + relPartName, e);
-			return false;
-		}
-		return true; // success
-	}
-}
+/* ====================================================================
+   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.poi.openxml4j.opc.internal.marshallers;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.URI;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipOutputStream;
+
+import org.dom4j.Document;
+import org.dom4j.DocumentHelper;
+import org.dom4j.Element;
+import org.dom4j.Namespace;
+import org.dom4j.QName;
+import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
+import org.apache.poi.openxml4j.opc.PackageNamespaces;
+import org.apache.poi.openxml4j.opc.PackagePart;
+import org.apache.poi.openxml4j.opc.PackagePartName;
+import org.apache.poi.openxml4j.opc.PackageRelationship;
+import org.apache.poi.openxml4j.opc.PackageRelationshipCollection;
+import org.apache.poi.openxml4j.opc.PackagingURIHelper;
+import org.apache.poi.openxml4j.opc.StreamHelper;
+import org.apache.poi.openxml4j.opc.TargetMode;
+import org.apache.poi.openxml4j.opc.internal.PartMarshaller;
+import org.apache.poi.openxml4j.opc.internal.ZipHelper;
+import org.apache.poi.util.POILogger;
+import org.apache.poi.util.POILogFactory;
+
+/**
+ * Zip part marshaller. This marshaller is use to save any part in a zip stream.
+ *
+ * @author Julien Chable
+ */
+public final class ZipPartMarshaller implements PartMarshaller {
+	private static POILogger logger = POILogFactory.getLogger(ZipPartMarshaller.class);
+
+	/**
+	 * Save the specified part.
+	 *
+	 * @throws OpenXML4JException
+	 *             Throws if an internal exception is thrown.
+	 */
+	public boolean marshall(PackagePart part, OutputStream os)
+			throws OpenXML4JException {
+		if (!(os instanceof ZipOutputStream)) {
+			logger.log(POILogger.ERROR,"Unexpected class " + os.getClass().getName());
+			throw new OpenXML4JException("ZipOutputStream expected !");
+			// Normally should happen only in developement phase, so just throw
+			// exception
+		}
+
+		ZipOutputStream zos = (ZipOutputStream) os;
+		ZipEntry partEntry = new ZipEntry(ZipHelper
+				.getZipItemNameFromOPCName(part.getPartName().getURI()
+						.getPath()));
+		try {
+			// Create next zip entry
+			zos.putNextEntry(partEntry);
+
+			// Saving data in the ZIP file
+			InputStream ins = part.getInputStream();
+			byte[] buff = new byte[ZipHelper.READ_WRITE_FILE_BUFFER_SIZE];
+			while (ins.available() > 0) {
+				int resultRead = ins.read(buff);
+				if (resultRead == -1) {
+					// End of file reached
+					break;
+				}
+				zos.write(buff, 0, resultRead);
+			}
+			zos.closeEntry();
+		} catch (IOException ioe) {
+			logger.log(POILogger.ERROR,"Cannot write: " + part.getPartName() + ": in ZIP",
+					ioe);
+			return false;
+		}
+
+		// Saving relationship part
+		if (part.hasRelationships()) {
+			PackagePartName relationshipPartName = PackagingURIHelper
+					.getRelationshipPartName(part.getPartName());
+
+			marshallRelationshipPart(part.getRelationships(),
+					relationshipPartName, zos);
+
+		}
+		return true;
+	}
+
+	/**
+	 * Save relationships into the part.
+	 *
+	 * @param rels
+	 *            The relationships collection to marshall.
+	 * @param relPartName
+	 *            Part name of the relationship part to marshall.
+	 * @param zos
+	 *            Zip output stream in which to save the XML content of the
+	 *            relationships serialization.
+	 */
+	public static boolean marshallRelationshipPart(
+			PackageRelationshipCollection rels, PackagePartName relPartName,
+			ZipOutputStream zos) {
+		// Building xml
+		Document xmlOutDoc = DocumentHelper.createDocument();
+		// make something like <Relationships
+		// xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
+		Namespace dfNs = Namespace.get("", PackageNamespaces.RELATIONSHIPS);
+		Element root = xmlOutDoc.addElement(new QName(
+				PackageRelationship.RELATIONSHIPS_TAG_NAME, dfNs));
+
+		// <Relationship
+		// TargetMode="External"
+		// Id="rIdx"
+		// Target="http://www.custom.com/images/pic1.jpg"
+		// Type="http://www.custom.com/external-resource"/>
+
+		URI sourcePartURI = PackagingURIHelper
+				.getSourcePartUriFromRelationshipPartUri(relPartName.getURI());
+
+		for (PackageRelationship rel : rels) {
+			// the relationship element
+			Element relElem = root
+					.addElement(PackageRelationship.RELATIONSHIP_TAG_NAME);
+
+			// the relationship ID
+			relElem.addAttribute(PackageRelationship.ID_ATTRIBUTE_NAME, rel
+					.getId());
+
+			// the relationship Type
+			relElem.addAttribute(PackageRelationship.TYPE_ATTRIBUTE_NAME, rel
+					.getRelationshipType());
+
+			// the relationship Target
+			String targetValue;
+			URI uri = rel.getTargetURI();
+			if (rel.getTargetMode() == TargetMode.EXTERNAL) {
+				// Save the target as-is - we don't need to validate it,
+				//  alter it etc
+				targetValue = uri.toString();
+
+				// add TargetMode attribute (as it is external link external)
+				relElem.addAttribute(
+						PackageRelationship.TARGET_MODE_ATTRIBUTE_NAME,
+						"External");
+			} else {
+				targetValue = PackagingURIHelper.relativizeURI(
+						sourcePartURI, rel.getTargetURI()).getPath();
+			}
+			relElem.addAttribute(PackageRelationship.TARGET_ATTRIBUTE_NAME,
+					targetValue);
+		}
+
+		xmlOutDoc.normalize();
+
+		// String schemaFilename = Configuration.getPathForXmlSchema()+
+		// File.separator + "opc-relationships.xsd";
+
+		// Save part in zip
+		ZipEntry ctEntry = new ZipEntry(ZipHelper.getZipURIFromOPCName(
+				relPartName.getURI().toASCIIString()).getPath());
+		try {
+			zos.putNextEntry(ctEntry);
+			if (!StreamHelper.saveXmlInStream(xmlOutDoc, zos)) {
+				return false;
+			}
+			zos.closeEntry();
+		} catch (IOException e) {
+			logger.log(POILogger.ERROR,"Cannot create zip entry " + relPartName, e);
+			return false;
+		}
+		return true; // success
+	}
+}

Modified: poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/signature/DigitalCertificatePart.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/signature/DigitalCertificatePart.java?rev=776607&r1=776606&r2=776607&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/signature/DigitalCertificatePart.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/signature/DigitalCertificatePart.java Wed May 20 08:02:35 2009
@@ -1,78 +1,78 @@
-/* ====================================================================
-   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.poi.openxml4j.opc.internal.signature;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-
-import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
-import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
-import org.apache.poi.openxml4j.opc.PackagePart;
-import org.apache.poi.openxml4j.opc.internal.ContentType;
-
-/**
- * Digital certificate part.
- * 
- * @author Julien Chable
- * @version 0.1
- */
-public final class DigitalCertificatePart extends PackagePart  {
-
-	public DigitalCertificatePart() throws InvalidFormatException{
-		super(null, null, new ContentType(""));
-		// Review constructor
-	}
-	
-	@Override
-	public void close() {
-		// TODO Auto-generated method stub
-		
-	}
-
-	@Override
-	public void flush() {
-		// TODO Auto-generated method stub
-		
-	}
-
-	@Override
-	protected InputStream getInputStreamImpl() throws IOException {
-		// TODO Auto-generated method stub
-		return null;
-	}
-
-	@Override
-	protected OutputStream getOutputStreamImpl() {
-		// TODO Auto-generated method stub
-		return null;
-	}
-
-	@Override
-	public boolean load(InputStream ios) throws InvalidFormatException {
-		// TODO Auto-generated method stub
-		return false;
-	}
-
-	@Override
-	public boolean save(OutputStream zos) throws OpenXML4JException {
-		// TODO Auto-generated method stub
-		return false;
-	}
-
-}
+/* ====================================================================
+   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.poi.openxml4j.opc.internal.signature;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
+import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
+import org.apache.poi.openxml4j.opc.PackagePart;
+import org.apache.poi.openxml4j.opc.internal.ContentType;
+
+/**
+ * Digital certificate part.
+ *
+ * @author Julien Chable
+ * @version 0.1
+ */
+public final class DigitalCertificatePart extends PackagePart  {
+
+	public DigitalCertificatePart() throws InvalidFormatException{
+		super(null, null, new ContentType(""));
+		// Review constructor
+	}
+
+	@Override
+	public void close() {
+		// TODO Auto-generated method stub
+
+	}
+
+	@Override
+	public void flush() {
+		// TODO Auto-generated method stub
+
+	}
+
+	@Override
+	protected InputStream getInputStreamImpl() throws IOException {
+		// TODO Auto-generated method stub
+		return null;
+	}
+
+	@Override
+	protected OutputStream getOutputStreamImpl() {
+		// TODO Auto-generated method stub
+		return null;
+	}
+
+	@Override
+	public boolean load(InputStream ios) throws InvalidFormatException {
+		// TODO Auto-generated method stub
+		return false;
+	}
+
+	@Override
+	public boolean save(OutputStream zos) throws OpenXML4JException {
+		// TODO Auto-generated method stub
+		return false;
+	}
+
+}

Modified: poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/signature/DigitalSignatureOriginPart.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/signature/DigitalSignatureOriginPart.java?rev=776607&r1=776606&r2=776607&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/signature/DigitalSignatureOriginPart.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/signature/DigitalSignatureOriginPart.java Wed May 20 08:02:35 2009
@@ -1,28 +1,28 @@
-/* ====================================================================
-   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.poi.openxml4j.opc.internal.signature;
-
-/**
- * Represents a digital signature origin part.
- * 
- * @author Julien Chable
- * @version 0.1
- */
-public class DigitalSignatureOriginPart {
-
-}
+/* ====================================================================
+   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.poi.openxml4j.opc.internal.signature;
+
+/**
+ * Represents a digital signature origin part.
+ *
+ * @author Julien Chable
+ * @version 0.1
+ */
+public final class DigitalSignatureOriginPart {
+
+}

Modified: poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/unmarshallers/PackagePropertiesUnmarshaller.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/unmarshallers/PackagePropertiesUnmarshaller.java?rev=776607&r1=776606&r2=776607&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/unmarshallers/PackagePropertiesUnmarshaller.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/unmarshallers/PackagePropertiesUnmarshaller.java Wed May 20 08:02:35 2009
@@ -1,391 +1,393 @@
-/* ====================================================================
-   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.poi.openxml4j.opc.internal.unmarshallers;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Iterator;
-import java.util.List;
-import java.util.zip.ZipEntry;
-
-import org.dom4j.Attribute;
-import org.dom4j.Document;
-import org.dom4j.DocumentException;
-import org.dom4j.Element;
-import org.dom4j.Namespace;
-import org.dom4j.QName;
-import org.dom4j.io.SAXReader;
-import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
-import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
-import org.apache.poi.openxml4j.opc.PackageNamespaces;
-import org.apache.poi.openxml4j.opc.PackagePart;
-import org.apache.poi.openxml4j.opc.PackageProperties;
-import org.apache.poi.openxml4j.opc.ZipPackage;
-import org.apache.poi.openxml4j.opc.internal.PackagePropertiesPart;
-import org.apache.poi.openxml4j.opc.internal.PartUnmarshaller;
-import org.apache.poi.openxml4j.opc.internal.ZipHelper;
-
-/**
- * Package properties unmarshaller.
- * 
- * @author Julien Chable
- * @version 1.0
- */
-public class PackagePropertiesUnmarshaller implements PartUnmarshaller {
-
-	private final static Namespace namespaceDC = new Namespace("dc",
-			PackageProperties.NAMESPACE_DC);
-
-	private final static Namespace namespaceCP = new Namespace("cp",
-			PackageNamespaces.CORE_PROPERTIES);
-
-	private final static Namespace namespaceDcTerms = new Namespace("dcterms",
-			PackageProperties.NAMESPACE_DCTERMS);
-
-	private final static Namespace namespaceXML = new Namespace("xml",
-			"http://www.w3.org/XML/1998/namespace");
-
-	private final static Namespace namespaceXSI = new Namespace("xsi",
-			"http://www.w3.org/2001/XMLSchema-instance");
-
-	protected static final String KEYWORD_CATEGORY = "category";
-
-	protected static final String KEYWORD_CONTENT_STATUS = "contentStatus";
-
-	protected static final String KEYWORD_CONTENT_TYPE = "contentType";
-
-	protected static final String KEYWORD_CREATED = "created";
-
-	protected static final String KEYWORD_CREATOR = "creator";
-
-	protected static final String KEYWORD_DESCRIPTION = "description";
-
-	protected static final String KEYWORD_IDENTIFIER = "identifier";
-
-	protected static final String KEYWORD_KEYWORDS = "keywords";
-
-	protected static final String KEYWORD_LANGUAGE = "language";
-
-	protected static final String KEYWORD_LAST_MODIFIED_BY = "lastModifiedBy";
-
-	protected static final String KEYWORD_LAST_PRINTED = "lastPrinted";
-
-	protected static final String KEYWORD_MODIFIED = "modified";
-
-	protected static final String KEYWORD_REVISION = "revision";
-
-	protected static final String KEYWORD_SUBJECT = "subject";
-
-	protected static final String KEYWORD_TITLE = "title";
-
-	protected static final String KEYWORD_VERSION = "version";
-
-	// TODO Load element with XMLBeans or dynamic table
-	// TODO Check every element/namespace for compliance
-	public PackagePart unmarshall(UnmarshallContext context, InputStream in)
-			throws InvalidFormatException, IOException {
-		PackagePropertiesPart coreProps = new PackagePropertiesPart(context
-				.getPackage(), context.getPartName());
-
-		// If the input stream is null then we try to get it from the
-		// package.
-		if (in == null) {
-			if (context.getZipEntry() != null) {
-				in = ((ZipPackage) context.getPackage()).getZipArchive()
-						.getInputStream(context.getZipEntry());
-			} else if (context.getPackage() != null) {
-				// Try to retrieve the part inputstream from the URI
-				ZipEntry zipEntry;
-				try {
-					zipEntry = ZipHelper
-							.getCorePropertiesZipEntry((ZipPackage) context
-									.getPackage());
-				} catch (OpenXML4JException e) {
-					throw new IOException(
-							"Error while trying to get the part input stream.");
-				}
-				in = ((ZipPackage) context.getPackage()).getZipArchive()
-						.getInputStream(zipEntry);
-			} else
-				throw new IOException(
-						"Error while trying to get the part input stream.");
-		}
-
-		SAXReader xmlReader = new SAXReader();
-		Document xmlDoc;
-		try {
-			xmlDoc = xmlReader.read(in);
-
-			/* Check OPC compliance */
-
-			// Rule M4.2, M4.3, M4.4 and M4.5/
-			checkElementForOPCCompliance(xmlDoc.getRootElement());
-
-			/* End OPC compliance */
-
-		} catch (DocumentException e) {
-			throw new IOException(e.getMessage());
-		}
-
-		coreProps.setCategoryProperty(loadCategory(xmlDoc));
-		coreProps.setContentStatusProperty(loadContentStatus(xmlDoc));
-		coreProps.setContentTypeProperty(loadContentType(xmlDoc));
-		coreProps.setCreatedProperty(loadCreated(xmlDoc));
-		coreProps.setCreatorProperty(loadCreator(xmlDoc));
-		coreProps.setDescriptionProperty(loadDescription(xmlDoc));
-		coreProps.setIdentifierProperty(loadIdentifier(xmlDoc));
-		coreProps.setKeywordsProperty(loadKeywords(xmlDoc));
-		coreProps.setLanguageProperty(loadLanguage(xmlDoc));
-		coreProps.setLastModifiedByProperty(loadLastModifiedBy(xmlDoc));
-		coreProps.setLastPrintedProperty(loadLastPrinted(xmlDoc));
-		coreProps.setModifiedProperty(loadModified(xmlDoc));
-		coreProps.setRevisionProperty(loadRevision(xmlDoc));
-		coreProps.setSubjectProperty(loadSubject(xmlDoc));
-		coreProps.setTitleProperty(loadTitle(xmlDoc));
-		coreProps.setVersionProperty(loadVersion(xmlDoc));
-
-		return coreProps;
-	}
-
-	private String loadCategory(Document xmlDoc) {
-		Element el = xmlDoc.getRootElement().element(
-				new QName(KEYWORD_CATEGORY, namespaceCP));
-		if (el != null)
-			return el.getStringValue();
-		else
-			return null;
-	}
-
-	private String loadContentStatus(Document xmlDoc) {
-		Element el = xmlDoc.getRootElement().element(
-				new QName(KEYWORD_CONTENT_STATUS, namespaceCP));
-		if (el != null)
-			return el.getStringValue();
-		else
-			return null;
-	}
-
-	private String loadContentType(Document xmlDoc) {
-		Element el = xmlDoc.getRootElement().element(
-				new QName(KEYWORD_CONTENT_TYPE, namespaceCP));
-		if (el != null)
-			return el.getStringValue();
-		else
-			return null;
-	}
-
-	private String loadCreated(Document xmlDoc) {
-		Element el = xmlDoc.getRootElement().element(
-				new QName(KEYWORD_CREATED, namespaceDcTerms));
-		if (el != null)
-			return el.getStringValue();
-		else
-			return null;
-	}
-
-	private String loadCreator(Document xmlDoc) {
-		Element el = xmlDoc.getRootElement().element(
-				new QName(KEYWORD_CREATOR, namespaceDC));
-		if (el != null)
-			return el.getStringValue();
-		else
-			return null;
-	}
-
-	private String loadDescription(Document xmlDoc) {
-		Element el = xmlDoc.getRootElement().element(
-				new QName(KEYWORD_DESCRIPTION, namespaceDC));
-		if (el != null)
-			return el.getStringValue();
-		else
-			return null;
-	}
-
-	private String loadIdentifier(Document xmlDoc) {
-		Element el = xmlDoc.getRootElement().element(
-				new QName(KEYWORD_IDENTIFIER, namespaceDC));
-		if (el != null)
-			return el.getStringValue();
-		else
-			return null;
-	}
-
-	private String loadKeywords(Document xmlDoc) {
-		Element el = xmlDoc.getRootElement().element(
-				new QName(KEYWORD_KEYWORDS, namespaceCP));
-		if (el != null)
-			return el.getStringValue();
-		else
-			return null;
-	}
-
-	private String loadLanguage(Document xmlDoc) {
-		Element el = xmlDoc.getRootElement().element(
-				new QName(KEYWORD_LANGUAGE, namespaceDC));
-		if (el != null)
-			return el.getStringValue();
-		else
-			return null;
-	}
-
-	private String loadLastModifiedBy(Document xmlDoc) {
-		Element el = xmlDoc.getRootElement().element(
-				new QName(KEYWORD_LAST_MODIFIED_BY, namespaceCP));
-		if (el != null)
-			return el.getStringValue();
-		else
-			return null;
-	}
-
-	private String loadLastPrinted(Document xmlDoc) {
-		Element el = xmlDoc.getRootElement().element(
-				new QName(KEYWORD_LAST_PRINTED, namespaceCP));
-		if (el != null)
-			return el.getStringValue();
-		else
-			return null;
-	}
-
-	private String loadModified(Document xmlDoc) {
-		Element el = xmlDoc.getRootElement().element(
-				new QName(KEYWORD_MODIFIED, namespaceDcTerms));
-		if (el != null)
-			return el.getStringValue();
-		else
-			return null;
-	}
-
-	private String loadRevision(Document xmlDoc) {
-		Element el = xmlDoc.getRootElement().element(
-				new QName(KEYWORD_REVISION, namespaceCP));
-		if (el != null)
-			return el.getStringValue();
-		else
-			return null;
-	}
-
-	private String loadSubject(Document xmlDoc) {
-		Element el = xmlDoc.getRootElement().element(
-				new QName(KEYWORD_SUBJECT, namespaceDC));
-		if (el != null)
-			return el.getStringValue();
-		else
-			return null;
-	}
-
-	private String loadTitle(Document xmlDoc) {
-		Element el = xmlDoc.getRootElement().element(
-				new QName(KEYWORD_TITLE, namespaceDC));
-		if (el != null)
-			return el.getStringValue();
-		else
-			return null;
-	}
-
-	private String loadVersion(Document xmlDoc) {
-		Element el = xmlDoc.getRootElement().element(
-				new QName(KEYWORD_VERSION, namespaceCP));
-		if (el != null)
-			return el.getStringValue();
-		else
-			return null;
-	}
-
-	/* OPC Compliance methods */
-
-	/**
-	 * Check the element for the following OPC compliance rules:
-	 * <p>
-	 * Rule M4.2: A format consumer shall consider the use of the Markup
-	 * Compatibility namespace to be an error.
-	 * </p><p>
-	 * Rule M4.3: Producers shall not create a document element that contains
-	 * refinements to the Dublin Core elements, except for the two specified in
-	 * the schema: <dcterms:created> and <dcterms:modified> Consumers shall
-	 * consider a document element that violates this constraint to be an error.
-	 * </p><p>
-	 * Rule M4.4: Producers shall not create a document element that contains
-	 * the xml:lang attribute. Consumers shall consider a document element that
-	 * violates this constraint to be an error.
-	 *  </p><p>
-	 * Rule M4.5: Producers shall not create a document element that contains
-	 * the xsi:type attribute, except for a <dcterms:created> or
-	 * <dcterms:modified> element where the xsi:type attribute shall be present
-	 * and shall hold the value dcterms:W3CDTF, where dcterms is the namespace
-	 * prefix of the Dublin Core namespace. Consumers shall consider a document
-	 * element that violates this constraint to be an error.
-     * </p>
-	 */
-	public void checkElementForOPCCompliance(Element el)
-			throws InvalidFormatException {
-		// Check the current element
-		List declaredNamespaces = el.declaredNamespaces();
-		Iterator itNS = declaredNamespaces.iterator();
-		while (itNS.hasNext()) {
-			Namespace ns = (Namespace) itNS.next();
-
-			// Rule M4.2
-			if (ns.getURI().equals(PackageNamespaces.MARKUP_COMPATIBILITY))
-				throw new InvalidFormatException(
-						"OPC Compliance error [M4.2]: A format consumer shall consider the use of the Markup Compatibility namespace to be an error.");
-		}
-
-		// Rule M4.3
-		if (el.getNamespace().getURI().equals(
-				PackageProperties.NAMESPACE_DCTERMS)
-				&& !(el.getName().equals(KEYWORD_CREATED) || el.getName()
-						.equals(KEYWORD_MODIFIED)))
-			throw new InvalidFormatException(
-					"OPC Compliance error [M4.3]: Producers shall not create a document element that contains refinements to the Dublin Core elements, except for the two specified in the schema: <dcterms:created> and <dcterms:modified> Consumers shall consider a document element that violates this constraint to be an error.");
-
-		// Rule M4.4
-		if (el.attribute(new QName("lang", namespaceXML)) != null)
-			throw new InvalidFormatException(
-					"OPC Compliance error [M4.4]: Producers shall not create a document element that contains the xml:lang attribute. Consumers shall consider a document element that violates this constraint to be an error.");
-
-		// Rule M4.5
-		if (el.getNamespace().getURI().equals(
-				PackageProperties.NAMESPACE_DCTERMS)) {
-			// DCTerms namespace only use with 'created' and 'modified' elements
-			String elName = el.getName();
-			if (!(elName.equals(KEYWORD_CREATED) || elName
-					.equals(KEYWORD_MODIFIED)))
-				throw new InvalidFormatException("Namespace error : " + elName
-						+ " shouldn't have the following naemspace -> "
-						+ PackageProperties.NAMESPACE_DCTERMS);
-
-			// Check for the 'xsi:type' attribute
-			Attribute typeAtt = el.attribute(new QName("type", namespaceXSI));
-			if (typeAtt == null)
-				throw new InvalidFormatException("The element '" + elName
-						+ "' must have the '" + namespaceXSI.getPrefix()
-						+ ":type' attribute present !");
-
-			// Check for the attribute value => 'dcterms:W3CDTF'
-			if (!typeAtt.getValue().equals("dcterms:W3CDTF"))
-				throw new InvalidFormatException("The element '" + elName
-						+ "' must have the '" + namespaceXSI.getPrefix()
-						+ ":type' attribute with the value 'dcterms:W3CDTF' !");
-		}
-
-		// Check its children
-		Iterator itChildren = el.elementIterator();
-		while (itChildren.hasNext())
-			checkElementForOPCCompliance((Element) itChildren.next());
-	}
-}
+/* ====================================================================
+   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.poi.openxml4j.opc.internal.unmarshallers;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Iterator;
+import java.util.List;
+import java.util.zip.ZipEntry;
+
+import org.dom4j.Attribute;
+import org.dom4j.Document;
+import org.dom4j.DocumentException;
+import org.dom4j.Element;
+import org.dom4j.Namespace;
+import org.dom4j.QName;
+import org.dom4j.io.SAXReader;
+import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
+import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
+import org.apache.poi.openxml4j.opc.PackageNamespaces;
+import org.apache.poi.openxml4j.opc.PackagePart;
+import org.apache.poi.openxml4j.opc.PackageProperties;
+import org.apache.poi.openxml4j.opc.ZipPackage;
+import org.apache.poi.openxml4j.opc.internal.PackagePropertiesPart;
+import org.apache.poi.openxml4j.opc.internal.PartUnmarshaller;
+import org.apache.poi.openxml4j.opc.internal.ZipHelper;
+
+/**
+ * Package properties unmarshaller.
+ *
+ * @author Julien Chable
+ * @version 1.0
+ */
+public final class PackagePropertiesUnmarshaller implements PartUnmarshaller {
+
+	private final static Namespace namespaceDC = new Namespace("dc",
+			PackageProperties.NAMESPACE_DC);
+
+	private final static Namespace namespaceCP = new Namespace("cp",
+			PackageNamespaces.CORE_PROPERTIES);
+
+	private final static Namespace namespaceDcTerms = new Namespace("dcterms",
+			PackageProperties.NAMESPACE_DCTERMS);
+
+	private final static Namespace namespaceXML = new Namespace("xml",
+			"http://www.w3.org/XML/1998/namespace");
+
+	private final static Namespace namespaceXSI = new Namespace("xsi",
+			"http://www.w3.org/2001/XMLSchema-instance");
+
+	protected static final String KEYWORD_CATEGORY = "category";
+
+	protected static final String KEYWORD_CONTENT_STATUS = "contentStatus";
+
+	protected static final String KEYWORD_CONTENT_TYPE = "contentType";
+
+	protected static final String KEYWORD_CREATED = "created";
+
+	protected static final String KEYWORD_CREATOR = "creator";
+
+	protected static final String KEYWORD_DESCRIPTION = "description";
+
+	protected static final String KEYWORD_IDENTIFIER = "identifier";
+
+	protected static final String KEYWORD_KEYWORDS = "keywords";
+
+	protected static final String KEYWORD_LANGUAGE = "language";
+
+	protected static final String KEYWORD_LAST_MODIFIED_BY = "lastModifiedBy";
+
+	protected static final String KEYWORD_LAST_PRINTED = "lastPrinted";
+
+	protected static final String KEYWORD_MODIFIED = "modified";
+
+	protected static final String KEYWORD_REVISION = "revision";
+
+	protected static final String KEYWORD_SUBJECT = "subject";
+
+	protected static final String KEYWORD_TITLE = "title";
+
+	protected static final String KEYWORD_VERSION = "version";
+
+	// TODO Load element with XMLBeans or dynamic table
+	// TODO Check every element/namespace for compliance
+	public PackagePart unmarshall(UnmarshallContext context, InputStream in)
+			throws InvalidFormatException, IOException {
+		PackagePropertiesPart coreProps = new PackagePropertiesPart(context
+				.getPackage(), context.getPartName());
+
+		// If the input stream is null then we try to get it from the
+		// package.
+		if (in == null) {
+			if (context.getZipEntry() != null) {
+				in = ((ZipPackage) context.getPackage()).getZipArchive()
+						.getInputStream(context.getZipEntry());
+			} else if (context.getPackage() != null) {
+				// Try to retrieve the part inputstream from the URI
+				ZipEntry zipEntry;
+				try {
+					zipEntry = ZipHelper
+							.getCorePropertiesZipEntry((ZipPackage) context
+									.getPackage());
+				} catch (OpenXML4JException e) {
+					throw new IOException(
+							"Error while trying to get the part input stream.");
+				}
+				in = ((ZipPackage) context.getPackage()).getZipArchive()
+						.getInputStream(zipEntry);
+			} else
+				throw new IOException(
+						"Error while trying to get the part input stream.");
+		}
+
+		SAXReader xmlReader = new SAXReader();
+		Document xmlDoc;
+		try {
+			xmlDoc = xmlReader.read(in);
+
+			/* Check OPC compliance */
+
+			// Rule M4.2, M4.3, M4.4 and M4.5/
+			checkElementForOPCCompliance(xmlDoc.getRootElement());
+
+			/* End OPC compliance */
+
+		} catch (DocumentException e) {
+			throw new IOException(e.getMessage());
+		}
+
+		coreProps.setCategoryProperty(loadCategory(xmlDoc));
+		coreProps.setContentStatusProperty(loadContentStatus(xmlDoc));
+		coreProps.setContentTypeProperty(loadContentType(xmlDoc));
+		coreProps.setCreatedProperty(loadCreated(xmlDoc));
+		coreProps.setCreatorProperty(loadCreator(xmlDoc));
+		coreProps.setDescriptionProperty(loadDescription(xmlDoc));
+		coreProps.setIdentifierProperty(loadIdentifier(xmlDoc));
+		coreProps.setKeywordsProperty(loadKeywords(xmlDoc));
+		coreProps.setLanguageProperty(loadLanguage(xmlDoc));
+		coreProps.setLastModifiedByProperty(loadLastModifiedBy(xmlDoc));
+		coreProps.setLastPrintedProperty(loadLastPrinted(xmlDoc));
+		coreProps.setModifiedProperty(loadModified(xmlDoc));
+		coreProps.setRevisionProperty(loadRevision(xmlDoc));
+		coreProps.setSubjectProperty(loadSubject(xmlDoc));
+		coreProps.setTitleProperty(loadTitle(xmlDoc));
+		coreProps.setVersionProperty(loadVersion(xmlDoc));
+
+		return coreProps;
+	}
+
+	private String loadCategory(Document xmlDoc) {
+		Element el = xmlDoc.getRootElement().element(
+				new QName(KEYWORD_CATEGORY, namespaceCP));
+		if (el == null) {
+			return null;
+		}
+		return el.getStringValue();
+	}
+
+	private String loadContentStatus(Document xmlDoc) {
+		Element el = xmlDoc.getRootElement().element(
+				new QName(KEYWORD_CONTENT_STATUS, namespaceCP));
+		if (el == null) {
+			return null;
+		}
+		return el.getStringValue();
+	}
+
+	private String loadContentType(Document xmlDoc) {
+		Element el = xmlDoc.getRootElement().element(
+				new QName(KEYWORD_CONTENT_TYPE, namespaceCP));
+		if (el == null) {
+			return null;
+		}
+		return el.getStringValue();
+	}
+
+	private String loadCreated(Document xmlDoc) {
+		Element el = xmlDoc.getRootElement().element(
+				new QName(KEYWORD_CREATED, namespaceDcTerms));
+		if (el == null) {
+			return null;
+		}
+		return el.getStringValue();
+	}
+
+	private String loadCreator(Document xmlDoc) {
+		Element el = xmlDoc.getRootElement().element(
+				new QName(KEYWORD_CREATOR, namespaceDC));
+		if (el == null) {
+			return null;
+		}
+		return el.getStringValue();
+	}
+
+	private String loadDescription(Document xmlDoc) {
+		Element el = xmlDoc.getRootElement().element(
+				new QName(KEYWORD_DESCRIPTION, namespaceDC));
+		if (el == null) {
+			return null;
+		}
+		return el.getStringValue();
+	}
+
+	private String loadIdentifier(Document xmlDoc) {
+		Element el = xmlDoc.getRootElement().element(
+				new QName(KEYWORD_IDENTIFIER, namespaceDC));
+		if (el == null) {
+			return null;
+		}
+		return el.getStringValue();
+	}
+
+	private String loadKeywords(Document xmlDoc) {
+		Element el = xmlDoc.getRootElement().element(
+				new QName(KEYWORD_KEYWORDS, namespaceCP));
+		if (el == null) {
+			return null;
+		}
+		return el.getStringValue();
+	}
+
+	private String loadLanguage(Document xmlDoc) {
+		Element el = xmlDoc.getRootElement().element(
+				new QName(KEYWORD_LANGUAGE, namespaceDC));
+		if (el == null) {
+			return null;
+		}
+		return el.getStringValue();
+	}
+
+	private String loadLastModifiedBy(Document xmlDoc) {
+		Element el = xmlDoc.getRootElement().element(
+				new QName(KEYWORD_LAST_MODIFIED_BY, namespaceCP));
+		if (el == null) {
+			return null;
+		}
+		return el.getStringValue();
+	}
+
+	private String loadLastPrinted(Document xmlDoc) {
+		Element el = xmlDoc.getRootElement().element(
+				new QName(KEYWORD_LAST_PRINTED, namespaceCP));
+		if (el == null) {
+			return null;
+		}
+		return el.getStringValue();
+	}
+
+	private String loadModified(Document xmlDoc) {
+		Element el = xmlDoc.getRootElement().element(
+				new QName(KEYWORD_MODIFIED, namespaceDcTerms));
+		if (el == null) {
+			return null;
+		}
+		return el.getStringValue();
+	}
+
+	private String loadRevision(Document xmlDoc) {
+		Element el = xmlDoc.getRootElement().element(
+				new QName(KEYWORD_REVISION, namespaceCP));
+		if (el == null) {
+			return null;
+		}
+		return el.getStringValue();
+	}
+
+	private String loadSubject(Document xmlDoc) {
+		Element el = xmlDoc.getRootElement().element(
+				new QName(KEYWORD_SUBJECT, namespaceDC));
+		if (el == null) {
+			return null;
+		}
+		return el.getStringValue();
+	}
+
+	private String loadTitle(Document xmlDoc) {
+		Element el = xmlDoc.getRootElement().element(
+				new QName(KEYWORD_TITLE, namespaceDC));
+		if (el == null) {
+			return null;
+		}
+		return el.getStringValue();
+	}
+
+	private String loadVersion(Document xmlDoc) {
+		Element el = xmlDoc.getRootElement().element(
+				new QName(KEYWORD_VERSION, namespaceCP));
+		if (el == null) {
+			return null;
+		}
+		return el.getStringValue();
+	}
+
+	/* OPC Compliance methods */
+
+	/**
+	 * Check the element for the following OPC compliance rules:
+	 * <p>
+	 * Rule M4.2: A format consumer shall consider the use of the Markup
+	 * Compatibility namespace to be an error.
+	 * </p><p>
+	 * Rule M4.3: Producers shall not create a document element that contains
+	 * refinements to the Dublin Core elements, except for the two specified in
+	 * the schema: <dcterms:created> and <dcterms:modified> Consumers shall
+	 * consider a document element that violates this constraint to be an error.
+	 * </p><p>
+	 * Rule M4.4: Producers shall not create a document element that contains
+	 * the xml:lang attribute. Consumers shall consider a document element that
+	 * violates this constraint to be an error.
+	 *  </p><p>
+	 * Rule M4.5: Producers shall not create a document element that contains
+	 * the xsi:type attribute, except for a <dcterms:created> or
+	 * <dcterms:modified> element where the xsi:type attribute shall be present
+	 * and shall hold the value dcterms:W3CDTF, where dcterms is the namespace
+	 * prefix of the Dublin Core namespace. Consumers shall consider a document
+	 * element that violates this constraint to be an error.
+	 * </p>
+	 */
+	public void checkElementForOPCCompliance(Element el)
+			throws InvalidFormatException {
+		// Check the current element
+		@SuppressWarnings("unchecked")
+		List<Namespace> declaredNamespaces = el.declaredNamespaces();
+		Iterator<Namespace> itNS = declaredNamespaces.iterator();
+		while (itNS.hasNext()) {
+			Namespace ns = itNS.next();
+
+			// Rule M4.2
+			if (ns.getURI().equals(PackageNamespaces.MARKUP_COMPATIBILITY))
+				throw new InvalidFormatException(
+						"OPC Compliance error [M4.2]: A format consumer shall consider the use of the Markup Compatibility namespace to be an error.");
+		}
+
+		// Rule M4.3
+		if (el.getNamespace().getURI().equals(
+				PackageProperties.NAMESPACE_DCTERMS)
+				&& !(el.getName().equals(KEYWORD_CREATED) || el.getName()
+						.equals(KEYWORD_MODIFIED)))
+			throw new InvalidFormatException(
+					"OPC Compliance error [M4.3]: Producers shall not create a document element that contains refinements to the Dublin Core elements, except for the two specified in the schema: <dcterms:created> and <dcterms:modified> Consumers shall consider a document element that violates this constraint to be an error.");
+
+		// Rule M4.4
+		if (el.attribute(new QName("lang", namespaceXML)) != null)
+			throw new InvalidFormatException(
+					"OPC Compliance error [M4.4]: Producers shall not create a document element that contains the xml:lang attribute. Consumers shall consider a document element that violates this constraint to be an error.");
+
+		// Rule M4.5
+		if (el.getNamespace().getURI().equals(
+				PackageProperties.NAMESPACE_DCTERMS)) {
+			// DCTerms namespace only use with 'created' and 'modified' elements
+			String elName = el.getName();
+			if (!(elName.equals(KEYWORD_CREATED) || elName
+					.equals(KEYWORD_MODIFIED)))
+				throw new InvalidFormatException("Namespace error : " + elName
+						+ " shouldn't have the following naemspace -> "
+						+ PackageProperties.NAMESPACE_DCTERMS);
+
+			// Check for the 'xsi:type' attribute
+			Attribute typeAtt = el.attribute(new QName("type", namespaceXSI));
+			if (typeAtt == null)
+				throw new InvalidFormatException("The element '" + elName
+						+ "' must have the '" + namespaceXSI.getPrefix()
+						+ ":type' attribute present !");
+
+			// Check for the attribute value => 'dcterms:W3CDTF'
+			if (!typeAtt.getValue().equals("dcterms:W3CDTF"))
+				throw new InvalidFormatException("The element '" + elName
+						+ "' must have the '" + namespaceXSI.getPrefix()
+						+ ":type' attribute with the value 'dcterms:W3CDTF' !");
+		}
+
+		// Check its children
+		@SuppressWarnings("unchecked")
+		Iterator<Element> itChildren = el.elementIterator();
+		while (itChildren.hasNext())
+			checkElementForOPCCompliance(itChildren.next());
+	}
+}

Modified: poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/signature/PackageDigitalSignature.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/signature/PackageDigitalSignature.java?rev=776607&r1=776606&r2=776607&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/signature/PackageDigitalSignature.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/signature/PackageDigitalSignature.java Wed May 20 08:02:35 2009
@@ -1,70 +1,70 @@
-/* ====================================================================
-   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.poi.openxml4j.opc.signature;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-
-import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
-import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
-import org.apache.poi.openxml4j.opc.PackagePart;
-import org.apache.poi.openxml4j.opc.internal.ContentType;
-
-public class PackageDigitalSignature extends PackagePart {
-
-	public PackageDigitalSignature() throws InvalidFormatException {
-		super(null, null, new ContentType(""));
-	}
-
-	@Override
-	public void close() {
-		// TODO Auto-generated method stub
-
-	}
-
-	@Override
-	public void flush() {
-		// TODO Auto-generated method stub
-
-	}
-
-	@Override
-	protected InputStream getInputStreamImpl() throws IOException {
-		// TODO Auto-generated method stub
-		return null;
-	}
-
-	@Override
-	protected OutputStream getOutputStreamImpl() {
-		// TODO Auto-generated method stub
-		return null;
-	}
-
-	@Override
-	public boolean load(InputStream ios) throws InvalidFormatException {
-		// TODO Auto-generated method stub
-		return false;
-	}
-
-	@Override
-	public boolean save(OutputStream zos) throws OpenXML4JException {
-		// TODO Auto-generated method stub
-		return false;
-	}
-}
+/* ====================================================================
+   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.poi.openxml4j.opc.signature;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
+import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
+import org.apache.poi.openxml4j.opc.PackagePart;
+import org.apache.poi.openxml4j.opc.internal.ContentType;
+
+public final class PackageDigitalSignature extends PackagePart {
+
+	public PackageDigitalSignature() throws InvalidFormatException {
+		super(null, null, new ContentType(""));
+	}
+
+	@Override
+	public void close() {
+		// TODO Auto-generated method stub
+
+	}
+
+	@Override
+	public void flush() {
+		// TODO Auto-generated method stub
+
+	}
+
+	@Override
+	protected InputStream getInputStreamImpl() throws IOException {
+		// TODO Auto-generated method stub
+		return null;
+	}
+
+	@Override
+	protected OutputStream getOutputStreamImpl() {
+		// TODO Auto-generated method stub
+		return null;
+	}
+
+	@Override
+	public boolean load(InputStream ios) throws InvalidFormatException {
+		// TODO Auto-generated method stub
+		return false;
+	}
+
+	@Override
+	public boolean save(OutputStream zos) throws OpenXML4JException {
+		// TODO Auto-generated method stub
+		return false;
+	}
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message