aboutsummaryrefslogtreecommitdiffstats
path: root/src/java
diff options
context:
space:
mode:
authorMarius Volkhart <mariusvolkhart@apache.org>2021-02-21 20:57:25 +0000
committerMarius Volkhart <mariusvolkhart@apache.org>2021-02-21 20:57:25 +0000
commit259c9967efb354a0feff2a861ac8bd20582b6562 (patch)
treeba76a4f20503d97e77bdf18146d59e00a2369fb9 /src/java
parent6d10f26718f84591671d7cafdcc009345b9c777e (diff)
downloadpoi-259c9967efb354a0feff2a861ac8bd20582b6562.tar.gz
poi-259c9967efb354a0feff2a861ac8bd20582b6562.zip
[bug-63046] Use Log4j 2 for logging
This removes the POILogger and POILogFactory mechanism for logging. This mechanism was created at a time when the Java landscape looked very different than it does today. Log4j 2 is an Apache Foundation project that is well maintained and is widely regarded as having good performance and capabilities. We use only the Log4j API artifact. This lets application developers choose how they want to capture logging events if at all. Integrations with Log4j 2 Core and Logback are available from the Log4j project. Closes #224 git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1886770 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java')
-rw-r--r--src/java/org/apache/poi/POIDocument.java23
-rw-r--r--src/java/org/apache/poi/common/usermodel/fonts/FontCharset.java8
-rw-r--r--src/java/org/apache/poi/ddf/EscherContainerRecord.java12
-rw-r--r--src/java/org/apache/poi/ddf/EscherMetafileBlip.java14
-rw-r--r--src/java/org/apache/poi/extractor/ExtractorFactory.java8
-rw-r--r--src/java/org/apache/poi/hpsf/ClipboardData.java14
-rw-r--r--src/java/org/apache/poi/hpsf/CodePageString.java23
-rw-r--r--src/java/org/apache/poi/hpsf/CustomProperties.java16
-rw-r--r--src/java/org/apache/poi/hpsf/Property.java19
-rw-r--r--src/java/org/apache/poi/hpsf/Section.java22
-rw-r--r--src/java/org/apache/poi/hpsf/TypedPropertyValue.java11
-rw-r--r--src/java/org/apache/poi/hpsf/UnicodeString.java18
-rw-r--r--src/java/org/apache/poi/hpsf/VariantBool.java10
-rw-r--r--src/java/org/apache/poi/hpsf/VariantSupport.java8
-rw-r--r--src/java/org/apache/poi/hssf/dev/BiffViewer.java19
-rw-r--r--src/java/org/apache/poi/hssf/eventusermodel/FormatTrackingHSSFListener.java19
-rw-r--r--src/java/org/apache/poi/hssf/model/InternalSheet.java106
-rw-r--r--src/java/org/apache/poi/hssf/model/InternalWorkbook.java91
-rw-r--r--src/java/org/apache/poi/hssf/record/CFRule12Record.java5
-rw-r--r--src/java/org/apache/poi/hssf/record/CFRuleBase.java6
-rw-r--r--src/java/org/apache/poi/hssf/record/DimensionsRecord.java8
-rw-r--r--src/java/org/apache/poi/hssf/record/EmbeddedObjectRefSubRecord.java10
-rw-r--r--src/java/org/apache/poi/hssf/record/FeatRecord.java12
-rw-r--r--src/java/org/apache/poi/hssf/record/FormatRecord.java13
-rw-r--r--src/java/org/apache/poi/hssf/record/HyperlinkRecord.java17
-rw-r--r--src/java/org/apache/poi/hssf/record/LabelRecord.java17
-rw-r--r--src/java/org/apache/poi/hssf/record/OldLabelRecord.java15
-rw-r--r--src/java/org/apache/poi/hssf/record/SSTDeserializer.java10
-rw-r--r--src/java/org/apache/poi/hssf/record/SupBookRecord.java10
-rw-r--r--src/java/org/apache/poi/hssf/record/aggregates/CFRecordsAggregate.java17
-rw-r--r--src/java/org/apache/poi/hssf/record/cf/ColorGradientFormatting.java10
-rw-r--r--src/java/org/apache/poi/hssf/record/cf/DataBarFormatting.java11
-rw-r--r--src/java/org/apache/poi/hssf/record/cf/IconMultiStateFormatting.java10
-rw-r--r--src/java/org/apache/poi/hssf/record/common/ExtRst.java12
-rw-r--r--src/java/org/apache/poi/hssf/record/common/UnicodeString.java10
-rw-r--r--src/java/org/apache/poi/hssf/usermodel/EscherGraphics.java41
-rw-r--r--src/java/org/apache/poi/hssf/usermodel/EscherGraphics2d.java49
-rw-r--r--src/java/org/apache/poi/hssf/usermodel/HSSFPatriarch.java1
-rw-r--r--src/java/org/apache/poi/hssf/usermodel/HSSFPolygon.java10
-rw-r--r--src/java/org/apache/poi/hssf/usermodel/HSSFShape.java8
-rw-r--r--src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java61
-rw-r--r--src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java79
-rw-r--r--src/java/org/apache/poi/hssf/usermodel/StaticFontMetrics.java10
-rw-r--r--src/java/org/apache/poi/hssf/usermodel/helpers/HSSFColumnShifter.java6
-rw-r--r--src/java/org/apache/poi/hssf/usermodel/helpers/HSSFRowShifter.java8
-rw-r--r--src/java/org/apache/poi/poifs/crypt/ChunkedCipherOutputStream.java10
-rw-r--r--src/java/org/apache/poi/poifs/crypt/standard/StandardEncryptor.java8
-rw-r--r--src/java/org/apache/poi/poifs/filesystem/POIFSDocumentPath.java6
-rw-r--r--src/java/org/apache/poi/poifs/filesystem/POIFSFileSystem.java8
-rw-r--r--src/java/org/apache/poi/poifs/macros/VBAMacroReader.java19
-rw-r--r--src/java/org/apache/poi/poifs/nio/FileBackedDataSource.java10
-rw-r--r--src/java/org/apache/poi/poifs/property/PropertyTable.java14
-rw-r--r--src/java/org/apache/poi/sl/draw/BitmapImageRenderer.java8
-rw-r--r--src/java/org/apache/poi/sl/draw/DrawPaint.java16
-rw-r--r--src/java/org/apache/poi/sl/draw/DrawPictureShape.java12
-rw-r--r--src/java/org/apache/poi/sl/draw/DrawTextParagraph.java27
-rw-r--r--src/java/org/apache/poi/sl/draw/SLGraphics.java211
-rw-r--r--src/java/org/apache/poi/sl/draw/geom/PresetGeometries.java8
-rw-r--r--src/java/org/apache/poi/sl/draw/geom/PresetParser.java8
-rw-r--r--src/java/org/apache/poi/sl/extractor/SlideShowExtractor.java8
-rw-r--r--src/java/org/apache/poi/sl/image/ImageHeaderBitmap.java10
-rw-r--r--src/java/org/apache/poi/sl/image/ImageHeaderEMF.java10
-rw-r--r--src/java/org/apache/poi/sl/image/ImageHeaderWMF.java10
-rw-r--r--src/java/org/apache/poi/sl/usermodel/ObjectData.java8
-rw-r--r--src/java/org/apache/poi/ss/extractor/EmbeddedExtractor.java8
-rw-r--r--src/java/org/apache/poi/ss/format/CellNumberFormatter.java10
-rw-r--r--src/java/org/apache/poi/ss/formula/FormulaParser.java26
-rw-r--r--src/java/org/apache/poi/ss/formula/WorkbookEvaluator.java63
-rw-r--r--src/java/org/apache/poi/ss/formula/constant/ErrorConstant.java13
-rw-r--r--src/java/org/apache/poi/ss/formula/functions/Rate.java10
-rw-r--r--src/java/org/apache/poi/ss/usermodel/DataFormatter.java16
-rw-r--r--src/java/org/apache/poi/ss/usermodel/FractionFormat.java8
-rw-r--r--src/java/org/apache/poi/ss/util/CellUtil.java34
-rw-r--r--src/java/org/apache/poi/ss/util/DateFormatConverter.java8
-rw-r--r--src/java/org/apache/poi/ss/util/ImageUtils.java16
-rw-r--r--src/java/org/apache/poi/util/CommonsLogger.java177
-rw-r--r--src/java/org/apache/poi/util/Configurator.java7
-rw-r--r--src/java/org/apache/poi/util/IOUtils.java7
-rw-r--r--src/java/org/apache/poi/util/NullLogger.java81
-rw-r--r--src/java/org/apache/poi/util/POILogFactory.java122
-rw-r--r--src/java/org/apache/poi/util/POILogger.java128
-rw-r--r--src/java/org/apache/poi/util/SLF4JLogger.java157
-rw-r--r--src/java/org/apache/poi/util/SystemOutLogger.java96
-rw-r--r--src/java/org/apache/poi/util/XMLHelper.java17
84 files changed, 767 insertions, 1555 deletions
diff --git a/src/java/org/apache/poi/POIDocument.java b/src/java/org/apache/poi/POIDocument.java
index 97521691de..2a2c1acd92 100644
--- a/src/java/org/apache/poi/POIDocument.java
+++ b/src/java/org/apache/poi/POIDocument.java
@@ -17,18 +17,23 @@
package org.apache.poi;
+import static org.apache.logging.log4j.util.Unbox.box;
import static org.apache.poi.hpsf.PropertySetFactory.newDocumentSummaryInformation;
+import java.io.BufferedOutputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.Closeable;
import java.io.File;
+import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.security.GeneralSecurityException;
import java.util.List;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
import org.apache.poi.hpsf.DocumentSummaryInformation;
import org.apache.poi.hpsf.PropertySet;
import org.apache.poi.hpsf.PropertySetFactory;
@@ -43,8 +48,6 @@ import org.apache.poi.poifs.filesystem.DocumentInputStream;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.util.IOUtils;
import org.apache.poi.util.Internal;
-import org.apache.poi.util.POILogFactory;
-import org.apache.poi.util.POILogger;
/**
* This holds the common functionality for all POI
@@ -60,7 +63,7 @@ public abstract class POIDocument implements Closeable {
private DirectoryNode directory;
/** For our own logging use */
- private static final POILogger LOG = POILogFactory.getLogger(POIDocument.class);
+ private static final Logger LOG = LogManager.getLogger(POIDocument.class);
/* Have the property streams been read yet? (Only done on-demand) */
private boolean initialized;
@@ -162,12 +165,12 @@ public abstract class POIDocument implements Closeable {
if (clazz.isInstance(ps)) {
return (T)ps;
} else if (ps != null) {
- LOG.log(POILogger.WARN, localName+" property set came back with wrong class - "+ps.getClass().getName());
+ LOG.atWarn().log("{} property set came back with wrong class - {}", localName, ps.getClass().getName());
} else {
- LOG.log(POILogger.WARN, localName+" property set came back as null");
+ LOG.atWarn().log("{} property set came back as null {}", localName, box(5));
}
} catch (IOException e) {
- LOG.log(POILogger.ERROR, "can't retrieve property set", e);
+ LOG.atError().withThrowable(e).log("can't retrieve property set");
}
return null;
}
@@ -333,9 +336,9 @@ public abstract class POIDocument implements Closeable {
// Create or Update the Property Set stream in the POIFS
outFS.createOrUpdateDocument(bIn, name);
- LOG.log(POILogger.INFO, "Wrote property set ", name, " of size ", data.length);
+ LOG.atInfo().log("Wrote property set {} of size {}", name, box(data.length));
} catch(WritingNotSupportedException ignored) {
- LOG.log( POILogger.ERROR, "Couldn't write property set with name ", name, " as not supported by HPSF yet");
+ LOG.atError().log("Couldn't write property set with name {} as not supported by HPSF yet", name);
}
}
@@ -397,9 +400,9 @@ public abstract class POIDocument implements Closeable {
* {@link #write()} or to a different File. Overwriting the currently
* open file via an OutputStream isn't possible.
*
- * If {@code stream} is a {@link java.io.FileOutputStream} on a networked drive
+ * If {@code stream} is a {@link FileOutputStream} on a networked drive
* or has a high cost/latency associated with each written byte,
- * consider wrapping the OutputStream in a {@link java.io.BufferedOutputStream}
+ * consider wrapping the OutputStream in a {@link BufferedOutputStream}
* to improve write performance, or use {@link #write()} / {@link #write(File)}
* if possible.
*
diff --git a/src/java/org/apache/poi/common/usermodel/fonts/FontCharset.java b/src/java/org/apache/poi/common/usermodel/fonts/FontCharset.java
index 28df6cad4e..044765738f 100644
--- a/src/java/org/apache/poi/common/usermodel/fonts/FontCharset.java
+++ b/src/java/org/apache/poi/common/usermodel/fonts/FontCharset.java
@@ -20,8 +20,8 @@ package org.apache.poi.common.usermodel.fonts;
import java.nio.charset.Charset;
import java.nio.charset.UnsupportedCharsetException;
-import org.apache.poi.util.POILogFactory;
-import org.apache.poi.util.POILogger;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
/**
* Charset represents the basic set of characters associated with a font (that it can display), and
@@ -99,8 +99,8 @@ public enum FontCharset {
charset = Charset.forName(javaCharsetName);
return;
} catch (UnsupportedCharsetException e) {
- POILogger logger = POILogFactory.getLogger(FontCharset.class);
- logger.log(POILogger.WARN, "Unsupported charset: "+javaCharsetName);
+ Logger logger = LogManager.getLogger(FontCharset.class);
+ logger.atWarn().log("Unsupported charset: {}", javaCharsetName);
}
}
charset = null;
diff --git a/src/java/org/apache/poi/ddf/EscherContainerRecord.java b/src/java/org/apache/poi/ddf/EscherContainerRecord.java
index 0f192937bf..474b24a436 100644
--- a/src/java/org/apache/poi/ddf/EscherContainerRecord.java
+++ b/src/java/org/apache/poi/ddf/EscherContainerRecord.java
@@ -25,11 +25,13 @@ import java.util.List;
import java.util.Map;
import java.util.function.Supplier;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
import org.apache.poi.util.GenericRecordUtil;
import org.apache.poi.util.HexDump;
import org.apache.poi.util.LittleEndian;
-import org.apache.poi.util.POILogFactory;
-import org.apache.poi.util.POILogger;
+
+import static org.apache.logging.log4j.util.Unbox.box;
/**
* Escher container records store other escher records as children.
@@ -45,7 +47,7 @@ public final class EscherContainerRecord extends EscherRecord implements Iterabl
public static final short SP_CONTAINER = EscherRecordTypes.SP_CONTAINER.typeID;
public static final short SOLVER_CONTAINER = EscherRecordTypes.SOLVER_CONTAINER.typeID;
- private static final POILogger log = POILogFactory.getLogger(EscherContainerRecord.class);
+ private static final Logger LOGGER = LogManager.getLogger(EscherContainerRecord.class);
/**
* in case if document contains any charts we have such document structure:
@@ -95,9 +97,7 @@ public final class EscherContainerRecord extends EscherRecord implements Iterabl
addChildRecord(child);
if (offset >= data.length && bytesRemaining > 0) {
_remainingLength = bytesRemaining;
- if (log.check(POILogger.WARN)) {
- log.log(POILogger.WARN, "Not enough Escher data: " + bytesRemaining + " bytes remaining but no space left");
- }
+ LOGGER.atWarn().log("Not enough Escher data: {} bytes remaining but no space left", box(bytesRemaining));
}
}
return bytesWritten;
diff --git a/src/java/org/apache/poi/ddf/EscherMetafileBlip.java b/src/java/org/apache/poi/ddf/EscherMetafileBlip.java
index 19b4e20af5..6713b5fc17 100644
--- a/src/java/org/apache/poi/ddf/EscherMetafileBlip.java
+++ b/src/java/org/apache/poi/ddf/EscherMetafileBlip.java
@@ -29,14 +29,16 @@ import java.util.function.Supplier;
import java.util.zip.DeflaterOutputStream;
import java.util.zip.InflaterInputStream;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
import org.apache.poi.hssf.usermodel.HSSFPictureData;
import org.apache.poi.util.IOUtils;
import org.apache.poi.util.LittleEndian;
-import org.apache.poi.util.POILogFactory;
-import org.apache.poi.util.POILogger;
+
+import static org.apache.logging.log4j.util.Unbox.box;
public final class EscherMetafileBlip extends EscherBlipRecord {
- private static final POILogger log = POILogFactory.getLogger(EscherMetafileBlip.class);
+ private static final Logger LOGGER = LogManager.getLogger(EscherMetafileBlip.class);
//arbitrarily selected; may need to increase
private static final int MAX_RECORD_LENGTH = 100_000_000;
@@ -175,7 +177,7 @@ public final class EscherMetafileBlip extends EscherBlipRecord {
}
return out.toByteArray();
} catch (IOException e) {
- log.log(POILogger.WARN, "Possibly corrupt compression or non-compressed data", e);
+ LOGGER.atWarn().withThrowable(e).log("Possibly corrupt compression or non-compressed data");
return data;
}
}
@@ -375,9 +377,7 @@ public final class EscherMetafileBlip extends EscherBlipRecord {
case BLIP_WMF: return HSSFPictureData.MSOBI_WMF;
case BLIP_PICT: return HSSFPictureData.MSOBI_PICT;
}
- if (log.check(POILogger.WARN)) {
- log.log(POILogger.WARN, "Unknown metafile: " + getRecordId());
- }
+ LOGGER.atWarn().log("Unknown metafile: {}", box(getRecordId()));
return 0;
}
diff --git a/src/java/org/apache/poi/extractor/ExtractorFactory.java b/src/java/org/apache/poi/extractor/ExtractorFactory.java
index c310715bb2..a8d2f2d492 100644
--- a/src/java/org/apache/poi/extractor/ExtractorFactory.java
+++ b/src/java/org/apache/poi/extractor/ExtractorFactory.java
@@ -27,6 +27,8 @@ import java.util.List;
import java.util.ServiceLoader;
import java.util.stream.StreamSupport;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
import org.apache.poi.EmptyFileException;
import org.apache.poi.hssf.extractor.ExcelExtractor;
import org.apache.poi.poifs.crypt.Decryptor;
@@ -36,8 +38,6 @@ import org.apache.poi.poifs.filesystem.Entry;
import org.apache.poi.poifs.filesystem.FileMagic;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.util.IOUtils;
-import org.apache.poi.util.POILogFactory;
-import org.apache.poi.util.POILogger;
/**
* Figures out the correct POIOLE2TextExtractor for your supplied
@@ -60,7 +60,7 @@ public final class ExtractorFactory {
*/
public static final String OOXML_PACKAGE = "Package";
- private static final POILogger LOGGER = POILogFactory.getLogger(ExtractorFactory.class);
+ private static final Logger LOGGER = LogManager.getLogger(ExtractorFactory.class);
/** Should this thread prefer event based over usermodel based extractors? */
private static final ThreadLocal<Boolean> threadPreferEventExtractors = ThreadLocal.withInitial(() -> Boolean.FALSE);
@@ -293,7 +293,7 @@ public final class ExtractorFactory {
textExtractors.add(createExtractor(stream));
} catch (IOException e) {
// Ignore, just means it didn't contain a format we support as yet
- LOGGER.log(POILogger.INFO, "Format not supported yet", e.getLocalizedMessage());
+ LOGGER.atInfo().log("Format not supported yet ({})", e.getLocalizedMessage());
}
}
return textExtractors.toArray(new POITextExtractor[0]);
diff --git a/src/java/org/apache/poi/hpsf/ClipboardData.java b/src/java/org/apache/poi/hpsf/ClipboardData.java
index a5b18156c3..d92269a785 100644
--- a/src/java/org/apache/poi/hpsf/ClipboardData.java
+++ b/src/java/org/apache/poi/hpsf/ClipboardData.java
@@ -16,20 +16,22 @@
==================================================================== */
package org.apache.poi.hpsf;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
import org.apache.poi.util.IOUtils;
import org.apache.poi.util.Internal;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.LittleEndianByteArrayInputStream;
import org.apache.poi.util.LittleEndianConsts;
-import org.apache.poi.util.POILogFactory;
-import org.apache.poi.util.POILogger;
+
+import static org.apache.logging.log4j.util.Unbox.box;
@Internal
public class ClipboardData {
//arbitrarily selected; may need to increase
private static final int MAX_RECORD_LENGTH = 100_000_000;
- private static final POILogger LOG = POILogFactory.getLogger( ClipboardData.class );
+ private static final Logger LOG = LogManager.getLogger(ClipboardData.class);
private int _format;
private byte[] _value;
@@ -39,10 +41,8 @@ public class ClipboardData {
long size = lei.readInt();
if ( size < 4 ) {
- String msg =
- "ClipboardData at offset "+offset+" size less than 4 bytes "+
- "(doesn't even have format field!). Setting to format == 0 and hope for the best";
- LOG.log( POILogger.WARN, msg);
+ LOG.atWarn().log("ClipboardData at offset {} size less than 4 bytes (doesn't even have format " +
+ "field!). Setting to format == 0 and hope for the best", box(offset));
_format = 0;
_value = new byte[0];
return;
diff --git a/src/java/org/apache/poi/hpsf/CodePageString.java b/src/java/org/apache/poi/hpsf/CodePageString.java
index 7cd6b5a9d7..4ba9b0d063 100644
--- a/src/java/org/apache/poi/hpsf/CodePageString.java
+++ b/src/java/org/apache/poi/hpsf/CodePageString.java
@@ -20,21 +20,23 @@ import java.io.IOException;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
import org.apache.poi.util.CodePageUtil;
import org.apache.poi.util.IOUtils;
import org.apache.poi.util.Internal;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.LittleEndianByteArrayInputStream;
import org.apache.poi.util.LittleEndianConsts;
-import org.apache.poi.util.POILogFactory;
-import org.apache.poi.util.POILogger;
+
+import static org.apache.logging.log4j.util.Unbox.box;
@Internal
public class CodePageString {
//arbitrarily selected; may need to increase
private static final int MAX_RECORD_LENGTH = 100_000;
- private static final POILogger LOG = POILogFactory.getLogger( CodePageString.class );
+ private static final Logger LOG = LogManager.getLogger(CodePageString.class);
private byte[] _value;
@@ -61,8 +63,7 @@ public class CodePageString {
// TODO Some files, such as TestVisioWithCodepage.vsd, are currently
// triggering this for values that don't look like codepages
// See Bug #52258 for details
- String msg = "CodePageString started at offset #" + offset + " is not NULL-terminated";
- LOG.log(POILogger.WARN, msg);
+ LOG.atWarn().log("CodePageString started at offset #{} is not NULL-terminated", box(offset));
}
TypedPropertyValue.skipPadding(lei);
@@ -75,17 +76,13 @@ public class CodePageString {
final int terminator = result.indexOf( '\0' );
if ( terminator == -1 ) {
- String msg =
- "String terminator (\\0) for CodePageString property value not found. " +
- "Continue without trimming and hope for the best.";
- LOG.log(POILogger.WARN, msg);
+ LOG.atWarn().log("String terminator (\\0) for CodePageString property value not found. " +
+ "Continue without trimming and hope for the best.");
return result;
}
if ( terminator != result.length() - 1 ) {
- String msg =
- "String terminator (\\0) for CodePageString property value occured before the end of string. "+
- "Trimming and hope for the best.";
- LOG.log(POILogger.WARN, msg );
+ LOG.atWarn().log("String terminator (\\0) for CodePageString property value occurred before the end of " +
+ "string. Trimming and hope for the best.");
}
return result.substring( 0, terminator );
}
diff --git a/src/java/org/apache/poi/hpsf/CustomProperties.java b/src/java/org/apache/poi/hpsf/CustomProperties.java
index 6e901832d8..e260e3066f 100644
--- a/src/java/org/apache/poi/hpsf/CustomProperties.java
+++ b/src/java/org/apache/poi/hpsf/CustomProperties.java
@@ -31,10 +31,12 @@ import java.util.Map;
import java.util.Set;
import org.apache.commons.collections4.bidimap.TreeBidiMap;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
import org.apache.poi.hpsf.wellknown.PropertyIDMap;
import org.apache.poi.util.CodePageUtil;
-import org.apache.poi.util.POILogFactory;
-import org.apache.poi.util.POILogger;
+
+import static org.apache.logging.log4j.util.Unbox.box;
/**
* Maintains the instances of {@link CustomProperty} that belong to a
@@ -65,8 +67,8 @@ import org.apache.poi.util.POILogger;
* HashMap&lt;String,Object&gt; mapping between Names and Custom Property Values.
*/
public class CustomProperties implements Map<String,Object> {
- private static final POILogger LOG = POILogFactory.getLogger(CustomProperties.class);
-
+ private static final Logger LOG = LogManager.getLogger(CustomProperties.class);
+
/**
* The custom properties
*/
@@ -207,7 +209,7 @@ public class CustomProperties implements Map<String,Object> {
@Override
public void putAll(Map<? extends String, ?> m) {
- for (Map.Entry<? extends String, ?> me : m.entrySet()) {
+ for (Entry<? extends String, ?> me : m.entrySet()) {
put(me.getKey(), me.getValue());
}
}
@@ -393,12 +395,12 @@ public class CustomProperties implements Map<String,Object> {
try {
cps = CodePageUtil.codepageToEncoding(cp, false);
} catch (UnsupportedEncodingException e) {
- LOG.log(POILogger.ERROR, "Codepage '", cp, "' can't be found.");
+ LOG.atError().log("Codepage '{}' can't be found.", box(cp));
}
if (!cps.isEmpty() && Charset.forName(cps).newEncoder().canEncode(value)) {
return;
}
- LOG.log(POILogger.DEBUG, "Charset '"+cps+"' can't encode '"+value+"' - switching to unicode.");
+ LOG.atDebug().log("Charset '{}' can't encode '{}' - switching to unicode.", cps, value);
setCodepage(CodePageUtil.CP_UNICODE);
}
}
diff --git a/src/java/org/apache/poi/hpsf/Property.java b/src/java/org/apache/poi/hpsf/Property.java
index 8e45771dc8..0e3e2cdea2 100644
--- a/src/java/org/apache/poi/hpsf/Property.java
+++ b/src/java/org/apache/poi/hpsf/Property.java
@@ -24,10 +24,13 @@ import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
+import java.util.Date;
import java.util.Locale;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
import org.apache.poi.hpsf.wellknown.PropertyIDMap;
import org.apache.poi.util.CodePageUtil;
import org.apache.poi.util.HexDump;
@@ -35,8 +38,8 @@ import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.LittleEndianByteArrayInputStream;
import org.apache.poi.util.LittleEndianConsts;
import org.apache.poi.util.LocaleUtil;
-import org.apache.poi.util.POILogFactory;
-import org.apache.poi.util.POILogger;
+
+import static org.apache.logging.log4j.util.Unbox.box;
/**
* A property in a {@link Section} of a {@link PropertySet}.<p>
@@ -70,7 +73,7 @@ public class Property {
*/
public static final int DEFAULT_CODEPAGE = CodePageUtil.CP_WINDOWS_1252;
- private static final POILogger LOG = POILogFactory.getLogger(Property.class);
+ private static final Logger LOG = LogManager.getLogger(Property.class);
/** The property's ID. */
private long id;
@@ -293,7 +296,7 @@ public class Property {
* section's dictionary. Another special case are strings: Two properties
* may have the different types Variant.VT_LPSTR and Variant.VT_LPWSTR;
*
- * @see Object#equals(java.lang.Object)
+ * @see Object#equals(Object)
*/
@Override
public boolean equals(final Object o) {
@@ -412,7 +415,7 @@ public class Property {
try {
write(bos, codepage);
} catch (Exception e) {
- LOG.log(POILogger.WARN, "can't serialize string", e);
+ LOG.atWarn().withThrowable(e).log("can't serialize string");
}
// skip length field
@@ -427,8 +430,8 @@ public class Property {
String hex = HexDump.dump(bytes, 0L, 0);
b.append(hex);
}
- } else if (value instanceof java.util.Date) {
- java.util.Date d = (java.util.Date)value;
+ } else if (value instanceof Date) {
+ Date d = (Date)value;
long filetime = Filetime.dateToFileTime(d);
if (Filetime.isUndefined(d)) {
b.append("<undefined>");
@@ -484,7 +487,7 @@ public class Property {
return LocaleUtil.getLocaleFromLCID(((Number)value).intValue());
}
} catch (Exception e) {
- LOG.log(POILogger.WARN, "Can't decode id "+getID());
+ LOG.atWarn().log("Can't decode id {}", box(getID()));
}
return null;
}
diff --git a/src/java/org/apache/poi/hpsf/Section.java b/src/java/org/apache/poi/hpsf/Section.java
index 89802a017a..c404e49858 100644
--- a/src/java/org/apache/poi/hpsf/Section.java
+++ b/src/java/org/apache/poi/hpsf/Section.java
@@ -31,6 +31,8 @@ import java.util.Set;
import java.util.TreeMap;
import org.apache.commons.collections4.bidimap.TreeBidiMap;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
import org.apache.poi.hpsf.wellknown.PropertyIDMap;
import org.apache.poi.util.CodePageUtil;
import org.apache.poi.util.IOUtils;
@@ -38,8 +40,6 @@ import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.LittleEndianByteArrayInputStream;
import org.apache.poi.util.LittleEndianConsts;
import org.apache.poi.util.LittleEndianOutputStream;
-import org.apache.poi.util.POILogFactory;
-import org.apache.poi.util.POILogger;
/**
* Represents a section in a {@link PropertySet}.
@@ -48,7 +48,7 @@ public class Section {
//arbitrarily selected; may need to increase
private static final int MAX_RECORD_LENGTH = 100_000;
- private static final POILogger LOG = POILogFactory.getLogger(Section.class);
+ private static final Logger LOG = LogManager.getLogger(Section.class);
/**
* Maps property IDs to section-private PID strings. These
@@ -235,7 +235,7 @@ public class Section {
id = Math.max(PropertyIDMap.PID_MAX, offset2Id.inverseBidiMap().lastKey())+1;
setProperty(new Property(id, leis, pLen, codepage));
} catch (RuntimeException e) {
- LOG.log(POILogger.INFO, "Dictionary fallback failed - ignoring property");
+ LOG.atInfo().log("Dictionary fallback failed - ignoring property");
}
}
} else {
@@ -730,10 +730,8 @@ public class Section {
* (property 0) the codepage property (property 1) must be set, too. */
int codepage = getCodepage();
if (codepage == -1) {
- String msg =
- "The codepage property is not set although a dictionary is present. "+
- "Defaulting to ISO-8859-1.";
- LOG.log(POILogger.WARN, msg);
+ LOG.atWarn().log("The codepage property is not set although a dictionary is present. " +
+ "Defaulting to ISO-8859-1.");
codepage = Property.DEFAULT_CODEPAGE;
}
@@ -826,7 +824,7 @@ public class Section {
int cp = (codepage == -1) ? Property.DEFAULT_CODEPAGE : codepage;
int nrBytes = Math.toIntExact(((sLength-1) * (cp == CodePageUtil.CP_UNICODE ? 2 : 1)));
if (nrBytes > 0xFFFFFF) {
- LOG.log(POILogger.WARN, errMsg);
+ LOG.atWarn().log(errMsg);
isCorrupted = true;
break;
}
@@ -844,7 +842,7 @@ public class Section {
dic.put(id, str);
} catch (RuntimeException|IOException ex) {
- LOG.log(POILogger.WARN, errMsg, ex);
+ LOG.atWarn().withThrowable(ex).log(errMsg);
isCorrupted = true;
break;
}
@@ -894,8 +892,8 @@ public class Section {
/**
* Sets the section's dictionary. All keys in the dictionary must be
- * {@link java.lang.Long} instances, all values must be
- * {@link java.lang.String}s. This method overwrites the properties with IDs
+ * {@link Long} instances, all values must be
+ * {@link String}s. This method overwrites the properties with IDs
* 0 and 1 since they are reserved for the dictionary and the dictionary's
* codepage. Setting these properties explicitly might have surprising
* effects. An application should never do this but always use this
diff --git a/src/java/org/apache/poi/hpsf/TypedPropertyValue.java b/src/java/org/apache/poi/hpsf/TypedPropertyValue.java
index 0cba4a6204..1b4f5c6489 100644
--- a/src/java/org/apache/poi/hpsf/TypedPropertyValue.java
+++ b/src/java/org/apache/poi/hpsf/TypedPropertyValue.java
@@ -20,15 +20,17 @@ package org.apache.poi.hpsf;
import java.math.BigInteger;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
import org.apache.poi.util.Internal;
import org.apache.poi.util.LittleEndianByteArrayInputStream;
import org.apache.poi.util.LittleEndianConsts;
-import org.apache.poi.util.POILogFactory;
-import org.apache.poi.util.POILogger;
+
+import static org.apache.logging.log4j.util.Unbox.box;
@Internal
public class TypedPropertyValue {
- private static final POILogger LOG = POILogFactory.getLogger( TypedPropertyValue.class );
+ private static final Logger LOG = LogManager.getLogger(TypedPropertyValue.class);
private int _type;
private Object _value;
@@ -46,8 +48,7 @@ public class TypedPropertyValue {
_type = lei.readShort();
short padding = lei.readShort();
if ( padding != 0 ) {
- LOG.log( POILogger.WARN, "TypedPropertyValue padding at offset "
- + lei.getReadIndex() + " MUST be 0, but it's value is " + padding );
+ LOG.atWarn().log("TypedPropertyValue padding at offset {} MUST be 0, but it's value is {}", box(lei.getReadIndex()),box(padding));
}
readValue( lei );
}
diff --git a/src/java/org/apache/poi/hpsf/UnicodeString.java b/src/java/org/apache/poi/hpsf/UnicodeString.java
index f6be7d3768..866a2b2acd 100644
--- a/src/java/org/apache/poi/hpsf/UnicodeString.java
+++ b/src/java/org/apache/poi/hpsf/UnicodeString.java
@@ -20,19 +20,19 @@ import java.io.IOException;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
import org.apache.poi.util.CodePageUtil;
import org.apache.poi.util.IOUtils;
import org.apache.poi.util.Internal;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.LittleEndianByteArrayInputStream;
import org.apache.poi.util.LittleEndianConsts;
-import org.apache.poi.util.POILogFactory;
-import org.apache.poi.util.POILogger;
import org.apache.poi.util.StringUtil;
@Internal
public class UnicodeString {
- private static final POILogger LOG = POILogFactory.getLogger( UnicodeString.class );
+ private static final Logger LOG = LogManager.getLogger(UnicodeString.class);
//arbitrarily selected; may need to increase
private static final int MAX_RECORD_LENGTH = 100_000;
@@ -77,18 +77,14 @@ public class UnicodeString {
final int terminator = result.indexOf( '\0' );
if ( terminator == -1 ) {
- String msg =
- "String terminator (\\0) for UnicodeString property value not found. " +
- "Continue without trimming and hope for the best.";
- LOG.log(POILogger.WARN, msg);
+ LOG.atWarn().log("String terminator (\\0) for UnicodeString property value not found. " +
+ "Continue without trimming and hope for the best.");
return result;
}
if ( terminator != result.length() - 1 ) {
- String msg =
- "String terminator (\\0) for UnicodeString property value occured before the end of string. " +
- "Trimming and hope for the best.";
- LOG.log(POILogger.WARN, msg);
+ LOG.atWarn().log("String terminator (\\0) for UnicodeString property value occured before the end of " +
+ "string. Trimming and hope for the best.");
}
return result.substring( 0, terminator );
}
diff --git a/src/java/org/apache/poi/hpsf/VariantBool.java b/src/java/org/apache/poi/hpsf/VariantBool.java
index dc8659483e..0f59164688 100644
--- a/src/java/org/apache/poi/hpsf/VariantBool.java
+++ b/src/java/org/apache/poi/hpsf/VariantBool.java
@@ -16,14 +16,16 @@
==================================================================== */
package org.apache.poi.hpsf;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
import org.apache.poi.util.Internal;
import org.apache.poi.util.LittleEndianByteArrayInputStream;
-import org.apache.poi.util.POILogFactory;
-import org.apache.poi.util.POILogger;
+
+import static org.apache.logging.log4j.util.Unbox.box;
@Internal
public class VariantBool {
- private static final POILogger LOG = POILogFactory.getLogger( VariantBool.class );
+ private static final Logger LOG = LogManager.getLogger(VariantBool.class);
static final int SIZE = 2;
@@ -39,7 +41,7 @@ public class VariantBool {
_value = true;
break;
default:
- LOG.log( POILogger.WARN, "VARIANT_BOOL value '"+value+"' is incorrect" );
+ LOG.atWarn().log("VARIANT_BOOL value '{}' is incorrect", box(value));
_value = true;
break;
}
diff --git a/src/java/org/apache/poi/hpsf/VariantSupport.java b/src/java/org/apache/poi/hpsf/VariantSupport.java
index 4fd4a7e75d..5d49c8a28e 100644
--- a/src/java/org/apache/poi/hpsf/VariantSupport.java
+++ b/src/java/org/apache/poi/hpsf/VariantSupport.java
@@ -25,12 +25,12 @@ import java.util.Date;
import java.util.LinkedList;
import java.util.List;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
import org.apache.poi.util.IOUtils;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.LittleEndianByteArrayInputStream;
import org.apache.poi.util.LittleEndianConsts;
-import org.apache.poi.util.POILogFactory;
-import org.apache.poi.util.POILogger;
/**
* Supports reading and writing of variant data.<p>
@@ -58,7 +58,7 @@ public class VariantSupport extends Variant {
Variant.VT_CF, Variant.VT_BOOL };
- private static final POILogger LOG = POILogFactory.getLogger(VariantSupport.class);
+ private static final Logger LOG = LogManager.getLogger(VariantSupport.class);
//arbitrarily selected; may need to increase
private static final int MAX_RECORD_LENGTH = 100_000;
@@ -114,7 +114,7 @@ public class VariantSupport extends Variant {
Long vt = Long.valueOf(ex.getVariantType());
if (!unsupportedMessage.contains(vt))
{
- LOG.log( POILogger.ERROR, ex.getMessage());
+ LOG.atError().withThrowable(ex).log("Unsupported type");
unsupportedMessage.add(vt);
}
}
diff --git a/src/java/org/apache/poi/hssf/dev/BiffViewer.java b/src/java/org/apache/poi/hssf/dev/BiffViewer.java
index 998df2fa7b..4adbedad61 100644
--- a/src/java/org/apache/poi/hssf/dev/BiffViewer.java
+++ b/src/java/org/apache/poi/hssf/dev/BiffViewer.java
@@ -31,6 +31,8 @@ import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
import org.apache.poi.hssf.record.*;
import org.apache.poi.hssf.record.RecordInputStream.LeftoverDataException;
import org.apache.poi.hssf.record.chart.*;
@@ -46,18 +48,19 @@ import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.util.HexDump;
import org.apache.poi.util.IOUtils;
import org.apache.poi.util.LittleEndian;
-import org.apache.poi.util.POILogFactory;
-import org.apache.poi.util.POILogger;
+import org.apache.poi.util.RecordFormatException;
import org.apache.poi.util.StringUtil;
import org.apache.poi.util.SuppressForbidden;
+import static org.apache.logging.log4j.util.Unbox.box;
+
/**
* Utility for reading in BIFF8 records and displaying data from them.
* @see #main
*/
public final class BiffViewer {
private static final char[] NEW_LINE_CHARS = System.getProperty("line.separator").toCharArray();
- private static final POILogger LOG = POILogFactory.getLogger(BiffViewer.class);
+ private static final Logger LOG = LogManager.getLogger(BiffViewer.class);
private BiffViewer() {
// no instances of this class
@@ -71,17 +74,17 @@ public final class BiffViewer {
* @param recListener the record listener to notify about read records
* @param dumpInterpretedRecords if {@code true}, the read records will be written to the PrintWriter
*
- * @exception org.apache.poi.util.RecordFormatException on error processing the InputStream
+ * @exception RecordFormatException on error processing the InputStream
*/
private static void createRecords(InputStream is, PrintWriter ps, BiffRecordListener recListener, boolean dumpInterpretedRecords)
- throws org.apache.poi.util.RecordFormatException {
+ throws RecordFormatException {
RecordInputStream recStream = new RecordInputStream(is);
while (true) {
boolean hasNext;
try {
hasNext = recStream.hasNextRecord();
} catch (LeftoverDataException e) {
- LOG.log(POILogger.ERROR, "Discarding ", recStream.remaining(), " bytes and continuing", e);
+ LOG.atError().withThrowable(e).log("Discarding {} bytes and continuing", box(recStream.remaining()));
recStream.readRemainder();
hasNext = recStream.hasNextRecord();
}
@@ -92,7 +95,7 @@ public final class BiffViewer {
if (recStream.getSid() == 0) {
continue;
}
- org.apache.poi.hssf.record.Record record;
+ Record record;
if (dumpInterpretedRecords) {
record = createRecord (recStream);
if (record.getSid() == ContinueRecord.sid) {
@@ -116,7 +119,7 @@ public final class BiffViewer {
* up non-debug operations.
*
*/
- private static org.apache.poi.hssf.record.Record createRecord(RecordInputStream in) {
+ private static Record createRecord(RecordInputStream in) {
switch (in.getSid()) {
case AreaFormatRecord.sid: return new AreaFormatRecord(in);
case AreaRecord.sid: return new AreaRecord(in);
diff --git a/src/java/org/apache/poi/hssf/eventusermodel/FormatTrackingHSSFListener.java b/src/java/org/apache/poi/hssf/eventusermodel/FormatTrackingHSSFListener.java
index 16c7bdfb1a..fcd4cdd2a3 100644
--- a/src/java/org/apache/poi/hssf/eventusermodel/FormatTrackingHSSFListener.java
+++ b/src/java/org/apache/poi/hssf/eventusermodel/FormatTrackingHSSFListener.java
@@ -23,16 +23,19 @@ import java.util.List;
import java.util.Locale;
import java.util.Map;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
import org.apache.poi.hssf.record.CellValueRecordInterface;
import org.apache.poi.hssf.record.ExtendedFormatRecord;
import org.apache.poi.hssf.record.FormatRecord;
import org.apache.poi.hssf.record.FormulaRecord;
import org.apache.poi.hssf.record.NumberRecord;
+import org.apache.poi.hssf.record.Record;
import org.apache.poi.hssf.usermodel.HSSFDataFormat;
import org.apache.poi.hssf.usermodel.HSSFDataFormatter;
import org.apache.poi.util.LocaleUtil;
-import org.apache.poi.util.POILogFactory;
-import org.apache.poi.util.POILogger;
+
+import static org.apache.logging.log4j.util.Unbox.box;
/**
* A proxy HSSFListener that keeps track of the document formatting records, and
@@ -40,7 +43,7 @@ import org.apache.poi.util.POILogger;
* ids.
*/
public class FormatTrackingHSSFListener implements HSSFListener {
- private static final POILogger LOG = POILogFactory.getLogger(FormatTrackingHSSFListener.class);
+ private static final Logger LOG = LogManager.getLogger(FormatTrackingHSSFListener.class);
private final HSSFListener _childListener;
private final HSSFDataFormatter _formatter;
private final NumberFormat _defaultFormat;
@@ -83,7 +86,7 @@ public class FormatTrackingHSSFListener implements HSSFListener {
* Process this record ourselves, and then pass it on to our child listener
*/
@Override
- public void processRecord(org.apache.poi.hssf.record.Record record) {
+ public void processRecord(Record record) {
// Handle it ourselves
processRecordInternally(record);
@@ -97,7 +100,7 @@ public class FormatTrackingHSSFListener implements HSSFListener {
*
* @param record the record to be processed
*/
- public void processRecordInternally(org.apache.poi.hssf.record.Record record) {
+ public void processRecordInternally(Record record) {
if (record instanceof FormatRecord) {
FormatRecord fr = (FormatRecord) record;
_customFormatRecords.put(Integer.valueOf(fr.getIndexCode()), fr);
@@ -154,8 +157,7 @@ public class FormatTrackingHSSFListener implements HSSFListener {
if (formatIndex >= HSSFDataFormat.getNumberOfBuiltinBuiltinFormats()) {
FormatRecord tfr = _customFormatRecords.get(Integer.valueOf(formatIndex));
if (tfr == null) {
- LOG.log( POILogger.ERROR, "Requested format at index ", formatIndex,
- ", but it wasn't found");
+ LOG.atError().log("Requested format at index {}, but it wasn't found", box(formatIndex));
} else {
format = tfr.getFormatString();
}
@@ -191,8 +193,7 @@ public class FormatTrackingHSSFListener implements HSSFListener {
public int getFormatIndex(CellValueRecordInterface cell) {
ExtendedFormatRecord xfr = _xfRecords.get(cell.getXFIndex());
if (xfr == null) {
- LOG.log( POILogger.ERROR, "Cell ", cell.getRow(), ",", cell.getColumn(),
- " uses XF with index ", cell.getXFIndex(), ", but we don't have that");
+ LOG.atError().log("Cell {},{} uses XF with index {}, but we don't have that", box(cell.getRow()),box(cell.getColumn()),box(cell.getXFIndex()));
return -1;
}
return xfr.getFormatIndex();
diff --git a/src/java/org/apache/poi/hssf/model/InternalSheet.java b/src/java/org/apache/poi/hssf/model/InternalSheet.java
index c28dbee408..efba5e75c5 100644
--- a/src/java/org/apache/poi/hssf/model/InternalSheet.java
+++ b/src/java/org/apache/poi/hssf/model/InternalSheet.java
@@ -21,6 +21,9 @@ import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.message.SimpleMessage;
import org.apache.poi.hssf.record.*;
import org.apache.poi.hssf.record.aggregates.ChartSubstreamRecordAggregate;
import org.apache.poi.hssf.record.aggregates.ColumnInfoRecordsAggregate;
@@ -34,14 +37,15 @@ import org.apache.poi.hssf.record.aggregates.RecordAggregate.PositionTrackingVis
import org.apache.poi.hssf.record.aggregates.RecordAggregate.RecordVisitor;
import org.apache.poi.hssf.record.aggregates.RowRecordsAggregate;
import org.apache.poi.hssf.record.aggregates.WorksheetProtectionBlock;
+import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.ss.formula.FormulaShifter;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.ss.util.PaneInformation;
import org.apache.poi.util.Internal;
-import org.apache.poi.util.POILogFactory;
-import org.apache.poi.util.POILogger;
import org.apache.poi.util.RecordFormatException;
+import static org.apache.logging.log4j.util.Unbox.box;
+
/**
* Low level model implementation of a Sheet (one workbook contains many sheets)
* This file contains the low level binary records starting at the sheets BOF and
@@ -53,8 +57,8 @@ import org.apache.poi.util.RecordFormatException;
* Kit (Microsoft Press) and the documentation at http://sc.openoffice.org/excelfileformat.pdf
* before even attempting to use this.
*
- * @see org.apache.poi.hssf.model.InternalWorkbook
- * @see org.apache.poi.hssf.usermodel.HSSFSheet
+ * @see InternalWorkbook
+ * @see HSSFSheet
*/
@Internal
public final class InternalSheet {
@@ -63,7 +67,7 @@ public final class InternalSheet {
public static final short TopMargin = 2;
public static final short BottomMargin = 3;
- private static POILogger log = POILogFactory.getLogger(InternalSheet.class);
+ private static final Logger LOGGER = LogManager.getLogger(InternalSheet.class);
private List<RecordBase> _records;
protected PrintGridlinesRecord printGridlines;
@@ -115,8 +119,8 @@ public final class InternalSheet {
*
* @return Sheet object with all values set to those read from the file
*
- * @see org.apache.poi.hssf.model.InternalWorkbook
- * @see org.apache.poi.hssf.record.Record
+ * @see InternalWorkbook
+ * @see Record
*/
public static InternalSheet createSheet(RecordStream rs) {
return new InternalSheet(rs);
@@ -144,7 +148,7 @@ public final class InternalSheet {
// Not a supported type
// Skip onto the EOF, then complain
while (rs.hasNext()) {
- org.apache.poi.hssf.record.Record rec = rs.getNext();
+ Record rec = rs.getNext();
if (rec instanceof EOFRecord) {
break;
}
@@ -229,7 +233,7 @@ public final class InternalSheet {
continue;
}
- org.apache.poi.hssf.record.Record rec = rs.getNext();
+ Record rec = rs.getNext();
if ( recSid == IndexRecord.sid ) {
// ignore INDEX record because it is only needed by Excel,
// and POI always re-calculates its contents
@@ -313,9 +317,7 @@ public final class InternalSheet {
// Not clear which application wrote these files.
rra = new RowRecordsAggregate();
} else {
- if (log.check(POILogger.WARN)) {
- log.log(POILogger.WARN, "DIMENSION record not found even though row/cells present");
- }
+ LOGGER.atWarn().log("DIMENSION record not found even though row/cells present");
// Not sure if any tools write files like this, but Excel reads them OK
}
dimsloc = findFirstRecordLocBySid(WindowTwoRecord.sid);
@@ -330,8 +332,7 @@ public final class InternalSheet {
// put merged cells table in the right place (regardless of where the first MergedCellsRecord was found */
RecordOrderer.addNewSheetRecord(records, _mergedCellsTable);
RecordOrderer.addNewSheetRecord(records, _protectionBlock);
- if (log.check( POILogger.DEBUG ))
- log.log(POILogger.DEBUG, "sheet createSheet (existing file) exited");
+ LOGGER.atDebug().log("sheet createSheet (existing file) exited");
}
private static void spillAggregate(RecordAggregate ra, final List<RecordBase> recs) {
ra.visitContainedRecords(r -> recs.add(r));
@@ -351,12 +352,12 @@ public final class InternalSheet {
private static final class RecordCloner implements RecordVisitor {
- private final List<org.apache.poi.hssf.record.Record> _destList;
+ private final List<Record> _destList;
- public RecordCloner(List<org.apache.poi.hssf.record.Record> destList) {
+ public RecordCloner(List<Record> destList) {
_destList = destList;
}
- public void visitRecord(org.apache.poi.hssf.record.Record r) {
+ public void visitRecord(Record r) {
_destList.add(r.copy());
}
}
@@ -371,7 +372,7 @@ public final class InternalSheet {
* @return the cloned sheet
*/
public InternalSheet cloneSheet() {
- List<org.apache.poi.hssf.record.Record> clonedRecords = new ArrayList<>(_records.size());
+ List<Record> clonedRecords = new ArrayList<>(_records.size());
for (int i = 0; i < _records.size(); i++) {
RecordBase rb = _records.get(i);
if (rb instanceof RecordAggregate) {
@@ -384,7 +385,7 @@ public final class InternalSheet {
*/
rb = new DrawingRecord();
}
- org.apache.poi.hssf.record.Record rec = ((org.apache.poi.hssf.record.Record) rb).copy();
+ Record rec = ((Record) rb).copy();
clonedRecords.add(rec);
}
return createSheet(new RecordStream(clonedRecords, 0));
@@ -405,7 +406,7 @@ public final class InternalSheet {
_mergedCellsTable = new MergedCellsTable();
List<RecordBase> records = new ArrayList<>(32);
- log.log(POILogger.DEBUG, "Sheet createsheet from scratch called");
+ LOGGER.atDebug().log("Sheet createsheet from scratch called");
records.add(createBOF());
@@ -452,7 +453,7 @@ public final class InternalSheet {
records.add(EOFRecord.instance);
_records = records;
- log.log(POILogger.DEBUG, "Sheet createsheet from scratch exit");
+ LOGGER.atDebug().log("Sheet createsheet from scratch exit");
}
public RowRecordsAggregate getRowsAggregate() {
@@ -533,24 +534,22 @@ public final class InternalSheet {
* @param lastrow the last row index
* @param lastcol the last column index
*
- * @see org.apache.poi.hssf.record.DimensionsRecord
+ * @see DimensionsRecord
*/
public void setDimensions(int firstrow, short firstcol, int lastrow, short lastcol)
{
- if (log.check( POILogger.DEBUG ))
- {
- log.log(POILogger.DEBUG, "Sheet.setDimensions");
- log.log(POILogger.DEBUG,
- (new StringBuilder("firstrow")).append(firstrow)
- .append("firstcol").append(firstcol).append("lastrow")
- .append(lastrow).append("lastcol").append(lastcol)
- .toString());
- }
+ LOGGER.atDebug().log("Sheet.setDimensions");
+ LOGGER.atDebug().log(() -> new SimpleMessage(
+ "firstrow" + firstrow +
+ "firstcol" + firstcol +
+ "lastrow" + lastrow +
+ "lastcol" + lastcol
+ ));
_dimensions.setFirstCol(firstcol);
_dimensions.setFirstRow(firstrow);
_dimensions.setLastCol(lastcol);
_dimensions.setLastRow(lastrow);
- log.log(POILogger.DEBUG, "Sheet.setDimensions exiting");
+ LOGGER.atDebug().log("Sheet.setDimensions exiting");
}
public void visitContainedRecords(RecordVisitor rv, int offset) {
@@ -566,7 +565,7 @@ public final class InternalSheet {
RecordAggregate agg = (RecordAggregate) record;
agg.visitContainedRecords(ptv);
} else {
- ptv.visitRecord((org.apache.poi.hssf.record.Record) record);
+ ptv.visitRecord((Record) record);
}
// If the BOF record was just serialized then add the IndexRecord
@@ -628,9 +627,7 @@ public final class InternalSheet {
*/
public void addValueRecord(int row, CellValueRecordInterface col) {
- if(log.check(POILogger.DEBUG)) {
- log.log(POILogger.DEBUG, "add value record row" + row);
- }
+ LOGGER.atDebug().log("add value record row{}", box(row));
DimensionsRecord d = _dimensions;
if (col.getColumn() >= d.getLastCol()) {
@@ -649,11 +646,11 @@ public final class InternalSheet {
*
* @param row - the row of the value record you wish to remove
* @param col - a record supporting the CellValueRecordInterface.
- * @see org.apache.poi.hssf.record.CellValueRecordInterface
+ * @see CellValueRecordInterface
*/
public void removeValueRecord(int row, CellValueRecordInterface col) {
- log.log(POILogger.DEBUG, "remove value record row "+row);
+ LOGGER.atDebug().log("remove value record row {}", box(row));
_rowsAggregate.removeCell(col);
}
@@ -669,8 +666,7 @@ public final class InternalSheet {
public void replaceValueRecord(CellValueRecordInterface newval) {
- if (log.check( POILogger.DEBUG ))
- log.log(POILogger.DEBUG, "replaceValueRecord ");
+ LOGGER.atDebug().log("replaceValueRecord ");
//The ValueRecordsAggregate use a tree map underneath.
//The tree Map uses the CellValueRecordInterface as both the
//key and the value, if we dont do a remove, then
@@ -693,8 +689,7 @@ public final class InternalSheet {
*/
public void addRow(RowRecord row) {
- if (log.check( POILogger.DEBUG ))
- log.log(POILogger.DEBUG, "addRow ");
+ LOGGER.atDebug().log("addRow ");
DimensionsRecord d = _dimensions;
if (row.getRowNumber() >= d.getLastRow()) {
@@ -712,8 +707,7 @@ public final class InternalSheet {
_rowsAggregate.insertRow(row);
- if (log.check( POILogger.DEBUG ))
- log.log(POILogger.DEBUG, "exit addRow");
+ LOGGER.atDebug().log("exit addRow");
}
/**
@@ -1002,8 +996,8 @@ public final class InternalSheet {
/**
* get the width of a given column in units of 1/256th of a character width
* @param columnIndex index
- * @see org.apache.poi.hssf.record.DefaultColWidthRecord
- * @see org.apache.poi.hssf.record.ColumnInfoRecord
+ * @see DefaultColWidthRecord
+ * @see ColumnInfoRecord
* @see #setColumnWidth(int, int)
* @return column width in units of 1/256th of a character width
*/
@@ -1057,8 +1051,8 @@ public final class InternalSheet {
/**
* Get the hidden property for a given column.
* @param columnIndex column index
- * @see org.apache.poi.hssf.record.DefaultColWidthRecord
- * @see org.apache.poi.hssf.record.ColumnInfoRecord
+ * @see DefaultColWidthRecord
+ * @see ColumnInfoRecord
* @see #setColumnHidden(int, boolean)
* @return whether the column is hidden or not.
*/
@@ -1180,7 +1174,7 @@ public final class InternalSheet {
/**
* Returns the active row
*
- * @see org.apache.poi.hssf.record.SelectionRecord
+ * @see SelectionRecord
* @return row the active row index
*/
public int getActiveCellRow() {
@@ -1194,7 +1188,7 @@ public final class InternalSheet {
* Sets the active row
*
* @param row the row index
- * @see org.apache.poi.hssf.record.SelectionRecord
+ * @see SelectionRecord
*/
public void setActiveCellRow(int row) {
//shouldn't have a sheet w/o a SelectionRecord, but best to guard anyway
@@ -1204,7 +1198,7 @@ public final class InternalSheet {
}
/**
- * @see org.apache.poi.hssf.record.SelectionRecord
+ * @see SelectionRecord
* @return column of the active cell
*/
public short getActiveCellCol() {
@@ -1218,7 +1212,7 @@ public final class InternalSheet {
* Sets the active column
*
* @param col the column index
- * @see org.apache.poi.hssf.record.SelectionRecord
+ * @see SelectionRecord
*/
public void setActiveCellCol(short col) {
//shouldn't have a sheet w/o a SelectionRecord, but best to guard anyway
@@ -1249,12 +1243,12 @@ public final class InternalSheet {
*
* @return the matching record or {@code null} if it wasn't found
*/
- public org.apache.poi.hssf.record.Record findFirstRecordBySid(short sid) {
+ public Record findFirstRecordBySid(short sid) {
int ix = findFirstRecordLocBySid(sid);
if (ix < 0) {
return null;
}
- return (org.apache.poi.hssf.record.Record) _records.get(ix);
+ return (Record) _records.get(ix);
}
/**
@@ -1285,10 +1279,10 @@ public final class InternalSheet {
int max = _records.size();
for (int i=0; i< max; i++) {
Object rb = _records.get(i);
- if (!(rb instanceof org.apache.poi.hssf.record.Record)) {
+ if (!(rb instanceof Record)) {
continue;
}
- org.apache.poi.hssf.record.Record record = (org.apache.poi.hssf.record.Record) rb;
+ Record record = (Record) rb;
if (record.getSid() == sid) {
return i;
}
diff --git a/src/java/org/apache/poi/hssf/model/InternalWorkbook.java b/src/java/org/apache/poi/hssf/model/InternalWorkbook.java
index e1d4f85718..58f86ef36c 100644
--- a/src/java/org/apache/poi/hssf/model/InternalWorkbook.java
+++ b/src/java/org/apache/poi/hssf/model/InternalWorkbook.java
@@ -17,7 +17,7 @@
package org.apache.poi.hssf.model;
-import static org.apache.poi.util.POILogger.DEBUG;
+import static org.apache.logging.log4j.util.Unbox.box;
import java.security.AccessControlException;
import java.util.ArrayList;
@@ -26,6 +26,8 @@ import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
import org.apache.poi.ddf.EscherBSERecord;
import org.apache.poi.ddf.EscherBoolProperty;
import org.apache.poi.ddf.EscherContainerRecord;
@@ -41,6 +43,7 @@ import org.apache.poi.ddf.EscherSplitMenuColorsRecord;
import org.apache.poi.hssf.extractor.OldExcelExtractor;
import org.apache.poi.hssf.record.*;
import org.apache.poi.hssf.record.common.UnicodeString;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.HSSFColor.HSSFColorPredefined;
import org.apache.poi.poifs.crypt.CryptoFunctions;
import org.apache.poi.ss.formula.EvaluationWorkbook.ExternalName;
@@ -58,8 +61,6 @@ import org.apache.poi.ss.usermodel.SheetVisibility;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.util.Internal;
import org.apache.poi.util.LocaleUtil;
-import org.apache.poi.util.POILogFactory;
-import org.apache.poi.util.POILogger;
import org.apache.poi.util.RecordFormatException;
/**
@@ -75,7 +76,7 @@ import org.apache.poi.util.RecordFormatException;
* Kit (Microsoft Press) and the documentation at http://sc.openoffice.org/excelfileformat.pdf
* before even attempting to use this.
*
- * @see org.apache.poi.hssf.usermodel.HSSFWorkbook
+ * @see HSSFWorkbook
*/
@Internal
public final class InternalWorkbook {
@@ -103,7 +104,7 @@ public final class InternalWorkbook {
*/
public static final String OLD_WORKBOOK_DIR_ENTRY_NAME = "Book";
- private static final POILogger LOG = POILogFactory.getLogger(InternalWorkbook.class);
+ private static final Logger LOG = LogManager.getLogger(InternalWorkbook.class);
/**
* constant used to set the "codepage" wherever "codepage" is set in records
@@ -179,15 +180,15 @@ public final class InternalWorkbook {
* @param recs an array of Record objects
* @return Workbook object
*/
- public static InternalWorkbook createWorkbook(List<org.apache.poi.hssf.record.Record> recs) {
- LOG.log(DEBUG, "Workbook (readfile) created with reclen=", recs.size());
+ public static InternalWorkbook createWorkbook(List<Record> recs) {
+ LOG.atDebug().log("Workbook (readfile) created with reclen={}", box(recs.size()));
InternalWorkbook retval = new InternalWorkbook();
- List<org.apache.poi.hssf.record.Record> records = new ArrayList<>(recs.size() / 3);
+ List<Record> records = new ArrayList<>(recs.size() / 3);
retval.records.setRecords(records);
boolean eofPassed = false;
for (int k = 0; k < recs.size(); k++) {
- org.apache.poi.hssf.record.Record rec = recs.get(k);
+ Record rec = recs.get(k);
String logObj;
switch (rec.getSid()) {
@@ -239,7 +240,7 @@ public final class InternalWorkbook {
case NameRecord.sid :
case SupBookRecord.sid :
// LinkTable can start with either of these
- LOG.log(DEBUG, "found SupBook record at " + k);
+ LOG.atDebug().log("found SupBook record at {}", box(k));
retval.linkTable = new LinkTable(recs, k, retval.records, retval.commentRecords);
k+=retval.linkTable.getRecordCount() - 1;
continue;
@@ -300,7 +301,7 @@ public final class InternalWorkbook {
if (!eofPassed) {
records.add(rec);
}
- LOG.log(DEBUG, "found "+logObj+" record at " + k);
+ LOG.atTrace().log("found {} record at {}", logObj, box(k));
if (rec.getSid() == EOFRecord.sid) {
eofPassed = true;
}
@@ -314,7 +315,7 @@ public final class InternalWorkbook {
if (retval.windowOne == null) {
retval.windowOne = createWindowOne();
}
- LOG.log(DEBUG, "exit create workbook from existing file function");
+ LOG.atDebug().log("exit create workbook from existing file function");
return retval;
}
@@ -325,10 +326,10 @@ public final class InternalWorkbook {
* @return an empty workbook object
*/
public static InternalWorkbook createWorkbook() {
- LOG.log( DEBUG, "creating new workbook from scratch" );
+ LOG.atDebug().log("creating new workbook from scratch");
InternalWorkbook retval = new InternalWorkbook();
- List<org.apache.poi.hssf.record.Record> records = new ArrayList<>(30);
+ List<Record> records = new ArrayList<>(30);
retval.records.setRecords(records);
List<FormatRecord> formats = retval.formats;
@@ -400,7 +401,7 @@ public final class InternalWorkbook {
records.add(InternalWorkbook.createExtendedSST());
records.add(EOFRecord.instance);
- LOG.log( DEBUG, "exit create new workbook from scratch" );
+ LOG.atDebug().log("exit create new workbook from scratch");
return retval;
}
@@ -523,7 +524,7 @@ public final class InternalWorkbook {
*/
public void setSheetBof(int sheetIndex, int pos) {
- LOG.log(DEBUG, "setting bof for sheetnum =", sheetIndex, " at pos=", pos);
+ LOG.atDebug().log("setting bof for sheetnum ={} at pos={}", box(sheetIndex),box(pos));
checkSheets(sheetIndex);
getBoundSheetRec(sheetIndex)
@@ -605,7 +606,7 @@ public final class InternalWorkbook {
// also adjust order of Records, calculate the position of the Boundsheets via getBspos()...
int initialBspos = records.getBspos();
int pos0 = initialBspos - (boundsheets.size() - 1);
- org.apache.poi.hssf.record.Record removed = records.get(pos0 + sheetNumber);
+ Record removed = records.get(pos0 + sheetNumber);
records.remove(pos0 + sheetNumber);
records.add(pos0 + pos, removed);
records.setBspos(initialBspos);
@@ -775,7 +776,7 @@ public final class InternalWorkbook {
* make the tabid record look like the current situation.
*/
private void fixTabIdRecord() {
- org.apache.poi.hssf.record.Record rec = records.get(records.getTabpos());
+ Record rec = records.get(records.getTabpos());
// see bug 55982, quite a number of documents do not have a TabIdRecord and
// thus there is no way to do the fixup here,
@@ -800,7 +801,7 @@ public final class InternalWorkbook {
*/
public int getNumSheets() {
- LOG.log(DEBUG, "getNumSheets=", boundsheets.size());
+ LOG.atDebug().log("getNumSheets={}", box(boundsheets.size()));
return boundsheets.size();
}
@@ -811,7 +812,7 @@ public final class InternalWorkbook {
*/
public int getNumExFormats() {
- LOG.log(DEBUG, "getXF=", numxfs);
+ LOG.atDebug().log("getXF={}", box(numxfs));
return numxfs;
}
@@ -886,7 +887,7 @@ public final class InternalWorkbook {
// Style records always follow after
// the ExtendedFormat records
for(int i=records.getXfpos(); i<records.size(); i++) {
- org.apache.poi.hssf.record.Record r = records.get(i);
+ Record r = records.get(i);
if (r instanceof StyleRecord) {
StyleRecord sr = (StyleRecord)r;
if (sr.getXFIndex() == xfIndex) {
@@ -908,7 +909,7 @@ public final class InternalWorkbook {
// Style records always follow after
// the ExtendedFormat records
for(int i=records.getXfpos(); i<records.size(); i++) {
- org.apache.poi.hssf.record.Record r = records.get(i);
+ Record r = records.get(i);
if (r instanceof StyleRecord) {
StyleRecord sr = (StyleRecord)r;
if (sr.getXFIndex() == oldXf) {
@@ -937,7 +938,7 @@ public final class InternalWorkbook {
int addAt = -1;
for(int i=records.getXfpos(); i<records.size() &&
addAt == -1; i++) {
- org.apache.poi.hssf.record.Record r = records.get(i);
+ Record r = records.get(i);
if(r instanceof ExtendedFormatRecord ||
r instanceof StyleRecord) {
// Keep going
@@ -964,7 +965,7 @@ public final class InternalWorkbook {
*/
public int addSSTString(UnicodeString string) {
- LOG.log(DEBUG, "insert to sst string='", string);
+ LOG.atDebug().log("insert to sst string='{}'", string);
if (sst == null) {
insertSST();
}
@@ -982,7 +983,7 @@ public final class InternalWorkbook {
}
UnicodeString retval = sst.getString(str);
- LOG.log(DEBUG, "Returning SST for index=", str, " String= ", retval);
+ LOG.atTrace().log("Returning SST for index={} String= {}", box(str), retval);
return retval;
}
@@ -990,11 +991,11 @@ public final class InternalWorkbook {
* use this function to add a Shared String Table to an existing sheet (say
* generated by a different java api) without an sst....
* @see #createExtendedSST()
- * @see org.apache.poi.hssf.record.SSTRecord
+ * @see SSTRecord
*/
public void insertSST() {
- LOG.log(DEBUG, "creating new SST via insertSST!");
+ LOG.atDebug().log("creating new SST via insertSST!");
sst = new SSTRecord();
records.add(records.size() - 1, createExtendedSST());
@@ -1009,14 +1010,14 @@ public final class InternalWorkbook {
* @return the length of serialized bytes
*/
public int serialize( int offset, byte[] data ) {
- LOG.log( DEBUG, "Serializing Workbook with offsets" );
+ LOG.atDebug().log("Serializing Workbook with offsets");
int pos = 0;
SSTRecord lSST = null;
int sstPos = 0;
boolean wroteBoundSheets = false;
- for ( org.apache.poi.hssf.record.Record record : records.getRecords() ) {
+ for ( Record record : records.getRecords() ) {
int len = 0;
if (record instanceof SSTRecord) {
lSST = (SSTRecord)record;
@@ -1038,7 +1039,7 @@ public final class InternalWorkbook {
pos += len;
}
- LOG.log( DEBUG, "Exiting serialize workbook" );
+ LOG.atDebug().log("Exiting serialize workbook");
return pos;
}
@@ -1062,7 +1063,7 @@ public final class InternalWorkbook {
int retval = 0;
SSTRecord lSST = null;
- for ( org.apache.poi.hssf.record.Record record : records.getRecords() ) {
+ for ( Record record : records.getRecords() ) {
if (record instanceof SSTRecord) {
lSST = (SSTRecord)record;
}
@@ -1115,7 +1116,7 @@ public final class InternalWorkbook {
retval.setUsername(username);
} catch (AccessControlException e) {
- LOG.log(POILogger.WARN, "can't determine user.name", e);
+ LOG.atWarn().withThrowable(e).log("can't determine user.name");
// AccessControlException can occur in a restricted context
// (client applet/jws application or restricted security server)
retval.setUsername(defaultUserName);
@@ -1426,8 +1427,8 @@ public final class InternalWorkbook {
* Always sets the sheet's bof to 0. You'll need to set that yourself.
* @param id either sheet 0,1 or 2.
* @return record containing a BoundSheetRecord
- * @see org.apache.poi.hssf.record.BoundSheetRecord
- * @see org.apache.poi.hssf.record.Record
+ * @see BoundSheetRecord
+ * @see Record
*/
private static BoundSheetRecord createBoundSheet(int id) {
return new BoundSheetRecord("Sheet" + (id+1));
@@ -1707,8 +1708,8 @@ public final class InternalWorkbook {
* Creates a FormatRecord, inserts it, and returns the index code.
* @param formatString the format string
* @return the index code of the format record.
- * @see org.apache.poi.hssf.record.FormatRecord
- * @see org.apache.poi.hssf.record.Record
+ * @see FormatRecord
+ * @see Record
*/
public int createFormat(String formatString) {
@@ -1734,8 +1735,8 @@ public final class InternalWorkbook {
*
* @return the matching record or {@code null} if it wasn't found
*/
- public org.apache.poi.hssf.record.Record findFirstRecordBySid(short sid) {
- for (org.apache.poi.hssf.record.Record record : records.getRecords() ) {
+ public Record findFirstRecordBySid(short sid) {
+ for (Record record : records.getRecords() ) {
if (record.getSid() == sid) {
return record;
}
@@ -1750,7 +1751,7 @@ public final class InternalWorkbook {
*/
public int findFirstRecordLocBySid(short sid) {
int index = 0;
- for (org.apache.poi.hssf.record.Record record : records.getRecords() ) {
+ for (Record record : records.getRecords() ) {
if (record.getSid() == sid) {
return index;
}
@@ -1767,9 +1768,9 @@ public final class InternalWorkbook {
*
* @return the matching record or {@code null} if it wasn't found
*/
- public org.apache.poi.hssf.record.Record findNextRecordBySid(short sid, int pos) {
+ public Record findNextRecordBySid(short sid, int pos) {
int matches = 0;
- for (org.apache.poi.hssf.record.Record record : records.getRecords() ) {
+ for (Record record : records.getRecords() ) {
if (record.getSid() == sid && matches++ == pos) {
return record;
}
@@ -1782,7 +1783,7 @@ public final class InternalWorkbook {
return hyperlinks;
}
- public List<org.apache.poi.hssf.record.Record> getRecords() {
+ public List<Record> getRecords() {
return records.getRecords();
}
@@ -1806,7 +1807,7 @@ public final class InternalWorkbook {
PaletteRecord palette;
int palettePos = records.getPalettepos();
if (palettePos != -1) {
- org.apache.poi.hssf.record.Record rec = records.get(palettePos);
+ Record rec = records.get(palettePos);
if (rec instanceof PaletteRecord) {
palette = (PaletteRecord) rec;
} else {
@@ -1833,7 +1834,7 @@ public final class InternalWorkbook {
}
// Need to find a DrawingGroupRecord that contains a EscherDggRecord
- for(org.apache.poi.hssf.record.Record r : records.getRecords() ) {
+ for(Record r : records.getRecords() ) {
if (!(r instanceof DrawingGroupRecord)) {
continue;
}
@@ -2207,7 +2208,7 @@ public final class InternalWorkbook {
*
* @return a new RecalcIdRecord
*
- * @see org.apache.poi.hssf.usermodel.HSSFWorkbook#setForceFormulaRecalculation(boolean)
+ * @see HSSFWorkbook#setForceFormulaRecalculation(boolean)
*/
public RecalcIdRecord getRecalcId(){
RecalcIdRecord record = (RecalcIdRecord)findFirstRecordBySid(RecalcIdRecord.sid);
diff --git a/src/java/org/apache/poi/hssf/record/CFRule12Record.java b/src/java/org/apache/poi/hssf/record/CFRule12Record.java
index 3106ded014..e1a3fc5883 100644
--- a/src/java/org/apache/poi/hssf/record/CFRule12Record.java
+++ b/src/java/org/apache/poi/hssf/record/CFRule12Record.java
@@ -40,7 +40,8 @@ import org.apache.poi.ss.usermodel.IconMultiStateFormatting.IconSet;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.util.IOUtils;
import org.apache.poi.util.LittleEndianOutput;
-import org.apache.poi.util.POILogger;
+
+import static org.apache.logging.log4j.util.Unbox.box;
/**
* Conditional Formatting v12 Rule Record (0x087A).
@@ -285,7 +286,7 @@ public final class CFRule12Record extends CFRuleBase implements FutureRecord {
template_params = IOUtils.safelyAllocate(template_param_length, MAX_RECORD_LENGTH);
in.readFully(template_params);
} else {
- LOG.log(POILogger.WARN, "CF Rule v12 template params length should be 0 or 16, found " + template_param_length);
+ LOG.atWarn().log("CF Rule v12 template params length should be 0 or 16, found {}", box(template_param_length));
in.readRemainder();
}
diff --git a/src/java/org/apache/poi/hssf/record/CFRuleBase.java b/src/java/org/apache/poi/hssf/record/CFRuleBase.java
index 71f52a0105..22ee40f54a 100644
--- a/src/java/org/apache/poi/hssf/record/CFRuleBase.java
+++ b/src/java/org/apache/poi/hssf/record/CFRuleBase.java
@@ -20,6 +20,8 @@ package org.apache.poi.hssf.record;
import java.util.Map;
import java.util.function.Supplier;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
import org.apache.poi.hssf.model.HSSFFormulaParser;
import org.apache.poi.hssf.record.cf.BorderFormatting;
import org.apache.poi.hssf.record.cf.FontFormatting;
@@ -32,8 +34,6 @@ import org.apache.poi.util.BitField;
import org.apache.poi.util.BitFieldFactory;
import org.apache.poi.util.GenericRecordUtil;
import org.apache.poi.util.LittleEndianOutput;
-import org.apache.poi.util.POILogFactory;
-import org.apache.poi.util.POILogger;
/**
* Conditional Formatting Rules. This can hold old-style rules
@@ -95,7 +95,7 @@ public abstract class CFRuleBase extends StandardRecord {
public static final int TEMPLATE_ABOVE_OR_EQUAL_TO_AVERAGE = 0x001D;
public static final int TEMPLATE_BELOW_OR_EQUAL_TO_AVERAGE = 0x001E;
- protected static final POILogger LOG = POILogFactory.getLogger(CFRuleBase.class);
+ protected static final Logger LOG = LogManager.getLogger(CFRuleBase.class);
static final BitField modificationBits = bf(0x003FFFFF); // Bits: font,align,bord,patt,prot
static final BitField alignHor = bf(0x00000001); // 0 = Horizontal alignment modified
diff --git a/src/java/org/apache/poi/hssf/record/DimensionsRecord.java b/src/java/org/apache/poi/hssf/record/DimensionsRecord.java
index 6f64b613e4..b12d008786 100644
--- a/src/java/org/apache/poi/hssf/record/DimensionsRecord.java
+++ b/src/java/org/apache/poi/hssf/record/DimensionsRecord.java
@@ -22,10 +22,10 @@ package org.apache.poi.hssf.record;
import java.util.Map;
import java.util.function.Supplier;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
import org.apache.poi.util.GenericRecordUtil;
import org.apache.poi.util.LittleEndianOutput;
-import org.apache.poi.util.POILogFactory;
-import org.apache.poi.util.POILogger;
/**
* Provides the minumum and maximum bounds of a sheet.
@@ -35,7 +35,7 @@ import org.apache.poi.util.POILogger;
public final class DimensionsRecord extends StandardRecord {
- private static final POILogger LOG = POILogFactory.getLogger(DimensionsRecord.class);
+ private static final Logger LOG = LogManager.getLogger(DimensionsRecord.class);
public static final short sid = 0x200;
private int field_1_first_row;
@@ -63,7 +63,7 @@ public final class DimensionsRecord extends StandardRecord {
field_5_zero = in.readShort();
//POI-61045 -- in practice, there can be an extra 2 bytes
if (in.available() == 2) {
- LOG.log(POILogger.INFO, "DimensionsRecord has extra 2 bytes.");
+ LOG.atInfo().log("DimensionsRecord has extra 2 bytes.");
in.readShort();
}
}
diff --git a/src/java/org/apache/poi/hssf/record/EmbeddedObjectRefSubRecord.java b/src/java/org/apache/poi/hssf/record/EmbeddedObjectRefSubRecord.java
index bffc37d6c1..ab5d3874ef 100644
--- a/src/java/org/apache/poi/hssf/record/EmbeddedObjectRefSubRecord.java
+++ b/src/java/org/apache/poi/hssf/record/EmbeddedObjectRefSubRecord.java
@@ -21,6 +21,8 @@ import java.io.ByteArrayInputStream;
import java.util.Map;
import java.util.function.Supplier;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
import org.apache.poi.ss.formula.ptg.Area3DPtg;
import org.apache.poi.ss.formula.ptg.AreaPtg;
import org.apache.poi.ss.formula.ptg.Ptg;
@@ -32,18 +34,18 @@ import org.apache.poi.util.LittleEndianConsts;
import org.apache.poi.util.LittleEndianInput;
import org.apache.poi.util.LittleEndianInputStream;
import org.apache.poi.util.LittleEndianOutput;
-import org.apache.poi.util.POILogFactory;
-import org.apache.poi.util.POILogger;
import org.apache.poi.util.RecordFormatException;
import org.apache.poi.util.StringUtil;
+import static org.apache.logging.log4j.util.Unbox.box;
+
/**
* ftPictFmla (0x0009)<p>
* A sub-record within the OBJ record which stores a reference to an object
* stored in a separate entry within the OLE2 compound file.
*/
public final class EmbeddedObjectRefSubRecord extends SubRecord {
- private static final POILogger LOG = POILogFactory.getLogger(EmbeddedObjectRefSubRecord.class);
+ private static final Logger LOG = LogManager.getLogger(EmbeddedObjectRefSubRecord.class);
//arbitrarily selected; may need to increase
private static final int MAX_RECORD_LENGTH = 100_000;
@@ -157,7 +159,7 @@ public final class EmbeddedObjectRefSubRecord extends SubRecord {
int nUnexpectedPadding = remaining - dataLenAfterFormula;
if (nUnexpectedPadding > 0) {
- LOG.log( POILogger.ERROR, "Discarding ", nUnexpectedPadding, " unexpected padding bytes");
+ LOG.atError().log("Discarding {} unexpected padding bytes", box(nUnexpectedPadding));
readRawData(in, nUnexpectedPadding);
remaining-=nUnexpectedPadding;
}
diff --git a/src/java/org/apache/poi/hssf/record/FeatRecord.java b/src/java/org/apache/poi/hssf/record/FeatRecord.java
index 22a3e8988d..f5850bfefa 100644
--- a/src/java/org/apache/poi/hssf/record/FeatRecord.java
+++ b/src/java/org/apache/poi/hssf/record/FeatRecord.java
@@ -21,6 +21,8 @@ import java.util.Map;
import java.util.function.Supplier;
import java.util.stream.Stream;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
import org.apache.poi.hssf.record.common.FeatFormulaErr2;
import org.apache.poi.hssf.record.common.FeatProtection;
import org.apache.poi.hssf.record.common.FeatSmartTag;
@@ -29,8 +31,8 @@ import org.apache.poi.hssf.record.common.SharedFeature;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.util.GenericRecordUtil;
import org.apache.poi.util.LittleEndianOutput;
-import org.apache.poi.util.POILogFactory;
-import org.apache.poi.util.POILogger;
+
+import static org.apache.logging.log4j.util.Unbox.box;
/**
* Title: Feat (Feature) Record
@@ -39,8 +41,8 @@ import org.apache.poi.util.POILogger;
* up with a {@link FeatHdrRecord}.
*/
public final class FeatRecord extends StandardRecord {
- private static final POILogger LOG = POILogFactory.getLogger(FeatRecord.class);
- public static final short sid = 0x0868;
+ private static final Logger LOG = LogManager.getLogger(FeatRecord.class);
+ public static final short sid = 0x0868;
// SIDs from newer versions
public static final short v11_sid = 0x0872;
public static final short v12_sid = 0x0878;
@@ -108,7 +110,7 @@ public final class FeatRecord extends StandardRecord {
sharedFeature = new FeatSmartTag(in);
break;
default:
- LOG.log( POILogger.ERROR, "Unknown Shared Feature ", isf_sharedFeatureType, " found!");
+ LOG.atError().log("Unknown Shared Feature {} found!", box(isf_sharedFeatureType));
}
}
diff --git a/src/java/org/apache/poi/hssf/record/FormatRecord.java b/src/java/org/apache/poi/hssf/record/FormatRecord.java
index 24063ff93d..7b2714bc77 100644
--- a/src/java/org/apache/poi/hssf/record/FormatRecord.java
+++ b/src/java/org/apache/poi/hssf/record/FormatRecord.java
@@ -21,19 +21,22 @@ import java.util.Arrays;
import java.util.Map;
import java.util.function.Supplier;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.apache.poi.hssf.model.InternalWorkbook;
import org.apache.poi.util.GenericRecordUtil;
import org.apache.poi.util.LittleEndianConsts;
import org.apache.poi.util.LittleEndianOutput;
-import org.apache.poi.util.POILogFactory;
-import org.apache.poi.util.POILogger;
import org.apache.poi.util.StringUtil;
+import static org.apache.logging.log4j.util.Unbox.box;
+
/**
* Describes a number format -- those goofy strings like $(#,###)
*/
public final class FormatRecord extends StandardRecord {
- private static final POILogger LOG = POILogFactory.getLogger(FormatRecord.class);
+ private static final Logger LOG = LogManager.getLogger(FormatRecord.class);
public static final short sid = 0x041E;
@@ -70,7 +73,7 @@ public final class FormatRecord extends StandardRecord {
* get the format index code (for built in formats)
*
* @return the format index code
- * @see org.apache.poi.hssf.model.InternalWorkbook
+ * @see InternalWorkbook
*/
public int getIndexCode() {
return field_1_index_code;
@@ -149,7 +152,7 @@ public final class FormatRecord extends StandardRecord {
}
if (ris.available() > 0) {
- LOG.log(POILogger.INFO, "FormatRecord has ", ris.available(), " unexplained bytes. Silently skipping");
+ LOG.atInfo().log("FormatRecord has {} unexplained bytes. Silently skipping", box(ris.available()));
//swallow what's left
while (ris.available() > 0) {
ris.readByte();
diff --git a/src/java/org/apache/poi/hssf/record/HyperlinkRecord.java b/src/java/org/apache/poi/hssf/record/HyperlinkRecord.java
index 1c24d0023a..78bda25262 100644
--- a/src/java/org/apache/poi/hssf/record/HyperlinkRecord.java
+++ b/src/java/org/apache/poi/hssf/record/HyperlinkRecord.java
@@ -17,24 +17,26 @@
package org.apache.poi.hssf.record;
+import static org.apache.logging.log4j.util.Unbox.box;
import static org.apache.poi.hpsf.ClassIDPredefined.FILE_MONIKER;
import static org.apache.poi.hpsf.ClassIDPredefined.STD_MONIKER;
import static org.apache.poi.hpsf.ClassIDPredefined.URL_MONIKER;
import static org.apache.poi.util.GenericRecordUtil.getBitsAsString;
+import static org.apache.poi.util.HexDump.toHex;
import java.util.Map;
import java.util.function.Supplier;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
import org.apache.poi.hpsf.ClassID;
+import org.apache.poi.hpsf.ClassIDPredefined;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.util.GenericRecordUtil;
-import org.apache.poi.util.HexDump;
import org.apache.poi.util.HexRead;
import org.apache.poi.util.IOUtils;
import org.apache.poi.util.LittleEndianInput;
import org.apache.poi.util.LittleEndianOutput;
-import org.apache.poi.util.POILogFactory;
-import org.apache.poi.util.POILogger;
import org.apache.poi.util.RecordFormatException;
import org.apache.poi.util.StringUtil;
@@ -45,7 +47,7 @@ import org.apache.poi.util.StringUtil;
*/
public final class HyperlinkRecord extends StandardRecord {
public static final short sid = 0x01B8;
- private static final POILogger LOG = POILogFactory.getLogger(HyperlinkRecord.class);
+ private static final Logger LOG = LogManager.getLogger(HyperlinkRecord.class);
//arbitrarily selected; may need to increase
private static final int MAX_RECORD_LENGTH = 100_000;
@@ -184,7 +186,7 @@ public final class HyperlinkRecord extends StandardRecord {
}
/**
- * @return 16-byte guid identifier Seems to always equal {@link org.apache.poi.hpsf.ClassIDPredefined#STD_MONIKER}
+ * @return 16-byte guid identifier Seems to always equal {@link ClassIDPredefined#STD_MONIKER}
*/
ClassID getGuid() {
return _guid;
@@ -403,10 +405,7 @@ public final class HyperlinkRecord extends StandardRecord {
}
if (in.remaining() > 0) {
- LOG.log(POILogger.WARN,
- "Hyperlink data remains: " + in.remaining() +
- " : " +HexDump.toHex(in.readRemainder())
- );
+ LOG.atWarn().log("Hyperlink data remains: {} : {}", box(in.remaining()), toHex(in.readRemainder()));
}
}
diff --git a/src/java/org/apache/poi/hssf/record/LabelRecord.java b/src/java/org/apache/poi/hssf/record/LabelRecord.java
index f3ac972d09..b21286085e 100644
--- a/src/java/org/apache/poi/hssf/record/LabelRecord.java
+++ b/src/java/org/apache/poi/hssf/record/LabelRecord.java
@@ -20,20 +20,22 @@ package org.apache.poi.hssf.record;
import java.util.Map;
import java.util.function.Supplier;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
import org.apache.poi.util.GenericRecordUtil;
-import org.apache.poi.util.HexDump;
-import org.apache.poi.util.POILogFactory;
-import org.apache.poi.util.POILogger;
import org.apache.poi.util.RecordFormatException;
+import static org.apache.logging.log4j.util.Unbox.box;
+import static org.apache.poi.util.HexDump.toHex;
+
/**
* Label Record (0x0204) - read only support for strings stored directly in the cell...
* Don't use this (except to read), use LabelSST instead
*
- * @see org.apache.poi.hssf.record.LabelSSTRecord
+ * @see LabelSSTRecord
*/
public final class LabelRecord extends Record implements CellValueRecordInterface {
- private static final POILogger LOG = POILogFactory.getLogger(LabelRecord.class);
+ private static final Logger LOG = LogManager.getLogger(LabelRecord.class);
public static final short sid = 0x0204;
@@ -77,10 +79,7 @@ public final class LabelRecord extends Record implements CellValueRecordInterfac
}
if (in.remaining() > 0) {
- LOG.log(POILogger.INFO,
- "LabelRecord data remains: ", in.remaining(),
- " : ", HexDump.toHex(in.readRemainder())
- );
+ LOG.atInfo().log("LabelRecord data remains: {} : {}", box(in.remaining()), toHex(in.readRemainder()));
}
}
diff --git a/src/java/org/apache/poi/hssf/record/OldLabelRecord.java b/src/java/org/apache/poi/hssf/record/OldLabelRecord.java
index dd59ca258f..e393c8e3d8 100644
--- a/src/java/org/apache/poi/hssf/record/OldLabelRecord.java
+++ b/src/java/org/apache/poi/hssf/record/OldLabelRecord.java
@@ -20,20 +20,22 @@ package org.apache.poi.hssf.record;
import java.util.Map;
import java.util.function.Supplier;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
import org.apache.poi.util.GenericRecordUtil;
-import org.apache.poi.util.HexDump;
import org.apache.poi.util.IOUtils;
-import org.apache.poi.util.POILogFactory;
-import org.apache.poi.util.POILogger;
import org.apache.poi.util.RecordFormatException;
+import static org.apache.logging.log4j.util.Unbox.box;
+import static org.apache.poi.util.HexDump.toHex;
+
/**
* Biff2 - Biff 4 Label Record (0x0004 / 0x0204) - read only support for
* strings stored directly in the cell, from the older file formats that
* didn't use {@link LabelSSTRecord}
*/
public final class OldLabelRecord extends OldCellRecord {
- private static final POILogger LOG = POILogFactory.getLogger(OldLabelRecord.class);
+ private static final Logger LOG = LogManager.getLogger(OldLabelRecord.class);
//arbitrarily set, may need to increase
private static final int MAX_RECORD_LENGTH = 100_000;
@@ -62,10 +64,7 @@ public final class OldLabelRecord extends OldCellRecord {
in.read(field_5_bytes, 0, field_4_string_len);
if (in.remaining() > 0) {
- LOG.log(POILogger.INFO,
- "LabelRecord data remains: ", in.remaining(),
- " : ", HexDump.toHex(in.readRemainder())
- );
+ LOG.atInfo().log("LabelRecord data remains: {} : {}", box(in.remaining()), toHex(in.readRemainder()));
}
}
diff --git a/src/java/org/apache/poi/hssf/record/SSTDeserializer.java b/src/java/org/apache/poi/hssf/record/SSTDeserializer.java
index bcd6452c25..6b3bce351d 100644
--- a/src/java/org/apache/poi/hssf/record/SSTDeserializer.java
+++ b/src/java/org/apache/poi/hssf/record/SSTDeserializer.java
@@ -19,10 +19,12 @@
package org.apache.poi.hssf.record;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
import org.apache.poi.hssf.record.common.UnicodeString;
import org.apache.poi.util.IntMapper;
-import org.apache.poi.util.POILogFactory;
-import org.apache.poi.util.POILogger;
+
+import static org.apache.logging.log4j.util.Unbox.box;
/**
* Handles the task of deserializing a SST string. The two main entry points are
@@ -32,7 +34,7 @@ import org.apache.poi.util.POILogger;
*/
class SSTDeserializer
{
- private static final POILogger LOG = POILogFactory.getLogger(SSTDeserializer.class);
+ private static final Logger LOG = LogManager.getLogger(SSTDeserializer.class);
private IntMapper<UnicodeString> strings;
public SSTDeserializer( IntMapper<UnicodeString> strings )
@@ -51,7 +53,7 @@ class SSTDeserializer
// Extract exactly the count of strings from the SST record.
UnicodeString str;
if (in.available() == 0 && !in.hasNextRecord()) {
- LOG.log(POILogger.ERROR, "Ran out of data before creating all the strings! String at index ", i);
+ LOG.atError().log("Ran out of data before creating all the strings! String at index {}", box(i));
str = new UnicodeString("");
} else {
str = new UnicodeString(in);
diff --git a/src/java/org/apache/poi/hssf/record/SupBookRecord.java b/src/java/org/apache/poi/hssf/record/SupBookRecord.java
index c9ff27f93e..2d610ac981 100644
--- a/src/java/org/apache/poi/hssf/record/SupBookRecord.java
+++ b/src/java/org/apache/poi/hssf/record/SupBookRecord.java
@@ -20,10 +20,10 @@ package org.apache.poi.hssf.record;
import java.util.Map;
import java.util.function.Supplier;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
import org.apache.poi.util.GenericRecordUtil;
import org.apache.poi.util.LittleEndianOutput;
-import org.apache.poi.util.POILogFactory;
-import org.apache.poi.util.POILogger;
import org.apache.poi.util.StringUtil;
/**
@@ -32,7 +32,7 @@ import org.apache.poi.util.StringUtil;
*/
public final class SupBookRecord extends StandardRecord {
- private static final POILogger LOG = POILogFactory.getLogger(SupBookRecord.class);
+ private static final Logger LOG = LogManager.getLogger(SupBookRecord.class);
public static final short sid = 0x01AE;
@@ -222,12 +222,12 @@ public final class SupBookRecord extends StandardRecord {
break;
case CH_LONG_VOLUME:
//Don't known to handle...
- LOG.log(POILogger.WARN, "Found unexpected key: ChLongVolume - IGNORING");
+ LOG.atWarn().log("Found unexpected key: ChLongVolume - IGNORING");
break;
case CH_STARTUP_DIR:
case CH_ALT_STARTUP_DIR:
case CH_LIB_DIR:
- LOG.log(POILogger.WARN, "EXCEL.EXE path unkown - using this directoy instead: .");
+ LOG.atWarn().log("EXCEL.EXE path unknown - using this directory instead: .");
sb.append(".").append(PATH_SEPERATOR);
break;
default:
diff --git a/src/java/org/apache/poi/hssf/record/aggregates/CFRecordsAggregate.java b/src/java/org/apache/poi/hssf/record/aggregates/CFRecordsAggregate.java
index 4ee339ae10..cd513e8683 100644
--- a/src/java/org/apache/poi/hssf/record/aggregates/CFRecordsAggregate.java
+++ b/src/java/org/apache/poi/hssf/record/aggregates/CFRecordsAggregate.java
@@ -22,6 +22,8 @@ import java.util.List;
import java.util.Map;
import java.util.function.Supplier;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
import org.apache.poi.common.usermodel.GenericRecord;
import org.apache.poi.hssf.model.RecordStream;
import org.apache.poi.hssf.record.CFHeader12Record;
@@ -37,10 +39,10 @@ import org.apache.poi.ss.usermodel.helpers.BaseRowColShifter;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.util.GenericRecordJsonWriter;
import org.apache.poi.util.GenericRecordUtil;
-import org.apache.poi.util.POILogFactory;
-import org.apache.poi.util.POILogger;
import org.apache.poi.util.RecordFormatException;
+import static org.apache.logging.log4j.util.Unbox.box;
+
/**
* <p>CFRecordsAggregate - aggregates Conditional Formatting records CFHeaderRecord
* and number of up CFRuleRecord records together to simplify access to them.</p>
@@ -52,7 +54,7 @@ import org.apache.poi.util.RecordFormatException;
public final class CFRecordsAggregate extends RecordAggregate implements GenericRecord {
/** Excel 97-2003 allows up to 3 conditional formating rules */
private static final int MAX_97_2003_CONDTIONAL_FORMAT_RULES = 3;
- private static final POILogger LOG = POILogFactory.getLogger(CFRecordsAggregate.class);
+ private static final Logger LOG = LogManager.getLogger(CFRecordsAggregate.class);
private final CFHeaderBase header;
@@ -72,10 +74,9 @@ public final class CFRecordsAggregate extends RecordAggregate implements Generic
throw new IllegalArgumentException("rules must not be null");
}
if(pRules.length > MAX_97_2003_CONDTIONAL_FORMAT_RULES) {
- LOG.log(POILogger.WARN, "Excel versions before 2007 require that "
- + "No more than " + MAX_97_2003_CONDTIONAL_FORMAT_RULES
- + " rules may be specified, " + pRules.length + " were found,"
- + " this file will cause problems with old Excel versions");
+ LOG.atWarn().log("Excel versions before 2007 require that No more than " +
+ MAX_97_2003_CONDTIONAL_FORMAT_RULES + " rules may be specified, {} were found, this file will " +
+ "cause problems with old Excel versions", box(pRules.length));
}
if (pRules.length != pHeader.getNumberOfConditionalFormats()) {
throw new RecordFormatException("Mismatch number of rules");
@@ -181,7 +182,7 @@ public final class CFRecordsAggregate extends RecordAggregate implements Generic
throw new IllegalArgumentException("r must not be null");
}
if(rules.size() >= MAX_97_2003_CONDTIONAL_FORMAT_RULES) {
- LOG.log(POILogger.WARN, "Excel versions before 2007 cannot cope with"
+ LOG.atWarn().log("Excel versions before 2007 cannot cope with"
+ " any more than " + MAX_97_2003_CONDTIONAL_FORMAT_RULES
+ " - this file will cause problems with old Excel versions");
}
diff --git a/src/java/org/apache/poi/hssf/record/cf/ColorGradientFormatting.java b/src/java/org/apache/poi/hssf/record/cf/ColorGradientFormatting.java
index c46238a740..ab463c9fa8 100644
--- a/src/java/org/apache/poi/hssf/record/cf/ColorGradientFormatting.java
+++ b/src/java/org/apache/poi/hssf/record/cf/ColorGradientFormatting.java
@@ -21,6 +21,8 @@ import java.util.Map;
import java.util.function.Supplier;
import java.util.stream.Stream;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
import org.apache.poi.common.Duplicatable;
import org.apache.poi.common.usermodel.GenericRecord;
import org.apache.poi.hssf.record.common.ExtendedColor;
@@ -30,8 +32,8 @@ import org.apache.poi.util.GenericRecordJsonWriter;
import org.apache.poi.util.GenericRecordUtil;
import org.apache.poi.util.LittleEndianInput;
import org.apache.poi.util.LittleEndianOutput;
-import org.apache.poi.util.POILogFactory;
-import org.apache.poi.util.POILogger;
+
+import static org.apache.logging.log4j.util.Unbox.box;
/**
* Color Gradient / Color Scale Conditional Formatting Rule Record.
@@ -39,7 +41,7 @@ import org.apache.poi.util.POILogger;
* Color Scale in the UI)
*/
public final class ColorGradientFormatting implements Duplicatable, GenericRecord {
- private static final POILogger log = POILogFactory.getLogger(ColorGradientFormatting.class);
+ private static final Logger LOGGER = LogManager.getLogger(ColorGradientFormatting.class);
private static final BitField clamp = BitFieldFactory.getInstance(0x01);
private static final BitField background = BitFieldFactory.getInstance(0x02);
@@ -70,7 +72,7 @@ public final class ColorGradientFormatting implements Duplicatable, GenericRecor
int numI = in.readByte();
int numG = in.readByte();
if (numI != numG) {
- log.log(POILogger.WARN, "Inconsistent Color Gradient defintion, found " + numI + " vs " + numG + " entries");
+ LOGGER.atWarn().log("Inconsistent Color Gradient definition, found {} vs {} entries", box(numI),box(numG));
}
options = in.readByte();
diff --git a/src/java/org/apache/poi/hssf/record/cf/DataBarFormatting.java b/src/java/org/apache/poi/hssf/record/cf/DataBarFormatting.java
index 7dd3fa0ffb..5063cfe3bf 100644
--- a/src/java/org/apache/poi/hssf/record/cf/DataBarFormatting.java
+++ b/src/java/org/apache/poi/hssf/record/cf/DataBarFormatting.java
@@ -17,11 +17,14 @@
package org.apache.poi.hssf.record.cf;
+import static org.apache.logging.log4j.util.Unbox.box;
import static org.apache.poi.util.GenericRecordUtil.getBitsAsString;
import java.util.Map;
import java.util.function.Supplier;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
import org.apache.poi.common.Duplicatable;
import org.apache.poi.common.usermodel.GenericRecord;
import org.apache.poi.hssf.record.common.ExtendedColor;
@@ -31,14 +34,12 @@ import org.apache.poi.util.GenericRecordJsonWriter;
import org.apache.poi.util.GenericRecordUtil;
import org.apache.poi.util.LittleEndianInput;
import org.apache.poi.util.LittleEndianOutput;
-import org.apache.poi.util.POILogFactory;
-import org.apache.poi.util.POILogger;
/**
* Data Bar Conditional Formatting Rule Record.
*/
public final class DataBarFormatting implements Duplicatable, GenericRecord {
- private static final POILogger LOG = POILogFactory.getLogger(DataBarFormatting.class);
+ private static final Logger LOG = LogManager.getLogger(DataBarFormatting.class);
private static final BitField ICON_ONLY = BitFieldFactory.getInstance(0x01);
private static final BitField REVERSED = BitFieldFactory.getInstance(0x04);
@@ -71,9 +72,9 @@ public final class DataBarFormatting implements Duplicatable, GenericRecord {
percentMin = in.readByte();
percentMax = in.readByte();
if (percentMin < 0 || percentMin > 100)
- LOG.log(POILogger.WARN, "Inconsistent Minimum Percentage found " + percentMin);
+ LOG.atWarn().log("Inconsistent Minimum Percentage found {}", box(percentMin));
if (percentMax < 0 || percentMax > 100)
- LOG.log(POILogger.WARN, "Inconsistent Maximum Percentage found " + percentMax);
+ LOG.atWarn().log("Inconsistent Maximum Percentage found {}", box(percentMax));
color = new ExtendedColor(in);
thresholdMin = new DataBarThreshold(in);
diff --git a/src/java/org/apache/poi/hssf/record/cf/IconMultiStateFormatting.java b/src/java/org/apache/poi/hssf/record/cf/IconMultiStateFormatting.java
index 616d3e00a0..ac2a42fc15 100644
--- a/src/java/org/apache/poi/hssf/record/cf/IconMultiStateFormatting.java
+++ b/src/java/org/apache/poi/hssf/record/cf/IconMultiStateFormatting.java
@@ -21,6 +21,8 @@ import java.util.Map;
import java.util.function.Supplier;
import java.util.stream.Stream;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
import org.apache.poi.common.Duplicatable;
import org.apache.poi.common.usermodel.GenericRecord;
import org.apache.poi.ss.usermodel.IconMultiStateFormatting.IconSet;
@@ -30,14 +32,14 @@ import org.apache.poi.util.GenericRecordJsonWriter;
import org.apache.poi.util.GenericRecordUtil;
import org.apache.poi.util.LittleEndianInput;
import org.apache.poi.util.LittleEndianOutput;
-import org.apache.poi.util.POILogFactory;
-import org.apache.poi.util.POILogger;
+
+import static org.apache.logging.log4j.util.Unbox.box;
/**
* Icon / Multi-State Conditional Formatting Rule Record.
*/
public final class IconMultiStateFormatting implements Duplicatable, GenericRecord {
- private static final POILogger LOG = POILogFactory.getLogger(IconMultiStateFormatting.class);
+ private static final Logger LOG = LogManager.getLogger(IconMultiStateFormatting.class);
private static BitField ICON_ONLY = BitFieldFactory.getInstance(0x01);
private static BitField REVERSED = BitFieldFactory.getInstance(0x04);
@@ -67,7 +69,7 @@ public final class IconMultiStateFormatting implements Duplicatable, GenericReco
int set = in.readByte();
iconSet = IconSet.byId(set);
if (iconSet.num != num) {
- LOG.log(POILogger.WARN, "Inconsistent Icon Set defintion, found " + iconSet + " but defined as " + num + " entries");
+ LOG.atWarn().log("Inconsistent Icon Set definition, found {} but defined as {} entries", iconSet, box(num));
}
options = in.readByte();
diff --git a/src/java/org/apache/poi/hssf/record/common/ExtRst.java b/src/java/org/apache/poi/hssf/record/common/ExtRst.java
index 1d8101b451..bb409edcad 100644
--- a/src/java/org/apache/poi/hssf/record/common/ExtRst.java
+++ b/src/java/org/apache/poi/hssf/record/common/ExtRst.java
@@ -22,19 +22,21 @@ import java.util.Map;
import java.util.function.Supplier;
import java.util.stream.Stream;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
import org.apache.poi.common.usermodel.GenericRecord;
import org.apache.poi.hssf.record.cont.ContinuableRecordOutput;
import org.apache.poi.util.GenericRecordUtil;
import org.apache.poi.util.IOUtils;
import org.apache.poi.util.Internal;
import org.apache.poi.util.LittleEndianInput;
-import org.apache.poi.util.POILogFactory;
-import org.apache.poi.util.POILogger;
import org.apache.poi.util.StringUtil;
+import static org.apache.logging.log4j.util.Unbox.box;
+
@Internal
public class ExtRst implements Comparable<ExtRst>, GenericRecord {
- private static final POILogger LOG = POILogFactory.getLogger(ExtRst.class);
+ private static final Logger LOG = LogManager.getLogger(ExtRst.class);
//arbitrarily selected; may need to increase
private static final int MAX_RECORD_LENGTH = 100_000;
@@ -78,7 +80,7 @@ public class ExtRst implements Comparable<ExtRst>, GenericRecord {
// Spot corrupt records
if(reserved != 1) {
- LOG.log(POILogger.WARN, "Warning - ExtRst has wrong magic marker, expecting 1 but found ", reserved, " - ignoring");
+ LOG.atWarn().log("ExtRst has wrong magic marker, expecting 1 but found {} - ignoring", box(reserved));
// Grab all the remaining data, and ignore it
for(int i=0; i<expectedLength-2; i++) {
in.readByte();
@@ -121,7 +123,7 @@ public class ExtRst implements Comparable<ExtRst>, GenericRecord {
int extraDataLength = runData - (numRuns*6);
if(extraDataLength < 0) {
- LOG.log( POILogger.WARN, "Warning - ExtRst overran by ", (0-extraDataLength), " bytes");
+ LOG.atWarn().log("ExtRst overran by {} bytes", box(-extraDataLength));
extraDataLength = 0;
}
extraData = IOUtils.safelyAllocate(extraDataLength, MAX_RECORD_LENGTH);
diff --git a/src/java/org/apache/poi/hssf/record/common/UnicodeString.java b/src/java/org/apache/poi/hssf/record/common/UnicodeString.java
index d6afa2a9ca..d9b56d7e7d 100644
--- a/src/java/org/apache/poi/hssf/record/common/UnicodeString.java
+++ b/src/java/org/apache/poi/hssf/record/common/UnicodeString.java
@@ -26,6 +26,8 @@ import java.util.Objects;
import java.util.function.Supplier;
import java.util.stream.Collectors;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
import org.apache.poi.common.Duplicatable;
import org.apache.poi.common.usermodel.GenericRecord;
import org.apache.poi.hssf.record.RecordInputStream;
@@ -34,8 +36,8 @@ import org.apache.poi.hssf.record.cont.ContinuableRecordOutput;
import org.apache.poi.util.BitField;
import org.apache.poi.util.BitFieldFactory;
import org.apache.poi.util.GenericRecordUtil;
-import org.apache.poi.util.POILogFactory;
-import org.apache.poi.util.POILogger;
+
+import static org.apache.logging.log4j.util.Unbox.box;
/**
* Unicode String - just standard fields that are in several records.
@@ -43,7 +45,7 @@ import org.apache.poi.util.POILogger;
* This is often called a XLUnicodeRichExtendedString in MS documentation.<p>
*/
public class UnicodeString implements Comparable<UnicodeString>, Duplicatable, GenericRecord {
- private static final POILogger LOG = POILogFactory.getLogger(UnicodeString.class);
+ private static final Logger LOG = LogManager.getLogger(UnicodeString.class);
private static final BitField highByte = BitFieldFactory.getInstance(0x1);
// 0x2 is reserved
@@ -102,7 +104,7 @@ public class UnicodeString implements Comparable<UnicodeString>, Duplicatable, G
if (isExtendedText() && (extensionLength > 0)) {
field_5_ext_rst = new ExtRst(new ContinuableRecordInput(in), extensionLength);
if(field_5_ext_rst.getDataSize()+4 != extensionLength) {
- LOG.log(POILogger.WARN, "ExtRst was supposed to be " + extensionLength + " bytes long, but seems to actually be " + (field_5_ext_rst.getDataSize() + 4));
+ LOG.atWarn().log("ExtRst was supposed to be {} bytes long, but seems to actually be {}", box(extensionLength),box(field_5_ext_rst.getDataSize() + 4));
}
}
}
diff --git a/src/java/org/apache/poi/hssf/usermodel/EscherGraphics.java b/src/java/org/apache/poi/hssf/usermodel/EscherGraphics.java
index fb58e04429..4e3c4bd1ca 100644
--- a/src/java/org/apache/poi/hssf/usermodel/EscherGraphics.java
+++ b/src/java/org/apache/poi/hssf/usermodel/EscherGraphics.java
@@ -17,10 +17,10 @@
package org.apache.poi.hssf.usermodel;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.util.NotImplemented;
-import org.apache.poi.util.POILogFactory;
-import org.apache.poi.util.POILogger;
import org.apache.poi.util.SuppressForbidden;
import java.awt.*;
@@ -60,7 +60,7 @@ import java.text.AttributedCharacterIterator;
* </blockquote>
*/
public class EscherGraphics extends Graphics {
- private static final POILogger LOG = POILogFactory.getLogger(EscherGraphics.class);
+ private static final Logger LOG = LogManager.getLogger(EscherGraphics.class);
private final HSSFShapeGroup escherGroup;
private final HSSFWorkbook workbook;
@@ -135,14 +135,14 @@ public class EscherGraphics extends Graphics {
@NotImplemented
public void clipRect(int x, int y, int width, int height)
{
- LOG.log(POILogger.WARN,"clipRect not supported");
+ LOG.atWarn().log("clipRect not supported");
}
@Override
@NotImplemented
public void copyArea(int x, int y, int width, int height, int dx, int dy)
{
- LOG.log(POILogger.WARN,"copyArea not supported");
+ LOG.atWarn().log("copyArea not supported");
}
@Override
@@ -162,7 +162,7 @@ public class EscherGraphics extends Graphics {
public void drawArc(int x, int y, int width, int height,
int startAngle, int arcAngle)
{
- LOG.log(POILogger.WARN,"drawArc not supported");
+ LOG.atWarn().log("drawArc not supported");
}
@Override
@@ -173,7 +173,7 @@ public class EscherGraphics extends Graphics {
Color bgcolor,
ImageObserver observer)
{
- LOG.log(POILogger.WARN,"drawImage not supported");
+ LOG.atWarn().log("drawImage not supported");
return true;
}
@@ -185,7 +185,7 @@ public class EscherGraphics extends Graphics {
int sx1, int sy1, int sx2, int sy2,
ImageObserver observer)
{
- LOG.log(POILogger.WARN,"drawImage not supported");
+ LOG.atWarn().log("drawImage not supported");
return true;
}
@@ -266,14 +266,14 @@ public class EscherGraphics extends Graphics {
public void drawPolyline(int[] xPoints, int[] yPoints,
int nPoints)
{
- LOG.log(POILogger.WARN,"drawPolyline not supported");
+ LOG.atWarn().log("drawPolyline not supported");
}
@Override
@NotImplemented
public void drawRect(int x, int y, int width, int height)
{
- LOG.log(POILogger.WARN,"drawRect not supported");
+ LOG.atWarn().log("drawRect not supported");
}
@Override
@@ -281,7 +281,7 @@ public class EscherGraphics extends Graphics {
public void drawRoundRect(int x, int y, int width, int height,
int arcWidth, int arcHeight)
{
- LOG.log(POILogger.WARN,"drawRoundRect not supported");
+ LOG.atWarn().log("drawRoundRect not supported");
}
@Override
@@ -349,16 +349,14 @@ public class EscherGraphics extends Graphics {
public void drawString(AttributedCharacterIterator iterator,
int x, int y)
{
- if (LOG.check( POILogger.WARN ))
- LOG.log(POILogger.WARN,"drawString not supported");
+ LOG.atWarn().log("drawString not supported");
}
@Override
public void fillArc(int x, int y, int width, int height,
int startAngle, int arcAngle)
{
- if (LOG.check( POILogger.WARN ))
- LOG.log(POILogger.WARN,"fillArc not supported");
+ LOG.atWarn().log("fillArc not supported");
}
@Override
@@ -389,7 +387,7 @@ public class EscherGraphics extends Graphics {
* @param xPoints array of the <code>x</code> coordinates.
* @param yPoints array of the <code>y</code> coordinates.
* @param nPoints the total number of points in the polygon.
- * @see java.awt.Graphics#drawPolygon(int[], int[], int)
+ * @see Graphics#drawPolygon(int[], int[], int)
*/
@Override
public void fillPolygon(int[] xPoints, int[] yPoints,
@@ -442,8 +440,7 @@ public class EscherGraphics extends Graphics {
public void fillRoundRect(int x, int y, int width, int height,
int arcWidth, int arcHeight)
{
- if (LOG.check( POILogger.WARN ))
- LOG.log(POILogger.WARN,"fillRoundRect not supported");
+ LOG.atWarn().log("fillRoundRect not supported");
}
@Override
@@ -488,7 +485,7 @@ public class EscherGraphics extends Graphics {
@NotImplemented
public void setClip(Shape shape)
{
- LOG.log(POILogger.WARN,"setClip not supported");
+ LOG.atWarn().log("setClip not supported");
}
@Override
@@ -507,21 +504,21 @@ public class EscherGraphics extends Graphics {
@NotImplemented
public void setPaintMode()
{
- LOG.log(POILogger.WARN,"setPaintMode not supported");
+ LOG.atWarn().log("setPaintMode not supported");
}
@Override
@NotImplemented
public void setXORMode(Color color)
{
- LOG.log(POILogger.WARN,"setXORMode not supported");
+ LOG.atWarn().log("setXORMode not supported");
}
@Override
@NotImplemented
public void translate(int x, int y)
{
- LOG.log(POILogger.WARN,"translate not supported");
+ LOG.atWarn().log("translate not supported");
}
public Color getBackground()
diff --git a/src/java/org/apache/poi/hssf/usermodel/EscherGraphics2d.java b/src/java/org/apache/poi/hssf/usermodel/EscherGraphics2d.java
index 6d631efb1f..a5e3516ab0 100644
--- a/src/java/org/apache/poi/hssf/usermodel/EscherGraphics2d.java
+++ b/src/java/org/apache/poi/hssf/usermodel/EscherGraphics2d.java
@@ -17,17 +17,19 @@
package org.apache.poi.hssf.usermodel;
-import org.apache.poi.util.POILogFactory;
-import org.apache.poi.util.POILogger;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
import java.awt.*;
import java.awt.font.FontRenderContext;
import java.awt.font.GlyphVector;
import java.awt.font.TextLayout;
import java.awt.geom.AffineTransform;
+import java.awt.geom.Arc2D;
import java.awt.geom.Area;
import java.awt.geom.GeneralPath;
import java.awt.geom.Line2D;
+import java.awt.geom.RoundRectangle2D;
import java.awt.image.BufferedImage;
import java.awt.image.BufferedImageOp;
import java.awt.image.ImageObserver;
@@ -69,7 +71,7 @@ import java.util.Map;
* </blockquote>
*/
public final class EscherGraphics2d extends Graphics2D {
- private static final POILogger LOG = POILogFactory.getLogger(EscherGraphics2d.class);
+ private static final Logger LOG = LogManager.getLogger(EscherGraphics2d.class);
private EscherGraphics _escherGraphics;
private BufferedImage _img;
@@ -153,15 +155,14 @@ public final class EscherGraphics2d extends Graphics2D {
}
else
{
- if (LOG.check(POILogger.WARN))
- LOG.log(POILogger.WARN, "draw not fully supported");
+ LOG.atWarn().log("draw not fully supported");
}
}
public void drawArc(int x, int y, int width, int height,
int startAngle, int arcAngle)
{
- draw(new java.awt.geom.Arc2D.Float(x, y, width, height, startAngle, arcAngle, 0));
+ draw(new Arc2D.Float(x, y, width, height, startAngle, arcAngle, 0));
}
public void drawGlyphVector(GlyphVector g, float x, float y)
@@ -172,22 +173,19 @@ public final class EscherGraphics2d extends Graphics2D {
public boolean drawImage(Image image, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1,
int sx2, int sy2, Color bgColor, ImageObserver imageobserver)
{
- if (LOG.check( POILogger.WARN ))
- LOG.log(POILogger.WARN,"drawImage() not supported");
+ LOG.atWarn().log("drawImage() not supported");
return true;
}
public boolean drawImage(Image image, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1,
int sx2, int sy2, ImageObserver imageobserver)
{
- if (LOG.check( POILogger.WARN ))
- LOG.log(POILogger.WARN,"drawImage() not supported");
+ LOG.atWarn().log("drawImage() not supported");
return drawImage(image, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, null, imageobserver);
}
public boolean drawImage(Image image, int dx1, int dy1, int dx2, int dy2, Color bgColor, ImageObserver imageobserver)
{
- if (LOG.check( POILogger.WARN ))
- LOG.log(POILogger.WARN,"drawImage() not supported");
+ LOG.atWarn().log("drawImage() not supported");
return true;
}
@@ -282,7 +280,7 @@ public final class EscherGraphics2d extends Graphics2D {
public void drawRoundRect(int i, int j, int k, int l, int i1, int j1)
{
- draw(new java.awt.geom.RoundRectangle2D.Float(i, j, k, l, i1, j1));
+ draw(new RoundRectangle2D.Float(i, j, k, l, i1, j1));
}
public void drawString(String string, float x, float y)
@@ -311,13 +309,12 @@ public final class EscherGraphics2d extends Graphics2D {
public void fill(Shape shape)
{
- if (LOG.check( POILogger.WARN ))
- LOG.log(POILogger.WARN,"fill(Shape) not supported");
+ LOG.atWarn().log("fill(Shape) not supported");
}
public void fillArc(int i, int j, int k, int l, int i1, int j1)
{
- fill(new java.awt.geom.Arc2D.Float(i, j, k, l, i1, j1, 2));
+ fill(new Arc2D.Float(i, j, k, l, i1, j1, 2));
}
public void fillOval(int x, int y, int width, int height)
@@ -342,7 +339,7 @@ public final class EscherGraphics2d extends Graphics2D {
* @param xPoints array of the <code>x</code> coordinates.
* @param yPoints array of the <code>y</code> coordinates.
* @param nPoints the total number of points in the polygon.
- * @see java.awt.Graphics#drawPolygon(int[], int[], int)
+ * @see Graphics#drawPolygon(int[], int[], int)
*/
public void fillPolygon(int[] xPoints, int[] yPoints, int nPoints)
{
@@ -357,7 +354,7 @@ public final class EscherGraphics2d extends Graphics2D {
public void fillRoundRect(int x, int y, int width, int height,
int arcWidth, int arcHeight)
{
- fill(new java.awt.geom.RoundRectangle2D.Float(x, y, width, height, arcWidth, arcHeight));
+ fill(new RoundRectangle2D.Float(x, y, width, height, arcWidth, arcHeight));
}
public Color getBackground()
@@ -422,7 +419,7 @@ public final class EscherGraphics2d extends Graphics2D {
return _paint;
}
- public Object getRenderingHint(java.awt.RenderingHints.Key key)
+ public Object getRenderingHint(RenderingHints.Key key)
{
return getG2D().getRenderingHint(key);
}
@@ -510,7 +507,7 @@ public final class EscherGraphics2d extends Graphics2D {
getEscherGraphics().setPaintMode();
}
- public void setRenderingHint(java.awt.RenderingHints.Key key, Object obj)
+ public void setRenderingHint(RenderingHints.Key key, Object obj)
{
getG2D().setRenderingHint(key, obj);
}
@@ -545,18 +542,6 @@ public final class EscherGraphics2d extends Graphics2D {
getTrans().concatenate(affinetransform);
}
-// Image transformImage(Image image, Rectangle rectangle, Rectangle rectangle1, ImageObserver imageobserver, Color color1)
-// {
-// logger.log(POILogger.WARN,"transformImage() not supported");
-// return null;
-// }
-//
-// Image transformImage(Image image, int ai[], Rectangle rectangle, ImageObserver imageobserver, Color color1)
-// {
-// logger.log(POILogger.WARN,"transformImage() not supported");
-// return null;
-// }
-
public void translate(double d, double d1)
{
getTrans().translate(d, d1);
diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFPatriarch.java b/src/java/org/apache/poi/hssf/usermodel/HSSFPatriarch.java
index c0aa36f524..e5b6d668cc 100644
--- a/src/java/org/apache/poi/hssf/usermodel/HSSFPatriarch.java
+++ b/src/java/org/apache/poi/hssf/usermodel/HSSFPatriarch.java
@@ -57,7 +57,6 @@ import org.apache.poi.util.StringUtil;
* little other than act as a container for other shapes and groups.
*/
public final class HSSFPatriarch implements HSSFShapeContainer, Drawing<HSSFShape> {
- // private static POILogger log = POILogFactory.getLogger(HSSFPatriarch.class);
private final List<HSSFShape> _shapes = new ArrayList<>();
private final EscherSpgrRecord _spgrRecord;
diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFPolygon.java b/src/java/org/apache/poi/hssf/usermodel/HSSFPolygon.java
index b56e105e22..430fe62798 100644
--- a/src/java/org/apache/poi/hssf/usermodel/HSSFPolygon.java
+++ b/src/java/org/apache/poi/hssf/usermodel/HSSFPolygon.java
@@ -17,6 +17,8 @@
package org.apache.poi.hssf.usermodel;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
import org.apache.poi.ddf.EscherArrayProperty;
import org.apache.poi.ddf.EscherBoolProperty;
import org.apache.poi.ddf.EscherClientDataRecord;
@@ -34,8 +36,6 @@ import org.apache.poi.hssf.record.EscherAggregate;
import org.apache.poi.hssf.record.ObjRecord;
import org.apache.poi.hssf.record.TextObjectRecord;
import org.apache.poi.util.LittleEndian;
-import org.apache.poi.util.POILogFactory;
-import org.apache.poi.util.POILogger;
/**
*
@@ -43,7 +43,7 @@ import org.apache.poi.util.POILogger;
public class HSSFPolygon extends HSSFSimpleShape {
public static final short OBJECT_TYPE_MICROSOFT_OFFICE_DRAWING = 0x1E;
- private static final POILogger LOG = POILogFactory.getLogger(HSSFPolygon.class);
+ private static final Logger LOG = LogManager.getLogger(HSSFPolygon.class);
public HSSFPolygon(EscherContainerRecord spContainer, ObjRecord objRecord, TextObjectRecord _textObjectRecord) {
super(spContainer, objRecord, _textObjectRecord);
@@ -174,11 +174,11 @@ public class HSSFPolygon extends HSSFSimpleShape {
*/
public void setPoints(int[] xPoints, int[] yPoints) {
if (xPoints.length != yPoints.length){
- LOG.log( POILogger.ERROR, "xPoint.length must be equal to yPoints.length");
+ LOG.atError().log("xPoint.length must be equal to yPoints.length");
return;
}
if (xPoints.length == 0){
- LOG.log( POILogger.ERROR, "HSSFPolygon must have at least one point");
+ LOG.atError().log("HSSFPolygon must have at least one point");
}
EscherArrayProperty verticesProp = new EscherArrayProperty(EscherPropertyTypes.GEOMETRY__VERTICES, false, 0);
verticesProp.setNumberOfElementsInArray(xPoints.length+1);
diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFShape.java b/src/java/org/apache/poi/hssf/usermodel/HSSFShape.java
index 7e575a6642..92d66e1db6 100644
--- a/src/java/org/apache/poi/hssf/usermodel/HSSFShape.java
+++ b/src/java/org/apache/poi/hssf/usermodel/HSSFShape.java
@@ -20,6 +20,8 @@ package org.apache.poi.hssf.usermodel;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
import org.apache.poi.ddf.EscherBoolProperty;
import org.apache.poi.ddf.EscherChildAnchorRecord;
import org.apache.poi.ddf.EscherClientAnchorRecord;
@@ -35,8 +37,6 @@ import org.apache.poi.hssf.record.CommonObjectDataSubRecord;
import org.apache.poi.hssf.record.ObjRecord;
import org.apache.poi.ss.usermodel.Shape;
import org.apache.poi.util.LittleEndian;
-import org.apache.poi.util.POILogFactory;
-import org.apache.poi.util.POILogger;
import org.apache.poi.util.StringUtil;
/**
@@ -48,7 +48,7 @@ import org.apache.poi.util.StringUtil;
* setFlipVertical() or setFlipHorizontally().
*/
public abstract class HSSFShape implements Shape {
- private static final POILogger LOG = POILogFactory.getLogger(HSSFShape.class);
+ private static final Logger LOG = LogManager.getLogger(HSSFShape.class);
public static final int LINEWIDTH_ONE_PT = 12700;
public static final int LINEWIDTH_DEFAULT = 9525;
@@ -374,7 +374,7 @@ public abstract class HSSFShape implements Shape {
LittleEndian.putInt(property.getPropertyValue(), bos);
return LittleEndian.getShort(bos.toByteArray(), 2);
} catch (IOException e) {
- LOG.log(POILogger.ERROR, "can't determine rotation degree", e);
+ LOG.atError().withThrowable(e).log("can't determine rotation degree");
return 0;
}
}
diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java b/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java
index 03d4f215e5..975419077c 100644
--- a/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java
+++ b/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java
@@ -26,6 +26,9 @@ import java.util.Map;
import java.util.TreeMap;
import java.util.TreeSet;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.message.SimpleMessage;
import org.apache.poi.ddf.EscherRecord;
import org.apache.poi.hssf.model.DrawingManager2;
import org.apache.poi.hssf.model.HSSFFormulaParser;
@@ -64,7 +67,10 @@ import org.apache.poi.ss.usermodel.CellRange;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.DataValidation;
import org.apache.poi.ss.usermodel.DataValidationHelper;
+import org.apache.poi.ss.usermodel.FormulaEvaluator;
import org.apache.poi.ss.usermodel.Row;
+import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.helpers.RowShifter;
import org.apache.poi.ss.util.CellAddress;
import org.apache.poi.ss.util.CellRangeAddress;
@@ -76,15 +82,15 @@ import org.apache.poi.ss.util.SheetUtil;
import org.apache.poi.util.Beta;
import org.apache.poi.util.Configurator;
import org.apache.poi.util.Internal;
-import org.apache.poi.util.POILogFactory;
-import org.apache.poi.util.POILogger;
+
+import static java.lang.System.currentTimeMillis;
+import static org.apache.logging.log4j.util.Unbox.box;
/**
* High level representation of a worksheet.
*/
-public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet {
- private static final POILogger log = POILogFactory.getLogger(HSSFSheet.class);
- private static final int DEBUG = POILogger.DEBUG;
+public final class HSSFSheet implements Sheet {
+ private static final Logger LOGGER = LogManager.getLogger(HSSFSheet.class);
/**
* width of 1px in columns with default width in units of 1/256 of a character width
@@ -122,7 +128,7 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet {
* scratch. You should not be calling this from application code (its protected anyhow).
*
* @param workbook - The HSSF Workbook object associated with the sheet.
- * @see org.apache.poi.hssf.usermodel.HSSFWorkbook#createSheet()
+ * @see HSSFWorkbook#createSheet()
*/
protected HSSFSheet(HSSFWorkbook workbook) {
_sheet = InternalSheet.createSheet();
@@ -137,7 +143,7 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet {
*
* @param workbook - The HSSF Workbook object associated with the sheet.
* @param sheet - lowlevel Sheet object this sheet will represent
- * @see org.apache.poi.hssf.usermodel.HSSFWorkbook#createSheet()
+ * @see HSSFWorkbook#createSheet()
*/
protected HSSFSheet(HSSFWorkbook workbook, InternalSheet sheet) {
this._sheet = sheet;
@@ -196,19 +202,16 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet {
}
Iterator<CellValueRecordInterface> iter = sheet.getCellValueIterator();
- long timestart = System.currentTimeMillis();
+ long timestart = currentTimeMillis();
- if (log.check( POILogger.DEBUG )) {
- log.log(DEBUG, "Time at start of cell creating in HSSF sheet = ",
- Long.valueOf(timestart));
- }
+ LOGGER.atDebug().log("Time at start of cell creating in HSSF sheet = {}", box(timestart));
HSSFRow lastrow = null;
// Add every cell to its row
while (iter.hasNext()) {
CellValueRecordInterface cval = iter.next();
- long cellstart = System.currentTimeMillis();
+ long cellstart = currentTimeMillis();
HSSFRow hrow = lastrow;
if (hrow == null || hrow.getRowNum() != cval.getRow()) {
@@ -229,24 +232,18 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet {
hrow = createRowFromRecord(rowRec);
}
}
- if (log.check( POILogger.DEBUG )) {
+ LOGGER.atTrace().log(() -> {
if (cval instanceof Record) {
- log.log( DEBUG, "record id = ", Integer.toHexString( ( (org.apache.poi.hssf.record.Record) cval ).getSid() ) );
+ return new SimpleMessage("record id = " + Integer.toHexString(((Record) cval).getSid()));
} else {
- log.log( DEBUG, "record = ", cval );
+ return new SimpleMessage("record = " + cval);
}
- }
+ });
hrow.createCellFromRecord( cval );
- if (log.check( POILogger.DEBUG )) {
- log.log( DEBUG, "record took ",
- Long.valueOf( System.currentTimeMillis() - cellstart ) );
- }
+ LOGGER.atTrace().log("record took {}ms", box(currentTimeMillis() - cellstart));
}
- if (log.check( POILogger.DEBUG )) {
- log.log(DEBUG, "total sheet cell creation took ",
- Long.valueOf(System.currentTimeMillis() - timestart));
- }
+ LOGGER.atDebug().log("total sheet cell creation took {}ms", box(currentTimeMillis() - timestart));
}
/**
@@ -254,8 +251,8 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet {
*
* @param rownum row number
* @return High level HSSFRow object representing a row in the sheet
- * @see org.apache.poi.hssf.usermodel.HSSFRow
- * @see #removeRow(org.apache.poi.ss.usermodel.Row)
+ * @see HSSFRow
+ * @see #removeRow(Row)
*/
@Override
public HSSFRow createRow(int rownum) {
@@ -438,7 +435,7 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet {
private HSSFEvaluationWorkbook book = HSSFEvaluationWorkbook.create(getWorkbook());
@Override
- public void visitRecord(org.apache.poi.hssf.record.Record r) {
+ public void visitRecord(Record r) {
if (!(r instanceof DVRecord)) {
return;
}
@@ -815,17 +812,17 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet {
* Control if Excel should be asked to recalculate all formulas on this sheet
* when the workbook is opened.<p>
*
- * Calculating the formula values with {@link org.apache.poi.ss.usermodel.FormulaEvaluator} is the
+ * Calculating the formula values with {@link FormulaEvaluator} is the
* recommended solution, but this may be used for certain cases where
* evaluation in POI is not possible.<p>
*
* It is recommended to force recalcuation of formulas on workbook level using
- * {@link org.apache.poi.ss.usermodel.Workbook#setForceFormulaRecalculation(boolean)}
+ * {@link Workbook#setForceFormulaRecalculation(boolean)}
* to ensure that all cross-worksheet formuals and external dependencies are updated.
*
* @param value true if the application will perform a full recalculation of
* this worksheet values when the workbook is opened
- * @see org.apache.poi.ss.usermodel.Workbook#setForceFormulaRecalculation(boolean)
+ * @see Workbook#setForceFormulaRecalculation(boolean)
*/
@Override
public void setForceFormulaRecalculation(boolean value) {
@@ -1773,7 +1770,7 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet {
// add logic for hyperlinks etc, like in shiftRows()
}
- protected void insertChartRecords(List<org.apache.poi.hssf.record.Record> records) {
+ protected void insertChartRecords(List<Record> records) {
int window2Loc = _sheet.findFirstRecordLocBySid(WindowTwoRecord.sid);
_sheet.getRecords().addAll(window2Loc, records);
}
diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java b/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java
index 9d78e85539..d6e5c6329f 100644
--- a/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java
+++ b/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java
@@ -17,12 +17,15 @@
package org.apache.poi.hssf.usermodel;
+import static org.apache.logging.log4j.util.Unbox.box;
import static org.apache.poi.hssf.model.InternalWorkbook.OLD_WORKBOOK_DIR_ENTRY_NAME;
import static org.apache.poi.hssf.model.InternalWorkbook.WORKBOOK_DIR_ENTRY_NAMES;
+import java.io.BufferedOutputStream;
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 java.io.OutputStream;
@@ -44,6 +47,8 @@ import java.util.Set;
import java.util.regex.Pattern;
import org.apache.commons.codec.digest.DigestUtils;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
import org.apache.poi.EncryptedDocumentException;
import org.apache.poi.POIDocument;
import org.apache.poi.ddf.EscherBSERecord;
@@ -70,6 +75,7 @@ import org.apache.poi.hssf.record.DrawingGroupRecord;
import org.apache.poi.hssf.record.ExtendedFormatRecord;
import org.apache.poi.hssf.record.FilePassRecord;
import org.apache.poi.hssf.record.FontRecord;
+import org.apache.poi.hssf.record.FormatRecord;
import org.apache.poi.hssf.record.LabelRecord;
import org.apache.poi.hssf.record.LabelSSTRecord;
import org.apache.poi.hssf.record.NameRecord;
@@ -110,6 +116,7 @@ import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.SheetVisibility;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.util.CellReference;
+import org.apache.poi.ss.util.WorkbookUtil;
import org.apache.poi.util.Configurator;
import org.apache.poi.util.HexDump;
import org.apache.poi.util.IOUtils;
@@ -117,8 +124,6 @@ import org.apache.poi.util.Internal;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.LittleEndianByteArrayInputStream;
import org.apache.poi.util.LittleEndianByteArrayOutputStream;
-import org.apache.poi.util.POILogFactory;
-import org.apache.poi.util.POILogger;
import org.apache.poi.util.Removal;
/**
@@ -126,11 +131,11 @@ import org.apache.poi.util.Removal;
* will construct whether they are reading or writing a workbook. It is also the
* top level object for creating new sheets/etc.
*
- * @see org.apache.poi.hssf.model.InternalWorkbook
- * @see org.apache.poi.hssf.usermodel.HSSFSheet
+ * @see InternalWorkbook
+ * @see HSSFSheet
*/
@SuppressWarnings("WeakerAccess")
-public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss.usermodel.Workbook {
+public final class HSSFWorkbook extends POIDocument implements Workbook {
//arbitrarily selected; may need to increase
private static final int MAX_RECORD_LENGTH = 100_000;
@@ -147,8 +152,6 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
*/
private static final int MAX_STYLES = 4030;
- private static final int DEBUG = POILogger.DEBUG;
-
/**
* used for compile-time performance/memory optimization. This determines the
* initial capacity for the sheet collection. Its currently set to 3.
@@ -203,7 +206,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
*/
private MissingCellPolicy missingCellPolicy = MissingCellPolicy.RETURN_NULL_AND_BLANK;
- private static final POILogger log = POILogFactory.getLogger(HSSFWorkbook.class);
+ private static final Logger LOGGER = LogManager.getLogger(HSSFWorkbook.class);
/**
* The locator of user-defined functions.
@@ -237,7 +240,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
*
* @throws IOException if the stream cannot be read
* @see #HSSFWorkbook(POIFSFileSystem, boolean)
- * @see org.apache.poi.poifs.filesystem.POIFSFileSystem
+ * @see POIFSFileSystem
*/
public HSSFWorkbook(POIFSFileSystem fs) throws IOException {
this(fs, true);
@@ -253,7 +256,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
* need to. If set, will store all of the POIFSFileSystem
* in memory
* @throws IOException if the stream cannot be read
- * @see org.apache.poi.poifs.filesystem.POIFSFileSystem
+ * @see POIFSFileSystem
*/
public HSSFWorkbook(POIFSFileSystem fs, boolean preserveNodes)
throws IOException {
@@ -300,7 +303,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
* need to. If set, will store all of the POIFSFileSystem
* in memory
* @throws IOException if the stream cannot be read
- * @see org.apache.poi.poifs.filesystem.POIFSFileSystem
+ * @see POIFSFileSystem
*/
public HSSFWorkbook(DirectoryNode directory, POIFSFileSystem fs, boolean preserveNodes)
throws IOException {
@@ -318,7 +321,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
* need to. If set, will store all of the POIFSFileSystem
* in memory
* @throws IOException if the stream cannot be read
- * @see org.apache.poi.poifs.filesystem.POIFSFileSystem
+ * @see POIFSFileSystem
*/
public HSSFWorkbook(DirectoryNode directory, boolean preserveNodes)
throws IOException {
@@ -340,7 +343,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
// it happens to be spelled.
InputStream stream = directory.createDocumentInputStream(workbookName);
- List<org.apache.poi.hssf.record.Record> records = RecordFactory.createRecords(stream);
+ List<Record> records = RecordFactory.createRecords(stream);
workbook = InternalWorkbook.createWorkbook(records);
setPropertiesFromWorkbook(workbook);
@@ -355,7 +358,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
_sheets.add(new HSSFSheet(this, sheet));
} catch (UnsupportedBOFType eb) {
// Hopefully there's a supported one after this!
- log.log(POILogger.WARN, "Unsupported BOF found of type " + eb.getType());
+ LOGGER.atWarn().log("Unsupported BOF found of type {}", box(eb.getType()));
}
}
@@ -375,7 +378,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
* @throws IOException if the stream cannot be read
* @see #HSSFWorkbook(InputStream, boolean)
* @see #HSSFWorkbook(POIFSFileSystem)
- * @see org.apache.poi.poifs.filesystem.POIFSFileSystem
+ * @see POIFSFileSystem
*/
public HSSFWorkbook(InputStream s) throws IOException {
this(s, true);
@@ -390,7 +393,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
* macros. This takes more memory, so only say yes if you
* need to.
* @throws IOException if the stream cannot be read
- * @see org.apache.poi.poifs.filesystem.POIFSFileSystem
+ * @see POIFSFileSystem
* @see #HSSFWorkbook(POIFSFileSystem)
*/
@SuppressWarnings("resource") // POIFSFileSystem always closes the stream
@@ -421,13 +424,13 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
*
* @param records a collection of sheet's records.
* @param offset the offset to search at
- * @see org.apache.poi.hssf.record.LabelRecord
- * @see org.apache.poi.hssf.record.LabelSSTRecord
- * @see org.apache.poi.hssf.record.SSTRecord
+ * @see LabelRecord
+ * @see LabelSSTRecord
+ * @see SSTRecord
*/
- private void convertLabelRecords(List<org.apache.poi.hssf.record.Record> records, int offset) {
- log.log(POILogger.DEBUG, "convertLabelRecords called");
+ private void convertLabelRecords(List<Record> records, int offset) {
+ LOGGER.atDebug().log("convertLabelRecords called");
for (int k = offset; k < records.size(); k++) {
Record rec = records.get(k);
@@ -446,7 +449,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
records.add(k, newrec);
}
}
- log.log(POILogger.DEBUG, "convertLabelRecords exit");
+ LOGGER.atDebug().log("convertLabelRecords exit");
}
/**
@@ -655,7 +658,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
* allow you to show the data of one sheet when another is seen "selected"
* in the tabs (at the bottom).
*
- * @see org.apache.poi.hssf.usermodel.HSSFSheet#setSelected(boolean)
+ * @see HSSFSheet#setSelected(boolean)
*/
@Override
public int getActiveSheetIndex() {
@@ -690,7 +693,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
* @throws IllegalArgumentException if the name is null or invalid
* or workbook already contains a sheet with this name
* @see #createSheet(String)
- * @see org.apache.poi.ss.util.WorkbookUtil#createSafeSheetName(String nameProposal)
+ * @see WorkbookUtil#createSafeSheetName(String nameProposal)
*/
@Override
public void setSheetName(int sheetIx, String name) {
@@ -770,7 +773,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
* @return index of the sheet (0 based). <tt>-1</tt> if not found
*/
@Override
- public int getSheetIndex(org.apache.poi.ss.usermodel.Sheet sheet) {
+ public int getSheetIndex(Sheet sheet) {
return _sheets.indexOf(sheet);
}
@@ -898,7 +901,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
* @return Sheet representing the new sheet.
* @throws IllegalArgumentException if the name is null or invalid
* or workbook already contains a sheet with this name
- * @see org.apache.poi.ss.util.WorkbookUtil#createSafeSheetName(String nameProposal)
+ * @see WorkbookUtil#createSafeSheetName(String nameProposal)
*/
@Override
public HSSFSheet createSheet(String sheetname) {
@@ -1328,7 +1331,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
*
* @param newFile The new File you wish to write the XLS to
* @throws IOException if anything can't be written.
- * @see org.apache.poi.poifs.filesystem.POIFSFileSystem
+ * @see POIFSFileSystem
*/
@Override
public void write(File newFile) throws IOException {
@@ -1343,14 +1346,14 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
* a new POI POIFSFileSystem, passes in the workbook binary representation and
* writes it out.
* <p>
- * If {@code stream} is a {@link java.io.FileOutputStream} on a networked drive
+ * If {@code stream} is a {@link FileOutputStream} on a networked drive
* or has a high cost/latency associated with each written byte,
- * consider wrapping the OutputStream in a {@link java.io.BufferedOutputStream}
+ * consider wrapping the OutputStream in a {@link BufferedOutputStream}
* to improve write performance.
*
* @param stream - the java OutputStream you wish to write the XLS to
* @throws IOException if anything can't be written.
- * @see org.apache.poi.poifs.filesystem.POIFSFileSystem
+ * @see POIFSFileSystem
*/
@Override
public void write(OutputStream stream) throws IOException {
@@ -1405,7 +1408,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
*/
private static final class SheetRecordCollector implements RecordVisitor {
- private List<org.apache.poi.hssf.record.Record> _list;
+ private List<Record> _list;
private int _totalSize;
public SheetRecordCollector() {
@@ -1418,7 +1421,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
}
@Override
- public void visitRecord(org.apache.poi.hssf.record.Record r) {
+ public void visitRecord(Record r) {
_list.add(r);
_totalSize += r.getRecordSize();
@@ -1426,7 +1429,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
public int serialize(int offset, byte[] data) {
int result = 0;
- for (org.apache.poi.hssf.record.Record rec : _list) {
+ for (Record rec : _list) {
result += rec.serialize(offset + result, data);
}
return result;
@@ -1442,9 +1445,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
* sheets, rows, cells, etc.
*/
public byte[] getBytes() {
- if (log.check(POILogger.DEBUG)) {
- log.log(DEBUG, "HSSFWorkbook.getBytes()");
- }
+ LOGGER.atDebug().log("HSSFWorkbook.getBytes()");
HSSFSheet[] sheets = getSheets();
int nSheets = sheets.length;
@@ -1744,8 +1745,8 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
* Returns the instance of HSSFDataFormat for this workbook.
*
* @return the HSSFDataFormat object
- * @see org.apache.poi.hssf.record.FormatRecord
- * @see org.apache.poi.hssf.record.Record
+ * @see FormatRecord
+ * @see Record
*/
@Override
public HSSFDataFormat createDataFormat() {
@@ -1929,7 +1930,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
public List<HSSFPictureData> getAllPictures() {
// The drawing group record always exists at the top level, so we won't need to do this recursively.
List<HSSFPictureData> pictures = new ArrayList<>();
- for (org.apache.poi.hssf.record.Record r : workbook.getRecords()) {
+ for (Record r : workbook.getRecords()) {
if (r instanceof AbstractEscherHolderRecord) {
((AbstractEscherHolderRecord) r).decode();
List<EscherRecord> escherRecords = ((AbstractEscherHolderRecord) r).getEscherRecords();
diff --git a/src/java/org/apache/poi/hssf/usermodel/StaticFontMetrics.java b/src/java/org/apache/poi/hssf/usermodel/StaticFontMetrics.java
index a586c73211..453f3db384 100644
--- a/src/java/org/apache/poi/hssf/usermodel/StaticFontMetrics.java
+++ b/src/java/org/apache/poi/hssf/usermodel/StaticFontMetrics.java
@@ -26,8 +26,8 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
-import org.apache.poi.util.POILogFactory;
-import org.apache.poi.util.POILogger;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
/**
* Allows the user to lookup the font metrics for a particular font without
@@ -37,7 +37,7 @@ import org.apache.poi.util.POILogger;
* font. Use a multiplier for other sizes.
*/
final class StaticFontMetrics {
- private static final POILogger LOGGER = POILogFactory.getLogger(StaticFontMetrics.class);
+ private static final Logger LOGGER = LogManager.getLogger(StaticFontMetrics.class);
/** The font metrics property file we're using */
private static Properties fontMetricsProps;
/** Our cache of font details we've already looked up */
@@ -109,12 +109,12 @@ final class StaticFontMetrics {
if (propFileName != null) {
propFile = new File(propFileName);
if (!propFile.exists()) {
- LOGGER.log(POILogger.WARN, "font_metrics.properties not found at path "+propFile.getAbsolutePath());
+ LOGGER.atWarn().log("font_metrics.properties not found at path {}", propFile.getAbsolutePath());
propFile = null;
}
}
} catch (SecurityException e) {
- LOGGER.log(POILogger.WARN, "Can't access font.metrics.filename system property", e);
+ LOGGER.atWarn().withThrowable(e).log("Can't access font.metrics.filename system property");
}
try (InputStream metricsIn = (propFile != null)
diff --git a/src/java/org/apache/poi/hssf/usermodel/helpers/HSSFColumnShifter.java b/src/java/org/apache/poi/hssf/usermodel/helpers/HSSFColumnShifter.java
index 5ed4870398..3f86caddd6 100644
--- a/src/java/org/apache/poi/hssf/usermodel/helpers/HSSFColumnShifter.java
+++ b/src/java/org/apache/poi/hssf/usermodel/helpers/HSSFColumnShifter.java
@@ -17,14 +17,14 @@
package org.apache.poi.hssf.usermodel.helpers;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.ss.formula.FormulaShifter;
import org.apache.poi.ss.formula.eval.NotImplementedException;
import org.apache.poi.ss.usermodel.helpers.ColumnShifter;
import org.apache.poi.util.Beta;
import org.apache.poi.util.NotImplemented;
-import org.apache.poi.util.POILogFactory;
-import org.apache.poi.util.POILogger;
/**
* Helper for shifting columns up or down
@@ -35,7 +35,7 @@ import org.apache.poi.util.POILogger;
// {@link org.apache.poi.xssf.usermodel.helpers.XSSFColumnShifter}
@Beta
public final class HSSFColumnShifter extends ColumnShifter {
- private static final POILogger LOG = POILogFactory.getLogger(HSSFColumnShifter.class);
+ private static final Logger LOG = LogManager.getLogger(HSSFColumnShifter.class);
public HSSFColumnShifter(HSSFSheet sh) {
super(sh);
diff --git a/src/java/org/apache/poi/hssf/usermodel/helpers/HSSFRowShifter.java b/src/java/org/apache/poi/hssf/usermodel/helpers/HSSFRowShifter.java
index 8889205b48..4a743556a4 100644
--- a/src/java/org/apache/poi/hssf/usermodel/helpers/HSSFRowShifter.java
+++ b/src/java/org/apache/poi/hssf/usermodel/helpers/HSSFRowShifter.java
@@ -17,15 +17,13 @@
package org.apache.poi.hssf.usermodel.helpers;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.ss.formula.FormulaShifter;
import org.apache.poi.ss.formula.eval.NotImplementedException;
-import org.apache.poi.ss.usermodel.Row;
-import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.helpers.RowShifter;
import org.apache.poi.util.NotImplemented;
-import org.apache.poi.util.POILogFactory;
-import org.apache.poi.util.POILogger;
/**
* Helper for shifting rows up or down
@@ -33,7 +31,7 @@ import org.apache.poi.util.POILogger;
// non-Javadoc: When possible, code should be implemented in the RowShifter abstract class to avoid duplication with
// {@link org.apache.poi.xssf.usermodel.helpers.XSSFRowShifter}
public final class HSSFRowShifter extends RowShifter {
- private static final POILogger LOG = POILogFactory.getLogger(HSSFRowShifter.class);
+ private static final Logger LOG = LogManager.getLogger(HSSFRowShifter.class);
public HSSFRowShifter(HSSFSheet sh) {
super(sh);
diff --git a/src/java/org/apache/poi/poifs/crypt/ChunkedCipherOutputStream.java b/src/java/org/apache/poi/poifs/crypt/ChunkedCipherOutputStream.java
index d5ea57a655..5270fc0461 100644
--- a/src/java/org/apache/poi/poifs/crypt/ChunkedCipherOutputStream.java
+++ b/src/java/org/apache/poi/poifs/crypt/ChunkedCipherOutputStream.java
@@ -32,6 +32,8 @@ import javax.crypto.IllegalBlockSizeException;
import javax.crypto.ShortBufferException;
import com.zaxxer.sparsebits.SparseBitSet;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
import org.apache.poi.EncryptedDocumentException;
import org.apache.poi.poifs.filesystem.DirectoryNode;
import org.apache.poi.poifs.filesystem.POIFSWriterEvent;
@@ -40,13 +42,11 @@ import org.apache.poi.util.IOUtils;
import org.apache.poi.util.Internal;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.LittleEndianConsts;
-import org.apache.poi.util.POILogFactory;
-import org.apache.poi.util.POILogger;
import org.apache.poi.util.TempFile;
@Internal
public abstract class ChunkedCipherOutputStream extends FilterOutputStream {
- private static final POILogger LOG = POILogFactory.getLogger(ChunkedCipherOutputStream.class);
+ private static final Logger LOG = LogManager.getLogger(ChunkedCipherOutputStream.class);
//arbitrarily selected; may need to increase
private static final int MAX_RECORD_LENGTH = 100_000;
@@ -257,7 +257,7 @@ public abstract class ChunkedCipherOutputStream extends FilterOutputStream {
@Override
public void close() throws IOException {
if (isClosed) {
- LOG.log(POILogger.DEBUG, "ChunkedCipherOutputStream was already closed - ignoring");
+ LOG.atDebug().log("ChunkedCipherOutputStream was already closed - ignoring");
return;
}
@@ -324,7 +324,7 @@ public abstract class ChunkedCipherOutputStream extends FilterOutputStream {
}
if (!fileOut.delete()) {
- LOG.log(POILogger.ERROR, "Can't delete temporary encryption file: ", fileOut);
+ LOG.atError().log("Can't delete temporary encryption file: {}", fileOut);
}
} catch (IOException e) {
throw new EncryptedDocumentException(e);
diff --git a/src/java/org/apache/poi/poifs/crypt/standard/StandardEncryptor.java b/src/java/org/apache/poi/poifs/crypt/standard/StandardEncryptor.java
index 84c897074d..097a7bd6d7 100644
--- a/src/java/org/apache/poi/poifs/crypt/standard/StandardEncryptor.java
+++ b/src/java/org/apache/poi/poifs/crypt/standard/StandardEncryptor.java
@@ -36,6 +36,8 @@ import javax.crypto.Cipher;
import javax.crypto.CipherOutputStream;
import javax.crypto.SecretKey;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
import org.apache.poi.EncryptedDocumentException;
import org.apache.poi.poifs.crypt.CryptoFunctions;
import org.apache.poi.poifs.crypt.DataSpaceMapUtils;
@@ -49,12 +51,10 @@ import org.apache.poi.util.IOUtils;
import org.apache.poi.util.LittleEndianByteArrayOutputStream;
import org.apache.poi.util.LittleEndianConsts;
import org.apache.poi.util.LittleEndianOutputStream;
-import org.apache.poi.util.POILogFactory;
-import org.apache.poi.util.POILogger;
import org.apache.poi.util.TempFile;
public class StandardEncryptor extends Encryptor {
- private static final POILogger LOG = POILogFactory.getLogger(StandardEncryptor.class);
+ private static final Logger LOG = LogManager.getLogger(StandardEncryptor.class);
protected StandardEncryptor() {}
@@ -193,7 +193,7 @@ public class StandardEncryptor extends Encryptor {
IOUtils.copy(fis, leos);
}
if (!fileOut.delete()) {
- LOG.log(POILogger.ERROR, "Can't delete temporary encryption file: ", fileOut);
+ LOG.atError().log("Can't delete temporary encryption file: {}", fileOut);
}
leos.close();
diff --git a/src/java/org/apache/poi/poifs/filesystem/POIFSDocumentPath.java b/src/java/org/apache/poi/poifs/filesystem/POIFSDocumentPath.java
index c613bdcd3f..1db851e8b6 100644
--- a/src/java/org/apache/poi/poifs/filesystem/POIFSDocumentPath.java
+++ b/src/java/org/apache/poi/poifs/filesystem/POIFSDocumentPath.java
@@ -25,8 +25,8 @@ import java.util.Objects;
import java.util.function.Predicate;
import java.util.stream.Stream;
-import org.apache.poi.util.POILogFactory;
-import org.apache.poi.util.POILogger;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
/**
* Class POIFSDocumentPath
@@ -34,7 +34,7 @@ import org.apache.poi.util.POILogger;
public class POIFSDocumentPath {
- private static final POILogger log = POILogFactory.getLogger(POIFSDocumentPath.class);
+ private static final Logger LOGGER = LogManager.getLogger(POIFSDocumentPath.class);
private final String[] components;
private int hashcode; //lazy-compute hashCode
diff --git a/src/java/org/apache/poi/poifs/filesystem/POIFSFileSystem.java b/src/java/org/apache/poi/poifs/filesystem/POIFSFileSystem.java
index 94c68a6379..2fb09dc04d 100644
--- a/src/java/org/apache/poi/poifs/filesystem/POIFSFileSystem.java
+++ b/src/java/org/apache/poi/poifs/filesystem/POIFSFileSystem.java
@@ -34,6 +34,8 @@ import java.util.Iterator;
import java.util.List;
import org.apache.commons.math3.util.ArithmeticUtils;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
import org.apache.poi.EmptyFileException;
import org.apache.poi.poifs.common.POIFSBigBlockSize;
import org.apache.poi.poifs.common.POIFSConstants;
@@ -49,8 +51,6 @@ import org.apache.poi.poifs.storage.BATBlock.BATBlockAndIndex;
import org.apache.poi.poifs.storage.HeaderBlock;
import org.apache.poi.util.IOUtils;
import org.apache.poi.util.Internal;
-import org.apache.poi.util.POILogFactory;
-import org.apache.poi.util.POILogger;
/**
* <p>This is the main class of the POIFS system; it manages the entire
@@ -63,7 +63,7 @@ public class POIFSFileSystem extends BlockStore
//arbitrarily selected; may need to increase
private static final int MAX_RECORD_LENGTH = 100_000;
- private static final POILogger LOG = POILogFactory.getLogger(POIFSFileSystem.class);
+ private static final Logger LOG = LogManager.getLogger(POIFSFileSystem.class);
/**
* Maximum number size (in blocks) of the allocation table as supported by
@@ -327,7 +327,7 @@ public class POIFSFileSystem extends BlockStore
}
// else not success? Try block did not complete normally
// just print stack trace and leave original ex to be thrown
- LOG.log(POILogger.ERROR, "can't close input stream", e);
+ LOG.atError().withThrowable(e).log("can't close input stream");
}
}
diff --git a/src/java/org/apache/poi/poifs/macros/VBAMacroReader.java b/src/java/org/apache/poi/poifs/macros/VBAMacroReader.java
index 624a5fd360..2f28c6397e 100644
--- a/src/java/org/apache/poi/poifs/macros/VBAMacroReader.java
+++ b/src/java/org/apache/poi/poifs/macros/VBAMacroReader.java
@@ -17,6 +17,7 @@
package org.apache.poi.poifs.macros;
+import static org.apache.logging.log4j.util.Unbox.box;
import static org.apache.poi.util.StringUtil.endsWithIgnoreCase;
import static org.apache.poi.util.StringUtil.startsWithIgnoreCase;
@@ -37,6 +38,8 @@ import java.util.Map;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
import org.apache.poi.poifs.filesystem.DirectoryNode;
import org.apache.poi.poifs.filesystem.DocumentInputStream;
import org.apache.poi.poifs.filesystem.DocumentNode;
@@ -49,8 +52,6 @@ import org.apache.poi.util.CodePageUtil;
import org.apache.poi.util.HexDump;
import org.apache.poi.util.IOUtils;
import org.apache.poi.util.LittleEndian;
-import org.apache.poi.util.POILogFactory;
-import org.apache.poi.util.POILogger;
import org.apache.poi.util.RLEDecompressingInputStream;
import org.apache.poi.util.StringUtil;
@@ -68,7 +69,7 @@ import org.apache.poi.util.StringUtil;
* @since 3.15-beta2
*/
public class VBAMacroReader implements Closeable {
- private static final POILogger LOGGER = POILogFactory.getLogger(VBAMacroReader.class);
+ private static final Logger LOGGER = LogManager.getLogger(VBAMacroReader.class);
//arbitrary limit on size of strings to read, etc.
private static final int MAX_STRING_LENGTH = 20000;
@@ -663,9 +664,7 @@ public class VBAMacroReader implements Closeable {
}
}
- if (records >= maxNameRecords) {
- LOGGER.log(POILogger.WARN, "Hit max name records to read ("+maxNameRecords+"). Stopped early.");
- }
+ LOGGER.atWarn().log("Hit max name records to read (" + maxNameRecords + "). Stopped early.");
}
private static String readUnicode(InputStream is, int maxLength) throws IOException {
@@ -684,7 +683,7 @@ public class VBAMacroReader implements Closeable {
read += 2;
}
if (read >= maxLength) {
- LOGGER.log(POILogger.WARN, "stopped reading unicode name after "+read+" bytes");
+ LOGGER.atWarn().log("stopped reading unicode name after {} bytes", box(read));
}
return new String (bos.toByteArray(), StandardCharsets.UTF_16LE);
}
@@ -747,21 +746,21 @@ public class VBAMacroReader implements Closeable {
if (module != null) {
module.moduleType = ModuleType.Document;
} else {
- LOGGER.log(POILogger.WARN, "couldn't find module with name: "+mn);
+ LOGGER.atWarn().log("couldn't find module with name: {}", mn);
}
} else if ("Module".equals(tokens[0]) && tokens.length > 1) {
ModuleImpl module = getModule(tokens[1], moduleNameMap, modules);
if (module != null) {
module.moduleType = ModuleType.Module;
} else {
- LOGGER.log(POILogger.WARN, "couldn't find module with name: "+tokens[1]);
+ LOGGER.atWarn().log("couldn't find module with name: {}", tokens[1]);
}
} else if ("Class".equals(tokens[0]) && tokens.length > 1) {
ModuleImpl module = getModule(tokens[1], moduleNameMap, modules);
if (module != null) {
module.moduleType = ModuleType.Class;
} else {
- LOGGER.log(POILogger.WARN, "couldn't find module with name: "+tokens[1]);
+ LOGGER.atWarn().log("couldn't find module with name: {}", tokens[1]);
}
}
}
diff --git a/src/java/org/apache/poi/poifs/nio/FileBackedDataSource.java b/src/java/org/apache/poi/poifs/nio/FileBackedDataSource.java
index d74eb9d2b8..e3001f238f 100644
--- a/src/java/org/apache/poi/poifs/nio/FileBackedDataSource.java
+++ b/src/java/org/apache/poi/poifs/nio/FileBackedDataSource.java
@@ -29,15 +29,15 @@ import java.nio.channels.FileChannel;
import java.nio.channels.WritableByteChannel;
import java.util.IdentityHashMap;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
import org.apache.poi.util.IOUtils;
-import org.apache.poi.util.POILogFactory;
-import org.apache.poi.util.POILogger;
/**
* A POIFS {@link DataSource} backed by a File
*/
public class FileBackedDataSource extends DataSource implements Closeable {
- private static final POILogger LOG = POILogFactory.getLogger(FileBackedDataSource.class);
+ private static final Logger LOG = LogManager.getLogger(FileBackedDataSource.class);
private final FileChannel channel;
private Long channelSize;
@@ -195,10 +195,10 @@ public class FileBackedDataSource extends DataSource implements Closeable {
try {
CleanerUtil.getCleaner().freeBuffer(buffer);
} catch (IOException e) {
- LOG.log(POILogger.WARN, "Failed to unmap the buffer", e);
+ LOG.atWarn().withThrowable(e).log("Failed to unmap the buffer");
}
} else {
- LOG.log(POILogger.DEBUG, CleanerUtil.UNMAP_NOT_SUPPORTED_REASON);
+ LOG.atDebug().log(CleanerUtil.UNMAP_NOT_SUPPORTED_REASON);
}
}
}
diff --git a/src/java/org/apache/poi/poifs/property/PropertyTable.java b/src/java/org/apache/poi/poifs/property/PropertyTable.java
index e1f663cea6..596bea5070 100644
--- a/src/java/org/apache/poi/poifs/property/PropertyTable.java
+++ b/src/java/org/apache/poi/poifs/property/PropertyTable.java
@@ -24,6 +24,8 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Stack;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
import org.apache.poi.poifs.common.POIFSBigBlockSize;
import org.apache.poi.poifs.common.POIFSConstants;
import org.apache.poi.poifs.filesystem.BATManaged;
@@ -31,8 +33,8 @@ import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.poifs.filesystem.POIFSStream;
import org.apache.poi.poifs.storage.HeaderBlock;
import org.apache.poi.util.IOUtils;
-import org.apache.poi.util.POILogFactory;
-import org.apache.poi.util.POILogger;
+
+import static org.apache.logging.log4j.util.Unbox.box;
/**
* This class embodies the Property Table for a {@link POIFSFileSystem};
@@ -41,7 +43,7 @@ import org.apache.poi.util.POILogger;
* chain of blocks.
*/
public final class PropertyTable implements BATManaged {
- private static final POILogger LOG = POILogFactory.getLogger(PropertyTable.class);
+ private static final Logger LOG = LogManager.getLogger(PropertyTable.class);
//arbitrarily selected; may need to increase
private static final int MAX_RECORD_LENGTH = 100_000;
@@ -96,8 +98,7 @@ public final class PropertyTable implements BATManaged {
// Looks to be a truncated block
// This isn't allowed, but some third party created files
// sometimes do this, and we can normally read anyway
- LOG.log(POILogger.WARN, "Short Property Block, ", bb.remaining(),
- " bytes instead of the expected " + _bigBigBlockSize.getBigBlockSize());
+ LOG.atWarn().log("Short Property Block, {} bytes instead of the expected {}", box(bb.remaining()),box(_bigBigBlockSize.getBigBlockSize()));
toRead = bb.remaining();
}
@@ -247,8 +248,7 @@ public final class PropertyTable implements BATManaged {
if (! Property.isValidIndex(index))
return false;
if (index < 0 || index >= _properties.size()) {
- LOG.log(POILogger.WARN, "Property index " + index +
- "outside the valid range 0.."+_properties.size());
+ LOG.atWarn().log("Property index {} outside the valid range 0..{}", box(index),box(_properties.size()));
return false;
}
return true;
diff --git a/src/java/org/apache/poi/sl/draw/BitmapImageRenderer.java b/src/java/org/apache/poi/sl/draw/BitmapImageRenderer.java
index 21139719d9..96e63a6448 100644
--- a/src/java/org/apache/poi/sl/draw/BitmapImageRenderer.java
+++ b/src/java/org/apache/poi/sl/draw/BitmapImageRenderer.java
@@ -40,16 +40,16 @@ import javax.imageio.ImageTypeSpecifier;
import javax.imageio.stream.ImageInputStream;
import javax.imageio.stream.MemoryCacheImageInputStream;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
import org.apache.poi.sl.usermodel.PictureData.PictureType;
import org.apache.poi.util.IOUtils;
-import org.apache.poi.util.POILogFactory;
-import org.apache.poi.util.POILogger;
/**
* For now this class renders only images supported by the javax.imageio.ImageIO framework.
**/
public class BitmapImageRenderer implements ImageRenderer {
- private static final POILogger LOG = POILogFactory.getLogger(BitmapImageRenderer.class);
+ private static final Logger LOG = LogManager.getLogger(BitmapImageRenderer.class);
protected BufferedImage img;
@@ -200,7 +200,7 @@ public class BitmapImageRenderer implements ImageRenderer {
// multiple locations above ...
throw lastException;
}
- LOG.log(POILogger.WARN, "Content-type: "+contentType+" is not support. Image ignored.");
+ LOG.atWarn().log("Content-type: {} is not support. Image ignored.", contentType);
return null;
}
diff --git a/src/java/org/apache/poi/sl/draw/DrawPaint.java b/src/java/org/apache/poi/sl/draw/DrawPaint.java
index 157c4103e9..e78dd2ee14 100644
--- a/src/java/org/apache/poi/sl/draw/DrawPaint.java
+++ b/src/java/org/apache/poi/sl/draw/DrawPaint.java
@@ -46,6 +46,8 @@ import java.util.TreeMap;
import java.util.function.BiFunction;
import java.util.stream.Stream;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
import org.apache.poi.sl.usermodel.AbstractColorStyle;
import org.apache.poi.sl.usermodel.ColorStyle;
import org.apache.poi.sl.usermodel.Insets2D;
@@ -57,8 +59,6 @@ import org.apache.poi.sl.usermodel.PaintStyle.SolidPaint;
import org.apache.poi.sl.usermodel.PaintStyle.TexturePaint;
import org.apache.poi.sl.usermodel.PlaceableShape;
import org.apache.poi.util.Dimension2DDouble;
-import org.apache.poi.util.POILogFactory;
-import org.apache.poi.util.POILogger;
/**
@@ -69,7 +69,9 @@ import org.apache.poi.util.POILogger;
public class DrawPaint {
// HSL code is public domain - see https://tips4java.wordpress.com/contact-us/
- private static final POILogger LOG = POILogFactory.getLogger(DrawPaint.class);
+ // HSL code is public domain - see https://tips4java.wordpress.com/contact-us/
+
+ private static final Logger LOG = LogManager.getLogger(DrawPaint.class);
private static final Color TRANSPARENT = new Color(1f,1f,1f,0f);
@@ -286,7 +288,7 @@ public class DrawPaint {
BufferedImage image = renderer.getImage(imgDim);
if(image == null) {
- LOG.log(POILogger.ERROR, "Can't load image data");
+ LOG.atError().log("Can't load image data");
return TRANSPARENT;
}
@@ -336,7 +338,7 @@ public class DrawPaint {
// TODO: check why original bitmaps scale/behave differently to vector based images
return new DrawTexturePaint(image, s, fill, flipX, flipY, renderer instanceof BitmapImageRenderer);
} catch (IOException e) {
- LOG.log(POILogger.ERROR, "Can't load image data - using transparent color", e);
+ LOG.atError().withThrowable(e).log("Can't load image data - using transparent color");
return TRANSPARENT;
}
}
@@ -796,10 +798,10 @@ public class DrawPaint {
try {
graphics.fill(shape);
} catch (ArrayIndexOutOfBoundsException e) {
- LOG.log(POILogger.WARN, "IBM JDK failed with TexturePaintContext AIOOBE - try adding the following to the VM parameter:\n" +
+ LOG.atWarn().withThrowable(e).log("IBM JDK failed with TexturePaintContext AIOOBE - try adding the following to the VM parameter:\n" +
"-Xjit:exclude={sun/java2d/pipe/AlphaPaintPipe.renderPathTile(Ljava/lang/Object;[BIIIIII)V} and " +
"search for 'JIT Problem Determination for IBM SDK using -Xjit' (http://www-01.ibm.com/support/docview.wss?uid=swg21294023) " +
- "for how to add/determine further excludes", e);
+ "for how to add/determine further excludes");
}
}
}
diff --git a/src/java/org/apache/poi/sl/draw/DrawPictureShape.java b/src/java/org/apache/poi/sl/draw/DrawPictureShape.java
index 933211658a..71cb1bdd23 100644
--- a/src/java/org/apache/poi/sl/draw/DrawPictureShape.java
+++ b/src/java/org/apache/poi/sl/draw/DrawPictureShape.java
@@ -27,17 +27,17 @@ import java.util.ServiceLoader;
import java.util.function.Supplier;
import java.util.stream.StreamSupport;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
import org.apache.poi.common.usermodel.PictureType;
import org.apache.poi.poifs.filesystem.FileMagic;
import org.apache.poi.sl.usermodel.PictureData;
import org.apache.poi.sl.usermodel.PictureShape;
import org.apache.poi.sl.usermodel.RectAlign;
-import org.apache.poi.util.POILogFactory;
-import org.apache.poi.util.POILogger;
public class DrawPictureShape extends DrawSimpleShape {
- private static final POILogger LOG = POILogFactory.getLogger(DrawPictureShape.class);
+ private static final Logger LOG = LogManager.getLogger(DrawPictureShape.class);
public DrawPictureShape(PictureShape<?,?> shape) {
super(shape);
@@ -69,7 +69,7 @@ public class DrawPictureShape extends DrawSimpleShape {
return;
}
} catch (IOException e) {
- LOG.log(POILogger.ERROR, "image can't be loaded/rendered.", e);
+ LOG.atError().withThrowable(e).log("image can't be loaded/rendered.");
}
}
}
@@ -93,8 +93,8 @@ public class DrawPictureShape extends DrawSimpleShape {
// the fallback is the BitmapImageRenderer, at least it gracefully handles invalid images
final Supplier<ImageRenderer> getFallback = () -> {
- LOG.log(POILogger.WARN, "No suitable image renderer found for content-type '",
- contentType, "' - include poi-scratchpad (for wmf/emf) or poi-ooxml (for svg) jars!");
+ LOG.atWarn().log("No suitable image renderer found for content-type '{}' - include " +
+ "poi-scratchpad (for wmf/emf) or poi-ooxml (for svg) jars!", contentType);
return fallback;
};
diff --git a/src/java/org/apache/poi/sl/draw/DrawTextParagraph.java b/src/java/org/apache/poi/sl/draw/DrawTextParagraph.java
index e047b3468d..b49f7276b8 100644
--- a/src/java/org/apache/poi/sl/draw/DrawTextParagraph.java
+++ b/src/java/org/apache/poi/sl/draw/DrawTextParagraph.java
@@ -37,6 +37,8 @@ import java.util.List;
import java.util.Locale;
import java.util.Map;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
import org.apache.poi.common.usermodel.fonts.FontGroup;
import org.apache.poi.common.usermodel.fonts.FontGroup.FontGroupRange;
import org.apache.poi.common.usermodel.fonts.FontInfo;
@@ -57,12 +59,12 @@ import org.apache.poi.sl.usermodel.TextShape;
import org.apache.poi.sl.usermodel.TextShape.TextDirection;
import org.apache.poi.util.Internal;
import org.apache.poi.util.LocaleUtil;
-import org.apache.poi.util.POILogFactory;
-import org.apache.poi.util.POILogger;
import org.apache.poi.util.Units;
+import static org.apache.logging.log4j.util.Unbox.box;
+
public class DrawTextParagraph implements Drawable {
- private static final POILogger LOG = POILogFactory.getLogger(DrawTextParagraph.class);
+ private static final Logger LOG = LogManager.getLogger(DrawTextParagraph.class);
/** Keys for passing hyperlinks to the graphics context */
public static final XlinkAttribute HYPERLINK_HREF = new XlinkAttribute("href");
@@ -713,10 +715,12 @@ public class DrawTextParagraph implements Drawable {
if (partBegin < partEnd) {
// handle (b) and (c)
- attList.add(new AttributedStringData(TextAttribute.FAMILY, fontMapped.getFontName(Locale.ROOT), beginIndex+partBegin, beginIndex+partEnd));
- if (LOG.check(POILogger.DEBUG)) {
- LOG.log(POILogger.DEBUG, "mapped: ",fontMapped.getFontName(Locale.ROOT)," ",(beginIndex+partBegin)," ",(beginIndex+partEnd)," - ",runText.substring(partBegin, partEnd));
- }
+
+ final String fontName = fontMapped.getFontName(Locale.ROOT);
+ final int startIndex = beginIndex + partBegin;
+ final int endIndex = beginIndex + partEnd;
+ attList.add(new AttributedStringData(TextAttribute.FAMILY, fontName, startIndex, endIndex));
+ LOG.atDebug().log("mapped: {} {} {} - {}", fontName, box(startIndex),box(endIndex),runText.substring(partBegin, partEnd));
}
// fallback for unsupported glyphs
@@ -725,10 +729,11 @@ public class DrawTextParagraph implements Drawable {
if (partBegin < partEnd) {
// handle (a) and (b)
- attList.add(new AttributedStringData(TextAttribute.FAMILY, fontFallback.getFontName(Locale.ROOT), beginIndex+partBegin, beginIndex+partEnd));
- if (LOG.check(POILogger.DEBUG)) {
- LOG.log(POILogger.DEBUG, "fallback: ",fontFallback.getFontName(Locale.ROOT)," ",(beginIndex+partBegin)," ",(beginIndex+partEnd)," - ",runText.substring(partBegin, partEnd));
- }
+ final String fontName = fontFallback.getFontName(Locale.ROOT);
+ final int startIndex = beginIndex + partBegin;
+ final int endIndex = beginIndex + partEnd;
+ attList.add(new AttributedStringData(TextAttribute.FAMILY, fontName, startIndex, endIndex));
+ LOG.atDebug().log("fallback: {} {} {} - {}", fontName, box(startIndex),box(endIndex),runText.substring(partBegin, partEnd));
}
}
diff --git a/src/java/org/apache/poi/sl/draw/SLGraphics.java b/src/java/org/apache/poi/sl/draw/SLGraphics.java
index dfd74444cd..9d0398e585 100644
--- a/src/java/org/apache/poi/sl/draw/SLGraphics.java
+++ b/src/java/org/apache/poi/sl/draw/SLGraphics.java
@@ -18,22 +18,7 @@
package org.apache.poi.sl.draw;
-import java.awt.BasicStroke;
-import java.awt.Color;
-import java.awt.Composite;
-import java.awt.Font;
-import java.awt.FontMetrics;
-import java.awt.Graphics;
-import java.awt.Graphics2D;
-import java.awt.GraphicsConfiguration;
-import java.awt.GraphicsEnvironment;
-import java.awt.Image;
-import java.awt.Paint;
-import java.awt.Rectangle;
-import java.awt.RenderingHints;
-import java.awt.Shape;
-import java.awt.Stroke;
-import java.awt.Toolkit;
+import java.awt.*;
import java.awt.font.FontRenderContext;
import java.awt.font.GlyphVector;
import java.awt.font.TextLayout;
@@ -52,6 +37,8 @@ import java.awt.image.renderable.RenderableImage;
import java.text.AttributedCharacterIterator;
import java.util.Map;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
import org.apache.poi.sl.usermodel.FreeformShape;
import org.apache.poi.sl.usermodel.GroupShape;
import org.apache.poi.sl.usermodel.Insets2D;
@@ -61,8 +48,6 @@ import org.apache.poi.sl.usermodel.TextBox;
import org.apache.poi.sl.usermodel.TextRun;
import org.apache.poi.sl.usermodel.VerticalAlignment;
import org.apache.poi.util.NotImplemented;
-import org.apache.poi.util.POILogFactory;
-import org.apache.poi.util.POILogger;
import org.apache.poi.util.SuppressForbidden;
/**
@@ -70,7 +55,7 @@ import org.apache.poi.util.SuppressForbidden;
*/
public class SLGraphics extends Graphics2D implements Cloneable {
- private static final POILogger LOG = POILogFactory.getLogger(SLGraphics.class);
+ private static final Logger LOG = LogManager.getLogger(SLGraphics.class);
//The ppt object to write into.
private GroupShape<?,?> _group;
@@ -110,8 +95,8 @@ public class SLGraphics extends Graphics2D implements Cloneable {
/**
* Gets the current font.
* @return this graphics context's current font.
- * @see java.awt.Font
- * @see java.awt.Graphics#setFont(Font)
+ * @see Font
+ * @see Graphics#setFont(Font)
*/
public Font getFont(){
return _font;
@@ -122,10 +107,10 @@ public class SLGraphics extends Graphics2D implements Cloneable {
* All subsequent text operations using this graphics context
* use this font.
* @param font the font.
- * @see java.awt.Graphics#getFont
- * @see java.awt.Graphics#drawString(java.lang.String, int, int)
- * @see java.awt.Graphics#drawBytes(byte[], int, int, int, int)
- * @see java.awt.Graphics#drawChars(char[], int, int, int, int)
+ * @see Graphics#getFont
+ * @see Graphics#drawString(String, int, int)
+ * @see Graphics#drawBytes(byte[], int, int, int, int)
+ * @see Graphics#drawChars(char[], int, int, int, int)
*/
public void setFont(Font font){
this._font = font;
@@ -134,8 +119,8 @@ public class SLGraphics extends Graphics2D implements Cloneable {
/**
* Gets this graphics context's current color.
* @return this graphics context's current color.
- * @see java.awt.Color
- * @see java.awt.Graphics#setColor
+ * @see Color
+ * @see Graphics#setColor
*/
public Color getColor(){
return _foreground;
@@ -146,8 +131,8 @@ public class SLGraphics extends Graphics2D implements Cloneable {
* color. All subsequent graphics operations using this graphics
* context use this specified color.
* @param c the new rendering color.
- * @see java.awt.Color
- * @see java.awt.Graphics#getColor
+ * @see Color
+ * @see Graphics#getColor
*/
public void setColor(Color c) {
setPaint(c);
@@ -179,7 +164,7 @@ public class SLGraphics extends Graphics2D implements Cloneable {
* @return the current <code>Graphics2D</code> <code>Paint</code>,
* which defines a color or pattern.
* @see #setPaint
- * @see java.awt.Graphics#setColor
+ * @see Graphics#setColor
*/
public Paint getPaint(){
return _paint;
@@ -193,7 +178,7 @@ public class SLGraphics extends Graphics2D implements Cloneable {
* of this <code>Graphics2D</code>.
* @param paint the <code>Paint</code> object to be used to generate
* color during the rendering process, or <code>null</code>
- * @see java.awt.Graphics#setColor
+ * @see Graphics#setColor
*/
public void setPaint(Paint paint){
if(paint == null) return;
@@ -235,7 +220,7 @@ public class SLGraphics extends Graphics2D implements Cloneable {
* @param shape the <code>Shape</code> to be rendered
* @see #setStroke
* @see #setPaint
- * @see java.awt.Graphics#setColor
+ * @see Graphics#setColor
* @see #_transform
* @see #setTransform
* @see #clip
@@ -272,8 +257,8 @@ public class SLGraphics extends Graphics2D implements Cloneable {
* @throws NullPointerException if <code>str</code> is
* <code>null</code>
* @see #setPaint
- * @see java.awt.Graphics#setColor
- * @see java.awt.Graphics#setFont
+ * @see Graphics#setColor
+ * @see Graphics#setFont
* @see #setTransform
* @see #setComposite
* @see #setClip
@@ -332,7 +317,7 @@ public class SLGraphics extends Graphics2D implements Cloneable {
* <code>Paint</code>, and <code>Composite</code>.
* @param shape the <code>Shape</code> to be filled
* @see #setPaint
- * @see java.awt.Graphics#setColor
+ * @see Graphics#setColor
* @see #_transform
* @see #setTransform
* @see #setComposite
@@ -374,7 +359,7 @@ public class SLGraphics extends Graphics2D implements Cloneable {
* The <i>user clip</i> modified by this method is independent of the
* clipping associated with device bounds and visibility. If no clip has
* previously been set, or if the clip has been cleared using
- * {@link java.awt.Graphics#setClip(Shape) setClip} with a
+ * {@link Graphics#setClip(Shape) setClip} with a
* <code>null</code> argument, the specified <code>Shape</code> becomes
* the new user clip.
* @param s the <code>Shape</code> to be intersected with the current
@@ -396,10 +381,10 @@ public class SLGraphics extends Graphics2D implements Cloneable {
* @return a <code>Shape</code> object representing the
* current clipping area, or <code>null</code> if
* no clip is set.
- * @see java.awt.Graphics#getClipBounds()
- * @see java.awt.Graphics#clipRect
- * @see java.awt.Graphics#setClip(int, int, int, int)
- * @see java.awt.Graphics#setClip(Shape)
+ * @see Graphics#getClipBounds()
+ * @see Graphics#clipRect
+ * @see Graphics#setClip(int, int, int, int)
+ * @see Graphics#setClip(Shape)
* @since JDK1.1
*/
@NotImplemented
@@ -445,7 +430,7 @@ public class SLGraphics extends Graphics2D implements Cloneable {
* at the four corners.
* @param arcHeight the vertical diameter of the arc
* at the four corners.
- * @see java.awt.Graphics#fillRoundRect
+ * @see Graphics#fillRoundRect
*/
public void drawRoundRect(int x, int y, int width, int height,
int arcWidth, int arcHeight){
@@ -461,8 +446,8 @@ public class SLGraphics extends Graphics2D implements Cloneable {
* @param str the string to be drawn.
* @param x the <i>x</i> coordinate.
* @param y the <i>y</i> coordinate.
- * @see java.awt.Graphics#drawBytes
- * @see java.awt.Graphics#drawChars
+ * @see Graphics#drawBytes
+ * @see Graphics#drawChars
*/
public void drawString(String str, int x, int y){
drawString(str, (float)x, (float)y);
@@ -477,7 +462,7 @@ public class SLGraphics extends Graphics2D implements Cloneable {
* of the oval to be filled.
* @param width the width of the oval to be filled.
* @param height the height of the oval to be filled.
- * @see java.awt.Graphics#drawOval
+ * @see Graphics#drawOval
*/
public void fillOval(int x, int y, int width, int height){
Ellipse2D oval = new Ellipse2D.Double(x, y, width, height);
@@ -498,7 +483,7 @@ public class SLGraphics extends Graphics2D implements Cloneable {
* of the arc at the four corners.
* @param arcHeight the vertical diameter
* of the arc at the four corners.
- * @see java.awt.Graphics#drawRoundRect
+ * @see Graphics#drawRoundRect
*/
public void fillRoundRect(int x, int y, int width, int height,
int arcWidth, int arcHeight){
@@ -541,7 +526,7 @@ public class SLGraphics extends Graphics2D implements Cloneable {
* @param startAngle the beginning angle.
* @param arcAngle the angular extent of the arc,
* relative to the start angle.
- * @see java.awt.Graphics#drawArc
+ * @see Graphics#drawArc
*/
public void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle){
Arc2D arc = new Arc2D.Double(x, y, width, height, startAngle, arcAngle, Arc2D.PIE);
@@ -583,7 +568,7 @@ public class SLGraphics extends Graphics2D implements Cloneable {
* @param startAngle the beginning angle.
* @param arcAngle the angular extent of the arc,
* relative to the start angle.
- * @see java.awt.Graphics#fillArc
+ * @see Graphics#fillArc
*/
public void drawArc(int x, int y, int width, int height, int startAngle, int arcAngle) {
Arc2D arc = new Arc2D.Double(x, y, width, height, startAngle, arcAngle, Arc2D.OPEN);
@@ -600,7 +585,7 @@ public class SLGraphics extends Graphics2D implements Cloneable {
* @param xPoints an array of <i>x</i> points
* @param yPoints an array of <i>y</i> points
* @param nPoints the total number of points
- * @see java.awt.Graphics#drawPolygon(int[], int[], int)
+ * @see Graphics#drawPolygon(int[], int[], int)
* @since JDK1.1
*/
public void drawPolyline(int[] xPoints, int[] yPoints,
@@ -630,7 +615,7 @@ public class SLGraphics extends Graphics2D implements Cloneable {
* corner of the oval to be drawn.
* @param width the width of the oval to be drawn.
* @param height the height of the oval to be drawn.
- * @see java.awt.Graphics#fillOval
+ * @see Graphics#fillOval
*/
public void drawOval(int x, int y, int width, int height){
Ellipse2D oval = new Ellipse2D.Double(x, y, width, height);
@@ -663,9 +648,9 @@ public class SLGraphics extends Graphics2D implements Cloneable {
* non-opaque portions of the image.
* @param observer object to be notified as more of
* the image is converted.
- * @see java.awt.Image
- * @see java.awt.image.ImageObserver
- * @see java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int)
+ * @see Image
+ * @see ImageObserver
+ * @see ImageObserver#imageUpdate(Image, int, int, int, int, int)
*/
@NotImplemented
public boolean drawImage(Image img, int x, int y,
@@ -709,9 +694,9 @@ public class SLGraphics extends Graphics2D implements Cloneable {
* non-opaque portions of the image.
* @param observer object to be notified as more of
* the image is converted.
- * @see java.awt.Image
- * @see java.awt.image.ImageObserver
- * @see java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int)
+ * @see Image
+ * @see ImageObserver
+ * @see ImageObserver#imageUpdate(Image, int, int, int, int, int)
*/
@NotImplemented
public boolean drawImage(Image img, int x, int y,
@@ -765,9 +750,9 @@ public class SLGraphics extends Graphics2D implements Cloneable {
* source rectangle.
* @param observer object to be notified as more of the image is
* scaled and converted.
- * @see java.awt.Image
- * @see java.awt.image.ImageObserver
- * @see java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int)
+ * @see Image
+ * @see ImageObserver
+ * @see ImageObserver#imageUpdate(Image, int, int, int, int, int)
* @since JDK1.1
*/
@NotImplemented
@@ -827,9 +812,9 @@ public class SLGraphics extends Graphics2D implements Cloneable {
* non-opaque portions of the image.
* @param observer object to be notified as more of the image is
* scaled and converted.
- * @see java.awt.Image
- * @see java.awt.image.ImageObserver
- * @see java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int)
+ * @see Image
+ * @see ImageObserver
+ * @see ImageObserver#imageUpdate(Image, int, int, int, int, int)
* @since JDK1.1
*/
@NotImplemented
@@ -870,9 +855,9 @@ public class SLGraphics extends Graphics2D implements Cloneable {
* the image is converted.
* @return <code>false</code> if the image pixels are still changing;
* <code>true</code> otherwise.
- * @see java.awt.Image
- * @see java.awt.image.ImageObserver
- * @see java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int)
+ * @see Image
+ * @see ImageObserver
+ * @see ImageObserver#imageUpdate(Image, int, int, int, int, int)
*/
@NotImplemented
public boolean drawImage(Image img, int x, int y,
@@ -902,11 +887,11 @@ public class SLGraphics extends Graphics2D implements Cloneable {
* call <code>dispose</code> when finished using
* a <code>Graphics</code> object only if it was created
* directly from a component or another <code>Graphics</code> object.
- * @see java.awt.Graphics#finalize
- * @see java.awt.Component#paint
- * @see java.awt.Component#update
- * @see java.awt.Component#getGraphics
- * @see java.awt.Graphics#create
+ * @see Graphics#finalize
+ * @see Component#paint
+ * @see Component#update
+ * @see Component#getGraphics
+ * @see Graphics#create
*/
public void dispose() {
}
@@ -943,11 +928,11 @@ public class SLGraphics extends Graphics2D implements Cloneable {
* @param xPoints a an array of <code>x</code> coordinates.
* @param yPoints a an array of <code>y</code> coordinates.
* @param nPoints a the total number of points.
- * @see java.awt.Graphics#drawPolygon(int[], int[], int)
+ * @see Graphics#drawPolygon(int[], int[], int)
*/
public void fillPolygon(int[] xPoints, int[] yPoints,
int nPoints){
- java.awt.Polygon polygon = new java.awt.Polygon(xPoints, yPoints, nPoints);
+ Polygon polygon = new Polygon(xPoints, yPoints, nPoints);
fill(polygon);
}
@@ -967,8 +952,8 @@ public class SLGraphics extends Graphics2D implements Cloneable {
* of the rectangle to be filled.
* @param width the width of the rectangle to be filled.
* @param height the height of the rectangle to be filled.
- * @see java.awt.Graphics#clearRect
- * @see java.awt.Graphics#drawRect
+ * @see Graphics#clearRect
+ * @see Graphics#drawRect
*/
public void fillRect(int x, int y, int width, int height){
Rectangle rect = new Rectangle(x, y, width, height);
@@ -988,8 +973,8 @@ public class SLGraphics extends Graphics2D implements Cloneable {
* of the rectangle to be drawn.
* @param width the width of the rectangle to be drawn.
* @param height the height of the rectangle to be drawn.
- * @see java.awt.Graphics#fillRect
- * @see java.awt.Graphics#clearRect
+ * @see Graphics#fillRect
+ * @see Graphics#clearRect
*/
public void drawRect(int x, int y, int width, int height) {
Rectangle rect = new Rectangle(x, y, width, height);
@@ -1012,12 +997,12 @@ public class SLGraphics extends Graphics2D implements Cloneable {
* @param xPoints a an array of <code>x</code> coordinates.
* @param yPoints a an array of <code>y</code> coordinates.
* @param nPoints a the total number of points.
- * @see java.awt.Graphics#fillPolygon(int[],int[],int)
- * @see java.awt.Graphics#drawPolyline
+ * @see Graphics#fillPolygon(int[],int[],int)
+ * @see Graphics#drawPolyline
*/
public void drawPolygon(int[] xPoints, int[] yPoints,
int nPoints){
- java.awt.Polygon polygon = new java.awt.Polygon(xPoints, yPoints, nPoints);
+ Polygon polygon = new Polygon(xPoints, yPoints, nPoints);
draw(polygon);
}
@@ -1055,9 +1040,9 @@ public class SLGraphics extends Graphics2D implements Cloneable {
* user clip, which is independent of the clipping associated
* with device bounds and window visibility.
* @param clip the <code>Shape</code> to use to set the clip
- * @see java.awt.Graphics#getClip()
- * @see java.awt.Graphics#clipRect
- * @see java.awt.Graphics#setClip(int, int, int, int)
+ * @see Graphics#getClip()
+ * @see Graphics#clipRect
+ * @see Graphics#setClip(int, int, int, int)
* @since JDK1.1
*/
@NotImplemented
@@ -1076,10 +1061,10 @@ public class SLGraphics extends Graphics2D implements Cloneable {
* system origin of this graphics context.
* @return the bounding rectangle of the current clipping area,
* or <code>null</code> if no clip is set.
- * @see java.awt.Graphics#getClip
- * @see java.awt.Graphics#clipRect
- * @see java.awt.Graphics#setClip(int, int, int, int)
- * @see java.awt.Graphics#setClip(Shape)
+ * @see Graphics#getClip
+ * @see Graphics#clipRect
+ * @see Graphics#setClip(int, int, int, int)
+ * @see Graphics#setClip(Shape)
* @since JDK1.1
*/
public Rectangle getClipBounds(){
@@ -1096,8 +1081,8 @@ public class SLGraphics extends Graphics2D implements Cloneable {
* @param iterator the iterator whose text is to be drawn
* @param x the <i>x</i> coordinate.
* @param y the <i>y</i> coordinate.
- * @see java.awt.Graphics#drawBytes
- * @see java.awt.Graphics#drawChars
+ * @see Graphics#drawBytes
+ * @see Graphics#drawChars
*/
public void drawString(AttributedCharacterIterator iterator,
int x, int y){
@@ -1117,11 +1102,11 @@ public class SLGraphics extends Graphics2D implements Cloneable {
* @param y the <i>y</i> coordinate of the rectangle to clear.
* @param width the width of the rectangle to clear.
* @param height the height of the rectangle to clear.
- * @see java.awt.Graphics#fillRect(int, int, int, int)
- * @see java.awt.Graphics#drawRect
- * @see java.awt.Graphics#setColor(java.awt.Color)
- * @see java.awt.Graphics#setPaintMode
- * @see java.awt.Graphics#setXORMode(java.awt.Color)
+ * @see Graphics#fillRect(int, int, int, int)
+ * @see Graphics#drawRect
+ * @see Graphics#setColor(Color)
+ * @see Graphics#setPaintMode
+ * @see Graphics#setXORMode(Color)
*/
public void clearRect(int x, int y, int width, int height) {
Paint paint = getPaint();
@@ -1143,8 +1128,8 @@ public class SLGraphics extends Graphics2D implements Cloneable {
* @param y the <i>y</i> coordinate of the new clip rectangle.
* @param width the width of the new clip rectangle.
* @param height the height of the new clip rectangle.
- * @see java.awt.Graphics#clipRect
- * @see java.awt.Graphics#setClip(Shape)
+ * @see Graphics#clipRect
+ * @see Graphics#setClip(Shape)
* @since JDK1.1
*/
public void setClip(int x, int y, int width, int height){
@@ -1232,9 +1217,9 @@ public class SLGraphics extends Graphics2D implements Cloneable {
* the text rendering.
*
* @return a reference to an instance of FontRenderContext.
- * @see java.awt.font.FontRenderContext
- * @see java.awt.Font#createGlyphVector(FontRenderContext,char[])
- * @see java.awt.font.TextLayout
+ * @see FontRenderContext
+ * @see Font#createGlyphVector(FontRenderContext,char[])
+ * @see TextLayout
* @since JDK1.2
*/
public FontRenderContext getFontRenderContext() {
@@ -1311,7 +1296,7 @@ public class SLGraphics extends Graphics2D implements Cloneable {
* @param color the background color that isused in
* subsequent calls to <code>clearRect</code>
* @see #getBackground
- * @see java.awt.Graphics#clearRect
+ * @see Graphics#clearRect
*/
public void setBackground(Color color) {
if(color == null)
@@ -1351,9 +1336,9 @@ public class SLGraphics extends Graphics2D implements Cloneable {
* used to render to the screen and a security manager
* is set and its <code>checkPermission</code> method
* does not allow the operation.
- * @see java.awt.Graphics#setXORMode
- * @see java.awt.Graphics#setPaintMode
- * @see java.awt.AlphaComposite
+ * @see Graphics#setXORMode
+ * @see Graphics#setPaintMode
+ * @see AlphaComposite
*/
@NotImplemented
public void setComposite(Composite comp){
@@ -1423,10 +1408,10 @@ public class SLGraphics extends Graphics2D implements Cloneable {
* @param y the y position in user space where the glyphs should be
* rendered
*
- * @see java.awt.Font#createGlyphVector(FontRenderContext, char[])
- * @see java.awt.font.GlyphVector
+ * @see Font#createGlyphVector(FontRenderContext, char[])
+ * @see GlyphVector
* @see #setPaint
- * @see java.awt.Graphics#setColor
+ * @see Graphics#setColor
* @see #setTransform
* @see #setComposite
* @see #setClip(Shape)
@@ -1504,7 +1489,7 @@ public class SLGraphics extends Graphics2D implements Cloneable {
* @param y the y coordinate where the iterator's text is to be
* rendered
* @see #setPaint
- * @see java.awt.Graphics#setColor
+ * @see Graphics#setColor
* @see #setTransform
* @see #setComposite
* @see #setClip
@@ -1652,9 +1637,9 @@ public class SLGraphics extends Graphics2D implements Cloneable {
* the image is converted.
* @return <code>false</code> if the image pixels are still changing;
* <code>true</code> otherwise.
- * @see java.awt.Image
- * @see java.awt.image.ImageObserver
- * @see java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int)
+ * @see Image
+ * @see ImageObserver
+ * @see ImageObserver#imageUpdate(Image, int, int, int, int, int)
*/
@NotImplemented
public boolean drawImage(Image img, int x, int y,
@@ -1682,9 +1667,9 @@ public class SLGraphics extends Graphics2D implements Cloneable {
* Gets the font metrics for the specified font.
* @return the font metrics for the specified font.
* @param f the specified font
- * @see java.awt.Graphics#getFont
- * @see java.awt.FontMetrics
- * @see java.awt.Graphics#getFontMetrics()
+ * @see Graphics#getFont
+ * @see FontMetrics
+ * @see Graphics#getFontMetrics()
*/
@SuppressWarnings("deprecation")
@SuppressForbidden
@@ -1805,8 +1790,6 @@ public class SLGraphics extends Graphics2D implements Cloneable {
}
private void logNotImplemented() {
- if (LOG.check(POILogger.WARN)) {
- LOG.log(POILogger.WARN, "Not implemented");
- }
+ LOG.atWarn().log("Not implemented");
}
}
diff --git a/src/java/org/apache/poi/sl/draw/geom/PresetGeometries.java b/src/java/org/apache/poi/sl/draw/geom/PresetGeometries.java
index 13e3992fd6..acde02c945 100644
--- a/src/java/org/apache/poi/sl/draw/geom/PresetGeometries.java
+++ b/src/java/org/apache/poi/sl/draw/geom/PresetGeometries.java
@@ -31,12 +31,12 @@ import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import javax.xml.transform.stream.StreamSource;
-import org.apache.poi.util.POILogFactory;
-import org.apache.poi.util.POILogger;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
import org.apache.poi.util.XMLHelper;
public final class PresetGeometries {
- private static final POILogger LOG = POILogFactory.getLogger(PresetGeometries.class);
+ private static final Logger LOG = LogManager.getLogger(PresetGeometries.class);
private final Map<String, CustomGeometry> map = new TreeMap<>();
@@ -76,7 +76,7 @@ public final class PresetGeometries {
p.parse(staxReader);
return p.getGeom().values().stream().findFirst().orElse(null);
} catch (XMLStreamException e) {
- LOG.log(POILogger.ERROR, "Unable to parse single custom geometry", e);
+ LOG.atError().withThrowable(e).log("Unable to parse single custom geometry");
return null;
}
}
diff --git a/src/java/org/apache/poi/sl/draw/geom/PresetParser.java b/src/java/org/apache/poi/sl/draw/geom/PresetParser.java
index 9cfa06b661..998b0ee776 100644
--- a/src/java/org/apache/poi/sl/draw/geom/PresetParser.java
+++ b/src/java/org/apache/poi/sl/draw/geom/PresetParser.java
@@ -27,10 +27,10 @@ import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
import org.apache.poi.sl.usermodel.PaintStyle.PaintModifier;
import org.apache.poi.util.Internal;
-import org.apache.poi.util.POILogFactory;
-import org.apache.poi.util.POILogger;
@Internal
class PresetParser {
@@ -55,7 +55,7 @@ class PresetParser {
}
}
- private static final POILogger LOG = POILogFactory.getLogger(PresetParser.class);
+ private static final Logger LOG = LogManager.getLogger(PresetParser.class);
private Mode mode;
@@ -104,7 +104,7 @@ class PresetParser {
final String name = sr.getLocalName();
customGeometry = new CustomGeometry();
if (geom.containsKey(name)) {
- LOG.log(POILogger.WARN, "Duplicate definition of " + name);
+ LOG.atWarn().log("Duplicate definition of {}", name);
}
geom.put(name, customGeometry);
mode = Mode.SHAPE;
diff --git a/src/java/org/apache/poi/sl/extractor/SlideShowExtractor.java b/src/java/org/apache/poi/sl/extractor/SlideShowExtractor.java
index fa454501d6..fabab5a7a1 100644
--- a/src/java/org/apache/poi/sl/extractor/SlideShowExtractor.java
+++ b/src/java/org/apache/poi/sl/extractor/SlideShowExtractor.java
@@ -26,6 +26,8 @@ import java.util.function.Function;
import java.util.function.Predicate;
import com.zaxxer.sparsebits.SparseBitSet;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
import org.apache.poi.extractor.POITextExtractor;
import org.apache.poi.sl.usermodel.MasterSheet;
import org.apache.poi.sl.usermodel.Notes;
@@ -43,8 +45,6 @@ import org.apache.poi.sl.usermodel.TextParagraph;
import org.apache.poi.sl.usermodel.TextRun;
import org.apache.poi.sl.usermodel.TextShape;
import org.apache.poi.util.LocaleUtil;
-import org.apache.poi.util.POILogFactory;
-import org.apache.poi.util.POILogger;
/**
* Common SlideShow extractor
@@ -55,7 +55,7 @@ public class SlideShowExtractor<
S extends Shape<S,P>,
P extends TextParagraph<S,P,? extends TextRun>
> implements POITextExtractor {
- private static final POILogger LOG = POILogFactory.getLogger(SlideShowExtractor.class);
+ private static final Logger LOG = LogManager.getLogger(SlideShowExtractor.class);
// placeholder text for slide numbers
private static final String SLIDE_NUMBER_PH = "‹#›";
@@ -178,7 +178,7 @@ public class SlideShowExtractor<
if (ts.isPlaceholder()) {
// don't bother about boiler plate text on master sheets
- LOG.log(POILogger.INFO, "Ignoring boiler plate (placeholder) text on slide master:", text);
+ LOG.atInfo().log("Ignoring boiler plate (placeholder) text on slide master: {}", text);
continue;
}
diff --git a/src/java/org/apache/poi/sl/image/ImageHeaderBitmap.java b/src/java/org/apache/poi/sl/image/ImageHeaderBitmap.java
index c6283b6759..b7d0a3c4ec 100644
--- a/src/java/org/apache/poi/sl/image/ImageHeaderBitmap.java
+++ b/src/java/org/apache/poi/sl/image/ImageHeaderBitmap.java
@@ -24,15 +24,15 @@ import java.io.IOException;
import javax.imageio.ImageIO;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
import org.apache.poi.util.Internal;
-import org.apache.poi.util.POILogFactory;
-import org.apache.poi.util.POILogger;
import org.apache.poi.util.Units;
@Internal
public class ImageHeaderBitmap {
- private static final POILogger LOG = POILogFactory.getLogger(ImageHeaderBitmap.class);
-
+ private static final Logger LOG = LogManager.getLogger(ImageHeaderBitmap.class);
+
private final Dimension size;
public ImageHeaderBitmap(byte[] data, int offset) {
@@ -40,7 +40,7 @@ public class ImageHeaderBitmap {
try {
img = ImageIO.read(new ByteArrayInputStream(data, offset, data.length-offset));
} catch (IOException e) {
- LOG.log(POILogger.WARN, "Can't determine image dimensions", e);
+ LOG.atWarn().withThrowable(e).log("Can't determine image dimensions");
}
// set dummy size, in case of dummy dimension can't be set
size = (img == null)
diff --git a/src/java/org/apache/poi/sl/image/ImageHeaderEMF.java b/src/java/org/apache/poi/sl/image/ImageHeaderEMF.java
index 48bf45564b..6dd5faf440 100644
--- a/src/java/org/apache/poi/sl/image/ImageHeaderEMF.java
+++ b/src/java/org/apache/poi/sl/image/ImageHeaderEMF.java
@@ -20,15 +20,15 @@ package org.apache.poi.sl.image;
import java.awt.Dimension;
import java.awt.Rectangle;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
import org.apache.poi.util.Internal;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.LocaleUtil;
-import org.apache.poi.util.POILogFactory;
-import org.apache.poi.util.POILogger;
@Internal
public class ImageHeaderEMF {
- private static final POILogger LOG = POILogFactory.getLogger(ImageHeaderEMF.class);
+ private static final Logger LOG = LogManager.getLogger(ImageHeaderEMF.class);
private static final String EMF_SIGNATURE = " EMF"; // 0x464D4520 (LE)
@@ -40,7 +40,7 @@ public class ImageHeaderEMF {
int offset = off;
int type = (int)LittleEndian.getUInt(data, offset); offset += 4;
if (type != 1) {
- LOG.log(POILogger.WARN, "Invalid EMF picture - invalid type");
+ LOG.atWarn().log("Invalid EMF picture - invalid type");
deviceBounds = new Rectangle(0,0,200,200);
return;
}
@@ -55,7 +55,7 @@ public class ImageHeaderEMF {
offset += 16;
String signature = new String(data, offset, EMF_SIGNATURE.length(), LocaleUtil.CHARSET_1252);
if (!EMF_SIGNATURE.equals(signature)) {
- LOG.log(POILogger.WARN, "Invalid EMF picture - invalid signature");
+ LOG.atWarn().log("Invalid EMF picture - invalid signature");
}
}
diff --git a/src/java/org/apache/poi/sl/image/ImageHeaderWMF.java b/src/java/org/apache/poi/sl/image/ImageHeaderWMF.java
index d210bc5429..cf2f75867f 100644
--- a/src/java/org/apache/poi/sl/image/ImageHeaderWMF.java
+++ b/src/java/org/apache/poi/sl/image/ImageHeaderWMF.java
@@ -22,11 +22,11 @@ import java.awt.Rectangle;
import java.io.IOException;
import java.io.OutputStream;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
import org.apache.poi.util.Internal;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.LittleEndianConsts;
-import org.apache.poi.util.POILogFactory;
-import org.apache.poi.util.POILogger;
import org.apache.poi.util.Units;
/**
@@ -47,7 +47,7 @@ import org.apache.poi.util.Units;
public class ImageHeaderWMF {
public static final int APMHEADER_KEY = 0x9AC6CDD7;
- private static final POILogger LOG = POILogFactory.getLogger(ImageHeaderWMF.class);
+ private static final Logger LOG = LogManager.getLogger(ImageHeaderWMF.class);
@SuppressWarnings("unused")
private final int handle;
@@ -80,7 +80,7 @@ public class ImageHeaderWMF {
int offset = off;
int key = LittleEndian.getInt(data, offset); offset += LittleEndianConsts.INT_SIZE; //header key
if (key != APMHEADER_KEY) {
- LOG.log(POILogger.WARN, "WMF file doesn't contain a placeable header - ignore parsing");
+ LOG.atWarn().log("WMF file doesn't contain a placeable header - ignore parsing");
handle = 0;
left = 0;
top = 0;
@@ -102,7 +102,7 @@ public class ImageHeaderWMF {
checksum = LittleEndian.getShort(data, offset); offset += LittleEndianConsts.SHORT_SIZE;
if (checksum != getChecksum()){
- LOG.log(POILogger.WARN, "WMF checksum does not match the header data");
+ LOG.atWarn().log("WMF checksum does not match the header data");
}
}
diff --git a/src/java/org/apache/poi/sl/usermodel/ObjectData.java b/src/java/org/apache/poi/sl/usermodel/ObjectData.java
index db30a9b245..11a94281ed 100644
--- a/src/java/org/apache/poi/sl/usermodel/ObjectData.java
+++ b/src/java/org/apache/poi/sl/usermodel/ObjectData.java
@@ -21,12 +21,12 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
import org.apache.poi.poifs.filesystem.DirectoryEntry;
import org.apache.poi.poifs.filesystem.FileMagic;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.util.IOUtils;
-import org.apache.poi.util.POILogFactory;
-import org.apache.poi.util.POILogger;
/**
* Common interface for OLE shapes, i.e. shapes linked to embedded documents
@@ -68,8 +68,8 @@ public interface ObjectData {
FileMagic fm = FileMagic.valueOf(is);
return fm == FileMagic.OLE2;
} catch (IOException e) {
- POILogger LOG = POILogFactory.getLogger(ObjectData.class);
- LOG.log(POILogger.WARN, "Can't determine filemagic of ole stream", e);
+ Logger LOG = LogManager.getLogger(ObjectData.class);
+ LOG.atWarn().withThrowable(e).log("Can't determine filemagic of ole stream");
return false;
}
}
diff --git a/src/java/org/apache/poi/ss/extractor/EmbeddedExtractor.java b/src/java/org/apache/poi/ss/extractor/EmbeddedExtractor.java
index 153733f5a1..dbce0249ea 100644
--- a/src/java/org/apache/poi/ss/extractor/EmbeddedExtractor.java
+++ b/src/java/org/apache/poi/ss/extractor/EmbeddedExtractor.java
@@ -28,6 +28,8 @@ import java.util.Collections;
import java.util.Iterator;
import java.util.List;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
import org.apache.poi.hpsf.ClassID;
import org.apache.poi.hpsf.ClassIDPredefined;
import org.apache.poi.poifs.filesystem.DirectoryNode;
@@ -47,8 +49,6 @@ import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.util.Beta;
import org.apache.poi.util.IOUtils;
import org.apache.poi.util.LocaleUtil;
-import org.apache.poi.util.POILogFactory;
-import org.apache.poi.util.POILogger;
/**
* This extractor class tries to identify various embedded documents within Excel files
@@ -56,7 +56,7 @@ import org.apache.poi.util.POILogger;
*/
@Beta
public class EmbeddedExtractor implements Iterable<EmbeddedExtractor> {
- private static final POILogger LOG = POILogFactory.getLogger(EmbeddedExtractor.class);
+ private static final Logger LOG = LogManager.getLogger(EmbeddedExtractor.class);
//arbitrarily selected; may need to increase
private static final int MAX_RECORD_LENGTH = 1_000_000;
@@ -117,7 +117,7 @@ public class EmbeddedExtractor implements Iterable<EmbeddedExtractor> {
data = new EmbeddedData(od.getFileName(), od.getObjectData(), od.getContentType());
}
} catch (Exception e) {
- LOG.log(POILogger.WARN, "Entry not found / readable - ignoring OLE embedding", e);
+ LOG.atWarn().withThrowable(e).log("Entry not found / readable - ignoring OLE embedding");
}
} else if (shape instanceof Picture) {
data = extractOne((Picture)shape);
diff --git a/src/java/org/apache/poi/ss/format/CellNumberFormatter.java b/src/java/org/apache/poi/ss/format/CellNumberFormatter.java
index 901a65c2f9..f25965af75 100644
--- a/src/java/org/apache/poi/ss/format/CellNumberFormatter.java
+++ b/src/java/org/apache/poi/ss/format/CellNumberFormatter.java
@@ -32,15 +32,15 @@ import java.util.Set;
import java.util.TreeSet;
import com.zaxxer.sparsebits.SparseBitSet;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
import org.apache.poi.util.LocaleUtil;
-import org.apache.poi.util.POILogFactory;
-import org.apache.poi.util.POILogger;
/**
* This class implements printing out a value using a number format.
*/
public class CellNumberFormatter extends CellFormatter {
- private static final POILogger LOG = POILogFactory.getLogger(CellNumberFormatter.class);
+ private static final Logger LOG = LogManager.getLogger(CellNumberFormatter.class);
private final String desc;
private final String printfFmt;
@@ -695,8 +695,8 @@ public class CellNumberFormatter extends CellFormatter {
}
writeSingleInteger(numeratorFmt, n, output, numeratorSpecials, mods);
writeSingleInteger(denominatorFmt, d, output, denominatorSpecials, mods);
- } catch (RuntimeException ignored) {
- LOG.log(POILogger.ERROR, "error while fraction evaluation", ignored);
+ } catch (RuntimeException e) {
+ LOG.atError().withThrowable(e).log("error while fraction evaluation");
}
}
diff --git a/src/java/org/apache/poi/ss/formula/FormulaParser.java b/src/java/org/apache/poi/ss/formula/FormulaParser.java
index b7cab41459..a05166e29e 100644
--- a/src/java/org/apache/poi/ss/formula/FormulaParser.java
+++ b/src/java/org/apache/poi/ss/formula/FormulaParser.java
@@ -22,6 +22,10 @@ import java.util.List;
import java.util.Locale;
import java.util.regex.Pattern;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.SpreadsheetVersion;
import org.apache.poi.ss.formula.constant.ErrorConstant;
import org.apache.poi.ss.formula.function.FunctionMetadata;
@@ -71,12 +75,11 @@ import org.apache.poi.ss.formula.ptg.ValueOperatorPtg;
import org.apache.poi.ss.usermodel.FormulaError;
import org.apache.poi.ss.usermodel.Name;
import org.apache.poi.ss.usermodel.Table;
+import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.util.AreaReference;
import org.apache.poi.ss.util.CellReference;
import org.apache.poi.ss.util.CellReference.NameType;
import org.apache.poi.util.Internal;
-import org.apache.poi.util.POILogFactory;
-import org.apache.poi.util.POILogger;
/**
* This class parses a formula string into a List of tokens in RPN order.
@@ -93,7 +96,7 @@ import org.apache.poi.util.POILogger;
*/
@Internal
public final class FormulaParser {
- private static final POILogger log = POILogFactory.getLogger(FormulaParser.class);
+ private static final Logger LOGGER = LogManager.getLogger(FormulaParser.class);
private final String _formulaString;
private final int _formulaLength;
/** points at the next character to be read (after the {@link #look} codepoint) */
@@ -132,9 +135,9 @@ public final class FormulaParser {
* parse results.
* This class is recommended only for single threaded use.
*
- * If you have a {@link org.apache.poi.hssf.usermodel.HSSFWorkbook}, and not a
- * {@link org.apache.poi.ss.usermodel.Workbook}, then use the convenience method on
- * {@link org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator}
+ * If you have a {@link HSSFWorkbook}, and not a
+ * {@link Workbook}, then use the convenience method on
+ * {@link HSSFFormulaEvaluator}
*/
private FormulaParser(String formula, FormulaParsingWorkbook book, int sheetIndex, int rowIndex) {
_formulaString = formula;
@@ -148,7 +151,7 @@ public final class FormulaParser {
/**
* Parse a formula into an array of tokens
- * Side effect: creates name ({@link org.apache.poi.ss.usermodel.Workbook#createName})
+ * Side effect: creates name ({@link Workbook#createName})
* if formula contains unrecognized names (names are likely UDFs)
*
* @param formula the formula to parse
@@ -173,7 +176,7 @@ public final class FormulaParser {
/**
* Parse a formula into an array of tokens
- * Side effect: creates name ({@link org.apache.poi.ss.usermodel.Workbook#createName})
+ * Side effect: creates name ({@link Workbook#createName})
* if formula contains unrecognized names (names are likely UDFs)
*
* @param formula the formula to parse
@@ -1012,7 +1015,7 @@ public final class FormulaParser {
/**
* Matches a zero or one letter-runs followed by zero or one digit-runs.
* Either or both runs man optionally be prefixed with a single '$'.
- * (copied+modified from {@link org.apache.poi.ss.util.CellReference#CELL_REF_PATTERN})
+ * (copied+modified from {@link CellReference#CELL_REF_PATTERN})
*/
private static final Pattern CELL_REF_PATTERN = Pattern.compile("(\\$?[A-Za-z]+)?(\\$?[0-9]+)?");
@@ -1325,10 +1328,7 @@ public final class FormulaParser {
nameToken = _book.getNameXPtg(name, null);
if (nameToken == null) {
// name is not an internal or external name
- if (log.check(POILogger.WARN)) {
- log.log(POILogger.WARN,
- "FormulaParser.function: Name '" + name + "' is completely unknown in the current workbook.");
- }
+ LOGGER.atWarn().log("FormulaParser.function: Name '{}' is completely unknown in the current workbook.", name);
// name is probably the name of an unregistered User-Defined Function
switch (_book.getSpreadsheetVersion()) {
case EXCEL97:
diff --git a/src/java/org/apache/poi/ss/formula/WorkbookEvaluator.java b/src/java/org/apache/poi/ss/formula/WorkbookEvaluator.java
index fa8dec334b..8cb4cbf26b 100644
--- a/src/java/org/apache/poi/ss/formula/WorkbookEvaluator.java
+++ b/src/java/org/apache/poi/ss/formula/WorkbookEvaluator.java
@@ -25,6 +25,9 @@ import java.util.Map;
import java.util.Stack;
import java.util.TreeSet;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.message.SimpleMessage;
import org.apache.poi.ss.SpreadsheetVersion;
import org.apache.poi.ss.formula.CollaboratingWorkbooksEnvironment.WorkbookNotFoundException;
import org.apache.poi.ss.formula.atp.AnalysisToolPak;
@@ -38,8 +41,9 @@ import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.util.CellRangeAddressBase;
import org.apache.poi.ss.util.CellReference;
import org.apache.poi.util.Internal;
-import org.apache.poi.util.POILogFactory;
-import org.apache.poi.util.POILogger;
+
+import static org.apache.logging.log4j.util.Unbox.box;
+
/**
* Evaluates formula cells.<p/>
*
@@ -55,7 +59,7 @@ import org.apache.poi.util.POILogger;
@Internal
public final class WorkbookEvaluator {
- private static final POILogger LOG = POILogFactory.getLogger(WorkbookEvaluator.class);
+ private static final Logger LOG = LogManager.getLogger(WorkbookEvaluator.class);
private final EvaluationWorkbook _workbook;
private EvaluationCache _cache;
@@ -77,7 +81,7 @@ public final class WorkbookEvaluator {
private boolean dbgEvaluationOutputForNextEval;
// special logger for formula evaluation output (because of possibly very large output)
- private final POILogger EVAL_LOG = POILogFactory.getLogger("POI.FormulaEval");
+ private final Logger EVAL_LOG = LogManager.getLogger("POI.FormulaEval");
// current indent level for evalution; negative value for no output
private int dbgEvaluationOutputIndent = -1;
@@ -125,22 +129,6 @@ public final class WorkbookEvaluator {
return _workbook.getName(name, sheetIndex);
}
- private static boolean isDebugLogEnabled() {
- return LOG.check(POILogger.DEBUG);
- }
- private static boolean isInfoLogEnabled() {
- return LOG.check(POILogger.INFO);
- }
- private static void logDebug(String s) {
- if (isDebugLogEnabled()) {
- LOG.log(POILogger.DEBUG, s);
- }
- }
- private static void logInfo(String s) {
- if (isInfoLogEnabled()) {
- LOG.log(POILogger.INFO, s);
- }
- }
/* package */ void attachToEnvironment(CollaboratingWorkbooksEnvironment collaboratingWorkbooksEnvironment, EvaluationCache cache, int workbookIx) {
_collaboratingWorkbookEnvironment = collaboratingWorkbooksEnvironment;
_cache = cache;
@@ -285,7 +273,7 @@ public final class WorkbookEvaluator {
throw addExceptionInfo(e, sheetIndex, rowIndex, columnIndex);
} catch (RuntimeException re) {
if (re.getCause() instanceof WorkbookNotFoundException && _ignoreMissingWorkbooks) {
- logInfo(re.getCause().getMessage() + " - Continuing with cached value!");
+ LOG.atInfo().log("{} - Continuing with cached value!", re.getCause().getMessage());
switch(srcCell.getCachedFormulaResultType()) {
case NUMERIC:
result = new NumberEval(srcCell.getNumericCellValue());
@@ -318,11 +306,12 @@ public final class WorkbookEvaluator {
}
return cce.getValue();
}
- if (isDebugLogEnabled()) {
+ final ValueEval resultForLogging = result;
+ LOG.atDebug().log(()->{
String sheetName = getSheetName(sheetIndex);
CellReference cr = new CellReference(rowIndex, columnIndex);
- logDebug("Evaluated " + sheetName + "!" + cr.formatAsString() + " to " + result);
- }
+ return new SimpleMessage("Evaluated " + sheetName + "!" + cr.formatAsString() + " to " + resultForLogging);
+ });
// Usually (result === cce.getValue())
// But sometimes: (result==ErrorEval.CIRCULAR_REF_ERROR, cce.getValue()==null)
// When circular references are detected, the cache entry is only updated for
@@ -344,7 +333,7 @@ public final class WorkbookEvaluator {
return new NotImplementedException(msg, inner);
} catch (Exception e) {
// avoid bombing out during exception handling
- LOG.log(POILogger.ERROR, "Can't add exception info", e);
+ LOG.atError().withThrowable(e).log("Can't add exception info");
return inner; // preserve original exception
}
}
@@ -387,14 +376,18 @@ public final class WorkbookEvaluator {
dbgEvaluationOutputForNextEval = false;
}
if (dbgEvaluationOutputIndent > 0) {
- // init. indent string to needed spaces (create as substring vom very long space-only string;
- // limit indendation for deep recursions)
+ // init. indent string to needed spaces (create as substring from very long space-only string;
+ // limit indentation for deep recursions)
dbgIndentStr = " ";
dbgIndentStr = dbgIndentStr.substring(0, Math.min(dbgIndentStr.length(), dbgEvaluationOutputIndent*2));
- EVAL_LOG.log(POILogger.WARN, dbgIndentStr
- + "- evaluateFormula('" + ec.getRefEvaluatorForCurrentSheet().getSheetNameRange()
- + "'/" + new CellReference(ec.getRowIndex(), ec.getColumnIndex()).formatAsString()
- + "): " + Arrays.toString(ptgs).replaceAll("\\Qorg.apache.poi.ss.formula.ptg.\\E", ""));
+ String finalDbgIndentStr = dbgIndentStr;
+ EVAL_LOG.atWarn().log(() -> {
+ String message = finalDbgIndentStr
+ + "- evaluateFormula('" + ec.getRefEvaluatorForCurrentSheet().getSheetNameRange()
+ + "'/" + new CellReference(ec.getRowIndex(), ec.getColumnIndex()).formatAsString()
+ + "): " + Arrays.toString(ptgs).replaceAll("\\Qorg.apache.poi.ss.formula.ptg.\\E", "");
+ return new SimpleMessage(message);
+ });
dbgEvaluationOutputIndent++;
}
@@ -406,7 +399,7 @@ public final class WorkbookEvaluator {
// since we don't know how to handle these yet :(
Ptg ptg = ptgs[i];
if (dbgEvaluationOutputIndent > 0) {
- EVAL_LOG.log(POILogger.INFO, dbgIndentStr, " * ptg ", i, ": ", ptg, ", stack: ", stack);
+ EVAL_LOG.atInfo().log("{} * ptg {}: {}, stack: {}", dbgIndentStr, box(i),ptg, stack);
}
if (ptg instanceof AttrPtg) {
AttrPtg attrPtg = (AttrPtg) ptg;
@@ -551,7 +544,7 @@ public final class WorkbookEvaluator {
// logDebug("push " + opResult);
stack.push(opResult);
if (dbgEvaluationOutputIndent > 0) {
- EVAL_LOG.log(POILogger.INFO, dbgIndentStr, " = ", opResult);
+ EVAL_LOG.atInfo().log("{} = {}", dbgIndentStr, opResult);
}
}
@@ -570,9 +563,7 @@ public final class WorkbookEvaluator {
}
if (dbgEvaluationOutputIndent > 0) {
- EVAL_LOG.log(POILogger.INFO, dbgIndentStr, "finished eval of ",
- new CellReference(ec.getRowIndex(), ec.getColumnIndex()).formatAsString(),
- ": ", result);
+ EVAL_LOG.atInfo().log("{}finished eval of {}: {}", dbgIndentStr, new CellReference(ec.getRowIndex(), ec.getColumnIndex()).formatAsString(), result);
dbgEvaluationOutputIndent--;
if (dbgEvaluationOutputIndent == 1) {
// this evaluation is done, reset indent to stop logging
diff --git a/src/java/org/apache/poi/ss/formula/constant/ErrorConstant.java b/src/java/org/apache/poi/ss/formula/constant/ErrorConstant.java
index 3d6641a3eb..3d8fb50c84 100644
--- a/src/java/org/apache/poi/ss/formula/constant/ErrorConstant.java
+++ b/src/java/org/apache/poi/ss/formula/constant/ErrorConstant.java
@@ -17,9 +17,12 @@
package org.apache.poi.ss.formula.constant;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
import org.apache.poi.ss.usermodel.FormulaError;
-import org.apache.poi.util.POILogFactory;
-import org.apache.poi.util.POILogger;
+
+import static org.apache.logging.log4j.util.Unbox.box;
+
/**
* Represents a constant error code value as encoded in a constant values array. <p>
*
@@ -27,8 +30,8 @@ import org.apache.poi.util.POILogger;
* <tt>ErrorEval</tt>.
*/
public final class ErrorConstant {
- private static final POILogger LOG = POILogFactory.getLogger(ErrorConstant.class);
- private static final ErrorConstant NULL = new ErrorConstant(FormulaError.NULL.getCode());
+ private static final Logger LOG = LogManager.getLogger(ErrorConstant.class);
+ private static final ErrorConstant NULL = new ErrorConstant(FormulaError.NULL.getCode());
private static final ErrorConstant DIV_0 = new ErrorConstant(FormulaError.DIV0.getCode());
private static final ErrorConstant VALUE = new ErrorConstant(FormulaError.VALUE.getCode());
private static final ErrorConstant REF = new ErrorConstant(FormulaError.REF.getCode());
@@ -66,7 +69,7 @@ public final class ErrorConstant {
default: break;
}
}
- LOG.log( POILogger.WARN, "Warning - unexpected error code (", errorCode, ")");
+ LOG.atWarn().log("Warning - unexpected error code ({})", box(errorCode));
return new ErrorConstant(errorCode);
}
diff --git a/src/java/org/apache/poi/ss/formula/functions/Rate.java b/src/java/org/apache/poi/ss/formula/functions/Rate.java
index 3b9de86dce..d0a840f6b7 100644
--- a/src/java/org/apache/poi/ss/formula/functions/Rate.java
+++ b/src/java/org/apache/poi/ss/formula/functions/Rate.java
@@ -17,20 +17,20 @@
package org.apache.poi.ss.formula.functions;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
import org.apache.poi.ss.formula.eval.ErrorEval;
import org.apache.poi.ss.formula.eval.EvaluationException;
import org.apache.poi.ss.formula.eval.NumberEval;
import org.apache.poi.ss.formula.eval.OperandResolver;
import org.apache.poi.ss.formula.eval.ValueEval;
-import org.apache.poi.util.POILogFactory;
-import org.apache.poi.util.POILogger;
/**
* Implements the Excel Rate function
*/
public class Rate implements Function {
- private static final POILogger LOG = POILogFactory.getLogger(Rate.class);
-
+ private static final Logger LOG = LogManager.getLogger(Rate.class);
+
public ValueEval evaluate(ValueEval[] args, int srcRowIndex, int srcColumnIndex) {
if (args.length < 3) { //First 3 parameters are mandatory
return ErrorEval.VALUE_INVALID;
@@ -65,7 +65,7 @@ public class Rate implements Function {
checkValue(rate);
} catch (EvaluationException e) {
- LOG.log(POILogger.ERROR, "Can't evaluate rate function", e);
+ LOG.atError().withThrowable(e).log("Can't evaluate rate function");
return e.getErrorEval();
}
diff --git a/src/java/org/apache/poi/ss/usermodel/DataFormatter.java b/src/java/org/apache/poi/ss/usermodel/DataFormatter.java
index a4c7e32637..78bbd79b55 100644
--- a/src/java/org/apache/poi/ss/usermodel/DataFormatter.java
+++ b/src/java/org/apache/poi/ss/usermodel/DataFormatter.java
@@ -40,14 +40,14 @@ import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
import org.apache.poi.ss.format.CellFormat;
import org.apache.poi.ss.format.CellFormatResult;
import org.apache.poi.ss.formula.ConditionalFormattingEvaluator;
import org.apache.poi.ss.util.DateFormatConverter;
import org.apache.poi.ss.util.NumberToTextConverter;
import org.apache.poi.util.LocaleUtil;
-import org.apache.poi.util.POILogFactory;
-import org.apache.poi.util.POILogger;
/**
@@ -58,7 +58,7 @@ import org.apache.poi.util.POILogger;
* codes, etc.
* <p>
* Internally, formats will be implemented using subclasses of {@link Format}
- * such as {@link DecimalFormat} and {@link java.text.SimpleDateFormat}. Therefore the
+ * such as {@link DecimalFormat} and {@link SimpleDateFormat}. Therefore the
* formats used by this class must obey the same pattern rules as these Format
* subclasses. This means that only legal number pattern characters ("0", "#",
* ".", "," etc.) may appear in number formats. Other characters can be
@@ -216,7 +216,7 @@ public class DataFormatter {
private final PropertyChangeSupport pcs;
/** For logging any problems we find */
- private static final POILogger LOG = POILogFactory.getLogger(DataFormatter.class);
+ private static final Logger LOG = LogManager.getLogger(DataFormatter.class);
/**
* Creates a formatter using the {@link Locale#getDefault() default locale}.
@@ -337,7 +337,7 @@ public class DataFormatter {
// Wrap and return (non-cacheable - CellFormat does that)
return new CellFormatResultWrapper( cfmt.apply(cellValueO) );
} catch (Exception e) {
- LOG.log(POILogger.WARN, "Formatting failed for format " + formatStr + ", falling back", e);
+ LOG.atWarn().withThrowable(e).log("Formatting failed for format {}, falling back", formatStr);
}
}
@@ -598,7 +598,7 @@ public class DataFormatter {
try {
return new ExcelStyleDateFormatter(formatStr, dateSymbols);
} catch(IllegalArgumentException iae) {
- LOG.log(POILogger.DEBUG, "Formatting failed for format ", formatStr, ", falling back", iae);
+ LOG.atDebug().withThrowable(iae).log("Formatting failed for format {}, falling back", formatStr);
// the pattern could not be parsed correctly,
// so fall back to the default number format
return getDefaultFormat(cellValue);
@@ -758,7 +758,7 @@ public class DataFormatter {
try {
return new InternalDecimalFormatWithScale(format, symbols);
} catch(IllegalArgumentException iae) {
- LOG.log(POILogger.DEBUG, "Formatting failed for format ", formatStr, ", falling back", iae);
+ LOG.atDebug().withThrowable(iae).log("Formatting failed for format {}, falling back", formatStr);
// the pattern could not be parsed correctly,
// so fall back to the default number format
return getDefaultFormat(cellValue);
@@ -1044,7 +1044,7 @@ public class DataFormatter {
* </p>
*
* @param format A Format instance to be used as a default
- * @see java.text.Format#format
+ * @see Format#format
*/
public void setDefaultNumberFormat(Format format) {
for (Map.Entry<String, Format> entry : formats.entrySet()) {
diff --git a/src/java/org/apache/poi/ss/usermodel/FractionFormat.java b/src/java/org/apache/poi/ss/usermodel/FractionFormat.java
index eb6fa7bf6b..c89838a5da 100644
--- a/src/java/org/apache/poi/ss/usermodel/FractionFormat.java
+++ b/src/java/org/apache/poi/ss/usermodel/FractionFormat.java
@@ -24,10 +24,10 @@ import java.text.ParsePosition;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
import org.apache.poi.ss.format.SimpleFraction;
import org.apache.poi.ss.formula.eval.NotImplementedException;
-import org.apache.poi.util.POILogFactory;
-import org.apache.poi.util.POILogger;
/**
* <p>Format class that handles Excel style fractions, such as "# #/#" and "#/###"</p>
@@ -43,7 +43,7 @@ import org.apache.poi.util.POILogger;
@SuppressWarnings("serial")
public class FractionFormat extends Format {
- private static final POILogger LOGGER = POILogFactory.getLogger(FractionFormat.class);
+ private static final Logger LOGGER = LogManager.getLogger(FractionFormat.class);
private static final Pattern DENOM_FORMAT_PATTERN = Pattern.compile("(?:(#+)|(\\d+))");
//this was chosen to match the earlier limitation of max denom power
@@ -147,7 +147,7 @@ public class FractionFormat extends Format {
fract = SimpleFraction.buildFractionMaxDenominator(decPart.doubleValue(), maxDenom);
}
} catch (RuntimeException e){
- LOGGER.log(POILogger.WARN, "Can't format fraction", e);
+ LOGGER.atWarn().withThrowable(e).log("Can't format fraction");
return Double.toString(doubleValue.doubleValue());
}
diff --git a/src/java/org/apache/poi/ss/util/CellUtil.java b/src/java/org/apache/poi/ss/util/CellUtil.java
index 67823b5494..4d5e3e01c7 100644
--- a/src/java/org/apache/poi/ss/util/CellUtil.java
+++ b/src/java/org/apache/poi/ss/util/CellUtil.java
@@ -25,6 +25,8 @@ import java.util.Locale;
import java.util.Map;
import java.util.Set;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
import org.apache.poi.ss.usermodel.BorderStyle;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
@@ -35,8 +37,6 @@ import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.VerticalAlignment;
import org.apache.poi.ss.usermodel.Workbook;
-import org.apache.poi.util.POILogFactory;
-import org.apache.poi.util.POILogger;
/**
* Various utility functions that make working with a cells and rows easier. The various methods
@@ -50,7 +50,7 @@ import org.apache.poi.util.POILogger;
*/
public final class CellUtil {
- private static final POILogger log = POILogFactory.getLogger(CellUtil.class);
+ private static final Logger LOGGER = LogManager.getLogger(CellUtil.class);
// FIXME: Move these constants into an enum
public static final String ALIGNMENT = "alignment";
@@ -258,7 +258,7 @@ public final class CellUtil {
* <p>This is necessary because Excel has an upper limit on the number of styles that it supports.</p>
*
* <p>This function is more efficient than multiple calls to
- * {@link #setCellStyleProperty(org.apache.poi.ss.usermodel.Cell, String, Object)}
+ * {@link #setCellStyleProperty(Cell, String, Object)}
* if adding multiple cell styles.</p>
*
* <p>For performance reasons, if this is the only cell in a workbook that uses a cell style,
@@ -313,7 +313,7 @@ public final class CellUtil {
* same style.</p>
*
* <p>If setting more than one cell style property on a cell, use
- * {@link #setCellStyleProperties(org.apache.poi.ss.usermodel.Cell, Map)},
+ * {@link #setCellStyleProperties(Cell, Map)},
* which is faster and does not add unnecessary intermediate CellStyles to the workbook.</p>
*
* @param cell The cell that is to be changed.
@@ -333,7 +333,7 @@ public final class CellUtil {
*
* @param style cell style
* @return map of format properties (String -> Object)
- * @see #setFormatProperties(org.apache.poi.ss.usermodel.CellStyle, org.apache.poi.ss.usermodel.Workbook, java.util.Map)
+ * @see #setFormatProperties(CellStyle, Workbook, Map)
*/
private static Map<String, Object> getFormatProperties(CellStyle style) {
Map<String, Object> properties = new HashMap<>();
@@ -385,7 +385,7 @@ public final class CellUtil {
} else if (FILL_PATTERN.equals(key)) {
dest.put(key, getFillPattern(src, key));
} else {
- log.log(POILogger.INFO, "Ignoring unrecognized CellUtil format properties key: ", key);
+ LOGGER.atInfo().log("Ignoring unrecognized CellUtil format properties key: {}", key);
}
}
}
@@ -468,10 +468,7 @@ public final class CellUtil {
}
// @deprecated 3.15 beta 2. getBorderStyle will only work on BorderStyle enums instead of codes in the future.
else if (value instanceof Short) {
- if (log.check(POILogger.WARN)) {
- log.log(POILogger.WARN, "Deprecation warning: CellUtil properties map uses Short values for "
- + name + ". Should use BorderStyle enums instead.");
- }
+ LOGGER.atWarn().log("Deprecation warning: CellUtil properties map uses Short values for {}. Should use BorderStyle enums instead.", name);
short code = ((Short) value).shortValue();
border = BorderStyle.valueOf(code);
}
@@ -500,10 +497,7 @@ public final class CellUtil {
}
// @deprecated 3.15 beta 2. getFillPattern will only work on FillPatternType enums instead of codes in the future.
else if (value instanceof Short) {
- if (log.check(POILogger.WARN)) {
- log.log(POILogger.WARN, "Deprecation warning: CellUtil properties map uses Short values for "
- + name + ". Should use FillPatternType enums instead.");
- }
+ LOGGER.atWarn().log("Deprecation warning: CellUtil properties map uses Short values for {}. Should use FillPatternType enums instead.", name);
short code = ((Short) value).shortValue();
pattern = FillPatternType.forInt(code);
}
@@ -532,10 +526,7 @@ public final class CellUtil {
}
// @deprecated 3.15 beta 2. getHorizontalAlignment will only work on HorizontalAlignment enums instead of codes in the future.
else if (value instanceof Short) {
- if (log.check(POILogger.WARN)) {
- log.log(POILogger.WARN, "Deprecation warning: CellUtil properties map used a Short value for "
- + name + ". Should use HorizontalAlignment enums instead.");
- }
+ LOGGER.atWarn().log("Deprecation warning: CellUtil properties map used a Short value for {}. Should use HorizontalAlignment enums instead.", name);
short code = ((Short) value).shortValue();
align = HorizontalAlignment.forInt(code);
}
@@ -564,10 +555,7 @@ public final class CellUtil {
}
// @deprecated 3.15 beta 2. getVerticalAlignment will only work on VerticalAlignment enums instead of codes in the future.
else if (value instanceof Short) {
- if (log.check(POILogger.WARN)) {
- log.log(POILogger.WARN, "Deprecation warning: CellUtil properties map used a Short value for "
- + name + ". Should use VerticalAlignment enums instead.");
- }
+ LOGGER.atWarn().log("Deprecation warning: CellUtil properties map used a Short value for {}. Should use VerticalAlignment enums instead.", name);
short code = ((Short) value).shortValue();
align = VerticalAlignment.forInt(code);
}
diff --git a/src/java/org/apache/poi/ss/util/DateFormatConverter.java b/src/java/org/apache/poi/ss/util/DateFormatConverter.java
index e338e8485c..47d1a04623 100644
--- a/src/java/org/apache/poi/ss/util/DateFormatConverter.java
+++ b/src/java/org/apache/poi/ss/util/DateFormatConverter.java
@@ -24,9 +24,9 @@ import java.util.List;
import java.util.Locale;
import java.util.Map;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
import org.apache.poi.util.LocaleID;
-import org.apache.poi.util.POILogFactory;
-import org.apache.poi.util.POILogger;
/**
* Convert java DateFormat patterns into Excel custom number formats.
@@ -49,7 +49,7 @@ import org.apache.poi.util.POILogger;
*/
@SuppressWarnings("unused")
public final class DateFormatConverter {
- private static final POILogger LOG = POILogFactory.getLogger(DateFormatConverter.class);
+ private static final Logger LOG = LogManager.getLogger(DateFormatConverter.class);
private DateFormatConverter() {
}
@@ -155,7 +155,7 @@ public final class DateFormatConverter {
}
if (loc == null) {
- LOG.log(POILogger.ERROR, "Unable to find prefix for Locale '", languageTag, "' or its parent locales.");
+ LOG.atError().log("Unable to find prefix for Locale '{}' or its parent locales.", languageTag);
return "";
}
diff --git a/src/java/org/apache/poi/ss/util/ImageUtils.java b/src/java/org/apache/poi/ss/util/ImageUtils.java
index 8ab65b5813..2b6a013e02 100644
--- a/src/java/org/apache/poi/ss/util/ImageUtils.java
+++ b/src/java/org/apache/poi/ss/util/ImageUtils.java
@@ -31,6 +31,8 @@ import javax.imageio.ImageIO;
import javax.imageio.ImageReader;
import javax.imageio.stream.ImageInputStream;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
import org.apache.poi.hssf.usermodel.HSSFClientAnchor;
import org.apache.poi.ss.usermodel.ClientAnchor;
import org.apache.poi.ss.usermodel.Picture;
@@ -38,14 +40,12 @@ import org.apache.poi.ss.usermodel.PictureData;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
-import org.apache.poi.util.POILogFactory;
-import org.apache.poi.util.POILogger;
import org.apache.poi.util.Units;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
public final class ImageUtils {
- private static final POILogger LOG = POILogFactory.getLogger(ImageUtils.class);
+ private static final Logger LOG = LogManager.getLogger(ImageUtils.class);
private static final int WIDTH_UNITS = 1024;
private static final int HEIGHT_UNITS = 256;
@@ -56,8 +56,8 @@ public final class ImageUtils {
* Return the dimension of this image
*
* @param is the stream containing the image data
- * @param type type of the picture: {@link org.apache.poi.ss.usermodel.Workbook#PICTURE_TYPE_JPEG},
- * {@link org.apache.poi.ss.usermodel.Workbook#PICTURE_TYPE_PNG} or {@link org.apache.poi.ss.usermodel.Workbook#PICTURE_TYPE_DIB}
+ * @param type type of the picture: {@link Workbook#PICTURE_TYPE_JPEG},
+ * {@link Workbook#PICTURE_TYPE_PNG} or {@link Workbook#PICTURE_TYPE_DIB}
*
* @return image dimension in pixels
*/
@@ -93,18 +93,18 @@ public final class ImageUtils {
r.dispose();
}
} else {
- LOG.log(POILogger.WARN, "ImageIO found no images");
+ LOG.atWarn().log("ImageIO found no images");
}
}
} catch (IOException e) {
//silently return if ImageIO failed to read the image
- LOG.log(POILogger.WARN, e);
+ LOG.atWarn().withThrowable(e).log("Failed to determine image dimensions");
}
break;
default:
- LOG.log(POILogger.WARN, "Only JPEG, PNG and DIB pictures can be automatically sized");
+ LOG.atWarn().log("Only JPEG, PNG and DIB pictures can be automatically sized");
}
return size;
}
diff --git a/src/java/org/apache/poi/util/CommonsLogger.java b/src/java/org/apache/poi/util/CommonsLogger.java
deleted file mode 100644
index cdc4f92804..0000000000
--- a/src/java/org/apache/poi/util/CommonsLogger.java
+++ /dev/null
@@ -1,177 +0,0 @@
-/* ====================================================================
- 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.util;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-/**
- * An implementation of the {@link POILogger} using the
- * Apache Commons Logging framework. Which itself can be configured to
- * send log to various different log frameworks and even allows to create
- * a small wrapper for custom log frameworks.
- */
-public class CommonsLogger implements POILogger
-{
- private static final LogFactory _creator = LogFactory.getFactory();
- private Log log;
-
- @Override
- public void initialize(final String cat) {
- this.log = _creator.getInstance(cat);
- }
-
- /**
- * Log a message
- *
- * @param level One of DEBUG, INFO, WARN, ERROR, FATAL
- * @param obj1 The object to log.
- */
- @Override
- public void _log(final int level, final Object obj1) {
- // FIXME: What happens if level is in between two levels (an even number)?
- // Should this be `if (level >= FATAL) ...`?
- switch (level) {
- case FATAL:
- if (log.isFatalEnabled()) {
- log.fatal(obj1);
- }
- break;
- case ERROR:
- if (log.isErrorEnabled()) {
- log.error(obj1);
- }
- break;
- case WARN:
- if (log.isWarnEnabled()) {
- log.warn(obj1);
- }
- break;
- case INFO:
- if (log.isInfoEnabled()) {
- log.info(obj1);
- }
- break;
- case DEBUG:
- if (log.isDebugEnabled()) {
- log.debug(obj1);
- }
- break;
- default:
- if (log.isTraceEnabled()) {
- log.trace(obj1);
- }
- break;
- }
- }
-
- /**
- * Log a message
- *
- * @param level One of DEBUG, INFO, WARN, ERROR, FATAL
- * @param obj1 The object to log. This is converted to a string.
- * @param exception An exception to be logged
- */
- @Override
- public void _log(final int level, final Object obj1, final Throwable exception) {
- // FIXME: What happens if level is in between two levels (an even number)?
- // Should this be `if (level >= FATAL) ...`?
- switch (level) {
- case FATAL:
- if (log.isFatalEnabled()) {
- if (obj1 != null) {
- log.fatal(obj1, exception);
- } else {
- log.fatal(exception);
- }
- }
- break;
- case ERROR:
- if (log.isErrorEnabled()) {
- if (obj1 != null) {
- log.error(obj1, exception);
- } else {
- log.error(exception);
- }
- }
- break;
- case WARN:
- if (log.isWarnEnabled()) {
- if (obj1 != null) {
- log.warn(obj1, exception);
- } else {
- log.warn(exception);
- }
- }
- break;
- case INFO:
- if (log.isInfoEnabled()) {
- if (obj1 != null) {
- log.info(obj1, exception);
- } else {
- log.info(exception);
- }
- }
- break;
- case DEBUG:
- if (log.isDebugEnabled()) {
- if (obj1 != null) {
- log.debug(obj1, exception);
- } else {
- log.debug(exception);
- }
- }
- break;
- default:
- if (log.isTraceEnabled()) {
- if (obj1 != null) {
- log.trace(obj1, exception);
- } else {
- log.trace(exception);
- }
- }
- break;
- }
- }
-
- /**
- * Check if a logger is enabled to log at the specified level
- *
- * @param level One of DEBUG, INFO, WARN, ERROR, FATAL
- */
- @Override
- public boolean check(final int level)
- {
- // FIXME: What happens if level is in between two levels (an even number)?
- // Should this be `if (level >= FATAL) ...`?
- switch (level) {
- case FATAL:
- return log.isFatalEnabled();
- case ERROR:
- return log.isErrorEnabled();
- case WARN:
- return log.isWarnEnabled();
- case INFO:
- return log.isInfoEnabled();
- case DEBUG:
- return log.isDebugEnabled();
- default:
- return false;
- }
- }
-}
-
diff --git a/src/java/org/apache/poi/util/Configurator.java b/src/java/org/apache/poi/util/Configurator.java
index a8efb68e08..b82ad9b8c7 100644
--- a/src/java/org/apache/poi/util/Configurator.java
+++ b/src/java/org/apache/poi/util/Configurator.java
@@ -17,11 +17,14 @@ package org.apache.poi.util;
limitations under the License.
==================================================================== */
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
/**
* Helper for fetching int values from system properties
*/
public class Configurator {
- private static final POILogger LOG = POILogFactory.getLogger(Configurator.class);
+ private static final Logger LOG = LogManager.getLogger(Configurator.class);
public static int getIntValue(String systemProperty, int defaultValue) {
String property = System.getProperty(systemProperty);
@@ -31,7 +34,7 @@ public class Configurator {
try {
return Integer.parseInt(property);
} catch (Exception e) {
- LOG.log(POILogger.ERROR, "System property -D", systemProperty, " does not contains a valid integer: ", property);
+ LOG.atError().log("System property -D{} does not contains a valid integer: {}", systemProperty, property);
return defaultValue;
}
}
diff --git a/src/java/org/apache/poi/util/IOUtils.java b/src/java/org/apache/poi/util/IOUtils.java
index a578a2b004..8e69427553 100644
--- a/src/java/org/apache/poi/util/IOUtils.java
+++ b/src/java/org/apache/poi/util/IOUtils.java
@@ -33,11 +33,13 @@ import java.util.Locale;
import java.util.zip.CRC32;
import java.util.zip.Checksum;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
import org.apache.poi.EmptyFileException;
@Internal
public final class IOUtils {
- private static final POILogger LOG = POILogFactory.getLogger( IOUtils.class );
+ private static final Logger LOG = LogManager.getLogger(IOUtils.class);
/**
* The default buffer size to use for the skip() methods.
@@ -395,8 +397,7 @@ public final class IOUtils {
try {
closeable.close();
} catch ( Exception exc ) {
- LOG.log( POILogger.ERROR, "Unable to close resource: ", exc,
- exc );
+ LOG.atError().withThrowable(exc).log("Unable to close resource");
}
}
diff --git a/src/java/org/apache/poi/util/NullLogger.java b/src/java/org/apache/poi/util/NullLogger.java
deleted file mode 100644
index 8a9daeaa0b..0000000000
--- a/src/java/org/apache/poi/util/NullLogger.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/* ====================================================================
- 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.util;
-
-/**
- * An empty-implementation of the {@link POILogger}.
- *
- * This can be used to not log anything, however the suggested approach
- * in production systems is to use the {@link CommonsLogger} and configure
- * proper log-handling via Apache Commons Logging.
- */
-@Internal
-public class NullLogger implements POILogger {
- @Override
- public void initialize(final String cat) {
- // do nothing
- }
-
- /**
- * Log a message
- *
- * @param level One of DEBUG, INFO, WARN, ERROR, FATAL
- * @param obj1 The object to log.
- */
-
- @Override
- public void _log(final int level, final Object obj1) {
- // do nothing
- }
-
- /**
- * Log a message
- *
- * @param level One of DEBUG, INFO, WARN, ERROR, FATAL
- * @param obj1 The object to log. This is converted to a string.
- * @param exception An exception to be logged
- */
- @Override
- public void _log(int level, Object obj1, final Throwable exception) {
- // do nothing
- }
-
- /**
- * Log a message. Lazily appends Object parameters together.
- * If the last parameter is a {@link Throwable} it is logged specially.
- *
- * @param level One of DEBUG, INFO, WARN, ERROR, FATAL
- * @param objs the objects to place in the message
- */
- @Override
- public void log(int level, Object... objs) {
- // do nothing
- }
-
-
- /**
- * Check if a logger is enabled to log at the specified level
- *
- * @param level One of DEBUG, INFO, WARN, ERROR, FATAL
- */
- @Override
- public boolean check(final int level) {
- return false;
- }
-}
-
diff --git a/src/java/org/apache/poi/util/POILogFactory.java b/src/java/org/apache/poi/util/POILogFactory.java
deleted file mode 100644
index 576ea55586..0000000000
--- a/src/java/org/apache/poi/util/POILogFactory.java
+++ /dev/null
@@ -1,122 +0,0 @@
-
-/* ====================================================================
- 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.util;
-
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * Provides logging without clients having to mess with
- * configuration/initialization.
- *
- * @author Andrew C. Oliver (acoliver at apache dot org)
- * @author Marc Johnson (mjohnson at apache dot org)
- * @author Nicola Ken Barozzi (nicolaken at apache.org)
- */
-@Internal
-public final class POILogFactory {
- /**
- * Map of POILogger instances, with classes as keys
- */
- private static final Map<String,POILogger> _loggers = new HashMap<>();
-
- /**
- * A common instance of NullLogger, as it does nothing
- * we only need the one
- */
- private static final POILogger _nullLogger = new NullLogger();
- /**
- * The name of the class to use. Initialised the
- * first time we need it
- */
- static String _loggerClassName;
-
- /**
- * Construct a POILogFactory.
- */
- private POILogFactory() {}
-
- /**
- * Get a logger, based on a class name
- *
- * @param theclass the class whose name defines the log
- *
- * @return a POILogger for the specified class
- */
- public static POILogger getLogger(final Class<?> theclass) {
- return getLogger(theclass.getName());
- }
-
- /**
- * Get a logger, based on a String
- *
- * @param cat the String that defines the log
- *
- * @return a POILogger for the specified class
- */
- public static POILogger getLogger(final String cat) {
- // If we haven't found out what logger to use yet,
- // then do so now
- // Don't look it up until we're first asked, so
- // that our users can set the system property
- // between class loading and first use
- if(_loggerClassName == null) {
- try {
- _loggerClassName = System.getProperty("org.apache.poi.util.POILogger");
- } catch(Exception e) {
- // ignore any exception here
- }
-
- // Use the default logger if none specified,
- // or none could be fetched
- if(_loggerClassName == null) {
- _loggerClassName = _nullLogger.getClass().getName();
- }
- }
-
- // Short circuit for the null logger, which
- // ignores all categories
- if(_loggerClassName.equals(_nullLogger.getClass().getName())) {
- return _nullLogger;
- }
-
-
- // Fetch the right logger for them, creating
- // it if that's required
- POILogger logger = _loggers.get(cat);
- if (logger == null) {
- try {
- @SuppressWarnings("unchecked")
- Class<? extends POILogger> loggerClass =
- (Class<? extends POILogger>) Class.forName(_loggerClassName);
- logger = loggerClass.getConstructor().newInstance();
- logger.initialize(cat);
- } catch(Exception e) {
- // Give up and use the null logger
- logger = _nullLogger;
- _loggerClassName = _nullLogger.getClass().getName();
- }
-
- // Save for next time
- _loggers.put(cat, logger);
- }
- return logger;
- }
-} \ No newline at end of file
diff --git a/src/java/org/apache/poi/util/POILogger.java b/src/java/org/apache/poi/util/POILogger.java
deleted file mode 100644
index da4fbb2d14..0000000000
--- a/src/java/org/apache/poi/util/POILogger.java
+++ /dev/null
@@ -1,128 +0,0 @@
-/* ====================================================================
- 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.util;
-
-/**
- * A logger interface that strives to make it as easy as possible for
- * developers to write log calls, while simultaneously making those
- * calls as cheap as possible by performing lazy evaluation of the log
- * message.
- *
- * A logger can be selected via system properties, e.g.
- * <code>
- * -Dorg.apache.poi.util.POILogger=org.apache.poi.util.SystemOutLogger
- * </code>
- *
- * The following Logger-implementations are provided:
- *
- * <ul>
- * <li>NullLogger</li>
- * <li>CommonsLogger</li>
- * <li>SystemOutLogger</li>
- * </ul>
- */
-@Internal
-public interface POILogger {
-
- int DEBUG = 1;
- int INFO = 3;
- int WARN = 5;
- int ERROR = 7;
- int FATAL = 9;
-
- /**
- * Initialize the Logger - belongs to the SPI, called from the POILogFactory
- * @param cat the String that defines the log
- */
- void initialize(String cat);
-
- /**
- * Log a message - belongs to the SPI, usually not called from user code
- *
- * @param level One of DEBUG, INFO, WARN, ERROR, FATAL
- * @param obj1 The object to log. This is converted to a string.
- */
- @Internal
- void _log(int level, Object obj1);
-
- /**
- * Log a message - belongs to the SPI, usually not called from user code
- *
- * @param level One of DEBUG, INFO, WARN, ERROR, FATAL
- * @param obj1 The object to log. This is converted to a string.
- * @param exception An exception to be logged
- */
- @Internal
- void _log(int level, Object obj1, final Throwable exception);
-
-
- /**
- * Check if a logger is enabled to log at the specified level
- * This allows code to avoid building strings or evaluating functions in
- * the arguments to log.
- *
- * An example:
- * <code><pre>
- * if (logger.check(POILogger.INFO)) {
- * logger.log(POILogger.INFO, "Avoid concatenating ", " strings and evaluating ", functions());
- * }
- * </pre></code>
- *
- * @param level One of DEBUG, INFO, WARN, ERROR, FATAL
- */
- boolean check(int level);
-
- /**
- * Log a message. Lazily appends Object parameters together.
- * If the last parameter is a {@link Throwable} it is logged specially.
- *
- * @param level One of DEBUG, INFO, WARN, ERROR, FATAL
- * @param objs the objects to place in the message
- */
- default void log(int level, Object... objs) {
- if (!check(level)) return;
- Throwable lastEx = null;
- String msg;
- if (objs.length == 0) {
- msg = "";
- } else if (objs.length == 1) {
- if (objs[0] instanceof Throwable) {
- lastEx = (Throwable)objs[0];
- }
- msg = objs[0].toString();
- } else {
- StringBuilder sb = new StringBuilder(32);
- for (int i=0; i<objs.length; i++) {
- if (i == objs.length-1 && objs[i] instanceof Throwable) {
- lastEx = (Throwable)objs[i];
- } else {
- sb.append(objs[i]);
- }
- }
- msg = sb.toString();
- }
- // log forging escape
- msg = msg.replaceAll("[\r\n]+", " ");
-
- if (lastEx == null) {
- _log(level, msg);
- } else {
- _log(level, msg, lastEx);
- }
- }
-}
diff --git a/src/java/org/apache/poi/util/SLF4JLogger.java b/src/java/org/apache/poi/util/SLF4JLogger.java
deleted file mode 100644
index 236fc2cee6..0000000000
--- a/src/java/org/apache/poi/util/SLF4JLogger.java
+++ /dev/null
@@ -1,157 +0,0 @@
-/* ====================================================================
- 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.util;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * An implementation of the {@link POILogger} using the
- * SLF4J framework. Which itself can be configured to
- * send log to various different log frameworks and even allows to create
- * a small wrapper for custom log frameworks.
- */
-public class SLF4JLogger implements POILogger
-{
- private Logger log;
-
- @Override
- public void initialize(final String cat) {
- this.log = LoggerFactory.getLogger(cat);
- }
-
- /**
- * Log a message
- *
- * @param level One of DEBUG, INFO, WARN, ERROR, FATAL
- * @param obj1 The object to log.
- */
- @Override
- public void _log(final int level, final Object obj1) {
- switch (level) {
- case FATAL:
- case ERROR:
- if (log.isErrorEnabled()) {
- log.error(obj1.toString());
- }
- break;
- case WARN:
- if (log.isWarnEnabled()) {
- log.warn(obj1.toString());
- }
- break;
- case INFO:
- if (log.isInfoEnabled()) {
- log.info(obj1.toString());
- }
- break;
- case DEBUG:
- if (log.isDebugEnabled()) {
- log.debug(obj1.toString());
- }
- break;
- default:
- if (log.isTraceEnabled()) {
- log.trace(obj1.toString());
- }
- break;
- }
- }
-
- /**
- * Log a message
- *
- * @param level One of DEBUG, INFO, WARN, ERROR, FATAL
- * @param obj1 The object to log. This is converted to a string.
- * @param exception An exception to be logged
- */
- @Override
- public void _log(final int level, final Object obj1, final Throwable exception) {
- switch (level) {
- case FATAL:
- case ERROR:
- if (log.isErrorEnabled()) {
- if (obj1 != null) {
- log.error(obj1.toString(), exception);
- } else {
- log.error(exception.toString(), exception);
- }
- }
- break;
- case WARN:
- if (log.isWarnEnabled()) {
- if (obj1 != null) {
- log.warn(obj1.toString(), exception);
- } else {
- log.warn(exception.toString(), exception);
- }
- }
- break;
- case INFO:
- if (log.isInfoEnabled()) {
- if (obj1 != null) {
- log.info(obj1.toString(), exception);
- } else {
- log.info(exception.toString(), exception);
- }
- }
- break;
- case DEBUG:
- if (log.isDebugEnabled()) {
- if (obj1 != null) {
- log.debug(obj1.toString(), exception);
- } else {
- log.debug(exception.toString(), exception);
- }
- }
- break;
- default:
- if (log.isTraceEnabled()) {
- if (obj1 != null) {
- log.trace(obj1.toString(), exception);
- } else {
- log.trace(exception.toString(), exception);
- }
- }
- break;
- }
- }
-
- /**
- * Check if a logger is enabled to log at the specified level
- *
- * @param level One of DEBUG, INFO, WARN, ERROR, FATAL
- */
- @Override
- public boolean check(final int level)
- {
- switch (level) {
- case FATAL:
- case ERROR:
- return log.isErrorEnabled();
- case WARN:
- return log.isWarnEnabled();
- case INFO:
- return log.isInfoEnabled();
- case DEBUG:
- return log.isDebugEnabled();
- default:
- return false;
- }
- }
-}
-
diff --git a/src/java/org/apache/poi/util/SystemOutLogger.java b/src/java/org/apache/poi/util/SystemOutLogger.java
deleted file mode 100644
index cc414f76a5..0000000000
--- a/src/java/org/apache/poi/util/SystemOutLogger.java
+++ /dev/null
@@ -1,96 +0,0 @@
-/* ====================================================================
- 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.util;
-
-/**
- * An implementation of the {@link POILogger} which uses System.out.println.
- *
- * This can be used to provide simply output from applications, however the
- * suggested approach in production systems is to use the {@link CommonsLogger}
- * and configure proper log-handling via Apache Commons Logging.
- */
-public class SystemOutLogger implements POILogger {
- /**
- * Short strings for numeric log level. Use level as array index.
- */
- private static final String LEVEL_STRINGS_SHORT = "?D?I?W?E?F?";
-
- private String _cat;
-
- @Override
- public void initialize(final String cat) {
- this._cat=cat;
- }
-
- /**
- * Log a message
- *
- * @param level One of DEBUG, INFO, WARN, ERROR, FATAL
- * @param obj1 The object to log.
- */
- @Override
- public void _log(final int level, final Object obj1) {
- _log(level, obj1, null);
- }
-
- /**
- * Log a message
- *
- * @param level One of DEBUG, INFO, WARN, ERROR, FATAL
- * @param obj1 The object to log. This is converted to a string.
- * @param exception An exception to be logged
- */
- @Override
- @SuppressForbidden("uses printStackTrace")
- public void _log(final int level, final Object obj1, final Throwable exception) {
- if (!check(level)) {
- return;
- }
- System.out.print("[");
- System.out.print(_cat);
- System.out.print("]");
- System.out.print(LEVEL_STRINGS_SHORT.charAt(Math.min(LEVEL_STRINGS_SHORT.length()-1, level)));
- System.out.print(" ");
- System.out.println(obj1);
- if (exception != null) {
- exception.printStackTrace(System.out);
- }
- }
-
- /**
- * Check if a logger is enabled to log at the specified level
- *
- * @param level One of DEBUG, INFO, WARN, ERROR, FATAL
- * @see #DEBUG
- * @see #INFO
- * @see #WARN
- * @see #ERROR
- * @see #FATAL
- */
- @Override
- public boolean check(final int level) {
- int currentLevel;
- try {
- currentLevel = Integer.parseInt(System.getProperty("poi.log.level", WARN + ""));
- } catch (SecurityException e) {
- currentLevel = POILogger.DEBUG;
- }
-
- return level >= currentLevel;
- }
-}
-
diff --git a/src/java/org/apache/poi/util/XMLHelper.java b/src/java/org/apache/poi/util/XMLHelper.java
index f58306f15c..fd23c0c5f2 100644
--- a/src/java/org/apache/poi/util/XMLHelper.java
+++ b/src/java/org/apache/poi/util/XMLHelper.java
@@ -46,6 +46,9 @@ import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.validation.SchemaFactory;
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
import org.xml.sax.ErrorHandler;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
@@ -74,7 +77,7 @@ public final class XMLHelper {
};
- private static final POILogger LOG = POILogFactory.getLogger(XMLHelper.class);
+ private static final Logger LOG = LogManager.getLogger(XMLHelper.class);
private static long lastLog;
// DocumentBuilderFactory.newDocumentBuilder is thread-safe
@@ -290,7 +293,7 @@ public final class XMLHelper {
private static void logThrowable(Throwable t, String message, String name) {
if (System.currentTimeMillis() > lastLog + TimeUnit.MINUTES.toMillis(5)) {
- LOG.log(POILogger.WARN, message + " [log suppressed for 5 minutes]", name, t);
+ LOG.atWarn().withThrowable(t).log("{} [log suppressed for 5 minutes]{}", message, name);
lastLog = System.currentTimeMillis();
}
}
@@ -298,22 +301,22 @@ public final class XMLHelper {
private static class DocHelperErrorHandler implements ErrorHandler {
public void warning(SAXParseException exception) {
- printError(POILogger.WARN, exception);
+ printError(Level.WARN, exception);
}
public void error(SAXParseException exception) {
- printError(POILogger.ERROR, exception);
+ printError(Level.ERROR, exception);
}
public void fatalError(SAXParseException exception) throws SAXException {
- printError(POILogger.FATAL, exception);
+ printError(Level.FATAL, exception);
throw exception;
}
/**
* Prints the error message.
*/
- private void printError(int type, SAXParseException ex) {
+ private void printError(Level type, SAXParseException ex) {
String systemId = ex.getSystemId();
if (systemId != null) {
int index = systemId.lastIndexOf('/');
@@ -326,7 +329,7 @@ public final class XMLHelper {
':' + ex.getColumnNumber() +
':' + ex.getMessage();
- LOG.log(type, message, ex);
+ LOG.atLevel(type).withThrowable(ex).log(message);
}
}