Author: nick
Date: Mon Nov 11 23:03:00 2013
New Revision: 1540877
URL: http://svn.apache.org/r1540877
Log:
Try to make a few OPCPackage error messages more helpful, and slightly reform
the configure code block to make it hopefully easier to read
Modified:
poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/OPCPackage.java
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=1540877&r1=1540876&r2=1540877&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 Mon
Nov 11 23:03:00 2013
@@ -52,8 +52,8 @@ import org.apache.poi.openxml4j.opc.inte
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.
@@ -214,9 +214,12 @@ public abstract class OPCPackage impleme
*/
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");
+ if (path == null || "".equals(path.trim()))
+ throw new IllegalArgumentException("'path' must be
given");
+
+ File file = new File(path);
+ if (file.exists() && file.isDirectory())
+ throw new IllegalArgumentException("path must not be a
directory");
OPCPackage pack = new ZipPackage(path, access);
if (pack.partList == null && access != PackageAccess.WRITE) {
@@ -240,8 +243,10 @@ public abstract class OPCPackage impleme
*/
public static OPCPackage open(File file, PackageAccess access)
throws InvalidFormatException {
- if (file == null|| (file.exists() && file.isDirectory()))
- throw new IllegalArgumentException("file");
+ if (file == null)
+ throw new IllegalArgumentException("'file' must be
given");
+ if (file == null || (file.exists() && file.isDirectory()))
+ throw new IllegalArgumentException("file must not be a
directory");
OPCPackage pack = new ZipPackage(file, access);
if (pack.partList == null && access != PackageAccess.WRITE) {
@@ -346,23 +351,21 @@ public abstract class OPCPackage impleme
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);
+ 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
+ // Initialise 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()));
+ pkg.packageProperties.setCreatorProperty("Generated by
Apache POI OpenXML4J");
+ pkg.packageProperties.setCreatedProperty(new
Nullable<Date>(new Date()));
} catch (InvalidFormatException e) {
// Should never happen
throw new IllegalStateException(e);
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]