Reduce duplication by replacing lots of deprecated methods with calls to their replacement (which is basically the same code anyway)

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1540878 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Nick Burch 2013-11-11 23:08:36 +00:00
parent 0457300fdf
commit 6780a911e2

View File

@ -21,29 +21,14 @@ import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Date;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.openxml4j.exceptions.InvalidOperationException;
import org.apache.poi.openxml4j.opc.internal.PackagePropertiesPart;
import org.apache.poi.openxml4j.opc.internal.ZipContentTypeManager;
import org.apache.poi.openxml4j.util.Nullable;
/**
* @deprecated (name clash with {@link java.lang.Package} use {@link OPCPackage} instead.
*
* @author Julien Chable, CDubet
*
*/
@Deprecated
public abstract class Package extends OPCPackage {
/**
* Logger.
*/
//private static POILogger logger = POILogFactory.getLogger(Package.class);
/**
* @deprecated use {@link OPCPackage}
*/
@ -52,7 +37,6 @@ public abstract class Package extends OPCPackage {
super(access);
}
/**
* @deprecated use {@link OPCPackage#open(String)}
*/
@ -67,16 +51,7 @@ public abstract class Package extends OPCPackage {
@Deprecated
public static Package 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");
Package pack = new ZipPackage(path, access);
if (pack.partList == null && access != PackageAccess.WRITE) {
pack.getParts();
}
pack.originalPackagePath = new File(path).getAbsolutePath();
return pack;
return (Package)OPCPackage.open(path, access);
}
/**
@ -85,11 +60,7 @@ public abstract class Package extends OPCPackage {
@Deprecated
public static Package open(InputStream in) throws InvalidFormatException,
IOException {
Package pack = new ZipPackage(in, PackageAccess.READ);
if (pack.partList == null) {
pack.getParts();
}
return pack;
return (Package)OPCPackage.open(in);
}
/**
@ -97,13 +68,7 @@ public abstract class Package extends OPCPackage {
*/
@Deprecated
public static Package openOrCreate(File file) throws InvalidFormatException {
Package retPackage = null;
if (file.exists()) {
retPackage = open(file.getAbsolutePath());
} else {
retPackage = create(file);
}
return retPackage;
return (Package)OPCPackage.openOrCreate(file);
}
/**
@ -111,7 +76,7 @@ public abstract class Package extends OPCPackage {
*/
@Deprecated
public static Package create(String path) {
return create(new File(path));
return (Package)OPCPackage.create(path);
}
/**
@ -119,21 +84,7 @@ public abstract class Package extends OPCPackage {
*/
@Deprecated
public static Package 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
Package pkg = null;
pkg = new ZipPackage();
pkg.originalPackagePath = file.getAbsolutePath();
configurePackage(pkg);
return pkg;
return (Package)OPCPackage.create(file);
}
/**
@ -141,46 +92,6 @@ public abstract class Package extends OPCPackage {
*/
@Deprecated
public static Package create(OutputStream output) {
Package pkg = null;
pkg = new ZipPackage();
pkg.originalPackagePath = null;
pkg.output = output;
configurePackage(pkg);
return pkg;
return (Package)OPCPackage.create(output);
}
/**
* Configure the package.
*
* @param pkg
*/
private static void configurePackage(Package 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 Package 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);
}
}
}