ASF Bugzilla – Attachment 23386 Details for
Bug 46859
[Patch] rename org.apache.poi.openxml4j.opc.Package
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
svn diff
diff46859-pkgRename.txt (text/plain), 165.65 KB, created by
Josh Micich
on 2009-03-15 23:44:53 UTC
(
hide
)
Description:
svn diff
Filename:
MIME Type:
Creator:
Josh Micich
Created:
2009-03-15 23:44:53 UTC
Size:
165.65 KB
patch
obsolete
>Index: src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackagePart.java >=================================================================== >--- src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackagePart.java (revision 754500) >+++ src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackagePart.java (working copy) >@@ -53,7 +53,7 @@ > * @throws InvalidFormatException > * Throws if the content of this part invalid. > */ >- public ZipPackagePart(Package container, PackagePartName partName, >+ public ZipPackagePart(OPCPackage container, PackagePartName partName, > String contentType) throws InvalidFormatException { > super(container, partName, contentType); > } >@@ -72,7 +72,7 @@ > * @throws InvalidFormatException > * Throws if the content of this part is invalid. > */ >- public ZipPackagePart(Package container, ZipEntry zipEntry, >+ public ZipPackagePart(OPCPackage container, ZipEntry zipEntry, > PackagePartName partName, String contentType) > throws InvalidFormatException { > super(container, partName, contentType); >Index: src/ooxml/java/org/apache/poi/openxml4j/opc/PackageProperties.java >=================================================================== >--- src/ooxml/java/org/apache/poi/openxml4j/opc/PackageProperties.java (revision 754500) >+++ src/ooxml/java/org/apache/poi/openxml4j/opc/PackageProperties.java (working copy) >@@ -26,7 +26,7 @@ > * > * @author Julien Chable > * @version 1.0 >- * @see org.apache.poi.openxml4j.opc.Package >+ * @see org.apache.poi.openxml4j.opc.OPCPackage > */ > public interface PackageProperties { > >Index: src/ooxml/java/org/apache/poi/openxml4j/opc/PackageRelationship.java >=================================================================== >--- src/ooxml/java/org/apache/poi/openxml4j/opc/PackageRelationship.java (revision 754500) >+++ src/ooxml/java/org/apache/poi/openxml4j/opc/PackageRelationship.java (working copy) >@@ -62,7 +62,7 @@ > /** > * Reference to the package. > */ >- private Package container; >+ private OPCPackage container; > > /** > * Type de relation. >@@ -94,7 +94,7 @@ > * @param relationshipType > * @param id > */ >- public PackageRelationship(Package pkg, PackagePart sourcePart, >+ public PackageRelationship(OPCPackage pkg, PackagePart sourcePart, > URI targetUri, TargetMode targetMode, String relationshipType, > String id) { > if (pkg == null) >@@ -143,7 +143,7 @@ > /** > * @return the container > */ >- public Package getPackage() { >+ public OPCPackage getPackage() { > return container; > } > >Index: src/ooxml/java/org/apache/poi/openxml4j/opc/PackagePart.java >=================================================================== >--- src/ooxml/java/org/apache/poi/openxml4j/opc/PackagePart.java (revision 754500) >+++ src/ooxml/java/org/apache/poi/openxml4j/opc/PackagePart.java (working copy) >@@ -39,7 +39,7 @@ > /** > * This part's container. > */ >- protected Package container; >+ protected OPCPackage container; > > /** > * The part name. (required by the specification [M1.1]) >@@ -78,7 +78,7 @@ > * @throws InvalidFormatException > * If the specified URI is not valid. > */ >- protected PackagePart(Package pack, PackagePartName partName, >+ protected PackagePart(OPCPackage pack, PackagePartName partName, > ContentType contentType) throws InvalidFormatException { > this(pack, partName, contentType, true); > } >@@ -97,12 +97,12 @@ > * @throws InvalidFormatException > * If the specified URI is not valid. > */ >- protected PackagePart(Package pack, PackagePartName partName, >+ protected PackagePart(OPCPackage pack, PackagePartName partName, > ContentType contentType, boolean loadRelationships) > throws InvalidFormatException { > this.partName = partName; > this.contentType = contentType; >- this.container = (ZipPackage) pack; >+ 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(); >@@ -123,7 +123,7 @@ > * The Multipurpose Internet Mail Extensions (MIME) content type > * of the part's data stream. > */ >- public PackagePart(Package pack, PackagePartName partName, >+ public PackagePart(OPCPackage pack, PackagePartName partName, > String contentType) throws InvalidFormatException { > this(pack, partName, new ContentType(contentType)); > } >@@ -567,7 +567,7 @@ > "You can't change the content type of a part."); > } > >- public Package getPackage() { >+ public OPCPackage getPackage() { > return container; > } > >Index: src/ooxml/java/org/apache/poi/openxml4j/opc/PackageRelationshipCollection.java >=================================================================== >--- src/ooxml/java/org/apache/poi/openxml4j/opc/PackageRelationshipCollection.java (revision 754500) >+++ src/ooxml/java/org/apache/poi/openxml4j/opc/PackageRelationshipCollection.java (working copy) >@@ -71,7 +71,7 @@ > /** > * Reference to the package. > */ >- private Package container; >+ private OPCPackage container; > > /** > * Constructor. >@@ -105,7 +105,7 @@ > /** > * Constructor. > */ >- public PackageRelationshipCollection(Package container) >+ public PackageRelationshipCollection(OPCPackage container) > throws InvalidFormatException { > this(container, null); > } >@@ -136,7 +136,7 @@ > * If an error occurs during the parsing of the relatinships > * part fo the specified part. > */ >- public PackageRelationshipCollection(Package container, PackagePart part) >+ public PackageRelationshipCollection(OPCPackage container, PackagePart part) > throws InvalidFormatException { > this(); > >Index: src/ooxml/java/org/apache/poi/openxml4j/opc/Package.java >=================================================================== >--- src/ooxml/java/org/apache/poi/openxml4j/opc/Package.java (revision 754500) >+++ src/ooxml/java/org/apache/poi/openxml4j/opc/Package.java (working copy) >@@ -17,174 +17,51 @@ > > package org.apache.poi.openxml4j.opc; > >-import java.io.ByteArrayOutputStream; > import java.io.File; >-import java.io.FileInputStream; >-import java.io.FileNotFoundException; >-import java.io.FileOutputStream; > import java.io.IOException; > import java.io.InputStream; > import java.io.OutputStream; >-import java.net.URI; >-import java.net.URISyntaxException; >-import java.util.ArrayList; > import java.util.Date; >-import java.util.Hashtable; >-import java.util.concurrent.locks.ReentrantReadWriteLock; > > 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.exceptions.OpenXML4JRuntimeException; >-import org.apache.poi.openxml4j.opc.internal.ContentType; >-import org.apache.poi.openxml4j.opc.internal.ContentTypeManager; > import org.apache.poi.openxml4j.opc.internal.PackagePropertiesPart; >-import org.apache.poi.openxml4j.opc.internal.PartMarshaller; >-import org.apache.poi.openxml4j.opc.internal.PartUnmarshaller; > import org.apache.poi.openxml4j.opc.internal.ZipContentTypeManager; >-import org.apache.poi.openxml4j.opc.internal.marshallers.DefaultMarshaller; >-import org.apache.poi.openxml4j.opc.internal.marshallers.ZipPackagePropertiesMarshaller; >-import org.apache.poi.openxml4j.opc.internal.unmarshallers.PackagePropertiesUnmarshaller; >-import org.apache.poi.openxml4j.opc.internal.unmarshallers.UnmarshallContext; > import org.apache.poi.openxml4j.util.Nullable; >-import org.apache.poi.util.POILogger; > import org.apache.poi.util.POILogFactory; >+import org.apache.poi.util.POILogger; > > /** >- * Represents a container that can store multiple data objects. >+ * @deprecated (name clash with {@link java.lang.Package} use {@link OPCPackage} instead. > * > * @author Julien Chable, CDubet >- * @version 0.1 >+ * > */ >-public abstract class Package implements RelationshipSource { >+public abstract class Package extends OPCPackage { > > /** > * Logger. > */ > private static POILogger logger = POILogFactory.getLogger(Package.class); > >- /** >- * Default package access. >- */ >- protected static final PackageAccess defaultPackageAccess = PackageAccess.READ_WRITE; > > /** >- * Package access. >+ * @deprecated use {@link OPCPackage} > */ >- private PackageAccess packageAccess; >- >- /** >- * Package parts collection. >- */ >- protected PackagePartCollection partList; >- >- /** >- * Package relationships. >- */ >- protected PackageRelationshipCollection relationships; >- >- /** >- * Part marshallers by content type. >- */ >- protected Hashtable<ContentType, PartMarshaller> partMarshallers; >- >- /** >- * Default part marshaller. >- */ >- protected PartMarshaller defaultPartMarshaller; >- >- /** >- * Part unmarshallers by content type. >- */ >- protected Hashtable<ContentType, PartUnmarshaller> partUnmarshallers; >- >- /** >- * Core package properties. >- */ >- protected PackagePropertiesPart packageProperties; >- >- /** >- * Manage parts content types of this package. >- */ >- protected ContentTypeManager contentTypeManager; >- >- /** >- * Flag if a modification is done to the document. >- */ >- protected boolean isDirty = false; >- >- /** >- * File path of this package. >- */ >- protected String originalPackagePath; >- >- /** >- * Output stream for writing this package. >- */ >- protected OutputStream output; >- >- /** >- * Constructor. >- * >- * @param access >- * Package access. >- */ > protected Package(PackageAccess access) { >- init(); >- this.packageAccess = access; >+ super(access); > } > >- /** >- * Initialize the package instance. >- */ >- private void init() { >- this.partMarshallers = new Hashtable<ContentType, PartMarshaller>(5); >- this.partUnmarshallers = new Hashtable<ContentType, PartUnmarshaller>(2); > >- try { >- // Add 'default' unmarshaller >- this.partUnmarshallers.put(new ContentType( >- ContentTypes.CORE_PROPERTIES_PART), >- new PackagePropertiesUnmarshaller()); >- >- // Add default marshaller >- this.defaultPartMarshaller = new DefaultMarshaller(); >- // TODO Delocalize specialized marshallers >- this.partMarshallers.put(new ContentType( >- ContentTypes.CORE_PROPERTIES_PART), >- new ZipPackagePropertiesMarshaller()); >- } catch (InvalidFormatException e) { >- // Should never happpen >- throw new OpenXML4JRuntimeException( >- "Package.init() : this exception should never happen, if you read this message please send a mail to the developers team."); >- } >- } >- > /** >- * Open a package with read/write permission. >- * >- * @param path >- * The document path. >- * @return A Package object, else <b>null</b>. >- * @throws InvalidFormatException >- * If the specified file doesn't exist, and a parsing error >- * occur. >+ * @deprecated use {@link OPCPackage#open(String)} > */ > public static Package open(String path) throws InvalidFormatException { > return open(path, defaultPackageAccess); > } > > /** >- * Open a package. >- * >- * @param path >- * The document path. >- * @param access >- * Package access. >- * @return A Package object, else <b>null</b>. >- * @throws InvalidFormatException >- * If the specified file doesn't exist, and a parsing error >- * occur. >+ * @deprecated use {@link OPCPackage#open(String,PackageAccess)} > */ > public static Package open(String path, PackageAccess access) > throws InvalidFormatException { >@@ -201,15 +78,7 @@ > } > > /** >- * Open a package. >- * >- * Note - uses quite a bit more memory than {@link #open(String)}, which >- * doesn't need to hold the whole zip file in memory, and can take advantage >- * of native methods >- * >- * @param in >- * The InputStream to read the package from >- * @return A Package object >+ * @deprecated use {@link OPCPackage#open(InputStream)} > */ > public static Package open(InputStream in) throws InvalidFormatException, > IOException { >@@ -221,14 +90,7 @@ > } > > /** >- * Opens a package if it exists, else it creates one. >- * >- * @param file >- * The file to open or to create. >- * @return A newly created package if the specified file does not exist, >- * else the package extract from the file. >- * @throws InvalidFormatException >- * Throws if the specified file exist and is not valid. >+ * @deprecated use {@link OPCPackage#open(File)} > */ > public static Package openOrCreate(File file) throws InvalidFormatException { > Package retPackage = null; >@@ -241,22 +103,14 @@ > } > > /** >- * Creates a new package. >- * >- * @param path >- * Path of the document. >- * @return A newly created Package ready to use. >+ * @deprecated use {@link OPCPackage#create(String)} > */ > public static Package create(String path) { > return create(new File(path)); > } > > /** >- * Creates a new package. >- * >- * @param file >- * Path of the document. >- * @return A newly created Package ready to use. >+ * @deprecated use {@link OPCPackage#create(File)} > */ > public static Package create(File file) { > if (file == null || (file.exists() && file.isDirectory())) >@@ -276,6 +130,9 @@ > return pkg; > } > >+ /** >+ * @deprecated use {@link OPCPackage#create(OutputStream)} >+ */ > public static Package create(OutputStream output) { > Package pkg = null; > pkg = new ZipPackage(); >@@ -318,1080 +175,5 @@ > } > } > >- /** >- * Flush the package : save all. >- * >- * @see #close() >- */ >- public void flush() { >- throwExceptionIfReadOnly(); > >- if (this.packageProperties != null) >- ((PackagePropertiesPart) this.packageProperties).flush(); >- >- this.flushImpl(); >- } >- >- /** >- * Close the package and save its content. >- * >- * @throws IOException >- * If an IO exception occur during the saving process. >- */ >- public void close() throws IOException { >- if (this.packageAccess == PackageAccess.READ) { >- logger >- .log(POILogger.WARN, "The close() method is intended to SAVE a package. This package is open in READ ONLY mode, use the revert() method instead !"); >- return; >- } >- >- // Save the content >- ReentrantReadWriteLock l = new ReentrantReadWriteLock(); >- try { >- l.writeLock().lock(); >- if (this.originalPackagePath != null >- && !"".equals(this.originalPackagePath.trim())) { >- File targetFile = new File(this.originalPackagePath); >- if (!targetFile.exists() >- || !(this.originalPackagePath >- .equalsIgnoreCase(targetFile.getAbsolutePath()))) { >- // Case of a package created from scratch >- save(targetFile); >- } else { >- closeImpl(); >- } >- } else if (this.output != null) { >- save(this.output); >- } >- } finally { >- l.writeLock().unlock(); >- } >- >- // Clear >- this.contentTypeManager.clearAll(); >- >- // Call the garbage collector >- Runtime.getRuntime().gc(); >- } >- >- /** >- * Close the package WITHOUT saving its content. Reinitialize this package >- * and cancel all changes done to it. >- */ >- public void revert() { >- revertImpl(); >- } >- >- /** >- * Add a thumbnail to the package. This method is provided to make easier >- * the addition of a thumbnail in a package. You can do the same work by >- * using the traditionnal relationship and part mechanism. >- * >- * @param path >- * The full path to the image file. >- */ >- public void addThumbnail(String path) throws IOException { >- // Check parameter >- if ("".equals(path)) >- throw new IllegalArgumentException("path"); >- >- // Get the filename from the path >- String filename = path >- .substring(path.lastIndexOf(File.separatorChar) + 1); >- >- // Create the thumbnail part name >- String contentType = ContentTypes >- .getContentTypeFromFileExtension(filename); >- PackagePartName thumbnailPartName = null; >- try { >- thumbnailPartName = PackagingURIHelper.createPartName("/docProps/" >- + filename); >- } catch (InvalidFormatException e) { >- try { >- thumbnailPartName = PackagingURIHelper >- .createPartName("/docProps/thumbnail" >- + path.substring(path.lastIndexOf(".") + 1)); >- } catch (InvalidFormatException e2) { >- throw new InvalidOperationException( >- "Can't add a thumbnail file named '" + filename + "'"); >- } >- } >- >- // Check if part already exist >- if (this.getPart(thumbnailPartName) != null) >- throw new InvalidOperationException( >- "You already add a thumbnail named '" + filename + "'"); >- >- // Add the thumbnail part to this package. >- PackagePart thumbnailPart = this.createPart(thumbnailPartName, >- contentType, false); >- >- // Add the relationship between the package and the thumbnail part >- this.addRelationship(thumbnailPartName, TargetMode.INTERNAL, >- PackageRelationshipTypes.THUMBNAIL); >- >- // Copy file data to the newly created part >- StreamHelper.copyStream(new FileInputStream(path), thumbnailPart >- .getOutputStream()); >- } >- >- /** >- * Throws an exception if the package access mode is in read only mode >- * (PackageAccess.Read). >- * >- * @throws InvalidOperationException >- * Throws if a writing operation is done on a read only package. >- * @see org.apache.poi.openxml4j.opc.PackageAccess >- */ >- void throwExceptionIfReadOnly() throws InvalidOperationException { >- if (packageAccess == PackageAccess.READ) >- throw new InvalidOperationException( >- "Operation not allowed, document open in read only mode!"); >- } >- >- /** >- * Throws an exception if the package access mode is in write only mode >- * (PackageAccess.Write). This method is call when other methods need write >- * right. >- * >- * @throws InvalidOperationException >- * Throws if a read operation is done on a write only package. >- * @see org.apache.poi.openxml4j.opc.PackageAccess >- */ >- void throwExceptionIfWriteOnly() throws InvalidOperationException { >- if (packageAccess == PackageAccess.WRITE) >- throw new InvalidOperationException( >- "Operation not allowed, document open in write only mode!"); >- } >- >- /** >- * Retrieves or creates if none exists, core package property part. >- * >- * @return The PackageProperties part of this package. >- */ >- public PackageProperties getPackageProperties() >- throws InvalidFormatException { >- this.throwExceptionIfWriteOnly(); >- // If no properties part has been found then we create one >- if (this.packageProperties == null) { >- this.packageProperties = new PackagePropertiesPart(this, >- PackagingURIHelper.CORE_PROPERTIES_PART_NAME); >- } >- return this.packageProperties; >- } >- >- /** >- * Retrieve a part identified by its name. >- * >- * @param partName >- * Part name of the part to retrieve. >- * @return The part with the specified name, else <code>null</code>. >- */ >- public PackagePart getPart(PackagePartName partName) { >- throwExceptionIfWriteOnly(); >- >- if (partName == null) >- throw new IllegalArgumentException("partName"); >- >- // If the partlist is null, then we parse the package. >- if (partList == null) { >- try { >- getParts(); >- } catch (InvalidFormatException e) { >- return null; >- } >- } >- return getPartImpl(partName); >- } >- >- /** >- * Retrieve parts by content type. >- * >- * @param contentType >- * The content type criteria. >- * @return All part associated to the specified content type. >- */ >- public ArrayList<PackagePart> getPartsByContentType(String contentType) { >- ArrayList<PackagePart> retArr = new ArrayList<PackagePart>(); >- for (PackagePart part : partList.values()) { >- if (part.getContentType().equals(contentType)) >- retArr.add(part); >- } >- return retArr; >- } >- >- /** >- * Retrieve parts by relationship type. >- * >- * @param relationshipType >- * Relationship type. >- * @return All parts which are the target of a relationship with the >- * specified type, if the method can't retrieve relationships from >- * the package, then return <code>null</code>. >- */ >- public ArrayList<PackagePart> getPartsByRelationshipType( >- String relationshipType) { >- if (relationshipType == null) >- throw new IllegalArgumentException("relationshipType"); >- ArrayList<PackagePart> retArr = new ArrayList<PackagePart>(); >- try { >- for (PackageRelationship rel : getRelationshipsByType(relationshipType)) { >- retArr.add(getPart(rel)); >- } >- } catch (OpenXML4JException e) { >- logger >- .log(POILogger.WARN, "Can't retrieve parts by relationship type: an exception has been thrown by getRelationshipsByType method"); >- return null; >- } >- return retArr; >- } >- >- /** >- * Get the target part from the specified relationship. >- * >- * @param partRel >- * The part relationship uses to retrieve the part. >- */ >- public PackagePart getPart(PackageRelationship partRel) { >- PackagePart retPart = null; >- ensureRelationships(); >- for (PackageRelationship rel : relationships) { >- if (rel.getRelationshipType().equals(partRel.getRelationshipType())) { >- try { >- retPart = getPart(PackagingURIHelper.createPartName(rel >- .getTargetURI())); >- } catch (InvalidFormatException e) { >- continue; >- } >- break; >- } >- } >- return retPart; >- } >- >- /** >- * Load the parts of the archive if it has not been done yet The >- * relationships of each part are not loaded >- * >- * @return All this package's parts. >- */ >- public ArrayList<PackagePart> getParts() throws InvalidFormatException { >- throwExceptionIfWriteOnly(); >- >- // If the part list is null, we parse the package to retrieve all parts. >- if (partList == null) { >- /* Variables use to validate OPC Compliance */ >- >- // Ensure rule M4.1 -> A format consumer shall consider more than >- // one core properties relationship for a package to be an error >- boolean hasCorePropertiesPart = false; >- >- PackagePart[] parts = this.getPartsImpl(); >- this.partList = new PackagePartCollection(); >- for (PackagePart part : parts) { >- if (partList.containsKey(part.partName)) >- throw new InvalidFormatException( >- "A part with the name '" >- + part.partName >- + "' already exist : Packages shall not contain equivalent part names and package implementers shall neither create nor recognize packages with equivalent part names. [M1.12]"); >- >- // Check OPC compliance rule M4.1 >- if (part.getContentType().equals( >- ContentTypes.CORE_PROPERTIES_PART)) { >- if (!hasCorePropertiesPart) >- hasCorePropertiesPart = true; >- else >- throw new InvalidFormatException( >- "OPC Compliance error [M4.1]: there is more than one core properties relationship in the package !"); >- } >- >- PartUnmarshaller partUnmarshaller = partUnmarshallers >- .get(part.contentType); >- >- if (partUnmarshaller != null) { >- UnmarshallContext context = new UnmarshallContext(this, >- part.partName); >- try { >- PackagePart unmarshallPart = partUnmarshaller >- .unmarshall(context, part.getInputStream()); >- partList.put(unmarshallPart.partName, unmarshallPart); >- >- // Core properties case >- if (unmarshallPart instanceof PackagePropertiesPart) >- this.packageProperties = (PackagePropertiesPart) unmarshallPart; >- } catch (IOException ioe) { >- logger.log(POILogger.WARN, "Unmarshall operation : IOException for " >- + part.partName); >- continue; >- } catch (InvalidOperationException invoe) { >- throw new InvalidFormatException(invoe.getMessage()); >- } >- } else { >- try { >- partList.put(part.partName, part); >- } catch (InvalidOperationException e) { >- throw new InvalidFormatException(e.getMessage()); >- } >- } >- } >- } >- return new ArrayList<PackagePart>(partList.values()); >- } >- >- /** >- * Create and add a part, with the specified name and content type, to the >- * package. >- * >- * @param partName >- * Part name. >- * @param contentType >- * Part content type. >- * @return The newly created part. >- * @throws InvalidFormatException >- * If rule M1.12 is not verified : Packages shall not contain >- * equivalent part names and package implementers shall neither >- * create nor recognize packages with equivalent part names. >- * @see #createPartImpl(PackagePartName, String, boolean) >- */ >- public PackagePart createPart(PackagePartName partName, String contentType) { >- return this.createPart(partName, contentType, true); >- } >- >- /** >- * Create and add a part, with the specified name and content type, to the >- * package. For general purpose, prefer the overload version of this method >- * without the 'loadRelationships' parameter. >- * >- * @param partName >- * Part name. >- * @param contentType >- * Part content type. >- * @param loadRelationships >- * Specify if the existing relationship part, if any, logically >- * associated to the newly created part will be loaded. >- * @return The newly created part. >- * @throws InvalidFormatException >- * If rule M1.12 is not verified : Packages shall not contain >- * equivalent part names and package implementers shall neither >- * create nor recognize packages with equivalent part names. >- * @see {@link#createPartImpl(URI, String)} >- */ >- PackagePart createPart(PackagePartName partName, String contentType, >- boolean loadRelationships) { >- throwExceptionIfReadOnly(); >- if (partName == null) { >- throw new IllegalArgumentException("partName"); >- } >- >- if (contentType == null || contentType == "") { >- throw new IllegalArgumentException("contentType"); >- } >- >- // Check if the specified part name already exists >- if (partList.containsKey(partName) >- && !partList.get(partName).isDeleted()) { >- throw new InvalidOperationException( >- "A part with the name '" >- + partName.getName() >- + "' already exists : Packages shall not contain equivalent part names and package implementers shall neither create nor recognize packages with equivalent part names. [M1.12]"); >- } >- >- /* Check OPC compliance */ >- >- // Rule [M4.1]: The format designer shall specify and the format >- // producer >- // shall create at most one core properties relationship for a package. >- // A format consumer shall consider more than one core properties >- // relationship for a package to be an error. If present, the >- // relationship shall target the Core Properties part. >- if (contentType == ContentTypes.CORE_PROPERTIES_PART) { >- if (this.packageProperties != null) >- throw new InvalidOperationException( >- "OPC Compliance error [M4.1]: you try to add more than one core properties relationship in the package !"); >- } >- >- /* End check OPC compliance */ >- >- PackagePart part = this.createPartImpl(partName, contentType, >- loadRelationships); >- this.contentTypeManager.addContentType(partName, contentType); >- this.partList.put(partName, part); >- this.isDirty = true; >- return part; >- } >- >- /** >- * Add a part to the package. >- * >- * @param partName >- * Part name of the part to create. >- * @param contentType >- * type associated with the file >- * @param content >- * the contents to add. In order to have faster operation in >- * document merge, the data are stored in memory not on a hard >- * disk >- * >- * @return The new part. >- * @see #createPart(PackagePartName, String) >- */ >- public PackagePart createPart(PackagePartName partName, String contentType, >- ByteArrayOutputStream content) { >- PackagePart addedPart = this.createPart(partName, contentType); >- if (addedPart == null) { >- return null; >- } >- // Extract the zip entry content to put it in the part content >- if (content != null) { >- try { >- OutputStream partOutput = addedPart.getOutputStream(); >- if (partOutput == null) { >- return null; >- } >- >- partOutput.write(content.toByteArray(), 0, content.size()); >- partOutput.close(); >- >- } catch (IOException ioe) { >- return null; >- } >- } else { >- return null; >- } >- return addedPart; >- } >- >- /** >- * Add the specified part to the package. If a part already exists in the >- * package with the same name as the one specified, then we replace the old >- * part by the specified part. >- * >- * @param part >- * The part to add (or replace). >- * @return The part added to the package, the same as the one specified. >- * @throws InvalidFormatException >- * If rule M1.12 is not verified : Packages shall not contain >- * equivalent part names and package implementers shall neither >- * create nor recognize packages with equivalent part names. >- */ >- protected PackagePart addPackagePart(PackagePart part) { >- throwExceptionIfReadOnly(); >- if (part == null) { >- throw new IllegalArgumentException("part"); >- } >- >- if (partList.containsKey(part.partName)) { >- if (!partList.get(part.partName).isDeleted()) { >- throw new InvalidOperationException( >- "A part with the name '" >- + part.partName.getName() >- + "' already exists : Packages shall not contain equivalent part names and package implementers shall neither create nor recognize packages with equivalent part names. [M1.12]"); >- } else { >- // If the specified partis flagged as deleted, we make it >- // available >- part.setDeleted(false); >- // and delete the old part to replace it thereafeter >- this.partList.remove(part.partName); >- } >- } >- this.partList.put(part.partName, part); >- this.isDirty = true; >- return part; >- } >- >- /** >- * Remove the specified part in this package. If this part is relationship >- * part, then delete all relationships in the source part. >- * >- * @param part >- * The part to remove. If <code>null</code>, skip the action. >- * @see #removePart(PackagePartName) >- */ >- public void removePart(PackagePart part) { >- if (part != null) { >- removePart(part.getPartName()); >- } >- } >- >- /** >- * Remove a part in this package. If this part is relationship part, then >- * delete all relationships in the source part. >- * >- * @param partName >- * The part name of the part to remove. >- */ >- public void removePart(PackagePartName partName) { >- throwExceptionIfReadOnly(); >- if (partName == null || !this.containPart(partName)) >- throw new IllegalArgumentException("partName"); >- >- // Delete the specified part from the package. >- if (this.partList.containsKey(partName)) { >- this.partList.get(partName).setDeleted(true); >- this.removePartImpl(partName); >- this.partList.remove(partName); >- } else { >- this.removePartImpl(partName); >- } >- >- // Delete content type >- this.contentTypeManager.removeContentType(partName); >- >- // If this part is a relationship part, then delete all relationships of >- // the source part. >- if (partName.isRelationshipPartURI()) { >- URI sourceURI = PackagingURIHelper >- .getSourcePartUriFromRelationshipPartUri(partName.getURI()); >- PackagePartName sourcePartName; >- try { >- sourcePartName = PackagingURIHelper.createPartName(sourceURI); >- } catch (InvalidFormatException e) { >- logger >- .log(POILogger.ERROR, "Part name URI '" >- + sourceURI >- + "' is not valid ! This message is not intended to be displayed !"); >- return; >- } >- if (sourcePartName.getURI().equals( >- PackagingURIHelper.PACKAGE_ROOT_URI)) { >- clearRelationships(); >- } else if (containPart(sourcePartName)) { >- PackagePart part = getPart(sourcePartName); >- if (part != null) >- part.clearRelationships(); >- } >- } >- >- this.isDirty = true; >- } >- >- /** >- * Remove a part from this package as well as its relationship part, if one >- * exists, and all parts listed in the relationship part. Be aware that this >- * do not delete relationships which target the specified part. >- * >- * @param partName >- * The name of the part to delete. >- * @throws InvalidFormatException >- * Throws if the associated relationship part of the specified >- * part is not valid. >- */ >- public void removePartRecursive(PackagePartName partName) >- throws InvalidFormatException { >- // Retrieves relationship part, if one exists >- PackagePart relPart = this.partList.get(PackagingURIHelper >- .getRelationshipPartName(partName)); >- // Retrieves PackagePart object from the package >- PackagePart partToRemove = this.partList.get(partName); >- >- if (relPart != null) { >- PackageRelationshipCollection partRels = new PackageRelationshipCollection( >- partToRemove); >- for (PackageRelationship rel : partRels) { >- PackagePartName partNameToRemove = PackagingURIHelper >- .createPartName(PackagingURIHelper.resolvePartUri(rel >- .getSourceURI(), rel.getTargetURI())); >- removePart(partNameToRemove); >- } >- >- // Finally delete its relationship part if one exists >- this.removePart(relPart.partName); >- } >- >- // Delete the specified part >- this.removePart(partToRemove.partName); >- } >- >- /** >- * Delete the part with the specified name and its associated relationships >- * part if one exists. Prefer the use of this method to delete a part in the >- * package, compare to the remove() methods that don't remove associated >- * relationships part. >- * >- * @param partName >- * Name of the part to delete >- */ >- public void deletePart(PackagePartName partName) { >- if (partName == null) >- throw new IllegalArgumentException("partName"); >- >- // Remove the part >- this.removePart(partName); >- // Remove the relationships part >- this.removePart(PackagingURIHelper.getRelationshipPartName(partName)); >- } >- >- /** >- * Delete the part with the specified name and all part listed in its >- * associated relationships part if one exists. This process is recursively >- * apply to all parts in the relationships part of the specified part. >- * Prefer the use of this method to delete a part in the package, compare to >- * the remove() methods that don't remove associated relationships part. >- * >- * @param partName >- * Name of the part to delete >- */ >- public void deletePartRecursive(PackagePartName partName) { >- if (partName == null || !this.containPart(partName)) >- throw new IllegalArgumentException("partName"); >- >- PackagePart partToDelete = this.getPart(partName); >- // Remove the part >- this.removePart(partName); >- // Remove all relationship parts associated >- try { >- for (PackageRelationship relationship : partToDelete >- .getRelationships()) { >- PackagePartName targetPartName = PackagingURIHelper >- .createPartName(PackagingURIHelper.resolvePartUri( >- partName.getURI(), relationship.getTargetURI())); >- this.deletePartRecursive(targetPartName); >- } >- } catch (InvalidFormatException e) { >- logger.log(POILogger.WARN, "An exception occurs while deleting part '" >- + partName.getName() >- + "'. Some parts may remain in the package. - " >- + e.getMessage()); >- return; >- } >- // Remove the relationships part >- PackagePartName relationshipPartName = PackagingURIHelper >- .getRelationshipPartName(partName); >- if (relationshipPartName != null && containPart(relationshipPartName)) >- this.removePart(relationshipPartName); >- } >- >- /** >- * Check if a part already exists in this package from its name. >- * >- * @param partName >- * Part name to check. >- * @return <i>true</i> if the part is logically added to this package, else >- * <i>false</i>. >- */ >- public boolean containPart(PackagePartName partName) { >- return (this.getPart(partName) != null); >- } >- >- /** >- * Add a relationship to the package (except relationships part). >- * >- * Check rule M4.1 : The format designer shall specify and the format >- * producer shall create at most one core properties relationship for a >- * package. A format consumer shall consider more than one core properties >- * relationship for a package to be an error. If present, the relationship >- * shall target the Core Properties part. >- * >- * 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. >- * >- * @param targetPartName >- * Target part name. >- * @param targetMode >- * Target mode, either Internal or External. >- * @param relationshipType >- * Relationship type. >- * @param relID >- * ID of the relationship. >- * @see PackageRelationshipTypes >- */ >- public PackageRelationship addRelationship(PackagePartName targetPartName, >- TargetMode targetMode, String relationshipType, String relID) { >- /* Check OPC compliance */ >- >- // Check rule M4.1 : The format designer shall specify and the format >- // producer >- // shall create at most one core properties relationship for a package. >- // A format consumer shall consider more than one core properties >- // relationship for a package to be an error. If present, the >- // relationship shall target the Core Properties part. >- if (relationshipType.equals(PackageRelationshipTypes.CORE_PROPERTIES) >- && this.packageProperties != null) >- throw new InvalidOperationException( >- "OPC Compliance error [M4.1]: can't add another core properties part ! Use the built-in package method instead."); >- >- /* >- * 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. >- */ >- if (targetPartName.isRelationshipPartURI()) { >- throw new InvalidOperationException( >- "Rule M1.25: The Relationships part shall not have relationships to any other part."); >- } >- >- /* End OPC compliance */ >- >- ensureRelationships(); >- PackageRelationship retRel = relationships.addRelationship( >- targetPartName.getURI(), targetMode, relationshipType, relID); >- this.isDirty = true; >- return retRel; >- } >- >- /** >- * Add a package relationship. >- * >- * @param targetPartName >- * Target part name. >- * @param targetMode >- * Target mode, either Internal or External. >- * @param relationshipType >- * Relationship type. >- * @see PackageRelationshipTypes >- */ >- public PackageRelationship addRelationship(PackagePartName targetPartName, >- TargetMode targetMode, String relationshipType) { >- return this.addRelationship(targetPartName, targetMode, >- 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. >- * @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"); >- } >- >- URI targetURI; >- try { >- targetURI = new URI(target); >- } catch (URISyntaxException e) { >- throw new IllegalArgumentException("Invalid target - " + e); >- } >- >- ensureRelationships(); >- PackageRelationship retRel = relationships.addRelationship(targetURI, >- TargetMode.EXTERNAL, relationshipType, id); >- this.isDirty = true; >- return retRel; >- } >- >- /** >- * Delete a relationship from this package. >- * >- * @param id >- * Id of the relationship to delete. >- */ >- public void removeRelationship(String id) { >- if (relationships != null) { >- relationships.removeRelationship(id); >- this.isDirty = true; >- } >- } >- >- /** >- * Retrieves all package relationships. >- * >- * @return All package relationships of this package. >- * @throws OpenXML4JException >- * @see #getRelationshipsHelper(String) >- */ >- public PackageRelationshipCollection getRelationships() >- throws OpenXML4JException { >- return getRelationshipsHelper(null); >- } >- >- /** >- * Retrives all relationships with the specified type. >- * >- * @param relationshipType >- * The filter specifying the relationship type. >- * @return All relationships with the specified relationship type. >- * @throws OpenXML4JException >- */ >- public PackageRelationshipCollection getRelationshipsByType( >- String relationshipType) throws IllegalArgumentException, >- OpenXML4JException { >- throwExceptionIfWriteOnly(); >- if (relationshipType == null) { >- throw new IllegalArgumentException("relationshipType"); >- } >- return getRelationshipsHelper(relationshipType); >- } >- >- /** >- * Retrieves all relationships with specified id (normally just ine because >- * a relationship id is supposed to be unique). >- * >- * @param id >- * Id of the wanted relationship. >- * @throws OpenXML4JException >- */ >- private PackageRelationshipCollection getRelationshipsHelper(String id) >- throws OpenXML4JException { >- throwExceptionIfWriteOnly(); >- ensureRelationships(); >- return this.relationships.getRelationships(id); >- } >- >- /** >- * Clear package relationships. >- */ >- public void clearRelationships() { >- if (relationships != null) { >- relationships.clear(); >- this.isDirty = true; >- } >- } >- >- /** >- * Ensure that the relationships collection is not null. >- */ >- public void ensureRelationships() { >- if (this.relationships == null) { >- try { >- this.relationships = new PackageRelationshipCollection(this); >- } catch (InvalidFormatException e) { >- this.relationships = new PackageRelationshipCollection(); >- } >- } >- } >- >- /** >- * @see org.apache.poi.openxml4j.opc.RelationshipSource#getRelationship(java.lang.String) >- */ >- public PackageRelationship getRelationship(String id) { >- return this.relationships.getRelationshipByID(id); >- } >- >- /** >- * @see org.apache.poi.openxml4j.opc.RelationshipSource#hasRelationships() >- */ >- public boolean hasRelationships() { >- return (relationships.size() > 0); >- } >- >- /** >- * @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; >- } >- } >- >- /** >- * Add a marshaller. >- * >- * @param contentType >- * The content type to bind to the specified marshaller. >- * @param marshaller >- * The marshaller to register with the specified content type. >- */ >- public void addMarshaller(String contentType, PartMarshaller marshaller) { >- try { >- partMarshallers.put(new ContentType(contentType), marshaller); >- } catch (InvalidFormatException e) { >- logger.log(POILogger.WARN, "The specified content type is not valid: '" >- + e.getMessage() + "'. The marshaller will not be added !"); >- } >- } >- >- /** >- * Add an unmarshaller. >- * >- * @param contentType >- * The content type to bind to the specified unmarshaller. >- * @param unmarshaller >- * The unmarshaller to register with the specified content type. >- */ >- public void addUnmarshaller(String contentType, >- PartUnmarshaller unmarshaller) { >- try { >- partUnmarshallers.put(new ContentType(contentType), unmarshaller); >- } catch (InvalidFormatException e) { >- logger.log(POILogger.WARN, "The specified content type is not valid: '" >- + e.getMessage() >- + "'. The unmarshaller will not be added !"); >- } >- } >- >- /** >- * Remove a marshaller by its content type. >- * >- * @param contentType >- * The content type associated with the marshaller to remove. >- */ >- public void removeMarshaller(String contentType) { >- partMarshallers.remove(contentType); >- } >- >- /** >- * Remove an unmarshaller by its content type. >- * >- * @param contentType >- * The content type associated with the unmarshaller to remove. >- */ >- public void removeUnmarshaller(String contentType) { >- partUnmarshallers.remove(contentType); >- } >- >- /* Accesseurs */ >- >- /** >- * Get the package access mode. >- * >- * @return the packageAccess The current package access. >- */ >- public PackageAccess getPackageAccess() { >- return packageAccess; >- } >- >- /** >- * Validates the package compliance with the OPC specifications. >- * >- * @return <b>true</b> if the package is valid else <b>false</b> >- */ >- public boolean validatePackage(Package pkg) throws InvalidFormatException { >- throw new InvalidOperationException("Not implemented yet !!!"); >- } >- >- /** >- * Save the document in the specified file. >- * >- * @param targetFile >- * Destination file. >- * @throws IOException >- * Throws if an IO exception occur. >- * @see #save(OutputStream) >- */ >- public void save(File targetFile) throws IOException { >- if (targetFile == null) >- throw new IllegalArgumentException("targetFile"); >- >- this.throwExceptionIfReadOnly(); >- FileOutputStream fos = null; >- try { >- fos = new FileOutputStream(targetFile); >- } catch (FileNotFoundException e) { >- throw new IOException(e.getLocalizedMessage()); >- } >- this.save(fos); >- } >- >- /** >- * Save the document in the specified output stream. >- * >- * @param outputStream >- * The stream to save the package. >- * @see #saveImpl(OutputStream) >- */ >- public void save(OutputStream outputStream) throws IOException { >- throwExceptionIfReadOnly(); >- this.saveImpl(outputStream); >- } >- >- /** >- * Core method to create a package part. This method must be implemented by >- * the subclass. >- * >- * @param partName >- * URI of the part to create. >- * @param contentType >- * Content type of the part to create. >- * @return The newly created package part. >- */ >- protected abstract PackagePart createPartImpl(PackagePartName partName, >- String contentType, boolean loadRelationships); >- >- /** >- * Core method to delete a package part. This method must be implemented by >- * the subclass. >- * >- * @param partName >- * The URI of the part to delete. >- */ >- protected abstract void removePartImpl(PackagePartName partName); >- >- /** >- * Flush the package but not save. >- */ >- protected abstract void flushImpl(); >- >- /** >- * Close the package and cause a save of the package. >- * >- */ >- protected abstract void closeImpl() throws IOException; >- >- /** >- * Close the package without saving the document. Discard all changes made >- * to this package. >- */ >- protected abstract void revertImpl(); >- >- /** >- * Save the package into the specified output stream. >- * >- * @param outputStream >- * The output stream use to save this package. >- */ >- protected abstract void saveImpl(OutputStream outputStream) >- throws IOException; >- >- /** >- * Get the package part mapped to the specified URI. >- * >- * @param partName >- * The URI of the part to retrieve. >- * @return The package part located by the specified URI, else <b>null</b>. >- */ >- protected abstract PackagePart getPartImpl(PackagePartName partName); >- >- /** >- * Get all parts link to the package. >- * >- * @return A list of the part owned by the package. >- */ >- protected abstract PackagePart[] getPartsImpl() >- throws InvalidFormatException; > } >Index: src/ooxml/java/org/apache/poi/openxml4j/opc/internal/PackagePropertiesPart.java >=================================================================== >--- src/ooxml/java/org/apache/poi/openxml4j/opc/internal/PackagePropertiesPart.java (revision 754500) >+++ src/ooxml/java/org/apache/poi/openxml4j/opc/internal/PackagePropertiesPart.java (working copy) >@@ -27,7 +27,7 @@ > import org.apache.poi.openxml4j.exceptions.InvalidOperationException; > import org.apache.poi.openxml4j.exceptions.OpenXML4JException; > import org.apache.poi.openxml4j.opc.ContentTypes; >-import org.apache.poi.openxml4j.opc.Package; >+import org.apache.poi.openxml4j.opc.OPCPackage; > import org.apache.poi.openxml4j.opc.PackagePart; > import org.apache.poi.openxml4j.opc.PackagePartName; > import org.apache.poi.openxml4j.opc.PackageProperties; >@@ -60,7 +60,7 @@ > * @throws InvalidFormatException > * Throws if the content is invalid. > */ >- public PackagePropertiesPart(Package pack, PackagePartName partName) >+ public PackagePropertiesPart(OPCPackage pack, PackagePartName partName) > throws InvalidFormatException { > super(pack, partName, ContentTypes.CORE_PROPERTIES_PART); > } >Index: src/ooxml/java/org/apache/poi/openxml4j/opc/internal/unmarshallers/UnmarshallContext.java >=================================================================== >--- src/ooxml/java/org/apache/poi/openxml4j/opc/internal/unmarshallers/UnmarshallContext.java (revision 754500) >+++ src/ooxml/java/org/apache/poi/openxml4j/opc/internal/unmarshallers/UnmarshallContext.java (working copy) >@@ -19,7 +19,7 @@ > > import java.util.zip.ZipEntry; > >-import org.apache.poi.openxml4j.opc.Package; >+import org.apache.poi.openxml4j.opc.OPCPackage; > import org.apache.poi.openxml4j.opc.PackagePartName; > > /** >@@ -30,7 +30,7 @@ > */ > public final class UnmarshallContext { > >- private Package _package; >+ private OPCPackage _package; > > private PackagePartName partName; > >@@ -44,7 +44,7 @@ > * @param partName > * Name of the part to unmarshall. > */ >- public UnmarshallContext(Package targetPackage, PackagePartName partName) { >+ public UnmarshallContext(OPCPackage targetPackage, PackagePartName partName) { > this._package = targetPackage; > this.partName = partName; > } >@@ -52,7 +52,7 @@ > /** > * @return the container > */ >- Package getPackage() { >+ OPCPackage getPackage() { > return _package; > } > >@@ -60,7 +60,7 @@ > * @param container > * the container to set > */ >- public void setPackage(Package container) { >+ public void setPackage(OPCPackage container) { > this._package = container; > } > >Index: src/ooxml/java/org/apache/poi/openxml4j/opc/internal/ContentTypeManager.java >=================================================================== >--- src/ooxml/java/org/apache/poi/openxml4j/opc/internal/ContentTypeManager.java (revision 754500) >+++ src/ooxml/java/org/apache/poi/openxml4j/opc/internal/ContentTypeManager.java (working copy) >@@ -25,8 +25,14 @@ > import java.util.List; > import java.util.TreeMap; > import java.util.Map.Entry; >-import java.util.zip.ZipOutputStream; > >+import org.apache.poi.openxml4j.exceptions.InvalidFormatException; >+import org.apache.poi.openxml4j.exceptions.InvalidOperationException; >+import org.apache.poi.openxml4j.exceptions.OpenXML4JRuntimeException; >+import org.apache.poi.openxml4j.opc.OPCPackage; >+import org.apache.poi.openxml4j.opc.PackagePart; >+import org.apache.poi.openxml4j.opc.PackagePartName; >+import org.apache.poi.openxml4j.opc.PackagingURIHelper; > import org.dom4j.Document; > import org.dom4j.DocumentException; > import org.dom4j.DocumentHelper; >@@ -34,15 +40,6 @@ > 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.InvalidOperationException; >-import org.apache.poi.openxml4j.exceptions.OpenXML4JRuntimeException; >-import org.apache.poi.openxml4j.opc.Package; >-import org.apache.poi.openxml4j.opc.PackagePart; >-import org.apache.poi.openxml4j.opc.PackagePartName; >-import org.apache.poi.openxml4j.opc.PackagingURIHelper; >-import org.apache.poi.util.POILogger; >-import org.apache.poi.util.POILogFactory; > > /** > * Manage package content types ([Content_Types].xml part). >@@ -52,14 +49,7 @@ > */ > public abstract class ContentTypeManager { > >- private static POILogger logger = POILogFactory.getLogger(ContentTypeManager.class); >- > /** >- * Reference to the package using this content type manager. >- */ >- protected Package container; >- >- /** > * Content type part name. > */ > public static final String CONTENT_TYPES_PART_NAME = "[Content_Types].xml"; >@@ -84,6 +74,11 @@ > private static final String PART_NAME_ATTRIBUTE_NAME = "PartName"; > > /** >+ * Reference to the package using this content type manager. >+ */ >+ protected OPCPackage container; >+ >+ /** > * Default content type tree. <Extension, ContentType> > */ > private TreeMap<String, String> defaultContentType; >@@ -102,7 +97,7 @@ > * @throws InvalidFormatException > * If the content types part content is not valid. > */ >- public ContentTypeManager(InputStream in, Package pkg) >+ public ContentTypeManager(InputStream in, OPCPackage pkg) > throws InvalidFormatException { > this.container = pkg; > this.defaultContentType = new TreeMap<String, String>(); >Index: src/ooxml/java/org/apache/poi/openxml4j/opc/internal/ZipContentTypeManager.java >=================================================================== >--- src/ooxml/java/org/apache/poi/openxml4j/opc/internal/ZipContentTypeManager.java (revision 754500) >+++ src/ooxml/java/org/apache/poi/openxml4j/opc/internal/ZipContentTypeManager.java (working copy) >@@ -25,12 +25,12 @@ > import java.util.zip.ZipEntry; > import java.util.zip.ZipOutputStream; > >-import org.dom4j.Document; > import org.apache.poi.openxml4j.exceptions.InvalidFormatException; >-import org.apache.poi.openxml4j.opc.Package; >+import org.apache.poi.openxml4j.opc.OPCPackage; > import org.apache.poi.openxml4j.opc.StreamHelper; >+import org.apache.poi.util.POILogFactory; > import org.apache.poi.util.POILogger; >-import org.apache.poi.util.POILogFactory; >+import org.dom4j.Document; > > /** > * Zip implementation of the ContentTypeManager. >@@ -51,7 +51,7 @@ > * @throws InvalidFormatException > * If the content types part content is not valid. > */ >- public ZipContentTypeManager(InputStream in, Package pkg) >+ public ZipContentTypeManager(InputStream in, OPCPackage pkg) > throws InvalidFormatException { > super(in, pkg); > } >Index: src/ooxml/java/org/apache/poi/openxml4j/opc/internal/MemoryPackagePart.java >=================================================================== >--- src/ooxml/java/org/apache/poi/openxml4j/opc/internal/MemoryPackagePart.java (revision 754500) >+++ src/ooxml/java/org/apache/poi/openxml4j/opc/internal/MemoryPackagePart.java (working copy) >@@ -23,7 +23,7 @@ > > import org.apache.poi.openxml4j.exceptions.InvalidFormatException; > import org.apache.poi.openxml4j.exceptions.OpenXML4JException; >-import org.apache.poi.openxml4j.opc.Package; >+import org.apache.poi.openxml4j.opc.OPCPackage; > import org.apache.poi.openxml4j.opc.PackagePart; > import org.apache.poi.openxml4j.opc.PackagePartName; > import org.apache.poi.openxml4j.opc.internal.marshallers.ZipPartMarshaller; >@@ -58,7 +58,7 @@ > * @throws InvalidFormatException > * If the specified URI is not OPC compliant. > */ >- public MemoryPackagePart(Package pack, PackagePartName partName, >+ public MemoryPackagePart(OPCPackage pack, PackagePartName partName, > String contentType) throws InvalidFormatException { > super(pack, partName, contentType); > } >@@ -77,7 +77,7 @@ > * @throws InvalidFormatException > * If the specified URI is not OPC compliant. > */ >- public MemoryPackagePart(Package pack, PackagePartName partName, >+ public MemoryPackagePart(OPCPackage pack, PackagePartName partName, > String contentType, boolean loadRelationships) > throws InvalidFormatException { > super(pack, partName, new ContentType(contentType), loadRelationships); >Index: src/ooxml/java/org/apache/poi/openxml4j/opc/OPCPackage.java >=================================================================== >--- src/ooxml/java/org/apache/poi/openxml4j/opc/OPCPackage.java (revision 0) >+++ src/ooxml/java/org/apache/poi/openxml4j/opc/OPCPackage.java (revision 0) >@@ -0,0 +1,1390 @@ >+/* ==================================================================== >+ 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.ByteArrayOutputStream; >+import java.io.File; >+import java.io.FileInputStream; >+import java.io.FileNotFoundException; >+import java.io.FileOutputStream; >+import java.io.IOException; >+import java.io.InputStream; >+import java.io.OutputStream; >+import java.net.URI; >+import java.net.URISyntaxException; >+import java.util.ArrayList; >+import java.util.Date; >+import java.util.Hashtable; >+import java.util.concurrent.locks.ReentrantReadWriteLock; >+ >+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.exceptions.OpenXML4JRuntimeException; >+import org.apache.poi.openxml4j.opc.internal.ContentType; >+import org.apache.poi.openxml4j.opc.internal.ContentTypeManager; >+import org.apache.poi.openxml4j.opc.internal.PackagePropertiesPart; >+import org.apache.poi.openxml4j.opc.internal.PartMarshaller; >+import org.apache.poi.openxml4j.opc.internal.PartUnmarshaller; >+import org.apache.poi.openxml4j.opc.internal.ZipContentTypeManager; >+import org.apache.poi.openxml4j.opc.internal.marshallers.DefaultMarshaller; >+import org.apache.poi.openxml4j.opc.internal.marshallers.ZipPackagePropertiesMarshaller; >+import org.apache.poi.openxml4j.opc.internal.unmarshallers.PackagePropertiesUnmarshaller; >+import org.apache.poi.openxml4j.opc.internal.unmarshallers.UnmarshallContext; >+import org.apache.poi.openxml4j.util.Nullable; >+import org.apache.poi.util.POILogger; >+import org.apache.poi.util.POILogFactory; >+ >+/** >+ * Represents a container that can store multiple data objects. >+ * >+ * @author Julien Chable, CDubet >+ * @version 0.1 >+ */ >+public abstract class OPCPackage implements RelationshipSource { >+ >+ /** >+ * Logger. >+ */ >+ private static POILogger logger = POILogFactory.getLogger(OPCPackage.class); >+ >+ /** >+ * Default package access. >+ */ >+ protected static final PackageAccess defaultPackageAccess = PackageAccess.READ_WRITE; >+ >+ /** >+ * Package access. >+ */ >+ private PackageAccess packageAccess; >+ >+ /** >+ * Package parts collection. >+ */ >+ protected PackagePartCollection partList; >+ >+ /** >+ * Package relationships. >+ */ >+ protected PackageRelationshipCollection relationships; >+ >+ /** >+ * Part marshallers by content type. >+ */ >+ protected Hashtable<ContentType, PartMarshaller> partMarshallers; >+ >+ /** >+ * Default part marshaller. >+ */ >+ protected PartMarshaller defaultPartMarshaller; >+ >+ /** >+ * Part unmarshallers by content type. >+ */ >+ protected Hashtable<ContentType, PartUnmarshaller> partUnmarshallers; >+ >+ /** >+ * Core package properties. >+ */ >+ protected PackagePropertiesPart packageProperties; >+ >+ /** >+ * Manage parts content types of this package. >+ */ >+ protected ContentTypeManager contentTypeManager; >+ >+ /** >+ * Flag if a modification is done to the document. >+ */ >+ protected boolean isDirty = false; >+ >+ /** >+ * File path of this package. >+ */ >+ protected String originalPackagePath; >+ >+ /** >+ * Output stream for writing this package. >+ */ >+ protected OutputStream output; >+ >+ /** >+ * Constructor. >+ * >+ * @param access >+ * Package access. >+ */ >+ OPCPackage(PackageAccess access) { >+ if (getClass() != ZipPackage.class) { >+ throw new IllegalArgumentException("PackageBase may not be subclassed"); >+ } >+ init(); >+ this.packageAccess = access; >+ } >+ >+ /** >+ * Initialize the package instance. >+ */ >+ private void init() { >+ this.partMarshallers = new Hashtable<ContentType, PartMarshaller>(5); >+ this.partUnmarshallers = new Hashtable<ContentType, PartUnmarshaller>(2); >+ >+ try { >+ // Add 'default' unmarshaller >+ this.partUnmarshallers.put(new ContentType( >+ ContentTypes.CORE_PROPERTIES_PART), >+ new PackagePropertiesUnmarshaller()); >+ >+ // Add default marshaller >+ this.defaultPartMarshaller = new DefaultMarshaller(); >+ // TODO Delocalize specialized marshallers >+ this.partMarshallers.put(new ContentType( >+ ContentTypes.CORE_PROPERTIES_PART), >+ new ZipPackagePropertiesMarshaller()); >+ } catch (InvalidFormatException e) { >+ // Should never happen >+ throw new OpenXML4JRuntimeException( >+ "Package.init() : this exception should never happen, if you read this message please send a mail to the developers team."); >+ } >+ } >+ >+ >+ /** >+ * Open a package with read/write permission. >+ * >+ * @param path >+ * The document path. >+ * @return A Package object, else <b>null</b>. >+ * @throws InvalidFormatException >+ * If the specified file doesn't exist, and a parsing error >+ * occur. >+ */ >+ public static OPCPackage open(String path) throws InvalidFormatException { >+ return open(path, defaultPackageAccess); >+ } >+ >+ /** >+ * Open a package. >+ * >+ * @param path >+ * The document path. >+ * @param access >+ * PackageBase access. >+ * @return A PackageBase object, else <b>null</b>. >+ * @throws InvalidFormatException >+ * If the specified file doesn't exist, and a parsing error >+ * occur. >+ */ >+ public static OPCPackage open(String path, PackageAccess access) >+ throws InvalidFormatException { >+ if (path == null || "".equals(path.trim()) >+ || (new File(path).exists() && new File(path).isDirectory())) >+ throw new IllegalArgumentException("path"); >+ >+ OPCPackage pack = new ZipPackage(path, access); >+ if (pack.partList == null && access != PackageAccess.WRITE) { >+ pack.getParts(); >+ } >+ pack.originalPackagePath = new File(path).getAbsolutePath(); >+ return pack; >+ } >+ >+ /** >+ * Open a package. >+ * >+ * Note - uses quite a bit more memory than {@link #open(String)}, which >+ * doesn't need to hold the whole zip file in memory, and can take advantage >+ * of native methods >+ * >+ * @param in >+ * The InputStream to read the package from >+ * @return A PackageBase object >+ */ >+ public static OPCPackage open(InputStream in) throws InvalidFormatException, >+ IOException { >+ OPCPackage pack = new ZipPackage(in, PackageAccess.READ); >+ if (pack.partList == null) { >+ pack.getParts(); >+ } >+ return pack; >+ } >+ >+ /** >+ * Opens a package if it exists, else it creates one. >+ * >+ * @param file >+ * The file to open or to create. >+ * @return A newly created package if the specified file does not exist, >+ * else the package extract from the file. >+ * @throws InvalidFormatException >+ * Throws if the specified file exist and is not valid. >+ */ >+ public static OPCPackage openOrCreate(File file) throws InvalidFormatException { >+ OPCPackage retPackage = null; >+ if (file.exists()) { >+ retPackage = open(file.getAbsolutePath()); >+ } else { >+ retPackage = create(file); >+ } >+ return retPackage; >+ } >+ >+ /** >+ * Creates a new package. >+ * >+ * @param path >+ * Path of the document. >+ * @return A newly created PackageBase ready to use. >+ */ >+ public static OPCPackage create(String path) { >+ return create(new File(path)); >+ } >+ >+ /** >+ * Creates a new package. >+ * >+ * @param file >+ * Path of the document. >+ * @return A newly created PackageBase ready to use. >+ */ >+ public static OPCPackage create(File file) { >+ if (file == null || (file.exists() && file.isDirectory())) >+ throw new IllegalArgumentException("file"); >+ >+ if (file.exists()) { >+ throw new InvalidOperationException( >+ "This package (or file) already exists : use the open() method or delete the file."); >+ } >+ >+ // Creates a new package >+ OPCPackage pkg = null; >+ pkg = new ZipPackage(); >+ pkg.originalPackagePath = file.getAbsolutePath(); >+ >+ configurePackage(pkg); >+ return pkg; >+ } >+ >+ public static OPCPackage create(OutputStream output) { >+ OPCPackage pkg = null; >+ pkg = new ZipPackage(); >+ pkg.originalPackagePath = null; >+ pkg.output = output; >+ >+ configurePackage(pkg); >+ return pkg; >+ } >+ >+ /** >+ * Configure the package. >+ * >+ * @param pkg >+ */ >+ private static void configurePackage(OPCPackage pkg) { >+ try { >+ // Content type manager >+ pkg.contentTypeManager = new ZipContentTypeManager(null, pkg); >+ // Add default content types for .xml and .rels >+ pkg.contentTypeManager >+ .addContentType( >+ PackagingURIHelper >+ .createPartName(PackagingURIHelper.PACKAGE_RELATIONSHIPS_ROOT_URI), >+ ContentTypes.RELATIONSHIPS_PART); >+ pkg.contentTypeManager >+ .addContentType(PackagingURIHelper >+ .createPartName("/default.xml"), >+ ContentTypes.PLAIN_OLD_XML); >+ >+ // Init some PackageBase properties >+ pkg.packageProperties = new PackagePropertiesPart(pkg, >+ PackagingURIHelper.CORE_PROPERTIES_PART_NAME); >+ pkg.packageProperties.setCreatorProperty("Generated by OpenXML4J"); >+ pkg.packageProperties.setCreatedProperty(new Nullable<Date>( >+ new Date())); >+ } catch (InvalidFormatException e) { >+ // Should never happen >+ throw new IllegalStateException(e); >+ } >+ } >+ >+ /** >+ * Flush the package : save all. >+ * >+ * @see #close() >+ */ >+ public void flush() { >+ throwExceptionIfReadOnly(); >+ >+ if (this.packageProperties != null) { >+ this.packageProperties.flush(); >+ } >+ >+ this.flushImpl(); >+ } >+ >+ /** >+ * Close the package and save its content. >+ * >+ * @throws IOException >+ * If an IO exception occur during the saving process. >+ */ >+ public void close() throws IOException { >+ if (this.packageAccess == PackageAccess.READ) { >+ logger >+ .log(POILogger.WARN, "The close() method is intended to SAVE a package. This package is open in READ ONLY mode, use the revert() method instead !"); >+ return; >+ } >+ >+ // Save the content >+ ReentrantReadWriteLock l = new ReentrantReadWriteLock(); >+ try { >+ l.writeLock().lock(); >+ if (this.originalPackagePath != null >+ && !"".equals(this.originalPackagePath.trim())) { >+ File targetFile = new File(this.originalPackagePath); >+ if (!targetFile.exists() >+ || !(this.originalPackagePath >+ .equalsIgnoreCase(targetFile.getAbsolutePath()))) { >+ // Case of a package created from scratch >+ save(targetFile); >+ } else { >+ closeImpl(); >+ } >+ } else if (this.output != null) { >+ save(this.output); >+ } >+ } finally { >+ l.writeLock().unlock(); >+ } >+ >+ // Clear >+ this.contentTypeManager.clearAll(); >+ >+ // Call the garbage collector >+ Runtime.getRuntime().gc(); >+ } >+ >+ /** >+ * Close the package WITHOUT saving its content. Reinitialize this package >+ * and cancel all changes done to it. >+ */ >+ public void revert() { >+ revertImpl(); >+ } >+ >+ /** >+ * Add a thumbnail to the package. This method is provided to make easier >+ * the addition of a thumbnail in a package. You can do the same work by >+ * using the traditionnal relationship and part mechanism. >+ * >+ * @param path >+ * The full path to the image file. >+ */ >+ public void addThumbnail(String path) throws IOException { >+ // Check parameter >+ if ("".equals(path)) >+ throw new IllegalArgumentException("path"); >+ >+ // Get the filename from the path >+ String filename = path >+ .substring(path.lastIndexOf(File.separatorChar) + 1); >+ >+ // Create the thumbnail part name >+ String contentType = ContentTypes >+ .getContentTypeFromFileExtension(filename); >+ PackagePartName thumbnailPartName = null; >+ try { >+ thumbnailPartName = PackagingURIHelper.createPartName("/docProps/" >+ + filename); >+ } catch (InvalidFormatException e) { >+ try { >+ thumbnailPartName = PackagingURIHelper >+ .createPartName("/docProps/thumbnail" >+ + path.substring(path.lastIndexOf(".") + 1)); >+ } catch (InvalidFormatException e2) { >+ throw new InvalidOperationException( >+ "Can't add a thumbnail file named '" + filename + "'"); >+ } >+ } >+ >+ // Check if part already exist >+ if (this.getPart(thumbnailPartName) != null) >+ throw new InvalidOperationException( >+ "You already add a thumbnail named '" + filename + "'"); >+ >+ // Add the thumbnail part to this package. >+ PackagePart thumbnailPart = this.createPart(thumbnailPartName, >+ contentType, false); >+ >+ // Add the relationship between the package and the thumbnail part >+ this.addRelationship(thumbnailPartName, TargetMode.INTERNAL, >+ PackageRelationshipTypes.THUMBNAIL); >+ >+ // Copy file data to the newly created part >+ StreamHelper.copyStream(new FileInputStream(path), thumbnailPart >+ .getOutputStream()); >+ } >+ >+ /** >+ * Throws an exception if the package access mode is in read only mode >+ * (PackageAccess.Read). >+ * >+ * @throws InvalidOperationException >+ * Throws if a writing operation is done on a read only package. >+ * @see org.apache.poi.openxml4j.opc.PackageAccess >+ */ >+ void throwExceptionIfReadOnly() throws InvalidOperationException { >+ if (packageAccess == PackageAccess.READ) >+ throw new InvalidOperationException( >+ "Operation not allowed, document open in read only mode!"); >+ } >+ >+ /** >+ * Throws an exception if the package access mode is in write only mode >+ * (PackageAccess.Write). This method is call when other methods need write >+ * right. >+ * >+ * @throws InvalidOperationException >+ * Throws if a read operation is done on a write only package. >+ * @see org.apache.poi.openxml4j.opc.PackageAccess >+ */ >+ void throwExceptionIfWriteOnly() throws InvalidOperationException { >+ if (packageAccess == PackageAccess.WRITE) >+ throw new InvalidOperationException( >+ "Operation not allowed, document open in write only mode!"); >+ } >+ >+ /** >+ * Retrieves or creates if none exists, core package property part. >+ * >+ * @return The PackageProperties part of this package. >+ */ >+ public PackageProperties getPackageProperties() >+ throws InvalidFormatException { >+ this.throwExceptionIfWriteOnly(); >+ // If no properties part has been found then we create one >+ if (this.packageProperties == null) { >+ this.packageProperties = new PackagePropertiesPart(this, >+ PackagingURIHelper.CORE_PROPERTIES_PART_NAME); >+ } >+ return this.packageProperties; >+ } >+ >+ /** >+ * Retrieve a part identified by its name. >+ * >+ * @param partName >+ * Part name of the part to retrieve. >+ * @return The part with the specified name, else <code>null</code>. >+ */ >+ public PackagePart getPart(PackagePartName partName) { >+ throwExceptionIfWriteOnly(); >+ >+ if (partName == null) >+ throw new IllegalArgumentException("partName"); >+ >+ // If the partlist is null, then we parse the package. >+ if (partList == null) { >+ try { >+ getParts(); >+ } catch (InvalidFormatException e) { >+ return null; >+ } >+ } >+ return getPartImpl(partName); >+ } >+ >+ /** >+ * Retrieve parts by content type. >+ * >+ * @param contentType >+ * The content type criteria. >+ * @return All part associated to the specified content type. >+ */ >+ public ArrayList<PackagePart> getPartsByContentType(String contentType) { >+ ArrayList<PackagePart> retArr = new ArrayList<PackagePart>(); >+ for (PackagePart part : partList.values()) { >+ if (part.getContentType().equals(contentType)) >+ retArr.add(part); >+ } >+ return retArr; >+ } >+ >+ /** >+ * Retrieve parts by relationship type. >+ * >+ * @param relationshipType >+ * Relationship type. >+ * @return All parts which are the target of a relationship with the >+ * specified type, if the method can't retrieve relationships from >+ * the package, then return <code>null</code>. >+ */ >+ public ArrayList<PackagePart> getPartsByRelationshipType( >+ String relationshipType) { >+ if (relationshipType == null) >+ throw new IllegalArgumentException("relationshipType"); >+ ArrayList<PackagePart> retArr = new ArrayList<PackagePart>(); >+ for (PackageRelationship rel : getRelationshipsByType(relationshipType)) { >+ retArr.add(getPart(rel)); >+ } >+ return retArr; >+ } >+ >+ /** >+ * Get the target part from the specified relationship. >+ * >+ * @param partRel >+ * The part relationship uses to retrieve the part. >+ */ >+ public PackagePart getPart(PackageRelationship partRel) { >+ PackagePart retPart = null; >+ ensureRelationships(); >+ for (PackageRelationship rel : relationships) { >+ if (rel.getRelationshipType().equals(partRel.getRelationshipType())) { >+ try { >+ retPart = getPart(PackagingURIHelper.createPartName(rel >+ .getTargetURI())); >+ } catch (InvalidFormatException e) { >+ continue; >+ } >+ break; >+ } >+ } >+ return retPart; >+ } >+ >+ /** >+ * Load the parts of the archive if it has not been done yet The >+ * relationships of each part are not loaded >+ * >+ * @return All this package's parts. >+ */ >+ public ArrayList<PackagePart> getParts() throws InvalidFormatException { >+ throwExceptionIfWriteOnly(); >+ >+ // If the part list is null, we parse the package to retrieve all parts. >+ if (partList == null) { >+ /* Variables use to validate OPC Compliance */ >+ >+ // Ensure rule M4.1 -> A format consumer shall consider more than >+ // one core properties relationship for a package to be an error >+ boolean hasCorePropertiesPart = false; >+ >+ PackagePart[] parts = this.getPartsImpl(); >+ this.partList = new PackagePartCollection(); >+ for (PackagePart part : parts) { >+ if (partList.containsKey(part.partName)) >+ throw new InvalidFormatException( >+ "A part with the name '" >+ + part.partName >+ + "' already exist : Packages shall not contain equivalent part names and package implementers shall neither create nor recognize packages with equivalent part names. [M1.12]"); >+ >+ // Check OPC compliance rule M4.1 >+ if (part.getContentType().equals( >+ ContentTypes.CORE_PROPERTIES_PART)) { >+ if (!hasCorePropertiesPart) >+ hasCorePropertiesPart = true; >+ else >+ throw new InvalidFormatException( >+ "OPC Compliance error [M4.1]: there is more than one core properties relationship in the package !"); >+ } >+ >+ PartUnmarshaller partUnmarshaller = partUnmarshallers >+ .get(part.contentType); >+ >+ if (partUnmarshaller != null) { >+ UnmarshallContext context = new UnmarshallContext(this, >+ part.partName); >+ try { >+ PackagePart unmarshallPart = partUnmarshaller >+ .unmarshall(context, part.getInputStream()); >+ partList.put(unmarshallPart.partName, unmarshallPart); >+ >+ // Core properties case >+ if (unmarshallPart instanceof PackagePropertiesPart) >+ this.packageProperties = (PackagePropertiesPart) unmarshallPart; >+ } catch (IOException ioe) { >+ logger.log(POILogger.WARN, "Unmarshall operation : IOException for " >+ + part.partName); >+ continue; >+ } catch (InvalidOperationException invoe) { >+ throw new InvalidFormatException(invoe.getMessage()); >+ } >+ } else { >+ try { >+ partList.put(part.partName, part); >+ } catch (InvalidOperationException e) { >+ throw new InvalidFormatException(e.getMessage()); >+ } >+ } >+ } >+ } >+ return new ArrayList<PackagePart>(partList.values()); >+ } >+ >+ /** >+ * Create and add a part, with the specified name and content type, to the >+ * package. >+ * >+ * @param partName >+ * Part name. >+ * @param contentType >+ * Part content type. >+ * @return The newly created part. >+ * @throws InvalidFormatException >+ * If rule M1.12 is not verified : Packages shall not contain >+ * equivalent part names and package implementers shall neither >+ * create nor recognize packages with equivalent part names. >+ * @see #createPartImpl(PackagePartName, String, boolean) >+ */ >+ public PackagePart createPart(PackagePartName partName, String contentType) { >+ return this.createPart(partName, contentType, true); >+ } >+ >+ /** >+ * Create and add a part, with the specified name and content type, to the >+ * package. For general purpose, prefer the overload version of this method >+ * without the 'loadRelationships' parameter. >+ * >+ * @param partName >+ * Part name. >+ * @param contentType >+ * Part content type. >+ * @param loadRelationships >+ * Specify if the existing relationship part, if any, logically >+ * associated to the newly created part will be loaded. >+ * @return The newly created part. >+ * @throws InvalidFormatException >+ * If rule M1.12 is not verified : Packages shall not contain >+ * equivalent part names and package implementers shall neither >+ * create nor recognize packages with equivalent part names. >+ * @see {@link#createPartImpl(URI, String)} >+ */ >+ PackagePart createPart(PackagePartName partName, String contentType, >+ boolean loadRelationships) { >+ throwExceptionIfReadOnly(); >+ if (partName == null) { >+ throw new IllegalArgumentException("partName"); >+ } >+ >+ if (contentType == null || contentType == "") { >+ throw new IllegalArgumentException("contentType"); >+ } >+ >+ // Check if the specified part name already exists >+ if (partList.containsKey(partName) >+ && !partList.get(partName).isDeleted()) { >+ throw new InvalidOperationException( >+ "A part with the name '" >+ + partName.getName() >+ + "' already exists : Packages shall not contain equivalent part names and package implementers shall neither create nor recognize packages with equivalent part names. [M1.12]"); >+ } >+ >+ /* Check OPC compliance */ >+ >+ // Rule [M4.1]: The format designer shall specify and the format >+ // producer >+ // shall create at most one core properties relationship for a package. >+ // A format consumer shall consider more than one core properties >+ // relationship for a package to be an error. If present, the >+ // relationship shall target the Core Properties part. >+ if (contentType == ContentTypes.CORE_PROPERTIES_PART) { >+ if (this.packageProperties != null) >+ throw new InvalidOperationException( >+ "OPC Compliance error [M4.1]: you try to add more than one core properties relationship in the package !"); >+ } >+ >+ /* End check OPC compliance */ >+ >+ PackagePart part = this.createPartImpl(partName, contentType, >+ loadRelationships); >+ this.contentTypeManager.addContentType(partName, contentType); >+ this.partList.put(partName, part); >+ this.isDirty = true; >+ return part; >+ } >+ >+ /** >+ * Add a part to the package. >+ * >+ * @param partName >+ * Part name of the part to create. >+ * @param contentType >+ * type associated with the file >+ * @param content >+ * the contents to add. In order to have faster operation in >+ * document merge, the data are stored in memory not on a hard >+ * disk >+ * >+ * @return The new part. >+ * @see #createPart(PackagePartName, String) >+ */ >+ public PackagePart createPart(PackagePartName partName, String contentType, >+ ByteArrayOutputStream content) { >+ PackagePart addedPart = this.createPart(partName, contentType); >+ if (addedPart == null) { >+ return null; >+ } >+ // Extract the zip entry content to put it in the part content >+ if (content != null) { >+ try { >+ OutputStream partOutput = addedPart.getOutputStream(); >+ if (partOutput == null) { >+ return null; >+ } >+ >+ partOutput.write(content.toByteArray(), 0, content.size()); >+ partOutput.close(); >+ >+ } catch (IOException ioe) { >+ return null; >+ } >+ } else { >+ return null; >+ } >+ return addedPart; >+ } >+ >+ /** >+ * Add the specified part to the package. If a part already exists in the >+ * package with the same name as the one specified, then we replace the old >+ * part by the specified part. >+ * >+ * @param part >+ * The part to add (or replace). >+ * @return The part added to the package, the same as the one specified. >+ * @throws InvalidFormatException >+ * If rule M1.12 is not verified : Packages shall not contain >+ * equivalent part names and package implementers shall neither >+ * create nor recognize packages with equivalent part names. >+ */ >+ protected PackagePart addPackagePart(PackagePart part) { >+ throwExceptionIfReadOnly(); >+ if (part == null) { >+ throw new IllegalArgumentException("part"); >+ } >+ >+ if (partList.containsKey(part.partName)) { >+ if (!partList.get(part.partName).isDeleted()) { >+ throw new InvalidOperationException( >+ "A part with the name '" >+ + part.partName.getName() >+ + "' already exists : Packages shall not contain equivalent part names and package implementers shall neither create nor recognize packages with equivalent part names. [M1.12]"); >+ } >+ // If the specified partis flagged as deleted, we make it >+ // available >+ part.setDeleted(false); >+ // and delete the old part to replace it thereafeter >+ this.partList.remove(part.partName); >+ } >+ this.partList.put(part.partName, part); >+ this.isDirty = true; >+ return part; >+ } >+ >+ /** >+ * Remove the specified part in this package. If this part is relationship >+ * part, then delete all relationships in the source part. >+ * >+ * @param part >+ * The part to remove. If <code>null</code>, skip the action. >+ * @see #removePart(PackagePartName) >+ */ >+ public void removePart(PackagePart part) { >+ if (part != null) { >+ removePart(part.getPartName()); >+ } >+ } >+ >+ /** >+ * Remove a part in this package. If this part is relationship part, then >+ * delete all relationships in the source part. >+ * >+ * @param partName >+ * The part name of the part to remove. >+ */ >+ public void removePart(PackagePartName partName) { >+ throwExceptionIfReadOnly(); >+ if (partName == null || !this.containPart(partName)) >+ throw new IllegalArgumentException("partName"); >+ >+ // Delete the specified part from the package. >+ if (this.partList.containsKey(partName)) { >+ this.partList.get(partName).setDeleted(true); >+ this.removePartImpl(partName); >+ this.partList.remove(partName); >+ } else { >+ this.removePartImpl(partName); >+ } >+ >+ // Delete content type >+ this.contentTypeManager.removeContentType(partName); >+ >+ // If this part is a relationship part, then delete all relationships of >+ // the source part. >+ if (partName.isRelationshipPartURI()) { >+ URI sourceURI = PackagingURIHelper >+ .getSourcePartUriFromRelationshipPartUri(partName.getURI()); >+ PackagePartName sourcePartName; >+ try { >+ sourcePartName = PackagingURIHelper.createPartName(sourceURI); >+ } catch (InvalidFormatException e) { >+ logger >+ .log(POILogger.ERROR, "Part name URI '" >+ + sourceURI >+ + "' is not valid ! This message is not intended to be displayed !"); >+ return; >+ } >+ if (sourcePartName.getURI().equals( >+ PackagingURIHelper.PACKAGE_ROOT_URI)) { >+ clearRelationships(); >+ } else if (containPart(sourcePartName)) { >+ PackagePart part = getPart(sourcePartName); >+ if (part != null) >+ part.clearRelationships(); >+ } >+ } >+ >+ this.isDirty = true; >+ } >+ >+ /** >+ * Remove a part from this package as well as its relationship part, if one >+ * exists, and all parts listed in the relationship part. Be aware that this >+ * do not delete relationships which target the specified part. >+ * >+ * @param partName >+ * The name of the part to delete. >+ * @throws InvalidFormatException >+ * Throws if the associated relationship part of the specified >+ * part is not valid. >+ */ >+ public void removePartRecursive(PackagePartName partName) >+ throws InvalidFormatException { >+ // Retrieves relationship part, if one exists >+ PackagePart relPart = this.partList.get(PackagingURIHelper >+ .getRelationshipPartName(partName)); >+ // Retrieves PackagePart object from the package >+ PackagePart partToRemove = this.partList.get(partName); >+ >+ if (relPart != null) { >+ PackageRelationshipCollection partRels = new PackageRelationshipCollection( >+ partToRemove); >+ for (PackageRelationship rel : partRels) { >+ PackagePartName partNameToRemove = PackagingURIHelper >+ .createPartName(PackagingURIHelper.resolvePartUri(rel >+ .getSourceURI(), rel.getTargetURI())); >+ removePart(partNameToRemove); >+ } >+ >+ // Finally delete its relationship part if one exists >+ this.removePart(relPart.partName); >+ } >+ >+ // Delete the specified part >+ this.removePart(partToRemove.partName); >+ } >+ >+ /** >+ * Delete the part with the specified name and its associated relationships >+ * part if one exists. Prefer the use of this method to delete a part in the >+ * package, compare to the remove() methods that don't remove associated >+ * relationships part. >+ * >+ * @param partName >+ * Name of the part to delete >+ */ >+ public void deletePart(PackagePartName partName) { >+ if (partName == null) >+ throw new IllegalArgumentException("partName"); >+ >+ // Remove the part >+ this.removePart(partName); >+ // Remove the relationships part >+ this.removePart(PackagingURIHelper.getRelationshipPartName(partName)); >+ } >+ >+ /** >+ * Delete the part with the specified name and all part listed in its >+ * associated relationships part if one exists. This process is recursively >+ * apply to all parts in the relationships part of the specified part. >+ * Prefer the use of this method to delete a part in the package, compare to >+ * the remove() methods that don't remove associated relationships part. >+ * >+ * @param partName >+ * Name of the part to delete >+ */ >+ public void deletePartRecursive(PackagePartName partName) { >+ if (partName == null || !this.containPart(partName)) >+ throw new IllegalArgumentException("partName"); >+ >+ PackagePart partToDelete = this.getPart(partName); >+ // Remove the part >+ this.removePart(partName); >+ // Remove all relationship parts associated >+ try { >+ for (PackageRelationship relationship : partToDelete >+ .getRelationships()) { >+ PackagePartName targetPartName = PackagingURIHelper >+ .createPartName(PackagingURIHelper.resolvePartUri( >+ partName.getURI(), relationship.getTargetURI())); >+ this.deletePartRecursive(targetPartName); >+ } >+ } catch (InvalidFormatException e) { >+ logger.log(POILogger.WARN, "An exception occurs while deleting part '" >+ + partName.getName() >+ + "'. Some parts may remain in the package. - " >+ + e.getMessage()); >+ return; >+ } >+ // Remove the relationships part >+ PackagePartName relationshipPartName = PackagingURIHelper >+ .getRelationshipPartName(partName); >+ if (relationshipPartName != null && containPart(relationshipPartName)) >+ this.removePart(relationshipPartName); >+ } >+ >+ /** >+ * Check if a part already exists in this package from its name. >+ * >+ * @param partName >+ * Part name to check. >+ * @return <i>true</i> if the part is logically added to this package, else >+ * <i>false</i>. >+ */ >+ public boolean containPart(PackagePartName partName) { >+ return (this.getPart(partName) != null); >+ } >+ >+ /** >+ * Add a relationship to the package (except relationships part). >+ * >+ * Check rule M4.1 : The format designer shall specify and the format >+ * producer shall create at most one core properties relationship for a >+ * package. A format consumer shall consider more than one core properties >+ * relationship for a package to be an error. If present, the relationship >+ * shall target the Core Properties part. >+ * >+ * 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. >+ * >+ * @param targetPartName >+ * Target part name. >+ * @param targetMode >+ * Target mode, either Internal or External. >+ * @param relationshipType >+ * Relationship type. >+ * @param relID >+ * ID of the relationship. >+ * @see PackageRelationshipTypes >+ */ >+ public PackageRelationship addRelationship(PackagePartName targetPartName, >+ TargetMode targetMode, String relationshipType, String relID) { >+ /* Check OPC compliance */ >+ >+ // Check rule M4.1 : The format designer shall specify and the format >+ // producer >+ // shall create at most one core properties relationship for a package. >+ // A format consumer shall consider more than one core properties >+ // relationship for a package to be an error. If present, the >+ // relationship shall target the Core Properties part. >+ if (relationshipType.equals(PackageRelationshipTypes.CORE_PROPERTIES) >+ && this.packageProperties != null) >+ throw new InvalidOperationException( >+ "OPC Compliance error [M4.1]: can't add another core properties part ! Use the built-in package method instead."); >+ >+ /* >+ * 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. >+ */ >+ if (targetPartName.isRelationshipPartURI()) { >+ throw new InvalidOperationException( >+ "Rule M1.25: The Relationships part shall not have relationships to any other part."); >+ } >+ >+ /* End OPC compliance */ >+ >+ ensureRelationships(); >+ PackageRelationship retRel = relationships.addRelationship( >+ targetPartName.getURI(), targetMode, relationshipType, relID); >+ this.isDirty = true; >+ return retRel; >+ } >+ >+ /** >+ * Add a package relationship. >+ * >+ * @param targetPartName >+ * Target part name. >+ * @param targetMode >+ * Target mode, either Internal or External. >+ * @param relationshipType >+ * Relationship type. >+ * @see PackageRelationshipTypes >+ */ >+ public PackageRelationship addRelationship(PackagePartName targetPartName, >+ TargetMode targetMode, String relationshipType) { >+ return this.addRelationship(targetPartName, targetMode, >+ 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. >+ * @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"); >+ } >+ >+ URI targetURI; >+ try { >+ targetURI = new URI(target); >+ } catch (URISyntaxException e) { >+ throw new IllegalArgumentException("Invalid target - " + e); >+ } >+ >+ ensureRelationships(); >+ PackageRelationship retRel = relationships.addRelationship(targetURI, >+ TargetMode.EXTERNAL, relationshipType, id); >+ this.isDirty = true; >+ return retRel; >+ } >+ >+ /** >+ * Delete a relationship from this package. >+ * >+ * @param id >+ * Id of the relationship to delete. >+ */ >+ public void removeRelationship(String id) { >+ if (relationships != null) { >+ relationships.removeRelationship(id); >+ this.isDirty = true; >+ } >+ } >+ >+ /** >+ * Retrieves all package relationships. >+ * >+ * @return All package relationships of this package. >+ * @throws OpenXML4JException >+ * @see #getRelationshipsHelper(String) >+ */ >+ public PackageRelationshipCollection getRelationships() { >+ return getRelationshipsHelper(null); >+ } >+ >+ /** >+ * Retrieves all relationships with the specified type. >+ * >+ * @param relationshipType >+ * The filter specifying the relationship type. >+ * @return All relationships with the specified relationship type. >+ */ >+ public PackageRelationshipCollection getRelationshipsByType( >+ String relationshipType) { >+ throwExceptionIfWriteOnly(); >+ if (relationshipType == null) { >+ throw new IllegalArgumentException("relationshipType"); >+ } >+ return getRelationshipsHelper(relationshipType); >+ } >+ >+ /** >+ * Retrieves all relationships with specified id (normally just ine because >+ * a relationship id is supposed to be unique). >+ * >+ * @param id >+ * Id of the wanted relationship. >+ */ >+ private PackageRelationshipCollection getRelationshipsHelper(String id) { >+ throwExceptionIfWriteOnly(); >+ ensureRelationships(); >+ return this.relationships.getRelationships(id); >+ } >+ >+ /** >+ * Clear package relationships. >+ */ >+ public void clearRelationships() { >+ if (relationships != null) { >+ relationships.clear(); >+ this.isDirty = true; >+ } >+ } >+ >+ /** >+ * Ensure that the relationships collection is not null. >+ */ >+ public void ensureRelationships() { >+ if (this.relationships == null) { >+ try { >+ this.relationships = new PackageRelationshipCollection(this); >+ } catch (InvalidFormatException e) { >+ this.relationships = new PackageRelationshipCollection(); >+ } >+ } >+ } >+ >+ /** >+ * @see org.apache.poi.openxml4j.opc.RelationshipSource#getRelationship(java.lang.String) >+ */ >+ public PackageRelationship getRelationship(String id) { >+ return this.relationships.getRelationshipByID(id); >+ } >+ >+ /** >+ * @see org.apache.poi.openxml4j.opc.RelationshipSource#hasRelationships() >+ */ >+ public boolean hasRelationships() { >+ return (relationships.size() > 0); >+ } >+ >+ /** >+ * @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; >+ } >+ } >+ >+ /** >+ * Add a marshaller. >+ * >+ * @param contentType >+ * The content type to bind to the specified marshaller. >+ * @param marshaller >+ * The marshaller to register with the specified content type. >+ */ >+ public void addMarshaller(String contentType, PartMarshaller marshaller) { >+ try { >+ partMarshallers.put(new ContentType(contentType), marshaller); >+ } catch (InvalidFormatException e) { >+ logger.log(POILogger.WARN, "The specified content type is not valid: '" >+ + e.getMessage() + "'. The marshaller will not be added !"); >+ } >+ } >+ >+ /** >+ * Add an unmarshaller. >+ * >+ * @param contentType >+ * The content type to bind to the specified unmarshaller. >+ * @param unmarshaller >+ * The unmarshaller to register with the specified content type. >+ */ >+ public void addUnmarshaller(String contentType, >+ PartUnmarshaller unmarshaller) { >+ try { >+ partUnmarshallers.put(new ContentType(contentType), unmarshaller); >+ } catch (InvalidFormatException e) { >+ logger.log(POILogger.WARN, "The specified content type is not valid: '" >+ + e.getMessage() >+ + "'. The unmarshaller will not be added !"); >+ } >+ } >+ >+ /** >+ * Remove a marshaller by its content type. >+ * >+ * @param contentType >+ * The content type associated with the marshaller to remove. >+ */ >+ public void removeMarshaller(String contentType) { >+ partMarshallers.remove(contentType); >+ } >+ >+ /** >+ * Remove an unmarshaller by its content type. >+ * >+ * @param contentType >+ * The content type associated with the unmarshaller to remove. >+ */ >+ public void removeUnmarshaller(String contentType) { >+ partUnmarshallers.remove(contentType); >+ } >+ >+ /* Accesseurs */ >+ >+ /** >+ * Get the package access mode. >+ * >+ * @return the packageAccess The current package access. >+ */ >+ public PackageAccess getPackageAccess() { >+ return packageAccess; >+ } >+ >+ /** >+ * Validates the package compliance with the OPC specifications. >+ * >+ * @return <b>true</b> if the package is valid else <b>false</b> >+ */ >+ public boolean validatePackage(OPCPackage pkg) throws InvalidFormatException { >+ throw new InvalidOperationException("Not implemented yet !!!"); >+ } >+ >+ /** >+ * Save the document in the specified file. >+ * >+ * @param targetFile >+ * Destination file. >+ * @throws IOException >+ * Throws if an IO exception occur. >+ * @see #save(OutputStream) >+ */ >+ public void save(File targetFile) throws IOException { >+ if (targetFile == null) >+ throw new IllegalArgumentException("targetFile"); >+ >+ this.throwExceptionIfReadOnly(); >+ FileOutputStream fos = null; >+ try { >+ fos = new FileOutputStream(targetFile); >+ } catch (FileNotFoundException e) { >+ throw new IOException(e.getLocalizedMessage()); >+ } >+ this.save(fos); >+ } >+ >+ /** >+ * Save the document in the specified output stream. >+ * >+ * @param outputStream >+ * The stream to save the package. >+ * @see #saveImpl(OutputStream) >+ */ >+ public void save(OutputStream outputStream) throws IOException { >+ throwExceptionIfReadOnly(); >+ this.saveImpl(outputStream); >+ } >+ >+ /** >+ * Core method to create a package part. This method must be implemented by >+ * the subclass. >+ * >+ * @param partName >+ * URI of the part to create. >+ * @param contentType >+ * Content type of the part to create. >+ * @return The newly created package part. >+ */ >+ protected abstract PackagePart createPartImpl(PackagePartName partName, >+ String contentType, boolean loadRelationships); >+ >+ /** >+ * Core method to delete a package part. This method must be implemented by >+ * the subclass. >+ * >+ * @param partName >+ * The URI of the part to delete. >+ */ >+ protected abstract void removePartImpl(PackagePartName partName); >+ >+ /** >+ * Flush the package but not save. >+ */ >+ protected abstract void flushImpl(); >+ >+ /** >+ * Close the package and cause a save of the package. >+ * >+ */ >+ protected abstract void closeImpl() throws IOException; >+ >+ /** >+ * Close the package without saving the document. Discard all changes made >+ * to this package. >+ */ >+ protected abstract void revertImpl(); >+ >+ /** >+ * Save the package into the specified output stream. >+ * >+ * @param outputStream >+ * The output stream use to save this package. >+ */ >+ protected abstract void saveImpl(OutputStream outputStream) >+ throws IOException; >+ >+ /** >+ * Get the package part mapped to the specified URI. >+ * >+ * @param partName >+ * The URI of the part to retrieve. >+ * @return The package part located by the specified URI, else <b>null</b>. >+ */ >+ protected abstract PackagePart getPartImpl(PackagePartName partName); >+ >+ /** >+ * Get all parts link to the package. >+ * >+ * @return A list of the part owned by the package. >+ */ >+ protected abstract PackagePart[] getPartsImpl() >+ throws InvalidFormatException; >+} >Index: src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java >=================================================================== >--- src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java (revision 754500) >+++ src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java (working copy) >@@ -36,6 +36,14 @@ > import org.apache.poi.POIXMLDocumentPart; > import org.apache.poi.POIXMLException; > import org.apache.poi.hssf.record.formula.SheetNameFormatter; >+import org.apache.poi.openxml4j.exceptions.OpenXML4JException; >+import org.apache.poi.openxml4j.opc.OPCPackage; >+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.PackageRelationshipTypes; >+import org.apache.poi.openxml4j.opc.PackagingURIHelper; >+import org.apache.poi.openxml4j.opc.TargetMode; > import org.apache.poi.ss.usermodel.Row; > import org.apache.poi.ss.usermodel.Sheet; > import org.apache.poi.ss.usermodel.Workbook; >@@ -45,20 +53,12 @@ > import org.apache.poi.util.POILogFactory; > import org.apache.poi.util.POILogger; > import org.apache.poi.util.PackageHelper; >+import org.apache.poi.xssf.model.CalculationChain; > import org.apache.poi.xssf.model.SharedStringsTable; > import org.apache.poi.xssf.model.StylesTable; >-import org.apache.poi.xssf.model.CalculationChain; > import org.apache.xmlbeans.XmlException; > import org.apache.xmlbeans.XmlObject; > import org.apache.xmlbeans.XmlOptions; >-import org.apache.poi.openxml4j.exceptions.OpenXML4JException; >-import org.apache.poi.openxml4j.opc.Package; >-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.PackageRelationshipTypes; >-import org.apache.poi.openxml4j.opc.PackagingURIHelper; >-import org.apache.poi.openxml4j.opc.TargetMode; > import org.openxmlformats.schemas.officeDocument.x2006.relationships.STRelationshipId; > import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBookView; > import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBookViews; >@@ -152,7 +152,7 @@ > * > * @param pkg the OpenXML4J <code>Package</code> object. > */ >- public XSSFWorkbook(Package pkg) throws IOException { >+ public XSSFWorkbook(OPCPackage pkg) throws IOException { > super(ensureWriteAccess(pkg)); > > //build a tree of POIXMLDocumentParts, this workbook being the root >@@ -240,9 +240,9 @@ > /** > * Create a new SpreadsheetML package and setup the default minimal content > */ >- protected static Package newPackage() { >+ protected static OPCPackage newPackage() { > try { >- Package pkg = Package.create(PackageHelper.createTempFile()); >+ OPCPackage pkg = OPCPackage.create(PackageHelper.createTempFile()); > // Main part > PackagePartName corePartName = PackagingURIHelper.createPartName(XSSFRelation.WORKBOOK.getDefaultFileName()); > // Create main part relationship >Index: src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFReader.java >=================================================================== >--- src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFReader.java (revision 754500) >+++ src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFReader.java (working copy) >@@ -18,24 +18,28 @@ > > import java.io.IOException; > import java.io.InputStream; >-import java.util.*; >+import java.util.ArrayList; >+import java.util.Arrays; >+import java.util.HashMap; >+import java.util.Iterator; >+import java.util.Map; > >-import org.apache.poi.xssf.model.SharedStringsTable; >-import org.apache.poi.xssf.model.StylesTable; >-import org.apache.poi.xssf.usermodel.XSSFRelation; > import org.apache.poi.POIXMLException; >-import org.apache.xmlbeans.XmlException; > import org.apache.poi.openxml4j.exceptions.InvalidFormatException; > import org.apache.poi.openxml4j.exceptions.OpenXML4JException; >-import org.apache.poi.openxml4j.opc.Package; >+import org.apache.poi.openxml4j.opc.OPCPackage; > 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.PackageRelationshipTypes; > import org.apache.poi.openxml4j.opc.PackagingURIHelper; >+import org.apache.poi.xssf.model.SharedStringsTable; >+import org.apache.poi.xssf.model.StylesTable; >+import org.apache.poi.xssf.usermodel.XSSFRelation; >+import org.apache.xmlbeans.XmlException; >+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheet; > import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorkbook; > import org.openxmlformats.schemas.spreadsheetml.x2006.main.WorkbookDocument; >-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheet; > > /** > * This class makes it easy to get at individual parts >@@ -45,13 +49,13 @@ > * for XSSF. > */ > public class XSSFReader { >- private Package pkg; >+ private OPCPackage pkg; > private PackagePart workbookPart; > > /** > * Creates a new XSSFReader, for the given package > */ >- public XSSFReader(Package pkg) throws IOException, OpenXML4JException { >+ public XSSFReader(OPCPackage pkg) throws IOException, OpenXML4JException { > this.pkg = pkg; > > PackageRelationship coreDocRelationship = this.pkg.getRelationshipsByType( >Index: src/ooxml/java/org/apache/poi/xssf/extractor/XSSFExcelExtractor.java >=================================================================== >--- src/ooxml/java/org/apache/poi/xssf/extractor/XSSFExcelExtractor.java (revision 754500) >+++ src/ooxml/java/org/apache/poi/xssf/extractor/XSSFExcelExtractor.java (working copy) >@@ -21,6 +21,8 @@ > > import org.apache.poi.POIXMLTextExtractor; > import org.apache.poi.hssf.extractor.ExcelExtractor; >+import org.apache.poi.openxml4j.exceptions.OpenXML4JException; >+import org.apache.poi.openxml4j.opc.OPCPackage; > import org.apache.poi.ss.usermodel.Cell; > import org.apache.poi.ss.usermodel.Comment; > import org.apache.poi.ss.usermodel.HeaderFooter; >@@ -29,8 +31,6 @@ > import org.apache.poi.xssf.usermodel.XSSFSheet; > import org.apache.poi.xssf.usermodel.XSSFWorkbook; > import org.apache.xmlbeans.XmlException; >-import org.apache.poi.openxml4j.exceptions.OpenXML4JException; >-import org.apache.poi.openxml4j.opc.Package; > > /** > * Helper class to extract text from an OOXML Excel file >@@ -44,7 +44,7 @@ > public XSSFExcelExtractor(String path) throws XmlException, OpenXML4JException, IOException { > this(new XSSFWorkbook(path)); > } >- public XSSFExcelExtractor(Package container) throws XmlException, OpenXML4JException, IOException { >+ public XSSFExcelExtractor(OPCPackage container) throws XmlException, OpenXML4JException, IOException { > this(new XSSFWorkbook(container)); > } > public XSSFExcelExtractor(XSSFWorkbook workbook) { >Index: src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java >=================================================================== >--- src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java (revision 754500) >+++ src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java (working copy) >@@ -30,7 +30,6 @@ > import org.apache.poi.openxml4j.exceptions.InvalidFormatException; > import org.apache.poi.openxml4j.exceptions.OpenXML4JException; > import org.apache.poi.openxml4j.opc.*; >-import org.apache.poi.openxml4j.opc.Package; > import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBody; > import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTComment; > import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTDocument1; >@@ -65,7 +64,7 @@ > /** Handles the joy of different headers/footers for different pages */ > private XWPFHeaderFooterPolicy headerFooterPolicy; > >- public XWPFDocument(Package pkg) throws IOException { >+ public XWPFDocument(OPCPackage pkg) throws IOException { > super(ensureWriteAccess(pkg)); > > //build a tree of POIXMLDocumentParts, this document being the root >@@ -143,9 +142,9 @@ > /** > * Create a new SpreadsheetML package and setup the default minimal content > */ >- protected static Package newPackage() { >+ protected static OPCPackage newPackage() { > try { >- Package pkg = Package.create(PackageHelper.createTempFile()); >+ OPCPackage pkg = OPCPackage.create(PackageHelper.createTempFile()); > // Main part > PackagePartName corePartName = PackagingURIHelper.createPartName(XWPFRelation.DOCUMENT.getDefaultFileName()); > // Create main part relationship >Index: src/ooxml/java/org/apache/poi/xwpf/extractor/XWPFWordExtractor.java >=================================================================== >--- src/ooxml/java/org/apache/poi/xwpf/extractor/XWPFWordExtractor.java (revision 754500) >+++ src/ooxml/java/org/apache/poi/xwpf/extractor/XWPFWordExtractor.java (working copy) >@@ -21,16 +21,16 @@ > > import org.apache.poi.POIXMLDocument; > import org.apache.poi.POIXMLTextExtractor; >-import org.apache.poi.xwpf.usermodel.XWPFDocument; >+import org.apache.poi.openxml4j.exceptions.OpenXML4JException; >+import org.apache.poi.openxml4j.opc.OPCPackage; > import org.apache.poi.xwpf.model.XWPFCommentsDecorator; > import org.apache.poi.xwpf.model.XWPFHeaderFooterPolicy; > import org.apache.poi.xwpf.model.XWPFHyperlinkDecorator; > import org.apache.poi.xwpf.model.XWPFParagraphDecorator; >+import org.apache.poi.xwpf.usermodel.XWPFDocument; > import org.apache.poi.xwpf.usermodel.XWPFParagraph; > import org.apache.poi.xwpf.usermodel.XWPFTable; > import org.apache.xmlbeans.XmlException; >-import org.apache.poi.openxml4j.exceptions.OpenXML4JException; >-import org.apache.poi.openxml4j.opc.Package; > > /** > * Helper class to extract text from an OOXML Word file >@@ -39,7 +39,7 @@ > private XWPFDocument document; > private boolean fetchHyperlinks = false; > >- public XWPFWordExtractor(Package container) throws XmlException, OpenXML4JException, IOException { >+ public XWPFWordExtractor(OPCPackage container) throws XmlException, OpenXML4JException, IOException { > this(new XWPFDocument(container)); > } > public XWPFWordExtractor(XWPFDocument document) { >Index: src/ooxml/java/org/apache/poi/ss/usermodel/WorkbookFactory.java >=================================================================== >--- src/ooxml/java/org/apache/poi/ss/usermodel/WorkbookFactory.java (revision 754500) >+++ src/ooxml/java/org/apache/poi/ss/usermodel/WorkbookFactory.java (working copy) >@@ -22,10 +22,10 @@ > > import org.apache.poi.POIXMLDocument; > import org.apache.poi.hssf.usermodel.HSSFWorkbook; >+import org.apache.poi.openxml4j.exceptions.InvalidFormatException; >+import org.apache.poi.openxml4j.opc.OPCPackage; > import org.apache.poi.poifs.filesystem.POIFSFileSystem; > import org.apache.poi.xssf.usermodel.XSSFWorkbook; >-import org.apache.poi.openxml4j.exceptions.InvalidFormatException; >-import org.apache.poi.openxml4j.opc.Package; > > /** > * Factory for creating the appropriate kind of Workbook >@@ -41,7 +41,7 @@ > /** > * Creates an XSSFWorkbook from the given OOXML Package > */ >- public static Workbook create(Package pkg) throws IOException { >+ public static Workbook create(OPCPackage pkg) throws IOException { > return new XSSFWorkbook(pkg); > } > /** >@@ -60,7 +60,7 @@ > return new HSSFWorkbook(inp); > } > if(POIXMLDocument.hasOOXMLHeader(inp)) { >- return new XSSFWorkbook( Package.open(inp) ); >+ return new XSSFWorkbook(OPCPackage.open(inp)); > } > throw new IllegalArgumentException("Your InputStream was neither an OLE2 stream, nor an OOXML stream"); > } >Index: src/ooxml/java/org/apache/poi/POIXMLDocument.java >=================================================================== >--- src/ooxml/java/org/apache/poi/POIXMLDocument.java (revision 754500) >+++ src/ooxml/java/org/apache/poi/POIXMLDocument.java (working copy) >@@ -41,14 +41,14 @@ > public static final String PACK_OBJECT_REL_TYPE="http://schemas.openxmlformats.org/officeDocument/2006/relationships/package"; > > /** The OPC Package */ >- private Package pkg; >+ private OPCPackage pkg; > > /** > * The properties of the OPC package, opened as needed > */ > private POIXMLProperties properties; > >- protected POIXMLDocument(Package pkg) { >+ protected POIXMLDocument(OPCPackage pkg) { > super(pkg); > this.pkg = pkg; > } >@@ -58,15 +58,15 @@ > * in the event of a problem. > * Works around shortcomings in java's this() constructor calls > */ >- public static Package openPackage(String path) throws IOException { >+ public static OPCPackage openPackage(String path) throws IOException { > try { >- return Package.open(path); >+ return OPCPackage.open(path); > } catch (InvalidFormatException e) { > throw new IOException(e.toString()); > } > } > >- public Package getPackage() { >+ public OPCPackage getPackage() { > return this.pkg; > } > >@@ -92,7 +92,7 @@ > * @return The target part > * @throws InvalidFormatException > */ >- protected static PackagePart getTargetPart(Package pkg, PackageRelationship rel) throws InvalidFormatException { >+ protected static PackagePart getTargetPart(OPCPackage pkg, PackageRelationship rel) throws InvalidFormatException { > PackagePartName relName = PackagingURIHelper.createPartName(rel.getTargetURI()); > PackagePart part = pkg.getPart(relName); > if (part == null) { >@@ -176,7 +176,7 @@ > * there is no way to change or even save such an instance in a OutputStream. > * The workaround is to create a copy via a temp file > */ >- protected static Package ensureWriteAccess(Package pkg) throws IOException { >+ protected static OPCPackage ensureWriteAccess(OPCPackage pkg) throws IOException { > if(pkg.getPackageAccess() == PackageAccess.READ){ > try { > return PackageHelper.clone(pkg); >Index: src/ooxml/java/org/apache/poi/POIXMLProperties.java >=================================================================== >--- src/ooxml/java/org/apache/poi/POIXMLProperties.java (revision 754500) >+++ src/ooxml/java/org/apache/poi/POIXMLProperties.java (working copy) >@@ -18,23 +18,23 @@ > > import java.io.IOException; > >-import org.apache.xmlbeans.XmlException; > import org.apache.poi.openxml4j.exceptions.OpenXML4JException; >-import org.apache.poi.openxml4j.opc.Package; >+import org.apache.poi.openxml4j.opc.OPCPackage; > import org.apache.poi.openxml4j.opc.PackageRelationshipCollection; > import org.apache.poi.openxml4j.opc.internal.PackagePropertiesPart; >+import org.apache.xmlbeans.XmlException; > > /** > * Wrapper around the two different kinds of OOXML properties > * a document can have > */ > public class POIXMLProperties { >- private Package pkg; >+ private OPCPackage pkg; > private CoreProperties core; > private ExtendedProperties ext; > private CustomProperties cust; > >- public POIXMLProperties(Package docPackage) throws IOException, OpenXML4JException, XmlException { >+ public POIXMLProperties(OPCPackage docPackage) throws IOException, OpenXML4JException, XmlException { > this.pkg = docPackage; > > // Core properties >@@ -97,7 +97,7 @@ > * Writes out the ooxml properties into the supplied, > * new Package > */ >- public void write(Package pkg) { >+ public void write(OPCPackage pkg) { > // TODO > } > >Index: src/ooxml/java/org/apache/poi/extractor/ExtractorFactory.java >=================================================================== >--- src/ooxml/java/org/apache/poi/extractor/ExtractorFactory.java (revision 754500) >+++ src/ooxml/java/org/apache/poi/extractor/ExtractorFactory.java (working copy) >@@ -33,6 +33,11 @@ > import org.apache.poi.hslf.extractor.PowerPointExtractor; > import org.apache.poi.hssf.extractor.ExcelExtractor; > import org.apache.poi.hwpf.extractor.WordExtractor; >+import org.apache.poi.openxml4j.exceptions.InvalidFormatException; >+import org.apache.poi.openxml4j.exceptions.OpenXML4JException; >+import org.apache.poi.openxml4j.opc.OPCPackage; >+import org.apache.poi.openxml4j.opc.PackagePart; >+import org.apache.poi.openxml4j.opc.PackageRelationshipCollection; > import org.apache.poi.poifs.filesystem.DirectoryEntry; > import org.apache.poi.poifs.filesystem.DirectoryNode; > import org.apache.poi.poifs.filesystem.Entry; >@@ -41,14 +46,9 @@ > import org.apache.poi.xslf.extractor.XSLFPowerPointExtractor; > import org.apache.poi.xssf.extractor.XSSFExcelExtractor; > import org.apache.poi.xssf.usermodel.XSSFRelation; >+import org.apache.poi.xwpf.extractor.XWPFWordExtractor; > import org.apache.poi.xwpf.usermodel.XWPFRelation; >-import org.apache.poi.xwpf.extractor.XWPFWordExtractor; > import org.apache.xmlbeans.XmlException; >-import org.apache.poi.openxml4j.exceptions.InvalidFormatException; >-import org.apache.poi.openxml4j.exceptions.OpenXML4JException; >-import org.apache.poi.openxml4j.opc.Package; >-import org.apache.poi.openxml4j.opc.PackagePart; >-import org.apache.poi.openxml4j.opc.PackageRelationshipCollection; > > /** > * Figures out the correct POITextExtractor for your supplied >@@ -67,7 +67,7 @@ > } > if(POIXMLDocument.hasOOXMLHeader(inp)) { > inp.close(); >- return createExtractor(Package.open(f.toString())); >+ return createExtractor(OPCPackage.open(f.toString())); > } > throw new IllegalArgumentException("Your File was neither an OLE2 file, nor an OOXML file"); > } >@@ -83,12 +83,12 @@ > return createExtractor(new POIFSFileSystem(inp)); > } > if(POIXMLDocument.hasOOXMLHeader(inp)) { >- return createExtractor(Package.open(inp)); >+ return createExtractor(OPCPackage.open(inp)); > } > throw new IllegalArgumentException("Your InputStream was neither an OLE2 stream, nor an OOXML stream"); > } > >- public static POIXMLTextExtractor createExtractor(Package pkg) throws IOException, OpenXML4JException, XmlException { >+ public static POIXMLTextExtractor createExtractor(OPCPackage pkg) throws IOException, OpenXML4JException, XmlException { > PackageRelationshipCollection core = > pkg.getRelationshipsByType(CORE_DOCUMENT_REL); > if(core.size() != 1) { >Index: src/ooxml/java/org/apache/poi/xslf/extractor/XSLFPowerPointExtractor.java >=================================================================== >--- src/ooxml/java/org/apache/poi/xslf/extractor/XSLFPowerPointExtractor.java (revision 754500) >+++ src/ooxml/java/org/apache/poi/xslf/extractor/XSLFPowerPointExtractor.java (working copy) >@@ -19,12 +19,12 @@ > import java.io.IOException; > > import org.apache.poi.POIXMLTextExtractor; >+import org.apache.poi.openxml4j.exceptions.OpenXML4JException; >+import org.apache.poi.openxml4j.opc.OPCPackage; > import org.apache.poi.xslf.XSLFSlideShow; > import org.apache.poi.xslf.usermodel.XMLSlideShow; > import org.apache.poi.xslf.usermodel.XSLFSlide; > import org.apache.xmlbeans.XmlException; >-import org.apache.poi.openxml4j.exceptions.OpenXML4JException; >-import org.apache.poi.openxml4j.opc.Package; > import org.openxmlformats.schemas.drawingml.x2006.main.CTRegularTextRun; > import org.openxmlformats.schemas.drawingml.x2006.main.CTTextBody; > import org.openxmlformats.schemas.drawingml.x2006.main.CTTextParagraph; >@@ -48,7 +48,7 @@ > public XSLFPowerPointExtractor(XSLFSlideShow slideshow) throws XmlException, IOException { > this(new XMLSlideShow(slideshow)); > } >- public XSLFPowerPointExtractor(Package container) throws XmlException, OpenXML4JException, IOException { >+ public XSLFPowerPointExtractor(OPCPackage container) throws XmlException, OpenXML4JException, IOException { > this(new XSLFSlideShow(container)); > } > >Index: src/ooxml/java/org/apache/poi/xslf/XSLFSlideShow.java >=================================================================== >--- src/ooxml/java/org/apache/poi/xslf/XSLFSlideShow.java (revision 754500) >+++ src/ooxml/java/org/apache/poi/xslf/XSLFSlideShow.java (working copy) >@@ -17,17 +17,17 @@ > package org.apache.poi.xslf; > > import java.io.IOException; >+import java.util.LinkedList; > import java.util.List; >-import java.util.LinkedList; > > import org.apache.poi.POIXMLDocument; >-import org.apache.xmlbeans.XmlException; > import org.apache.poi.openxml4j.exceptions.InvalidFormatException; > import org.apache.poi.openxml4j.exceptions.OpenXML4JException; >-import org.apache.poi.openxml4j.opc.Package; >+import org.apache.poi.openxml4j.opc.OPCPackage; > import org.apache.poi.openxml4j.opc.PackagePart; > import org.apache.poi.openxml4j.opc.PackageRelationship; > import org.apache.poi.openxml4j.opc.PackageRelationshipCollection; >+import org.apache.xmlbeans.XmlException; > import org.openxmlformats.schemas.presentationml.x2006.main.CTCommentList; > import org.openxmlformats.schemas.presentationml.x2006.main.CTNotesSlide; > import org.openxmlformats.schemas.presentationml.x2006.main.CTPresentation; >@@ -68,7 +68,7 @@ > */ > private List<PackagePart> embedds; > >- public XSLFSlideShow(Package container) throws OpenXML4JException, IOException, XmlException { >+ public XSLFSlideShow(OPCPackage container) throws OpenXML4JException, IOException, XmlException { > super(container); > > presentationDoc = >Index: src/ooxml/java/org/apache/poi/util/PackageHelper.java >=================================================================== >--- src/ooxml/java/org/apache/poi/util/PackageHelper.java (revision 754500) >+++ src/ooxml/java/org/apache/poi/util/PackageHelper.java (working copy) >@@ -17,7 +17,7 @@ > package org.apache.poi.util; > > import org.apache.poi.openxml4j.opc.*; >-import org.apache.poi.openxml4j.opc.Package; >+import org.apache.poi.openxml4j.opc.OPCPackage; > import org.apache.poi.openxml4j.exceptions.OpenXML4JException; > import org.apache.poi.util.IOUtils; > >@@ -36,7 +36,7 @@ > * @param pkg the package to clone > * @return the cloned package > */ >- public static Package clone(Package pkg) throws OpenXML4JException, IOException { >+ public static OPCPackage clone(OPCPackage pkg) throws OpenXML4JException, IOException { > return clone(pkg, createTempFile()); > } > >@@ -47,11 +47,11 @@ > * @param file the destination file > * @return the cloned package > */ >- public static Package clone(Package pkg, File file) throws OpenXML4JException, IOException { >+ public static OPCPackage clone(OPCPackage pkg, File file) throws OpenXML4JException, IOException { > > String path = file.getAbsolutePath(); > >- Package dest = Package.create(path); >+ OPCPackage dest = OPCPackage.create(path); > PackageRelationshipCollection rels = pkg.getRelationships(); > for (PackageRelationship rel : rels) { > PackagePart part = pkg.getPart(rel); >@@ -76,7 +76,7 @@ > > //the temp file will be deleted when JVM terminates > new File(path).deleteOnExit(); >- return Package.open(path); >+ return OPCPackage.open(path); > } > > /** >@@ -95,7 +95,7 @@ > /** > * Recursively copy package parts to the destination package > */ >- private static void copy(Package pkg, PackagePart part, Package tgt, PackagePart part_tgt) throws OpenXML4JException, IOException { >+ private static void copy(OPCPackage pkg, PackagePart part, OPCPackage tgt, PackagePart part_tgt) throws OpenXML4JException, IOException { > PackageRelationshipCollection rels = part.getRelationships(); > if(rels != null) for (PackageRelationship rel : rels) { > PackagePart p; >Index: src/ooxml/java/org/apache/poi/dev/OOXMLLister.java >=================================================================== >--- src/ooxml/java/org/apache/poi/dev/OOXMLLister.java (revision 754500) >+++ src/ooxml/java/org/apache/poi/dev/OOXMLLister.java (working copy) >@@ -22,7 +22,7 @@ > import java.io.PrintStream; > import java.util.ArrayList; > >-import org.apache.poi.openxml4j.opc.Package; >+import org.apache.poi.openxml4j.opc.OPCPackage; > import org.apache.poi.openxml4j.opc.PackageAccess; > import org.apache.poi.openxml4j.opc.PackagePart; > import org.apache.poi.openxml4j.opc.PackageRelationship; >@@ -34,13 +34,13 @@ > * they're all related to each other. > */ > public class OOXMLLister { >- private Package container; >+ private OPCPackage container; > private PrintStream disp; > >- public OOXMLLister(Package container) { >+ public OOXMLLister(OPCPackage container) { > this(container, System.out); > } >- public OOXMLLister(Package container, PrintStream disp) { >+ public OOXMLLister(OPCPackage container, PrintStream disp) { > this.container = container; > this.disp = disp; > } >@@ -122,7 +122,7 @@ > } > > OOXMLLister lister = new OOXMLLister( >- Package.open(f.toString(), PackageAccess.READ) >+ OPCPackage.open(f.toString(), PackageAccess.READ) > ); > > lister.disp.println(f.toString() + "\n"); >Index: src/ooxml/java/org/apache/poi/POIXMLDocumentPart.java >=================================================================== >--- src/ooxml/java/org/apache/poi/POIXMLDocumentPart.java (revision 754500) >+++ src/ooxml/java/org/apache/poi/POIXMLDocumentPart.java (working copy) >@@ -55,17 +55,13 @@ > /** > * Construct POIXMLDocumentPart representing a "core document" package part. > */ >- public POIXMLDocumentPart(Package pkg) { >- try { >- PackageRelationship coreRel = pkg.getRelationshipsByType( >- PackageRelationshipTypes.CORE_DOCUMENT).getRelationship(0); >+ public POIXMLDocumentPart(OPCPackage pkg) { >+ PackageRelationship coreRel = pkg.getRelationshipsByType( >+ PackageRelationshipTypes.CORE_DOCUMENT).getRelationship(0); > >- this.relations = new LinkedList<POIXMLDocumentPart>(); >- this.packagePart = pkg.getPart(coreRel); >- this.packageRel = coreRel; >- } catch (OpenXML4JException e){ >- throw new POIXMLException(e); >- } >+ this.relations = new LinkedList<POIXMLDocumentPart>(); >+ this.packagePart = pkg.getPart(coreRel); >+ this.packageRel = coreRel; > } > > /** >Index: src/ooxml/testcases/org/apache/poi/openxml4j/OpenXML4JTestDataSamples.java >=================================================================== >--- src/ooxml/testcases/org/apache/poi/openxml4j/OpenXML4JTestDataSamples.java (revision 754500) >+++ src/ooxml/testcases/org/apache/poi/openxml4j/OpenXML4JTestDataSamples.java (working copy) >@@ -113,6 +113,9 @@ > } > > private static File getAndCheckDirByProperty(String propName) { >+ File bd = new File(new File("C:/josh/client/poi/svn/trunkA/src/ooxml/testcases"), "org/apache/poi/openxml4j/opc"); >+ System.setProperty(COMP_IN_DIR_PROP_NAME, new File(bd, "compliance/data").getAbsolutePath()); >+ System.setProperty(IN_DIR_PROP_NAME, new File(bd, "data").getAbsolutePath()); > String dirName = System.getProperty(propName); > File dir = new File(dirName); > if (!dir.exists()) { >Index: src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackageThumbnail.java >=================================================================== >--- src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackageThumbnail.java (revision 754500) >+++ src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackageThumbnail.java (working copy) >@@ -41,13 +41,13 @@ > File outputFile = OpenXML4JTestDataSamples.getOutputFile("TestPackageThumbnailOUTPUT.docx"); > > // Open package >- Package p = Package.open(inputPath, PackageAccess.READ_WRITE); >+ OPCPackage p = OPCPackage.open(inputPath, PackageAccess.READ_WRITE); > p.addThumbnail(imagePath); > // Save the package in the output directory > p.save(outputFile); > > // Open the newly created file to check core properties saved values. >- Package p2 = Package.open(outputFile.getAbsolutePath(), PackageAccess.READ); >+ OPCPackage p2 = OPCPackage.open(outputFile.getAbsolutePath(), PackageAccess.READ); > if (p2.getRelationshipsByType(PackageRelationshipTypes.THUMBNAIL) > .size() == 0) > fail("Thumbnail not added to the package !"); >Index: src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackageCoreProperties.java >=================================================================== >--- src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackageCoreProperties.java (revision 754500) >+++ src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackageCoreProperties.java (working copy) >@@ -39,7 +39,7 @@ > public void testGetProperties() { > try { > // Open the package >- Package p = Package.open(OpenXML4JTestDataSamples.openSampleStream("TestPackageCoreProperiesGetters.docx")); >+ OPCPackage p = OPCPackage.open(OpenXML4JTestDataSamples.openSampleStream("TestPackageCoreProperiesGetters.docx")); > compareProperties(p); > p.revert(); > } catch (OpenXML4JException e) { >@@ -59,7 +59,7 @@ > File outputFile = OpenXML4JTestDataSamples.getOutputFile("TestPackageCoreProperiesSettersOUTPUT.docx"); > > // Open package >- Package p = Package.open(inputPath, PackageAccess.READ_WRITE); >+ OPCPackage p = OPCPackage.open(inputPath, PackageAccess.READ_WRITE); > > SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); > Date dateToInsert = df.parse("2007-05-12T08:00:00Z", new ParsePosition( >@@ -86,13 +86,13 @@ > p.save(outputFile); > > // Open the newly created file to check core properties saved values. >- Package p2 = Package.open(outputFile.getAbsolutePath(), PackageAccess.READ); >+ OPCPackage p2 = OPCPackage.open(outputFile.getAbsolutePath(), PackageAccess.READ); > compareProperties(p2); > p2.revert(); > outputFile.delete(); > } > >- private void compareProperties(Package p) throws InvalidFormatException { >+ private void compareProperties(OPCPackage p) throws InvalidFormatException { > SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); > Date expectedDate = df.parse("2007-05-12T08:00:00Z", new ParsePosition( > 0)); >Index: src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackagingURIHelper.java >=================================================================== >--- src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackagingURIHelper.java (revision 754500) >+++ src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackagingURIHelper.java (working copy) >@@ -22,7 +22,7 @@ > > import org.apache.poi.openxml4j.exceptions.InvalidFormatException; > import org.apache.poi.openxml4j.opc.ContentTypes; >-import org.apache.poi.openxml4j.opc.Package; >+import org.apache.poi.openxml4j.opc.OPCPackage; > import org.apache.poi.openxml4j.opc.PackagePart; > import org.apache.poi.openxml4j.opc.PackagePartName; > import org.apache.poi.openxml4j.opc.PackagingURIHelper; >@@ -80,7 +80,7 @@ > PackagePartName partNameToValid = PackagingURIHelper > .createPartName("/word/media/image1.gif"); > >- Package pkg = Package.create("DELETEIFEXISTS.docx"); >+ OPCPackage pkg = OPCPackage.create("DELETEIFEXISTS.docx"); > // Base part > PackagePartName nameBase = PackagingURIHelper > .createPartName("/word/document.xml"); >@@ -101,7 +101,7 @@ > PackagePartName partNameToValid = PackagingURIHelper > .createPartName("/word/media/image1.gif"); > >- Package pkg = Package.create("DELETEIFEXISTS.docx"); >+ OPCPackage pkg = OPCPackage.create("DELETEIFEXISTS.docx"); > // Base part > PackagePartName nameBase = PackagingURIHelper > .createPartName("/word/document.xml"); >Index: src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestRelationships.java >=================================================================== >--- src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestRelationships.java (revision 754500) >+++ src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestRelationships.java (working copy) >@@ -45,7 +45,7 @@ > */ > public void testLoadRelationships() throws Exception { > InputStream is = OpenXML4JTestDataSamples.openSampleStream("sample.xlsx"); >- Package pkg = Package.open(is); >+ OPCPackage pkg = OPCPackage.open(is); > logger.debug("1: " + pkg); > PackageRelationshipCollection rels = pkg.getRelationshipsByType(PackageRelationshipTypes.CORE_DOCUMENT); > PackageRelationship coreDocRelationship = rels.getRelationship(0); >@@ -66,7 +66,7 @@ > */ > public void testFetchFromCollection() throws Exception { > InputStream is = OpenXML4JTestDataSamples.openSampleStream("ExcelWithHyperlinks.xlsx"); >- Package pkg = Package.open(is); >+ OPCPackage pkg = OPCPackage.open(is); > PackagePart sheet = pkg.getPart( > PackagingURIHelper.createPartName(SHEET_WITH_COMMENTS)); > assertNotNull(sheet); >@@ -107,7 +107,7 @@ > */ > public void testLoadExcelHyperlinkRelations() throws Exception { > InputStream is = OpenXML4JTestDataSamples.openSampleStream("ExcelWithHyperlinks.xlsx"); >- Package pkg = Package.open(is); >+ OPCPackage pkg = OPCPackage.open(is); > PackagePart sheet = pkg.getPart( > PackagingURIHelper.createPartName(SHEET_WITH_COMMENTS)); > assertNotNull(sheet); >@@ -141,7 +141,7 @@ > */ > public void testCreateExcelHyperlinkRelations() throws Exception { > String filepath = OpenXML4JTestDataSamples.getSampleFileName("ExcelWithHyperlinks.xlsx"); >- Package pkg = Package.open(filepath, PackageAccess.READ_WRITE); >+ OPCPackage pkg = OPCPackage.open(filepath, PackageAccess.READ_WRITE); > PackagePart sheet = pkg.getPart( > PackagingURIHelper.createPartName(SHEET_WITH_COMMENTS)); > assertNotNull(sheet); >@@ -185,7 +185,7 @@ > ByteArrayOutputStream baos = new ByteArrayOutputStream(); > pkg.save(baos); > ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); >- pkg = Package.open(bais); >+ pkg = OPCPackage.open(bais); > > // Check again > sheet = pkg.getPart( >@@ -208,7 +208,7 @@ > > public void testCreateRelationsFromScratch() throws Exception { > ByteArrayOutputStream baos = new ByteArrayOutputStream(); >- Package pkg = Package.create(baos); >+ OPCPackage pkg = OPCPackage.create(baos); > > PackagePart partA = > pkg.createPart(PackagingURIHelper.createPartName("/partA"), "text/plain"); >@@ -235,7 +235,7 @@ > // Save, and re-load > pkg.close(); > ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); >- pkg = Package.open(bais); >+ pkg = OPCPackage.open(bais); > > partA = pkg.getPart(PackagingURIHelper.createPartName("/partA")); > partB = pkg.getPart(PackagingURIHelper.createPartName("/partB")); >Index: src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestListParts.java >=================================================================== >--- src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestListParts.java (revision 754500) >+++ src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestListParts.java (working copy) >@@ -83,9 +83,9 @@ > public void testListParts() throws InvalidFormatException { > InputStream is = OpenXML4JTestDataSamples.openSampleStream("sample.docx"); > >- Package p; >+ OPCPackage p; > try { >- p = Package.open(is); >+ p = OPCPackage.open(is); > } catch (IOException e) { > throw new RuntimeException(e); > } >Index: src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCComplianceCoreProperties.java >=================================================================== >--- src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCComplianceCoreProperties.java (revision 754500) >+++ src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCComplianceCoreProperties.java (working copy) >@@ -29,7 +29,7 @@ > import org.apache.poi.openxml4j.exceptions.InvalidFormatException; > import org.apache.poi.openxml4j.exceptions.InvalidOperationException; > import org.apache.poi.openxml4j.opc.ContentTypes; >-import org.apache.poi.openxml4j.opc.Package; >+import org.apache.poi.openxml4j.opc.OPCPackage; > import org.apache.poi.openxml4j.opc.PackageRelationshipTypes; > import org.apache.poi.openxml4j.opc.PackagingURIHelper; > import org.apache.poi.openxml4j.opc.TargetMode; >@@ -68,10 +68,10 @@ > public final class TestOPCComplianceCoreProperties extends TestCase { > > public void testCorePropertiesPart() { >- Package pkg; >+ OPCPackage pkg; > try { > InputStream is = OpenXML4JTestDataSamples.openComplianceSampleStream("OPCCompliance_CoreProperties_OnlyOneCorePropertiesPart.docx"); >- pkg = Package.open(is); >+ pkg = OPCPackage.open(is); > } catch (InvalidFormatException e) { > throw new RuntimeException(e); > } catch (IOException e) { >@@ -83,9 +83,9 @@ > private static String extractInvalidFormatMessage(String sampleNameSuffix) { > > InputStream is = OpenXML4JTestDataSamples.openComplianceSampleStream("OPCCompliance_CoreProperties_" + sampleNameSuffix); >- Package pkg; >+ OPCPackage pkg; > try { >- pkg = Package.open(is); >+ pkg = OPCPackage.open(is); > } catch (InvalidFormatException e) { > // expected during successful test > return e.getMessage(); >@@ -118,9 +118,9 @@ > */ > public void testOnlyOneCorePropertiesPart_AddRelationship() { > InputStream is = OpenXML4JTestDataSamples.openComplianceSampleStream("OPCCompliance_CoreProperties_OnlyOneCorePropertiesPart.docx"); >- Package pkg; >+ OPCPackage pkg; > try { >- pkg = Package.open(is); >+ pkg = OPCPackage.open(is); > } catch (InvalidFormatException e) { > throw new RuntimeException(e); > } catch (IOException e) { >@@ -145,9 +145,9 @@ > */ > public void testOnlyOneCorePropertiesPart_AddPart() { > String sampleFileName = OpenXML4JTestDataSamples.getComplianceSampleFileName("OPCCompliance_CoreProperties_OnlyOneCorePropertiesPart.docx"); >- Package pkg = null; >+ OPCPackage pkg = null; > try { >- pkg = Package.open(sampleFileName); >+ pkg = OPCPackage.open(sampleFileName); > } catch (InvalidFormatException e) { > throw new RuntimeException(e); > } >Index: src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCCompliancePackageModel.java >=================================================================== >--- src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCCompliancePackageModel.java (revision 754500) >+++ src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCCompliancePackageModel.java (working copy) >@@ -24,7 +24,7 @@ > import org.apache.poi.openxml4j.exceptions.InvalidFormatException; > import org.apache.poi.openxml4j.exceptions.InvalidOperationException; > import org.apache.poi.openxml4j.opc.ContentTypes; >-import org.apache.poi.openxml4j.opc.Package; >+import org.apache.poi.openxml4j.opc.OPCPackage; > import org.apache.poi.openxml4j.opc.PackagePartName; > import org.apache.poi.openxml4j.opc.PackageRelationshipTypes; > import org.apache.poi.openxml4j.opc.PackagingURIHelper; >@@ -50,7 +50,7 @@ > * [M1.11] > */ > public void testPartNameDerivationAdditionFailure() { >- Package pkg = Package.create("TODELETEIFEXIST.docx"); >+ OPCPackage pkg = OPCPackage.create("TODELETEIFEXIST.docx"); > try { > PackagePartName name = PackagingURIHelper > .createPartName("/word/document.xml"); >@@ -78,7 +78,7 @@ > String filepath = System.getProperty("openxml4j.compliance.input") > + File.separator + "OPCCompliance_DerivedPartNameFAIL.docx"; > try { >- Package.open(filepath); >+ OPCPackage.open(filepath); > } catch (InvalidFormatException e) { > return; > } >@@ -93,7 +93,7 @@ > * part names. > */ > public void testAddPackageAlreadyAddFailure() throws Exception { >- Package pkg = Package.create("DELETEIFEXISTS.docx"); >+ OPCPackage pkg = OPCPackage.create("DELETEIFEXISTS.docx"); > PackagePartName name1 = null; > PackagePartName name2 = null; > try { >@@ -117,7 +117,7 @@ > * part names. > */ > public void testAddPackageAlreadyAddFailure2() throws Exception { >- Package pkg = Package.create("DELETEIFEXISTS.docx"); >+ OPCPackage pkg = OPCPackage.create("DELETEIFEXISTS.docx"); > PackagePartName partName = null; > try { > partName = PackagingURIHelper.createPartName("/word/document.xml"); >@@ -142,7 +142,7 @@ > * relationship as invalid. > */ > public void testAddRelationshipRelationshipsPartFailure() { >- Package pkg = Package.create("DELETEIFEXISTS.docx"); >+ OPCPackage pkg = OPCPackage.create("DELETEIFEXISTS.docx"); > PackagePartName name1 = null; > try { > name1 = PackagingURIHelper >Index: src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackage.java >=================================================================== >--- src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackage.java (revision 754500) >+++ src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackage.java (working copy) >@@ -51,7 +51,7 @@ > String originalFile = OpenXML4JTestDataSamples.getSampleFileName("TestPackageCommon.docx"); > File targetFile = OpenXML4JTestDataSamples.getOutputFile("TestPackageOpenSaveTMP.docx"); > >- Package p = Package.open(originalFile, PackageAccess.READ_WRITE); >+ OPCPackage p = OPCPackage.open(originalFile, PackageAccess.READ_WRITE); > p.save(targetFile.getAbsoluteFile()); > > // Compare the original and newly saved document >@@ -70,7 +70,7 @@ > // Zap the target file, in case of an earlier run > if(targetFile.exists()) targetFile.delete(); > >- Package pkg = Package.create(targetFile); >+ OPCPackage pkg = OPCPackage.create(targetFile); > > // Check it has content types for rels and xml > ContentTypeManager ctm = getContentTypeManager(pkg); >@@ -105,7 +105,7 @@ > if(targetFile.exists()) targetFile.delete(); > > // Create a package >- Package pkg = Package.create(targetFile); >+ OPCPackage pkg = OPCPackage.create(targetFile); > PackagePartName corePartName = PackagingURIHelper > .createPartName("/word/document.xml"); > >@@ -145,7 +145,7 @@ > */ > public void testCreatePackageWithCoreDocument() throws Exception { > ByteArrayOutputStream baos = new ByteArrayOutputStream(); >- Package pkg = Package.create(baos); >+ OPCPackage pkg = OPCPackage.create(baos); > > // Add a core document > PackagePartName corePartName = PackagingURIHelper.createPartName("/xl/workbook.xml"); >@@ -184,7 +184,7 @@ > FileOutputStream fout = new FileOutputStream(File.createTempFile("testCreatePackageWithCoreDocument", ".zip")); > fout.write(baos.toByteArray()); > fout.close(); >- pkg = Package.open(new ByteArrayInputStream(baos.toByteArray())); >+ pkg = OPCPackage.open(new ByteArrayInputStream(baos.toByteArray())); > > > // Check still right >@@ -210,7 +210,7 @@ > FileHelper.copyFile(inputFile, targetFile); > > // Create a package >- Package pkg = Package.open(targetFile.getAbsolutePath()); >+ OPCPackage pkg = OPCPackage.open(targetFile.getAbsolutePath()); > > // Modify core part > PackagePartName corePartName = PackagingURIHelper >@@ -263,7 +263,7 @@ > String originalFile = OpenXML4JTestDataSamples.getSampleFileName("TestPackageCommon.docx"); > File targetFile = OpenXML4JTestDataSamples.getOutputFile("TestPackageOpenSaveTMP.docx"); > >- Package p = Package.open(originalFile, PackageAccess.READ_WRITE); >+ OPCPackage p = OPCPackage.open(originalFile, PackageAccess.READ_WRITE); > FileOutputStream fout = new FileOutputStream(targetFile); > p.save(fout); > fout.close(); >@@ -284,7 +284,7 @@ > > FileInputStream finp = new FileInputStream(originalFile); > >- Package p = Package.open(finp); >+ OPCPackage p = OPCPackage.open(finp); > > assertNotNull(p); > assertNotNull(p.getRelationships()); >@@ -303,7 +303,7 @@ > File targetFile = OpenXML4JTestDataSamples.getOutputFile("TestPackageRemovePartRecursiveOUTPUT.docx"); > File tempFile = OpenXML4JTestDataSamples.getOutputFile("TestPackageRemovePartRecursiveTMP.docx"); > >- Package p = Package.open(originalFile, PackageAccess.READ_WRITE); >+ OPCPackage p = OPCPackage.open(originalFile, PackageAccess.READ_WRITE); > p.removePartRecursive(PackagingURIHelper.createPartName(new URI( > "/word/document.xml"))); > p.save(tempFile.getAbsoluteFile()); >@@ -353,7 +353,7 @@ > > String filepath = OpenXML4JTestDataSamples.getSampleFileName("sample.docx"); > >- Package p = Package.open(filepath, PackageAccess.READ_WRITE); >+ OPCPackage p = OPCPackage.open(filepath, PackageAccess.READ_WRITE); > // Remove the core part > p.deletePart(PackagingURIHelper.createPartName("/word/document.xml")); > >@@ -391,7 +391,7 @@ > > String filepath = OpenXML4JTestDataSamples.getSampleFileName("sample.docx"); > >- Package p = Package.open(filepath, PackageAccess.READ_WRITE); >+ OPCPackage p = OPCPackage.open(filepath, PackageAccess.READ_WRITE); > // Remove the core part > p.deletePartRecursive(PackagingURIHelper.createPartName("/word/document.xml")); > >@@ -409,8 +409,8 @@ > p.revert(); > } > >- private static ContentTypeManager getContentTypeManager(Package pkg) throws Exception { >- Field f = Package.class.getDeclaredField("contentTypeManager"); >+ private static ContentTypeManager getContentTypeManager(OPCPackage pkg) throws Exception { >+ Field f = OPCPackage.class.getDeclaredField("contentTypeManager"); > f.setAccessible(true); > return (ContentTypeManager)f.get(pkg); > } >Index: src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDrawing.java >=================================================================== >--- src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDrawing.java (revision 754500) >+++ src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDrawing.java (working copy) >@@ -16,12 +16,14 @@ > ==================================================================== */ > package org.apache.poi.xssf.usermodel; > >+import java.util.List; >+ > import junit.framework.TestCase; >+ >+import org.apache.poi.POIXMLDocumentPart; >+import org.apache.poi.openxml4j.opc.OPCPackage; > import org.apache.poi.xssf.XSSFTestDataSamples; >-import org.apache.poi.POIXMLDocumentPart; > >-import java.util.List; >- > /** > * @author Yegor Kozlov > */ >@@ -71,7 +73,7 @@ > XSSFSheet sheet = wb.createSheet(); > XSSFDrawing drawing = sheet.createDrawingPatriarch(); > } >- org.apache.poi.openxml4j.opc.Package pkg = wb.getPackage(); >+ OPCPackage pkg = wb.getPackage(); > assertEquals(3, pkg.getPartsByContentType(XSSFRelation.DRAWINGS.getContentType()).size()); > } > } >Index: src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java >=================================================================== >--- src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java (revision 754500) >+++ src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java (working copy) >@@ -29,7 +29,7 @@ > import org.apache.poi.xssf.XSSFTestDataSamples; > import org.apache.poi.xssf.model.StylesTable; > import org.apache.poi.openxml4j.opc.ContentTypes; >-import org.apache.poi.openxml4j.opc.Package; >+import org.apache.poi.openxml4j.opc.OPCPackage; > import org.apache.poi.openxml4j.opc.PackagePart; > import org.apache.poi.openxml4j.opc.PackagingURIHelper; > import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheet; >@@ -251,7 +251,7 @@ > out.close(); > > // Check the package contains what we'd expect it to >- Package pkg = Package.open(file.toString()); >+ OPCPackage pkg = OPCPackage.open(file.toString()); > PackagePart wbRelPart = > pkg.getPart(PackagingURIHelper.createPartName("/xl/_rels/workbook.xml.rels")); > assertNotNull(wbRelPart); >@@ -293,7 +293,7 @@ > assertNotNull(workbook.getStylesSource()); > > // And check a few low level bits too >- Package pkg = Package.open(HSSFTestDataSamples.openSampleFileStream("Formatting.xlsx")); >+ OPCPackage pkg = OPCPackage.open(HSSFTestDataSamples.openSampleFileStream("Formatting.xlsx")); > PackagePart wbPart = > pkg.getPart(PackagingURIHelper.createPartName("/xl/workbook.xml")); > >Index: src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java >=================================================================== >--- src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java (revision 754500) >+++ src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java (working copy) >@@ -21,7 +21,8 @@ > > import junit.framework.TestCase; > >-import org.apache.poi.openxml4j.opc.Package; >+import org.apache.poi.openxml4j.opc.OPCPackage; >+import org.apache.poi.openxml4j.opc.OPCPackage; > import org.apache.poi.openxml4j.opc.PackagePart; > import org.apache.poi.openxml4j.opc.PackagingURIHelper; > import org.apache.poi.xssf.XSSFTestDataSamples; >@@ -71,7 +72,7 @@ > * We should carry vba macros over after save > */ > public void test45431() throws Exception { >- Package pkg = Package.open(getFilePath("45431.xlsm")); >+ OPCPackage pkg = OPCPackage.open(getFilePath("45431.xlsm")); > XSSFWorkbook wb = new XSSFWorkbook(pkg); > assertTrue(wb.isMacroEnabled()); > >@@ -89,7 +90,7 @@ > > // Save and re-open, both still there > XSSFWorkbook nwb = XSSFTestDataSamples.writeOutAndReadBack(wb); >- Package nPkg = nwb.getPackage(); >+ OPCPackage nPkg = nwb.getPackage(); > assertTrue(nwb.isMacroEnabled()); > > vba = nPkg.getPart( >Index: src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestFormulaEvaluatorOnXSSF.java >=================================================================== >--- src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestFormulaEvaluatorOnXSSF.java (revision 754500) >+++ src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestFormulaEvaluatorOnXSSF.java (working copy) >@@ -32,7 +32,7 @@ > import org.apache.poi.ss.usermodel.FormulaEvaluator; > import org.apache.poi.ss.usermodel.Row; > import org.apache.poi.ss.usermodel.Sheet; >-import org.apache.poi.openxml4j.opc.Package; >+import org.apache.poi.openxml4j.opc.OPCPackage; > > /** > * Performs much the same role as {@link TestFormulasFromSpreadsheet}, >@@ -149,7 +149,7 @@ > protected void setUp() throws Exception { > if (workbook == null) { > InputStream is = HSSFTestDataSamples.openSampleFileStream(SS.FILENAME); >- Package pkg = Package.open(is); >+ OPCPackage pkg = OPCPackage.open(is); > workbook = new XSSFWorkbook( pkg ); > sheet = workbook.getSheetAt( 0 ); > } >Index: src/ooxml/testcases/org/apache/poi/xssf/model/TestCommentsTable.java >=================================================================== >--- src/ooxml/testcases/org/apache/poi/xssf/model/TestCommentsTable.java (revision 754500) >+++ src/ooxml/testcases/org/apache/poi/xssf/model/TestCommentsTable.java (working copy) >@@ -32,7 +32,7 @@ > import org.apache.poi.xssf.usermodel.XSSFWorkbook; > import org.apache.poi.xssf.XSSFTestDataSamples; > import org.apache.poi.POIXMLDocumentPart; >-import org.apache.poi.openxml4j.opc.Package; >+import org.apache.poi.openxml4j.opc.OPCPackage; > import org.openxmlformats.schemas.spreadsheetml.x2006.main.*; > > import junit.framework.TestCase; >@@ -125,7 +125,7 @@ > ); > assertTrue(xml.exists()); > >- Package pkg = Package.open(xml.toString()); >+ OPCPackage pkg = OPCPackage.open(xml.toString()); > XSSFWorkbook wb = new XSSFWorkbook(pkg); > List<POIXMLDocumentPart> rels = wb.getSheetAt(0).getRelations(); > CommentsTable ct = null; >Index: src/ooxml/testcases/org/apache/poi/xssf/eventusermodel/TestXSSFReader.java >=================================================================== >--- src/ooxml/testcases/org/apache/poi/xssf/eventusermodel/TestXSSFReader.java (revision 754500) >+++ src/ooxml/testcases/org/apache/poi/xssf/eventusermodel/TestXSSFReader.java (working copy) >@@ -25,7 +25,7 @@ > > import org.apache.poi.util.IOUtils; > import org.apache.poi.xssf.usermodel.XSSFRichTextString; >-import org.apache.poi.openxml4j.opc.Package; >+import org.apache.poi.openxml4j.opc.OPCPackage; > > /** > * Tests for XSSFReader >@@ -49,7 +49,7 @@ > > public void testGetBits() throws Exception { > File f = new File(dirName, "SampleSS.xlsx"); >- Package pkg = Package.open(f.toString()); >+ OPCPackage pkg = OPCPackage.open(f.toString()); > > XSSFReader r = new XSSFReader(pkg); > >@@ -63,7 +63,7 @@ > > public void testStyles() throws Exception { > File f = new File(dirName, "SampleSS.xlsx"); >- Package pkg = Package.open(f.toString()); >+ OPCPackage pkg = OPCPackage.open(f.toString()); > > XSSFReader r = new XSSFReader(pkg); > >@@ -73,7 +73,7 @@ > > public void testStrings() throws Exception { > File f = new File(dirName, "SampleSS.xlsx"); >- Package pkg = Package.open(f.toString()); >+ OPCPackage pkg = OPCPackage.open(f.toString()); > > XSSFReader r = new XSSFReader(pkg); > >@@ -83,7 +83,7 @@ > > public void testSheets() throws Exception { > File f = new File(dirName, "SampleSS.xlsx"); >- Package pkg = Package.open(f.toString()); >+ OPCPackage pkg = OPCPackage.open(f.toString()); > > XSSFReader r = new XSSFReader(pkg); > byte[] data = new byte[4096]; >@@ -116,7 +116,7 @@ > */ > public void testOrderOfSheets() throws Exception { > File f = new File(dirName, "reordered_sheets.xlsx"); >- Package pkg = Package.open(f.toString()); >+ OPCPackage pkg = OPCPackage.open(f.toString()); > > XSSFReader r = new XSSFReader(pkg); > >Index: src/ooxml/testcases/org/apache/poi/xssf/XSSFTestDataSamples.java >=================================================================== >--- src/ooxml/testcases/org/apache/poi/xssf/XSSFTestDataSamples.java (revision 754500) >+++ src/ooxml/testcases/org/apache/poi/xssf/XSSFTestDataSamples.java (working copy) >@@ -17,14 +17,19 @@ > > package org.apache.poi.xssf; > >-import java.io.*; >+import java.io.ByteArrayInputStream; >+import java.io.ByteArrayOutputStream; >+import java.io.File; >+import java.io.FileOutputStream; >+import java.io.IOException; >+import java.io.InputStream; > > import org.apache.poi.hssf.HSSFTestDataSamples; > import org.apache.poi.hssf.usermodel.HSSFWorkbook; >+import org.apache.poi.openxml4j.exceptions.InvalidFormatException; >+import org.apache.poi.openxml4j.opc.OPCPackage; > import org.apache.poi.ss.usermodel.Workbook; > import org.apache.poi.xssf.usermodel.XSSFWorkbook; >-import org.apache.poi.openxml4j.exceptions.InvalidFormatException; >-import org.apache.poi.openxml4j.opc.Package; > > /** > * Centralises logic for finding/opening sample files in the src/testcases/org/apache/poi/hssf/hssf/data folder. >@@ -35,7 +40,7 @@ > public static final XSSFWorkbook openSampleWorkbook(String sampleName) { > InputStream is = HSSFTestDataSamples.openSampleFileStream(sampleName); > try { >- Package pkg = Package.open(is); >+ OPCPackage pkg = OPCPackage.open(is); > return new XSSFWorkbook(pkg); > } catch (InvalidFormatException e) { > throw new RuntimeException(e); >@@ -57,7 +62,7 @@ > FileOutputStream out = new FileOutputStream(tmp); > wb.write(out); > out.close(); >- Package pkg = Package.open(tmp.getAbsolutePath()); >+ OPCPackage pkg = OPCPackage.open(tmp.getAbsolutePath()); > result = new XSSFWorkbook(pkg); > } else { > throw new RuntimeException("Unexpected workbook type (" >Index: src/ooxml/testcases/org/apache/poi/xwpf/TestXWPFDocument.java >=================================================================== >--- src/ooxml/testcases/org/apache/poi/xwpf/TestXWPFDocument.java (revision 754500) >+++ src/ooxml/testcases/org/apache/poi/xwpf/TestXWPFDocument.java (working copy) >@@ -18,14 +18,14 @@ > > import java.io.File; > >+import junit.framework.TestCase; >+ > import org.apache.poi.POIXMLDocument; >+import org.apache.poi.openxml4j.opc.OPCPackage; >+import org.apache.poi.openxml4j.opc.PackagePart; > import org.apache.poi.xwpf.usermodel.XWPFDocument; > import org.apache.poi.xwpf.usermodel.XWPFRelation; >-import org.apache.poi.openxml4j.opc.Package; >-import org.apache.poi.openxml4j.opc.PackagePart; > >-import junit.framework.TestCase; >- > public class TestXWPFDocument extends TestCase { > private File sampleFile; > private File complexFile; >@@ -47,7 +47,7 @@ > } > > public void testContainsMainContentType() throws Exception { >- Package pack = POIXMLDocument.openPackage(sampleFile.toString()); >+ OPCPackage pack = POIXMLDocument.openPackage(sampleFile.toString()); > > boolean found = false; > for(PackagePart part : pack.getParts()) { >Index: src/ooxml/testcases/org/apache/poi/ss/TestWorkbookFactory.java >=================================================================== >--- src/ooxml/testcases/org/apache/poi/ss/TestWorkbookFactory.java (revision 754500) >+++ src/ooxml/testcases/org/apache/poi/ss/TestWorkbookFactory.java (working copy) >@@ -24,7 +24,7 @@ > import org.apache.poi.ss.usermodel.Workbook; > import org.apache.poi.ss.usermodel.WorkbookFactory; > import org.apache.poi.xssf.usermodel.XSSFWorkbook; >-import org.apache.poi.openxml4j.opc.Package; >+import org.apache.poi.openxml4j.opc.OPCPackage; > > import junit.framework.TestCase; > >@@ -63,7 +63,7 @@ > > // Package -> xssf > wb = WorkbookFactory.create( >- Package.open(xlsx.toString()) >+ OPCPackage.open(xlsx.toString()) > ); > assertNotNull(wb); > assertTrue(wb instanceof XSSFWorkbook); >Index: src/ooxml/testcases/org/apache/poi/TestEmbeded.java >=================================================================== >--- src/ooxml/testcases/org/apache/poi/TestEmbeded.java (revision 754500) >+++ src/ooxml/testcases/org/apache/poi/TestEmbeded.java (working copy) >@@ -25,7 +25,7 @@ > import org.apache.poi.xslf.XSLFSlideShow; > import org.apache.poi.xssf.usermodel.XSSFWorkbook; > import org.apache.poi.xwpf.usermodel.XWPFDocument; >-import org.apache.poi.openxml4j.opc.Package; >+import org.apache.poi.openxml4j.opc.OPCPackage; > import org.apache.poi.openxml4j.opc.PackagePart; > > import junit.framework.TestCase; >@@ -47,7 +47,7 @@ > File f = new File(dirname, "ExcelWithAttachments.xlsx"); > assertTrue(f.exists()); > >- POIXMLDocument doc = new XSSFWorkbook(Package.open(f.toString())); >+ POIXMLDocument doc = new XSSFWorkbook(OPCPackage.open(f.toString())); > test(doc, 4); > } > >@@ -55,7 +55,7 @@ > File f = new File(dirname, "WordWithAttachments.docx"); > assertTrue(f.exists()); > >- POIXMLDocument doc = new XWPFDocument(Package.open(f.toString())); >+ POIXMLDocument doc = new XWPFDocument(OPCPackage.open(f.toString())); > test(doc, 5); > } > >@@ -63,7 +63,7 @@ > File f = new File(dirname, "PPTWithAttachments.pptx"); > assertTrue(f.exists()); > >- POIXMLDocument doc = new XSLFSlideShow(Package.open(f.toString())); >+ POIXMLDocument doc = new XSLFSlideShow(OPCPackage.open(f.toString())); > test(doc, 4); > } > >Index: src/ooxml/testcases/org/apache/poi/extractor/TestExtractorFactory.java >=================================================================== >--- src/ooxml/testcases/org/apache/poi/extractor/TestExtractorFactory.java (revision 754500) >+++ src/ooxml/testcases/org/apache/poi/extractor/TestExtractorFactory.java (working copy) >@@ -34,7 +34,7 @@ > import junit.framework.TestCase; > > import org.apache.poi.openxml4j.exceptions.InvalidOperationException; >-import org.apache.poi.openxml4j.opc.Package; >+import org.apache.poi.openxml4j.opc.OPCPackage; > > /** > * Test that the extractor factory plays nicely >@@ -276,34 +276,34 @@ > public void testPackage() throws Exception { > // Excel > assertTrue( >- ExtractorFactory.createExtractor(Package.open(xlsx.toString())) >+ ExtractorFactory.createExtractor(OPCPackage.open(xlsx.toString())) > instanceof XSSFExcelExtractor > ); > assertTrue( >- ExtractorFactory.createExtractor(Package.open(xlsx.toString())).getText().length() > 200 >+ ExtractorFactory.createExtractor(OPCPackage.open(xlsx.toString())).getText().length() > 200 > ); > > // Word > assertTrue( >- ExtractorFactory.createExtractor(Package.open(docx.toString())) >+ ExtractorFactory.createExtractor(OPCPackage.open(docx.toString())) > instanceof XWPFWordExtractor > ); > assertTrue( >- ExtractorFactory.createExtractor(Package.open(docx.toString())).getText().length() > 120 >+ ExtractorFactory.createExtractor(OPCPackage.open(docx.toString())).getText().length() > 120 > ); > > // PowerPoint > assertTrue( >- ExtractorFactory.createExtractor(Package.open(pptx.toString())) >+ ExtractorFactory.createExtractor(OPCPackage.open(pptx.toString())) > instanceof XSLFPowerPointExtractor > ); > assertTrue( >- ExtractorFactory.createExtractor(Package.open(pptx.toString())).getText().length() > 120 >+ ExtractorFactory.createExtractor(OPCPackage.open(pptx.toString())).getText().length() > 120 > ); > > // Text > try { >- ExtractorFactory.createExtractor(Package.open(txt.toString())); >+ ExtractorFactory.createExtractor(OPCPackage.open(txt.toString())); > fail(); > } catch(InvalidOperationException e) { > // Good >Index: src/ooxml/testcases/org/apache/poi/xslf/TestXSLFSlideShow.java >=================================================================== >--- src/ooxml/testcases/org/apache/poi/xslf/TestXSLFSlideShow.java (revision 754500) >+++ src/ooxml/testcases/org/apache/poi/xslf/TestXSLFSlideShow.java (working copy) >@@ -18,14 +18,14 @@ > > import java.io.File; > >+import junit.framework.TestCase; >+ > import org.apache.poi.POIXMLDocument; >-import org.apache.poi.openxml4j.opc.Package; >+import org.apache.poi.openxml4j.opc.OPCPackage; > import org.apache.poi.openxml4j.opc.PackagePart; > import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideIdListEntry; > import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideMasterIdListEntry; > >-import junit.framework.TestCase; >- > public class TestXSLFSlideShow extends TestCase { > private String sampleFile; > >@@ -39,7 +39,7 @@ > } > > public void testContainsMainContentType() throws Exception { >- Package pack = POIXMLDocument.openPackage(sampleFile); >+ OPCPackage pack = POIXMLDocument.openPackage(sampleFile); > > boolean found = false; > for(PackagePart part : pack.getParts()) { >Index: src/ooxml/testcases/org/apache/poi/TestXMLPropertiesTextExtractor.java >=================================================================== >--- src/ooxml/testcases/org/apache/poi/TestXMLPropertiesTextExtractor.java (revision 754500) >+++ src/ooxml/testcases/org/apache/poi/TestXMLPropertiesTextExtractor.java (working copy) >@@ -20,7 +20,7 @@ > > import org.apache.poi.xssf.extractor.XSSFExcelExtractor; > import org.apache.poi.xssf.usermodel.XSSFWorkbook; >-import org.apache.poi.openxml4j.opc.Package; >+import org.apache.poi.openxml4j.opc.OPCPackage; > > import junit.framework.TestCase; > >@@ -33,7 +33,7 @@ > } > > public void testGetFromMainExtractor() throws Exception { >- org.apache.poi.openxml4j.opc.Package pkg = Package.open( >+ OPCPackage pkg = OPCPackage.open( > (new File(dirname, "ExcelWithAttachments.xlsx")).toString() > ); > XSSFWorkbook wb = new XSSFWorkbook(pkg); >@@ -54,7 +54,7 @@ > } > > public void testCore() throws Exception { >- org.apache.poi.openxml4j.opc.Package pkg = Package.open( >+ OPCPackage pkg = OPCPackage.open( > (new File(dirname, "ExcelWithAttachments.xlsx")).toString() > ); > XSSFWorkbook wb = new XSSFWorkbook(pkg); >@@ -71,7 +71,7 @@ > } > > public void testExtended() throws Exception { >- org.apache.poi.openxml4j.opc.Package pkg = Package.open( >+ OPCPackage pkg = OPCPackage.open( > (new File(dirname, "ExcelWithAttachments.xlsx")).toString() > ); > XSSFWorkbook wb = new XSSFWorkbook(pkg); >Index: src/examples/src/org/apache/poi/xssf/eventusermodel/examples/FromHowTo.java >=================================================================== >--- src/examples/src/org/apache/poi/xssf/eventusermodel/examples/FromHowTo.java (revision 754500) >+++ src/examples/src/org/apache/poi/xssf/eventusermodel/examples/FromHowTo.java (working copy) >@@ -22,7 +22,7 @@ > import org.apache.poi.xssf.eventusermodel.XSSFReader; > import org.apache.poi.xssf.model.SharedStringsTable; > import org.apache.poi.xssf.usermodel.XSSFRichTextString; >-import org.apache.poi.openxml4j.opc.Package; >+import org.apache.poi.openxml4j.opc.OPCPackage; > import org.xml.sax.Attributes; > import org.xml.sax.ContentHandler; > import org.xml.sax.InputSource; >@@ -36,7 +36,7 @@ > */ > public class FromHowTo { > public void processOneSheet(String filename) throws Exception { >- Package pkg = Package.open(filename); >+ OPCPackage pkg = OPCPackage.open(filename); > XSSFReader r = new XSSFReader( pkg ); > SharedStringsTable sst = r.getSharedStringsTable(); > >@@ -51,7 +51,7 @@ > } > > public void processAllSheets(String filename) throws Exception { >- Package pkg = Package.open(filename); >+ OPCPackage pkg = OPCPackage.open(filename); > XSSFReader r = new XSSFReader( pkg ); > SharedStringsTable sst = r.getSharedStringsTable(); >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 46859
: 23386