mirror of https://github.com/apache/poi.git
SonarQube fixes
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1777669 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
2802a3c153
commit
fb2dbf1e73
|
@ -19,6 +19,12 @@
|
|||
|
||||
package org.apache.poi.ss.examples.formula;
|
||||
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.poi.ss.formula.OperationEvaluationContext;
|
||||
import org.apache.poi.ss.formula.eval.ErrorEval;
|
||||
import org.apache.poi.ss.formula.eval.ValueEval;
|
||||
|
@ -29,19 +35,11 @@ import org.apache.poi.ss.usermodel.Sheet;
|
|||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Demonstrates how to use functions provided by third-party add-ins, e.g. Bloomberg Excel Add-in.
|
||||
*
|
||||
* There can be situations when you are not interested in formula evaluation,
|
||||
* you just need to set the formula and the workbook will be evaluation by the client.
|
||||
*
|
||||
* @author Yegor Kozlov
|
||||
*/
|
||||
public class SettingExternalFunction {
|
||||
|
||||
|
@ -91,6 +89,7 @@ public class SettingExternalFunction {
|
|||
wb.write(out);
|
||||
out.close();
|
||||
|
||||
wb.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -194,7 +194,7 @@ public class CryptoAPIDecryptor extends Decryptor implements Cloneable {
|
|||
assert(entry.streamName.length() == nameSize);
|
||||
}
|
||||
|
||||
fsOut = new POIFSFileSystem();
|
||||
fsOut = new POIFSFileSystem(); // NOSONAR
|
||||
for (StreamDescriptorEntry entry : entries) {
|
||||
sbis.seek(entry.streamOffset);
|
||||
sbis.setBlock(entry.block);
|
||||
|
|
|
@ -126,7 +126,7 @@ public class CryptoAPIEncryptor extends Encryptor implements Cloneable {
|
|||
*/
|
||||
public OutputStream getSummaryEntries(DirectoryNode dir)
|
||||
throws IOException, GeneralSecurityException {
|
||||
CryptoAPIDocumentOutputStream bos = new CryptoAPIDocumentOutputStream(this);
|
||||
CryptoAPIDocumentOutputStream bos = new CryptoAPIDocumentOutputStream(this); // NOSONAR
|
||||
byte buf[] = new byte[8];
|
||||
|
||||
bos.write(buf, 0, 8); // skip header
|
||||
|
|
|
@ -19,9 +19,10 @@
|
|||
|
||||
package org.apache.poi.poifs.eventfilesystem;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
import java.util.*;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.apache.poi.poifs.filesystem.DocumentInputStream;
|
||||
import org.apache.poi.poifs.filesystem.OPOIFSDocument;
|
||||
|
@ -34,6 +35,7 @@ import org.apache.poi.poifs.storage.BlockList;
|
|||
import org.apache.poi.poifs.storage.HeaderBlock;
|
||||
import org.apache.poi.poifs.storage.RawDataBlockList;
|
||||
import org.apache.poi.poifs.storage.SmallBlockTableReader;
|
||||
import org.apache.poi.util.IOUtils;
|
||||
|
||||
/**
|
||||
* An event-driven reader for POIFS file systems. Users of this class
|
||||
|
@ -42,8 +44,6 @@ import org.apache.poi.poifs.storage.SmallBlockTableReader;
|
|||
* documents. Once all the listeners have been registered, the read()
|
||||
* method is called, which results in the listeners being notified as
|
||||
* their documents are read.
|
||||
*
|
||||
* @author Marc Johnson (mjohnson at apache dot org)
|
||||
*/
|
||||
|
||||
public class POIFSReader
|
||||
|
@ -190,20 +190,19 @@ public class POIFSReader
|
|||
{
|
||||
if (args.length == 0)
|
||||
{
|
||||
System.err
|
||||
.println("at least one argument required: input filename(s)");
|
||||
System.err.println("at least one argument required: input filename(s)");
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
// register for all
|
||||
for (int j = 0; j < args.length; j++)
|
||||
for (String arg : args)
|
||||
{
|
||||
POIFSReader reader = new POIFSReader();
|
||||
POIFSReaderListener listener = new SampleListener();
|
||||
|
||||
reader.registerListener(listener);
|
||||
System.out.println("reading " + args[ j ]);
|
||||
FileInputStream istream = new FileInputStream(args[ j ]);
|
||||
System.out.println("reading " + arg);
|
||||
FileInputStream istream = new FileInputStream(arg);
|
||||
|
||||
reader.read(istream);
|
||||
istream.close();
|
||||
|
@ -300,31 +299,25 @@ public class POIFSReader
|
|||
* @param event
|
||||
*/
|
||||
|
||||
public void processPOIFSReaderEvent(final POIFSReaderEvent event)
|
||||
{
|
||||
@SuppressWarnings("resource")
|
||||
@Override
|
||||
public void processPOIFSReaderEvent(final POIFSReaderEvent event) {
|
||||
DocumentInputStream istream = event.getStream();
|
||||
POIFSDocumentPath path = event.getPath();
|
||||
String name = event.getName();
|
||||
|
||||
try
|
||||
{
|
||||
byte[] data = new byte[ istream.available() ];
|
||||
|
||||
istream.read(data);
|
||||
try {
|
||||
byte[] data = IOUtils.toByteArray(istream);
|
||||
int pathLength = path.length();
|
||||
|
||||
for (int k = 0; k < pathLength; k++)
|
||||
{
|
||||
for (int k = 0; k < pathLength; k++) {
|
||||
System.out.print("/" + path.getComponent(k));
|
||||
}
|
||||
System.out.println("/" + name + ": " + data.length
|
||||
+ " bytes read");
|
||||
}
|
||||
catch (IOException ignored)
|
||||
{
|
||||
System.out.println("/" + name + ": " + data.length + " bytes read");
|
||||
} catch (IOException ignored) {
|
||||
} finally {
|
||||
IOUtils.closeQuietly(istream);
|
||||
}
|
||||
}
|
||||
} // end private class SampleListener
|
||||
} // end public class POIFSReader
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -25,7 +25,6 @@ import java.awt.geom.AffineTransform;
|
|||
import java.awt.geom.Ellipse2D;
|
||||
import java.awt.geom.Path2D;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
@ -53,6 +52,7 @@ import org.apache.poi.sl.usermodel.LineDecoration.DecorationSize;
|
|||
import org.apache.poi.sl.usermodel.PaintStyle.SolidPaint;
|
||||
import org.apache.poi.sl.usermodel.Shadow;
|
||||
import org.apache.poi.sl.usermodel.SimpleShape;
|
||||
import org.apache.poi.util.IOUtils;
|
||||
import org.apache.poi.util.Units;
|
||||
|
||||
|
||||
|
@ -110,15 +110,21 @@ public class DrawSimpleShape extends DrawShape {
|
|||
}
|
||||
|
||||
protected void drawDecoration(Graphics2D graphics, Paint line, BasicStroke stroke) {
|
||||
if(line == null) return;
|
||||
if(line == null) {
|
||||
return;
|
||||
}
|
||||
graphics.setPaint(line);
|
||||
|
||||
List<Outline> lst = new ArrayList<Outline>();
|
||||
LineDecoration deco = getShape().getLineDecoration();
|
||||
Outline head = getHeadDecoration(graphics, deco, stroke);
|
||||
if (head != null) lst.add(head);
|
||||
if (head != null) {
|
||||
lst.add(head);
|
||||
}
|
||||
Outline tail = getTailDecoration(graphics, deco, stroke);
|
||||
if (tail != null) lst.add(tail);
|
||||
if (tail != null) {
|
||||
lst.add(tail);
|
||||
}
|
||||
|
||||
|
||||
for(Outline o : lst){
|
||||
|
@ -126,8 +132,12 @@ public class DrawSimpleShape extends DrawShape {
|
|||
Path p = o.getPath();
|
||||
graphics.setRenderingHint(Drawable.GRADIENT_SHAPE, s);
|
||||
|
||||
if(p.isFilled()) graphics.fill(s);
|
||||
if(p.isStroked()) graphics.draw(s);
|
||||
if(p.isFilled()) {
|
||||
graphics.fill(s);
|
||||
}
|
||||
if(p.isStroked()) {
|
||||
graphics.draw(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -221,8 +231,7 @@ public class DrawSimpleShape extends DrawShape {
|
|||
double lineWidth = Math.max(2.5, stroke.getLineWidth());
|
||||
|
||||
Rectangle2D anchor = getAnchor(graphics, getShape());
|
||||
double x1 = anchor.getX(),
|
||||
y1 = anchor.getY();
|
||||
double x1 = anchor.getX(), y1 = anchor.getY();
|
||||
|
||||
double alpha = Math.atan(anchor.getHeight() / anchor.getWidth());
|
||||
|
||||
|
@ -283,13 +292,15 @@ public class DrawSimpleShape extends DrawShape {
|
|||
}
|
||||
|
||||
protected void drawShadow(
|
||||
Graphics2D graphics
|
||||
, Collection<Outline> outlines
|
||||
, Paint fill
|
||||
, Paint line
|
||||
Graphics2D graphics
|
||||
, Collection<Outline> outlines
|
||||
, Paint fill
|
||||
, Paint line
|
||||
) {
|
||||
Shadow<?,?> shadow = getShape().getShadow();
|
||||
if (shadow == null || (fill == null && line == null)) return;
|
||||
if (shadow == null || (fill == null && line == null)) {
|
||||
return;
|
||||
}
|
||||
|
||||
SolidPaint shadowPaint = shadow.getFillStyle();
|
||||
Color shadowColor = DrawPaint.applyColorTransform(shadowPaint.getSolidColor());
|
||||
|
@ -373,11 +384,7 @@ public class DrawSimpleShape extends DrawShape {
|
|||
} catch (Exception e) {
|
||||
throw new RuntimeException("Unable to load preset geometries.", e);
|
||||
} finally {
|
||||
try {
|
||||
presetIS.close();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Unable to load preset geometries.", e);
|
||||
}
|
||||
IOUtils.closeQuietly(presetIS);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -16,16 +16,20 @@
|
|||
==================================================================== */
|
||||
package org.apache.poi.sl.usermodel;
|
||||
|
||||
import java.io.*;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.PushbackInputStream;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.apache.poi.EncryptedDocumentException;
|
||||
import org.apache.poi.OldFileFormatException;
|
||||
import org.apache.poi.poifs.filesystem.DocumentFactoryHelper;
|
||||
import org.apache.poi.hssf.record.crypto.Biff8EncryptionKey;
|
||||
import org.apache.poi.poifs.crypt.Decryptor;
|
||||
import org.apache.poi.poifs.filesystem.DirectoryNode;
|
||||
import org.apache.poi.poifs.filesystem.DocumentFactoryHelper;
|
||||
import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
|
||||
import org.apache.poi.poifs.filesystem.OfficeXmlFileException;
|
||||
import org.apache.poi.util.IOUtils;
|
||||
|
@ -66,7 +70,7 @@ public class SlideShowFactory {
|
|||
|
||||
return createXSLFSlideShow(stream);
|
||||
} finally {
|
||||
if (stream != null) stream.close();
|
||||
IOUtils.closeQuietly(stream);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -211,14 +215,10 @@ public class SlideShowFactory {
|
|||
fs = new NPOIFSFileSystem(file, readOnly);
|
||||
return create(fs, password);
|
||||
} catch(OfficeXmlFileException e) {
|
||||
if(fs != null) {
|
||||
fs.close();
|
||||
}
|
||||
IOUtils.closeQuietly(fs);
|
||||
return createXSLFSlideShow(file, readOnly);
|
||||
} catch(RuntimeException e) {
|
||||
if(fs != null) {
|
||||
fs.close();
|
||||
}
|
||||
IOUtils.closeQuietly(fs);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,9 +25,7 @@ import java.util.Map;
|
|||
import org.apache.poi.ss.util.CellReference;
|
||||
|
||||
/**
|
||||
* Optimisation - compacts many blank cell references used by a single formula.
|
||||
*
|
||||
* @author Josh Micich
|
||||
* Optimization - compacts many blank cell references used by a single formula.
|
||||
*/
|
||||
final class FormulaUsedBlankCellSet {
|
||||
public static final class BookSheetKey {
|
||||
|
@ -39,11 +37,15 @@ final class FormulaUsedBlankCellSet {
|
|||
_bookIndex = bookIndex;
|
||||
_sheetIndex = sheetIndex;
|
||||
}
|
||||
public int hashCode() {
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return _bookIndex * 17 + _sheetIndex;
|
||||
}
|
||||
public boolean equals(Object obj) {
|
||||
assert obj instanceof BookSheetKey : "these private cache key instances are only compared to themselves";
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (!(obj instanceof BookSheetKey)) {
|
||||
return false;
|
||||
}
|
||||
BookSheetKey other = (BookSheetKey) obj;
|
||||
return _bookIndex == other._bookIndex && _sheetIndex == other._sheetIndex;
|
||||
}
|
||||
|
@ -148,7 +150,8 @@ final class FormulaUsedBlankCellSet {
|
|||
_lastRowIndex = rowIndex;
|
||||
return true;
|
||||
}
|
||||
public String toString() {
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuffer sb = new StringBuffer(64);
|
||||
CellReference crA = new CellReference(_firstRowIndex, _firstColumnIndex, false, false);
|
||||
CellReference crB = new CellReference(_lastRowIndex, _lastColumnIndex, false, false);
|
||||
|
|
|
@ -20,10 +20,6 @@ package org.apache.poi.ss.formula;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Josh Micich
|
||||
*/
|
||||
final class PlainCellCache {
|
||||
|
||||
public static final class Loc {
|
||||
|
@ -48,12 +44,16 @@ final class PlainCellCache {
|
|||
_rowIndex = rowIndex;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return (int)(_bookSheetColumn ^ (_bookSheetColumn >>> 32)) + 17 * _rowIndex;
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
assert obj instanceof Loc : "these package-private cache key instances are only compared to themselves";
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (!(obj instanceof Loc)) {
|
||||
return false;
|
||||
}
|
||||
Loc other = (Loc) obj;
|
||||
return _bookSheetColumn == other._bookSheetColumn && _rowIndex == other._rowIndex;
|
||||
}
|
||||
|
|
|
@ -29,8 +29,6 @@ import org.apache.poi.util.LocaleUtil;
|
|||
* Internal calculation methods for Excel 'Analysis ToolPak' function YEARFRAC()<br/>
|
||||
*
|
||||
* Algorithm inspired by www.dwheeler.com/yearfrac
|
||||
*
|
||||
* @author Josh Micich
|
||||
*/
|
||||
final class YearFracCalculator {
|
||||
private static final int MS_PER_HOUR = 60 * 60 * 1000;
|
||||
|
@ -212,25 +210,21 @@ final class YearFracCalculator {
|
|||
* @return <code>true</code> if dates both within a leap year, or span a period including Feb 29
|
||||
*/
|
||||
private static boolean shouldCountFeb29(SimpleDate start, SimpleDate end) {
|
||||
boolean startIsLeapYear = isLeapYear(start.year);
|
||||
if (startIsLeapYear && start.year == end.year) {
|
||||
// note - dates may not actually span Feb-29, but it gets counted anyway in this case
|
||||
return true;
|
||||
}
|
||||
if (isLeapYear(start.year)) {
|
||||
if (start.year == end.year) {
|
||||
// note - dates may not actually span Feb-29, but it gets counted anyway in this case
|
||||
return true;
|
||||
}
|
||||
|
||||
boolean endIsLeapYear = isLeapYear(end.year);
|
||||
if (!startIsLeapYear && !endIsLeapYear) {
|
||||
return false;
|
||||
}
|
||||
if (startIsLeapYear) {
|
||||
switch (start.month) {
|
||||
switch (start.month) {
|
||||
case SimpleDate.JANUARY:
|
||||
case SimpleDate.FEBRUARY:
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (endIsLeapYear) {
|
||||
|
||||
if (isLeapYear(end.year)) {
|
||||
switch (end.month) {
|
||||
case SimpleDate.JANUARY:
|
||||
return false;
|
||||
|
|
|
@ -37,8 +37,6 @@ import org.apache.poi.util.Internal;
|
|||
* will be used in all subsequent evaluations.<br/>
|
||||
*
|
||||
* For POI internal use only
|
||||
*
|
||||
* @author Josh Micich
|
||||
*/
|
||||
@Internal
|
||||
final class ForkedEvaluationSheet implements EvaluationSheet {
|
||||
|
@ -128,7 +126,9 @@ final class ForkedEvaluationSheet implements EvaluationSheet {
|
|||
}
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
assert obj instanceof RowColKey : "these private cache key instances are only compared to themselves";
|
||||
if (!(obj instanceof RowColKey)) {
|
||||
return false;
|
||||
}
|
||||
RowColKey other = (RowColKey) obj;
|
||||
return _rowIndex == other._rowIndex && _columnIndex == other._columnIndex;
|
||||
}
|
||||
|
@ -136,6 +136,7 @@ final class ForkedEvaluationSheet implements EvaluationSheet {
|
|||
public int hashCode() {
|
||||
return _rowIndex ^ _columnIndex;
|
||||
}
|
||||
@Override
|
||||
public int compareTo(RowColKey o) {
|
||||
int cmp = _rowIndex - o._rowIndex;
|
||||
if (cmp != 0) {
|
||||
|
|
|
@ -136,6 +136,7 @@ public final class Countif extends Fixed2ArgFunction {
|
|||
throw new RuntimeException("Cannot call boolean evaluate on non-equality operator '"
|
||||
+ _representation + "'");
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuffer sb = new StringBuffer(64);
|
||||
sb.append(getClass().getName());
|
||||
|
@ -187,6 +188,7 @@ public final class Countif extends Fixed2ArgFunction {
|
|||
return String.valueOf(_value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(ValueEval x) {
|
||||
double testValue;
|
||||
if(x instanceof StringEval) {
|
||||
|
@ -246,22 +248,21 @@ public final class Countif extends Fixed2ArgFunction {
|
|||
return value ? 1 : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(ValueEval x) {
|
||||
int testValue;
|
||||
if(x instanceof StringEval) {
|
||||
if (true) { // change to false to observe more intuitive behaviour
|
||||
// Note - Unlike with numbers, it seems that COUNTIF never matches
|
||||
// boolean values when the target(x) is a string
|
||||
return false;
|
||||
}
|
||||
@SuppressWarnings("unused")
|
||||
StringEval se = (StringEval)x;
|
||||
Boolean val = parseBoolean(se.getStringValue());
|
||||
if(val == null) {
|
||||
// x is text that is not a boolean
|
||||
return false;
|
||||
}
|
||||
testValue = boolToInt(val.booleanValue());
|
||||
// Note - Unlike with numbers, it seems that COUNTIF never matches
|
||||
// boolean values when the target(x) is a string
|
||||
return false;
|
||||
// uncomment to observe more intuitive behaviour
|
||||
// StringEval se = (StringEval)x;
|
||||
// Boolean val = parseBoolean(se.getStringValue());
|
||||
// if(val == null) {
|
||||
// // x is text that is not a boolean
|
||||
// return false;
|
||||
// }
|
||||
// testValue = boolToInt(val.booleanValue());
|
||||
} else if((x instanceof BoolEval)) {
|
||||
BoolEval be = (BoolEval) x;
|
||||
testValue = boolToInt(be.getBooleanValue());
|
||||
|
@ -300,6 +301,7 @@ public final class Countif extends Fixed2ArgFunction {
|
|||
return FormulaError.forInt(_value).getString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(ValueEval x) {
|
||||
if(x instanceof ErrorEval) {
|
||||
int testValue = ((ErrorEval)x).getErrorCode();
|
||||
|
@ -339,6 +341,7 @@ public final class Countif extends Fixed2ArgFunction {
|
|||
return _pattern.pattern();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(ValueEval x) {
|
||||
if (x instanceof BlankEval) {
|
||||
switch(getCode()) {
|
||||
|
@ -433,6 +436,7 @@ public final class Countif extends Fixed2ArgFunction {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ValueEval evaluate(int srcRowIndex, int srcColumnIndex, ValueEval arg0, ValueEval arg1) {
|
||||
|
||||
I_MatchPredicate mp = createCriteriaPredicate(arg1, srcRowIndex, srcColumnIndex);
|
||||
|
@ -525,13 +529,27 @@ public final class Countif extends Fixed2ArgFunction {
|
|||
if (value.length() < 4 || value.charAt(0) != '#') {
|
||||
return null;
|
||||
}
|
||||
if (value.equals("#NULL!")) return ErrorEval.NULL_INTERSECTION;
|
||||
if (value.equals("#DIV/0!")) return ErrorEval.DIV_ZERO;
|
||||
if (value.equals("#VALUE!")) return ErrorEval.VALUE_INVALID;
|
||||
if (value.equals("#REF!")) return ErrorEval.REF_INVALID;
|
||||
if (value.equals("#NAME?")) return ErrorEval.NAME_INVALID;
|
||||
if (value.equals("#NUM!")) return ErrorEval.NUM_ERROR;
|
||||
if (value.equals("#N/A")) return ErrorEval.NA;
|
||||
if (value.equals("#NULL!")) {
|
||||
return ErrorEval.NULL_INTERSECTION;
|
||||
}
|
||||
if (value.equals("#DIV/0!")) {
|
||||
return ErrorEval.DIV_ZERO;
|
||||
}
|
||||
if (value.equals("#VALUE!")) {
|
||||
return ErrorEval.VALUE_INVALID;
|
||||
}
|
||||
if (value.equals("#REF!")) {
|
||||
return ErrorEval.REF_INVALID;
|
||||
}
|
||||
if (value.equals("#NAME?")) {
|
||||
return ErrorEval.NAME_INVALID;
|
||||
}
|
||||
if (value.equals("#NUM!")) {
|
||||
return ErrorEval.NUM_ERROR;
|
||||
}
|
||||
if (value.equals("#N/A")) {
|
||||
return ErrorEval.NA;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -35,10 +35,6 @@ import org.apache.poi.util.LittleEndianOutput;
|
|||
* parsed formula. However, in BIFF files <tt>Ptg</tt>s are written/read in
|
||||
* <em>Reverse-Polish Notation</em> order. The RPN ordering also simplifies formula
|
||||
* evaluation logic, so POI mostly accesses <tt>Ptg</tt>s in the same way.
|
||||
*
|
||||
* @author andy
|
||||
* @author avik
|
||||
* @author Jason Height (jheight at chariot dot net dot au)
|
||||
*/
|
||||
public abstract class Ptg {
|
||||
public static final Ptg[] EMPTY_PTG_ARRAY = { };
|
||||
|
@ -201,7 +197,7 @@ public abstract class Ptg {
|
|||
* @return number of bytes written
|
||||
*/
|
||||
public static int serializePtgs(Ptg[] ptgs, byte[] array, int offset) {
|
||||
LittleEndianByteArrayOutputStream out = new LittleEndianByteArrayOutputStream(array, offset);
|
||||
LittleEndianByteArrayOutputStream out = new LittleEndianByteArrayOutputStream(array, offset); // NOSONAR
|
||||
|
||||
List<Ptg> arrayPtgs = null;
|
||||
|
||||
|
|
|
@ -323,6 +323,7 @@ public class CellReference {
|
|||
/**
|
||||
* @deprecated 3.15 beta 2. Use {@link #isColumnWithinRange}.
|
||||
*/
|
||||
@Deprecated
|
||||
public static boolean isColumnWithnRange(String colStr, SpreadsheetVersion ssVersion) {
|
||||
return isColumnWithinRange(colStr, ssVersion);
|
||||
}
|
||||
|
@ -352,6 +353,7 @@ public class CellReference {
|
|||
/**
|
||||
* @deprecated 3.15 beta 2. Use {@link #isRowWithinRange}
|
||||
*/
|
||||
@Deprecated
|
||||
public static boolean isRowWithnRange(String rowStr, SpreadsheetVersion ssVersion) {
|
||||
return isRowWithinRange(rowStr, ssVersion);
|
||||
}
|
||||
|
@ -388,7 +390,9 @@ public class CellReference {
|
|||
final String sheetName = parseSheetName(reference, plingPos);
|
||||
String cell = reference.substring(plingPos+1).toUpperCase(Locale.ROOT);
|
||||
Matcher matcher = CELL_REF_PATTERN.matcher(cell);
|
||||
if (!matcher.matches()) throw new IllegalArgumentException("Invalid CellReference: " + reference);
|
||||
if (!matcher.matches()) {
|
||||
throw new IllegalArgumentException("Invalid CellReference: " + reference);
|
||||
}
|
||||
String col = matcher.group(1);
|
||||
String row = matcher.group(2);
|
||||
|
||||
|
@ -430,13 +434,11 @@ public class CellReference {
|
|||
sb.append(ch);
|
||||
continue;
|
||||
}
|
||||
if(i < lastQuotePos) {
|
||||
if(reference.charAt(i+1) == SPECIAL_NAME_DELIMITER) {
|
||||
// two consecutive quotes is the escape sequence for a single one
|
||||
i++; // skip this and keep parsing the special name
|
||||
sb.append(ch);
|
||||
continue;
|
||||
}
|
||||
if(i+1 < lastQuotePos && reference.charAt(i+1) == SPECIAL_NAME_DELIMITER) {
|
||||
// two consecutive quotes is the escape sequence for a single one
|
||||
i++; // skip this and keep parsing the special name
|
||||
sb.append(ch);
|
||||
continue;
|
||||
}
|
||||
throw new IllegalArgumentException("Bad sheet name quote escaping: (" + reference + ")");
|
||||
}
|
||||
|
|
|
@ -48,6 +48,7 @@ import java.util.UUID;
|
|||
import javax.xml.crypto.MarshalException;
|
||||
|
||||
import org.apache.poi.poifs.crypt.dsig.services.RevocationData;
|
||||
import org.apache.poi.util.IOUtils;
|
||||
import org.apache.poi.util.POILogFactory;
|
||||
import org.apache.poi.util.POILogger;
|
||||
import org.apache.xml.security.c14n.Canonicalizer;
|
||||
|
@ -62,28 +63,7 @@ import org.bouncycastle.asn1.x509.Extension;
|
|||
import org.bouncycastle.cert.ocsp.BasicOCSPResp;
|
||||
import org.bouncycastle.cert.ocsp.OCSPResp;
|
||||
import org.bouncycastle.cert.ocsp.RespID;
|
||||
import org.etsi.uri.x01903.v13.CRLIdentifierType;
|
||||
import org.etsi.uri.x01903.v13.CRLRefType;
|
||||
import org.etsi.uri.x01903.v13.CRLRefsType;
|
||||
import org.etsi.uri.x01903.v13.CRLValuesType;
|
||||
import org.etsi.uri.x01903.v13.CertIDListType;
|
||||
import org.etsi.uri.x01903.v13.CertIDType;
|
||||
import org.etsi.uri.x01903.v13.CertificateValuesType;
|
||||
import org.etsi.uri.x01903.v13.CompleteCertificateRefsType;
|
||||
import org.etsi.uri.x01903.v13.CompleteRevocationRefsType;
|
||||
import org.etsi.uri.x01903.v13.DigestAlgAndValueType;
|
||||
import org.etsi.uri.x01903.v13.EncapsulatedPKIDataType;
|
||||
import org.etsi.uri.x01903.v13.OCSPIdentifierType;
|
||||
import org.etsi.uri.x01903.v13.OCSPRefType;
|
||||
import org.etsi.uri.x01903.v13.OCSPRefsType;
|
||||
import org.etsi.uri.x01903.v13.OCSPValuesType;
|
||||
import org.etsi.uri.x01903.v13.QualifyingPropertiesDocument;
|
||||
import org.etsi.uri.x01903.v13.QualifyingPropertiesType;
|
||||
import org.etsi.uri.x01903.v13.ResponderIDType;
|
||||
import org.etsi.uri.x01903.v13.RevocationValuesType;
|
||||
import org.etsi.uri.x01903.v13.UnsignedPropertiesType;
|
||||
import org.etsi.uri.x01903.v13.UnsignedSignaturePropertiesType;
|
||||
import org.etsi.uri.x01903.v13.XAdESTimeStampType;
|
||||
import org.etsi.uri.x01903.v13.*;
|
||||
import org.etsi.uri.x01903.v14.ValidationDataType;
|
||||
import org.w3.x2000.x09.xmldsig.CanonicalizationMethodType;
|
||||
import org.w3c.dom.Document;
|
||||
|
@ -341,8 +321,8 @@ public class XAdESXLSignatureFacet extends SignatureFacet {
|
|||
ASN1Integer integer = (ASN1Integer)asn1IS2.readObject();
|
||||
return integer.getPositiveValue();
|
||||
} finally {
|
||||
asn1IS2.close();
|
||||
asn1IS1.close();
|
||||
IOUtils.closeQuietly(asn1IS2);
|
||||
IOUtils.closeQuietly(asn1IS1);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("I/O error: " + e.getMessage(), e);
|
||||
|
|
|
@ -16,11 +16,14 @@
|
|||
==================================================================== */
|
||||
package org.apache.poi.ss.usermodel;
|
||||
|
||||
import java.io.*;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.PushbackInputStream;
|
||||
|
||||
import org.apache.poi.EmptyFileException;
|
||||
import org.apache.poi.EncryptedDocumentException;
|
||||
import org.apache.poi.poifs.filesystem.DocumentFactoryHelper;
|
||||
import org.apache.poi.hssf.record.crypto.Biff8EncryptionKey;
|
||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
||||
|
@ -28,6 +31,7 @@ import org.apache.poi.openxml4j.opc.OPCPackage;
|
|||
import org.apache.poi.openxml4j.opc.PackageAccess;
|
||||
import org.apache.poi.poifs.crypt.Decryptor;
|
||||
import org.apache.poi.poifs.filesystem.DirectoryNode;
|
||||
import org.apache.poi.poifs.filesystem.DocumentFactoryHelper;
|
||||
import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
|
||||
import org.apache.poi.poifs.filesystem.OfficeXmlFileException;
|
||||
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
|
||||
|
@ -252,8 +256,7 @@ public class WorkbookFactory {
|
|||
return create(fs, password);
|
||||
} catch (RuntimeException e) {
|
||||
// ensure that the file-handle is closed again
|
||||
fs.close();
|
||||
|
||||
IOUtils.closeQuietly(fs);
|
||||
throw e;
|
||||
}
|
||||
} catch(OfficeXmlFileException e) {
|
||||
|
@ -261,20 +264,18 @@ public class WorkbookFactory {
|
|||
OPCPackage pkg = OPCPackage.open(file, readOnly ? PackageAccess.READ : PackageAccess.READ_WRITE);
|
||||
try {
|
||||
return new XSSFWorkbook(pkg);
|
||||
} catch (IOException ioe) {
|
||||
// ensure that file handles are closed (use revert() to not re-write the file)
|
||||
} catch (Exception ioe) {
|
||||
// ensure that file handles are closed - use revert() to not re-write the file
|
||||
pkg.revert();
|
||||
//pkg.close();
|
||||
// do not pkg.close();
|
||||
|
||||
// rethrow exception
|
||||
throw ioe;
|
||||
} catch (RuntimeException ioe) {
|
||||
// ensure that file handles are closed (use revert() to not re-write the file)
|
||||
pkg.revert();
|
||||
//pkg.close();
|
||||
|
||||
// rethrow exception
|
||||
throw ioe;
|
||||
if (ioe instanceof IOException) {
|
||||
throw (IOException)ioe;
|
||||
} else if (ioe instanceof RuntimeException) {
|
||||
throw (RuntimeException)ioe;
|
||||
} else {
|
||||
throw new IOException(ioe);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue