poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n...@apache.org
Subject svn commit: r1351894 - in /poi/trunk/src: documentation/content/xdocs/ ooxml/java/org/apache/poi/openxml4j/opc/ ooxml/java/org/apache/poi/openxml4j/opc/internal/ ooxml/java/org/apache/poi/ss/usermodel/
Date Tue, 19 Jun 2012 22:50:14 GMT
Author: nick
Date: Tue Jun 19 22:50:14 2012
New Revision: 1351894

URL: http://svn.apache.org/viewvc?rev=1351894&view=rev
Log:
Add File based constructor to OPCPackage, alongside existing String one (which constructed
a File from the string internally)

Modified:
    poi/trunk/src/documentation/content/xdocs/status.xml
    poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/OPCPackage.java
    poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java
    poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/ZipHelper.java
    poi/trunk/src/ooxml/java/org/apache/poi/ss/usermodel/WorkbookFactory.java

Modified: poi/trunk/src/documentation/content/xdocs/status.xml
URL: http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/status.xml?rev=1351894&r1=1351893&r2=1351894&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/status.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/status.xml Tue Jun 19 22:50:14 2012
@@ -34,6 +34,7 @@
 
     <changes>
         <release version="3.9-beta1" date="2012-??-??">
+          <action dev="poi-developers" type="add">Add File based constructor to OPCPackage,
alongside existing String one (which constructed a File from the string internally)</action>
           <action dev="poi-developers" type="fix">53389 - Handle formatting General
and @ formats even if a locale is prefixed to them</action>
           <action dev="poi-developers" type="fix">53271 - Removed unconditional asserts
in SXSSF</action>
           <action dev="poi-developers" type="add">53025 - Updatad documentation and
example on using Data Validations  </action>

Modified: poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/OPCPackage.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/OPCPackage.java?rev=1351894&r1=1351893&r2=1351894&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/OPCPackage.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/OPCPackage.java Tue Jun 19 22:50:14
2012
@@ -186,6 +186,20 @@ public abstract class OPCPackage impleme
 		return open(path, defaultPackageAccess);
 	}
 
+   /**
+    * Open a package with read/write permission.
+    *
+    * @param file
+    *            The file to open.
+    * @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(File file) throws InvalidFormatException {
+      return open(file, defaultPackageAccess);
+   }
+
 	/**
 	 * Open a package.
 	 *
@@ -212,6 +226,31 @@ public abstract class OPCPackage impleme
 		return pack;
 	}
 
+   /**
+    * Open a package.
+    *
+    * @param file
+    *            The file to open.
+    * @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(File file, PackageAccess access)
+         throws InvalidFormatException {
+      if (file == null|| (file.exists() && file.isDirectory()))
+         throw new IllegalArgumentException("file");
+
+      OPCPackage pack = new ZipPackage(file, access);
+      if (pack.partList == null && access != PackageAccess.WRITE) {
+         pack.getParts();
+      }
+      pack.originalPackagePath = file.getAbsolutePath();
+      return pack;
+   }
+
 	/**
 	 * Open a package.
 	 *

Modified: poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java?rev=1351894&r1=1351893&r2=1351894&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java Tue Jun 19 22:50:14
2012
@@ -85,30 +85,55 @@ public final class ZipPackage extends Pa
 		);
 	}
 
-	/**
-	 * Constructor. Opens a Zip based Open XML document.
-	 *
-	 * @param path
-	 *            The path of the file to open or create.
-	 * @param access
-	 *            The package access mode.
-	 * @throws InvalidFormatException
-	 *             If the content type part parsing encounters an error.
-	 */
-	ZipPackage(String path, PackageAccess access) {
-		super(access);
+   /**
+    * Constructor. Opens a Zip based Open XML document.
+    *
+    * @param path
+    *            The path of the file to open or create.
+    * @param access
+    *            The package access mode.
+    * @throws InvalidFormatException
+    *             If the content type part parsing encounters an error.
+    */
+   ZipPackage(String path, PackageAccess access) {
+      super(access);
+
+      ZipFile zipFile = null;
+
+      try {
+         zipFile = ZipHelper.openZipFile(path);
+      } catch (IOException e) {
+         throw new InvalidOperationException(
+               "Can't open the specified file: '" + path + "'", e);
+      }
+
+      this.zipArchive = new ZipFileZipEntrySource(zipFile);
+   }
+
+   /**
+    * Constructor. Opens a Zip based Open XML document.
+    *
+    * @param file
+    *            The file to open or create.
+    * @param access
+    *            The package access mode.
+    * @throws InvalidFormatException
+    *             If the content type part parsing encounters an error.
+    */
+   ZipPackage(File file, PackageAccess access) {
+      super(access);
+
+      ZipFile zipFile = null;
+
+      try {
+         zipFile = ZipHelper.openZipFile(file);
+      } catch (IOException e) {
+         throw new InvalidOperationException(
+               "Can't open the specified file: '" + file + "'", e);
+      }
 
-        ZipFile zipFile = null;
-
-        try {
-            zipFile = ZipHelper.openZipFile(path);
-        } catch (IOException e) {
-            throw new InvalidOperationException(
-         					"Can't open the specified file: '" + path + "'", e);
-        }
-
-		this.zipArchive = new ZipFileZipEntrySource(zipFile);
-	}
+      this.zipArchive = new ZipFileZipEntrySource(zipFile);
+   }
 
 	/**
 	 * Retrieves the parts from this package. We assume that the package has not

Modified: poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/ZipHelper.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/ZipHelper.java?rev=1351894&r1=1351893&r2=1351894&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/ZipHelper.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/ZipHelper.java Tue Jun
19 22:50:14 2012
@@ -72,11 +72,12 @@ public final class ZipHelper {
 	 * Retrieve the Zip entry of the content types part.
 	 */
 	public static ZipEntry getContentTypeZipEntry(ZipPackage pkg) {
-		Enumeration entries = pkg.getZipArchive().getEntries();
+		Enumeration<? extends ZipEntry> entries = pkg.getZipArchive().getEntries();
+		
 		// Enumerate through the Zip entries until we find the one named
 		// '[Content_Types].xml'.
 		while (entries.hasMoreElements()) {
-			ZipEntry entry = (ZipEntry) entries.nextElement();
+			ZipEntry entry = entries.nextElement();
 			if (entry.getName().equals(
 					ContentTypeManager.CONTENT_TYPES_PART_NAME))
 				return entry;
@@ -141,6 +142,21 @@ public final class ZipHelper {
 		}
 	}
 
+   /**
+    * Opens the specified file as a zip, or returns null if no such file exists
+    *
+    * @param file
+    *            The file to open.
+    * @return The zip archive freshly open.
+    */
+   public static ZipFile openZipFile(File file) throws IOException {
+      if (!file.exists()) {
+         return null;
+      }
+
+      return new ZipFile(file);
+   }
+
 	/**
 	 * Retrieve and open a zip file with the specified path.
 	 *

Modified: poi/trunk/src/ooxml/java/org/apache/poi/ss/usermodel/WorkbookFactory.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/ss/usermodel/WorkbookFactory.java?rev=1351894&r1=1351893&r2=1351894&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/ss/usermodel/WorkbookFactory.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/ss/usermodel/WorkbookFactory.java Tue Jun 19 22:50:14
2012
@@ -87,7 +87,7 @@ public class WorkbookFactory {
 	      NPOIFSFileSystem fs = new NPOIFSFileSystem(file);
 	      return new HSSFWorkbook(fs.getRoot(), true);
 	   } catch(OfficeXmlFileException e) {
-	      OPCPackage pkg = OPCPackage.openOrCreate(file);
+	      OPCPackage pkg = OPCPackage.open(file);
 	      return new XSSFWorkbook(pkg);
 	   }
 	}



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


Mime
View raw message