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}
*/
super(access);
}
-
/**
* @deprecated use {@link OPCPackage#open(String)}
*/
@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);
}
/**
@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);
}
/**
*/
@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);
}
/**
*/
@Deprecated
public static Package create(String path) {
- return create(new File(path));
+ return (Package)OPCPackage.create(path);
}
/**
*/
@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);
}
/**
*/
@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);
- }
- }
-
-
}