aboutsummaryrefslogtreecommitdiffstats
path: root/src/ooxml/java/org
diff options
context:
space:
mode:
authorAndreas Beeker <kiwiwings@apache.org>2018-05-27 22:01:33 +0000
committerAndreas Beeker <kiwiwings@apache.org>2018-05-27 22:01:33 +0000
commit0c35761317208529c8855025017e7953d7d101cd (patch)
treeca3b2db6b6dbf0d28f6306305ee37721ac20f018 /src/ooxml/java/org
parent6ce329eca43ad902a132cf86e7b9853f652fc3c1 (diff)
downloadpoi-0c35761317208529c8855025017e7953d7d101cd.tar.gz
poi-0c35761317208529c8855025017e7953d7d101cd.zip
#62355 - unsplit packages - 2 - modified classes (not only imports)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1832359 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/ooxml/java/org')
-rw-r--r--src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlideShowFactory.java27
-rw-r--r--src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFObjectData.java9
-rw-r--r--src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbookFactory.java134
3 files changed, 168 insertions, 2 deletions
diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlideShowFactory.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlideShowFactory.java
index 501132c00c..c62e24134d 100644
--- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlideShowFactory.java
+++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlideShowFactory.java
@@ -32,6 +32,33 @@ import org.apache.poi.util.Internal;
public class XSLFSlideShowFactory extends SlideShowFactory {
/**
+ * Creates a XMLSlideShow from the given OOXML Package.
+ * This is a convenience method to go along the create-methods of the super class.
+ *
+ * <p>Note that in order to properly release resources the
+ * SlideShow should be closed after use.</p>
+ *
+ * @param pkg The {@link OPCPackage} opened for reading data.
+ *
+ * @return The created SlideShow
+ *
+ * @throws IOException if an error occurs while reading the data
+ * @throws InvalidFormatException
+ */
+ public static XMLSlideShow create(OPCPackage pkg) throws IOException {
+ try {
+ return new XMLSlideShow(pkg);
+ } catch (IllegalArgumentException ioe) {
+ // ensure that file handles are closed (use revert() to not re-write the file)
+ pkg.revert();
+ //pkg.close();
+
+ // rethrow exception
+ throw ioe;
+ }
+ }
+
+ /**
* Creates a XMLSlideShow from the given OOXML Package
*
* <p>Note that in order to properly release resources the
diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFObjectData.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFObjectData.java
index c20d8d44cc..0544800e67 100644
--- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFObjectData.java
+++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFObjectData.java
@@ -23,8 +23,8 @@ import java.io.InputStream;
import javax.xml.namespace.QName;
-import org.apache.poi.POIXMLDocumentPart;
-import org.apache.poi.POIXMLException;
+import org.apache.poi.ooxml.POIXMLDocumentPart;
+import org.apache.poi.ooxml.POIXMLException;
import org.apache.poi.openxml4j.opc.PackagePart;
import org.apache.poi.openxml4j.opc.PackageRelationshipTypes;
import org.apache.poi.poifs.filesystem.DirectoryEntry;
@@ -202,4 +202,9 @@ public class XSSFObjectData extends XSSFSimpleShape implements ObjectData {
cur.dispose();
}
}
+
+ @Override
+ public String getContentType() {
+ return getObjectPart().getContentType();
+ }
}
diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbookFactory.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbookFactory.java
new file mode 100644
index 0000000000..4bb6acc59a
--- /dev/null
+++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbookFactory.java
@@ -0,0 +1,134 @@
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.xssf.usermodel;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.apache.poi.EncryptedDocumentException;
+import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
+import org.apache.poi.openxml4j.opc.OPCPackage;
+import org.apache.poi.openxml4j.opc.PackageAccess;
+import org.apache.poi.openxml4j.opc.ZipPackage;
+import org.apache.poi.ss.usermodel.WorkbookFactory;
+
+public class XSSFWorkbookFactory extends WorkbookFactory {
+
+ /**
+ * Creates a XSSFWorkbook from the given OOXML Package.
+ * This is a convenience method to go along the create-methods of the super class.
+ *
+ * <p>Note that in order to properly release resources the
+ * Workbook should be closed after use.</p>
+ *
+ * @param pkg The {@link OPCPackage} opened for reading data.
+ *
+ * @return The created Workbook
+ *
+ * @throws IOException if an error occurs while reading the data
+ * @throws InvalidFormatException
+ */
+ public static XSSFWorkbook create(OPCPackage pkg) throws IOException {
+ return createWorkbook(pkg);
+ }
+
+ /**
+ * Creates a XSSFWorkbook from the given OOXML Package
+ *
+ * <p>Note that in order to properly release resources the
+ * Workbook should be closed after use.</p>
+ *
+ * @param pkg The {@link ZipPackage} opened for reading data.
+ *
+ * @return The created Workbook
+ *
+ * @throws IOException if an error occurs while reading the data
+ * @throws InvalidFormatException
+ */
+ public static XSSFWorkbook createWorkbook(ZipPackage pkg) throws IOException {
+ return createWorkbook((OPCPackage)pkg);
+ }
+
+ /**
+ * Creates a XSSFWorkbook from the given OOXML Package
+ *
+ * <p>Note that in order to properly release resources the
+ * Workbook should be closed after use.</p>
+ *
+ * @param pkg The {@link OPCPackage} opened for reading data.
+ *
+ * @return The created Workbook
+ *
+ * @throws IOException if an error occurs while reading the data
+ * @throws InvalidFormatException
+ */
+ public static XSSFWorkbook createWorkbook(OPCPackage pkg) throws IOException {
+ try {
+ return new XSSFWorkbook(pkg);
+ } catch (IllegalArgumentException ioe) {
+ // ensure that file handles are closed (use revert() to not re-write the file)
+ pkg.revert();
+ //pkg.close();
+
+ // rethrow exception
+ throw ioe;
+ }
+ }
+
+ /**
+ * Creates the XSSFWorkbook from the given File, which must exist and be readable.
+ * <p>Note that in order to properly release resources the Workbook should be closed after use.
+ *
+ * @param file The file to read data from.
+ * @param readOnly If the Workbook should be opened in read-only mode to avoid writing back
+ * changes when the document is closed.
+ *
+ * @return The created Workbook
+ *
+ * @throws IOException if an error occurs while reading the data
+ * @throws EncryptedDocumentException If the wrong password is given for a protected file
+ */
+ @SuppressWarnings("resource")
+ public static XSSFWorkbook createWorkbook(File file, boolean readOnly)
+ throws IOException, InvalidFormatException {
+ OPCPackage pkg = OPCPackage.open(file, readOnly ? PackageAccess.READ : PackageAccess.READ_WRITE);
+ return createWorkbook(pkg);
+ }
+
+ /**
+ * Creates a XSSFWorkbook from the given InputStream
+ *
+ * <p>Note that in order to properly release resources the
+ * Workbook should be closed after use.</p>
+ *
+ * @param stream The {@link InputStream} to read data from.
+ *
+ * @return The created Workbook
+ *
+ * @throws IOException if an error occurs while reading the data
+ * @throws InvalidFormatException
+ */
+ @SuppressWarnings("resource")
+ public static XSSFWorkbook createWorkbook(InputStream stream) throws IOException, InvalidFormatException {
+ OPCPackage pkg = OPCPackage.open(stream);
+ return createWorkbook(pkg);
+ }
+
+
+}