Renamed Package (in org.apache.poi.openxml4j.opc) to OPCPackage so as to avoid clash with java.lang.Package (see bugzilla 46859)

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@755699 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Josh Micich 2009-03-18 18:54:01 +00:00
parent 4f4ad37765
commit 67196db87e
48 changed files with 6569 additions and 6395 deletions

View File

@ -22,7 +22,7 @@ import java.util.Iterator;
import org.apache.poi.xssf.eventusermodel.XSSFReader;
import org.apache.poi.xssf.model.SharedStringsTable;
import org.apache.poi.xssf.usermodel.XSSFRichTextString;
import org.apache.poi.openxml4j.opc.Package;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
import org.xml.sax.InputSource;
@ -36,7 +36,7 @@ import org.xml.sax.helpers.XMLReaderFactory;
*/
public class FromHowTo {
public void processOneSheet(String filename) throws Exception {
Package pkg = Package.open(filename);
OPCPackage pkg = OPCPackage.open(filename);
XSSFReader r = new XSSFReader( pkg );
SharedStringsTable sst = r.getSharedStringsTable();
@ -51,7 +51,7 @@ public class FromHowTo {
}
public void processAllSheets(String filename) throws Exception {
Package pkg = Package.open(filename);
OPCPackage pkg = OPCPackage.open(filename);
XSSFReader r = new XSSFReader( pkg );
SharedStringsTable sst = r.getSharedStringsTable();

View File

@ -41,14 +41,14 @@ public abstract class POIXMLDocument extends POIXMLDocumentPart{
public static final String PACK_OBJECT_REL_TYPE="http://schemas.openxmlformats.org/officeDocument/2006/relationships/package";
/** The OPC Package */
private Package pkg;
private OPCPackage pkg;
/**
* The properties of the OPC package, opened as needed
*/
private POIXMLProperties properties;
protected POIXMLDocument(Package pkg) {
protected POIXMLDocument(OPCPackage pkg) {
super(pkg);
this.pkg = pkg;
}
@ -58,15 +58,15 @@ public abstract class POIXMLDocument extends POIXMLDocumentPart{
* in the event of a problem.
* Works around shortcomings in java's this() constructor calls
*/
public static Package openPackage(String path) throws IOException {
public static OPCPackage openPackage(String path) throws IOException {
try {
return Package.open(path);
return OPCPackage.open(path);
} catch (InvalidFormatException e) {
throw new IOException(e.toString());
}
}
public Package getPackage() {
public OPCPackage getPackage() {
return this.pkg;
}
@ -92,7 +92,7 @@ public abstract class POIXMLDocument extends POIXMLDocumentPart{
* @return The target part
* @throws InvalidFormatException
*/
protected static PackagePart getTargetPart(Package pkg, PackageRelationship rel) throws InvalidFormatException {
protected static PackagePart getTargetPart(OPCPackage pkg, PackageRelationship rel) throws InvalidFormatException {
PackagePartName relName = PackagingURIHelper.createPartName(rel.getTargetURI());
PackagePart part = pkg.getPart(relName);
if (part == null) {
@ -176,7 +176,7 @@ public abstract class POIXMLDocument extends POIXMLDocumentPart{
* there is no way to change or even save such an instance in a OutputStream.
* The workaround is to create a copy via a temp file
*/
protected static Package ensureWriteAccess(Package pkg) throws IOException {
protected static OPCPackage ensureWriteAccess(OPCPackage pkg) throws IOException {
if(pkg.getPackageAccess() == PackageAccess.READ){
try {
return PackageHelper.clone(pkg);

View File

@ -55,17 +55,13 @@ public class POIXMLDocumentPart {
/**
* Construct POIXMLDocumentPart representing a "core document" package part.
*/
public POIXMLDocumentPart(Package pkg) {
try {
public POIXMLDocumentPart(OPCPackage pkg) {
PackageRelationship coreRel = pkg.getRelationshipsByType(
PackageRelationshipTypes.CORE_DOCUMENT).getRelationship(0);
this.relations = new LinkedList<POIXMLDocumentPart>();
this.packagePart = pkg.getPart(coreRel);
this.packageRel = coreRel;
} catch (OpenXML4JException e){
throw new POIXMLException(e);
}
}
/**

View File

@ -18,23 +18,23 @@ package org.apache.poi;
import java.io.IOException;
import org.apache.xmlbeans.XmlException;
import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
import org.apache.poi.openxml4j.opc.Package;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.openxml4j.opc.PackageRelationshipCollection;
import org.apache.poi.openxml4j.opc.internal.PackagePropertiesPart;
import org.apache.xmlbeans.XmlException;
/**
* Wrapper around the two different kinds of OOXML properties
* a document can have
*/
public class POIXMLProperties {
private Package pkg;
private OPCPackage pkg;
private CoreProperties core;
private ExtendedProperties ext;
private CustomProperties cust;
public POIXMLProperties(Package docPackage) throws IOException, OpenXML4JException, XmlException {
public POIXMLProperties(OPCPackage docPackage) throws IOException, OpenXML4JException, XmlException {
this.pkg = docPackage;
// Core properties
@ -97,7 +97,7 @@ public class POIXMLProperties {
* Writes out the ooxml properties into the supplied,
* new Package
*/
public void write(Package pkg) {
public void write(OPCPackage pkg) {
// TODO
}

View File

@ -22,7 +22,7 @@ import java.io.InputStream;
import java.io.PrintStream;
import java.util.ArrayList;
import org.apache.poi.openxml4j.opc.Package;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.openxml4j.opc.PackageAccess;
import org.apache.poi.openxml4j.opc.PackagePart;
import org.apache.poi.openxml4j.opc.PackageRelationship;
@ -34,13 +34,13 @@ import org.apache.poi.openxml4j.opc.PackageRelationshipCollection;
* they're all related to each other.
*/
public class OOXMLLister {
private Package container;
private OPCPackage container;
private PrintStream disp;
public OOXMLLister(Package container) {
public OOXMLLister(OPCPackage container) {
this(container, System.out);
}
public OOXMLLister(Package container, PrintStream disp) {
public OOXMLLister(OPCPackage container, PrintStream disp) {
this.container = container;
this.disp = disp;
}
@ -122,7 +122,7 @@ public class OOXMLLister {
}
OOXMLLister lister = new OOXMLLister(
Package.open(f.toString(), PackageAccess.READ)
OPCPackage.open(f.toString(), PackageAccess.READ)
);
lister.disp.println(f.toString() + "\n");

View File

@ -33,6 +33,11 @@ import org.apache.poi.hdgf.extractor.VisioTextExtractor;
import org.apache.poi.hslf.extractor.PowerPointExtractor;
import org.apache.poi.hssf.extractor.ExcelExtractor;
import org.apache.poi.hwpf.extractor.WordExtractor;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.openxml4j.opc.PackagePart;
import org.apache.poi.openxml4j.opc.PackageRelationshipCollection;
import org.apache.poi.poifs.filesystem.DirectoryEntry;
import org.apache.poi.poifs.filesystem.DirectoryNode;
import org.apache.poi.poifs.filesystem.Entry;
@ -41,14 +46,9 @@ import org.apache.poi.xslf.XSLFSlideShow;
import org.apache.poi.xslf.extractor.XSLFPowerPointExtractor;
import org.apache.poi.xssf.extractor.XSSFExcelExtractor;
import org.apache.poi.xssf.usermodel.XSSFRelation;
import org.apache.poi.xwpf.usermodel.XWPFRelation;
import org.apache.poi.xwpf.extractor.XWPFWordExtractor;
import org.apache.poi.xwpf.usermodel.XWPFRelation;
import org.apache.xmlbeans.XmlException;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
import org.apache.poi.openxml4j.opc.Package;
import org.apache.poi.openxml4j.opc.PackagePart;
import org.apache.poi.openxml4j.opc.PackageRelationshipCollection;
/**
* Figures out the correct POITextExtractor for your supplied
@ -67,7 +67,7 @@ public class ExtractorFactory {
}
if(POIXMLDocument.hasOOXMLHeader(inp)) {
inp.close();
return createExtractor(Package.open(f.toString()));
return createExtractor(OPCPackage.open(f.toString()));
}
throw new IllegalArgumentException("Your File was neither an OLE2 file, nor an OOXML file");
}
@ -83,12 +83,12 @@ public class ExtractorFactory {
return createExtractor(new POIFSFileSystem(inp));
}
if(POIXMLDocument.hasOOXMLHeader(inp)) {
return createExtractor(Package.open(inp));
return createExtractor(OPCPackage.open(inp));
}
throw new IllegalArgumentException("Your InputStream was neither an OLE2 stream, nor an OOXML stream");
}
public static POIXMLTextExtractor createExtractor(Package pkg) throws IOException, OpenXML4JException, XmlException {
public static POIXMLTextExtractor createExtractor(OPCPackage pkg) throws IOException, OpenXML4JException, XmlException {
PackageRelationshipCollection core =
pkg.getRelationshipsByType(CORE_DOCUMENT_REL);
if(core.size() != 1) {

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -39,7 +39,7 @@ public abstract class PackagePart implements RelationshipSource {
/**
* This part's container.
*/
protected Package container;
protected OPCPackage container;
/**
* The part name. (required by the specification [M1.1])
@ -78,7 +78,7 @@ public abstract class PackagePart implements RelationshipSource {
* @throws InvalidFormatException
* If the specified URI is not valid.
*/
protected PackagePart(Package pack, PackagePartName partName,
protected PackagePart(OPCPackage pack, PackagePartName partName,
ContentType contentType) throws InvalidFormatException {
this(pack, partName, contentType, true);
}
@ -97,12 +97,12 @@ public abstract class PackagePart implements RelationshipSource {
* @throws InvalidFormatException
* If the specified URI is not valid.
*/
protected PackagePart(Package pack, PackagePartName partName,
protected PackagePart(OPCPackage pack, PackagePartName partName,
ContentType contentType, boolean loadRelationships)
throws InvalidFormatException {
this.partName = partName;
this.contentType = contentType;
this.container = (ZipPackage) pack;
this.container = (ZipPackage) pack; // TODO - enforcing ZipPackage here - perhaps should change constructor signature
// Check if this part is a relationship part
isRelationshipPart = this.partName.isRelationshipPartURI();
@ -123,7 +123,7 @@ public abstract class PackagePart implements RelationshipSource {
* The Multipurpose Internet Mail Extensions (MIME) content type
* of the part's data stream.
*/
public PackagePart(Package pack, PackagePartName partName,
public PackagePart(OPCPackage pack, PackagePartName partName,
String contentType) throws InvalidFormatException {
this(pack, partName, new ContentType(contentType));
}
@ -567,7 +567,7 @@ public abstract class PackagePart implements RelationshipSource {
"You can't change the content type of a part.");
}
public Package getPackage() {
public OPCPackage getPackage() {
return container;
}

View File

@ -26,7 +26,7 @@ import org.apache.poi.openxml4j.util.Nullable;
*
* @author Julien Chable
* @version 1.0
* @see org.apache.poi.openxml4j.opc.Package
* @see org.apache.poi.openxml4j.opc.OPCPackage
*/
public interface PackageProperties {

View File

@ -62,7 +62,7 @@ public final class PackageRelationship {
/**
* Reference to the package.
*/
private Package container;
private OPCPackage container;
/**
* Type de relation.
@ -94,7 +94,7 @@ public final class PackageRelationship {
* @param relationshipType
* @param id
*/
public PackageRelationship(Package pkg, PackagePart sourcePart,
public PackageRelationship(OPCPackage pkg, PackagePart sourcePart,
URI targetUri, TargetMode targetMode, String relationshipType,
String id) {
if (pkg == null)
@ -143,7 +143,7 @@ public final class PackageRelationship {
/**
* @return the container
*/
public Package getPackage() {
public OPCPackage getPackage() {
return container;
}

View File

@ -71,7 +71,7 @@ public final class PackageRelationshipCollection implements
/**
* Reference to the package.
*/
private Package container;
private OPCPackage container;
/**
* Constructor.
@ -105,7 +105,7 @@ public final class PackageRelationshipCollection implements
/**
* Constructor.
*/
public PackageRelationshipCollection(Package container)
public PackageRelationshipCollection(OPCPackage container)
throws InvalidFormatException {
this(container, null);
}
@ -136,7 +136,7 @@ public final class PackageRelationshipCollection implements
* If an error occurs during the parsing of the relatinships
* part fo the specified part.
*/
public PackageRelationshipCollection(Package container, PackagePart part)
public PackageRelationshipCollection(OPCPackage container, PackagePart part)
throws InvalidFormatException {
this();

View File

@ -53,7 +53,7 @@ public class ZipPackagePart extends PackagePart {
* @throws InvalidFormatException
* Throws if the content of this part invalid.
*/
public ZipPackagePart(Package container, PackagePartName partName,
public ZipPackagePart(OPCPackage container, PackagePartName partName,
String contentType) throws InvalidFormatException {
super(container, partName, contentType);
}
@ -72,7 +72,7 @@ public class ZipPackagePart extends PackagePart {
* @throws InvalidFormatException
* Throws if the content of this part is invalid.
*/
public ZipPackagePart(Package container, ZipEntry zipEntry,
public ZipPackagePart(OPCPackage container, ZipEntry zipEntry,
PackagePartName partName, String contentType)
throws InvalidFormatException {
super(container, partName, contentType);

View File

@ -25,8 +25,14 @@ import java.util.Iterator;
import java.util.List;
import java.util.TreeMap;
import java.util.Map.Entry;
import java.util.zip.ZipOutputStream;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.openxml4j.exceptions.InvalidOperationException;
import org.apache.poi.openxml4j.exceptions.OpenXML4JRuntimeException;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.openxml4j.opc.PackagePart;
import org.apache.poi.openxml4j.opc.PackagePartName;
import org.apache.poi.openxml4j.opc.PackagingURIHelper;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
@ -34,15 +40,6 @@ import org.dom4j.Element;
import org.dom4j.Namespace;
import org.dom4j.QName;
import org.dom4j.io.SAXReader;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.openxml4j.exceptions.InvalidOperationException;
import org.apache.poi.openxml4j.exceptions.OpenXML4JRuntimeException;
import org.apache.poi.openxml4j.opc.Package;
import org.apache.poi.openxml4j.opc.PackagePart;
import org.apache.poi.openxml4j.opc.PackagePartName;
import org.apache.poi.openxml4j.opc.PackagingURIHelper;
import org.apache.poi.util.POILogger;
import org.apache.poi.util.POILogFactory;
/**
* Manage package content types ([Content_Types].xml part).
@ -52,13 +49,6 @@ import org.apache.poi.util.POILogFactory;
*/
public abstract class ContentTypeManager {
private static POILogger logger = POILogFactory.getLogger(ContentTypeManager.class);
/**
* Reference to the package using this content type manager.
*/
protected Package container;
/**
* Content type part name.
*/
@ -83,6 +73,11 @@ public abstract class ContentTypeManager {
private static final String PART_NAME_ATTRIBUTE_NAME = "PartName";
/**
* Reference to the package using this content type manager.
*/
protected OPCPackage container;
/**
* Default content type tree. <Extension, ContentType>
*/
@ -102,7 +97,7 @@ public abstract class ContentTypeManager {
* @throws InvalidFormatException
* If the content types part content is not valid.
*/
public ContentTypeManager(InputStream in, Package pkg)
public ContentTypeManager(InputStream in, OPCPackage pkg)
throws InvalidFormatException {
this.container = pkg;
this.defaultContentType = new TreeMap<String, String>();

View File

@ -23,7 +23,7 @@ import java.io.OutputStream;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
import org.apache.poi.openxml4j.opc.Package;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.openxml4j.opc.PackagePart;
import org.apache.poi.openxml4j.opc.PackagePartName;
import org.apache.poi.openxml4j.opc.internal.marshallers.ZipPartMarshaller;
@ -58,7 +58,7 @@ public final class MemoryPackagePart extends PackagePart {
* @throws InvalidFormatException
* If the specified URI is not OPC compliant.
*/
public MemoryPackagePart(Package pack, PackagePartName partName,
public MemoryPackagePart(OPCPackage pack, PackagePartName partName,
String contentType) throws InvalidFormatException {
super(pack, partName, contentType);
}
@ -77,7 +77,7 @@ public final class MemoryPackagePart extends PackagePart {
* @throws InvalidFormatException
* If the specified URI is not OPC compliant.
*/
public MemoryPackagePart(Package pack, PackagePartName partName,
public MemoryPackagePart(OPCPackage pack, PackagePartName partName,
String contentType, boolean loadRelationships)
throws InvalidFormatException {
super(pack, partName, new ContentType(contentType), loadRelationships);

View File

@ -27,7 +27,7 @@ import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.openxml4j.exceptions.InvalidOperationException;
import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
import org.apache.poi.openxml4j.opc.ContentTypes;
import org.apache.poi.openxml4j.opc.Package;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.openxml4j.opc.PackagePart;
import org.apache.poi.openxml4j.opc.PackagePartName;
import org.apache.poi.openxml4j.opc.PackageProperties;
@ -60,7 +60,7 @@ public class PackagePropertiesPart extends PackagePart implements
* @throws InvalidFormatException
* Throws if the content is invalid.
*/
public PackagePropertiesPart(Package pack, PackagePartName partName)
public PackagePropertiesPart(OPCPackage pack, PackagePartName partName)
throws InvalidFormatException {
super(pack, partName, ContentTypes.CORE_PROPERTIES_PART);
}

View File

@ -25,12 +25,12 @@ import java.io.OutputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
import org.dom4j.Document;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.openxml4j.opc.Package;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.openxml4j.opc.StreamHelper;
import org.apache.poi.util.POILogger;
import org.apache.poi.util.POILogFactory;
import org.apache.poi.util.POILogger;
import org.dom4j.Document;
/**
* Zip implementation of the ContentTypeManager.
@ -51,7 +51,7 @@ public class ZipContentTypeManager extends ContentTypeManager {
* @throws InvalidFormatException
* If the content types part content is not valid.
*/
public ZipContentTypeManager(InputStream in, Package pkg)
public ZipContentTypeManager(InputStream in, OPCPackage pkg)
throws InvalidFormatException {
super(in, pkg);
}

View File

@ -19,7 +19,7 @@ package org.apache.poi.openxml4j.opc.internal.unmarshallers;
import java.util.zip.ZipEntry;
import org.apache.poi.openxml4j.opc.Package;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.openxml4j.opc.PackagePartName;
/**
@ -30,7 +30,7 @@ import org.apache.poi.openxml4j.opc.PackagePartName;
*/
public final class UnmarshallContext {
private Package _package;
private OPCPackage _package;
private PackagePartName partName;
@ -44,7 +44,7 @@ public final class UnmarshallContext {
* @param partName
* Name of the part to unmarshall.
*/
public UnmarshallContext(Package targetPackage, PackagePartName partName) {
public UnmarshallContext(OPCPackage targetPackage, PackagePartName partName) {
this._package = targetPackage;
this.partName = partName;
}
@ -52,7 +52,7 @@ public final class UnmarshallContext {
/**
* @return the container
*/
Package getPackage() {
OPCPackage getPackage() {
return _package;
}
@ -60,7 +60,7 @@ public final class UnmarshallContext {
* @param container
* the container to set
*/
public void setPackage(Package container) {
public void setPackage(OPCPackage container) {
this._package = container;
}

View File

@ -22,10 +22,10 @@ import java.io.PushbackInputStream;
import org.apache.poi.POIXMLDocument;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.openxml4j.opc.Package;
/**
* Factory for creating the appropriate kind of Workbook
@ -41,7 +41,7 @@ public class WorkbookFactory {
/**
* Creates an XSSFWorkbook from the given OOXML Package
*/
public static Workbook create(Package pkg) throws IOException {
public static Workbook create(OPCPackage pkg) throws IOException {
return new XSSFWorkbook(pkg);
}
/**
@ -60,7 +60,7 @@ public class WorkbookFactory {
return new HSSFWorkbook(inp);
}
if(POIXMLDocument.hasOOXMLHeader(inp)) {
return new XSSFWorkbook( Package.open(inp) );
return new XSSFWorkbook(OPCPackage.open(inp));
}
throw new IllegalArgumentException("Your InputStream was neither an OLE2 stream, nor an OOXML stream");
}

View File

@ -17,7 +17,7 @@
package org.apache.poi.util;
import org.apache.poi.openxml4j.opc.*;
import org.apache.poi.openxml4j.opc.Package;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
import org.apache.poi.util.IOUtils;
@ -36,7 +36,7 @@ public class PackageHelper {
* @param pkg the package to clone
* @return the cloned package
*/
public static Package clone(Package pkg) throws OpenXML4JException, IOException {
public static OPCPackage clone(OPCPackage pkg) throws OpenXML4JException, IOException {
return clone(pkg, createTempFile());
}
@ -47,11 +47,11 @@ public class PackageHelper {
* @param file the destination file
* @return the cloned package
*/
public static Package clone(Package pkg, File file) throws OpenXML4JException, IOException {
public static OPCPackage clone(OPCPackage pkg, File file) throws OpenXML4JException, IOException {
String path = file.getAbsolutePath();
Package dest = Package.create(path);
OPCPackage dest = OPCPackage.create(path);
PackageRelationshipCollection rels = pkg.getRelationships();
for (PackageRelationship rel : rels) {
PackagePart part = pkg.getPart(rel);
@ -76,7 +76,7 @@ public class PackageHelper {
//the temp file will be deleted when JVM terminates
new File(path).deleteOnExit();
return Package.open(path);
return OPCPackage.open(path);
}
/**
@ -95,7 +95,7 @@ public class PackageHelper {
/**
* Recursively copy package parts to the destination package
*/
private static void copy(Package pkg, PackagePart part, Package tgt, PackagePart part_tgt) throws OpenXML4JException, IOException {
private static void copy(OPCPackage pkg, PackagePart part, OPCPackage tgt, PackagePart part_tgt) throws OpenXML4JException, IOException {
PackageRelationshipCollection rels = part.getRelationships();
if(rels != null) for (PackageRelationship rel : rels) {
PackagePart p;

View File

@ -17,17 +17,17 @@
package org.apache.poi.xslf;
import java.io.IOException;
import java.util.List;
import java.util.LinkedList;
import java.util.List;
import org.apache.poi.POIXMLDocument;
import org.apache.xmlbeans.XmlException;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
import org.apache.poi.openxml4j.opc.Package;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.openxml4j.opc.PackagePart;
import org.apache.poi.openxml4j.opc.PackageRelationship;
import org.apache.poi.openxml4j.opc.PackageRelationshipCollection;
import org.apache.xmlbeans.XmlException;
import org.openxmlformats.schemas.presentationml.x2006.main.CTCommentList;
import org.openxmlformats.schemas.presentationml.x2006.main.CTNotesSlide;
import org.openxmlformats.schemas.presentationml.x2006.main.CTPresentation;
@ -68,7 +68,7 @@ public class XSLFSlideShow extends POIXMLDocument {
*/
private List<PackagePart> embedds;
public XSLFSlideShow(Package container) throws OpenXML4JException, IOException, XmlException {
public XSLFSlideShow(OPCPackage container) throws OpenXML4JException, IOException, XmlException {
super(container);
presentationDoc =

View File

@ -19,12 +19,12 @@ package org.apache.poi.xslf.extractor;
import java.io.IOException;
import org.apache.poi.POIXMLTextExtractor;
import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.xslf.XSLFSlideShow;
import org.apache.poi.xslf.usermodel.XMLSlideShow;
import org.apache.poi.xslf.usermodel.XSLFSlide;
import org.apache.xmlbeans.XmlException;
import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
import org.apache.poi.openxml4j.opc.Package;
import org.openxmlformats.schemas.drawingml.x2006.main.CTRegularTextRun;
import org.openxmlformats.schemas.drawingml.x2006.main.CTTextBody;
import org.openxmlformats.schemas.drawingml.x2006.main.CTTextParagraph;
@ -48,7 +48,7 @@ public class XSLFPowerPointExtractor extends POIXMLTextExtractor {
public XSLFPowerPointExtractor(XSLFSlideShow slideshow) throws XmlException, IOException {
this(new XMLSlideShow(slideshow));
}
public XSLFPowerPointExtractor(Package container) throws XmlException, OpenXML4JException, IOException {
public XSLFPowerPointExtractor(OPCPackage container) throws XmlException, OpenXML4JException, IOException {
this(new XSLFSlideShow(container));
}

View File

@ -18,24 +18,28 @@ package org.apache.poi.xssf.eventusermodel;
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import org.apache.poi.xssf.model.SharedStringsTable;
import org.apache.poi.xssf.model.StylesTable;
import org.apache.poi.xssf.usermodel.XSSFRelation;
import org.apache.poi.POIXMLException;
import org.apache.xmlbeans.XmlException;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
import org.apache.poi.openxml4j.opc.Package;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.openxml4j.opc.PackagePart;
import org.apache.poi.openxml4j.opc.PackagePartName;
import org.apache.poi.openxml4j.opc.PackageRelationship;
import org.apache.poi.openxml4j.opc.PackageRelationshipTypes;
import org.apache.poi.openxml4j.opc.PackagingURIHelper;
import org.apache.poi.xssf.model.SharedStringsTable;
import org.apache.poi.xssf.model.StylesTable;
import org.apache.poi.xssf.usermodel.XSSFRelation;
import org.apache.xmlbeans.XmlException;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheet;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorkbook;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.WorkbookDocument;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheet;
/**
* This class makes it easy to get at individual parts
@ -45,13 +49,13 @@ import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheet;
* for XSSF.
*/
public class XSSFReader {
private Package pkg;
private OPCPackage pkg;
private PackagePart workbookPart;
/**
* Creates a new XSSFReader, for the given package
*/
public XSSFReader(Package pkg) throws IOException, OpenXML4JException {
public XSSFReader(OPCPackage pkg) throws IOException, OpenXML4JException {
this.pkg = pkg;
PackageRelationship coreDocRelationship = this.pkg.getRelationshipsByType(

View File

@ -21,6 +21,8 @@ import java.util.Iterator;
import org.apache.poi.POIXMLTextExtractor;
import org.apache.poi.hssf.extractor.ExcelExtractor;
import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Comment;
import org.apache.poi.ss.usermodel.HeaderFooter;
@ -29,8 +31,6 @@ import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.xmlbeans.XmlException;
import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
import org.apache.poi.openxml4j.opc.Package;
/**
* Helper class to extract text from an OOXML Excel file
@ -44,7 +44,7 @@ public class XSSFExcelExtractor extends POIXMLTextExtractor implements org.apach
public XSSFExcelExtractor(String path) throws XmlException, OpenXML4JException, IOException {
this(new XSSFWorkbook(path));
}
public XSSFExcelExtractor(Package container) throws XmlException, OpenXML4JException, IOException {
public XSSFExcelExtractor(OPCPackage container) throws XmlException, OpenXML4JException, IOException {
this(new XSSFWorkbook(container));
}
public XSSFExcelExtractor(XSSFWorkbook workbook) {

View File

@ -36,6 +36,14 @@ import org.apache.poi.POIXMLDocument;
import org.apache.poi.POIXMLDocumentPart;
import org.apache.poi.POIXMLException;
import org.apache.poi.hssf.record.formula.SheetNameFormatter;
import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.openxml4j.opc.PackagePart;
import org.apache.poi.openxml4j.opc.PackagePartName;
import org.apache.poi.openxml4j.opc.PackageRelationship;
import org.apache.poi.openxml4j.opc.PackageRelationshipTypes;
import org.apache.poi.openxml4j.opc.PackagingURIHelper;
import org.apache.poi.openxml4j.opc.TargetMode;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
@ -45,20 +53,12 @@ import org.apache.poi.util.IOUtils;
import org.apache.poi.util.POILogFactory;
import org.apache.poi.util.POILogger;
import org.apache.poi.util.PackageHelper;
import org.apache.poi.xssf.model.CalculationChain;
import org.apache.poi.xssf.model.SharedStringsTable;
import org.apache.poi.xssf.model.StylesTable;
import org.apache.poi.xssf.model.CalculationChain;
import org.apache.xmlbeans.XmlException;
import org.apache.xmlbeans.XmlObject;
import org.apache.xmlbeans.XmlOptions;
import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
import org.apache.poi.openxml4j.opc.Package;
import org.apache.poi.openxml4j.opc.PackagePart;
import org.apache.poi.openxml4j.opc.PackagePartName;
import org.apache.poi.openxml4j.opc.PackageRelationship;
import org.apache.poi.openxml4j.opc.PackageRelationshipTypes;
import org.apache.poi.openxml4j.opc.PackagingURIHelper;
import org.apache.poi.openxml4j.opc.TargetMode;
import org.openxmlformats.schemas.officeDocument.x2006.relationships.STRelationshipId;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBookView;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBookViews;
@ -152,7 +152,7 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Iterable<X
*
* @param pkg the OpenXML4J <code>Package</code> object.
*/
public XSSFWorkbook(Package pkg) throws IOException {
public XSSFWorkbook(OPCPackage pkg) throws IOException {
super(ensureWriteAccess(pkg));
//build a tree of POIXMLDocumentParts, this workbook being the root
@ -240,9 +240,9 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Iterable<X
/**
* Create a new SpreadsheetML package and setup the default minimal content
*/
protected static Package newPackage() {
protected static OPCPackage newPackage() {
try {
Package pkg = Package.create(PackageHelper.createTempFile());
OPCPackage pkg = OPCPackage.create(PackageHelper.createTempFile());
// Main part
PackagePartName corePartName = PackagingURIHelper.createPartName(XSSFRelation.WORKBOOK.getDefaultFileName());
// Create main part relationship

View File

@ -21,16 +21,16 @@ import java.util.Iterator;
import org.apache.poi.POIXMLDocument;
import org.apache.poi.POIXMLTextExtractor;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.xwpf.model.XWPFCommentsDecorator;
import org.apache.poi.xwpf.model.XWPFHeaderFooterPolicy;
import org.apache.poi.xwpf.model.XWPFHyperlinkDecorator;
import org.apache.poi.xwpf.model.XWPFParagraphDecorator;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
import org.apache.poi.xwpf.usermodel.XWPFTable;
import org.apache.xmlbeans.XmlException;
import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
import org.apache.poi.openxml4j.opc.Package;
/**
* Helper class to extract text from an OOXML Word file
@ -39,7 +39,7 @@ public class XWPFWordExtractor extends POIXMLTextExtractor {
private XWPFDocument document;
private boolean fetchHyperlinks = false;
public XWPFWordExtractor(Package container) throws XmlException, OpenXML4JException, IOException {
public XWPFWordExtractor(OPCPackage container) throws XmlException, OpenXML4JException, IOException {
this(new XWPFDocument(container));
}
public XWPFWordExtractor(XWPFDocument document) {

View File

@ -30,7 +30,6 @@ import org.apache.xmlbeans.XmlOptions;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
import org.apache.poi.openxml4j.opc.*;
import org.apache.poi.openxml4j.opc.Package;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBody;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTComment;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTDocument1;
@ -65,7 +64,7 @@ public class XWPFDocument extends POIXMLDocument {
/** Handles the joy of different headers/footers for different pages */
private XWPFHeaderFooterPolicy headerFooterPolicy;
public XWPFDocument(Package pkg) throws IOException {
public XWPFDocument(OPCPackage pkg) throws IOException {
super(ensureWriteAccess(pkg));
//build a tree of POIXMLDocumentParts, this document being the root
@ -143,9 +142,9 @@ public class XWPFDocument extends POIXMLDocument {
/**
* Create a new SpreadsheetML package and setup the default minimal content
*/
protected static Package newPackage() {
protected static OPCPackage newPackage() {
try {
Package pkg = Package.create(PackageHelper.createTempFile());
OPCPackage pkg = OPCPackage.create(PackageHelper.createTempFile());
// Main part
PackagePartName corePartName = PackagingURIHelper.createPartName(XWPFRelation.DOCUMENT.getDefaultFileName());
// Create main part relationship

View File

@ -25,7 +25,7 @@ import org.apache.poi.util.IOUtils;
import org.apache.poi.xslf.XSLFSlideShow;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.openxml4j.opc.Package;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.openxml4j.opc.PackagePart;
import junit.framework.TestCase;
@ -47,7 +47,7 @@ public class TestEmbeded extends TestCase
File f = new File(dirname, "ExcelWithAttachments.xlsx");
assertTrue(f.exists());
POIXMLDocument doc = new XSSFWorkbook(Package.open(f.toString()));
POIXMLDocument doc = new XSSFWorkbook(OPCPackage.open(f.toString()));
test(doc, 4);
}
@ -55,7 +55,7 @@ public class TestEmbeded extends TestCase
File f = new File(dirname, "WordWithAttachments.docx");
assertTrue(f.exists());
POIXMLDocument doc = new XWPFDocument(Package.open(f.toString()));
POIXMLDocument doc = new XWPFDocument(OPCPackage.open(f.toString()));
test(doc, 5);
}
@ -63,7 +63,7 @@ public class TestEmbeded extends TestCase
File f = new File(dirname, "PPTWithAttachments.pptx");
assertTrue(f.exists());
POIXMLDocument doc = new XSLFSlideShow(Package.open(f.toString()));
POIXMLDocument doc = new XSLFSlideShow(OPCPackage.open(f.toString()));
test(doc, 4);
}

View File

@ -20,7 +20,7 @@ import java.io.File;
import org.apache.poi.xssf.extractor.XSSFExcelExtractor;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.openxml4j.opc.Package;
import org.apache.poi.openxml4j.opc.OPCPackage;
import junit.framework.TestCase;
@ -33,7 +33,7 @@ public class TestXMLPropertiesTextExtractor extends TestCase {
}
public void testGetFromMainExtractor() throws Exception {
org.apache.poi.openxml4j.opc.Package pkg = Package.open(
OPCPackage pkg = OPCPackage.open(
(new File(dirname, "ExcelWithAttachments.xlsx")).toString()
);
XSSFWorkbook wb = new XSSFWorkbook(pkg);
@ -54,7 +54,7 @@ public class TestXMLPropertiesTextExtractor extends TestCase {
}
public void testCore() throws Exception {
org.apache.poi.openxml4j.opc.Package pkg = Package.open(
OPCPackage pkg = OPCPackage.open(
(new File(dirname, "ExcelWithAttachments.xlsx")).toString()
);
XSSFWorkbook wb = new XSSFWorkbook(pkg);
@ -71,7 +71,7 @@ public class TestXMLPropertiesTextExtractor extends TestCase {
}
public void testExtended() throws Exception {
org.apache.poi.openxml4j.opc.Package pkg = Package.open(
OPCPackage pkg = OPCPackage.open(
(new File(dirname, "ExcelWithAttachments.xlsx")).toString()
);
XSSFWorkbook wb = new XSSFWorkbook(pkg);

View File

@ -34,7 +34,7 @@ import org.apache.poi.xwpf.extractor.XWPFWordExtractor;
import junit.framework.TestCase;
import org.apache.poi.openxml4j.exceptions.InvalidOperationException;
import org.apache.poi.openxml4j.opc.Package;
import org.apache.poi.openxml4j.opc.OPCPackage;
/**
* Test that the extractor factory plays nicely
@ -276,34 +276,34 @@ public class TestExtractorFactory extends TestCase {
public void testPackage() throws Exception {
// Excel
assertTrue(
ExtractorFactory.createExtractor(Package.open(xlsx.toString()))
ExtractorFactory.createExtractor(OPCPackage.open(xlsx.toString()))
instanceof XSSFExcelExtractor
);
assertTrue(
ExtractorFactory.createExtractor(Package.open(xlsx.toString())).getText().length() > 200
ExtractorFactory.createExtractor(OPCPackage.open(xlsx.toString())).getText().length() > 200
);
// Word
assertTrue(
ExtractorFactory.createExtractor(Package.open(docx.toString()))
ExtractorFactory.createExtractor(OPCPackage.open(docx.toString()))
instanceof XWPFWordExtractor
);
assertTrue(
ExtractorFactory.createExtractor(Package.open(docx.toString())).getText().length() > 120
ExtractorFactory.createExtractor(OPCPackage.open(docx.toString())).getText().length() > 120
);
// PowerPoint
assertTrue(
ExtractorFactory.createExtractor(Package.open(pptx.toString()))
ExtractorFactory.createExtractor(OPCPackage.open(pptx.toString()))
instanceof XSLFPowerPointExtractor
);
assertTrue(
ExtractorFactory.createExtractor(Package.open(pptx.toString())).getText().length() > 120
ExtractorFactory.createExtractor(OPCPackage.open(pptx.toString())).getText().length() > 120
);
// Text
try {
ExtractorFactory.createExtractor(Package.open(txt.toString()));
ExtractorFactory.createExtractor(OPCPackage.open(txt.toString()));
fail();
} catch(InvalidOperationException e) {
// Good

View File

@ -83,9 +83,9 @@ public final class TestListParts extends TestCase {
public void testListParts() throws InvalidFormatException {
InputStream is = OpenXML4JTestDataSamples.openSampleStream("sample.docx");
Package p;
OPCPackage p;
try {
p = Package.open(is);
p = OPCPackage.open(is);
} catch (IOException e) {
throw new RuntimeException(e);
}

View File

@ -51,7 +51,7 @@ public final class TestPackage extends TestCase {
String originalFile = OpenXML4JTestDataSamples.getSampleFileName("TestPackageCommon.docx");
File targetFile = OpenXML4JTestDataSamples.getOutputFile("TestPackageOpenSaveTMP.docx");
Package p = Package.open(originalFile, PackageAccess.READ_WRITE);
OPCPackage p = OPCPackage.open(originalFile, PackageAccess.READ_WRITE);
p.save(targetFile.getAbsoluteFile());
// Compare the original and newly saved document
@ -70,7 +70,7 @@ public final class TestPackage extends TestCase {
// Zap the target file, in case of an earlier run
if(targetFile.exists()) targetFile.delete();
Package pkg = Package.create(targetFile);
OPCPackage pkg = OPCPackage.create(targetFile);
// Check it has content types for rels and xml
ContentTypeManager ctm = getContentTypeManager(pkg);
@ -105,7 +105,7 @@ public final class TestPackage extends TestCase {
if(targetFile.exists()) targetFile.delete();
// Create a package
Package pkg = Package.create(targetFile);
OPCPackage pkg = OPCPackage.create(targetFile);
PackagePartName corePartName = PackagingURIHelper
.createPartName("/word/document.xml");
@ -145,7 +145,7 @@ public final class TestPackage extends TestCase {
*/
public void testCreatePackageWithCoreDocument() throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Package pkg = Package.create(baos);
OPCPackage pkg = OPCPackage.create(baos);
// Add a core document
PackagePartName corePartName = PackagingURIHelper.createPartName("/xl/workbook.xml");
@ -184,7 +184,7 @@ public final class TestPackage extends TestCase {
FileOutputStream fout = new FileOutputStream(File.createTempFile("testCreatePackageWithCoreDocument", ".zip"));
fout.write(baos.toByteArray());
fout.close();
pkg = Package.open(new ByteArrayInputStream(baos.toByteArray()));
pkg = OPCPackage.open(new ByteArrayInputStream(baos.toByteArray()));
// Check still right
@ -210,7 +210,7 @@ public final class TestPackage extends TestCase {
FileHelper.copyFile(inputFile, targetFile);
// Create a package
Package pkg = Package.open(targetFile.getAbsolutePath());
OPCPackage pkg = OPCPackage.open(targetFile.getAbsolutePath());
// Modify core part
PackagePartName corePartName = PackagingURIHelper
@ -263,7 +263,7 @@ public final class TestPackage extends TestCase {
String originalFile = OpenXML4JTestDataSamples.getSampleFileName("TestPackageCommon.docx");
File targetFile = OpenXML4JTestDataSamples.getOutputFile("TestPackageOpenSaveTMP.docx");
Package p = Package.open(originalFile, PackageAccess.READ_WRITE);
OPCPackage p = OPCPackage.open(originalFile, PackageAccess.READ_WRITE);
FileOutputStream fout = new FileOutputStream(targetFile);
p.save(fout);
fout.close();
@ -284,7 +284,7 @@ public final class TestPackage extends TestCase {
FileInputStream finp = new FileInputStream(originalFile);
Package p = Package.open(finp);
OPCPackage p = OPCPackage.open(finp);
assertNotNull(p);
assertNotNull(p.getRelationships());
@ -303,7 +303,7 @@ public final class TestPackage extends TestCase {
File targetFile = OpenXML4JTestDataSamples.getOutputFile("TestPackageRemovePartRecursiveOUTPUT.docx");
File tempFile = OpenXML4JTestDataSamples.getOutputFile("TestPackageRemovePartRecursiveTMP.docx");
Package p = Package.open(originalFile, PackageAccess.READ_WRITE);
OPCPackage p = OPCPackage.open(originalFile, PackageAccess.READ_WRITE);
p.removePartRecursive(PackagingURIHelper.createPartName(new URI(
"/word/document.xml")));
p.save(tempFile.getAbsoluteFile());
@ -353,7 +353,7 @@ public final class TestPackage extends TestCase {
String filepath = OpenXML4JTestDataSamples.getSampleFileName("sample.docx");
Package p = Package.open(filepath, PackageAccess.READ_WRITE);
OPCPackage p = OPCPackage.open(filepath, PackageAccess.READ_WRITE);
// Remove the core part
p.deletePart(PackagingURIHelper.createPartName("/word/document.xml"));
@ -391,7 +391,7 @@ public final class TestPackage extends TestCase {
String filepath = OpenXML4JTestDataSamples.getSampleFileName("sample.docx");
Package p = Package.open(filepath, PackageAccess.READ_WRITE);
OPCPackage p = OPCPackage.open(filepath, PackageAccess.READ_WRITE);
// Remove the core part
p.deletePartRecursive(PackagingURIHelper.createPartName("/word/document.xml"));
@ -409,8 +409,8 @@ public final class TestPackage extends TestCase {
p.revert();
}
private static ContentTypeManager getContentTypeManager(Package pkg) throws Exception {
Field f = Package.class.getDeclaredField("contentTypeManager");
private static ContentTypeManager getContentTypeManager(OPCPackage pkg) throws Exception {
Field f = OPCPackage.class.getDeclaredField("contentTypeManager");
f.setAccessible(true);
return (ContentTypeManager)f.get(pkg);
}

View File

@ -39,7 +39,7 @@ public final class TestPackageCoreProperties extends TestCase {
public void testGetProperties() {
try {
// Open the package
Package p = Package.open(OpenXML4JTestDataSamples.openSampleStream("TestPackageCoreProperiesGetters.docx"));
OPCPackage p = OPCPackage.open(OpenXML4JTestDataSamples.openSampleStream("TestPackageCoreProperiesGetters.docx"));
compareProperties(p);
p.revert();
} catch (OpenXML4JException e) {
@ -59,7 +59,7 @@ public final class TestPackageCoreProperties extends TestCase {
File outputFile = OpenXML4JTestDataSamples.getOutputFile("TestPackageCoreProperiesSettersOUTPUT.docx");
// Open package
Package p = Package.open(inputPath, PackageAccess.READ_WRITE);
OPCPackage p = OPCPackage.open(inputPath, PackageAccess.READ_WRITE);
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
Date dateToInsert = df.parse("2007-05-12T08:00:00Z", new ParsePosition(
@ -86,13 +86,13 @@ public final class TestPackageCoreProperties extends TestCase {
p.save(outputFile);
// Open the newly created file to check core properties saved values.
Package p2 = Package.open(outputFile.getAbsolutePath(), PackageAccess.READ);
OPCPackage p2 = OPCPackage.open(outputFile.getAbsolutePath(), PackageAccess.READ);
compareProperties(p2);
p2.revert();
outputFile.delete();
}
private void compareProperties(Package p) throws InvalidFormatException {
private void compareProperties(OPCPackage p) throws InvalidFormatException {
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
Date expectedDate = df.parse("2007-05-12T08:00:00Z", new ParsePosition(
0));

View File

@ -41,13 +41,13 @@ public final class TestPackageThumbnail extends TestCase {
File outputFile = OpenXML4JTestDataSamples.getOutputFile("TestPackageThumbnailOUTPUT.docx");
// Open package
Package p = Package.open(inputPath, PackageAccess.READ_WRITE);
OPCPackage p = OPCPackage.open(inputPath, PackageAccess.READ_WRITE);
p.addThumbnail(imagePath);
// Save the package in the output directory
p.save(outputFile);
// Open the newly created file to check core properties saved values.
Package p2 = Package.open(outputFile.getAbsolutePath(), PackageAccess.READ);
OPCPackage p2 = OPCPackage.open(outputFile.getAbsolutePath(), PackageAccess.READ);
if (p2.getRelationshipsByType(PackageRelationshipTypes.THUMBNAIL)
.size() == 0)
fail("Thumbnail not added to the package !");

View File

@ -22,7 +22,7 @@ import junit.framework.TestCase;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.openxml4j.opc.ContentTypes;
import org.apache.poi.openxml4j.opc.Package;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.openxml4j.opc.PackagePart;
import org.apache.poi.openxml4j.opc.PackagePartName;
import org.apache.poi.openxml4j.opc.PackagingURIHelper;
@ -80,7 +80,7 @@ public class TestPackagingURIHelper extends TestCase {
PackagePartName partNameToValid = PackagingURIHelper
.createPartName("/word/media/image1.gif");
Package pkg = Package.create("DELETEIFEXISTS.docx");
OPCPackage pkg = OPCPackage.create("DELETEIFEXISTS.docx");
// Base part
PackagePartName nameBase = PackagingURIHelper
.createPartName("/word/document.xml");
@ -101,7 +101,7 @@ public class TestPackagingURIHelper extends TestCase {
PackagePartName partNameToValid = PackagingURIHelper
.createPartName("/word/media/image1.gif");
Package pkg = Package.create("DELETEIFEXISTS.docx");
OPCPackage pkg = OPCPackage.create("DELETEIFEXISTS.docx");
// Base part
PackagePartName nameBase = PackagingURIHelper
.createPartName("/word/document.xml");

View File

@ -45,7 +45,7 @@ public class TestRelationships extends TestCase {
*/
public void testLoadRelationships() throws Exception {
InputStream is = OpenXML4JTestDataSamples.openSampleStream("sample.xlsx");
Package pkg = Package.open(is);
OPCPackage pkg = OPCPackage.open(is);
logger.debug("1: " + pkg);
PackageRelationshipCollection rels = pkg.getRelationshipsByType(PackageRelationshipTypes.CORE_DOCUMENT);
PackageRelationship coreDocRelationship = rels.getRelationship(0);
@ -66,7 +66,7 @@ public class TestRelationships extends TestCase {
*/
public void testFetchFromCollection() throws Exception {
InputStream is = OpenXML4JTestDataSamples.openSampleStream("ExcelWithHyperlinks.xlsx");
Package pkg = Package.open(is);
OPCPackage pkg = OPCPackage.open(is);
PackagePart sheet = pkg.getPart(
PackagingURIHelper.createPartName(SHEET_WITH_COMMENTS));
assertNotNull(sheet);
@ -107,7 +107,7 @@ public class TestRelationships extends TestCase {
*/
public void testLoadExcelHyperlinkRelations() throws Exception {
InputStream is = OpenXML4JTestDataSamples.openSampleStream("ExcelWithHyperlinks.xlsx");
Package pkg = Package.open(is);
OPCPackage pkg = OPCPackage.open(is);
PackagePart sheet = pkg.getPart(
PackagingURIHelper.createPartName(SHEET_WITH_COMMENTS));
assertNotNull(sheet);
@ -141,7 +141,7 @@ public class TestRelationships extends TestCase {
*/
public void testCreateExcelHyperlinkRelations() throws Exception {
String filepath = OpenXML4JTestDataSamples.getSampleFileName("ExcelWithHyperlinks.xlsx");
Package pkg = Package.open(filepath, PackageAccess.READ_WRITE);
OPCPackage pkg = OPCPackage.open(filepath, PackageAccess.READ_WRITE);
PackagePart sheet = pkg.getPart(
PackagingURIHelper.createPartName(SHEET_WITH_COMMENTS));
assertNotNull(sheet);
@ -185,7 +185,7 @@ public class TestRelationships extends TestCase {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
pkg.save(baos);
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
pkg = Package.open(bais);
pkg = OPCPackage.open(bais);
// Check again
sheet = pkg.getPart(
@ -208,7 +208,7 @@ public class TestRelationships extends TestCase {
public void testCreateRelationsFromScratch() throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Package pkg = Package.create(baos);
OPCPackage pkg = OPCPackage.create(baos);
PackagePart partA =
pkg.createPart(PackagingURIHelper.createPartName("/partA"), "text/plain");
@ -235,7 +235,7 @@ public class TestRelationships extends TestCase {
// Save, and re-load
pkg.close();
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
pkg = Package.open(bais);
pkg = OPCPackage.open(bais);
partA = pkg.getPart(PackagingURIHelper.createPartName("/partA"));
partB = pkg.getPart(PackagingURIHelper.createPartName("/partB"));

View File

@ -29,7 +29,7 @@ import org.apache.poi.openxml4j.OpenXML4JTestDataSamples;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.openxml4j.exceptions.InvalidOperationException;
import org.apache.poi.openxml4j.opc.ContentTypes;
import org.apache.poi.openxml4j.opc.Package;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.openxml4j.opc.PackageRelationshipTypes;
import org.apache.poi.openxml4j.opc.PackagingURIHelper;
import org.apache.poi.openxml4j.opc.TargetMode;
@ -68,10 +68,10 @@ import org.apache.poi.openxml4j.opc.TargetMode;
public final class TestOPCComplianceCoreProperties extends TestCase {
public void testCorePropertiesPart() {
Package pkg;
OPCPackage pkg;
try {
InputStream is = OpenXML4JTestDataSamples.openComplianceSampleStream("OPCCompliance_CoreProperties_OnlyOneCorePropertiesPart.docx");
pkg = Package.open(is);
pkg = OPCPackage.open(is);
} catch (InvalidFormatException e) {
throw new RuntimeException(e);
} catch (IOException e) {
@ -83,9 +83,9 @@ public final class TestOPCComplianceCoreProperties extends TestCase {
private static String extractInvalidFormatMessage(String sampleNameSuffix) {
InputStream is = OpenXML4JTestDataSamples.openComplianceSampleStream("OPCCompliance_CoreProperties_" + sampleNameSuffix);
Package pkg;
OPCPackage pkg;
try {
pkg = Package.open(is);
pkg = OPCPackage.open(is);
} catch (InvalidFormatException e) {
// expected during successful test
return e.getMessage();
@ -118,9 +118,9 @@ public final class TestOPCComplianceCoreProperties extends TestCase {
*/
public void testOnlyOneCorePropertiesPart_AddRelationship() {
InputStream is = OpenXML4JTestDataSamples.openComplianceSampleStream("OPCCompliance_CoreProperties_OnlyOneCorePropertiesPart.docx");
Package pkg;
OPCPackage pkg;
try {
pkg = Package.open(is);
pkg = OPCPackage.open(is);
} catch (InvalidFormatException e) {
throw new RuntimeException(e);
} catch (IOException e) {
@ -145,9 +145,9 @@ public final class TestOPCComplianceCoreProperties extends TestCase {
*/
public void testOnlyOneCorePropertiesPart_AddPart() {
String sampleFileName = OpenXML4JTestDataSamples.getComplianceSampleFileName("OPCCompliance_CoreProperties_OnlyOneCorePropertiesPart.docx");
Package pkg = null;
OPCPackage pkg = null;
try {
pkg = Package.open(sampleFileName);
pkg = OPCPackage.open(sampleFileName);
} catch (InvalidFormatException e) {
throw new RuntimeException(e);
}

View File

@ -24,7 +24,7 @@ import junit.framework.TestCase;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.openxml4j.exceptions.InvalidOperationException;
import org.apache.poi.openxml4j.opc.ContentTypes;
import org.apache.poi.openxml4j.opc.Package;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.openxml4j.opc.PackagePartName;
import org.apache.poi.openxml4j.opc.PackageRelationshipTypes;
import org.apache.poi.openxml4j.opc.PackagingURIHelper;
@ -50,7 +50,7 @@ public class TestOPCCompliancePackageModel extends TestCase {
* [M1.11]
*/
public void testPartNameDerivationAdditionFailure() {
Package pkg = Package.create("TODELETEIFEXIST.docx");
OPCPackage pkg = OPCPackage.create("TODELETEIFEXIST.docx");
try {
PackagePartName name = PackagingURIHelper
.createPartName("/word/document.xml");
@ -78,7 +78,7 @@ public class TestOPCCompliancePackageModel extends TestCase {
String filepath = System.getProperty("openxml4j.compliance.input")
+ File.separator + "OPCCompliance_DerivedPartNameFAIL.docx";
try {
Package.open(filepath);
OPCPackage.open(filepath);
} catch (InvalidFormatException e) {
return;
}
@ -93,7 +93,7 @@ public class TestOPCCompliancePackageModel extends TestCase {
* part names.
*/
public void testAddPackageAlreadyAddFailure() throws Exception {
Package pkg = Package.create("DELETEIFEXISTS.docx");
OPCPackage pkg = OPCPackage.create("DELETEIFEXISTS.docx");
PackagePartName name1 = null;
PackagePartName name2 = null;
try {
@ -117,7 +117,7 @@ public class TestOPCCompliancePackageModel extends TestCase {
* part names.
*/
public void testAddPackageAlreadyAddFailure2() throws Exception {
Package pkg = Package.create("DELETEIFEXISTS.docx");
OPCPackage pkg = OPCPackage.create("DELETEIFEXISTS.docx");
PackagePartName partName = null;
try {
partName = PackagingURIHelper.createPartName("/word/document.xml");
@ -142,7 +142,7 @@ public class TestOPCCompliancePackageModel extends TestCase {
* relationship as invalid.
*/
public void testAddRelationshipRelationshipsPartFailure() {
Package pkg = Package.create("DELETEIFEXISTS.docx");
OPCPackage pkg = OPCPackage.create("DELETEIFEXISTS.docx");
PackagePartName name1 = null;
try {
name1 = PackagingURIHelper

View File

@ -24,7 +24,7 @@ import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.openxml4j.opc.Package;
import org.apache.poi.openxml4j.opc.OPCPackage;
import junit.framework.TestCase;
@ -63,7 +63,7 @@ public class TestWorkbookFactory extends TestCase {
// Package -> xssf
wb = WorkbookFactory.create(
Package.open(xlsx.toString())
OPCPackage.open(xlsx.toString())
);
assertNotNull(wb);
assertTrue(wb instanceof XSSFWorkbook);

View File

@ -18,14 +18,14 @@ package org.apache.poi.xslf;
import java.io.File;
import junit.framework.TestCase;
import org.apache.poi.POIXMLDocument;
import org.apache.poi.openxml4j.opc.Package;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.openxml4j.opc.PackagePart;
import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideIdListEntry;
import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideMasterIdListEntry;
import junit.framework.TestCase;
public class TestXSLFSlideShow extends TestCase {
private String sampleFile;
@ -39,7 +39,7 @@ public class TestXSLFSlideShow extends TestCase {
}
public void testContainsMainContentType() throws Exception {
Package pack = POIXMLDocument.openPackage(sampleFile);
OPCPackage pack = POIXMLDocument.openPackage(sampleFile);
boolean found = false;
for(PackagePart part : pack.getParts()) {

View File

@ -17,14 +17,19 @@
package org.apache.poi.xssf;
import java.io.*;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.openxml4j.opc.Package;
/**
* Centralises logic for finding/opening sample files in the src/testcases/org/apache/poi/hssf/hssf/data folder.
@ -35,7 +40,7 @@ public class XSSFTestDataSamples {
public static final XSSFWorkbook openSampleWorkbook(String sampleName) {
InputStream is = HSSFTestDataSamples.openSampleFileStream(sampleName);
try {
Package pkg = Package.open(is);
OPCPackage pkg = OPCPackage.open(is);
return new XSSFWorkbook(pkg);
} catch (InvalidFormatException e) {
throw new RuntimeException(e);
@ -57,7 +62,7 @@ public class XSSFTestDataSamples {
FileOutputStream out = new FileOutputStream(tmp);
wb.write(out);
out.close();
Package pkg = Package.open(tmp.getAbsolutePath());
OPCPackage pkg = OPCPackage.open(tmp.getAbsolutePath());
result = new XSSFWorkbook(pkg);
} else {
throw new RuntimeException("Unexpected workbook type ("

View File

@ -25,7 +25,7 @@ import junit.framework.TestCase;
import org.apache.poi.util.IOUtils;
import org.apache.poi.xssf.usermodel.XSSFRichTextString;
import org.apache.poi.openxml4j.opc.Package;
import org.apache.poi.openxml4j.opc.OPCPackage;
/**
* Tests for XSSFReader
@ -49,7 +49,7 @@ public class TestXSSFReader extends TestCase {
public void testGetBits() throws Exception {
File f = new File(dirName, "SampleSS.xlsx");
Package pkg = Package.open(f.toString());
OPCPackage pkg = OPCPackage.open(f.toString());
XSSFReader r = new XSSFReader(pkg);
@ -63,7 +63,7 @@ public class TestXSSFReader extends TestCase {
public void testStyles() throws Exception {
File f = new File(dirName, "SampleSS.xlsx");
Package pkg = Package.open(f.toString());
OPCPackage pkg = OPCPackage.open(f.toString());
XSSFReader r = new XSSFReader(pkg);
@ -73,7 +73,7 @@ public class TestXSSFReader extends TestCase {
public void testStrings() throws Exception {
File f = new File(dirName, "SampleSS.xlsx");
Package pkg = Package.open(f.toString());
OPCPackage pkg = OPCPackage.open(f.toString());
XSSFReader r = new XSSFReader(pkg);
@ -83,7 +83,7 @@ public class TestXSSFReader extends TestCase {
public void testSheets() throws Exception {
File f = new File(dirName, "SampleSS.xlsx");
Package pkg = Package.open(f.toString());
OPCPackage pkg = OPCPackage.open(f.toString());
XSSFReader r = new XSSFReader(pkg);
byte[] data = new byte[4096];
@ -116,7 +116,7 @@ public class TestXSSFReader extends TestCase {
*/
public void testOrderOfSheets() throws Exception {
File f = new File(dirName, "reordered_sheets.xlsx");
Package pkg = Package.open(f.toString());
OPCPackage pkg = OPCPackage.open(f.toString());
XSSFReader r = new XSSFReader(pkg);

View File

@ -32,7 +32,7 @@ import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.xssf.XSSFTestDataSamples;
import org.apache.poi.POIXMLDocumentPart;
import org.apache.poi.openxml4j.opc.Package;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.*;
import junit.framework.TestCase;
@ -125,7 +125,7 @@ public class TestCommentsTable extends TestCase {
);
assertTrue(xml.exists());
Package pkg = Package.open(xml.toString());
OPCPackage pkg = OPCPackage.open(xml.toString());
XSSFWorkbook wb = new XSSFWorkbook(pkg);
List<POIXMLDocumentPart> rels = wb.getSheetAt(0).getRelations();
CommentsTable ct = null;

View File

@ -32,7 +32,7 @@ import org.apache.poi.ss.usermodel.CellValue;
import org.apache.poi.ss.usermodel.FormulaEvaluator;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.openxml4j.opc.Package;
import org.apache.poi.openxml4j.opc.OPCPackage;
/**
* Performs much the same role as {@link TestFormulasFromSpreadsheet},
@ -149,7 +149,7 @@ public final class TestFormulaEvaluatorOnXSSF extends TestCase {
protected void setUp() throws Exception {
if (workbook == null) {
InputStream is = HSSFTestDataSamples.openSampleFileStream(SS.FILENAME);
Package pkg = Package.open(is);
OPCPackage pkg = OPCPackage.open(is);
workbook = new XSSFWorkbook( pkg );
sheet = workbook.getSheetAt( 0 );
}

View File

@ -21,7 +21,8 @@ import java.io.File;
import junit.framework.TestCase;
import org.apache.poi.openxml4j.opc.Package;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.openxml4j.opc.PackagePart;
import org.apache.poi.openxml4j.opc.PackagingURIHelper;
import org.apache.poi.xssf.XSSFTestDataSamples;
@ -71,7 +72,7 @@ public class TestXSSFBugs extends TestCase {
* We should carry vba macros over after save
*/
public void test45431() throws Exception {
Package pkg = Package.open(getFilePath("45431.xlsm"));
OPCPackage pkg = OPCPackage.open(getFilePath("45431.xlsm"));
XSSFWorkbook wb = new XSSFWorkbook(pkg);
assertTrue(wb.isMacroEnabled());
@ -89,7 +90,7 @@ public class TestXSSFBugs extends TestCase {
// Save and re-open, both still there
XSSFWorkbook nwb = XSSFTestDataSamples.writeOutAndReadBack(wb);
Package nPkg = nwb.getPackage();
OPCPackage nPkg = nwb.getPackage();
assertTrue(nwb.isMacroEnabled());
vba = nPkg.getPart(

View File

@ -16,12 +16,14 @@
==================================================================== */
package org.apache.poi.xssf.usermodel;
import junit.framework.TestCase;
import org.apache.poi.xssf.XSSFTestDataSamples;
import org.apache.poi.POIXMLDocumentPart;
import java.util.List;
import junit.framework.TestCase;
import org.apache.poi.POIXMLDocumentPart;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.xssf.XSSFTestDataSamples;
/**
* @author Yegor Kozlov
*/
@ -71,7 +73,7 @@ public class TestXSSFDrawing extends TestCase {
XSSFSheet sheet = wb.createSheet();
XSSFDrawing drawing = sheet.createDrawingPatriarch();
}
org.apache.poi.openxml4j.opc.Package pkg = wb.getPackage();
OPCPackage pkg = wb.getPackage();
assertEquals(3, pkg.getPartsByContentType(XSSFRelation.DRAWINGS.getContentType()).size());
}
}

View File

@ -29,7 +29,7 @@ import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.XSSFTestDataSamples;
import org.apache.poi.xssf.model.StylesTable;
import org.apache.poi.openxml4j.opc.ContentTypes;
import org.apache.poi.openxml4j.opc.Package;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.openxml4j.opc.PackagePart;
import org.apache.poi.openxml4j.opc.PackagingURIHelper;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheet;
@ -251,7 +251,7 @@ public final class TestXSSFWorkbook extends TestCase {
out.close();
// Check the package contains what we'd expect it to
Package pkg = Package.open(file.toString());
OPCPackage pkg = OPCPackage.open(file.toString());
PackagePart wbRelPart =
pkg.getPart(PackagingURIHelper.createPartName("/xl/_rels/workbook.xml.rels"));
assertNotNull(wbRelPart);
@ -293,7 +293,7 @@ public final class TestXSSFWorkbook extends TestCase {
assertNotNull(workbook.getStylesSource());
// And check a few low level bits too
Package pkg = Package.open(HSSFTestDataSamples.openSampleFileStream("Formatting.xlsx"));
OPCPackage pkg = OPCPackage.open(HSSFTestDataSamples.openSampleFileStream("Formatting.xlsx"));
PackagePart wbPart =
pkg.getPart(PackagingURIHelper.createPartName("/xl/workbook.xml"));

View File

@ -18,13 +18,13 @@ package org.apache.poi.xwpf;
import java.io.File;
import junit.framework.TestCase;
import org.apache.poi.POIXMLDocument;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.openxml4j.opc.PackagePart;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFRelation;
import org.apache.poi.openxml4j.opc.Package;
import org.apache.poi.openxml4j.opc.PackagePart;
import junit.framework.TestCase;
public class TestXWPFDocument extends TestCase {
private File sampleFile;
@ -47,7 +47,7 @@ public class TestXWPFDocument extends TestCase {
}
public void testContainsMainContentType() throws Exception {
Package pack = POIXMLDocument.openPackage(sampleFile.toString());
OPCPackage pack = POIXMLDocument.openPackage(sampleFile.toString());
boolean found = false;
for(PackagePart part : pack.getParts()) {