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:
parent
0457300fdf
commit
6780a911e2
@ -21,29 +21,14 @@ import java.io.File;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
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.
|
* @deprecated (name clash with {@link java.lang.Package} use {@link OPCPackage} instead.
|
||||||
*
|
|
||||||
* @author Julien Chable, CDubet
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public abstract class Package extends OPCPackage {
|
public abstract class Package extends OPCPackage {
|
||||||
|
|
||||||
/**
|
|
||||||
* Logger.
|
|
||||||
*/
|
|
||||||
//private static POILogger logger = POILogFactory.getLogger(Package.class);
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated use {@link OPCPackage}
|
* @deprecated use {@link OPCPackage}
|
||||||
*/
|
*/
|
||||||
@ -52,7 +37,6 @@ public abstract class Package extends OPCPackage {
|
|||||||
super(access);
|
super(access);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated use {@link OPCPackage#open(String)}
|
* @deprecated use {@link OPCPackage#open(String)}
|
||||||
*/
|
*/
|
||||||
@ -67,16 +51,7 @@ public abstract class Package extends OPCPackage {
|
|||||||
@Deprecated
|
@Deprecated
|
||||||
public static Package open(String path, PackageAccess access)
|
public static Package open(String path, PackageAccess access)
|
||||||
throws InvalidFormatException {
|
throws InvalidFormatException {
|
||||||
if (path == null || "".equals(path.trim())
|
return (Package)OPCPackage.open(path, access);
|
||||||
|| (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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -85,11 +60,7 @@ public abstract class Package extends OPCPackage {
|
|||||||
@Deprecated
|
@Deprecated
|
||||||
public static Package open(InputStream in) throws InvalidFormatException,
|
public static Package open(InputStream in) throws InvalidFormatException,
|
||||||
IOException {
|
IOException {
|
||||||
Package pack = new ZipPackage(in, PackageAccess.READ);
|
return (Package)OPCPackage.open(in);
|
||||||
if (pack.partList == null) {
|
|
||||||
pack.getParts();
|
|
||||||
}
|
|
||||||
return pack;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -97,13 +68,7 @@ public abstract class Package extends OPCPackage {
|
|||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public static Package openOrCreate(File file) throws InvalidFormatException {
|
public static Package openOrCreate(File file) throws InvalidFormatException {
|
||||||
Package retPackage = null;
|
return (Package)OPCPackage.openOrCreate(file);
|
||||||
if (file.exists()) {
|
|
||||||
retPackage = open(file.getAbsolutePath());
|
|
||||||
} else {
|
|
||||||
retPackage = create(file);
|
|
||||||
}
|
|
||||||
return retPackage;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -111,7 +76,7 @@ public abstract class Package extends OPCPackage {
|
|||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public static Package create(String path) {
|
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
|
@Deprecated
|
||||||
public static Package create(File file) {
|
public static Package create(File file) {
|
||||||
if (file == null || (file.exists() && file.isDirectory()))
|
return (Package)OPCPackage.create(file);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -141,46 +92,6 @@ public abstract class Package extends OPCPackage {
|
|||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public static Package create(OutputStream output) {
|
public static Package create(OutputStream output) {
|
||||||
Package pkg = null;
|
return (Package)OPCPackage.create(output);
|
||||||
pkg = new ZipPackage();
|
|
||||||
pkg.originalPackagePath = null;
|
|
||||||
pkg.output = output;
|
|
||||||
|
|
||||||
configurePackage(pkg);
|
|
||||||
return pkg;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user