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:
parent
4f4ad37765
commit
67196db87e
@ -22,7 +22,7 @@ import java.util.Iterator;
|
|||||||
import org.apache.poi.xssf.eventusermodel.XSSFReader;
|
import org.apache.poi.xssf.eventusermodel.XSSFReader;
|
||||||
import org.apache.poi.xssf.model.SharedStringsTable;
|
import org.apache.poi.xssf.model.SharedStringsTable;
|
||||||
import org.apache.poi.xssf.usermodel.XSSFRichTextString;
|
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.Attributes;
|
||||||
import org.xml.sax.ContentHandler;
|
import org.xml.sax.ContentHandler;
|
||||||
import org.xml.sax.InputSource;
|
import org.xml.sax.InputSource;
|
||||||
@ -36,7 +36,7 @@ import org.xml.sax.helpers.XMLReaderFactory;
|
|||||||
*/
|
*/
|
||||||
public class FromHowTo {
|
public class FromHowTo {
|
||||||
public void processOneSheet(String filename) throws Exception {
|
public void processOneSheet(String filename) throws Exception {
|
||||||
Package pkg = Package.open(filename);
|
OPCPackage pkg = OPCPackage.open(filename);
|
||||||
XSSFReader r = new XSSFReader( pkg );
|
XSSFReader r = new XSSFReader( pkg );
|
||||||
SharedStringsTable sst = r.getSharedStringsTable();
|
SharedStringsTable sst = r.getSharedStringsTable();
|
||||||
|
|
||||||
@ -51,7 +51,7 @@ public class FromHowTo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void processAllSheets(String filename) throws Exception {
|
public void processAllSheets(String filename) throws Exception {
|
||||||
Package pkg = Package.open(filename);
|
OPCPackage pkg = OPCPackage.open(filename);
|
||||||
XSSFReader r = new XSSFReader( pkg );
|
XSSFReader r = new XSSFReader( pkg );
|
||||||
SharedStringsTable sst = r.getSharedStringsTable();
|
SharedStringsTable sst = r.getSharedStringsTable();
|
||||||
|
|
||||||
|
@ -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";
|
public static final String PACK_OBJECT_REL_TYPE="http://schemas.openxmlformats.org/officeDocument/2006/relationships/package";
|
||||||
|
|
||||||
/** The OPC Package */
|
/** The OPC Package */
|
||||||
private Package pkg;
|
private OPCPackage pkg;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The properties of the OPC package, opened as needed
|
* The properties of the OPC package, opened as needed
|
||||||
*/
|
*/
|
||||||
private POIXMLProperties properties;
|
private POIXMLProperties properties;
|
||||||
|
|
||||||
protected POIXMLDocument(Package pkg) {
|
protected POIXMLDocument(OPCPackage pkg) {
|
||||||
super(pkg);
|
super(pkg);
|
||||||
this.pkg = pkg;
|
this.pkg = pkg;
|
||||||
}
|
}
|
||||||
@ -58,15 +58,15 @@ public abstract class POIXMLDocument extends POIXMLDocumentPart{
|
|||||||
* in the event of a problem.
|
* in the event of a problem.
|
||||||
* Works around shortcomings in java's this() constructor calls
|
* 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 {
|
try {
|
||||||
return Package.open(path);
|
return OPCPackage.open(path);
|
||||||
} catch (InvalidFormatException e) {
|
} catch (InvalidFormatException e) {
|
||||||
throw new IOException(e.toString());
|
throw new IOException(e.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Package getPackage() {
|
public OPCPackage getPackage() {
|
||||||
return this.pkg;
|
return this.pkg;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,7 +92,7 @@ public abstract class POIXMLDocument extends POIXMLDocumentPart{
|
|||||||
* @return The target part
|
* @return The target part
|
||||||
* @throws InvalidFormatException
|
* @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());
|
PackagePartName relName = PackagingURIHelper.createPartName(rel.getTargetURI());
|
||||||
PackagePart part = pkg.getPart(relName);
|
PackagePart part = pkg.getPart(relName);
|
||||||
if (part == null) {
|
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.
|
* 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
|
* 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){
|
if(pkg.getPackageAccess() == PackageAccess.READ){
|
||||||
try {
|
try {
|
||||||
return PackageHelper.clone(pkg);
|
return PackageHelper.clone(pkg);
|
||||||
|
@ -55,17 +55,13 @@ public class POIXMLDocumentPart {
|
|||||||
/**
|
/**
|
||||||
* Construct POIXMLDocumentPart representing a "core document" package part.
|
* Construct POIXMLDocumentPart representing a "core document" package part.
|
||||||
*/
|
*/
|
||||||
public POIXMLDocumentPart(Package pkg) {
|
public POIXMLDocumentPart(OPCPackage pkg) {
|
||||||
try {
|
|
||||||
PackageRelationship coreRel = pkg.getRelationshipsByType(
|
PackageRelationship coreRel = pkg.getRelationshipsByType(
|
||||||
PackageRelationshipTypes.CORE_DOCUMENT).getRelationship(0);
|
PackageRelationshipTypes.CORE_DOCUMENT).getRelationship(0);
|
||||||
|
|
||||||
this.relations = new LinkedList<POIXMLDocumentPart>();
|
this.relations = new LinkedList<POIXMLDocumentPart>();
|
||||||
this.packagePart = pkg.getPart(coreRel);
|
this.packagePart = pkg.getPart(coreRel);
|
||||||
this.packageRel = coreRel;
|
this.packageRel = coreRel;
|
||||||
} catch (OpenXML4JException e){
|
|
||||||
throw new POIXMLException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -18,23 +18,23 @@ package org.apache.poi;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.apache.xmlbeans.XmlException;
|
|
||||||
import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
|
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.PackageRelationshipCollection;
|
||||||
import org.apache.poi.openxml4j.opc.internal.PackagePropertiesPart;
|
import org.apache.poi.openxml4j.opc.internal.PackagePropertiesPart;
|
||||||
|
import org.apache.xmlbeans.XmlException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wrapper around the two different kinds of OOXML properties
|
* Wrapper around the two different kinds of OOXML properties
|
||||||
* a document can have
|
* a document can have
|
||||||
*/
|
*/
|
||||||
public class POIXMLProperties {
|
public class POIXMLProperties {
|
||||||
private Package pkg;
|
private OPCPackage pkg;
|
||||||
private CoreProperties core;
|
private CoreProperties core;
|
||||||
private ExtendedProperties ext;
|
private ExtendedProperties ext;
|
||||||
private CustomProperties cust;
|
private CustomProperties cust;
|
||||||
|
|
||||||
public POIXMLProperties(Package docPackage) throws IOException, OpenXML4JException, XmlException {
|
public POIXMLProperties(OPCPackage docPackage) throws IOException, OpenXML4JException, XmlException {
|
||||||
this.pkg = docPackage;
|
this.pkg = docPackage;
|
||||||
|
|
||||||
// Core properties
|
// Core properties
|
||||||
@ -97,7 +97,7 @@ public class POIXMLProperties {
|
|||||||
* Writes out the ooxml properties into the supplied,
|
* Writes out the ooxml properties into the supplied,
|
||||||
* new Package
|
* new Package
|
||||||
*/
|
*/
|
||||||
public void write(Package pkg) {
|
public void write(OPCPackage pkg) {
|
||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ import java.io.InputStream;
|
|||||||
import java.io.PrintStream;
|
import java.io.PrintStream;
|
||||||
import java.util.ArrayList;
|
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.PackageAccess;
|
||||||
import org.apache.poi.openxml4j.opc.PackagePart;
|
import org.apache.poi.openxml4j.opc.PackagePart;
|
||||||
import org.apache.poi.openxml4j.opc.PackageRelationship;
|
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.
|
* they're all related to each other.
|
||||||
*/
|
*/
|
||||||
public class OOXMLLister {
|
public class OOXMLLister {
|
||||||
private Package container;
|
private OPCPackage container;
|
||||||
private PrintStream disp;
|
private PrintStream disp;
|
||||||
|
|
||||||
public OOXMLLister(Package container) {
|
public OOXMLLister(OPCPackage container) {
|
||||||
this(container, System.out);
|
this(container, System.out);
|
||||||
}
|
}
|
||||||
public OOXMLLister(Package container, PrintStream disp) {
|
public OOXMLLister(OPCPackage container, PrintStream disp) {
|
||||||
this.container = container;
|
this.container = container;
|
||||||
this.disp = disp;
|
this.disp = disp;
|
||||||
}
|
}
|
||||||
@ -122,7 +122,7 @@ public class OOXMLLister {
|
|||||||
}
|
}
|
||||||
|
|
||||||
OOXMLLister lister = new OOXMLLister(
|
OOXMLLister lister = new OOXMLLister(
|
||||||
Package.open(f.toString(), PackageAccess.READ)
|
OPCPackage.open(f.toString(), PackageAccess.READ)
|
||||||
);
|
);
|
||||||
|
|
||||||
lister.disp.println(f.toString() + "\n");
|
lister.disp.println(f.toString() + "\n");
|
||||||
|
@ -33,6 +33,11 @@ import org.apache.poi.hdgf.extractor.VisioTextExtractor;
|
|||||||
import org.apache.poi.hslf.extractor.PowerPointExtractor;
|
import org.apache.poi.hslf.extractor.PowerPointExtractor;
|
||||||
import org.apache.poi.hssf.extractor.ExcelExtractor;
|
import org.apache.poi.hssf.extractor.ExcelExtractor;
|
||||||
import org.apache.poi.hwpf.extractor.WordExtractor;
|
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.DirectoryEntry;
|
||||||
import org.apache.poi.poifs.filesystem.DirectoryNode;
|
import org.apache.poi.poifs.filesystem.DirectoryNode;
|
||||||
import org.apache.poi.poifs.filesystem.Entry;
|
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.xslf.extractor.XSLFPowerPointExtractor;
|
||||||
import org.apache.poi.xssf.extractor.XSSFExcelExtractor;
|
import org.apache.poi.xssf.extractor.XSSFExcelExtractor;
|
||||||
import org.apache.poi.xssf.usermodel.XSSFRelation;
|
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.extractor.XWPFWordExtractor;
|
||||||
|
import org.apache.poi.xwpf.usermodel.XWPFRelation;
|
||||||
import org.apache.xmlbeans.XmlException;
|
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
|
* Figures out the correct POITextExtractor for your supplied
|
||||||
@ -67,7 +67,7 @@ public class ExtractorFactory {
|
|||||||
}
|
}
|
||||||
if(POIXMLDocument.hasOOXMLHeader(inp)) {
|
if(POIXMLDocument.hasOOXMLHeader(inp)) {
|
||||||
inp.close();
|
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");
|
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));
|
return createExtractor(new POIFSFileSystem(inp));
|
||||||
}
|
}
|
||||||
if(POIXMLDocument.hasOOXMLHeader(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");
|
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 =
|
PackageRelationshipCollection core =
|
||||||
pkg.getRelationshipsByType(CORE_DOCUMENT_REL);
|
pkg.getRelationshipsByType(CORE_DOCUMENT_REL);
|
||||||
if(core.size() != 1) {
|
if(core.size() != 1) {
|
||||||
|
1390
src/ooxml/java/org/apache/poi/openxml4j/opc/OPCPackage.java
Normal file
1390
src/ooxml/java/org/apache/poi/openxml4j/opc/OPCPackage.java
Normal file
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -39,7 +39,7 @@ public abstract class PackagePart implements RelationshipSource {
|
|||||||
/**
|
/**
|
||||||
* This part's container.
|
* This part's container.
|
||||||
*/
|
*/
|
||||||
protected Package container;
|
protected OPCPackage container;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The part name. (required by the specification [M1.1])
|
* The part name. (required by the specification [M1.1])
|
||||||
@ -78,7 +78,7 @@ public abstract class PackagePart implements RelationshipSource {
|
|||||||
* @throws InvalidFormatException
|
* @throws InvalidFormatException
|
||||||
* If the specified URI is not valid.
|
* If the specified URI is not valid.
|
||||||
*/
|
*/
|
||||||
protected PackagePart(Package pack, PackagePartName partName,
|
protected PackagePart(OPCPackage pack, PackagePartName partName,
|
||||||
ContentType contentType) throws InvalidFormatException {
|
ContentType contentType) throws InvalidFormatException {
|
||||||
this(pack, partName, contentType, true);
|
this(pack, partName, contentType, true);
|
||||||
}
|
}
|
||||||
@ -97,12 +97,12 @@ public abstract class PackagePart implements RelationshipSource {
|
|||||||
* @throws InvalidFormatException
|
* @throws InvalidFormatException
|
||||||
* If the specified URI is not valid.
|
* If the specified URI is not valid.
|
||||||
*/
|
*/
|
||||||
protected PackagePart(Package pack, PackagePartName partName,
|
protected PackagePart(OPCPackage pack, PackagePartName partName,
|
||||||
ContentType contentType, boolean loadRelationships)
|
ContentType contentType, boolean loadRelationships)
|
||||||
throws InvalidFormatException {
|
throws InvalidFormatException {
|
||||||
this.partName = partName;
|
this.partName = partName;
|
||||||
this.contentType = contentType;
|
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
|
// Check if this part is a relationship part
|
||||||
isRelationshipPart = this.partName.isRelationshipPartURI();
|
isRelationshipPart = this.partName.isRelationshipPartURI();
|
||||||
@ -123,7 +123,7 @@ public abstract class PackagePart implements RelationshipSource {
|
|||||||
* The Multipurpose Internet Mail Extensions (MIME) content type
|
* The Multipurpose Internet Mail Extensions (MIME) content type
|
||||||
* of the part's data stream.
|
* of the part's data stream.
|
||||||
*/
|
*/
|
||||||
public PackagePart(Package pack, PackagePartName partName,
|
public PackagePart(OPCPackage pack, PackagePartName partName,
|
||||||
String contentType) throws InvalidFormatException {
|
String contentType) throws InvalidFormatException {
|
||||||
this(pack, partName, new ContentType(contentType));
|
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.");
|
"You can't change the content type of a part.");
|
||||||
}
|
}
|
||||||
|
|
||||||
public Package getPackage() {
|
public OPCPackage getPackage() {
|
||||||
return container;
|
return container;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ import org.apache.poi.openxml4j.util.Nullable;
|
|||||||
*
|
*
|
||||||
* @author Julien Chable
|
* @author Julien Chable
|
||||||
* @version 1.0
|
* @version 1.0
|
||||||
* @see org.apache.poi.openxml4j.opc.Package
|
* @see org.apache.poi.openxml4j.opc.OPCPackage
|
||||||
*/
|
*/
|
||||||
public interface PackageProperties {
|
public interface PackageProperties {
|
||||||
|
|
||||||
|
@ -62,7 +62,7 @@ public final class PackageRelationship {
|
|||||||
/**
|
/**
|
||||||
* Reference to the package.
|
* Reference to the package.
|
||||||
*/
|
*/
|
||||||
private Package container;
|
private OPCPackage container;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Type de relation.
|
* Type de relation.
|
||||||
@ -94,7 +94,7 @@ public final class PackageRelationship {
|
|||||||
* @param relationshipType
|
* @param relationshipType
|
||||||
* @param id
|
* @param id
|
||||||
*/
|
*/
|
||||||
public PackageRelationship(Package pkg, PackagePart sourcePart,
|
public PackageRelationship(OPCPackage pkg, PackagePart sourcePart,
|
||||||
URI targetUri, TargetMode targetMode, String relationshipType,
|
URI targetUri, TargetMode targetMode, String relationshipType,
|
||||||
String id) {
|
String id) {
|
||||||
if (pkg == null)
|
if (pkg == null)
|
||||||
@ -143,7 +143,7 @@ public final class PackageRelationship {
|
|||||||
/**
|
/**
|
||||||
* @return the container
|
* @return the container
|
||||||
*/
|
*/
|
||||||
public Package getPackage() {
|
public OPCPackage getPackage() {
|
||||||
return container;
|
return container;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,7 +71,7 @@ public final class PackageRelationshipCollection implements
|
|||||||
/**
|
/**
|
||||||
* Reference to the package.
|
* Reference to the package.
|
||||||
*/
|
*/
|
||||||
private Package container;
|
private OPCPackage container;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
@ -105,7 +105,7 @@ public final class PackageRelationshipCollection implements
|
|||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*/
|
*/
|
||||||
public PackageRelationshipCollection(Package container)
|
public PackageRelationshipCollection(OPCPackage container)
|
||||||
throws InvalidFormatException {
|
throws InvalidFormatException {
|
||||||
this(container, null);
|
this(container, null);
|
||||||
}
|
}
|
||||||
@ -136,7 +136,7 @@ public final class PackageRelationshipCollection implements
|
|||||||
* If an error occurs during the parsing of the relatinships
|
* If an error occurs during the parsing of the relatinships
|
||||||
* part fo the specified part.
|
* part fo the specified part.
|
||||||
*/
|
*/
|
||||||
public PackageRelationshipCollection(Package container, PackagePart part)
|
public PackageRelationshipCollection(OPCPackage container, PackagePart part)
|
||||||
throws InvalidFormatException {
|
throws InvalidFormatException {
|
||||||
this();
|
this();
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ public class ZipPackagePart extends PackagePart {
|
|||||||
* @throws InvalidFormatException
|
* @throws InvalidFormatException
|
||||||
* Throws if the content of this part invalid.
|
* Throws if the content of this part invalid.
|
||||||
*/
|
*/
|
||||||
public ZipPackagePart(Package container, PackagePartName partName,
|
public ZipPackagePart(OPCPackage container, PackagePartName partName,
|
||||||
String contentType) throws InvalidFormatException {
|
String contentType) throws InvalidFormatException {
|
||||||
super(container, partName, contentType);
|
super(container, partName, contentType);
|
||||||
}
|
}
|
||||||
@ -72,7 +72,7 @@ public class ZipPackagePart extends PackagePart {
|
|||||||
* @throws InvalidFormatException
|
* @throws InvalidFormatException
|
||||||
* Throws if the content of this part is invalid.
|
* 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)
|
PackagePartName partName, String contentType)
|
||||||
throws InvalidFormatException {
|
throws InvalidFormatException {
|
||||||
super(container, partName, contentType);
|
super(container, partName, contentType);
|
||||||
|
@ -25,8 +25,14 @@ import java.util.Iterator;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
import java.util.Map.Entry;
|
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.Document;
|
||||||
import org.dom4j.DocumentException;
|
import org.dom4j.DocumentException;
|
||||||
import org.dom4j.DocumentHelper;
|
import org.dom4j.DocumentHelper;
|
||||||
@ -34,15 +40,6 @@ import org.dom4j.Element;
|
|||||||
import org.dom4j.Namespace;
|
import org.dom4j.Namespace;
|
||||||
import org.dom4j.QName;
|
import org.dom4j.QName;
|
||||||
import org.dom4j.io.SAXReader;
|
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).
|
* Manage package content types ([Content_Types].xml part).
|
||||||
@ -52,13 +49,6 @@ import org.apache.poi.util.POILogFactory;
|
|||||||
*/
|
*/
|
||||||
public abstract class ContentTypeManager {
|
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.
|
* Content type part name.
|
||||||
*/
|
*/
|
||||||
@ -83,6 +73,11 @@ public abstract class ContentTypeManager {
|
|||||||
|
|
||||||
private static final String PART_NAME_ATTRIBUTE_NAME = "PartName";
|
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>
|
* Default content type tree. <Extension, ContentType>
|
||||||
*/
|
*/
|
||||||
@ -102,7 +97,7 @@ public abstract class ContentTypeManager {
|
|||||||
* @throws InvalidFormatException
|
* @throws InvalidFormatException
|
||||||
* If the content types part content is not valid.
|
* If the content types part content is not valid.
|
||||||
*/
|
*/
|
||||||
public ContentTypeManager(InputStream in, Package pkg)
|
public ContentTypeManager(InputStream in, OPCPackage pkg)
|
||||||
throws InvalidFormatException {
|
throws InvalidFormatException {
|
||||||
this.container = pkg;
|
this.container = pkg;
|
||||||
this.defaultContentType = new TreeMap<String, String>();
|
this.defaultContentType = new TreeMap<String, String>();
|
||||||
|
@ -23,7 +23,7 @@ import java.io.OutputStream;
|
|||||||
|
|
||||||
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
||||||
import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
|
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.PackagePart;
|
||||||
import org.apache.poi.openxml4j.opc.PackagePartName;
|
import org.apache.poi.openxml4j.opc.PackagePartName;
|
||||||
import org.apache.poi.openxml4j.opc.internal.marshallers.ZipPartMarshaller;
|
import org.apache.poi.openxml4j.opc.internal.marshallers.ZipPartMarshaller;
|
||||||
@ -58,7 +58,7 @@ public final class MemoryPackagePart extends PackagePart {
|
|||||||
* @throws InvalidFormatException
|
* @throws InvalidFormatException
|
||||||
* If the specified URI is not OPC compliant.
|
* If the specified URI is not OPC compliant.
|
||||||
*/
|
*/
|
||||||
public MemoryPackagePart(Package pack, PackagePartName partName,
|
public MemoryPackagePart(OPCPackage pack, PackagePartName partName,
|
||||||
String contentType) throws InvalidFormatException {
|
String contentType) throws InvalidFormatException {
|
||||||
super(pack, partName, contentType);
|
super(pack, partName, contentType);
|
||||||
}
|
}
|
||||||
@ -77,7 +77,7 @@ public final class MemoryPackagePart extends PackagePart {
|
|||||||
* @throws InvalidFormatException
|
* @throws InvalidFormatException
|
||||||
* If the specified URI is not OPC compliant.
|
* If the specified URI is not OPC compliant.
|
||||||
*/
|
*/
|
||||||
public MemoryPackagePart(Package pack, PackagePartName partName,
|
public MemoryPackagePart(OPCPackage pack, PackagePartName partName,
|
||||||
String contentType, boolean loadRelationships)
|
String contentType, boolean loadRelationships)
|
||||||
throws InvalidFormatException {
|
throws InvalidFormatException {
|
||||||
super(pack, partName, new ContentType(contentType), loadRelationships);
|
super(pack, partName, new ContentType(contentType), loadRelationships);
|
||||||
|
@ -27,7 +27,7 @@ import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
|||||||
import org.apache.poi.openxml4j.exceptions.InvalidOperationException;
|
import org.apache.poi.openxml4j.exceptions.InvalidOperationException;
|
||||||
import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
|
import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
|
||||||
import org.apache.poi.openxml4j.opc.ContentTypes;
|
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.PackagePart;
|
||||||
import org.apache.poi.openxml4j.opc.PackagePartName;
|
import org.apache.poi.openxml4j.opc.PackagePartName;
|
||||||
import org.apache.poi.openxml4j.opc.PackageProperties;
|
import org.apache.poi.openxml4j.opc.PackageProperties;
|
||||||
@ -60,7 +60,7 @@ public class PackagePropertiesPart extends PackagePart implements
|
|||||||
* @throws InvalidFormatException
|
* @throws InvalidFormatException
|
||||||
* Throws if the content is invalid.
|
* Throws if the content is invalid.
|
||||||
*/
|
*/
|
||||||
public PackagePropertiesPart(Package pack, PackagePartName partName)
|
public PackagePropertiesPart(OPCPackage pack, PackagePartName partName)
|
||||||
throws InvalidFormatException {
|
throws InvalidFormatException {
|
||||||
super(pack, partName, ContentTypes.CORE_PROPERTIES_PART);
|
super(pack, partName, ContentTypes.CORE_PROPERTIES_PART);
|
||||||
}
|
}
|
||||||
|
@ -25,12 +25,12 @@ import java.io.OutputStream;
|
|||||||
import java.util.zip.ZipEntry;
|
import java.util.zip.ZipEntry;
|
||||||
import java.util.zip.ZipOutputStream;
|
import java.util.zip.ZipOutputStream;
|
||||||
|
|
||||||
import org.dom4j.Document;
|
|
||||||
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
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.openxml4j.opc.StreamHelper;
|
||||||
import org.apache.poi.util.POILogger;
|
|
||||||
import org.apache.poi.util.POILogFactory;
|
import org.apache.poi.util.POILogFactory;
|
||||||
|
import org.apache.poi.util.POILogger;
|
||||||
|
import org.dom4j.Document;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Zip implementation of the ContentTypeManager.
|
* Zip implementation of the ContentTypeManager.
|
||||||
@ -51,7 +51,7 @@ public class ZipContentTypeManager extends ContentTypeManager {
|
|||||||
* @throws InvalidFormatException
|
* @throws InvalidFormatException
|
||||||
* If the content types part content is not valid.
|
* If the content types part content is not valid.
|
||||||
*/
|
*/
|
||||||
public ZipContentTypeManager(InputStream in, Package pkg)
|
public ZipContentTypeManager(InputStream in, OPCPackage pkg)
|
||||||
throws InvalidFormatException {
|
throws InvalidFormatException {
|
||||||
super(in, pkg);
|
super(in, pkg);
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ package org.apache.poi.openxml4j.opc.internal.unmarshallers;
|
|||||||
|
|
||||||
import java.util.zip.ZipEntry;
|
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;
|
import org.apache.poi.openxml4j.opc.PackagePartName;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -30,7 +30,7 @@ import org.apache.poi.openxml4j.opc.PackagePartName;
|
|||||||
*/
|
*/
|
||||||
public final class UnmarshallContext {
|
public final class UnmarshallContext {
|
||||||
|
|
||||||
private Package _package;
|
private OPCPackage _package;
|
||||||
|
|
||||||
private PackagePartName partName;
|
private PackagePartName partName;
|
||||||
|
|
||||||
@ -44,7 +44,7 @@ public final class UnmarshallContext {
|
|||||||
* @param partName
|
* @param partName
|
||||||
* Name of the part to unmarshall.
|
* Name of the part to unmarshall.
|
||||||
*/
|
*/
|
||||||
public UnmarshallContext(Package targetPackage, PackagePartName partName) {
|
public UnmarshallContext(OPCPackage targetPackage, PackagePartName partName) {
|
||||||
this._package = targetPackage;
|
this._package = targetPackage;
|
||||||
this.partName = partName;
|
this.partName = partName;
|
||||||
}
|
}
|
||||||
@ -52,7 +52,7 @@ public final class UnmarshallContext {
|
|||||||
/**
|
/**
|
||||||
* @return the container
|
* @return the container
|
||||||
*/
|
*/
|
||||||
Package getPackage() {
|
OPCPackage getPackage() {
|
||||||
return _package;
|
return _package;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,7 +60,7 @@ public final class UnmarshallContext {
|
|||||||
* @param container
|
* @param container
|
||||||
* the container to set
|
* the container to set
|
||||||
*/
|
*/
|
||||||
public void setPackage(Package container) {
|
public void setPackage(OPCPackage container) {
|
||||||
this._package = container;
|
this._package = container;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,10 +22,10 @@ import java.io.PushbackInputStream;
|
|||||||
|
|
||||||
import org.apache.poi.POIXMLDocument;
|
import org.apache.poi.POIXMLDocument;
|
||||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
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.poifs.filesystem.POIFSFileSystem;
|
||||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
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
|
* Factory for creating the appropriate kind of Workbook
|
||||||
@ -41,7 +41,7 @@ public class WorkbookFactory {
|
|||||||
/**
|
/**
|
||||||
* Creates an XSSFWorkbook from the given OOXML Package
|
* 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);
|
return new XSSFWorkbook(pkg);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@ -60,7 +60,7 @@ public class WorkbookFactory {
|
|||||||
return new HSSFWorkbook(inp);
|
return new HSSFWorkbook(inp);
|
||||||
}
|
}
|
||||||
if(POIXMLDocument.hasOOXMLHeader(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");
|
throw new IllegalArgumentException("Your InputStream was neither an OLE2 stream, nor an OOXML stream");
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
package org.apache.poi.util;
|
package org.apache.poi.util;
|
||||||
|
|
||||||
import org.apache.poi.openxml4j.opc.*;
|
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.openxml4j.exceptions.OpenXML4JException;
|
||||||
import org.apache.poi.util.IOUtils;
|
import org.apache.poi.util.IOUtils;
|
||||||
|
|
||||||
@ -36,7 +36,7 @@ public class PackageHelper {
|
|||||||
* @param pkg the package to clone
|
* @param pkg the package to clone
|
||||||
* @return the cloned package
|
* @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());
|
return clone(pkg, createTempFile());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,11 +47,11 @@ public class PackageHelper {
|
|||||||
* @param file the destination file
|
* @param file the destination file
|
||||||
* @return the cloned package
|
* @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();
|
String path = file.getAbsolutePath();
|
||||||
|
|
||||||
Package dest = Package.create(path);
|
OPCPackage dest = OPCPackage.create(path);
|
||||||
PackageRelationshipCollection rels = pkg.getRelationships();
|
PackageRelationshipCollection rels = pkg.getRelationships();
|
||||||
for (PackageRelationship rel : rels) {
|
for (PackageRelationship rel : rels) {
|
||||||
PackagePart part = pkg.getPart(rel);
|
PackagePart part = pkg.getPart(rel);
|
||||||
@ -76,7 +76,7 @@ public class PackageHelper {
|
|||||||
|
|
||||||
//the temp file will be deleted when JVM terminates
|
//the temp file will be deleted when JVM terminates
|
||||||
new File(path).deleteOnExit();
|
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
|
* 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();
|
PackageRelationshipCollection rels = part.getRelationships();
|
||||||
if(rels != null) for (PackageRelationship rel : rels) {
|
if(rels != null) for (PackageRelationship rel : rels) {
|
||||||
PackagePart p;
|
PackagePart p;
|
||||||
|
@ -17,17 +17,17 @@
|
|||||||
package org.apache.poi.xslf;
|
package org.apache.poi.xslf;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.poi.POIXMLDocument;
|
import org.apache.poi.POIXMLDocument;
|
||||||
import org.apache.xmlbeans.XmlException;
|
|
||||||
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
||||||
import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
|
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.PackagePart;
|
||||||
import org.apache.poi.openxml4j.opc.PackageRelationship;
|
import org.apache.poi.openxml4j.opc.PackageRelationship;
|
||||||
import org.apache.poi.openxml4j.opc.PackageRelationshipCollection;
|
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.CTCommentList;
|
||||||
import org.openxmlformats.schemas.presentationml.x2006.main.CTNotesSlide;
|
import org.openxmlformats.schemas.presentationml.x2006.main.CTNotesSlide;
|
||||||
import org.openxmlformats.schemas.presentationml.x2006.main.CTPresentation;
|
import org.openxmlformats.schemas.presentationml.x2006.main.CTPresentation;
|
||||||
@ -68,7 +68,7 @@ public class XSLFSlideShow extends POIXMLDocument {
|
|||||||
*/
|
*/
|
||||||
private List<PackagePart> embedds;
|
private List<PackagePart> embedds;
|
||||||
|
|
||||||
public XSLFSlideShow(Package container) throws OpenXML4JException, IOException, XmlException {
|
public XSLFSlideShow(OPCPackage container) throws OpenXML4JException, IOException, XmlException {
|
||||||
super(container);
|
super(container);
|
||||||
|
|
||||||
presentationDoc =
|
presentationDoc =
|
||||||
|
@ -19,12 +19,12 @@ package org.apache.poi.xslf.extractor;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.apache.poi.POIXMLTextExtractor;
|
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.XSLFSlideShow;
|
||||||
import org.apache.poi.xslf.usermodel.XMLSlideShow;
|
import org.apache.poi.xslf.usermodel.XMLSlideShow;
|
||||||
import org.apache.poi.xslf.usermodel.XSLFSlide;
|
import org.apache.poi.xslf.usermodel.XSLFSlide;
|
||||||
import org.apache.xmlbeans.XmlException;
|
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.CTRegularTextRun;
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.main.CTTextBody;
|
import org.openxmlformats.schemas.drawingml.x2006.main.CTTextBody;
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.main.CTTextParagraph;
|
import org.openxmlformats.schemas.drawingml.x2006.main.CTTextParagraph;
|
||||||
@ -48,7 +48,7 @@ public class XSLFPowerPointExtractor extends POIXMLTextExtractor {
|
|||||||
public XSLFPowerPointExtractor(XSLFSlideShow slideshow) throws XmlException, IOException {
|
public XSLFPowerPointExtractor(XSLFSlideShow slideshow) throws XmlException, IOException {
|
||||||
this(new XMLSlideShow(slideshow));
|
this(new XMLSlideShow(slideshow));
|
||||||
}
|
}
|
||||||
public XSLFPowerPointExtractor(Package container) throws XmlException, OpenXML4JException, IOException {
|
public XSLFPowerPointExtractor(OPCPackage container) throws XmlException, OpenXML4JException, IOException {
|
||||||
this(new XSLFSlideShow(container));
|
this(new XSLFSlideShow(container));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,24 +18,28 @@ package org.apache.poi.xssf.eventusermodel;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
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.poi.POIXMLException;
|
||||||
import org.apache.xmlbeans.XmlException;
|
|
||||||
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
||||||
import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
|
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.PackagePart;
|
||||||
import org.apache.poi.openxml4j.opc.PackagePartName;
|
import org.apache.poi.openxml4j.opc.PackagePartName;
|
||||||
import org.apache.poi.openxml4j.opc.PackageRelationship;
|
import org.apache.poi.openxml4j.opc.PackageRelationship;
|
||||||
import org.apache.poi.openxml4j.opc.PackageRelationshipTypes;
|
import org.apache.poi.openxml4j.opc.PackageRelationshipTypes;
|
||||||
import org.apache.poi.openxml4j.opc.PackagingURIHelper;
|
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.CTWorkbook;
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.WorkbookDocument;
|
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
|
* This class makes it easy to get at individual parts
|
||||||
@ -45,13 +49,13 @@ import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheet;
|
|||||||
* for XSSF.
|
* for XSSF.
|
||||||
*/
|
*/
|
||||||
public class XSSFReader {
|
public class XSSFReader {
|
||||||
private Package pkg;
|
private OPCPackage pkg;
|
||||||
private PackagePart workbookPart;
|
private PackagePart workbookPart;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new XSSFReader, for the given package
|
* 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;
|
this.pkg = pkg;
|
||||||
|
|
||||||
PackageRelationship coreDocRelationship = this.pkg.getRelationshipsByType(
|
PackageRelationship coreDocRelationship = this.pkg.getRelationshipsByType(
|
||||||
|
@ -21,6 +21,8 @@ import java.util.Iterator;
|
|||||||
|
|
||||||
import org.apache.poi.POIXMLTextExtractor;
|
import org.apache.poi.POIXMLTextExtractor;
|
||||||
import org.apache.poi.hssf.extractor.ExcelExtractor;
|
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.Cell;
|
||||||
import org.apache.poi.ss.usermodel.Comment;
|
import org.apache.poi.ss.usermodel.Comment;
|
||||||
import org.apache.poi.ss.usermodel.HeaderFooter;
|
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.XSSFSheet;
|
||||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||||
import org.apache.xmlbeans.XmlException;
|
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
|
* 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 {
|
public XSSFExcelExtractor(String path) throws XmlException, OpenXML4JException, IOException {
|
||||||
this(new XSSFWorkbook(path));
|
this(new XSSFWorkbook(path));
|
||||||
}
|
}
|
||||||
public XSSFExcelExtractor(Package container) throws XmlException, OpenXML4JException, IOException {
|
public XSSFExcelExtractor(OPCPackage container) throws XmlException, OpenXML4JException, IOException {
|
||||||
this(new XSSFWorkbook(container));
|
this(new XSSFWorkbook(container));
|
||||||
}
|
}
|
||||||
public XSSFExcelExtractor(XSSFWorkbook workbook) {
|
public XSSFExcelExtractor(XSSFWorkbook workbook) {
|
||||||
|
@ -36,6 +36,14 @@ import org.apache.poi.POIXMLDocument;
|
|||||||
import org.apache.poi.POIXMLDocumentPart;
|
import org.apache.poi.POIXMLDocumentPart;
|
||||||
import org.apache.poi.POIXMLException;
|
import org.apache.poi.POIXMLException;
|
||||||
import org.apache.poi.hssf.record.formula.SheetNameFormatter;
|
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.Row;
|
||||||
import org.apache.poi.ss.usermodel.Sheet;
|
import org.apache.poi.ss.usermodel.Sheet;
|
||||||
import org.apache.poi.ss.usermodel.Workbook;
|
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.POILogFactory;
|
||||||
import org.apache.poi.util.POILogger;
|
import org.apache.poi.util.POILogger;
|
||||||
import org.apache.poi.util.PackageHelper;
|
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.SharedStringsTable;
|
||||||
import org.apache.poi.xssf.model.StylesTable;
|
import org.apache.poi.xssf.model.StylesTable;
|
||||||
import org.apache.poi.xssf.model.CalculationChain;
|
|
||||||
import org.apache.xmlbeans.XmlException;
|
import org.apache.xmlbeans.XmlException;
|
||||||
import org.apache.xmlbeans.XmlObject;
|
import org.apache.xmlbeans.XmlObject;
|
||||||
import org.apache.xmlbeans.XmlOptions;
|
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.officeDocument.x2006.relationships.STRelationshipId;
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBookView;
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBookView;
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBookViews;
|
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.
|
* @param pkg the OpenXML4J <code>Package</code> object.
|
||||||
*/
|
*/
|
||||||
public XSSFWorkbook(Package pkg) throws IOException {
|
public XSSFWorkbook(OPCPackage pkg) throws IOException {
|
||||||
super(ensureWriteAccess(pkg));
|
super(ensureWriteAccess(pkg));
|
||||||
|
|
||||||
//build a tree of POIXMLDocumentParts, this workbook being the root
|
//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
|
* Create a new SpreadsheetML package and setup the default minimal content
|
||||||
*/
|
*/
|
||||||
protected static Package newPackage() {
|
protected static OPCPackage newPackage() {
|
||||||
try {
|
try {
|
||||||
Package pkg = Package.create(PackageHelper.createTempFile());
|
OPCPackage pkg = OPCPackage.create(PackageHelper.createTempFile());
|
||||||
// Main part
|
// Main part
|
||||||
PackagePartName corePartName = PackagingURIHelper.createPartName(XSSFRelation.WORKBOOK.getDefaultFileName());
|
PackagePartName corePartName = PackagingURIHelper.createPartName(XSSFRelation.WORKBOOK.getDefaultFileName());
|
||||||
// Create main part relationship
|
// Create main part relationship
|
||||||
|
@ -21,16 +21,16 @@ import java.util.Iterator;
|
|||||||
|
|
||||||
import org.apache.poi.POIXMLDocument;
|
import org.apache.poi.POIXMLDocument;
|
||||||
import org.apache.poi.POIXMLTextExtractor;
|
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.XWPFCommentsDecorator;
|
||||||
import org.apache.poi.xwpf.model.XWPFHeaderFooterPolicy;
|
import org.apache.poi.xwpf.model.XWPFHeaderFooterPolicy;
|
||||||
import org.apache.poi.xwpf.model.XWPFHyperlinkDecorator;
|
import org.apache.poi.xwpf.model.XWPFHyperlinkDecorator;
|
||||||
import org.apache.poi.xwpf.model.XWPFParagraphDecorator;
|
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.XWPFParagraph;
|
||||||
import org.apache.poi.xwpf.usermodel.XWPFTable;
|
import org.apache.poi.xwpf.usermodel.XWPFTable;
|
||||||
import org.apache.xmlbeans.XmlException;
|
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
|
* Helper class to extract text from an OOXML Word file
|
||||||
@ -39,7 +39,7 @@ public class XWPFWordExtractor extends POIXMLTextExtractor {
|
|||||||
private XWPFDocument document;
|
private XWPFDocument document;
|
||||||
private boolean fetchHyperlinks = false;
|
private boolean fetchHyperlinks = false;
|
||||||
|
|
||||||
public XWPFWordExtractor(Package container) throws XmlException, OpenXML4JException, IOException {
|
public XWPFWordExtractor(OPCPackage container) throws XmlException, OpenXML4JException, IOException {
|
||||||
this(new XWPFDocument(container));
|
this(new XWPFDocument(container));
|
||||||
}
|
}
|
||||||
public XWPFWordExtractor(XWPFDocument document) {
|
public XWPFWordExtractor(XWPFDocument document) {
|
||||||
|
@ -30,7 +30,6 @@ import org.apache.xmlbeans.XmlOptions;
|
|||||||
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
||||||
import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
|
import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
|
||||||
import org.apache.poi.openxml4j.opc.*;
|
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.CTBody;
|
||||||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTComment;
|
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTComment;
|
||||||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTDocument1;
|
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 */
|
/** Handles the joy of different headers/footers for different pages */
|
||||||
private XWPFHeaderFooterPolicy headerFooterPolicy;
|
private XWPFHeaderFooterPolicy headerFooterPolicy;
|
||||||
|
|
||||||
public XWPFDocument(Package pkg) throws IOException {
|
public XWPFDocument(OPCPackage pkg) throws IOException {
|
||||||
super(ensureWriteAccess(pkg));
|
super(ensureWriteAccess(pkg));
|
||||||
|
|
||||||
//build a tree of POIXMLDocumentParts, this document being the root
|
//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
|
* Create a new SpreadsheetML package and setup the default minimal content
|
||||||
*/
|
*/
|
||||||
protected static Package newPackage() {
|
protected static OPCPackage newPackage() {
|
||||||
try {
|
try {
|
||||||
Package pkg = Package.create(PackageHelper.createTempFile());
|
OPCPackage pkg = OPCPackage.create(PackageHelper.createTempFile());
|
||||||
// Main part
|
// Main part
|
||||||
PackagePartName corePartName = PackagingURIHelper.createPartName(XWPFRelation.DOCUMENT.getDefaultFileName());
|
PackagePartName corePartName = PackagingURIHelper.createPartName(XWPFRelation.DOCUMENT.getDefaultFileName());
|
||||||
// Create main part relationship
|
// Create main part relationship
|
||||||
|
@ -25,7 +25,7 @@ import org.apache.poi.util.IOUtils;
|
|||||||
import org.apache.poi.xslf.XSLFSlideShow;
|
import org.apache.poi.xslf.XSLFSlideShow;
|
||||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||||
import org.apache.poi.xwpf.usermodel.XWPFDocument;
|
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 org.apache.poi.openxml4j.opc.PackagePart;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
@ -47,7 +47,7 @@ public class TestEmbeded extends TestCase
|
|||||||
File f = new File(dirname, "ExcelWithAttachments.xlsx");
|
File f = new File(dirname, "ExcelWithAttachments.xlsx");
|
||||||
assertTrue(f.exists());
|
assertTrue(f.exists());
|
||||||
|
|
||||||
POIXMLDocument doc = new XSSFWorkbook(Package.open(f.toString()));
|
POIXMLDocument doc = new XSSFWorkbook(OPCPackage.open(f.toString()));
|
||||||
test(doc, 4);
|
test(doc, 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,7 +55,7 @@ public class TestEmbeded extends TestCase
|
|||||||
File f = new File(dirname, "WordWithAttachments.docx");
|
File f = new File(dirname, "WordWithAttachments.docx");
|
||||||
assertTrue(f.exists());
|
assertTrue(f.exists());
|
||||||
|
|
||||||
POIXMLDocument doc = new XWPFDocument(Package.open(f.toString()));
|
POIXMLDocument doc = new XWPFDocument(OPCPackage.open(f.toString()));
|
||||||
test(doc, 5);
|
test(doc, 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,7 +63,7 @@ public class TestEmbeded extends TestCase
|
|||||||
File f = new File(dirname, "PPTWithAttachments.pptx");
|
File f = new File(dirname, "PPTWithAttachments.pptx");
|
||||||
assertTrue(f.exists());
|
assertTrue(f.exists());
|
||||||
|
|
||||||
POIXMLDocument doc = new XSLFSlideShow(Package.open(f.toString()));
|
POIXMLDocument doc = new XSLFSlideShow(OPCPackage.open(f.toString()));
|
||||||
test(doc, 4);
|
test(doc, 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ import java.io.File;
|
|||||||
|
|
||||||
import org.apache.poi.xssf.extractor.XSSFExcelExtractor;
|
import org.apache.poi.xssf.extractor.XSSFExcelExtractor;
|
||||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
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;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
@ -33,7 +33,7 @@ public class TestXMLPropertiesTextExtractor extends TestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testGetFromMainExtractor() throws Exception {
|
public void testGetFromMainExtractor() throws Exception {
|
||||||
org.apache.poi.openxml4j.opc.Package pkg = Package.open(
|
OPCPackage pkg = OPCPackage.open(
|
||||||
(new File(dirname, "ExcelWithAttachments.xlsx")).toString()
|
(new File(dirname, "ExcelWithAttachments.xlsx")).toString()
|
||||||
);
|
);
|
||||||
XSSFWorkbook wb = new XSSFWorkbook(pkg);
|
XSSFWorkbook wb = new XSSFWorkbook(pkg);
|
||||||
@ -54,7 +54,7 @@ public class TestXMLPropertiesTextExtractor extends TestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testCore() throws Exception {
|
public void testCore() throws Exception {
|
||||||
org.apache.poi.openxml4j.opc.Package pkg = Package.open(
|
OPCPackage pkg = OPCPackage.open(
|
||||||
(new File(dirname, "ExcelWithAttachments.xlsx")).toString()
|
(new File(dirname, "ExcelWithAttachments.xlsx")).toString()
|
||||||
);
|
);
|
||||||
XSSFWorkbook wb = new XSSFWorkbook(pkg);
|
XSSFWorkbook wb = new XSSFWorkbook(pkg);
|
||||||
@ -71,7 +71,7 @@ public class TestXMLPropertiesTextExtractor extends TestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testExtended() throws Exception {
|
public void testExtended() throws Exception {
|
||||||
org.apache.poi.openxml4j.opc.Package pkg = Package.open(
|
OPCPackage pkg = OPCPackage.open(
|
||||||
(new File(dirname, "ExcelWithAttachments.xlsx")).toString()
|
(new File(dirname, "ExcelWithAttachments.xlsx")).toString()
|
||||||
);
|
);
|
||||||
XSSFWorkbook wb = new XSSFWorkbook(pkg);
|
XSSFWorkbook wb = new XSSFWorkbook(pkg);
|
||||||
|
@ -34,7 +34,7 @@ import org.apache.poi.xwpf.extractor.XWPFWordExtractor;
|
|||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
import org.apache.poi.openxml4j.exceptions.InvalidOperationException;
|
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
|
* Test that the extractor factory plays nicely
|
||||||
@ -276,34 +276,34 @@ public class TestExtractorFactory extends TestCase {
|
|||||||
public void testPackage() throws Exception {
|
public void testPackage() throws Exception {
|
||||||
// Excel
|
// Excel
|
||||||
assertTrue(
|
assertTrue(
|
||||||
ExtractorFactory.createExtractor(Package.open(xlsx.toString()))
|
ExtractorFactory.createExtractor(OPCPackage.open(xlsx.toString()))
|
||||||
instanceof XSSFExcelExtractor
|
instanceof XSSFExcelExtractor
|
||||||
);
|
);
|
||||||
assertTrue(
|
assertTrue(
|
||||||
ExtractorFactory.createExtractor(Package.open(xlsx.toString())).getText().length() > 200
|
ExtractorFactory.createExtractor(OPCPackage.open(xlsx.toString())).getText().length() > 200
|
||||||
);
|
);
|
||||||
|
|
||||||
// Word
|
// Word
|
||||||
assertTrue(
|
assertTrue(
|
||||||
ExtractorFactory.createExtractor(Package.open(docx.toString()))
|
ExtractorFactory.createExtractor(OPCPackage.open(docx.toString()))
|
||||||
instanceof XWPFWordExtractor
|
instanceof XWPFWordExtractor
|
||||||
);
|
);
|
||||||
assertTrue(
|
assertTrue(
|
||||||
ExtractorFactory.createExtractor(Package.open(docx.toString())).getText().length() > 120
|
ExtractorFactory.createExtractor(OPCPackage.open(docx.toString())).getText().length() > 120
|
||||||
);
|
);
|
||||||
|
|
||||||
// PowerPoint
|
// PowerPoint
|
||||||
assertTrue(
|
assertTrue(
|
||||||
ExtractorFactory.createExtractor(Package.open(pptx.toString()))
|
ExtractorFactory.createExtractor(OPCPackage.open(pptx.toString()))
|
||||||
instanceof XSLFPowerPointExtractor
|
instanceof XSLFPowerPointExtractor
|
||||||
);
|
);
|
||||||
assertTrue(
|
assertTrue(
|
||||||
ExtractorFactory.createExtractor(Package.open(pptx.toString())).getText().length() > 120
|
ExtractorFactory.createExtractor(OPCPackage.open(pptx.toString())).getText().length() > 120
|
||||||
);
|
);
|
||||||
|
|
||||||
// Text
|
// Text
|
||||||
try {
|
try {
|
||||||
ExtractorFactory.createExtractor(Package.open(txt.toString()));
|
ExtractorFactory.createExtractor(OPCPackage.open(txt.toString()));
|
||||||
fail();
|
fail();
|
||||||
} catch(InvalidOperationException e) {
|
} catch(InvalidOperationException e) {
|
||||||
// Good
|
// Good
|
||||||
|
@ -83,9 +83,9 @@ public final class TestListParts extends TestCase {
|
|||||||
public void testListParts() throws InvalidFormatException {
|
public void testListParts() throws InvalidFormatException {
|
||||||
InputStream is = OpenXML4JTestDataSamples.openSampleStream("sample.docx");
|
InputStream is = OpenXML4JTestDataSamples.openSampleStream("sample.docx");
|
||||||
|
|
||||||
Package p;
|
OPCPackage p;
|
||||||
try {
|
try {
|
||||||
p = Package.open(is);
|
p = OPCPackage.open(is);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,7 @@ public final class TestPackage extends TestCase {
|
|||||||
String originalFile = OpenXML4JTestDataSamples.getSampleFileName("TestPackageCommon.docx");
|
String originalFile = OpenXML4JTestDataSamples.getSampleFileName("TestPackageCommon.docx");
|
||||||
File targetFile = OpenXML4JTestDataSamples.getOutputFile("TestPackageOpenSaveTMP.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());
|
p.save(targetFile.getAbsoluteFile());
|
||||||
|
|
||||||
// Compare the original and newly saved document
|
// 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
|
// Zap the target file, in case of an earlier run
|
||||||
if(targetFile.exists()) targetFile.delete();
|
if(targetFile.exists()) targetFile.delete();
|
||||||
|
|
||||||
Package pkg = Package.create(targetFile);
|
OPCPackage pkg = OPCPackage.create(targetFile);
|
||||||
|
|
||||||
// Check it has content types for rels and xml
|
// Check it has content types for rels and xml
|
||||||
ContentTypeManager ctm = getContentTypeManager(pkg);
|
ContentTypeManager ctm = getContentTypeManager(pkg);
|
||||||
@ -105,7 +105,7 @@ public final class TestPackage extends TestCase {
|
|||||||
if(targetFile.exists()) targetFile.delete();
|
if(targetFile.exists()) targetFile.delete();
|
||||||
|
|
||||||
// Create a package
|
// Create a package
|
||||||
Package pkg = Package.create(targetFile);
|
OPCPackage pkg = OPCPackage.create(targetFile);
|
||||||
PackagePartName corePartName = PackagingURIHelper
|
PackagePartName corePartName = PackagingURIHelper
|
||||||
.createPartName("/word/document.xml");
|
.createPartName("/word/document.xml");
|
||||||
|
|
||||||
@ -145,7 +145,7 @@ public final class TestPackage extends TestCase {
|
|||||||
*/
|
*/
|
||||||
public void testCreatePackageWithCoreDocument() throws Exception {
|
public void testCreatePackageWithCoreDocument() throws Exception {
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
Package pkg = Package.create(baos);
|
OPCPackage pkg = OPCPackage.create(baos);
|
||||||
|
|
||||||
// Add a core document
|
// Add a core document
|
||||||
PackagePartName corePartName = PackagingURIHelper.createPartName("/xl/workbook.xml");
|
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"));
|
FileOutputStream fout = new FileOutputStream(File.createTempFile("testCreatePackageWithCoreDocument", ".zip"));
|
||||||
fout.write(baos.toByteArray());
|
fout.write(baos.toByteArray());
|
||||||
fout.close();
|
fout.close();
|
||||||
pkg = Package.open(new ByteArrayInputStream(baos.toByteArray()));
|
pkg = OPCPackage.open(new ByteArrayInputStream(baos.toByteArray()));
|
||||||
|
|
||||||
|
|
||||||
// Check still right
|
// Check still right
|
||||||
@ -210,7 +210,7 @@ public final class TestPackage extends TestCase {
|
|||||||
FileHelper.copyFile(inputFile, targetFile);
|
FileHelper.copyFile(inputFile, targetFile);
|
||||||
|
|
||||||
// Create a package
|
// Create a package
|
||||||
Package pkg = Package.open(targetFile.getAbsolutePath());
|
OPCPackage pkg = OPCPackage.open(targetFile.getAbsolutePath());
|
||||||
|
|
||||||
// Modify core part
|
// Modify core part
|
||||||
PackagePartName corePartName = PackagingURIHelper
|
PackagePartName corePartName = PackagingURIHelper
|
||||||
@ -263,7 +263,7 @@ public final class TestPackage extends TestCase {
|
|||||||
String originalFile = OpenXML4JTestDataSamples.getSampleFileName("TestPackageCommon.docx");
|
String originalFile = OpenXML4JTestDataSamples.getSampleFileName("TestPackageCommon.docx");
|
||||||
File targetFile = OpenXML4JTestDataSamples.getOutputFile("TestPackageOpenSaveTMP.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);
|
FileOutputStream fout = new FileOutputStream(targetFile);
|
||||||
p.save(fout);
|
p.save(fout);
|
||||||
fout.close();
|
fout.close();
|
||||||
@ -284,7 +284,7 @@ public final class TestPackage extends TestCase {
|
|||||||
|
|
||||||
FileInputStream finp = new FileInputStream(originalFile);
|
FileInputStream finp = new FileInputStream(originalFile);
|
||||||
|
|
||||||
Package p = Package.open(finp);
|
OPCPackage p = OPCPackage.open(finp);
|
||||||
|
|
||||||
assertNotNull(p);
|
assertNotNull(p);
|
||||||
assertNotNull(p.getRelationships());
|
assertNotNull(p.getRelationships());
|
||||||
@ -303,7 +303,7 @@ public final class TestPackage extends TestCase {
|
|||||||
File targetFile = OpenXML4JTestDataSamples.getOutputFile("TestPackageRemovePartRecursiveOUTPUT.docx");
|
File targetFile = OpenXML4JTestDataSamples.getOutputFile("TestPackageRemovePartRecursiveOUTPUT.docx");
|
||||||
File tempFile = OpenXML4JTestDataSamples.getOutputFile("TestPackageRemovePartRecursiveTMP.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(
|
p.removePartRecursive(PackagingURIHelper.createPartName(new URI(
|
||||||
"/word/document.xml")));
|
"/word/document.xml")));
|
||||||
p.save(tempFile.getAbsoluteFile());
|
p.save(tempFile.getAbsoluteFile());
|
||||||
@ -353,7 +353,7 @@ public final class TestPackage extends TestCase {
|
|||||||
|
|
||||||
String filepath = OpenXML4JTestDataSamples.getSampleFileName("sample.docx");
|
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
|
// Remove the core part
|
||||||
p.deletePart(PackagingURIHelper.createPartName("/word/document.xml"));
|
p.deletePart(PackagingURIHelper.createPartName("/word/document.xml"));
|
||||||
|
|
||||||
@ -391,7 +391,7 @@ public final class TestPackage extends TestCase {
|
|||||||
|
|
||||||
String filepath = OpenXML4JTestDataSamples.getSampleFileName("sample.docx");
|
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
|
// Remove the core part
|
||||||
p.deletePartRecursive(PackagingURIHelper.createPartName("/word/document.xml"));
|
p.deletePartRecursive(PackagingURIHelper.createPartName("/word/document.xml"));
|
||||||
|
|
||||||
@ -409,8 +409,8 @@ public final class TestPackage extends TestCase {
|
|||||||
p.revert();
|
p.revert();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ContentTypeManager getContentTypeManager(Package pkg) throws Exception {
|
private static ContentTypeManager getContentTypeManager(OPCPackage pkg) throws Exception {
|
||||||
Field f = Package.class.getDeclaredField("contentTypeManager");
|
Field f = OPCPackage.class.getDeclaredField("contentTypeManager");
|
||||||
f.setAccessible(true);
|
f.setAccessible(true);
|
||||||
return (ContentTypeManager)f.get(pkg);
|
return (ContentTypeManager)f.get(pkg);
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,7 @@ public final class TestPackageCoreProperties extends TestCase {
|
|||||||
public void testGetProperties() {
|
public void testGetProperties() {
|
||||||
try {
|
try {
|
||||||
// Open the package
|
// Open the package
|
||||||
Package p = Package.open(OpenXML4JTestDataSamples.openSampleStream("TestPackageCoreProperiesGetters.docx"));
|
OPCPackage p = OPCPackage.open(OpenXML4JTestDataSamples.openSampleStream("TestPackageCoreProperiesGetters.docx"));
|
||||||
compareProperties(p);
|
compareProperties(p);
|
||||||
p.revert();
|
p.revert();
|
||||||
} catch (OpenXML4JException e) {
|
} catch (OpenXML4JException e) {
|
||||||
@ -59,7 +59,7 @@ public final class TestPackageCoreProperties extends TestCase {
|
|||||||
File outputFile = OpenXML4JTestDataSamples.getOutputFile("TestPackageCoreProperiesSettersOUTPUT.docx");
|
File outputFile = OpenXML4JTestDataSamples.getOutputFile("TestPackageCoreProperiesSettersOUTPUT.docx");
|
||||||
|
|
||||||
// Open package
|
// 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'");
|
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
|
||||||
Date dateToInsert = df.parse("2007-05-12T08:00:00Z", new ParsePosition(
|
Date dateToInsert = df.parse("2007-05-12T08:00:00Z", new ParsePosition(
|
||||||
@ -86,13 +86,13 @@ public final class TestPackageCoreProperties extends TestCase {
|
|||||||
p.save(outputFile);
|
p.save(outputFile);
|
||||||
|
|
||||||
// Open the newly created file to check core properties saved values.
|
// 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);
|
compareProperties(p2);
|
||||||
p2.revert();
|
p2.revert();
|
||||||
outputFile.delete();
|
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'");
|
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
|
||||||
Date expectedDate = df.parse("2007-05-12T08:00:00Z", new ParsePosition(
|
Date expectedDate = df.parse("2007-05-12T08:00:00Z", new ParsePosition(
|
||||||
0));
|
0));
|
||||||
|
@ -41,13 +41,13 @@ public final class TestPackageThumbnail extends TestCase {
|
|||||||
File outputFile = OpenXML4JTestDataSamples.getOutputFile("TestPackageThumbnailOUTPUT.docx");
|
File outputFile = OpenXML4JTestDataSamples.getOutputFile("TestPackageThumbnailOUTPUT.docx");
|
||||||
|
|
||||||
// Open package
|
// Open package
|
||||||
Package p = Package.open(inputPath, PackageAccess.READ_WRITE);
|
OPCPackage p = OPCPackage.open(inputPath, PackageAccess.READ_WRITE);
|
||||||
p.addThumbnail(imagePath);
|
p.addThumbnail(imagePath);
|
||||||
// Save the package in the output directory
|
// Save the package in the output directory
|
||||||
p.save(outputFile);
|
p.save(outputFile);
|
||||||
|
|
||||||
// Open the newly created file to check core properties saved values.
|
// 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)
|
if (p2.getRelationshipsByType(PackageRelationshipTypes.THUMBNAIL)
|
||||||
.size() == 0)
|
.size() == 0)
|
||||||
fail("Thumbnail not added to the package !");
|
fail("Thumbnail not added to the package !");
|
||||||
|
@ -22,7 +22,7 @@ import junit.framework.TestCase;
|
|||||||
|
|
||||||
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
||||||
import org.apache.poi.openxml4j.opc.ContentTypes;
|
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.PackagePart;
|
||||||
import org.apache.poi.openxml4j.opc.PackagePartName;
|
import org.apache.poi.openxml4j.opc.PackagePartName;
|
||||||
import org.apache.poi.openxml4j.opc.PackagingURIHelper;
|
import org.apache.poi.openxml4j.opc.PackagingURIHelper;
|
||||||
@ -80,7 +80,7 @@ public class TestPackagingURIHelper extends TestCase {
|
|||||||
PackagePartName partNameToValid = PackagingURIHelper
|
PackagePartName partNameToValid = PackagingURIHelper
|
||||||
.createPartName("/word/media/image1.gif");
|
.createPartName("/word/media/image1.gif");
|
||||||
|
|
||||||
Package pkg = Package.create("DELETEIFEXISTS.docx");
|
OPCPackage pkg = OPCPackage.create("DELETEIFEXISTS.docx");
|
||||||
// Base part
|
// Base part
|
||||||
PackagePartName nameBase = PackagingURIHelper
|
PackagePartName nameBase = PackagingURIHelper
|
||||||
.createPartName("/word/document.xml");
|
.createPartName("/word/document.xml");
|
||||||
@ -101,7 +101,7 @@ public class TestPackagingURIHelper extends TestCase {
|
|||||||
PackagePartName partNameToValid = PackagingURIHelper
|
PackagePartName partNameToValid = PackagingURIHelper
|
||||||
.createPartName("/word/media/image1.gif");
|
.createPartName("/word/media/image1.gif");
|
||||||
|
|
||||||
Package pkg = Package.create("DELETEIFEXISTS.docx");
|
OPCPackage pkg = OPCPackage.create("DELETEIFEXISTS.docx");
|
||||||
// Base part
|
// Base part
|
||||||
PackagePartName nameBase = PackagingURIHelper
|
PackagePartName nameBase = PackagingURIHelper
|
||||||
.createPartName("/word/document.xml");
|
.createPartName("/word/document.xml");
|
||||||
|
@ -45,7 +45,7 @@ public class TestRelationships extends TestCase {
|
|||||||
*/
|
*/
|
||||||
public void testLoadRelationships() throws Exception {
|
public void testLoadRelationships() throws Exception {
|
||||||
InputStream is = OpenXML4JTestDataSamples.openSampleStream("sample.xlsx");
|
InputStream is = OpenXML4JTestDataSamples.openSampleStream("sample.xlsx");
|
||||||
Package pkg = Package.open(is);
|
OPCPackage pkg = OPCPackage.open(is);
|
||||||
logger.debug("1: " + pkg);
|
logger.debug("1: " + pkg);
|
||||||
PackageRelationshipCollection rels = pkg.getRelationshipsByType(PackageRelationshipTypes.CORE_DOCUMENT);
|
PackageRelationshipCollection rels = pkg.getRelationshipsByType(PackageRelationshipTypes.CORE_DOCUMENT);
|
||||||
PackageRelationship coreDocRelationship = rels.getRelationship(0);
|
PackageRelationship coreDocRelationship = rels.getRelationship(0);
|
||||||
@ -66,7 +66,7 @@ public class TestRelationships extends TestCase {
|
|||||||
*/
|
*/
|
||||||
public void testFetchFromCollection() throws Exception {
|
public void testFetchFromCollection() throws Exception {
|
||||||
InputStream is = OpenXML4JTestDataSamples.openSampleStream("ExcelWithHyperlinks.xlsx");
|
InputStream is = OpenXML4JTestDataSamples.openSampleStream("ExcelWithHyperlinks.xlsx");
|
||||||
Package pkg = Package.open(is);
|
OPCPackage pkg = OPCPackage.open(is);
|
||||||
PackagePart sheet = pkg.getPart(
|
PackagePart sheet = pkg.getPart(
|
||||||
PackagingURIHelper.createPartName(SHEET_WITH_COMMENTS));
|
PackagingURIHelper.createPartName(SHEET_WITH_COMMENTS));
|
||||||
assertNotNull(sheet);
|
assertNotNull(sheet);
|
||||||
@ -107,7 +107,7 @@ public class TestRelationships extends TestCase {
|
|||||||
*/
|
*/
|
||||||
public void testLoadExcelHyperlinkRelations() throws Exception {
|
public void testLoadExcelHyperlinkRelations() throws Exception {
|
||||||
InputStream is = OpenXML4JTestDataSamples.openSampleStream("ExcelWithHyperlinks.xlsx");
|
InputStream is = OpenXML4JTestDataSamples.openSampleStream("ExcelWithHyperlinks.xlsx");
|
||||||
Package pkg = Package.open(is);
|
OPCPackage pkg = OPCPackage.open(is);
|
||||||
PackagePart sheet = pkg.getPart(
|
PackagePart sheet = pkg.getPart(
|
||||||
PackagingURIHelper.createPartName(SHEET_WITH_COMMENTS));
|
PackagingURIHelper.createPartName(SHEET_WITH_COMMENTS));
|
||||||
assertNotNull(sheet);
|
assertNotNull(sheet);
|
||||||
@ -141,7 +141,7 @@ public class TestRelationships extends TestCase {
|
|||||||
*/
|
*/
|
||||||
public void testCreateExcelHyperlinkRelations() throws Exception {
|
public void testCreateExcelHyperlinkRelations() throws Exception {
|
||||||
String filepath = OpenXML4JTestDataSamples.getSampleFileName("ExcelWithHyperlinks.xlsx");
|
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(
|
PackagePart sheet = pkg.getPart(
|
||||||
PackagingURIHelper.createPartName(SHEET_WITH_COMMENTS));
|
PackagingURIHelper.createPartName(SHEET_WITH_COMMENTS));
|
||||||
assertNotNull(sheet);
|
assertNotNull(sheet);
|
||||||
@ -185,7 +185,7 @@ public class TestRelationships extends TestCase {
|
|||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
pkg.save(baos);
|
pkg.save(baos);
|
||||||
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
|
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
|
||||||
pkg = Package.open(bais);
|
pkg = OPCPackage.open(bais);
|
||||||
|
|
||||||
// Check again
|
// Check again
|
||||||
sheet = pkg.getPart(
|
sheet = pkg.getPart(
|
||||||
@ -208,7 +208,7 @@ public class TestRelationships extends TestCase {
|
|||||||
|
|
||||||
public void testCreateRelationsFromScratch() throws Exception {
|
public void testCreateRelationsFromScratch() throws Exception {
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
Package pkg = Package.create(baos);
|
OPCPackage pkg = OPCPackage.create(baos);
|
||||||
|
|
||||||
PackagePart partA =
|
PackagePart partA =
|
||||||
pkg.createPart(PackagingURIHelper.createPartName("/partA"), "text/plain");
|
pkg.createPart(PackagingURIHelper.createPartName("/partA"), "text/plain");
|
||||||
@ -235,7 +235,7 @@ public class TestRelationships extends TestCase {
|
|||||||
// Save, and re-load
|
// Save, and re-load
|
||||||
pkg.close();
|
pkg.close();
|
||||||
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
|
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
|
||||||
pkg = Package.open(bais);
|
pkg = OPCPackage.open(bais);
|
||||||
|
|
||||||
partA = pkg.getPart(PackagingURIHelper.createPartName("/partA"));
|
partA = pkg.getPart(PackagingURIHelper.createPartName("/partA"));
|
||||||
partB = pkg.getPart(PackagingURIHelper.createPartName("/partB"));
|
partB = pkg.getPart(PackagingURIHelper.createPartName("/partB"));
|
||||||
|
@ -29,7 +29,7 @@ import org.apache.poi.openxml4j.OpenXML4JTestDataSamples;
|
|||||||
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.exceptions.InvalidOperationException;
|
||||||
import org.apache.poi.openxml4j.opc.ContentTypes;
|
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.PackageRelationshipTypes;
|
||||||
import org.apache.poi.openxml4j.opc.PackagingURIHelper;
|
import org.apache.poi.openxml4j.opc.PackagingURIHelper;
|
||||||
import org.apache.poi.openxml4j.opc.TargetMode;
|
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 final class TestOPCComplianceCoreProperties extends TestCase {
|
||||||
|
|
||||||
public void testCorePropertiesPart() {
|
public void testCorePropertiesPart() {
|
||||||
Package pkg;
|
OPCPackage pkg;
|
||||||
try {
|
try {
|
||||||
InputStream is = OpenXML4JTestDataSamples.openComplianceSampleStream("OPCCompliance_CoreProperties_OnlyOneCorePropertiesPart.docx");
|
InputStream is = OpenXML4JTestDataSamples.openComplianceSampleStream("OPCCompliance_CoreProperties_OnlyOneCorePropertiesPart.docx");
|
||||||
pkg = Package.open(is);
|
pkg = OPCPackage.open(is);
|
||||||
} catch (InvalidFormatException e) {
|
} catch (InvalidFormatException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
@ -83,9 +83,9 @@ public final class TestOPCComplianceCoreProperties extends TestCase {
|
|||||||
private static String extractInvalidFormatMessage(String sampleNameSuffix) {
|
private static String extractInvalidFormatMessage(String sampleNameSuffix) {
|
||||||
|
|
||||||
InputStream is = OpenXML4JTestDataSamples.openComplianceSampleStream("OPCCompliance_CoreProperties_" + sampleNameSuffix);
|
InputStream is = OpenXML4JTestDataSamples.openComplianceSampleStream("OPCCompliance_CoreProperties_" + sampleNameSuffix);
|
||||||
Package pkg;
|
OPCPackage pkg;
|
||||||
try {
|
try {
|
||||||
pkg = Package.open(is);
|
pkg = OPCPackage.open(is);
|
||||||
} catch (InvalidFormatException e) {
|
} catch (InvalidFormatException e) {
|
||||||
// expected during successful test
|
// expected during successful test
|
||||||
return e.getMessage();
|
return e.getMessage();
|
||||||
@ -118,9 +118,9 @@ public final class TestOPCComplianceCoreProperties extends TestCase {
|
|||||||
*/
|
*/
|
||||||
public void testOnlyOneCorePropertiesPart_AddRelationship() {
|
public void testOnlyOneCorePropertiesPart_AddRelationship() {
|
||||||
InputStream is = OpenXML4JTestDataSamples.openComplianceSampleStream("OPCCompliance_CoreProperties_OnlyOneCorePropertiesPart.docx");
|
InputStream is = OpenXML4JTestDataSamples.openComplianceSampleStream("OPCCompliance_CoreProperties_OnlyOneCorePropertiesPart.docx");
|
||||||
Package pkg;
|
OPCPackage pkg;
|
||||||
try {
|
try {
|
||||||
pkg = Package.open(is);
|
pkg = OPCPackage.open(is);
|
||||||
} catch (InvalidFormatException e) {
|
} catch (InvalidFormatException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
@ -145,9 +145,9 @@ public final class TestOPCComplianceCoreProperties extends TestCase {
|
|||||||
*/
|
*/
|
||||||
public void testOnlyOneCorePropertiesPart_AddPart() {
|
public void testOnlyOneCorePropertiesPart_AddPart() {
|
||||||
String sampleFileName = OpenXML4JTestDataSamples.getComplianceSampleFileName("OPCCompliance_CoreProperties_OnlyOneCorePropertiesPart.docx");
|
String sampleFileName = OpenXML4JTestDataSamples.getComplianceSampleFileName("OPCCompliance_CoreProperties_OnlyOneCorePropertiesPart.docx");
|
||||||
Package pkg = null;
|
OPCPackage pkg = null;
|
||||||
try {
|
try {
|
||||||
pkg = Package.open(sampleFileName);
|
pkg = OPCPackage.open(sampleFileName);
|
||||||
} catch (InvalidFormatException e) {
|
} catch (InvalidFormatException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@ import junit.framework.TestCase;
|
|||||||
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.exceptions.InvalidOperationException;
|
||||||
import org.apache.poi.openxml4j.opc.ContentTypes;
|
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.PackagePartName;
|
||||||
import org.apache.poi.openxml4j.opc.PackageRelationshipTypes;
|
import org.apache.poi.openxml4j.opc.PackageRelationshipTypes;
|
||||||
import org.apache.poi.openxml4j.opc.PackagingURIHelper;
|
import org.apache.poi.openxml4j.opc.PackagingURIHelper;
|
||||||
@ -50,7 +50,7 @@ public class TestOPCCompliancePackageModel extends TestCase {
|
|||||||
* [M1.11]
|
* [M1.11]
|
||||||
*/
|
*/
|
||||||
public void testPartNameDerivationAdditionFailure() {
|
public void testPartNameDerivationAdditionFailure() {
|
||||||
Package pkg = Package.create("TODELETEIFEXIST.docx");
|
OPCPackage pkg = OPCPackage.create("TODELETEIFEXIST.docx");
|
||||||
try {
|
try {
|
||||||
PackagePartName name = PackagingURIHelper
|
PackagePartName name = PackagingURIHelper
|
||||||
.createPartName("/word/document.xml");
|
.createPartName("/word/document.xml");
|
||||||
@ -78,7 +78,7 @@ public class TestOPCCompliancePackageModel extends TestCase {
|
|||||||
String filepath = System.getProperty("openxml4j.compliance.input")
|
String filepath = System.getProperty("openxml4j.compliance.input")
|
||||||
+ File.separator + "OPCCompliance_DerivedPartNameFAIL.docx";
|
+ File.separator + "OPCCompliance_DerivedPartNameFAIL.docx";
|
||||||
try {
|
try {
|
||||||
Package.open(filepath);
|
OPCPackage.open(filepath);
|
||||||
} catch (InvalidFormatException e) {
|
} catch (InvalidFormatException e) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -93,7 +93,7 @@ public class TestOPCCompliancePackageModel extends TestCase {
|
|||||||
* part names.
|
* part names.
|
||||||
*/
|
*/
|
||||||
public void testAddPackageAlreadyAddFailure() throws Exception {
|
public void testAddPackageAlreadyAddFailure() throws Exception {
|
||||||
Package pkg = Package.create("DELETEIFEXISTS.docx");
|
OPCPackage pkg = OPCPackage.create("DELETEIFEXISTS.docx");
|
||||||
PackagePartName name1 = null;
|
PackagePartName name1 = null;
|
||||||
PackagePartName name2 = null;
|
PackagePartName name2 = null;
|
||||||
try {
|
try {
|
||||||
@ -117,7 +117,7 @@ public class TestOPCCompliancePackageModel extends TestCase {
|
|||||||
* part names.
|
* part names.
|
||||||
*/
|
*/
|
||||||
public void testAddPackageAlreadyAddFailure2() throws Exception {
|
public void testAddPackageAlreadyAddFailure2() throws Exception {
|
||||||
Package pkg = Package.create("DELETEIFEXISTS.docx");
|
OPCPackage pkg = OPCPackage.create("DELETEIFEXISTS.docx");
|
||||||
PackagePartName partName = null;
|
PackagePartName partName = null;
|
||||||
try {
|
try {
|
||||||
partName = PackagingURIHelper.createPartName("/word/document.xml");
|
partName = PackagingURIHelper.createPartName("/word/document.xml");
|
||||||
@ -142,7 +142,7 @@ public class TestOPCCompliancePackageModel extends TestCase {
|
|||||||
* relationship as invalid.
|
* relationship as invalid.
|
||||||
*/
|
*/
|
||||||
public void testAddRelationshipRelationshipsPartFailure() {
|
public void testAddRelationshipRelationshipsPartFailure() {
|
||||||
Package pkg = Package.create("DELETEIFEXISTS.docx");
|
OPCPackage pkg = OPCPackage.create("DELETEIFEXISTS.docx");
|
||||||
PackagePartName name1 = null;
|
PackagePartName name1 = null;
|
||||||
try {
|
try {
|
||||||
name1 = PackagingURIHelper
|
name1 = PackagingURIHelper
|
||||||
|
@ -24,7 +24,7 @@ import org.apache.poi.poifs.filesystem.POIFSFileSystem;
|
|||||||
import org.apache.poi.ss.usermodel.Workbook;
|
import org.apache.poi.ss.usermodel.Workbook;
|
||||||
import org.apache.poi.ss.usermodel.WorkbookFactory;
|
import org.apache.poi.ss.usermodel.WorkbookFactory;
|
||||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
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;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
@ -63,7 +63,7 @@ public class TestWorkbookFactory extends TestCase {
|
|||||||
|
|
||||||
// Package -> xssf
|
// Package -> xssf
|
||||||
wb = WorkbookFactory.create(
|
wb = WorkbookFactory.create(
|
||||||
Package.open(xlsx.toString())
|
OPCPackage.open(xlsx.toString())
|
||||||
);
|
);
|
||||||
assertNotNull(wb);
|
assertNotNull(wb);
|
||||||
assertTrue(wb instanceof XSSFWorkbook);
|
assertTrue(wb instanceof XSSFWorkbook);
|
||||||
|
@ -18,14 +18,14 @@ package org.apache.poi.xslf;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
import org.apache.poi.POIXMLDocument;
|
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.apache.poi.openxml4j.opc.PackagePart;
|
||||||
import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideIdListEntry;
|
import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideIdListEntry;
|
||||||
import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideMasterIdListEntry;
|
import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideMasterIdListEntry;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
|
||||||
|
|
||||||
public class TestXSLFSlideShow extends TestCase {
|
public class TestXSLFSlideShow extends TestCase {
|
||||||
private String sampleFile;
|
private String sampleFile;
|
||||||
|
|
||||||
@ -39,7 +39,7 @@ public class TestXSLFSlideShow extends TestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testContainsMainContentType() throws Exception {
|
public void testContainsMainContentType() throws Exception {
|
||||||
Package pack = POIXMLDocument.openPackage(sampleFile);
|
OPCPackage pack = POIXMLDocument.openPackage(sampleFile);
|
||||||
|
|
||||||
boolean found = false;
|
boolean found = false;
|
||||||
for(PackagePart part : pack.getParts()) {
|
for(PackagePart part : pack.getParts()) {
|
||||||
|
@ -17,14 +17,19 @@
|
|||||||
|
|
||||||
package org.apache.poi.xssf;
|
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.HSSFTestDataSamples;
|
||||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
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.ss.usermodel.Workbook;
|
||||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
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.
|
* 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) {
|
public static final XSSFWorkbook openSampleWorkbook(String sampleName) {
|
||||||
InputStream is = HSSFTestDataSamples.openSampleFileStream(sampleName);
|
InputStream is = HSSFTestDataSamples.openSampleFileStream(sampleName);
|
||||||
try {
|
try {
|
||||||
Package pkg = Package.open(is);
|
OPCPackage pkg = OPCPackage.open(is);
|
||||||
return new XSSFWorkbook(pkg);
|
return new XSSFWorkbook(pkg);
|
||||||
} catch (InvalidFormatException e) {
|
} catch (InvalidFormatException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
@ -57,7 +62,7 @@ public class XSSFTestDataSamples {
|
|||||||
FileOutputStream out = new FileOutputStream(tmp);
|
FileOutputStream out = new FileOutputStream(tmp);
|
||||||
wb.write(out);
|
wb.write(out);
|
||||||
out.close();
|
out.close();
|
||||||
Package pkg = Package.open(tmp.getAbsolutePath());
|
OPCPackage pkg = OPCPackage.open(tmp.getAbsolutePath());
|
||||||
result = new XSSFWorkbook(pkg);
|
result = new XSSFWorkbook(pkg);
|
||||||
} else {
|
} else {
|
||||||
throw new RuntimeException("Unexpected workbook type ("
|
throw new RuntimeException("Unexpected workbook type ("
|
||||||
|
@ -25,7 +25,7 @@ import junit.framework.TestCase;
|
|||||||
|
|
||||||
import org.apache.poi.util.IOUtils;
|
import org.apache.poi.util.IOUtils;
|
||||||
import org.apache.poi.xssf.usermodel.XSSFRichTextString;
|
import org.apache.poi.xssf.usermodel.XSSFRichTextString;
|
||||||
import org.apache.poi.openxml4j.opc.Package;
|
import org.apache.poi.openxml4j.opc.OPCPackage;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for XSSFReader
|
* Tests for XSSFReader
|
||||||
@ -49,7 +49,7 @@ public class TestXSSFReader extends TestCase {
|
|||||||
|
|
||||||
public void testGetBits() throws Exception {
|
public void testGetBits() throws Exception {
|
||||||
File f = new File(dirName, "SampleSS.xlsx");
|
File f = new File(dirName, "SampleSS.xlsx");
|
||||||
Package pkg = Package.open(f.toString());
|
OPCPackage pkg = OPCPackage.open(f.toString());
|
||||||
|
|
||||||
XSSFReader r = new XSSFReader(pkg);
|
XSSFReader r = new XSSFReader(pkg);
|
||||||
|
|
||||||
@ -63,7 +63,7 @@ public class TestXSSFReader extends TestCase {
|
|||||||
|
|
||||||
public void testStyles() throws Exception {
|
public void testStyles() throws Exception {
|
||||||
File f = new File(dirName, "SampleSS.xlsx");
|
File f = new File(dirName, "SampleSS.xlsx");
|
||||||
Package pkg = Package.open(f.toString());
|
OPCPackage pkg = OPCPackage.open(f.toString());
|
||||||
|
|
||||||
XSSFReader r = new XSSFReader(pkg);
|
XSSFReader r = new XSSFReader(pkg);
|
||||||
|
|
||||||
@ -73,7 +73,7 @@ public class TestXSSFReader extends TestCase {
|
|||||||
|
|
||||||
public void testStrings() throws Exception {
|
public void testStrings() throws Exception {
|
||||||
File f = new File(dirName, "SampleSS.xlsx");
|
File f = new File(dirName, "SampleSS.xlsx");
|
||||||
Package pkg = Package.open(f.toString());
|
OPCPackage pkg = OPCPackage.open(f.toString());
|
||||||
|
|
||||||
XSSFReader r = new XSSFReader(pkg);
|
XSSFReader r = new XSSFReader(pkg);
|
||||||
|
|
||||||
@ -83,7 +83,7 @@ public class TestXSSFReader extends TestCase {
|
|||||||
|
|
||||||
public void testSheets() throws Exception {
|
public void testSheets() throws Exception {
|
||||||
File f = new File(dirName, "SampleSS.xlsx");
|
File f = new File(dirName, "SampleSS.xlsx");
|
||||||
Package pkg = Package.open(f.toString());
|
OPCPackage pkg = OPCPackage.open(f.toString());
|
||||||
|
|
||||||
XSSFReader r = new XSSFReader(pkg);
|
XSSFReader r = new XSSFReader(pkg);
|
||||||
byte[] data = new byte[4096];
|
byte[] data = new byte[4096];
|
||||||
@ -116,7 +116,7 @@ public class TestXSSFReader extends TestCase {
|
|||||||
*/
|
*/
|
||||||
public void testOrderOfSheets() throws Exception {
|
public void testOrderOfSheets() throws Exception {
|
||||||
File f = new File(dirName, "reordered_sheets.xlsx");
|
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);
|
XSSFReader r = new XSSFReader(pkg);
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ import org.apache.poi.xssf.usermodel.XSSFSheet;
|
|||||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||||
import org.apache.poi.xssf.XSSFTestDataSamples;
|
import org.apache.poi.xssf.XSSFTestDataSamples;
|
||||||
import org.apache.poi.POIXMLDocumentPart;
|
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 org.openxmlformats.schemas.spreadsheetml.x2006.main.*;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
@ -125,7 +125,7 @@ public class TestCommentsTable extends TestCase {
|
|||||||
);
|
);
|
||||||
assertTrue(xml.exists());
|
assertTrue(xml.exists());
|
||||||
|
|
||||||
Package pkg = Package.open(xml.toString());
|
OPCPackage pkg = OPCPackage.open(xml.toString());
|
||||||
XSSFWorkbook wb = new XSSFWorkbook(pkg);
|
XSSFWorkbook wb = new XSSFWorkbook(pkg);
|
||||||
List<POIXMLDocumentPart> rels = wb.getSheetAt(0).getRelations();
|
List<POIXMLDocumentPart> rels = wb.getSheetAt(0).getRelations();
|
||||||
CommentsTable ct = null;
|
CommentsTable ct = null;
|
||||||
|
@ -32,7 +32,7 @@ import org.apache.poi.ss.usermodel.CellValue;
|
|||||||
import org.apache.poi.ss.usermodel.FormulaEvaluator;
|
import org.apache.poi.ss.usermodel.FormulaEvaluator;
|
||||||
import org.apache.poi.ss.usermodel.Row;
|
import org.apache.poi.ss.usermodel.Row;
|
||||||
import org.apache.poi.ss.usermodel.Sheet;
|
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},
|
* Performs much the same role as {@link TestFormulasFromSpreadsheet},
|
||||||
@ -149,7 +149,7 @@ public final class TestFormulaEvaluatorOnXSSF extends TestCase {
|
|||||||
protected void setUp() throws Exception {
|
protected void setUp() throws Exception {
|
||||||
if (workbook == null) {
|
if (workbook == null) {
|
||||||
InputStream is = HSSFTestDataSamples.openSampleFileStream(SS.FILENAME);
|
InputStream is = HSSFTestDataSamples.openSampleFileStream(SS.FILENAME);
|
||||||
Package pkg = Package.open(is);
|
OPCPackage pkg = OPCPackage.open(is);
|
||||||
workbook = new XSSFWorkbook( pkg );
|
workbook = new XSSFWorkbook( pkg );
|
||||||
sheet = workbook.getSheetAt( 0 );
|
sheet = workbook.getSheetAt( 0 );
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,8 @@ import java.io.File;
|
|||||||
|
|
||||||
import junit.framework.TestCase;
|
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.PackagePart;
|
||||||
import org.apache.poi.openxml4j.opc.PackagingURIHelper;
|
import org.apache.poi.openxml4j.opc.PackagingURIHelper;
|
||||||
import org.apache.poi.xssf.XSSFTestDataSamples;
|
import org.apache.poi.xssf.XSSFTestDataSamples;
|
||||||
@ -71,7 +72,7 @@ public class TestXSSFBugs extends TestCase {
|
|||||||
* We should carry vba macros over after save
|
* We should carry vba macros over after save
|
||||||
*/
|
*/
|
||||||
public void test45431() throws Exception {
|
public void test45431() throws Exception {
|
||||||
Package pkg = Package.open(getFilePath("45431.xlsm"));
|
OPCPackage pkg = OPCPackage.open(getFilePath("45431.xlsm"));
|
||||||
XSSFWorkbook wb = new XSSFWorkbook(pkg);
|
XSSFWorkbook wb = new XSSFWorkbook(pkg);
|
||||||
assertTrue(wb.isMacroEnabled());
|
assertTrue(wb.isMacroEnabled());
|
||||||
|
|
||||||
@ -89,7 +90,7 @@ public class TestXSSFBugs extends TestCase {
|
|||||||
|
|
||||||
// Save and re-open, both still there
|
// Save and re-open, both still there
|
||||||
XSSFWorkbook nwb = XSSFTestDataSamples.writeOutAndReadBack(wb);
|
XSSFWorkbook nwb = XSSFTestDataSamples.writeOutAndReadBack(wb);
|
||||||
Package nPkg = nwb.getPackage();
|
OPCPackage nPkg = nwb.getPackage();
|
||||||
assertTrue(nwb.isMacroEnabled());
|
assertTrue(nwb.isMacroEnabled());
|
||||||
|
|
||||||
vba = nPkg.getPart(
|
vba = nPkg.getPart(
|
||||||
|
@ -16,12 +16,14 @@
|
|||||||
==================================================================== */
|
==================================================================== */
|
||||||
package org.apache.poi.xssf.usermodel;
|
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 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
|
* @author Yegor Kozlov
|
||||||
*/
|
*/
|
||||||
@ -71,7 +73,7 @@ public class TestXSSFDrawing extends TestCase {
|
|||||||
XSSFSheet sheet = wb.createSheet();
|
XSSFSheet sheet = wb.createSheet();
|
||||||
XSSFDrawing drawing = sheet.createDrawingPatriarch();
|
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());
|
assertEquals(3, pkg.getPartsByContentType(XSSFRelation.DRAWINGS.getContentType()).size());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,7 @@ import org.apache.poi.ss.util.CellRangeAddress;
|
|||||||
import org.apache.poi.xssf.XSSFTestDataSamples;
|
import org.apache.poi.xssf.XSSFTestDataSamples;
|
||||||
import org.apache.poi.xssf.model.StylesTable;
|
import org.apache.poi.xssf.model.StylesTable;
|
||||||
import org.apache.poi.openxml4j.opc.ContentTypes;
|
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.PackagePart;
|
||||||
import org.apache.poi.openxml4j.opc.PackagingURIHelper;
|
import org.apache.poi.openxml4j.opc.PackagingURIHelper;
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheet;
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheet;
|
||||||
@ -251,7 +251,7 @@ public final class TestXSSFWorkbook extends TestCase {
|
|||||||
out.close();
|
out.close();
|
||||||
|
|
||||||
// Check the package contains what we'd expect it to
|
// Check the package contains what we'd expect it to
|
||||||
Package pkg = Package.open(file.toString());
|
OPCPackage pkg = OPCPackage.open(file.toString());
|
||||||
PackagePart wbRelPart =
|
PackagePart wbRelPart =
|
||||||
pkg.getPart(PackagingURIHelper.createPartName("/xl/_rels/workbook.xml.rels"));
|
pkg.getPart(PackagingURIHelper.createPartName("/xl/_rels/workbook.xml.rels"));
|
||||||
assertNotNull(wbRelPart);
|
assertNotNull(wbRelPart);
|
||||||
@ -293,7 +293,7 @@ public final class TestXSSFWorkbook extends TestCase {
|
|||||||
assertNotNull(workbook.getStylesSource());
|
assertNotNull(workbook.getStylesSource());
|
||||||
|
|
||||||
// And check a few low level bits too
|
// 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 =
|
PackagePart wbPart =
|
||||||
pkg.getPart(PackagingURIHelper.createPartName("/xl/workbook.xml"));
|
pkg.getPart(PackagingURIHelper.createPartName("/xl/workbook.xml"));
|
||||||
|
|
||||||
|
@ -18,13 +18,13 @@ package org.apache.poi.xwpf;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
import org.apache.poi.POIXMLDocument;
|
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.XWPFDocument;
|
||||||
import org.apache.poi.xwpf.usermodel.XWPFRelation;
|
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 {
|
public class TestXWPFDocument extends TestCase {
|
||||||
private File sampleFile;
|
private File sampleFile;
|
||||||
@ -47,7 +47,7 @@ public class TestXWPFDocument extends TestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testContainsMainContentType() throws Exception {
|
public void testContainsMainContentType() throws Exception {
|
||||||
Package pack = POIXMLDocument.openPackage(sampleFile.toString());
|
OPCPackage pack = POIXMLDocument.openPackage(sampleFile.toString());
|
||||||
|
|
||||||
boolean found = false;
|
boolean found = false;
|
||||||
for(PackagePart part : pack.getParts()) {
|
for(PackagePart part : pack.getParts()) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user