poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r755699 [3/7] - in /poi/trunk/src: examples/src/org/apache/poi/xssf/eventusermodel/examples/ ooxml/java/org/apache/poi/ ooxml/java/org/apache/poi/dev/ ooxml/java/org/apache/poi/extractor/ ooxml/java/org/apache/poi/openxml4j/opc/ ooxml/java/...
Date Wed, 18 Mar 2009 18:54:02 GMT
Modified: poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/PackagePart.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/PackagePart.java?rev=755699&r1=755698&r2=755699&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/PackagePart.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/PackagePart.java Wed Mar 18 18:54:01 2009
@@ -1,654 +1,654 @@
-/* ====================================================================
-   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;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.net.URI;
-import java.net.URISyntaxException;
-
-import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
-import org.apache.poi.openxml4j.exceptions.InvalidOperationException;
-import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
-import org.apache.poi.openxml4j.opc.internal.ContentType;
-
-/**
- * Provides a base class for parts stored in a Package.
- * 
- * @author Julien Chable
- * @version 0.9
- */
-public abstract class PackagePart implements RelationshipSource {
-
-	/**
-	 * This part's container.
-	 */
-	protected Package container;
-
-	/**
-	 * The part name. (required by the specification [M1.1])
-	 */
-	protected PackagePartName partName;
-
-	/**
-	 * The type of content of this part. (required by the specification [M1.2])
-	 */
-	protected ContentType contentType;
-
-	/**
-	 * Flag to know if this part is a relationship.
-	 */
-	private boolean isRelationshipPart;
-
-	/**
-	 * Flag to know if this part has been logically deleted.
-	 */
-	private boolean isDeleted;
-
-	/**
-	 * This part's relationships.
-	 */
-	private PackageRelationshipCollection relationships;
-
-	/**
-	 * Constructor.
-	 * 
-	 * @param pack
-	 *            Parent package.
-	 * @param partName
-	 *            The part name, relative to the parent Package root.
-	 * @param contentType
-	 *            The content type.
-	 * @throws InvalidFormatException
-	 *             If the specified URI is not valid.
-	 */
-	protected PackagePart(Package pack, PackagePartName partName,
-			ContentType contentType) throws InvalidFormatException {
-		this(pack, partName, contentType, true);
-	}
-
-	/**
-	 * Constructor.
-	 * 
-	 * @param pack
-	 *            Parent package.
-	 * @param partName
-	 *            The part name, relative to the parent Package root.
-	 * @param contentType
-	 *            The content type.
-	 * @param loadRelationships
-	 *            Specify if the relationships will be loaded
-	 * @throws InvalidFormatException
-	 *             If the specified URI is not valid.
-	 */
-	protected PackagePart(Package pack, PackagePartName partName,
-			ContentType contentType, boolean loadRelationships)
-			throws InvalidFormatException {
-		this.partName = partName;
-		this.contentType = contentType;
-		this.container = (ZipPackage) pack;
-
-		// Check if this part is a relationship part
-		isRelationshipPart = this.partName.isRelationshipPartURI();
-
-		// Load relationships if any
-		if (loadRelationships)
-			loadRelationships();
-	}
-
-	/**
-	 * Constructor.
-	 * 
-	 * @param pack
-	 *            Parent package.
-	 * @param partName
-	 *            The part name, relative to the parent Package root.
-	 * @param contentType
-	 *            The Multipurpose Internet Mail Extensions (MIME) content type
-	 *            of the part's data stream.
-	 */
-	public PackagePart(Package pack, PackagePartName partName,
-			String contentType) throws InvalidFormatException {
-		this(pack, partName, new ContentType(contentType));
-	}
-
-	/**
-	 * Adds an external relationship to a part (except relationships part).
-	 * 
-	 * The targets of external relationships are not subject to the same
-	 * validity checks that internal ones are, as the contents is potentially
-	 * any file, URL or similar.
-	 * 
-	 * @param target
-	 *            External target of the relationship
-	 * @param relationshipType
-	 *            Type of relationship.
-	 * @return The newly created and added relationship
-	 * @see org.apache.poi.openxml4j.opc.RelationshipSource#addExternalRelationship(java.lang.String,
-	 *      java.lang.String)
-	 */
-	public PackageRelationship addExternalRelationship(String target,
-			String relationshipType) {
-		return addExternalRelationship(target, relationshipType, null);
-	}
-
-	/**
-	 * Adds an external relationship to a part (except relationships part).
-	 * 
-	 * The targets of external relationships are not subject to the same
-	 * validity checks that internal ones are, as the contents is potentially
-	 * any file, URL or similar.
-	 * 
-	 * @param target
-	 *            External target of the relationship
-	 * @param relationshipType
-	 *            Type of relationship.
-	 * @param id
-	 *            Relationship unique id.
-	 * @return The newly created and added relationship
-	 * @see org.apache.poi.openxml4j.opc.RelationshipSource#addExternalRelationship(java.lang.String,
-	 *      java.lang.String)
-	 */
-	public PackageRelationship addExternalRelationship(String target,
-			String relationshipType, String id) {
-		if (target == null) {
-			throw new IllegalArgumentException("target");
-		}
-		if (relationshipType == null) {
-			throw new IllegalArgumentException("relationshipType");
-		}
-
-		if (relationships == null) {
-			relationships = new PackageRelationshipCollection();
-		}
-
-		URI targetURI;
-		try {
-			targetURI = new URI(target);
-		} catch (URISyntaxException e) {
-			throw new IllegalArgumentException("Invalid target - " + e);
-		}
-
-		return relationships.addRelationship(targetURI, TargetMode.EXTERNAL,
-				relationshipType, id);
-	}
-
-	/**
-	 * Add a relationship to a part (except relationships part).
-	 * 
-	 * @param targetPartName
-	 *            Name of the target part. This one must be relative to the
-	 *            source root directory of the part.
-	 * @param targetMode
-	 *            Mode [Internal|External].
-	 * @param relationshipType
-	 *            Type of relationship.
-	 * @return The newly created and added relationship
-	 * @see org.apache.poi.openxml4j.opc.RelationshipSource#addRelationship(org.apache.poi.openxml4j.opc.PackagePartName,
-	 *      org.apache.poi.openxml4j.opc.TargetMode, java.lang.String)
-	 */
-	public PackageRelationship addRelationship(PackagePartName targetPartName,
-			TargetMode targetMode, String relationshipType) {
-		return addRelationship(targetPartName, targetMode, relationshipType,
-				null);
-	}
-
-	/**
-	 * Add a relationship to a part (except relationships part).
-	 * <p>
-	 * Check rule M1.25: The Relationships part shall not have relationships to
-	 * any other part. Package implementers shall enforce this requirement upon
-	 * the attempt to create such a relationship and shall treat any such
-	 * relationship as invalid.
-	 * </p>
-	 * @param targetPartName
-	 *            Name of the target part. This one must be relative to the
-	 *            source root directory of the part.
-	 * @param targetMode
-	 *            Mode [Internal|External].
-	 * @param relationshipType
-	 *            Type of relationship.
-	 * @param id
-	 *            Relationship unique id.
-	 * @return The newly created and added relationship
-	 * 
-	 * @throws InvalidFormatException
-	 *             If the URI point to a relationship part URI.
-	 * @see org.apache.poi.openxml4j.opc.RelationshipSource#addRelationship(org.apache.poi.openxml4j.opc.PackagePartName,
-	 *      org.apache.poi.openxml4j.opc.TargetMode, java.lang.String, java.lang.String)
-	 */
-	public PackageRelationship addRelationship(PackagePartName targetPartName,
-			TargetMode targetMode, String relationshipType, String id) {
-		container.throwExceptionIfReadOnly();
-
-		if (targetPartName == null) {
-			throw new IllegalArgumentException("targetPartName");
-		}
-		if (targetMode == null) {
-			throw new IllegalArgumentException("targetMode");
-		}
-		if (relationshipType == null) {
-			throw new IllegalArgumentException("relationshipType");
-		}
-
-		if (this.isRelationshipPart || targetPartName.isRelationshipPartURI()) {
-			throw new InvalidOperationException(
-					"Rule M1.25: The Relationships part shall not have relationships to any other part.");
-		}
-
-		if (relationships == null) {
-			relationships = new PackageRelationshipCollection();
-		}
-
-		return relationships.addRelationship(targetPartName.getURI(),
-				targetMode, relationshipType, id);
-	}
-
-	/**
-	 * Add a relationship to a part (except relationships part).
-	 * 
-	 * @param targetURI
-	 *            URI the target part. Must be relative to the source root
-	 *            directory of the part.
-	 * @param targetMode
-	 *            Mode [Internal|External].
-	 * @param relationshipType
-	 *            Type of relationship.
-	 * @return The newly created and added relationship
-	 * @see org.apache.poi.openxml4j.opc.RelationshipSource#addRelationship(org.apache.poi.openxml4j.opc.PackagePartName,
-	 *      org.apache.poi.openxml4j.opc.TargetMode, java.lang.String)
-	 */
-	public PackageRelationship addRelationship(URI targetURI,
-			TargetMode targetMode, String relationshipType) {
-		return addRelationship(targetURI, targetMode, relationshipType, null);
-	}
-
-	/**
-	 * Add a relationship to a part (except relationships part).
-	 * <p>
-	 * Check rule M1.25: The Relationships part shall not have relationships to
-	 * any other part. Package implementers shall enforce this requirement upon
-	 * the attempt to create such a relationship and shall treat any such
-	 * relationship as invalid.
-	 * </p>
-	 * @param targetURI
-	 *            URI of the target part. Must be relative to the source root
-	 *            directory of the part.
-	 * @param targetMode
-	 *            Mode [Internal|External].
-	 * @param relationshipType
-	 *            Type of relationship.
-	 * @param id
-	 *            Relationship unique id.
-	 * @return The newly created and added relationship
-	 * 
-	 * @throws InvalidFormatException
-	 *             If the URI point to a relationship part URI.
-	 * @see org.apache.poi.openxml4j.opc.RelationshipSource#addRelationship(org.apache.poi.openxml4j.opc.PackagePartName,
-	 *      org.apache.poi.openxml4j.opc.TargetMode, java.lang.String, java.lang.String)
-	 */
-	public PackageRelationship addRelationship(URI targetURI,
-			TargetMode targetMode, String relationshipType, String id) {
-		container.throwExceptionIfReadOnly();
-
-		if (targetURI == null) {
-			throw new IllegalArgumentException("targetPartName");
-		}
-		if (targetMode == null) {
-			throw new IllegalArgumentException("targetMode");
-		}
-		if (relationshipType == null) {
-			throw new IllegalArgumentException("relationshipType");
-		}
-
-		// Try to retrieve the target part
-
-		if (this.isRelationshipPart
-				|| PackagingURIHelper.isRelationshipPartURI(targetURI)) {
-			throw new InvalidOperationException(
-					"Rule M1.25: The Relationships part shall not have relationships to any other part.");
-		}
-
-		if (relationships == null) {
-			relationships = new PackageRelationshipCollection();
-		}
-
-		return relationships.addRelationship(targetURI,
-				targetMode, relationshipType, id);
-	}
-
-	/**
-	 * @see org.apache.poi.openxml4j.opc.RelationshipSource#clearRelationships()
-	 */
-	public void clearRelationships() {
-		if (relationships != null) {
-			relationships.clear();
-		}
-	}
-
-	/**
-	 * Delete the relationship specified by its id.
-	 * 
-	 * @param id
-	 *            The ID identified the part to delete.
-	 * @see org.apache.poi.openxml4j.opc.RelationshipSource#removeRelationship(java.lang.String)
-	 */
-	public void removeRelationship(String id) {
-		this.container.throwExceptionIfReadOnly();
-		if (this.relationships != null)
-			this.relationships.removeRelationship(id);
-	}
-
-	/**
-	 * Retrieve all the relationships attached to this part.
-	 * 
-	 * @return This part's relationships.
-	 * @throws OpenXML4JException
-	 * @see org.apache.poi.openxml4j.opc.RelationshipSource#getRelationships()
-	 */
-	public PackageRelationshipCollection getRelationships()
-			throws InvalidFormatException {
-		return getRelationshipsCore(null);
-	}
-
-	/**
-	 * Retrieves a package relationship from its id.
-	 * 
-	 * @param id
-	 *            ID of the package relationship to retrieve.
-	 * @return The package relationship
-	 * @see org.apache.poi.openxml4j.opc.RelationshipSource#getRelationship(java.lang.String)
-	 */
-	public PackageRelationship getRelationship(String id) {
-		return this.relationships.getRelationshipByID(id);
-	}
-
-	/**
-	 * Retrieve all relationships attached to this part which have the specified
-	 * type.
-	 * 
-	 * @param relationshipType
-	 *            Relationship type filter.
-	 * @return All relationships from this part that have the specified type.
-	 * @throws InvalidFormatException
-	 *             If an error occurs while parsing the part.
-	 * @throws InvalidOperationException
-	 *             If the package is open in write only mode.
-	 * @see org.apache.poi.openxml4j.opc.RelationshipSource#getRelationshipsByType(java.lang.String)
-	 */
-	public PackageRelationshipCollection getRelationshipsByType(
-			String relationshipType) throws InvalidFormatException {
-		container.throwExceptionIfWriteOnly();
-
-		return getRelationshipsCore(relationshipType);
-	}
-
-	/**
-	 * Implementation of the getRelationships method().
-	 * 
-	 * @param filter
-	 *            Relationship type filter. If <i>null</i> then the filter is
-	 *            disabled and return all the relationships.
-	 * @return All relationships from this part that have the specified type.
-	 * @throws InvalidFormatException
-	 *             Throws if an error occurs during parsing the relationships
-	 *             part.
-	 * @throws InvalidOperationException
-	 *             Throws if the package is open en write only mode.
-	 * @see #getRelationshipsByType(String)
-	 */
-	private PackageRelationshipCollection getRelationshipsCore(String filter)
-			throws InvalidFormatException {
-		this.container.throwExceptionIfWriteOnly();
-		if (relationships == null) {
-			this.throwExceptionIfRelationship();
-			relationships = new PackageRelationshipCollection(this);
-		}
-		return new PackageRelationshipCollection(relationships, filter);
-	}
-
-	/**
-	 * Knows if the part have any relationships.
-	 * 
-	 * @return <b>true</b> if the part have at least one relationship else
-	 *         <b>false</b>.
-	 * @see org.apache.poi.openxml4j.opc.RelationshipSource#hasRelationships()
-	 */
-	public boolean hasRelationships() {
-		return (!this.isRelationshipPart && (relationships != null && relationships
-				.size() > 0));
-	}
-
-	/**
-	 * Checks if the specified relationship is part of this package part.
-	 * 
-	 * @param rel
-	 *            The relationship to check.
-	 * @return <b>true</b> if the specified relationship exists in this part,
-	 *         else returns <b>false</b>
-	 * @see org.apache.poi.openxml4j.opc.RelationshipSource#isRelationshipExists(org.apache.poi.openxml4j.opc.PackageRelationship)
-	 */
-	@SuppressWarnings("finally")
-	public boolean isRelationshipExists(PackageRelationship rel) {
-		try {
-			for (PackageRelationship r : this.getRelationships()) {
-				if (r == rel)
-					return true;
-			}
-		} finally {
-			return false;
-		}
-	}
-
-	/**
-	 * Get the input stream of this part to read its content.
-	 * 
-	 * @return The input stream of the content of this part, else
-	 *         <code>null</code>.
-	 */
-	public InputStream getInputStream() throws IOException {
-		InputStream inStream = this.getInputStreamImpl();
-		if (inStream == null) {
-			throw new IOException("Can't obtain the input stream from "
-					+ partName.getName());
-		} else
-			return inStream;
-	}
-
-	/**
-	 * Get the output stream of this part. If the part is originally embedded in
-	 * Zip package, it'll be transform intot a <i>MemoryPackagePart</i> in
-	 * order to write inside (the standard Java API doesn't allow to write in
-	 * the file)
-	 * 
-	 * @see org.apache.poi.openxml4j.opc.internal.MemoryPackagePart
-	 */
-	public OutputStream getOutputStream() {
-		OutputStream outStream;
-		// If this part is a zip package part (read only by design) we convert
-		// this part into a MemoryPackagePart instance for write purpose.
-		if (this instanceof ZipPackagePart) {
-			// Delete logically this part
-			this.container.removePart(this.partName);
-
-			// Create a memory part
-			PackagePart part = container.createPart(this.partName,
-					this.contentType.toString(), false);
-			part.relationships = this.relationships;
-			if (part == null) {
-				throw new InvalidOperationException(
-						"Can't create a temporary part !");
-			}
-			outStream = part.getOutputStreamImpl();
-		} else {
-			outStream = this.getOutputStreamImpl();
-		}
-		return outStream;
-	}
-
-	/**
-	 * Throws an exception if this package part is a relationship part.
-	 * 
-	 * @throws InvalidOperationException
-	 *             If this part is a relationship part.
-	 */
-	private void throwExceptionIfRelationship()
-			throws InvalidOperationException {
-		if (this.isRelationshipPart)
-			throw new InvalidOperationException(
-					"Can do this operation on a relationship part !");
-	}
-
-	/**
-	 * Ensure the package relationships collection instance is built.
-	 * 
-	 * @throws InvalidFormatException
-	 *             Throws if
-	 */
-	private void loadRelationships() throws InvalidFormatException {
-		if (this.relationships == null && !this.isRelationshipPart) {
-			this.throwExceptionIfRelationship();
-			relationships = new PackageRelationshipCollection(this);
-		}
-	}
-
-	/*
-	 * Accessors
-	 */
-
-	/**
-	 * @return the uri
-	 */
-	public PackagePartName getPartName() {
-		return partName;
-	}
-
-	/**
-	 * @return the contentType
-	 */
-	public String getContentType() {
-		return contentType.toString();
-	}
-
-	/**
-	 * Set the content type.
-	 * 
-	 * @param contentType
-	 *            the contentType to set
-	 * 
-	 * @throws InvalidFormatException
-	 *             Throws if the content type is not valid.
-	 * @throws InvalidOperationException
-	 *             Throws if you try to change the content type whereas this
-	 *             part is already attached to a package.
-	 */
-	public void setContentType(String contentType)
-			throws InvalidFormatException {
-		if (container == null)
-			this.contentType = new ContentType(contentType);
-		else
-			throw new InvalidOperationException(
-					"You can't change the content type of a part.");
-	}
-
-	public Package getPackage() {
-		return container;
-	}
-
-	/**
-	 * @return true if this part is a relationship
-	 */
-	public boolean isRelationshipPart() {
-		return this.isRelationshipPart;
-	}
-
-	/**
-	 * @return true if this part has been logically deleted
-	 */
-	public boolean isDeleted() {
-		return isDeleted;
-	}
-
-	/**
-	 * @param isDeleted
-	 *            the isDeleted to set
-	 */
-	public void setDeleted(boolean isDeleted) {
-		this.isDeleted = isDeleted;
-	}
-
-	@Override
-	public String toString() {
-		return "Name: " + this.partName + " - Content Type: "
-				+ this.contentType.toString();
-	}
-
-	/*-------------- Abstract methods ------------- */
-
-	/**
-	 * Abtract method that get the input stream of this part.
-	 * 
-	 * @exception IOException
-	 *                Throws if an IO Exception occur in the implementation
-	 *                method.
-	 */
-	protected abstract InputStream getInputStreamImpl() throws IOException;
-
-	/**
-	 * Abstract method that get the output stream of this part.
-	 */
-	protected abstract OutputStream getOutputStreamImpl();
-
-	/**
-	 * Save the content of this part and the associated relationships part (if
-	 * this part own at least one relationship) into the specified output
-	 * stream.
-	 * 
-	 * @param zos
-	 *            Output stream to save this part.
-	 * @throws OpenXML4JException
-	 *             If any exception occur.
-	 */
-	public abstract boolean save(OutputStream zos) throws OpenXML4JException;
-
-	/**
-	 * Load the content of this part.
-	 * 
-	 * @param ios
-	 *            The input stream of the content to load.
-	 * @return <b>true</b> if the content has been successfully loaded, else
-	 *         <b>false</b>.
-	 * @throws InvalidFormatException
-	 *             Throws if the content format is invalid.
-	 */
-	public abstract boolean load(InputStream ios) throws InvalidFormatException;
-
-	/**
-	 * Close this part : flush this part, close the input stream and output
-	 * stream. After this method call, the part must be available for packaging.
-	 */
-	public abstract void close();
-
-	/**
-	 * Flush the content of this part. If the input stream and/or output stream
-	 * as in a waiting state to read or write, the must to empty their
-	 * respective buffer.
-	 */
-	public abstract void flush();
-}
+/* ====================================================================
+   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;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
+import org.apache.poi.openxml4j.exceptions.InvalidOperationException;
+import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
+import org.apache.poi.openxml4j.opc.internal.ContentType;
+
+/**
+ * Provides a base class for parts stored in a Package.
+ * 
+ * @author Julien Chable
+ * @version 0.9
+ */
+public abstract class PackagePart implements RelationshipSource {
+
+	/**
+	 * This part's container.
+	 */
+	protected OPCPackage container;
+
+	/**
+	 * The part name. (required by the specification [M1.1])
+	 */
+	protected PackagePartName partName;
+
+	/**
+	 * The type of content of this part. (required by the specification [M1.2])
+	 */
+	protected ContentType contentType;
+
+	/**
+	 * Flag to know if this part is a relationship.
+	 */
+	private boolean isRelationshipPart;
+
+	/**
+	 * Flag to know if this part has been logically deleted.
+	 */
+	private boolean isDeleted;
+
+	/**
+	 * This part's relationships.
+	 */
+	private PackageRelationshipCollection relationships;
+
+	/**
+	 * Constructor.
+	 * 
+	 * @param pack
+	 *            Parent package.
+	 * @param partName
+	 *            The part name, relative to the parent Package root.
+	 * @param contentType
+	 *            The content type.
+	 * @throws InvalidFormatException
+	 *             If the specified URI is not valid.
+	 */
+	protected PackagePart(OPCPackage pack, PackagePartName partName,
+			ContentType contentType) throws InvalidFormatException {
+		this(pack, partName, contentType, true);
+	}
+
+	/**
+	 * Constructor.
+	 * 
+	 * @param pack
+	 *            Parent package.
+	 * @param partName
+	 *            The part name, relative to the parent Package root.
+	 * @param contentType
+	 *            The content type.
+	 * @param loadRelationships
+	 *            Specify if the relationships will be loaded
+	 * @throws InvalidFormatException
+	 *             If the specified URI is not valid.
+	 */
+	protected PackagePart(OPCPackage pack, PackagePartName partName,
+			ContentType contentType, boolean loadRelationships)
+			throws InvalidFormatException {
+		this.partName = partName;
+		this.contentType = contentType;
+		this.container = (ZipPackage) pack; // TODO - enforcing ZipPackage here - perhaps should change constructor signature
+
+		// Check if this part is a relationship part
+		isRelationshipPart = this.partName.isRelationshipPartURI();
+
+		// Load relationships if any
+		if (loadRelationships)
+			loadRelationships();
+	}
+
+	/**
+	 * Constructor.
+	 * 
+	 * @param pack
+	 *            Parent package.
+	 * @param partName
+	 *            The part name, relative to the parent Package root.
+	 * @param contentType
+	 *            The Multipurpose Internet Mail Extensions (MIME) content type
+	 *            of the part's data stream.
+	 */
+	public PackagePart(OPCPackage pack, PackagePartName partName,
+			String contentType) throws InvalidFormatException {
+		this(pack, partName, new ContentType(contentType));
+	}
+
+	/**
+	 * Adds an external relationship to a part (except relationships part).
+	 * 
+	 * The targets of external relationships are not subject to the same
+	 * validity checks that internal ones are, as the contents is potentially
+	 * any file, URL or similar.
+	 * 
+	 * @param target
+	 *            External target of the relationship
+	 * @param relationshipType
+	 *            Type of relationship.
+	 * @return The newly created and added relationship
+	 * @see org.apache.poi.openxml4j.opc.RelationshipSource#addExternalRelationship(java.lang.String,
+	 *      java.lang.String)
+	 */
+	public PackageRelationship addExternalRelationship(String target,
+			String relationshipType) {
+		return addExternalRelationship(target, relationshipType, null);
+	}
+
+	/**
+	 * Adds an external relationship to a part (except relationships part).
+	 * 
+	 * The targets of external relationships are not subject to the same
+	 * validity checks that internal ones are, as the contents is potentially
+	 * any file, URL or similar.
+	 * 
+	 * @param target
+	 *            External target of the relationship
+	 * @param relationshipType
+	 *            Type of relationship.
+	 * @param id
+	 *            Relationship unique id.
+	 * @return The newly created and added relationship
+	 * @see org.apache.poi.openxml4j.opc.RelationshipSource#addExternalRelationship(java.lang.String,
+	 *      java.lang.String)
+	 */
+	public PackageRelationship addExternalRelationship(String target,
+			String relationshipType, String id) {
+		if (target == null) {
+			throw new IllegalArgumentException("target");
+		}
+		if (relationshipType == null) {
+			throw new IllegalArgumentException("relationshipType");
+		}
+
+		if (relationships == null) {
+			relationships = new PackageRelationshipCollection();
+		}
+
+		URI targetURI;
+		try {
+			targetURI = new URI(target);
+		} catch (URISyntaxException e) {
+			throw new IllegalArgumentException("Invalid target - " + e);
+		}
+
+		return relationships.addRelationship(targetURI, TargetMode.EXTERNAL,
+				relationshipType, id);
+	}
+
+	/**
+	 * Add a relationship to a part (except relationships part).
+	 * 
+	 * @param targetPartName
+	 *            Name of the target part. This one must be relative to the
+	 *            source root directory of the part.
+	 * @param targetMode
+	 *            Mode [Internal|External].
+	 * @param relationshipType
+	 *            Type of relationship.
+	 * @return The newly created and added relationship
+	 * @see org.apache.poi.openxml4j.opc.RelationshipSource#addRelationship(org.apache.poi.openxml4j.opc.PackagePartName,
+	 *      org.apache.poi.openxml4j.opc.TargetMode, java.lang.String)
+	 */
+	public PackageRelationship addRelationship(PackagePartName targetPartName,
+			TargetMode targetMode, String relationshipType) {
+		return addRelationship(targetPartName, targetMode, relationshipType,
+				null);
+	}
+
+	/**
+	 * Add a relationship to a part (except relationships part).
+	 * <p>
+	 * Check rule M1.25: The Relationships part shall not have relationships to
+	 * any other part. Package implementers shall enforce this requirement upon
+	 * the attempt to create such a relationship and shall treat any such
+	 * relationship as invalid.
+	 * </p>
+	 * @param targetPartName
+	 *            Name of the target part. This one must be relative to the
+	 *            source root directory of the part.
+	 * @param targetMode
+	 *            Mode [Internal|External].
+	 * @param relationshipType
+	 *            Type of relationship.
+	 * @param id
+	 *            Relationship unique id.
+	 * @return The newly created and added relationship
+	 * 
+	 * @throws InvalidFormatException
+	 *             If the URI point to a relationship part URI.
+	 * @see org.apache.poi.openxml4j.opc.RelationshipSource#addRelationship(org.apache.poi.openxml4j.opc.PackagePartName,
+	 *      org.apache.poi.openxml4j.opc.TargetMode, java.lang.String, java.lang.String)
+	 */
+	public PackageRelationship addRelationship(PackagePartName targetPartName,
+			TargetMode targetMode, String relationshipType, String id) {
+		container.throwExceptionIfReadOnly();
+
+		if (targetPartName == null) {
+			throw new IllegalArgumentException("targetPartName");
+		}
+		if (targetMode == null) {
+			throw new IllegalArgumentException("targetMode");
+		}
+		if (relationshipType == null) {
+			throw new IllegalArgumentException("relationshipType");
+		}
+
+		if (this.isRelationshipPart || targetPartName.isRelationshipPartURI()) {
+			throw new InvalidOperationException(
+					"Rule M1.25: The Relationships part shall not have relationships to any other part.");
+		}
+
+		if (relationships == null) {
+			relationships = new PackageRelationshipCollection();
+		}
+
+		return relationships.addRelationship(targetPartName.getURI(),
+				targetMode, relationshipType, id);
+	}
+
+	/**
+	 * Add a relationship to a part (except relationships part).
+	 * 
+	 * @param targetURI
+	 *            URI the target part. Must be relative to the source root
+	 *            directory of the part.
+	 * @param targetMode
+	 *            Mode [Internal|External].
+	 * @param relationshipType
+	 *            Type of relationship.
+	 * @return The newly created and added relationship
+	 * @see org.apache.poi.openxml4j.opc.RelationshipSource#addRelationship(org.apache.poi.openxml4j.opc.PackagePartName,
+	 *      org.apache.poi.openxml4j.opc.TargetMode, java.lang.String)
+	 */
+	public PackageRelationship addRelationship(URI targetURI,
+			TargetMode targetMode, String relationshipType) {
+		return addRelationship(targetURI, targetMode, relationshipType, null);
+	}
+
+	/**
+	 * Add a relationship to a part (except relationships part).
+	 * <p>
+	 * Check rule M1.25: The Relationships part shall not have relationships to
+	 * any other part. Package implementers shall enforce this requirement upon
+	 * the attempt to create such a relationship and shall treat any such
+	 * relationship as invalid.
+	 * </p>
+	 * @param targetURI
+	 *            URI of the target part. Must be relative to the source root
+	 *            directory of the part.
+	 * @param targetMode
+	 *            Mode [Internal|External].
+	 * @param relationshipType
+	 *            Type of relationship.
+	 * @param id
+	 *            Relationship unique id.
+	 * @return The newly created and added relationship
+	 * 
+	 * @throws InvalidFormatException
+	 *             If the URI point to a relationship part URI.
+	 * @see org.apache.poi.openxml4j.opc.RelationshipSource#addRelationship(org.apache.poi.openxml4j.opc.PackagePartName,
+	 *      org.apache.poi.openxml4j.opc.TargetMode, java.lang.String, java.lang.String)
+	 */
+	public PackageRelationship addRelationship(URI targetURI,
+			TargetMode targetMode, String relationshipType, String id) {
+		container.throwExceptionIfReadOnly();
+
+		if (targetURI == null) {
+			throw new IllegalArgumentException("targetPartName");
+		}
+		if (targetMode == null) {
+			throw new IllegalArgumentException("targetMode");
+		}
+		if (relationshipType == null) {
+			throw new IllegalArgumentException("relationshipType");
+		}
+
+		// Try to retrieve the target part
+
+		if (this.isRelationshipPart
+				|| PackagingURIHelper.isRelationshipPartURI(targetURI)) {
+			throw new InvalidOperationException(
+					"Rule M1.25: The Relationships part shall not have relationships to any other part.");
+		}
+
+		if (relationships == null) {
+			relationships = new PackageRelationshipCollection();
+		}
+
+		return relationships.addRelationship(targetURI,
+				targetMode, relationshipType, id);
+	}
+
+	/**
+	 * @see org.apache.poi.openxml4j.opc.RelationshipSource#clearRelationships()
+	 */
+	public void clearRelationships() {
+		if (relationships != null) {
+			relationships.clear();
+		}
+	}
+
+	/**
+	 * Delete the relationship specified by its id.
+	 * 
+	 * @param id
+	 *            The ID identified the part to delete.
+	 * @see org.apache.poi.openxml4j.opc.RelationshipSource#removeRelationship(java.lang.String)
+	 */
+	public void removeRelationship(String id) {
+		this.container.throwExceptionIfReadOnly();
+		if (this.relationships != null)
+			this.relationships.removeRelationship(id);
+	}
+
+	/**
+	 * Retrieve all the relationships attached to this part.
+	 * 
+	 * @return This part's relationships.
+	 * @throws OpenXML4JException
+	 * @see org.apache.poi.openxml4j.opc.RelationshipSource#getRelationships()
+	 */
+	public PackageRelationshipCollection getRelationships()
+			throws InvalidFormatException {
+		return getRelationshipsCore(null);
+	}
+
+	/**
+	 * Retrieves a package relationship from its id.
+	 * 
+	 * @param id
+	 *            ID of the package relationship to retrieve.
+	 * @return The package relationship
+	 * @see org.apache.poi.openxml4j.opc.RelationshipSource#getRelationship(java.lang.String)
+	 */
+	public PackageRelationship getRelationship(String id) {
+		return this.relationships.getRelationshipByID(id);
+	}
+
+	/**
+	 * Retrieve all relationships attached to this part which have the specified
+	 * type.
+	 * 
+	 * @param relationshipType
+	 *            Relationship type filter.
+	 * @return All relationships from this part that have the specified type.
+	 * @throws InvalidFormatException
+	 *             If an error occurs while parsing the part.
+	 * @throws InvalidOperationException
+	 *             If the package is open in write only mode.
+	 * @see org.apache.poi.openxml4j.opc.RelationshipSource#getRelationshipsByType(java.lang.String)
+	 */
+	public PackageRelationshipCollection getRelationshipsByType(
+			String relationshipType) throws InvalidFormatException {
+		container.throwExceptionIfWriteOnly();
+
+		return getRelationshipsCore(relationshipType);
+	}
+
+	/**
+	 * Implementation of the getRelationships method().
+	 * 
+	 * @param filter
+	 *            Relationship type filter. If <i>null</i> then the filter is
+	 *            disabled and return all the relationships.
+	 * @return All relationships from this part that have the specified type.
+	 * @throws InvalidFormatException
+	 *             Throws if an error occurs during parsing the relationships
+	 *             part.
+	 * @throws InvalidOperationException
+	 *             Throws if the package is open en write only mode.
+	 * @see #getRelationshipsByType(String)
+	 */
+	private PackageRelationshipCollection getRelationshipsCore(String filter)
+			throws InvalidFormatException {
+		this.container.throwExceptionIfWriteOnly();
+		if (relationships == null) {
+			this.throwExceptionIfRelationship();
+			relationships = new PackageRelationshipCollection(this);
+		}
+		return new PackageRelationshipCollection(relationships, filter);
+	}
+
+	/**
+	 * Knows if the part have any relationships.
+	 * 
+	 * @return <b>true</b> if the part have at least one relationship else
+	 *         <b>false</b>.
+	 * @see org.apache.poi.openxml4j.opc.RelationshipSource#hasRelationships()
+	 */
+	public boolean hasRelationships() {
+		return (!this.isRelationshipPart && (relationships != null && relationships
+				.size() > 0));
+	}
+
+	/**
+	 * Checks if the specified relationship is part of this package part.
+	 * 
+	 * @param rel
+	 *            The relationship to check.
+	 * @return <b>true</b> if the specified relationship exists in this part,
+	 *         else returns <b>false</b>
+	 * @see org.apache.poi.openxml4j.opc.RelationshipSource#isRelationshipExists(org.apache.poi.openxml4j.opc.PackageRelationship)
+	 */
+	@SuppressWarnings("finally")
+	public boolean isRelationshipExists(PackageRelationship rel) {
+		try {
+			for (PackageRelationship r : this.getRelationships()) {
+				if (r == rel)
+					return true;
+			}
+		} finally {
+			return false;
+		}
+	}
+
+	/**
+	 * Get the input stream of this part to read its content.
+	 * 
+	 * @return The input stream of the content of this part, else
+	 *         <code>null</code>.
+	 */
+	public InputStream getInputStream() throws IOException {
+		InputStream inStream = this.getInputStreamImpl();
+		if (inStream == null) {
+			throw new IOException("Can't obtain the input stream from "
+					+ partName.getName());
+		} else
+			return inStream;
+	}
+
+	/**
+	 * Get the output stream of this part. If the part is originally embedded in
+	 * Zip package, it'll be transform intot a <i>MemoryPackagePart</i> in
+	 * order to write inside (the standard Java API doesn't allow to write in
+	 * the file)
+	 * 
+	 * @see org.apache.poi.openxml4j.opc.internal.MemoryPackagePart
+	 */
+	public OutputStream getOutputStream() {
+		OutputStream outStream;
+		// If this part is a zip package part (read only by design) we convert
+		// this part into a MemoryPackagePart instance for write purpose.
+		if (this instanceof ZipPackagePart) {
+			// Delete logically this part
+			this.container.removePart(this.partName);
+
+			// Create a memory part
+			PackagePart part = container.createPart(this.partName,
+					this.contentType.toString(), false);
+			part.relationships = this.relationships;
+			if (part == null) {
+				throw new InvalidOperationException(
+						"Can't create a temporary part !");
+			}
+			outStream = part.getOutputStreamImpl();
+		} else {
+			outStream = this.getOutputStreamImpl();
+		}
+		return outStream;
+	}
+
+	/**
+	 * Throws an exception if this package part is a relationship part.
+	 * 
+	 * @throws InvalidOperationException
+	 *             If this part is a relationship part.
+	 */
+	private void throwExceptionIfRelationship()
+			throws InvalidOperationException {
+		if (this.isRelationshipPart)
+			throw new InvalidOperationException(
+					"Can do this operation on a relationship part !");
+	}
+
+	/**
+	 * Ensure the package relationships collection instance is built.
+	 * 
+	 * @throws InvalidFormatException
+	 *             Throws if
+	 */
+	private void loadRelationships() throws InvalidFormatException {
+		if (this.relationships == null && !this.isRelationshipPart) {
+			this.throwExceptionIfRelationship();
+			relationships = new PackageRelationshipCollection(this);
+		}
+	}
+
+	/*
+	 * Accessors
+	 */
+
+	/**
+	 * @return the uri
+	 */
+	public PackagePartName getPartName() {
+		return partName;
+	}
+
+	/**
+	 * @return the contentType
+	 */
+	public String getContentType() {
+		return contentType.toString();
+	}
+
+	/**
+	 * Set the content type.
+	 * 
+	 * @param contentType
+	 *            the contentType to set
+	 * 
+	 * @throws InvalidFormatException
+	 *             Throws if the content type is not valid.
+	 * @throws InvalidOperationException
+	 *             Throws if you try to change the content type whereas this
+	 *             part is already attached to a package.
+	 */
+	public void setContentType(String contentType)
+			throws InvalidFormatException {
+		if (container == null)
+			this.contentType = new ContentType(contentType);
+		else
+			throw new InvalidOperationException(
+					"You can't change the content type of a part.");
+	}
+
+	public OPCPackage getPackage() {
+		return container;
+	}
+
+	/**
+	 * @return true if this part is a relationship
+	 */
+	public boolean isRelationshipPart() {
+		return this.isRelationshipPart;
+	}
+
+	/**
+	 * @return true if this part has been logically deleted
+	 */
+	public boolean isDeleted() {
+		return isDeleted;
+	}
+
+	/**
+	 * @param isDeleted
+	 *            the isDeleted to set
+	 */
+	public void setDeleted(boolean isDeleted) {
+		this.isDeleted = isDeleted;
+	}
+
+	@Override
+	public String toString() {
+		return "Name: " + this.partName + " - Content Type: "
+				+ this.contentType.toString();
+	}
+
+	/*-------------- Abstract methods ------------- */
+
+	/**
+	 * Abtract method that get the input stream of this part.
+	 * 
+	 * @exception IOException
+	 *                Throws if an IO Exception occur in the implementation
+	 *                method.
+	 */
+	protected abstract InputStream getInputStreamImpl() throws IOException;
+
+	/**
+	 * Abstract method that get the output stream of this part.
+	 */
+	protected abstract OutputStream getOutputStreamImpl();
+
+	/**
+	 * Save the content of this part and the associated relationships part (if
+	 * this part own at least one relationship) into the specified output
+	 * stream.
+	 * 
+	 * @param zos
+	 *            Output stream to save this part.
+	 * @throws OpenXML4JException
+	 *             If any exception occur.
+	 */
+	public abstract boolean save(OutputStream zos) throws OpenXML4JException;
+
+	/**
+	 * Load the content of this part.
+	 * 
+	 * @param ios
+	 *            The input stream of the content to load.
+	 * @return <b>true</b> if the content has been successfully loaded, else
+	 *         <b>false</b>.
+	 * @throws InvalidFormatException
+	 *             Throws if the content format is invalid.
+	 */
+	public abstract boolean load(InputStream ios) throws InvalidFormatException;
+
+	/**
+	 * Close this part : flush this part, close the input stream and output
+	 * stream. After this method call, the part must be available for packaging.
+	 */
+	public abstract void close();
+
+	/**
+	 * Flush the content of this part. If the input stream and/or output stream
+	 * as in a waiting state to read or write, the must to empty their
+	 * respective buffer.
+	 */
+	public abstract void flush();
+}

Modified: poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/PackageProperties.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/PackageProperties.java?rev=755699&r1=755698&r2=755699&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/PackageProperties.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/PackageProperties.java Wed Mar 18 18:54:01 2009
@@ -1,227 +1,227 @@
-/* ====================================================================
-   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;
-
-import java.util.Date;
-
-import org.apache.poi.openxml4j.util.Nullable;
-
-/**
- * Represents the core properties of an OPC package.
- * 
- * @author Julien Chable
- * @version 1.0
- * @see org.apache.poi.openxml4j.opc.Package
- */
-public interface PackageProperties {
-	
-	/**
-	 * Dublin Core Terms URI.
-	 */
-	public final static String NAMESPACE_DCTERMS = "http://purl.org/dc/terms/";
-	
-	/**
-	 * Dublin Core namespace URI.
-	 */
-	public final static String NAMESPACE_DC = "http://purl.org/dc/elements/1.1/";
-
-	/* Getters and setters */
-
-	/**
-	 * Set the category of the content of this package.
-	 */
-	public abstract Nullable<String> getCategoryProperty();
-
-	/**
-	 * Set the category of the content of this package.
-	 */
-	public abstract void setCategoryProperty(String category);
-
-	/**
-	 * Set the status of the content.
-	 */
-	public abstract Nullable<String> getContentStatusProperty();
-
-	/**
-	 * Get the status of the content.
-	 */
-	public abstract void setContentStatusProperty(String contentStatus);
-
-	/**
-	 * Get the type of content represented, generally defined by a specific use
-	 * and intended audience.
-	 */
-	public abstract Nullable<String> getContentTypeProperty();
-
-	/**
-	 * Set the type of content represented, generally defined by a specific use
-	 * and intended audience.
-	 */
-	public abstract void setContentTypeProperty(String contentType);
-
-	/**
-	 * Get the date of creation of the resource.
-	 */
-	public abstract Nullable<Date> getCreatedProperty();
-
-	/**
-	 * Set the date of creation of the resource.
-	 */
-	public abstract void setCreatedProperty(String created);
-	
-	/**
-	 * Set the date of creation of the resource.
-	 */
-	public abstract void setCreatedProperty(Nullable<Date> created);
-
-	/**
-	 * Get the entity primarily responsible for making the content of the
-	 * resource.
-	 */
-	public abstract Nullable<String> getCreatorProperty();
-
-	/**
-	 * Set the entity primarily responsible for making the content of the
-	 * resource.
-	 */
-	public abstract void setCreatorProperty(String creator);
-
-	/**
-	 * Get the explanation of the content of the resource.
-	 */
-	public abstract Nullable<String> getDescriptionProperty();
-
-	/**
-	 * Set the explanation of the content of the resource.
-	 */
-	public abstract void setDescriptionProperty(String description);
-
-	/**
-	 * Get an unambiguous reference to the resource within a given context.
-	 */
-	public abstract Nullable<String> getIdentifierProperty();
-
-	/**
-	 * Set an unambiguous reference to the resource within a given context.
-	 */
-	public abstract void setIdentifierProperty(String identifier);
-
-	/**
-	 * Get a delimited set of keywords to support searching and indexing. This
-	 * is typically a list of terms that are not available elsewhere in the
-	 * properties
-	 */
-	public abstract Nullable<String> getKeywordsProperty();
-
-	/**
-	 * Set a delimited set of keywords to support searching and indexing. This
-	 * is typically a list of terms that are not available elsewhere in the
-	 * properties
-	 */
-	public abstract void setKeywordsProperty(String keywords);
-
-	/**
-	 * Get the language of the intellectual content of the resource.
-	 */
-	public abstract Nullable<String> getLanguageProperty();
-
-	/**
-	 * Set the language of the intellectual content of the resource.
-	 */
-	public abstract void setLanguageProperty(String language);
-
-	/**
-	 * Get the user who performed the last modification.
-	 */
-	public abstract Nullable<String> getLastModifiedByProperty();
-
-	/**
-	 * Set the user who performed the last modification.
-	 */
-	public abstract void setLastModifiedByProperty(String lastModifiedBy);
-
-	/**
-	 * Get the date and time of the last printing.
-	 */
-	public abstract Nullable<Date> getLastPrintedProperty();
-
-	/**
-	 * Set the date and time of the last printing.
-	 */
-	public abstract void setLastPrintedProperty(String lastPrinted);
-	
-	/**
-	 * Set the date and time of the last printing.
-	 */
-	public abstract void setLastPrintedProperty(Nullable<Date> lastPrinted);
-
-	/**
-	 * Get the date on which the resource was changed.
-	 */
-	public abstract Nullable<Date> getModifiedProperty();
-
-	/**
-	 * Set the date on which the resource was changed.
-	 */
-	public abstract void setModifiedProperty(String modified);
-	
-	/**
-	 * Set the date on which the resource was changed.
-	 */
-	public abstract void setModifiedProperty(Nullable<Date> modified);
-
-	/**
-	 * Get the revision number.
-	 */
-	public abstract Nullable<String> getRevisionProperty();
-
-	/**
-	 * Set the revision number.
-	 */
-	public abstract void setRevisionProperty(String revision);
-
-	/**
-	 * Get the topic of the content of the resource.
-	 */
-	public abstract Nullable<String> getSubjectProperty();
-
-	/**
-	 * Set the topic of the content of the resource.
-	 */
-	public abstract void setSubjectProperty(String subject);
-
-	/**
-	 * Get the name given to the resource.
-	 */
-	public abstract Nullable<String> getTitleProperty();
-
-	/**
-	 * Set the name given to the resource.
-	 */
-	public abstract void setTitleProperty(String title);
-
-	/**
-	 * Get the version number.
-	 */
-	public abstract Nullable<String> getVersionProperty();
-
-	/**
-	 * Set the version number.
-	 */
-	public abstract void setVersionProperty(String version);
-}
+/* ====================================================================
+   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;
+
+import java.util.Date;
+
+import org.apache.poi.openxml4j.util.Nullable;
+
+/**
+ * Represents the core properties of an OPC package.
+ * 
+ * @author Julien Chable
+ * @version 1.0
+ * @see org.apache.poi.openxml4j.opc.OPCPackage
+ */
+public interface PackageProperties {
+	
+	/**
+	 * Dublin Core Terms URI.
+	 */
+	public final static String NAMESPACE_DCTERMS = "http://purl.org/dc/terms/";
+	
+	/**
+	 * Dublin Core namespace URI.
+	 */
+	public final static String NAMESPACE_DC = "http://purl.org/dc/elements/1.1/";
+
+	/* Getters and setters */
+
+	/**
+	 * Set the category of the content of this package.
+	 */
+	public abstract Nullable<String> getCategoryProperty();
+
+	/**
+	 * Set the category of the content of this package.
+	 */
+	public abstract void setCategoryProperty(String category);
+
+	/**
+	 * Set the status of the content.
+	 */
+	public abstract Nullable<String> getContentStatusProperty();
+
+	/**
+	 * Get the status of the content.
+	 */
+	public abstract void setContentStatusProperty(String contentStatus);
+
+	/**
+	 * Get the type of content represented, generally defined by a specific use
+	 * and intended audience.
+	 */
+	public abstract Nullable<String> getContentTypeProperty();
+
+	/**
+	 * Set the type of content represented, generally defined by a specific use
+	 * and intended audience.
+	 */
+	public abstract void setContentTypeProperty(String contentType);
+
+	/**
+	 * Get the date of creation of the resource.
+	 */
+	public abstract Nullable<Date> getCreatedProperty();
+
+	/**
+	 * Set the date of creation of the resource.
+	 */
+	public abstract void setCreatedProperty(String created);
+	
+	/**
+	 * Set the date of creation of the resource.
+	 */
+	public abstract void setCreatedProperty(Nullable<Date> created);
+
+	/**
+	 * Get the entity primarily responsible for making the content of the
+	 * resource.
+	 */
+	public abstract Nullable<String> getCreatorProperty();
+
+	/**
+	 * Set the entity primarily responsible for making the content of the
+	 * resource.
+	 */
+	public abstract void setCreatorProperty(String creator);
+
+	/**
+	 * Get the explanation of the content of the resource.
+	 */
+	public abstract Nullable<String> getDescriptionProperty();
+
+	/**
+	 * Set the explanation of the content of the resource.
+	 */
+	public abstract void setDescriptionProperty(String description);
+
+	/**
+	 * Get an unambiguous reference to the resource within a given context.
+	 */
+	public abstract Nullable<String> getIdentifierProperty();
+
+	/**
+	 * Set an unambiguous reference to the resource within a given context.
+	 */
+	public abstract void setIdentifierProperty(String identifier);
+
+	/**
+	 * Get a delimited set of keywords to support searching and indexing. This
+	 * is typically a list of terms that are not available elsewhere in the
+	 * properties
+	 */
+	public abstract Nullable<String> getKeywordsProperty();
+
+	/**
+	 * Set a delimited set of keywords to support searching and indexing. This
+	 * is typically a list of terms that are not available elsewhere in the
+	 * properties
+	 */
+	public abstract void setKeywordsProperty(String keywords);
+
+	/**
+	 * Get the language of the intellectual content of the resource.
+	 */
+	public abstract Nullable<String> getLanguageProperty();
+
+	/**
+	 * Set the language of the intellectual content of the resource.
+	 */
+	public abstract void setLanguageProperty(String language);
+
+	/**
+	 * Get the user who performed the last modification.
+	 */
+	public abstract Nullable<String> getLastModifiedByProperty();
+
+	/**
+	 * Set the user who performed the last modification.
+	 */
+	public abstract void setLastModifiedByProperty(String lastModifiedBy);
+
+	/**
+	 * Get the date and time of the last printing.
+	 */
+	public abstract Nullable<Date> getLastPrintedProperty();
+
+	/**
+	 * Set the date and time of the last printing.
+	 */
+	public abstract void setLastPrintedProperty(String lastPrinted);
+	
+	/**
+	 * Set the date and time of the last printing.
+	 */
+	public abstract void setLastPrintedProperty(Nullable<Date> lastPrinted);
+
+	/**
+	 * Get the date on which the resource was changed.
+	 */
+	public abstract Nullable<Date> getModifiedProperty();
+
+	/**
+	 * Set the date on which the resource was changed.
+	 */
+	public abstract void setModifiedProperty(String modified);
+	
+	/**
+	 * Set the date on which the resource was changed.
+	 */
+	public abstract void setModifiedProperty(Nullable<Date> modified);
+
+	/**
+	 * Get the revision number.
+	 */
+	public abstract Nullable<String> getRevisionProperty();
+
+	/**
+	 * Set the revision number.
+	 */
+	public abstract void setRevisionProperty(String revision);
+
+	/**
+	 * Get the topic of the content of the resource.
+	 */
+	public abstract Nullable<String> getSubjectProperty();
+
+	/**
+	 * Set the topic of the content of the resource.
+	 */
+	public abstract void setSubjectProperty(String subject);
+
+	/**
+	 * Get the name given to the resource.
+	 */
+	public abstract Nullable<String> getTitleProperty();
+
+	/**
+	 * Set the name given to the resource.
+	 */
+	public abstract void setTitleProperty(String title);
+
+	/**
+	 * Get the version number.
+	 */
+	public abstract Nullable<String> getVersionProperty();
+
+	/**
+	 * Set the version number.
+	 */
+	public abstract void setVersionProperty(String version);
+}

Modified: poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/PackageRelationship.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/PackageRelationship.java?rev=755699&r1=755698&r2=755699&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/PackageRelationship.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/PackageRelationship.java Wed Mar 18 18:54:01 2009
@@ -1,227 +1,227 @@
-/* ====================================================================
-   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;
-
-import java.net.URI;
-import java.net.URISyntaxException;
-
-/**
- * A part relationship.
- * 
- * @author Julien Chable
- * @version 1.0
- */
-public final class PackageRelationship {
-
-	private static URI containerRelationshipPart;
-
-	static {
-		try {
-			containerRelationshipPart = new URI("/_rels/.rels");
-		} catch (URISyntaxException e) {
-			// Do nothing
-		}
-	}
-
-	/* XML markup */
-
-	public static final String ID_ATTRIBUTE_NAME = "Id";
-
-	public static final String RELATIONSHIPS_TAG_NAME = "Relationships";
-
-	public static final String RELATIONSHIP_TAG_NAME = "Relationship";
-
-	public static final String TARGET_ATTRIBUTE_NAME = "Target";
-
-	public static final String TARGET_MODE_ATTRIBUTE_NAME = "TargetMode";
-
-	public static final String TYPE_ATTRIBUTE_NAME = "Type";
-
-	/* End XML markup */
-
-	/**
-	 * L'ID de la relation.
-	 */
-	private String id;
-
-	/**
-	 * Reference to the package.
-	 */
-	private Package container;
-
-	/**
-	 * Type de relation.
-	 */
-	private String relationshipType;
-
-	/**
-	 * Partie source de cette relation.
-	 */
-	private PackagePart source;
-
-	/**
-	 * Le mode de ciblage [Internal|External]
-	 */
-	private TargetMode targetMode;
-
-	/**
-	 * URI de la partie cible.
-	 */
-	private URI targetUri;
-
-	/**
-	 * Constructor.
-	 * 
-	 * @param pkg
-	 * @param sourcePart
-	 * @param targetUri
-	 * @param targetMode
-	 * @param relationshipType
-	 * @param id
-	 */
-	public PackageRelationship(Package pkg, PackagePart sourcePart,
-			URI targetUri, TargetMode targetMode, String relationshipType,
-			String id) {
-		if (pkg == null)
-			throw new IllegalArgumentException("pkg");
-		if (targetUri == null)
-			throw new IllegalArgumentException("targetUri");
-		if (relationshipType == null)
-			throw new IllegalArgumentException("relationshipType");
-		if (id == null)
-			throw new IllegalArgumentException("id");
-
-		this.container = pkg;
-		this.source = sourcePart;
-		this.targetUri = targetUri;
-		this.targetMode = targetMode;
-		this.relationshipType = relationshipType;
-		this.id = id;
-	}
-
-	@Override
-	public boolean equals(Object obj) {
-		if (!(obj instanceof PackageRelationship)) {
-			return false;
-		}
-		PackageRelationship rel = (PackageRelationship) obj;
-		return (this.id == rel.id
-				&& this.relationshipType == rel.relationshipType
-				&& (rel.source != null ? rel.source.equals(this.source) : true)
-				&& this.targetMode == rel.targetMode && this.targetUri
-				.equals(rel.targetUri));
-	}
-
-	@Override
-	public int hashCode() {
-		return this.id.hashCode() + this.relationshipType.hashCode()
-				+ this.source.hashCode() + this.targetMode.hashCode()
-				+ this.targetUri.hashCode();
-	}
-
-	/* Getters */
-
-	public URI getContainerPartRelationship() {
-		return containerRelationshipPart;
-	}
-
-	/**
-	 * @return the container
-	 */
-	public Package getPackage() {
-		return container;
-	}
-
-	/**
-	 * @return the id
-	 */
-	public String getId() {
-		return id;
-	}
-
-	/**
-	 * @return the relationshipType
-	 */
-	public String getRelationshipType() {
-		return relationshipType;
-	}
-
-	/**
-	 * @return the source
-	 */
-	public PackagePart getSource() {
-		return source;
-	}
-
-	/**
-	 * 
-	 * @return URL of the source part of this relationship
-	 */
-	public URI getSourceURI() {
-		if (source == null) {
-			return PackagingURIHelper.PACKAGE_ROOT_URI;
-		}
-		return source.partName.getURI();
-	}
-
-	/**
-	 * public URI getSourceUri(){ }
-	 * 
-	 * @return the targetMode
-	 */
-	public TargetMode getTargetMode() {
-		return targetMode;
-	}
-
-	/**
-	 * @return the targetUri
-	 */
-	public URI getTargetURI() {
-		// If it's an external target, we don't
-		//  need to apply our normal validation rules
-		if(targetMode == TargetMode.EXTERNAL) {
-			return targetUri;
-		}
-		
-		// Internal target
-		// If it isn't absolute, resolve it relative
-		//  to ourselves
-		if (!targetUri.toASCIIString().startsWith("/")) {
-			// So it's a relative part name, try to resolve it
-			return PackagingURIHelper.resolvePartUri(getSourceURI(), targetUri);
-		}
-		return targetUri;
-	}
-
-	@Override
-	public String toString() {
-		StringBuilder sb = new StringBuilder();
-		sb.append(id == null ? "id=null" : "id=" + id);
-		sb.append(container == null ? " - container=null" : " - container="
-				+ container.toString());
-		sb.append(relationshipType == null ? " - relationshipType=null"
-				: " - relationshipType=" + relationshipType.toString());
-		sb.append(source == null ? " - source=null" : " - source="
-				+ getSourceURI().toASCIIString());
-		sb.append(targetUri == null ? " - target=null" : " - target="
-				+ getTargetURI().toASCIIString());
-		sb.append(targetMode == null ? ",targetMode=null" : ",targetMode="
-				+ targetMode.toString());
-		return sb.toString();
-	}
-}
+/* ====================================================================
+   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;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+
+/**
+ * A part relationship.
+ * 
+ * @author Julien Chable
+ * @version 1.0
+ */
+public final class PackageRelationship {
+
+	private static URI containerRelationshipPart;
+
+	static {
+		try {
+			containerRelationshipPart = new URI("/_rels/.rels");
+		} catch (URISyntaxException e) {
+			// Do nothing
+		}
+	}
+
+	/* XML markup */
+
+	public static final String ID_ATTRIBUTE_NAME = "Id";
+
+	public static final String RELATIONSHIPS_TAG_NAME = "Relationships";
+
+	public static final String RELATIONSHIP_TAG_NAME = "Relationship";
+
+	public static final String TARGET_ATTRIBUTE_NAME = "Target";
+
+	public static final String TARGET_MODE_ATTRIBUTE_NAME = "TargetMode";
+
+	public static final String TYPE_ATTRIBUTE_NAME = "Type";
+
+	/* End XML markup */
+
+	/**
+	 * L'ID de la relation.
+	 */
+	private String id;
+
+	/**
+	 * Reference to the package.
+	 */
+	private OPCPackage container;
+
+	/**
+	 * Type de relation.
+	 */
+	private String relationshipType;
+
+	/**
+	 * Partie source de cette relation.
+	 */
+	private PackagePart source;
+
+	/**
+	 * Le mode de ciblage [Internal|External]
+	 */
+	private TargetMode targetMode;
+
+	/**
+	 * URI de la partie cible.
+	 */
+	private URI targetUri;
+
+	/**
+	 * Constructor.
+	 * 
+	 * @param pkg
+	 * @param sourcePart
+	 * @param targetUri
+	 * @param targetMode
+	 * @param relationshipType
+	 * @param id
+	 */
+	public PackageRelationship(OPCPackage pkg, PackagePart sourcePart,
+			URI targetUri, TargetMode targetMode, String relationshipType,
+			String id) {
+		if (pkg == null)
+			throw new IllegalArgumentException("pkg");
+		if (targetUri == null)
+			throw new IllegalArgumentException("targetUri");
+		if (relationshipType == null)
+			throw new IllegalArgumentException("relationshipType");
+		if (id == null)
+			throw new IllegalArgumentException("id");
+
+		this.container = pkg;
+		this.source = sourcePart;
+		this.targetUri = targetUri;
+		this.targetMode = targetMode;
+		this.relationshipType = relationshipType;
+		this.id = id;
+	}
+
+	@Override
+	public boolean equals(Object obj) {
+		if (!(obj instanceof PackageRelationship)) {
+			return false;
+		}
+		PackageRelationship rel = (PackageRelationship) obj;
+		return (this.id == rel.id
+				&& this.relationshipType == rel.relationshipType
+				&& (rel.source != null ? rel.source.equals(this.source) : true)
+				&& this.targetMode == rel.targetMode && this.targetUri
+				.equals(rel.targetUri));
+	}
+
+	@Override
+	public int hashCode() {
+		return this.id.hashCode() + this.relationshipType.hashCode()
+				+ this.source.hashCode() + this.targetMode.hashCode()
+				+ this.targetUri.hashCode();
+	}
+
+	/* Getters */
+
+	public URI getContainerPartRelationship() {
+		return containerRelationshipPart;
+	}
+
+	/**
+	 * @return the container
+	 */
+	public OPCPackage getPackage() {
+		return container;
+	}
+
+	/**
+	 * @return the id
+	 */
+	public String getId() {
+		return id;
+	}
+
+	/**
+	 * @return the relationshipType
+	 */
+	public String getRelationshipType() {
+		return relationshipType;
+	}
+
+	/**
+	 * @return the source
+	 */
+	public PackagePart getSource() {
+		return source;
+	}
+
+	/**
+	 * 
+	 * @return URL of the source part of this relationship
+	 */
+	public URI getSourceURI() {
+		if (source == null) {
+			return PackagingURIHelper.PACKAGE_ROOT_URI;
+		}
+		return source.partName.getURI();
+	}
+
+	/**
+	 * public URI getSourceUri(){ }
+	 * 
+	 * @return the targetMode
+	 */
+	public TargetMode getTargetMode() {
+		return targetMode;
+	}
+
+	/**
+	 * @return the targetUri
+	 */
+	public URI getTargetURI() {
+		// If it's an external target, we don't
+		//  need to apply our normal validation rules
+		if(targetMode == TargetMode.EXTERNAL) {
+			return targetUri;
+		}
+		
+		// Internal target
+		// If it isn't absolute, resolve it relative
+		//  to ourselves
+		if (!targetUri.toASCIIString().startsWith("/")) {
+			// So it's a relative part name, try to resolve it
+			return PackagingURIHelper.resolvePartUri(getSourceURI(), targetUri);
+		}
+		return targetUri;
+	}
+
+	@Override
+	public String toString() {
+		StringBuilder sb = new StringBuilder();
+		sb.append(id == null ? "id=null" : "id=" + id);
+		sb.append(container == null ? " - container=null" : " - container="
+				+ container.toString());
+		sb.append(relationshipType == null ? " - relationshipType=null"
+				: " - relationshipType=" + relationshipType.toString());
+		sb.append(source == null ? " - source=null" : " - source="
+				+ getSourceURI().toASCIIString());
+		sb.append(targetUri == null ? " - target=null" : " - target="
+				+ getTargetURI().toASCIIString());
+		sb.append(targetMode == null ? ",targetMode=null" : ",targetMode="
+				+ targetMode.toString());
+		return sb.toString();
+	}
+}



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


Mime
View raw message