#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
This commit is contained in:
parent
54f191b613
commit
1c0834c436
18
build.xml
18
build.xml
@ -869,7 +869,7 @@ under the License.
|
|||||||
|
|
||||||
<replace dir="${xmlbean.sources.dir}" includes="**/*.java" excludes="**/impl/**">
|
<replace dir="${xmlbean.sources.dir}" includes="**/*.java" excludes="**/impl/**">
|
||||||
<replacetoken>org.apache.xmlbeans.XmlBeans.getContextTypeLoader()</replacetoken>
|
<replacetoken>org.apache.xmlbeans.XmlBeans.getContextTypeLoader()</replacetoken>
|
||||||
<replacevalue>org.apache.poi.POIXMLTypeLoader</replacevalue>
|
<replacevalue>org.apache.poi.ooxml.POIXMLTypeLoader</replacevalue>
|
||||||
</replace>
|
</replace>
|
||||||
|
|
||||||
<!-- remove deprecated warnings, as we prefer the array methods - see #56854 -->
|
<!-- remove deprecated warnings, as we prefer the array methods - see #56854 -->
|
||||||
@ -880,9 +880,9 @@ under the License.
|
|||||||
|
|
||||||
<copy todir="${xmlbean.sources.dir}">
|
<copy todir="${xmlbean.sources.dir}">
|
||||||
<fileset dir="${ooxml.src}">
|
<fileset dir="${ooxml.src}">
|
||||||
<include name="org/apache/poi/POIXMLTypeLoader.java"/>
|
<include name="org/apache/poi/ooxml/POIXMLTypeLoader.java"/>
|
||||||
<include name="org/apache/poi/util/DocumentHelper.java"/>
|
<include name="org/apache/poi/ooxml/util/DocumentHelper.java"/>
|
||||||
<include name="org/apache/poi/util/SAXHelper.java"/>
|
<include name="org/apache/poi/ooxml/util/SAXHelper.java"/>
|
||||||
<include name="org/apache/poi/openxml4j/opc/PackageNamespaces.java"/>
|
<include name="org/apache/poi/openxml4j/opc/PackageNamespaces.java"/>
|
||||||
</fileset>
|
</fileset>
|
||||||
<fileset dir="${main.src}">
|
<fileset dir="${main.src}">
|
||||||
@ -907,10 +907,6 @@ under the License.
|
|||||||
includeantruntime="false">
|
includeantruntime="false">
|
||||||
<!-- debug="${compile.debug}" -->
|
<!-- debug="${compile.debug}" -->
|
||||||
<classpath refid="ooxml.classpath"/>
|
<classpath refid="ooxml.classpath"/>
|
||||||
|
|
||||||
<!-- unfortunately JUnit is required here for OOXMLLite, we should rather move OOXMLLite
|
|
||||||
to test or a separate folder to clean up dependencies -->
|
|
||||||
<classpath location="${main.junit.jar}"/>
|
|
||||||
</javac>
|
</javac>
|
||||||
|
|
||||||
<jar basedir="${xmlbean.classes.dir}" destfile="@{classes-jar}" excludes="org/apache/**" level="9" />
|
<jar basedir="${xmlbean.classes.dir}" destfile="@{classes-jar}" excludes="org/apache/**" level="9" />
|
||||||
@ -1081,10 +1077,6 @@ under the License.
|
|||||||
<classpath>
|
<classpath>
|
||||||
<path refid="ooxml.classpath"/>
|
<path refid="ooxml.classpath"/>
|
||||||
<path refid="ooxml.xmlsec.classpath"/>
|
<path refid="ooxml.xmlsec.classpath"/>
|
||||||
|
|
||||||
<!-- unfortunately JUnit is required here for OOXMLLite, we should rather move OOXMLLite
|
|
||||||
to test or a separate folder to clean up dependencies -->
|
|
||||||
<pathelement location="${main.junit.jar}"/>
|
|
||||||
</classpath>
|
</classpath>
|
||||||
</javac>
|
</javac>
|
||||||
<!-- compile the tests -->
|
<!-- compile the tests -->
|
||||||
@ -1562,7 +1554,7 @@ under the License.
|
|||||||
<zipfileset includes="**/*" src="${ooxml.security.jar}"/>
|
<zipfileset includes="**/*" src="${ooxml.security.jar}"/>
|
||||||
</jar>
|
</jar>
|
||||||
|
|
||||||
<java classname="org.apache.poi.util.OOXMLLite" fork="yes"
|
<java classname="org.apache.poi.ooxml.util.OOXMLLite" fork="yes"
|
||||||
failonerror="true">
|
failonerror="true">
|
||||||
<classpath>
|
<classpath>
|
||||||
<pathelement path="${ooxml.lite-merged.dir}/ooxml-lite-merged.jar"/>
|
<pathelement path="${ooxml.lite-merged.dir}/ooxml-lite-merged.jar"/>
|
||||||
|
@ -155,11 +155,11 @@
|
|||||||
<version>1.05</version>
|
<version>1.05</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- non-test dependency for OOXMLLite -->
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>junit</groupId>
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>junit</artifactId>
|
||||||
<version>${junit.version}</version>
|
<version>${junit.version}</version>
|
||||||
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
|
@ -261,7 +261,7 @@
|
|||||||
<target>
|
<target>
|
||||||
<replace dir="${basedir}/target/generated-sources/xmlbeans" includes="**/*.java" excludes="**/impl/**">
|
<replace dir="${basedir}/target/generated-sources/xmlbeans" includes="**/*.java" excludes="**/impl/**">
|
||||||
<replacetoken>org.apache.xmlbeans.XmlBeans.getContextTypeLoader()</replacetoken>
|
<replacetoken>org.apache.xmlbeans.XmlBeans.getContextTypeLoader()</replacetoken>
|
||||||
<replacevalue>org.apache.poi.POIXMLTypeLoader</replacevalue>
|
<replacevalue>org.apache.poi.ooxml.POIXMLTypeLoader</replacevalue>
|
||||||
</replace>
|
</replace>
|
||||||
</target>
|
</target>
|
||||||
</configuration>
|
</configuration>
|
||||||
|
@ -48,12 +48,8 @@ public abstract class SpreadsheetHandler extends AbstractFileHandler {
|
|||||||
ByteArrayOutputStream out = writeToArray(wb);
|
ByteArrayOutputStream out = writeToArray(wb);
|
||||||
|
|
||||||
// read in the written file
|
// read in the written file
|
||||||
Workbook read;
|
Workbook read = WorkbookFactory.create(new ByteArrayInputStream(out.toByteArray()));
|
||||||
try {
|
|
||||||
read = WorkbookFactory.create(new ByteArrayInputStream(out.toByteArray()));
|
|
||||||
} catch (InvalidFormatException e) {
|
|
||||||
throw new IllegalStateException(e);
|
|
||||||
}
|
|
||||||
assertNotNull(read);
|
assertNotNull(read);
|
||||||
|
|
||||||
readContent(read);
|
readContent(read);
|
||||||
|
@ -27,8 +27,6 @@ import java.util.Iterator;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.poi.EncryptedDocumentException;
|
import org.apache.poi.EncryptedDocumentException;
|
||||||
import org.apache.poi.POIOLE2TextExtractor;
|
|
||||||
import org.apache.poi.POITextExtractor;
|
|
||||||
import org.apache.poi.hssf.OldExcelFormatException;
|
import org.apache.poi.hssf.OldExcelFormatException;
|
||||||
import org.apache.poi.hssf.extractor.EventBasedExcelExtractor;
|
import org.apache.poi.hssf.extractor.EventBasedExcelExtractor;
|
||||||
import org.apache.poi.hssf.extractor.ExcelExtractor;
|
import org.apache.poi.hssf.extractor.ExcelExtractor;
|
||||||
@ -108,7 +106,7 @@ public class OLE2ExtractorFactory {
|
|||||||
* Should this thread use event based extractors is available?
|
* Should this thread use event based extractors is available?
|
||||||
* Checks the all-threads one first, then thread specific.
|
* Checks the all-threads one first, then thread specific.
|
||||||
*/
|
*/
|
||||||
protected static boolean getPreferEventExtractor() {
|
public static boolean getPreferEventExtractor() {
|
||||||
if(allPreferEventExtractors != null) {
|
if(allPreferEventExtractors != null) {
|
||||||
return allPreferEventExtractors;
|
return allPreferEventExtractors;
|
||||||
}
|
}
|
||||||
@ -156,7 +154,7 @@ public class OLE2ExtractorFactory {
|
|||||||
private static Class<?> getScratchpadClass() {
|
private static Class<?> getScratchpadClass() {
|
||||||
try {
|
try {
|
||||||
return OLE2ExtractorFactory.class.getClassLoader().loadClass(
|
return OLE2ExtractorFactory.class.getClassLoader().loadClass(
|
||||||
"org.apache.poi.extractor.OLE2ScratchpadExtractorFactory"
|
"org.apache.poi.extractor.ole2.OLE2ScratchpadExtractorFactory"
|
||||||
);
|
);
|
||||||
} catch (ClassNotFoundException e) {
|
} catch (ClassNotFoundException e) {
|
||||||
LOGGER.log(POILogger.ERROR, "POI Scratchpad jar missing");
|
LOGGER.log(POILogger.ERROR, "POI Scratchpad jar missing");
|
||||||
|
@ -0,0 +1,50 @@
|
|||||||
|
/* ====================================================================
|
||||||
|
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.hssf.usermodel;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.apache.poi.poifs.filesystem.DirectoryNode;
|
||||||
|
import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
|
||||||
|
import org.apache.poi.ss.usermodel.WorkbookFactory;
|
||||||
|
import org.apache.poi.util.Internal;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper class which is instantiated by reflection from
|
||||||
|
* {@link WorkbookFactory#create(java.io.File)} and similar
|
||||||
|
*/
|
||||||
|
@Internal
|
||||||
|
public class HSSFWorkbookFactory extends WorkbookFactory {
|
||||||
|
/**
|
||||||
|
* Creates a HSSFWorkbook from the given NPOIFSFileSystem<p>
|
||||||
|
* Note that in order to properly release resources the
|
||||||
|
* Workbook should be closed after use.
|
||||||
|
*/
|
||||||
|
public static HSSFWorkbook createWorkbook(final NPOIFSFileSystem fs) throws IOException {
|
||||||
|
return new HSSFWorkbook(fs);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a HSSFWorkbook from the given DirectoryNode<p>
|
||||||
|
* Note that in order to properly release resources the
|
||||||
|
* Workbook should be closed after use.
|
||||||
|
*/
|
||||||
|
public static HSSFWorkbook createWorkbook(final DirectoryNode root) throws IOException {
|
||||||
|
return new HSSFWorkbook(root, true);
|
||||||
|
}
|
||||||
|
}
|
@ -189,7 +189,7 @@ public class SlideShowFactory {
|
|||||||
case OOXML:
|
case OOXML:
|
||||||
return createXSLFSlideShow(is);
|
return createXSLFSlideShow(is);
|
||||||
default:
|
default:
|
||||||
throw new IllegalArgumentException("Your InputStream was neither an OLE2 stream, nor an OOXML stream");
|
throw new IOException("Your InputStream was neither an OLE2 stream, nor an OOXML stream");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -314,6 +314,8 @@ public class SlideShowFactory {
|
|||||||
throw (EncryptedDocumentException)t;
|
throw (EncryptedDocumentException)t;
|
||||||
} else if (t instanceof OldFileFormatException) {
|
} else if (t instanceof OldFileFormatException) {
|
||||||
throw (OldFileFormatException)t;
|
throw (OldFileFormatException)t;
|
||||||
|
} else if (t instanceof RuntimeException) {
|
||||||
|
throw (RuntimeException)t;
|
||||||
} else {
|
} else {
|
||||||
throw new IOException(t);
|
throw new IOException(t);
|
||||||
}
|
}
|
||||||
|
@ -62,4 +62,8 @@ public interface ObjectData extends SimpleShape {
|
|||||||
* @return the preview picture
|
* @return the preview picture
|
||||||
*/
|
*/
|
||||||
PictureData getPictureData();
|
PictureData getPictureData();
|
||||||
|
|
||||||
|
default String getContentType() {
|
||||||
|
return "binary/octet-stream";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,33 @@ import org.apache.poi.util.Internal;
|
|||||||
@Internal
|
@Internal
|
||||||
public class XSLFSlideShowFactory extends SlideShowFactory {
|
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
|
* Creates a XMLSlideShow from the given OOXML Package
|
||||||
*
|
*
|
||||||
|
@ -23,8 +23,8 @@ import java.io.InputStream;
|
|||||||
|
|
||||||
import javax.xml.namespace.QName;
|
import javax.xml.namespace.QName;
|
||||||
|
|
||||||
import org.apache.poi.POIXMLDocumentPart;
|
import org.apache.poi.ooxml.POIXMLDocumentPart;
|
||||||
import org.apache.poi.POIXMLException;
|
import org.apache.poi.ooxml.POIXMLException;
|
||||||
import org.apache.poi.openxml4j.opc.PackagePart;
|
import org.apache.poi.openxml4j.opc.PackagePart;
|
||||||
import org.apache.poi.openxml4j.opc.PackageRelationshipTypes;
|
import org.apache.poi.openxml4j.opc.PackageRelationshipTypes;
|
||||||
import org.apache.poi.poifs.filesystem.DirectoryEntry;
|
import org.apache.poi.poifs.filesystem.DirectoryEntry;
|
||||||
@ -202,4 +202,9 @@ public class XSSFObjectData extends XSSFSimpleShape implements ObjectData {
|
|||||||
cur.dispose();
|
cur.dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getContentType() {
|
||||||
|
return getObjectPart().getContentType();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -39,6 +39,7 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|||||||
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
||||||
import org.apache.poi.openxml4j.opc.OPCPackage;
|
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.xssf.usermodel.XSSFWorkbookFactory;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public final class TestWorkbookFactory {
|
public final class TestWorkbookFactory {
|
||||||
@ -107,7 +108,7 @@ public final class TestWorkbookFactory {
|
|||||||
assertCloseDoesNotModifyFile(xls, wb);
|
assertCloseDoesNotModifyFile(xls, wb);
|
||||||
|
|
||||||
// Package -> xssf
|
// Package -> xssf
|
||||||
wb = WorkbookFactory.create(
|
wb = XSSFWorkbookFactory.create(
|
||||||
OPCPackage.open(
|
OPCPackage.open(
|
||||||
HSSFTestDataSamples.openSampleFileStream(xlsx))
|
HSSFTestDataSamples.openSampleFileStream(xlsx))
|
||||||
);
|
);
|
||||||
@ -182,7 +183,7 @@ public final class TestWorkbookFactory {
|
|||||||
stream.close();
|
stream.close();
|
||||||
}
|
}
|
||||||
fail();
|
fail();
|
||||||
} catch(InvalidFormatException e) {
|
} catch(IOException e) {
|
||||||
// Good
|
// Good
|
||||||
}
|
}
|
||||||
final byte[] after = HSSFTestDataSamples.getTestDataFileContent(txt);
|
final byte[] after = HSSFTestDataSamples.getTestDataFileContent(txt);
|
||||||
|
@ -46,10 +46,10 @@ import java.util.TreeMap;
|
|||||||
|
|
||||||
import org.apache.poi.EncryptedDocumentException;
|
import org.apache.poi.EncryptedDocumentException;
|
||||||
import org.apache.poi.POIDataSamples;
|
import org.apache.poi.POIDataSamples;
|
||||||
import org.apache.poi.POIXMLDocumentPart;
|
import org.apache.poi.ooxml.POIXMLDocumentPart;
|
||||||
import org.apache.poi.POIXMLDocumentPart.RelationPart;
|
import org.apache.poi.ooxml.POIXMLDocumentPart.RelationPart;
|
||||||
import org.apache.poi.POIXMLException;
|
import org.apache.poi.ooxml.POIXMLException;
|
||||||
import org.apache.poi.POIXMLProperties;
|
import org.apache.poi.ooxml.POIXMLProperties;
|
||||||
import org.apache.poi.common.usermodel.HyperlinkType;
|
import org.apache.poi.common.usermodel.HyperlinkType;
|
||||||
import org.apache.poi.hssf.HSSFITestDataProvider;
|
import org.apache.poi.hssf.HSSFITestDataProvider;
|
||||||
import org.apache.poi.hssf.HSSFTestDataSamples;
|
import org.apache.poi.hssf.HSSFTestDataSamples;
|
||||||
@ -1459,10 +1459,10 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Password Protected .xlsx files should give a helpful
|
* Password Protected .xlsx files are now (as of 4.0.0) tested for the default password
|
||||||
* error message when called via WorkbookFactory with no password
|
* when opened via WorkbookFactory, so there's no EncryptedDocumentException thrown anymore
|
||||||
*/
|
*/
|
||||||
@Test(expected = EncryptedDocumentException.class)
|
@Test
|
||||||
public void bug55692_poifs() throws IOException {
|
public void bug55692_poifs() throws IOException {
|
||||||
// Via a POIFSFileSystem
|
// Via a POIFSFileSystem
|
||||||
try (POIFSFileSystem fsP = new POIFSFileSystem(
|
try (POIFSFileSystem fsP = new POIFSFileSystem(
|
||||||
@ -1951,7 +1951,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
|
|||||||
|
|
||||||
// Workbook Factory gives helpful error on package
|
// Workbook Factory gives helpful error on package
|
||||||
try {
|
try {
|
||||||
WorkbookFactory.create(pkg).close();
|
XSSFWorkbookFactory.create(pkg).close();
|
||||||
fail(".xlsb files not supported");
|
fail(".xlsb files not supported");
|
||||||
} catch (XLSBUnsupportedException e) {
|
} catch (XLSBUnsupportedException e) {
|
||||||
// Good, detected and warned
|
// Good, detected and warned
|
||||||
|
@ -502,18 +502,4 @@ public class AbstractWordUtils
|
|||||||
return loadDoc( poifsFileSystem.getRoot() );
|
return loadDoc( poifsFileSystem.getRoot() );
|
||||||
}
|
}
|
||||||
|
|
||||||
static String substringBeforeLast( String str, String separator )
|
|
||||||
{
|
|
||||||
if ( isEmpty( str ) || isEmpty( separator ) )
|
|
||||||
{
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
int pos = str.lastIndexOf( separator );
|
|
||||||
if ( pos == -1 )
|
|
||||||
{
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
return str.substring( 0, pos );
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -23,37 +23,33 @@ public class DefaultFontReplacer implements FontReplacer
|
|||||||
{
|
{
|
||||||
public Triplet update( Triplet original )
|
public Triplet update( Triplet original )
|
||||||
{
|
{
|
||||||
if ( AbstractWordUtils.isNotEmpty( original.fontName ) )
|
if ( isNotEmpty( original.fontName ) )
|
||||||
{
|
{
|
||||||
String fontName = original.fontName;
|
String fontName = original.fontName;
|
||||||
|
|
||||||
if ( fontName.endsWith( " Regular" ) )
|
if ( fontName.endsWith( " Regular" ) )
|
||||||
fontName = AbstractWordUtils.substringBeforeLast( fontName,
|
fontName = substringBeforeLast( fontName, " Regular" );
|
||||||
" Regular" );
|
|
||||||
|
|
||||||
if ( fontName
|
if ( fontName
|
||||||
.endsWith( " \u041F\u043E\u043B\u0443\u0436\u0438\u0440\u043D\u044B\u0439" ) )
|
.endsWith( " \u041F\u043E\u043B\u0443\u0436\u0438\u0440\u043D\u044B\u0439" ) )
|
||||||
fontName = AbstractWordUtils
|
fontName = substringBeforeLast( fontName,
|
||||||
.substringBeforeLast( fontName,
|
" \u041F\u043E\u043B\u0443\u0436\u0438\u0440\u043D\u044B\u0439" )
|
||||||
" \u041F\u043E\u043B\u0443\u0436\u0438\u0440\u043D\u044B\u0439" )
|
|
||||||
+ " Bold";
|
+ " Bold";
|
||||||
|
|
||||||
if ( fontName
|
if ( fontName
|
||||||
.endsWith( " \u041F\u043E\u043B\u0443\u0436\u0438\u0440\u043D\u044B\u0439 \u041A\u0443\u0440\u0441\u0438\u0432" ) )
|
.endsWith( " \u041F\u043E\u043B\u0443\u0436\u0438\u0440\u043D\u044B\u0439 \u041A\u0443\u0440\u0441\u0438\u0432" ) )
|
||||||
fontName = AbstractWordUtils
|
fontName = substringBeforeLast(
|
||||||
.substringBeforeLast(
|
fontName,
|
||||||
fontName,
|
" \u041F\u043E\u043B\u0443\u0436\u0438\u0440\u043D\u044B\u0439 \u041A\u0443\u0440\u0441\u0438\u0432" )
|
||||||
" \u041F\u043E\u043B\u0443\u0436\u0438\u0440\u043D\u044B\u0439 \u041A\u0443\u0440\u0441\u0438\u0432" )
|
|
||||||
+ " Bold Italic";
|
+ " Bold Italic";
|
||||||
|
|
||||||
if ( fontName.endsWith( " \u041A\u0443\u0440\u0441\u0438\u0432" ) )
|
if ( fontName.endsWith( " \u041A\u0443\u0440\u0441\u0438\u0432" ) )
|
||||||
fontName = AbstractWordUtils.substringBeforeLast( fontName,
|
fontName = substringBeforeLast( fontName, " \u041A\u0443\u0440\u0441\u0438\u0432" ) + " Italic";
|
||||||
" \u041A\u0443\u0440\u0441\u0438\u0432" ) + " Italic";
|
|
||||||
|
|
||||||
original.fontName = fontName;
|
original.fontName = fontName;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( AbstractWordUtils.isNotEmpty( original.fontName ) )
|
if ( isNotEmpty( original.fontName ) )
|
||||||
{
|
{
|
||||||
if ( "Times Regular".equals( original.fontName )
|
if ( "Times Regular".equals( original.fontName )
|
||||||
|| "Times-Regular".equals( original.fontName )
|
|| "Times-Regular".equals( original.fontName )
|
||||||
@ -88,4 +84,30 @@ public class DefaultFontReplacer implements FontReplacer
|
|||||||
|
|
||||||
return original;
|
return original;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean isEmpty( String str )
|
||||||
|
{
|
||||||
|
return str == null || str.length() == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isNotEmpty( String str )
|
||||||
|
{
|
||||||
|
return !isEmpty( str );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static String substringBeforeLast( String str, String separator )
|
||||||
|
{
|
||||||
|
if ( isEmpty( str ) || isEmpty( separator ) )
|
||||||
|
{
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
int pos = str.lastIndexOf( separator );
|
||||||
|
if ( pos == -1 )
|
||||||
|
{
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
return str.substring( 0, pos );
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user