diff options
author | Marius Volkhart <mariusvolkhart@apache.org> | 2021-02-21 20:57:25 +0000 |
---|---|---|
committer | Marius Volkhart <mariusvolkhart@apache.org> | 2021-02-21 20:57:25 +0000 |
commit | 259c9967efb354a0feff2a861ac8bd20582b6562 (patch) | |
tree | ba76a4f20503d97e77bdf18146d59e00a2369fb9 /src/ooxml | |
parent | 6d10f26718f84591671d7cafdcc009345b9c777e (diff) | |
download | poi-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/ooxml')
72 files changed, 501 insertions, 510 deletions
diff --git a/src/ooxml/java/org/apache/poi/ooxml/POIXMLDocumentPart.java b/src/ooxml/java/org/apache/poi/ooxml/POIXMLDocumentPart.java index e1291fe6d9..4696e71de9 100644 --- a/src/ooxml/java/org/apache/poi/ooxml/POIXMLDocumentPart.java +++ b/src/ooxml/java/org/apache/poi/ooxml/POIXMLDocumentPart.java @@ -25,6 +25,8 @@ import java.util.List; import java.util.Map; import java.util.Set; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import org.apache.poi.openxml4j.exceptions.OpenXML4JException; import org.apache.poi.openxml4j.exceptions.PartAlreadyExistsException; @@ -38,21 +40,20 @@ import org.apache.poi.openxml4j.opc.PackagingURIHelper; import org.apache.poi.openxml4j.opc.TargetMode; import org.apache.poi.util.IOUtils; import org.apache.poi.util.Internal; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; import org.apache.poi.xddf.usermodel.chart.XDDFChart; import org.apache.poi.xssf.usermodel.XSSFRelation; import org.apache.poi.xssf.usermodel.XSSFWorkbook; +import org.apache.poi.xwpf.usermodel.XWPFDocument; import org.apache.poi.xwpf.usermodel.XWPFRelation; /** * Represents an entry of a OOXML package. * <p> - * Each POIXMLDocumentPart keeps a reference to the underlying a {@link org.apache.poi.openxml4j.opc.PackagePart}. + * Each POIXMLDocumentPart keeps a reference to the underlying a {@link PackagePart}. * </p> */ public class POIXMLDocumentPart { - private static final POILogger LOG = POILogFactory.getLogger(POIXMLDocumentPart.class); + private static final Logger LOG = LogManager.getLogger(POIXMLDocumentPart.class); private String coreDocumentRel = PackageRelationshipTypes.CORE_DOCUMENT; private PackagePart packagePart; @@ -161,10 +162,10 @@ public class POIXMLDocumentPart { /** * Creates an POIXMLDocumentPart representing the given package part and relationship. - * Called by {@link #read(POIXMLFactory, java.util.Map)} when reading in an existing file. + * Called by {@link #read(POIXMLFactory, Map)} when reading in an existing file. * * @param part - The package part that holds xml data representing this sheet. - * @see #read(POIXMLFactory, java.util.Map) + * @see #read(POIXMLFactory, Map) * @since POI 3.14-Beta1 */ public POIXMLDocumentPart(PackagePart part) { @@ -173,11 +174,11 @@ public class POIXMLDocumentPart { /** * Creates an POIXMLDocumentPart representing the given package part, relationship and parent - * Called by {@link #read(POIXMLFactory, java.util.Map)} when reading in an existing file. + * Called by {@link #read(POIXMLFactory, Map)} when reading in an existing file. * * @param parent - Parent part * @param part - The package part that holds xml data representing this sheet. - * @see #read(POIXMLFactory, java.util.Map) + * @see #read(POIXMLFactory, Map) * @since POI 3.14-Beta1 */ public POIXMLDocumentPart(POIXMLDocumentPart parent, PackagePart part) { @@ -619,8 +620,7 @@ public class POIXMLDocumentPart { PackagePart pp = getPackagePart(); if (pp.getContentType().equals(XWPFRelation.GLOSSARY_DOCUMENT.getContentType())) { - LOG.log(POILogger.WARN, - "POI does not currently support template.main+xml (glossary) parts. " + + LOG.atWarn().log("POI does not currently support template.main+xml (glossary) parts. " + "Skipping this part for now."); return; } @@ -651,7 +651,7 @@ public class POIXMLDocumentPart { final PackagePart p = packagePart.getPackage().getPart(relName); if (p == null) { - LOG.log(POILogger.ERROR, "Skipped invalid entry ", rel.getTargetURI()); + LOG.atError().log("Skipped invalid entry {}", rel.getTargetURI()); continue; } @@ -721,7 +721,7 @@ public class POIXMLDocumentPart { * Internal method, do not use! * <p> * This method only exists to allow access to protected {@link POIXMLDocumentPart#onDocumentRead()} - * from {@link org.apache.poi.xwpf.usermodel.XWPFDocument} without reflection. It should be removed. + * from {@link XWPFDocument} without reflection. It should be removed. * * @param part the part which is to be read * @throws IOException if the part can't be read diff --git a/src/ooxml/java/org/apache/poi/ooxml/POIXMLFactory.java b/src/ooxml/java/org/apache/poi/ooxml/POIXMLFactory.java index b839e0fd17..0e91da3be9 100644 --- a/src/ooxml/java/org/apache/poi/ooxml/POIXMLFactory.java +++ b/src/ooxml/java/org/apache/poi/ooxml/POIXMLFactory.java @@ -18,20 +18,20 @@ package org.apache.poi.ooxml; import java.io.IOException; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.ooxml.POIXMLRelation.PackagePartConstructor; import org.apache.poi.ooxml.POIXMLRelation.ParentPartConstructor; import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import org.apache.poi.openxml4j.opc.PackagePart; import org.apache.poi.openxml4j.opc.PackageRelationship; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; import org.apache.xmlbeans.XmlException; /** * Defines a factory API that enables sub-classes to create instances of <code>POIXMLDocumentPart</code> */ public abstract class POIXMLFactory { - private static final POILogger LOGGER = POILogFactory.getLogger(POIXMLFactory.class); + private static final Logger LOGGER = LogManager.getLogger(POIXMLFactory.class); /** * Create a POIXMLDocumentPart from existing package part and relation. This method is called @@ -62,7 +62,7 @@ public abstract class POIXMLFactory { } } - LOGGER.log(POILogger.DEBUG, "using default POIXMLDocumentPart for ", rel.getRelationshipType()); + LOGGER.atDebug().log("using default POIXMLDocumentPart for {}", rel.getRelationshipType()); return new POIXMLDocumentPart(parent, part); } catch (IOException | XmlException e) { throw new POIXMLException(e.getMessage(), e); diff --git a/src/ooxml/java/org/apache/poi/ooxml/POIXMLRelation.java b/src/ooxml/java/org/apache/poi/ooxml/POIXMLRelation.java index ca08b55427..5bf576d4e0 100644 --- a/src/ooxml/java/org/apache/poi/ooxml/POIXMLRelation.java +++ b/src/ooxml/java/org/apache/poi/ooxml/POIXMLRelation.java @@ -20,6 +20,8 @@ import java.io.IOException; import java.io.InputStream; import java.util.Iterator; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import org.apache.poi.openxml4j.opc.PackagePart; import org.apache.poi.openxml4j.opc.PackagePartName; @@ -27,8 +29,6 @@ import org.apache.poi.openxml4j.opc.PackageRelationship; import org.apache.poi.openxml4j.opc.PackageRelationshipCollection; import org.apache.poi.openxml4j.opc.PackagingURIHelper; import org.apache.poi.util.Internal; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; import org.apache.xmlbeans.XmlException; /** @@ -51,7 +51,7 @@ public abstract class POIXMLRelation { POIXMLDocumentPart init(POIXMLDocumentPart parent, PackagePart part) throws IOException, XmlException; } - private static final POILogger log = POILogFactory.getLogger(POIXMLRelation.class); + private static final Logger LOGGER = LogManager.getLogger(POIXMLRelation.class); /** * Describes the content stored in a part. @@ -207,7 +207,7 @@ public abstract class POIXMLRelation { PackagePart part = corePart.getPackage().getPart(relName); return part.getInputStream(); } - log.log(POILogger.WARN, "No part " + getDefaultFileName() + " found"); + LOGGER.atWarn().log("No part {} found", getDefaultFileName()); return null; } } diff --git a/src/ooxml/java/org/apache/poi/ooxml/util/XPathHelper.java b/src/ooxml/java/org/apache/poi/ooxml/util/XPathHelper.java index cd4b25da2b..6677f01fb9 100644 --- a/src/ooxml/java/org/apache/poi/ooxml/util/XPathHelper.java +++ b/src/ooxml/java/org/apache/poi/ooxml/util/XPathHelper.java @@ -24,9 +24,9 @@ import javax.xml.namespace.QName; import javax.xml.xpath.XPathFactory; import com.microsoft.schemas.compatibility.AlternateContentDocument; +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.xslf.usermodel.XSLFShape; import org.apache.xmlbeans.XmlCursor; import org.apache.xmlbeans.XmlException; @@ -34,7 +34,7 @@ import org.apache.xmlbeans.XmlObject; import org.apache.xmlbeans.impl.values.XmlAnyTypeImpl; public final class XPathHelper { - private static final POILogger LOG = POILogFactory.getLogger(XPathHelper.class); + private static final Logger LOG = LogManager.getLogger(XPathHelper.class); private static final String OSGI_ERROR = "Schemas (*.xsb) for <CLASS> can't be loaded - usually this happens when OSGI " + @@ -62,9 +62,9 @@ public final class XPathHelper { try { xpf.setFeature(feature, enabled); } catch (Exception e) { - LOG.log(POILogger.WARN, "XPathFactory Feature unsupported", feature, e); + LOG.atWarn().withThrowable(e).log("XPathFactory Feature ({}) unsupported", feature); } catch (AbstractMethodError ame) { - LOG.log(POILogger.WARN, "Cannot set XPathFactory feature because outdated XML parser in classpath", feature, ame); + LOG.atWarn().withThrowable(ame).log("Cannot set XPathFactory feature ({}) because outdated XML parser in classpath", feature); } } diff --git a/src/ooxml/java/org/apache/poi/openxml4j/opc/OPCPackage.java b/src/ooxml/java/org/apache/poi/openxml4j/opc/OPCPackage.java index ffd764918b..6e11336bf5 100644 --- a/src/ooxml/java/org/apache/poi/openxml4j/opc/OPCPackage.java +++ b/src/ooxml/java/org/apache/poi/openxml4j/opc/OPCPackage.java @@ -42,6 +42,8 @@ import java.util.Optional; 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.openxml4j.exceptions.InvalidFormatException; import org.apache.poi.openxml4j.exceptions.InvalidOperationException; import org.apache.poi.openxml4j.exceptions.OpenXML4JRuntimeException; @@ -59,8 +61,6 @@ import org.apache.poi.openxml4j.opc.internal.unmarshallers.UnmarshallContext; import org.apache.poi.openxml4j.util.ZipEntrySource; import org.apache.poi.util.IOUtils; import org.apache.poi.util.NotImplemented; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; /** * Represents a container that can store multiple data objects. @@ -70,7 +70,7 @@ public abstract class OPCPackage implements RelationshipSource, Closeable { /** * Logger. */ - private static final POILogger LOG = POILogFactory.getLogger(OPCPackage.class); + private static final Logger LOG = LogManager.getLogger(OPCPackage.class); /** * Default package access. @@ -442,14 +442,12 @@ public abstract class OPCPackage implements RelationshipSource, Closeable { } if (this.packageAccess == PackageAccess.READ) { - LOG.log(POILogger.WARN, - "The close() method is intended to SAVE a package. This package is open in READ ONLY mode, use the revert() method instead !"); + LOG.atWarn().log("The close() method is intended to SAVE a package. This package is open in READ ONLY mode, use the revert() method instead!"); revert(); return; } if (this.contentTypeManager == null) { - LOG.log(POILogger.WARN, - "Unable to call close() on a package that hasn't been fully opened yet"); + LOG.atWarn().log("Unable to call close() on a package that hasn't been fully opened yet"); revert(); return; } @@ -559,7 +557,7 @@ public abstract class OPCPackage implements RelationshipSource, Closeable { * * @throws InvalidOperationException * Throws if a writing operation is done on a read only package. - * @see org.apache.poi.openxml4j.opc.PackageAccess + * @see PackageAccess */ void throwExceptionIfReadOnly() throws InvalidOperationException { if (packageAccess == PackageAccess.READ) { @@ -574,7 +572,7 @@ public abstract class OPCPackage implements RelationshipSource, Closeable { * right. * * @throws InvalidOperationException if a read operation is done on a write only package. - * @see org.apache.poi.openxml4j.opc.PackageAccess + * @see PackageAccess */ void throwExceptionIfWriteOnly() throws InvalidOperationException { if (packageAccess == PackageAccess.WRITE) { @@ -748,7 +746,7 @@ public abstract class OPCPackage implements RelationshipSource, Closeable { if (!hasCorePropertiesPart) { hasCorePropertiesPart = true; } else { - LOG.log(POILogger.WARN, "OPC Compliance error [M4.1]: " + + LOG.atWarn().log("OPC Compliance error [M4.1]: " + "there is more than one core properties relationship in the package! " + "POI will use only the first, but other software may reject this file."); } @@ -772,9 +770,7 @@ public abstract class OPCPackage implements RelationshipSource, Closeable { needCorePropertiesPart = false; } } catch (IOException ioe) { - LOG.log(POILogger.WARN, "Unmarshall operation : IOException for " - + part._partName); - continue; + LOG.atWarn().log("Unmarshall operation : IOException for {}", part._partName); } catch (InvalidOperationException invoe) { throw new InvalidFormatException(invoe.getMessage(), invoe); } @@ -1005,9 +1001,7 @@ public abstract class OPCPackage implements RelationshipSource, Closeable { try { sourcePartName = PackagingURIHelper.createPartName(sourceURI); } catch (InvalidFormatException e) { - LOG - .log(POILogger.ERROR, "Part name URI '", sourceURI, - "' is not valid ! This message is not intended to be displayed !"); + LOG.atError().log("Part name URI '{}' is not valid! This message is not intended to be displayed!", sourceURI); return; } if (sourcePartName.getURI().equals( @@ -1109,10 +1103,7 @@ public abstract class OPCPackage implements RelationshipSource, Closeable { this.deletePartRecursive(targetPartName); } } catch (InvalidFormatException e) { - LOG.log(POILogger.WARN, "An exception occurs while deleting part '" - + partName.getName() - + "'. Some parts may remain in the package. - " - + e.getMessage()); + LOG.atWarn().withThrowable(e).log("An exception occurs while deleting part '{}'. Some parts may remain in the package.", partName.getName()); return; } // Remove the relationships part @@ -1226,8 +1217,8 @@ public abstract class OPCPackage implements RelationshipSource, Closeable { * @param relationshipType * Type of relationship. * @return The newly created and added relationship - * @see org.apache.poi.openxml4j.opc.RelationshipSource#addExternalRelationship(java.lang.String, - * java.lang.String) + * @see RelationshipSource#addExternalRelationship(String, + * String) */ @Override public PackageRelationship addExternalRelationship(String target, @@ -1249,8 +1240,8 @@ public abstract class OPCPackage implements RelationshipSource, Closeable { * @param id * Relationship unique id. * @return The newly created and added relationship - * @see org.apache.poi.openxml4j.opc.RelationshipSource#addExternalRelationship(java.lang.String, - * java.lang.String) + * @see RelationshipSource#addExternalRelationship(String, + * String) */ @Override public PackageRelationship addExternalRelationship(String target, @@ -1357,7 +1348,7 @@ public abstract class OPCPackage implements RelationshipSource, Closeable { } /** - * @see org.apache.poi.openxml4j.opc.RelationshipSource#getRelationship(java.lang.String) + * @see RelationshipSource#getRelationship(String) */ @Override public PackageRelationship getRelationship(String id) { @@ -1365,7 +1356,7 @@ public abstract class OPCPackage implements RelationshipSource, Closeable { } /** - * @see org.apache.poi.openxml4j.opc.RelationshipSource#hasRelationships() + * @see RelationshipSource#hasRelationships() */ @Override public boolean hasRelationships() { @@ -1373,7 +1364,7 @@ public abstract class OPCPackage implements RelationshipSource, Closeable { } /** - * @see org.apache.poi.openxml4j.opc.RelationshipSource#isRelationshipExists(org.apache.poi.openxml4j.opc.PackageRelationship) + * @see RelationshipSource#isRelationshipExists(PackageRelationship) */ @Override public boolean isRelationshipExists(PackageRelationship rel) { @@ -1397,8 +1388,7 @@ public abstract class OPCPackage implements RelationshipSource, Closeable { try { partMarshallers.put(new ContentType(contentType), marshaller); } catch (InvalidFormatException e) { - LOG.log(POILogger.WARN, "The specified content type is not valid: '" - + e.getMessage() + "'. The marshaller will not be added !"); + LOG.atWarn().log("The specified content type is not valid: '{}'. The marshaller will not be added !", e.getMessage()); } } @@ -1415,9 +1405,7 @@ public abstract class OPCPackage implements RelationshipSource, Closeable { try { partUnmarshallers.put(new ContentType(contentType), unmarshaller); } catch (InvalidFormatException e) { - LOG.log(POILogger.WARN, "The specified content type is not valid: '" - + e.getMessage() - + "'. The unmarshaller will not be added !"); + LOG.atWarn().log("The specified content type is not valid: '{}'. The unmarshaller will not be added !", e.getMessage()); } } diff --git a/src/ooxml/java/org/apache/poi/openxml4j/opc/PackagePart.java b/src/ooxml/java/org/apache/poi/openxml4j/opc/PackagePart.java index 4956032f67..81519ff2a5 100644 --- a/src/ooxml/java/org/apache/poi/openxml4j/opc/PackagePart.java +++ b/src/ooxml/java/org/apache/poi/openxml4j/opc/PackagePart.java @@ -699,7 +699,7 @@ public abstract class PackagePart implements RelationshipSource, Comparable<Pack * @param zos * Output stream to save this part. * @return true if the content has been successfully stored, false otherwise. - * More information about errors may be logged via {@link org.apache.poi.util.POILogger} + * More information about errors may be logged via Log4j 2. * @throws OpenXML4JException * If any exception occur. */ @@ -711,7 +711,7 @@ public abstract class PackagePart implements RelationshipSource, Comparable<Pack * @param ios * The input stream of the content to load. * @return true if the content has been successfully loaded, false otherwise. - * More information about errors may be logged via {@link org.apache.poi.util.POILogger} + * More information about errors may be logged via Log4j 2. * @throws InvalidFormatException * Throws if the content format is invalid. */ diff --git a/src/ooxml/java/org/apache/poi/openxml4j/opc/PackageRelationshipCollection.java b/src/ooxml/java/org/apache/poi/openxml4j/opc/PackageRelationshipCollection.java index 53fb37246c..07f8b98a3c 100644 --- a/src/ooxml/java/org/apache/poi/openxml4j/opc/PackageRelationshipCollection.java +++ b/src/ooxml/java/org/apache/poi/openxml4j/opc/PackageRelationshipCollection.java @@ -20,11 +20,11 @@ import java.net.URI; import java.net.URISyntaxException; import java.util.*; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import org.apache.poi.openxml4j.exceptions.InvalidOperationException; import org.apache.poi.ooxml.util.DocumentHelper; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; import org.w3c.dom.Attr; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -39,7 +39,7 @@ import org.w3c.dom.NodeList; */ public final class PackageRelationshipCollection implements Iterable<PackageRelationship> { - private static final POILogger LOG = POILogFactory.getLogger(PackageRelationshipCollection.class); + private static final Logger LOG = LogManager.getLogger(PackageRelationshipCollection.class); /** * Package relationships ordered by ID. @@ -300,7 +300,7 @@ public final class PackageRelationshipCollection implements Iterable<PackageRela public void parseRelationshipsPart(PackagePart relPart) throws InvalidFormatException { try { - LOG.log(POILogger.DEBUG, "Parsing relationship: ", relPart.getPartName()); + LOG.atDebug().log("Parsing relationship: {}", relPart.getPartName()); Document xmlRelationshipsDoc = DocumentHelper.readDocument(relPart.getInputStream()); // Browse default types @@ -348,8 +348,7 @@ public final class PackageRelationshipCollection implements Iterable<PackageRela // package target = PackagingURIHelper.toURI(value); } catch (URISyntaxException e) { - LOG.log(POILogger.ERROR, "Cannot convert ", value, - " in a valid relationship URI-> dummy-URI used", e); + LOG.atError().withThrowable(e).log("Cannot convert {} in a valid relationship URI-> dummy-URI used", value); } addRelationship(target, targetMode, type, id); } diff --git a/src/ooxml/java/org/apache/poi/openxml4j/opc/PackagingURIHelper.java b/src/ooxml/java/org/apache/poi/openxml4j/opc/PackagingURIHelper.java index 32f8950b2f..bd1bce1b7e 100644 --- a/src/ooxml/java/org/apache/poi/openxml4j/opc/PackagingURIHelper.java +++ b/src/ooxml/java/org/apache/poi/openxml4j/opc/PackagingURIHelper.java @@ -23,10 +23,10 @@ import java.nio.ByteBuffer; import java.nio.charset.StandardCharsets; import java.util.regex.Pattern; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import org.apache.poi.openxml4j.exceptions.InvalidOperationException; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; /** * Helper for part and pack URI. @@ -38,7 +38,7 @@ public final class PackagingURIHelper { // FIXME: this class implements a lot of path joining and splitting logic that // is already implemented in java.nio.file.Path. // This class should heavily leverage Java library code to reduce the number of lines of code that POI has to maintain and test - private static final POILogger LOG = POILogFactory.getLogger(PackagingURIHelper.class); + private static final Logger LOG = LogManager.getLogger(PackagingURIHelper.class); /** * Package root URI. @@ -290,7 +290,7 @@ public final class PackagingURIHelper { try { targetURI = new URI(path.substring(1)); } catch (Exception e) { - LOG.log(POILogger.WARN, e); + LOG.atWarn().withThrowable(e).log("Failed to relativize"); return null; } } @@ -328,7 +328,7 @@ public final class PackagingURIHelper { try { return new URI(retVal.toString()); } catch (Exception e) { - LOG.log(POILogger.WARN, e); + LOG.atWarn().withThrowable(e).log("Failed to relativize"); return null; } } @@ -377,7 +377,7 @@ public final class PackagingURIHelper { try { return new URI(retVal.toString()); } catch (Exception e) { - LOG.log(POILogger.WARN, e); + LOG.atWarn().withThrowable(e).log("Failed to relativize"); return null; } } @@ -661,7 +661,7 @@ public final class PackagingURIHelper { } /** - * Convert a string to {@link java.net.URI} + * Convert a string to {@link URI} * * If part name is not a valid URI, it is resolved as follows: * <p> diff --git a/src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java b/src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java index b65996b53d..67e7c44567 100644 --- a/src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java +++ b/src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java @@ -33,6 +33,9 @@ import java.util.stream.Collectors; import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream; import org.apache.commons.compress.archivers.zip.ZipFile; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.message.SimpleMessage; import org.apache.poi.UnsupportedFileFormatException; import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import org.apache.poi.openxml4j.exceptions.InvalidOperationException; @@ -52,8 +55,6 @@ import org.apache.poi.openxml4j.util.ZipEntrySource; import org.apache.poi.openxml4j.util.ZipFileZipEntrySource; import org.apache.poi.openxml4j.util.ZipInputStreamZipEntrySource; import org.apache.poi.util.IOUtils; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; import org.apache.poi.util.TempFile; /** @@ -63,7 +64,7 @@ public final class ZipPackage extends OPCPackage { private static final String MIMETYPE = "mimetype"; private static final String SETTINGS_XML = "settings.xml"; - private static final POILogger LOG = POILogFactory.getLogger(ZipPackage.class); + private static final Logger LOG = LogManager.getLogger(ZipPackage.class); /** * Zip archive, as either a file on disk, @@ -81,7 +82,7 @@ public final class ZipPackage extends OPCPackage { try { this.contentTypeManager = new ZipContentTypeManager(null, this); } catch (InvalidFormatException e) { - LOG.log(POILogger.WARN,"Could not parse ZipPackage", e); + LOG.atWarn().withThrowable(e).log("Could not parse ZipPackage"); } } @@ -145,7 +146,7 @@ public final class ZipPackage extends OPCPackage { throw new InvalidOperationException("Can't open the specified file: '" + file + "'", e); } - LOG.log(POILogger.ERROR, "Error in zip file ", file, " - falling back to stream processing (i.e. ignoring zip central directory)"); + LOG.atError().log("Error in zip file {} - falling back to stream processing (i.e. ignoring zip central directory)", file); ze = openZipEntrySourceStream(file); } this.zipArchive = ze; @@ -311,7 +312,7 @@ public final class ZipPackage extends OPCPackage { : PackagingURIHelper.createPartName(ZipHelper.getOPCNameFromZipItemName(entryName)); } catch (Exception e) { // We assume we can continue, even in degraded mode ... - LOG.log(POILogger.WARN,"Entry ", entryName, " is not valid, so this part won't be add to the package.", e); + LOG.atWarn().withThrowable(e).log("Entry {} is not valid, so this part won't be add to the package.", entryName); } this.partName = ppn; @@ -370,7 +371,7 @@ public final class ZipPackage extends OPCPackage { try { return new MemoryPackagePart(this, partName, contentType, loadRelationships); } catch (InvalidFormatException e) { - LOG.log(POILogger.WARN, e); + LOG.atWarn().withThrowable(e).log("Failed to create part {}", partName); return null; } } @@ -437,9 +438,7 @@ public final class ZipPackage extends OPCPackage { } finally { // Either the save operation succeed or not, we delete the temporary file if (!tempFile.delete()) { - LOG.log(POILogger.WARN, "The temporary file: '", - targetFile.getAbsolutePath(), - "' cannot be deleted ! Make sure that no other application use it."); + LOG.atWarn().log("The temporary file: '{}' cannot be deleted ! Make sure that no other application use it.", targetFile.getAbsolutePath()); } } } @@ -496,7 +495,7 @@ public final class ZipPackage extends OPCPackage { // we save it as well if (this.getPartsByRelationshipType(PackageRelationshipTypes.CORE_PROPERTIES).size() == 0 && this.getPartsByRelationshipType(PackageRelationshipTypes.CORE_PROPERTIES_ECMA376).size() == 0 ) { - LOG.log(POILogger.DEBUG,"Save core properties part"); + LOG.atDebug().log("Save core properties part"); // Ensure that core properties are added if missing getPackageProperties(); @@ -516,11 +515,11 @@ public final class ZipPackage extends OPCPackage { } // Save content type part. - LOG.log(POILogger.DEBUG,"Save content types part"); + LOG.atDebug().log("Save content types part"); this.contentTypeManager.save(zos); // Save package relationships part. - LOG.log(POILogger.DEBUG,"Save package relationships"); + LOG.atDebug().log("Save package relationships"); ZipPartMarshaller.marshallRelationshipPart(this.getRelationships(), PackagingURIHelper.PACKAGE_RELATIONSHIPS_ROOT_PART_NAME, zos); @@ -534,13 +533,13 @@ public final class ZipPackage extends OPCPackage { } final PackagePartName ppn = part.getPartName(); - LOG.log(POILogger.DEBUG,"Save part '", ZipHelper.getZipItemNameFromOPCName(ppn.getName()), "'"); + LOG.atDebug().log(() -> new SimpleMessage("Save part '" + ZipHelper.getZipItemNameFromOPCName(ppn.getName()) + "'")); final PartMarshaller marshaller = partMarshallers.get(part._contentType); final PartMarshaller pm = (marshaller != null) ? marshaller : defaultPartMarshaller; if (!pm.marshall(part, zos)) { String errMsg = "The part " + ppn.getURI() + " failed to be saved in the stream with marshaller " + pm + - ". Enable logging via POILogger for more details."; + ". Enable logging via Log4j 2 for more details."; throw new OpenXML4JException(errMsg); } } diff --git a/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/ZipContentTypeManager.java b/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/ZipContentTypeManager.java index 3040262ba3..597335efc4 100644 --- a/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/ZipContentTypeManager.java +++ b/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/ZipContentTypeManager.java @@ -23,11 +23,11 @@ import java.io.OutputStream; import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import org.apache.poi.openxml4j.opc.OPCPackage; import org.apache.poi.openxml4j.opc.StreamHelper; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; import org.w3c.dom.Document; /** @@ -38,7 +38,7 @@ import org.w3c.dom.Document; * @see ContentTypeManager */ public class ZipContentTypeManager extends ContentTypeManager { - private static final POILogger LOG = POILogFactory.getLogger(ZipContentTypeManager.class); + private static final Logger LOG = LogManager.getLogger(ZipContentTypeManager.class); /** * Delegate constructor to the super constructor. @@ -71,8 +71,7 @@ public class ZipContentTypeManager extends ContentTypeManager { zos.closeArchiveEntry(); } } catch (IOException ioe) { - LOG.log(POILogger.ERROR, "Cannot write: ", CONTENT_TYPES_PART_NAME, - " in Zip !", ioe); + LOG.atError().withThrowable(ioe).log("Cannot write: " + CONTENT_TYPES_PART_NAME + " in Zip !"); return false; } } diff --git a/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/marshallers/DefaultMarshaller.java b/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/marshallers/DefaultMarshaller.java index 16a5917ad3..970768cb30 100644 --- a/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/marshallers/DefaultMarshaller.java +++ b/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/marshallers/DefaultMarshaller.java @@ -38,7 +38,7 @@ public final class DefaultMarshaller implements PartMarshaller { * @param part The {@link PackagePart} to store. * @param out Output stream to save this part. * @return true if the content has been successfully stored, false otherwise. - * More information about errors may be logged via {@link org.apache.poi.util.POILogger} + * More information about errors may be logged via Log4j 2. * @throws OpenXML4JException * If any error occur. */ diff --git a/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/marshallers/ZipPartMarshaller.java b/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/marshallers/ZipPartMarshaller.java index c1e058ea6d..384ad7687e 100644 --- a/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/marshallers/ZipPartMarshaller.java +++ b/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/marshallers/ZipPartMarshaller.java @@ -24,6 +24,8 @@ import java.net.URI; import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.openxml4j.exceptions.OpenXML4JException; import org.apache.poi.openxml4j.opc.PackageNamespaces; import org.apache.poi.openxml4j.opc.PackagePart; @@ -37,8 +39,6 @@ import org.apache.poi.openxml4j.opc.internal.PartMarshaller; import org.apache.poi.openxml4j.opc.internal.ZipHelper; import org.apache.poi.ooxml.util.DocumentHelper; import org.apache.poi.util.IOUtils; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; import org.apache.poi.xssf.usermodel.XSSFRelation; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -47,7 +47,7 @@ import org.w3c.dom.Element; * Zip part marshaller. This marshaller is use to save any part in a zip stream. */ public final class ZipPartMarshaller implements PartMarshaller { - private static final POILogger LOG = POILogFactory.getLogger(ZipPartMarshaller.class); + private static final Logger LOG = LogManager.getLogger(ZipPartMarshaller.class); /** * Save the specified part to the given stream. @@ -56,7 +56,7 @@ public final class ZipPartMarshaller implements PartMarshaller { * @param os The stream to write the data to * @return true if saving was successful or there was nothing to save, * false if an error occurred. - * In case of errors, logging via the {@link POILogger} is used to provide more information. + * In case of errors, logging via Log4j 2 is used to provide more information. * @throws OpenXML4JException * Throws if the stream cannot be written to or an internal exception is thrown. */ @@ -64,7 +64,7 @@ public final class ZipPartMarshaller implements PartMarshaller { public boolean marshall(PackagePart part, OutputStream os) throws OpenXML4JException { if (!(os instanceof ZipArchiveOutputStream)) { - LOG.log(POILogger.ERROR,"Unexpected class ", os.getClass().getName()); + LOG.atError().log("Unexpected class {}", os.getClass().getName()); throw new OpenXML4JException("ZipOutputStream expected !"); // Normally should happen only in development phase, so just throw // exception @@ -91,8 +91,7 @@ public final class ZipPartMarshaller implements PartMarshaller { zos.closeArchiveEntry(); } } catch (IOException ioe) { - LOG.log(POILogger.ERROR,"Cannot write: ", part.getPartName(), ": in ZIP", - ioe); + LOG.atError().withThrowable(ioe).log("Cannot write: {}: in ZIP", part.getPartName()); return false; } @@ -120,7 +119,7 @@ public final class ZipPartMarshaller implements PartMarshaller { * relationships serialization. * @return true if saving was successful, * false if an error occurred. - * In case of errors, logging via the {@link POILogger} is used to provide more information. + * In case of errors, logging via Log4j 2 is used to provide more information. */ public static boolean marshallRelationshipPart( PackageRelationshipCollection rels, PackagePartName relPartName, @@ -186,7 +185,7 @@ public final class ZipPartMarshaller implements PartMarshaller { zos.closeArchiveEntry(); } } catch (IOException e) { - LOG.log(POILogger.ERROR,"Cannot create zip entry ", relPartName, e); + LOG.atError().withThrowable(e).log("Cannot create zip entry {}", relPartName); return false; } } diff --git a/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/KeyInfoKeySelector.java b/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/KeyInfoKeySelector.java index 04ac6fd57a..e7a4eba080 100644 --- a/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/KeyInfoKeySelector.java +++ b/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/KeyInfoKeySelector.java @@ -38,8 +38,8 @@ import javax.xml.crypto.XMLStructure; import javax.xml.crypto.dsig.keyinfo.KeyInfo; import javax.xml.crypto.dsig.keyinfo.X509Data; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; /** * JSR105 key selector implementation using the ds:KeyInfo data of the signature @@ -47,14 +47,14 @@ import org.apache.poi.util.POILogger; */ public class KeyInfoKeySelector extends KeySelector implements KeySelectorResult { - private static final POILogger LOG = POILogFactory.getLogger(KeyInfoKeySelector.class); + private static final Logger LOG = LogManager.getLogger(KeyInfoKeySelector.class); private final List<X509Certificate> certChain = new ArrayList<>(); @SuppressWarnings("unchecked") @Override public KeySelectorResult select(KeyInfo keyInfo, Purpose purpose, AlgorithmMethod method, XMLCryptoContext context) throws KeySelectorException { - LOG.log(POILogger.DEBUG, "select key"); + LOG.atDebug().log("select key"); if (null == keyInfo) { throw new KeySelectorException("no ds:KeyInfo present"); } @@ -71,7 +71,7 @@ public class KeyInfoKeySelector extends KeySelector implements KeySelectorResult continue; } X509Certificate certificate = (X509Certificate) x509DataObject; - LOG.log(POILogger.DEBUG, "certificate", certificate.getSubjectX500Principal()); + LOG.atDebug().log("certificate: {}", certificate.getSubjectX500Principal()); certChain.add(certificate); } } diff --git a/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/OOXMLURIDereferencer.java b/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/OOXMLURIDereferencer.java index b809b06ef5..d38088c68c 100644 --- a/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/OOXMLURIDereferencer.java +++ b/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/OOXMLURIDereferencer.java @@ -38,19 +38,19 @@ import javax.xml.crypto.URIReference; import javax.xml.crypto.URIReferenceException; import javax.xml.crypto.XMLCryptoContext; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import org.apache.poi.openxml4j.opc.PackagePart; import org.apache.poi.openxml4j.opc.PackagePartName; import org.apache.poi.openxml4j.opc.PackagingURIHelper; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; /** * JSR105 URI dereferencer for Office Open XML documents. */ public class OOXMLURIDereferencer implements URIDereferencer { - private static final POILogger LOG = POILogFactory.getLogger(OOXMLURIDereferencer.class); + private static final Logger LOG = LogManager.getLogger(OOXMLURIDereferencer.class); private SignatureInfo signatureInfo; private URIDereferencer baseUriDereferencer; @@ -77,7 +77,7 @@ public class OOXMLURIDereferencer implements URIDereferencer { PackagePart part = findPart(uri); if (part == null) { - LOG.log(POILogger.DEBUG, "cannot resolve, delegating to base DOM URI dereferencer", uri); + LOG.atDebug().log("cannot resolve {}, delegating to base DOM URI dereferencer", uri); return baseUriDereferencer.dereference(uriReference, context); } @@ -105,11 +105,11 @@ public class OOXMLURIDereferencer implements URIDereferencer { } private PackagePart findPart(URI uri) { - LOG.log(POILogger.DEBUG, "dereference", uri); + LOG.atDebug().log("dereference: {}", uri); String path = uri.getPath(); if (path == null || path.isEmpty()) { - LOG.log(POILogger.DEBUG, "illegal part name (expected)", uri); + LOG.atDebug().log("illegal part name (expected): {}", uri); return null; } @@ -118,7 +118,7 @@ public class OOXMLURIDereferencer implements URIDereferencer { ppn = PackagingURIHelper.createPartName(path); return signatureInfo.getOpcPackage().getPart(ppn); } catch (InvalidFormatException e) { - LOG.log(POILogger.WARN, "illegal part name (not expected)", uri); + LOG.atWarn().log("illegal part name (not expected) in {}", uri); return null; } } diff --git a/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/SignatureConfig.java b/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/SignatureConfig.java index 07702f6760..98cb1933a3 100644 --- a/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/SignatureConfig.java +++ b/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/SignatureConfig.java @@ -44,6 +44,8 @@ import javax.xml.crypto.dsig.Transform; import javax.xml.crypto.dsig.XMLSignatureFactory; import javax.xml.crypto.dsig.keyinfo.KeyInfoFactory; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.EncryptedDocumentException; import org.apache.poi.hpsf.ClassID; import org.apache.poi.openxml4j.opc.OPCPackage; @@ -60,8 +62,6 @@ import org.apache.poi.poifs.crypt.dsig.services.TimeStampService; import org.apache.poi.poifs.crypt.dsig.services.TimeStampServiceValidator; 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.Removal; import org.apache.xml.security.signature.XMLSignature; @@ -76,7 +76,7 @@ public class SignatureConfig { public static final String SIGNATURE_TIME_FORMAT = "yyyy-MM-dd'T'HH:mm:ss'Z'"; - private static final POILogger LOG = POILogFactory.getLogger(SignatureConfig.class); + private static final Logger LOG = LogManager.getLogger(SignatureConfig.class); private static final String DigestMethod_SHA224 = "http://www.w3.org/2001/04/xmldsig-more#sha224"; private static final String DigestMethod_SHA384 = "http://www.w3.org/2001/04/xmldsig-more#sha384"; private static final String XMLSEC_SANTUARIO = "org.apache.jcp.xml.dsig.internal.dom.XMLDSigRI"; @@ -350,7 +350,7 @@ public class SignatureConfig { try { this.executionTime = fmt.parse(executionTime); } catch (ParseException e) { - LOG.log(POILogger.WARN, "Illegal execution time: ", executionTime); + LOG.atWarn().log("Illegal execution time: {}. Must be formatted as " + SIGNATURE_TIME_FORMAT, executionTime); } } } diff --git a/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/SignatureInfo.java b/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/SignatureInfo.java index b06a01f044..8f43ef150a 100644 --- a/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/SignatureInfo.java +++ b/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/SignatureInfo.java @@ -52,6 +52,7 @@ import javax.xml.crypto.dsig.SignatureMethod; import javax.xml.crypto.dsig.SignedInfo; import javax.xml.crypto.dsig.TransformException; import javax.xml.crypto.dsig.XMLObject; +import javax.xml.crypto.dsig.XMLSignature; import javax.xml.crypto.dsig.XMLSignatureException; import javax.xml.crypto.dsig.XMLSignatureFactory; import javax.xml.crypto.dsig.dom.DOMSignContext; @@ -61,6 +62,8 @@ import javax.xml.crypto.dsig.spec.C14NMethodParameterSpec; import org.apache.jcp.xml.dsig.internal.dom.DOMReference; import org.apache.jcp.xml.dsig.internal.dom.DOMSignedInfo; import org.apache.jcp.xml.dsig.internal.dom.DOMSubTreeData; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.EncryptedDocumentException; import org.apache.poi.ooxml.util.DocumentHelper; import org.apache.poi.openxml4j.exceptions.InvalidFormatException; @@ -76,8 +79,6 @@ import org.apache.poi.poifs.crypt.CryptoFunctions; import org.apache.poi.poifs.crypt.HashAlgorithm; import org.apache.poi.poifs.crypt.dsig.facets.SignatureFacet; import org.apache.poi.poifs.crypt.dsig.services.RelationshipTransformService; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; import org.apache.xml.security.Init; import org.apache.xml.security.utils.XMLUtils; import org.apache.xmlbeans.XmlOptions; @@ -154,12 +155,12 @@ import org.w3c.dom.events.MutationEvent; * <ul> * <li>BouncyCastle bcpkix and bcprov (tested against 1.67)</li> * <li>Apache Santuario "xmlsec" (tested against 2.2.0)</li> - * <li>and slf4j-api (tested against 1.7.30)</li> + * <li>and log4j-api (tested against 2.14.0)</li> * </ul> */ public class SignatureInfo { - private static final POILogger LOG = POILogFactory.getLogger(SignatureInfo.class); + private static final Logger LOG = LogManager.getLogger(SignatureInfo.class); private SignatureConfig signatureConfig; private OPCPackage opcPackage; @@ -313,11 +314,11 @@ public class SignatureInfo { return false; } sigPart = opcPackage.getPart(sigOrigRels.next()); - LOG.log(POILogger.DEBUG, "Digital Signature Origin part", sigPart); + LOG.atDebug().log("Digital Signature Origin part: {}", sigPart); try { sigRels = sigPart.getRelationshipsByType(PackageRelationshipTypes.DIGITAL_SIGNATURE).iterator(); } catch (InvalidFormatException e) { - LOG.log(POILogger.WARN, "Reference to signature is invalid.", e); + LOG.atWarn().withThrowable(e).log("Reference to signature is invalid."); } } return true; @@ -332,9 +333,9 @@ public class SignatureInfo { throw new NoSuchElementException(); } sigRelPart = sigPart.getRelatedPart(sigRels.next()); - LOG.log(POILogger.DEBUG, "XML Signature part", sigRelPart); + LOG.atDebug().log("XML Signature part: {}", sigRelPart); } catch (InvalidFormatException e) { - LOG.log(POILogger.WARN, "Reference to signature is invalid.", e); + LOG.atWarn().withThrowable(e).log("Reference to signature is invalid."); } } while (sigRelPart == null); return new SignaturePart(sigRelPart, SignatureInfo.this); @@ -378,7 +379,7 @@ public class SignatureInfo { */ List<XMLObject> objects = new ArrayList<>(); for (SignatureFacet signatureFacet : signatureConfig.getSignatureFacets()) { - LOG.log(POILogger.DEBUG, "invoking signature facet: ", signatureFacet.getClass().getSimpleName()); + LOG.atDebug().log("invoking signature facet: {}", signatureFacet.getClass().getSimpleName()); signatureFacet.preSign(this, document, references, objects); } @@ -402,7 +403,7 @@ public class SignatureInfo { * JSR105 ds:Signature creation */ String signatureValueId = signatureConfig.getPackageSignatureId() + "-signature-value"; - javax.xml.crypto.dsig.XMLSignature xmlSignature = signatureFactory + XMLSignature xmlSignature = signatureFactory .newXMLSignature(signedInfo, null, objects, signatureConfig.getPackageSignatureId(), signatureValueId); @@ -415,10 +416,10 @@ public class SignatureInfo { * Completion of undigested ds:References in the ds:Manifests. */ for (XMLObject object : objects) { - LOG.log(POILogger.DEBUG, "object java type: ", object.getClass().getName()); + LOG.atDebug().log("object java type: {}", object.getClass().getName()); List<XMLStructure> objectContentList = object.getContent(); for (XMLStructure objectContent : objectContentList) { - LOG.log(POILogger.DEBUG, "object content java type: ", objectContent.getClass().getName()); + LOG.atDebug().log("object content java type: {}", objectContent.getClass().getName()); if (!(objectContent instanceof Manifest)) { continue; } @@ -483,7 +484,7 @@ public class SignatureInfo { */ public void postSign(final DOMSignContext xmlSignContext, final String signatureValue) throws MarshalException { - LOG.log(POILogger.DEBUG, "postSign"); + LOG.atDebug().log("postSign"); final Document document = (Document)xmlSignContext.getParent(); @@ -527,7 +528,7 @@ public class SignatureInfo { xo.setSaveSuggestedPrefixes(namespaceMap); xo.setUseDefaultNamespace(); - LOG.log(POILogger.DEBUG, "output signed Office OpenXML document"); + LOG.atDebug().log("output signed Office OpenXML document"); /* * Copy the original OOXML content to the signed OOXML package. During @@ -593,8 +594,7 @@ public class SignatureInfo { return (Element)sigValNl.item(0); } - LOG.log(POILogger.WARN, "Signature element '", localName, "' was ", - (sigValNl.getLength() == 0 ? "not found" : "multiple times")); + LOG.atWarn().log("Signature element '{}' was {}", localName, sigValNl.getLength() == 0 ? "not found" : "multiple times"); return null; } @@ -704,7 +704,7 @@ public class SignatureInfo { try { return (Provider)Class.forName(className).getDeclaredConstructor().newInstance(); } catch (Exception e) { - LOG.log(POILogger.DEBUG, "XMLDsig-Provider '", className, "' can't be found - trying next."); + LOG.atDebug().log("XMLDsig-Provider '{}' can't be found - trying next.", className); return null; } } diff --git a/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/SignaturePart.java b/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/SignaturePart.java index d120d655e1..1fd4151eb7 100644 --- a/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/SignaturePart.java +++ b/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/SignaturePart.java @@ -40,12 +40,12 @@ import javax.xml.xpath.XPath; import javax.xml.xpath.XPathConstants; import javax.xml.xpath.XPathExpressionException; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.EncryptedDocumentException; import org.apache.poi.ooxml.util.DocumentHelper; import org.apache.poi.ooxml.util.XPathHelper; import org.apache.poi.openxml4j.opc.PackagePart; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; import org.apache.xmlbeans.XmlException; import org.w3.x2000.x09.xmldsig.SignatureDocument; import org.w3c.dom.Document; @@ -54,7 +54,7 @@ import org.w3c.dom.NodeList; import org.xml.sax.SAXException; public class SignaturePart { - private static final POILogger LOG = POILogFactory.getLogger(SignaturePart.class); + private static final Logger LOG = LogManager.getLogger(SignaturePart.class); private static final String XMLSEC_VALIDATE_MANIFEST = "org.jcp.xml.dsig.validateManifests"; @@ -139,23 +139,23 @@ public class SignaturePart { return valid; } catch (IOException e) { String s = "error in reading document"; - LOG.log(POILogger.ERROR, s, e); + LOG.atError().withThrowable(e).log(s); throw new EncryptedDocumentException(s, e); } catch (SAXException e) { String s = "error in parsing document"; - LOG.log(POILogger.ERROR, s, e); + LOG.atError().withThrowable(e).log(s); throw new EncryptedDocumentException(s, e); } catch (XPathExpressionException e) { String s = "error in searching document with xpath expression"; - LOG.log(POILogger.ERROR, s, e); + LOG.atError().withThrowable(e).log(s); throw new EncryptedDocumentException(s, e); } catch (MarshalException e) { String s = "error in unmarshalling the signature"; - LOG.log(POILogger.ERROR, s, e); + LOG.atError().withThrowable(e).log(s); throw new EncryptedDocumentException(s, e); } catch (XMLSignatureException e) { String s = "error in validating the signature"; - LOG.log(POILogger.ERROR, s, e); + LOG.atError().withThrowable(e).log(s); throw new EncryptedDocumentException(s, e); } } diff --git a/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/facets/KeyInfoSignatureFacet.java b/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/facets/KeyInfoSignatureFacet.java index 0943a8a596..d59f4c9acb 100644 --- a/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/facets/KeyInfoSignatureFacet.java +++ b/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/facets/KeyInfoSignatureFacet.java @@ -40,10 +40,10 @@ import javax.xml.crypto.dsig.keyinfo.KeyValue; import javax.xml.crypto.dsig.keyinfo.X509Data; import org.apache.jcp.xml.dsig.internal.dom.DOMKeyInfo; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.poifs.crypt.dsig.SignatureConfig; import org.apache.poi.poifs.crypt.dsig.SignatureInfo; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; @@ -56,12 +56,12 @@ import org.w3c.dom.NodeList; */ public class KeyInfoSignatureFacet implements SignatureFacet { - private static final POILogger LOG = POILogFactory.getLogger(KeyInfoSignatureFacet.class); + private static final Logger LOG = LogManager.getLogger(KeyInfoSignatureFacet.class); @Override public void postSign(SignatureInfo signatureInfo, Document document) throws MarshalException { - LOG.log(POILogger.DEBUG, "postSign"); + LOG.atDebug().log("postSign"); NodeList nl = document.getElementsByTagNameNS(XML_DIGSIG_NS, "Object"); diff --git a/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/facets/OOXMLSignatureFacet.java b/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/facets/OOXMLSignatureFacet.java index fb88e96f63..6f5061aac9 100644 --- a/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/facets/OOXMLSignatureFacet.java +++ b/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/facets/OOXMLSignatureFacet.java @@ -54,6 +54,8 @@ import javax.xml.crypto.dsig.XMLSignatureFactory; import com.microsoft.schemas.office.x2006.digsig.CTSignatureInfoV1; import com.microsoft.schemas.office.x2006.digsig.SignatureInfoV1Document; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import org.apache.poi.openxml4j.opc.ContentTypes; import org.apache.poi.openxml4j.opc.OPCPackage; @@ -68,8 +70,6 @@ import org.apache.poi.poifs.crypt.dsig.SignatureConfig; import org.apache.poi.poifs.crypt.dsig.SignatureInfo; import org.apache.poi.poifs.crypt.dsig.services.RelationshipTransformService; import org.apache.poi.poifs.crypt.dsig.services.RelationshipTransformService.RelationshipTransformParameterSpec; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; import org.openxmlformats.schemas.xpackage.x2006.digitalSignature.CTSignatureTime; import org.openxmlformats.schemas.xpackage.x2006.digitalSignature.SignatureTimeDocument; import org.w3c.dom.Document; @@ -82,7 +82,7 @@ import org.w3c.dom.Element; */ public class OOXMLSignatureFacet implements SignatureFacet { - private static final POILogger LOG = POILogFactory.getLogger(OOXMLSignatureFacet.class); + private static final Logger LOG = LogManager.getLogger(OOXMLSignatureFacet.class); private static final String ID_PACKAGE_OBJECT = "idPackageObject"; @Override @@ -92,7 +92,7 @@ public class OOXMLSignatureFacet implements SignatureFacet { , List<Reference> references , List<XMLObject> objects) throws XMLSignatureException { - LOG.log(POILogger.DEBUG, "pre sign"); + LOG.atDebug().log("pre sign"); addManifestObject(signatureInfo, document, references, objects); addSignatureInfo(signatureInfo, document, references, objects); } @@ -178,7 +178,7 @@ public class OOXMLSignatureFacet implements SignatureFacet { if (relationshipType.endsWith("customXml") && !(contentType.equals("inkml+xml") || contentType.equals("text/xml"))) { - LOG.log(POILogger.DEBUG, "skipping customXml with content type: ", contentType); + LOG.atDebug().log("skipping customXml with content type: {}", contentType); continue; } @@ -212,7 +212,7 @@ public class OOXMLSignatureFacet implements SignatureFacet { } try { pn = new URI(pn).normalize().getPath().replace('\\', '/'); - LOG.log(POILogger.DEBUG, "part name: ", pn); + LOG.atDebug().log("part name: {}", pn); } catch (URISyntaxException e) { throw new XMLSignatureException(e); } @@ -230,7 +230,7 @@ public class OOXMLSignatureFacet implements SignatureFacet { CTSignatureTime ctTime = sigTime.addNewSignatureTime(); ctTime.setFormat("YYYY-MM-DDThh:mm:ssTZD"); ctTime.setValue(signatureConfig.formatExecutionTime()); - LOG.log(POILogger.DEBUG, "execution time: ", ctTime.getValue()); + LOG.atDebug().log("execution time: {}", ctTime.getValue()); Element n = (Element)document.importNode(ctTime.getDomNode(),true); List<XMLStructure> signatureTimeContent = new ArrayList<>(); @@ -328,7 +328,7 @@ public class OOXMLSignatureFacet implements SignatureFacet { } protected static boolean isSignedRelationship(String relationshipType) { - LOG.log(POILogger.DEBUG, "relationship type: ", relationshipType); + LOG.atDebug().log("relationship type: {}", relationshipType); String rt = relationshipType.replaceFirst(".*/relationships/", ""); return (signed.contains(rt) || rt.endsWith("customXml")); } diff --git a/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/facets/XAdESSignatureFacet.java b/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/facets/XAdESSignatureFacet.java index 8ad617f22d..d18af54e46 100644 --- a/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/facets/XAdESSignatureFacet.java +++ b/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/facets/XAdESSignatureFacet.java @@ -32,7 +32,6 @@ import java.security.MessageDigest; import java.security.cert.CertificateEncodingException; import java.security.cert.X509Certificate; import java.util.Calendar; -import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Locale; @@ -47,13 +46,13 @@ import javax.xml.crypto.dsig.Transform; import javax.xml.crypto.dsig.XMLObject; import javax.xml.crypto.dsig.XMLSignatureException; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.poifs.crypt.CryptoFunctions; import org.apache.poi.poifs.crypt.HashAlgorithm; import org.apache.poi.poifs.crypt.dsig.SignatureConfig; import org.apache.poi.poifs.crypt.dsig.SignatureInfo; import org.apache.poi.poifs.crypt.dsig.services.SignaturePolicyService; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; import org.apache.xmlbeans.XmlCursor; import org.apache.xmlbeans.XmlObject; import org.apache.xmlbeans.XmlString; @@ -92,7 +91,7 @@ import org.w3c.dom.NodeList; */ public class XAdESSignatureFacet implements SignatureFacet { - private static final POILogger LOG = POILogFactory.getLogger(XAdESSignatureFacet.class); + private static final Logger LOG = LogManager.getLogger(XAdESSignatureFacet.class); private static final String XADES_TYPE = "http://uri.etsi.org/01903#SignedProperties"; @@ -106,7 +105,7 @@ public class XAdESSignatureFacet implements SignatureFacet { , List<Reference> references , List<XMLObject> objects) throws XMLSignatureException { - LOG.log(POILogger.DEBUG, "preSign"); + LOG.atDebug().log("preSign"); SignatureConfig signatureConfig = signatureInfo.getSignatureConfig(); @@ -241,7 +240,7 @@ public class XAdESSignatureFacet implements SignatureFacet { assert(nl.getLength() == 1); ((Element)nl.item(0)).setIdAttribute("Id", true); - List<XMLStructure> xadesObjectContent = Collections.singletonList(new DOMStructure(qualDocEl)); + List<XMLStructure> xadesObjectContent = singletonList(new DOMStructure(qualDocEl)); XMLObject xo = signatureInfo.getSignatureFactory().newXMLObject(xadesObjectContent, null, null, null); return xo; } diff --git a/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/facets/XAdESXLSignatureFacet.java b/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/facets/XAdESXLSignatureFacet.java index 3c70649b97..18f28f4837 100644 --- a/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/facets/XAdESXLSignatureFacet.java +++ b/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/facets/XAdESXLSignatureFacet.java @@ -47,11 +47,11 @@ import java.util.UUID; import javax.xml.crypto.MarshalException; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.poifs.crypt.dsig.SignatureConfig; import org.apache.poi.poifs.crypt.dsig.SignatureInfo; import org.apache.poi.poifs.crypt.dsig.services.RevocationData; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; import org.apache.xml.security.c14n.Canonicalizer; import org.apache.xmlbeans.XmlException; import org.bouncycastle.asn1.ASN1InputStream; @@ -87,7 +87,7 @@ import org.w3c.dom.NodeList; */ public class XAdESXLSignatureFacet implements SignatureFacet { - private static final POILogger LOG = POILogFactory.getLogger(XAdESXLSignatureFacet.class); + private static final Logger LOG = LogManager.getLogger(XAdESXLSignatureFacet.class); private final CertificateFactory certificateFactory; @@ -101,7 +101,7 @@ public class XAdESXLSignatureFacet implements SignatureFacet { @Override public void postSign(SignatureInfo signatureInfo, Document document) throws MarshalException { - LOG.log(POILogger.DEBUG, "XAdES-X-L post sign phase"); + LOG.atDebug().log("XAdES-X-L post sign phase"); SignatureConfig signatureConfig = signatureInfo.getSignatureConfig(); @@ -139,7 +139,7 @@ public class XAdESXLSignatureFacet implements SignatureFacet { } RevocationData tsaRevocationDataXadesT = new RevocationData(); - LOG.log(POILogger.DEBUG, "creating XAdES-T time-stamp"); + LOG.atDebug().log("creating XAdES-T time-stamp"); XAdESTimeStampType signatureTimeStamp = createXAdESTimeStamp (signatureInfo, Collections.singletonList(nlSigVal.item(0)), tsaRevocationDataXadesT); @@ -259,7 +259,7 @@ public class XAdESXLSignatureFacet implements SignatureFacet { timeStampNodesXadesX1.add(completeRevocationRefs.getDomNode()); RevocationData tsaRevocationDataXadesX1 = new RevocationData(); - LOG.log(POILogger.DEBUG, "creating XAdES-X time-stamp"); + LOG.atDebug().log("creating XAdES-X time-stamp"); XAdESTimeStampType timeStampXadesX1 = createXAdESTimeStamp (signatureInfo, timeStampNodesXadesX1, tsaRevocationDataXadesX1); if (tsaRevocationDataXadesX1.hasRevocationDataEntries()) { diff --git a/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/services/RelationshipTransformService.java b/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/services/RelationshipTransformService.java index a2069c8a89..d8fc9d4ceb 100644 --- a/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/services/RelationshipTransformService.java +++ b/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/services/RelationshipTransformService.java @@ -24,6 +24,7 @@ package org.apache.poi.poifs.crypt.dsig.services; +import static org.apache.logging.log4j.util.Unbox.box; import static org.apache.poi.ooxml.POIXMLTypeLoader.DEFAULT_XML_OPTIONS; import static org.apache.poi.poifs.crypt.dsig.facets.SignatureFacet.OO_DIGSIG_NS; import static org.apache.poi.poifs.crypt.dsig.facets.SignatureFacet.XML_NS; @@ -49,9 +50,9 @@ import javax.xml.crypto.dsig.TransformService; import javax.xml.crypto.dsig.spec.TransformParameterSpec; import org.apache.jcp.xml.dsig.internal.dom.ApacheNodeSetData; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.ooxml.util.DocumentHelper; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; import org.apache.poi.util.SuppressForbidden; import org.apache.xml.security.signature.XMLSignatureInput; import org.apache.xmlbeans.XmlException; @@ -77,7 +78,7 @@ public class RelationshipTransformService extends TransformService { private final List<String> sourceIds; - private static final POILogger LOG = POILogFactory.getLogger(RelationshipTransformService.class); + private static final Logger LOG = LogManager.getLogger(RelationshipTransformService.class); /** * Relationship Transform parameter specification class. @@ -107,14 +108,14 @@ public class RelationshipTransformService extends TransformService { public RelationshipTransformService() { super(); - LOG.log(POILogger.DEBUG, "constructor"); + LOG.atDebug().log("constructor"); this.sourceIds = new ArrayList<>(); } /** * Register the provider for this TransformService * - * @see javax.xml.crypto.dsig.TransformService + * @see TransformService */ public static synchronized void registerDsigProvider() { // the xml signature classes will try to find a special TransformerService, @@ -127,7 +128,7 @@ public class RelationshipTransformService extends TransformService { @Override public void init(TransformParameterSpec params) throws InvalidAlgorithmParameterException { - LOG.log(POILogger.DEBUG, "init(params)"); + LOG.atDebug().log("init(params)"); if (!(params instanceof RelationshipTransformParameterSpec)) { throw new InvalidAlgorithmParameterException(); } @@ -137,8 +138,8 @@ public class RelationshipTransformService extends TransformService { @Override public void init(XMLStructure parent, XMLCryptoContext context) throws InvalidAlgorithmParameterException { - LOG.log(POILogger.DEBUG, "init(parent,context)"); - LOG.log(POILogger.DEBUG, "parent java type: ", parent.getClass().getName()); + LOG.atDebug().log("init(parent,context)"); + LOG.atDebug().log("parent java type: {}", parent.getClass().getName()); DOMStructure domParent = (DOMStructure) parent; Node parentNode = domParent.getNode(); @@ -146,11 +147,11 @@ public class RelationshipTransformService extends TransformService { TransformDocument transDoc = TransformDocument.Factory.parse(parentNode, DEFAULT_XML_OPTIONS); XmlObject[] xoList = transDoc.getTransform().selectChildren(RelationshipReferenceDocument.type.getDocumentElementName()); if (xoList.length == 0) { - LOG.log(POILogger.WARN, "no RelationshipReference/@SourceId parameters present"); + LOG.atWarn().log("no RelationshipReference/@SourceId parameters present"); } for (XmlObject xo : xoList) { String sourceId = ((CTRelationshipReference)xo).getSourceId(); - LOG.log(POILogger.DEBUG, "sourceId: ", sourceId); + LOG.atDebug().log("sourceId: {}", sourceId); this.sourceIds.add(sourceId); } } catch (XmlException e) { @@ -160,7 +161,7 @@ public class RelationshipTransformService extends TransformService { @Override public void marshalParams(XMLStructure parent, XMLCryptoContext context) throws MarshalException { - LOG.log(POILogger.DEBUG, "marshallParams(parent,context)"); + LOG.atDebug().log("marshallParams(parent,context)"); DOMStructure domParent = (DOMStructure) parent; Element parentNode = (Element)domParent.getNode(); Document doc = parentNode.getOwnerDocument(); @@ -174,7 +175,7 @@ public class RelationshipTransformService extends TransformService { } public AlgorithmParameterSpec getParameterSpec() { - LOG.log(POILogger.DEBUG, "getParameterSpec"); + LOG.atDebug().log("getParameterSpec"); return null; } @@ -186,10 +187,10 @@ public class RelationshipTransformService extends TransformService { * @see <a href="https://stackoverflow.com/questions/36063375">XML Relationship Transform Algorithm</a> */ public Data transform(Data data, XMLCryptoContext context) throws TransformException { - LOG.log(POILogger.DEBUG, "transform(data,context)"); - LOG.log(POILogger.DEBUG, "data java type: ", data.getClass().getName()); + LOG.atDebug().log("transform(data,context)"); + LOG.atDebug().log("data java type: {}", data.getClass().getName()); OctetStreamData octetStreamData = (OctetStreamData) data; - LOG.log(POILogger.DEBUG, "URI: ", octetStreamData.getURI()); + LOG.atDebug().log("URI: {}", octetStreamData.getURI()); InputStream octetStream = octetStreamData.getOctetStream(); Document doc; @@ -223,18 +224,18 @@ public class RelationshipTransformService extends TransformService { root.appendChild(el); } - LOG.log(POILogger.DEBUG, "# Relationship elements: ", rsList.size()); + LOG.atDebug().log("# Relationship elements: {}", box(rsList.size())); return new ApacheNodeSetData(new XMLSignatureInput(root)); } public Data transform(Data data, XMLCryptoContext context, OutputStream os) throws TransformException { - LOG.log(POILogger.DEBUG, "transform(data,context,os)"); + LOG.atDebug().log("transform(data,context,os)"); return null; } public boolean isFeatureSupported(String feature) { - LOG.log(POILogger.DEBUG, "isFeatureSupported(feature)"); + LOG.atDebug().log("isFeatureSupported(feature)"); return false; } } diff --git a/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/services/TSPTimeStampService.java b/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/services/TSPTimeStampService.java index fce674f86d..945cf9f709 100644 --- a/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/services/TSPTimeStampService.java +++ b/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/services/TSPTimeStampService.java @@ -44,14 +44,15 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.message.SimpleMessage; import org.apache.poi.poifs.crypt.CryptoFunctions; import org.apache.poi.poifs.crypt.HashAlgorithm; import org.apache.poi.poifs.crypt.dsig.SignatureConfig; import org.apache.poi.poifs.crypt.dsig.SignatureInfo; 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.bouncycastle.asn1.ASN1ObjectIdentifier; import org.bouncycastle.asn1.cmp.PKIFailureInfo; import org.bouncycastle.asn1.nist.NISTObjectIdentifiers; @@ -71,6 +72,8 @@ import org.bouncycastle.tsp.TimeStampRequestGenerator; import org.bouncycastle.tsp.TimeStampResponse; import org.bouncycastle.tsp.TimeStampToken; +import static org.apache.logging.log4j.util.Unbox.box; + /** * A TSP time-stamp service implementation. * @@ -79,7 +82,7 @@ import org.bouncycastle.tsp.TimeStampToken; */ public class TSPTimeStampService implements TimeStampService { - private static final POILogger LOG = POILogFactory.getLogger(TSPTimeStampService.class); + private static final Logger LOG = LogManager.getLogger(TSPTimeStampService.class); /** * Maps the digest algorithm to corresponding OID value. @@ -151,10 +154,10 @@ public class TSPTimeStampService implements TimeStampService { int statusCode = huc.getResponseCode(); if (statusCode != 200) { - LOG.log(POILogger.ERROR, "Error contacting TSP server ", signatureConfig.getTspUrl(), - ", had status code ", statusCode, "/", huc.getResponseMessage()); - throw new IOException("Error contacting TSP server " + signatureConfig.getTspUrl() + - ", had status code " + statusCode + "/" + huc.getResponseMessage()); + final String message = "Error contacting TSP server " + signatureConfig.getTspUrl() + + ", had status code " + statusCode + "/" + huc.getResponseMessage(); + LOG.atError().log(message); + throw new IOException(message); } // HTTP input validation @@ -165,7 +168,7 @@ public class TSPTimeStampService implements TimeStampService { bos = new ByteArrayOutputStream(); IOUtils.copy(huc.getInputStream(), bos); - LOG.log(POILogger.DEBUG, "response content: ", HexDump.dump(bos.toByteArray(), 0, 0)); + LOG.atDebug().log(() -> new SimpleMessage("response content: " + HexDump.dump(bos.toByteArray(), 0, 0))); } finally { huc.disconnect(); } @@ -188,13 +191,13 @@ public class TSPTimeStampService implements TimeStampService { timeStampResponse.validate(request); if (0 != timeStampResponse.getStatus()) { - LOG.log(POILogger.DEBUG, "status: ", timeStampResponse.getStatus()); - LOG.log(POILogger.DEBUG, "status string: ", timeStampResponse.getStatusString()); + LOG.atDebug().log("status: {}", box(timeStampResponse.getStatus())); + LOG.atDebug().log("status string: {}", timeStampResponse.getStatusString()); PKIFailureInfo failInfo = timeStampResponse.getFailInfo(); if (null != failInfo) { - LOG.log(POILogger.DEBUG, "fail info int value: ", failInfo.intValue()); + LOG.atDebug().log("fail info int value: {}", box(failInfo.intValue())); if (/*PKIFailureInfo.unacceptedPolicy*/(1 << 8) == failInfo.intValue()) { - LOG.log(POILogger.DEBUG, "unaccepted policy"); + LOG.atDebug().log("unaccepted policy"); } } throw new RuntimeException("timestamp response status != 0: " @@ -204,8 +207,8 @@ public class TSPTimeStampService implements TimeStampService { SignerId signerId = timeStampToken.getSID(); BigInteger signerCertSerialNumber = signerId.getSerialNumber(); X500Name signerCertIssuer = signerId.getIssuer(); - LOG.log(POILogger.DEBUG, "signer cert serial number: ", signerCertSerialNumber); - LOG.log(POILogger.DEBUG, "signer cert issuer: ", signerCertIssuer); + LOG.atDebug().log("signer cert serial number: {}", signerCertSerialNumber); + LOG.atDebug().log("signer cert issuer: {}", signerCertIssuer); // TSP signer certificates retrieval Collection<X509CertificateHolder> certificates = timeStampToken.getCertificates().getMatches(null); @@ -229,7 +232,7 @@ public class TSPTimeStampService implements TimeStampService { x509converter.setProvider("BC"); X509CertificateHolder certificate = signerCert; do { - LOG.log(POILogger.DEBUG, "adding to certificate chain: ", certificate.getSubject()); + LOG.atDebug().log("adding to certificate chain: {}", certificate.getSubject()); tspCertificateChain.add(x509converter.getCertificate(certificate)); if (certificate.getSubject().equals(certificate.getIssuer())) { break; @@ -253,8 +256,7 @@ public class TSPTimeStampService implements TimeStampService { signatureConfig.getTspValidator().validate(tspCertificateChain, revocationData); } - LOG.log(POILogger.DEBUG, "time-stamp token time: ", - timeStampToken.getTimeStampInfo().getGenTime()); + LOG.atDebug().log("time-stamp token time: {}", timeStampToken.getTimeStampInfo().getGenTime()); return timeStampToken.getEncoded(); } diff --git a/src/ooxml/java/org/apache/poi/poifs/crypt/temp/AesZipFileZipEntrySource.java b/src/ooxml/java/org/apache/poi/poifs/crypt/temp/AesZipFileZipEntrySource.java index 454d17f82a..2fb1749d4b 100644 --- a/src/ooxml/java/org/apache/poi/poifs/crypt/temp/AesZipFileZipEntrySource.java +++ b/src/ooxml/java/org/apache/poi/poifs/crypt/temp/AesZipFileZipEntrySource.java @@ -36,14 +36,14 @@ import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream; import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream; import org.apache.commons.compress.archivers.zip.ZipFile; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.openxml4j.util.ZipEntrySource; import org.apache.poi.poifs.crypt.ChainingMode; import org.apache.poi.poifs.crypt.CipherAlgorithm; import org.apache.poi.poifs.crypt.CryptoFunctions; import org.apache.poi.util.Beta; import org.apache.poi.util.IOUtils; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; import org.apache.poi.util.TempFile; /** @@ -52,7 +52,7 @@ import org.apache.poi.util.TempFile; */ @Beta public final class AesZipFileZipEntrySource implements ZipEntrySource { - private static final POILogger LOG = POILogFactory.getLogger(AesZipFileZipEntrySource.class); + private static final Logger LOG = LogManager.getLogger(AesZipFileZipEntrySource.class); private static final String PADDING = "PKCS5Padding"; @@ -93,7 +93,7 @@ public final class AesZipFileZipEntrySource implements ZipEntrySource { if(!closed) { zipFile.close(); if (!tmpFile.delete()) { - LOG.log(POILogger.WARN, tmpFile.getAbsolutePath()+" can't be removed (or was already removed."); + LOG.atWarn().log("{} can't be removed (or was already removed.", tmpFile.getAbsolutePath()); } } closed = true; diff --git a/src/ooxml/java/org/apache/poi/poifs/crypt/temp/EncryptedTempData.java b/src/ooxml/java/org/apache/poi/poifs/crypt/temp/EncryptedTempData.java index a2d900bf7d..e1ea120e09 100644 --- a/src/ooxml/java/org/apache/poi/poifs/crypt/temp/EncryptedTempData.java +++ b/src/ooxml/java/org/apache/poi/poifs/crypt/temp/EncryptedTempData.java @@ -32,12 +32,12 @@ import javax.crypto.CipherInputStream; import javax.crypto.CipherOutputStream; import javax.crypto.spec.SecretKeySpec; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.poifs.crypt.ChainingMode; import org.apache.poi.poifs.crypt.CipherAlgorithm; import org.apache.poi.poifs.crypt.CryptoFunctions; import org.apache.poi.util.Beta; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; import org.apache.poi.util.TempFile; /** @@ -45,8 +45,8 @@ import org.apache.poi.util.TempFile; */ @Beta public class EncryptedTempData { - private static POILogger LOG = POILogFactory.getLogger(EncryptedTempData.class); - + private static Logger LOG = LogManager.getLogger(EncryptedTempData.class); + private static final CipherAlgorithm cipherAlgorithm = CipherAlgorithm.aes128; private static final String PADDING = "PKCS5Padding"; private final SecretKeySpec skeySpec; @@ -91,7 +91,7 @@ public class EncryptedTempData { */ public void dispose() { if (!tempFile.delete()) { - LOG.log(POILogger.WARN, tempFile.getAbsolutePath()+" can't be removed (or was already removed."); + LOG.atWarn().log("{} can't be removed (or was already removed).", tempFile.getAbsolutePath()); } } } diff --git a/src/ooxml/java/org/apache/poi/poifs/crypt/temp/SXSSFWorkbookWithCustomZipEntrySource.java b/src/ooxml/java/org/apache/poi/poifs/crypt/temp/SXSSFWorkbookWithCustomZipEntrySource.java index 01a0b21e18..4ca8b864ee 100644 --- a/src/ooxml/java/org/apache/poi/poifs/crypt/temp/SXSSFWorkbookWithCustomZipEntrySource.java +++ b/src/ooxml/java/org/apache/poi/poifs/crypt/temp/SXSSFWorkbookWithCustomZipEntrySource.java @@ -22,17 +22,19 @@ package org.apache.poi.poifs.crypt.temp; import java.io.IOException; import java.io.OutputStream; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.openxml4j.util.ZipEntrySource; import org.apache.poi.util.Beta; import org.apache.poi.util.IOUtils; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; import org.apache.poi.xssf.streaming.SXSSFWorkbook; import org.apache.poi.xssf.streaming.SheetDataWriter; +import static org.apache.logging.log4j.util.Unbox.box; + @Beta public class SXSSFWorkbookWithCustomZipEntrySource extends SXSSFWorkbook { - private static final POILogger LOG = POILogFactory.getLogger(SXSSFWorkbookWithCustomZipEntrySource.class); + private static final Logger LOG = LogManager.getLogger(SXSSFWorkbookWithCustomZipEntrySource.class); public SXSSFWorkbookWithCustomZipEntrySource() { super(20); @@ -60,8 +62,8 @@ public class SXSSFWorkbookWithCustomZipEntrySource extends SXSSFWorkbook { @Override protected SheetDataWriter createSheetDataWriter() throws IOException { //log values to ensure these values are accessible to subclasses - LOG.log(POILogger.INFO, "isCompressTempFiles: ", isCompressTempFiles()); - LOG.log(POILogger.INFO, "SharedStringSource: ", getSharedStringSource()); + LOG.atInfo().log("isCompressTempFiles: {}", box(isCompressTempFiles())); + LOG.atInfo().log("SharedStringSource: {}", getSharedStringSource()); return new SheetDataWriterWithDecorator(); } } diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java index 4a355fead0..1f81dc34ee 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java @@ -16,6 +16,7 @@ ==================================================================== */ package org.apache.poi.xslf.usermodel; +import static org.apache.logging.log4j.util.Unbox.box; import static org.apache.poi.ooxml.POIXMLTypeLoader.DEFAULT_XML_OPTIONS; import java.awt.Dimension; @@ -34,6 +35,8 @@ import java.util.OptionalLong; import java.util.regex.Pattern; import java.util.stream.Stream; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.ooxml.POIXMLDocument; import org.apache.poi.ooxml.POIXMLDocumentPart; import org.apache.poi.ooxml.POIXMLException; @@ -50,8 +53,6 @@ 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.Units; import org.apache.xmlbeans.XmlException; import org.openxmlformats.schemas.presentationml.x2006.main.CTNotesMasterIdList; @@ -72,7 +73,7 @@ import org.openxmlformats.schemas.presentationml.x2006.main.PresentationDocument @Beta public class XMLSlideShow extends POIXMLDocument implements SlideShow<XSLFShape, XSLFTextParagraph> { - private static final POILogger LOG = POILogFactory.getLogger(XMLSlideShow.class); + private static final Logger LOG = LogManager.getLogger(XMLSlideShow.class); //arbitrarily selected; may need to increase private static final int MAX_RECORD_LENGTH = 1_000_000; @@ -167,7 +168,7 @@ public class XMLSlideShow extends POIXMLDocument _presentation.getSldIdLst().getSldIdList().forEach(id -> { XSLFSlide sh = shIdMap.get(id.getId2()); if (sh == null) { - LOG.log(POILogger.WARN, "Slide with r:id " + id.getId() + " was defined, but didn't exist in package, skipping"); + LOG.atWarn().log("Slide with r:id {} was defined, but didn't exist in package, skipping", box(id.getId())); } else { _slides.add(sh); } @@ -260,7 +261,7 @@ public class XMLSlideShow extends POIXMLDocument XSLFSlideMaster sm = _masters.get(0); XSLFSlideLayout layout = sm.getLayout(SlideLayout.BLANK); if (layout == null) { - LOG.log(POILogger.WARN, "Blank layout was not found - defaulting to first slide layout in master"); + LOG.atWarn().log("Blank layout was not found - defaulting to first slide layout in master"); XSLFSlideLayout[] sl = sm.getSlideLayouts(); if (sl.length == 0) { throw new POIXMLException("SlideMaster must contain a SlideLayout."); diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFColor.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFColor.java index cafb705a7e..c939383488 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFColor.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFColor.java @@ -22,6 +22,8 @@ import java.awt.Color; import javax.xml.namespace.QName; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.ooxml.util.POIXMLUnits; import org.apache.poi.sl.draw.DrawPaint; import org.apache.poi.sl.usermodel.AbstractColorStyle; @@ -29,8 +31,6 @@ import org.apache.poi.sl.usermodel.ColorStyle; import org.apache.poi.sl.usermodel.PresetColor; import org.apache.poi.util.Beta; import org.apache.poi.util.Internal; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; import org.apache.xmlbeans.XmlCursor; import org.apache.xmlbeans.XmlObject; import org.openxmlformats.schemas.drawingml.x2006.main.CTColor; @@ -50,7 +50,7 @@ import org.openxmlformats.schemas.drawingml.x2006.main.CTSystemColor; @Beta @Internal public class XSLFColor { - private static final POILogger LOGGER = POILogFactory.getLogger(XSLFColor.class); + private static final Logger LOGGER = LogManager.getLogger(XSLFColor.class); private static final QName VAL_ATTR = new QName("val"); private final XmlObject _xmlObject; @@ -187,7 +187,7 @@ public class XSLFColor { @Internal protected void setColor(Color color) { if (!(_xmlObject instanceof CTSolidColorFillProperties)) { - LOGGER.log(POILogger.ERROR, "XSLFColor.setColor currently only supports CTSolidColorFillProperties"); + LOGGER.atError().log("XSLFColor.setColor currently only supports CTSolidColorFillProperties"); return; } CTSolidColorFillProperties fill = (CTSolidColorFillProperties)_xmlObject; diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFFreeformShape.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFFreeformShape.java index 13a4842735..593a4ee1ca 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFFreeformShape.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFFreeformShape.java @@ -27,14 +27,14 @@ import java.awt.geom.Rectangle2D; 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.ooxml.POIXMLTypeLoader; import org.apache.poi.ooxml.util.POIXMLUnits; import org.apache.poi.sl.draw.geom.CustomGeometry; import org.apache.poi.sl.draw.geom.PresetGeometries; import org.apache.poi.sl.usermodel.FreeformShape; import org.apache.poi.util.Beta; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; import org.apache.poi.util.Units; import org.apache.xmlbeans.XmlCursor; import org.apache.xmlbeans.XmlObject; @@ -62,7 +62,7 @@ import org.openxmlformats.schemas.presentationml.x2006.main.CTShapeNonVisual; public class XSLFFreeformShape extends XSLFAutoShape implements FreeformShape<XSLFShape,XSLFTextParagraph> { - private static final POILogger LOG = POILogFactory.getLogger(XSLFFreeformShape.class); + private static final Logger LOG = LogManager.getLogger(XSLFFreeformShape.class); /*package*/ XSLFFreeformShape(CTShape shape, XSLFSheet sheet) { super(shape, sheet); @@ -143,8 +143,7 @@ public class XSLFFreeformShape extends XSLFAutoShape try { staxReader.close(); } catch (XMLStreamException e) { - LOG.log(POILogger.WARN, - "An error occurred while closing a Custom Geometry XML Stream Reader: " + e.getMessage()); + LOG.atWarn().log("An error occurred while closing a Custom Geometry XML Stream Reader: {}", e.getMessage()); } return custGeo; @@ -177,7 +176,7 @@ public class XSLFFreeformShape extends XSLFAutoShape } else if (ch instanceof CTPath2DClose) { addClosePath(path); } else { - LOG.log(POILogger.WARN, "can't handle path of type "+xo.getClass()); + LOG.atWarn().log("can't handle path of type {}", xo.getClass()); } } while (cursor.toNextSibling()); } diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGraphicFrame.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGraphicFrame.java index 490908e35c..59109b7e32 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGraphicFrame.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGraphicFrame.java @@ -26,6 +26,8 @@ import java.io.IOException; import javax.xml.namespace.QName; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.ooxml.POIXMLException; import org.apache.poi.ooxml.util.POIXMLUnits; import org.apache.poi.openxml4j.exceptions.InvalidFormatException; @@ -34,8 +36,6 @@ import org.apache.poi.openxml4j.opc.PackageRelationship; import org.apache.poi.sl.usermodel.GraphicalFrame; import org.apache.poi.sl.usermodel.ShapeType; import org.apache.poi.util.Beta; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; import org.apache.poi.util.Units; import org.apache.xmlbeans.XmlCursor; import org.apache.xmlbeans.XmlException; @@ -51,7 +51,7 @@ import org.openxmlformats.schemas.presentationml.x2006.main.CTGroupShape; @Beta public class XSLFGraphicFrame extends XSLFShape implements GraphicalFrame<XSLFShape, XSLFTextParagraph> { private static final String DRAWINGML_CHART_URI = "http://schemas.openxmlformats.org/drawingml/2006/chart"; - private static final POILogger LOG = POILogFactory.getLogger(XSLFGraphicFrame.class); + private static final Logger LOG = LogManager.getLogger(XSLFGraphicFrame.class); /*package*/ XSLFGraphicFrame(CTGraphicalObjectFrame shape, XSLFSheet sheet){ super(shape,sheet); @@ -285,7 +285,7 @@ public class XSLFGraphicFrame extends XSLFShape implements GraphicalFrame<XSLFSh try { gs = CTGroupShape.Factory.parse(xo.newDomNode()); } catch (XmlException e) { - LOG.log(POILogger.WARN, "Can't parse fallback picture stream of graphical frame", e); + LOG.atWarn().withThrowable(e).log("Can't parse fallback picture stream of graphical frame"); return null; } diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGroupShape.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGroupShape.java index 0838d4e929..5cf47873f3 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGroupShape.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGroupShape.java @@ -25,14 +25,14 @@ 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.poi.ooxml.POIXMLDocumentPart.RelationPart; import org.apache.poi.ooxml.util.POIXMLUnits; import org.apache.poi.sl.draw.DrawPictureShape; import org.apache.poi.sl.usermodel.GroupShape; import org.apache.poi.sl.usermodel.PictureData; import org.apache.poi.util.Beta; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; import org.apache.poi.util.Units; import org.apache.xmlbeans.XmlObject; import org.openxmlformats.schemas.drawingml.x2006.main.CTGroupShapeProperties; @@ -56,7 +56,7 @@ import org.openxmlformats.schemas.presentationml.x2006.main.CTShape; @Beta public class XSLFGroupShape extends XSLFShape implements XSLFShapeContainer, GroupShape<XSLFShape,XSLFTextParagraph> { - private static final POILogger LOG = POILogFactory.getLogger(XSLFGroupShape.class); + private static final Logger LOG = LogManager.getLogger(XSLFGroupShape.class); private final List<XSLFShape> _shapes; private final CTGroupShapeProperties _grpSpPr; @@ -396,7 +396,7 @@ implements XSLFShapeContainer, GroupShape<XSLFShape,XSLFTextParagraph> { } else if (shape instanceof XSLFTable) { newShape = createTable(); } else { - LOG.log(POILogger.WARN, "copying of class "+shape.getClass()+" not supported."); + LOG.atWarn().log("copying of class {} not supported.", shape.getClass()); continue; } diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFPictureShape.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFPictureShape.java index 848c8c86c3..9c4fc5902e 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFPictureShape.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFPictureShape.java @@ -35,6 +35,8 @@ import javax.imageio.ImageIO; import javax.xml.namespace.QName; import javax.xml.stream.XMLStreamReader; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.ooxml.util.POIXMLUnits; import org.apache.poi.ooxml.util.XPathHelper; import org.apache.poi.openxml4j.opc.PackagePart; @@ -44,8 +46,6 @@ import org.apache.poi.sl.usermodel.PictureData.PictureType; import org.apache.poi.sl.usermodel.PictureShape; import org.apache.poi.sl.usermodel.Placeholder; import org.apache.poi.util.Beta; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; import org.apache.poi.util.Units; import org.apache.poi.xslf.draw.SVGImageRenderer; import org.apache.xmlbeans.XmlCursor; @@ -70,7 +70,7 @@ import org.openxmlformats.schemas.presentationml.x2006.main.CTPictureNonVisual; @Beta public class XSLFPictureShape extends XSLFSimpleShape implements PictureShape<XSLFShape,XSLFTextParagraph> { - private static final POILogger LOG = POILogFactory.getLogger(XSLFPictureShape.class); + private static final Logger LOG = LogManager.getLogger(XSLFPictureShape.class); private static final String MS_DML_NS = "http://schemas.microsoft.com/office/drawing/2010/main"; private static final String MS_SVG_NS = "http://schemas.microsoft.com/office/drawing/2016/SVG/main"; @@ -357,7 +357,7 @@ public class XSLFPictureShape extends XSLFSimpleShape XSLFPictureShape p = (XSLFPictureShape)sh; String blipId = p.getBlipId(); if (blipId == null) { - LOG.log(POILogger.WARN, "unable to copy invalid picture shape"); + LOG.atWarn().log("unable to copy invalid picture shape"); return; } diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFPropertiesDelegate.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFPropertiesDelegate.java index bce5af4d6b..bc1aee7850 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFPropertiesDelegate.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFPropertiesDelegate.java @@ -17,9 +17,9 @@ package org.apache.poi.xslf.usermodel; +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.xmlbeans.XmlCursor; import org.apache.xmlbeans.XmlObject; import org.openxmlformats.schemas.drawingml.x2006.main.CTBlipFillProperties; @@ -50,9 +50,9 @@ import org.openxmlformats.schemas.presentationml.x2006.main.CTBackgroundProperti */ @Internal /* package */ class XSLFPropertiesDelegate { - private static final POILogger LOG = POILogFactory.getLogger(XSLFPropertiesDelegate.class); + private static final Logger LOG = LogManager.getLogger(XSLFPropertiesDelegate.class); + - public static XSLFFillProperties getFillDelegate(XmlObject props) { return getDelegate(XSLFFillProperties.class, props); } @@ -1848,15 +1848,15 @@ import org.openxmlformats.schemas.presentationml.x2006.main.CTBackgroundProperti } else if (props instanceof CTTextCharacterProperties) { obj = new TextCharDelegate((CTTextCharacterProperties)props); } else { - LOG.log(POILogger.ERROR, props.getClass(), " is an unknown properties type"); + LOG.atError().log("{} is an unknown properties type", props.getClass()); return null; } if (clazz.isInstance(obj)) { return (T)obj; } - - LOG.log(POILogger.WARN, obj.getClass() +" doesn't implement "+ clazz); + + LOG.atWarn().log("{} doesn't implement {}", obj.getClass(), clazz); return null; } } diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSheet.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSheet.java index 59945d51db..1364cd7228 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSheet.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSheet.java @@ -16,10 +16,10 @@ ==================================================================== */ package org.apache.poi.xslf.usermodel; +import static org.apache.logging.log4j.util.Unbox.box; import static org.apache.poi.ooxml.POIXMLTypeLoader.DEFAULT_XML_OPTIONS; -import java.awt.Dimension; -import java.awt.Graphics2D; +import java.awt.*; import java.awt.geom.Rectangle2D; import java.io.IOException; import java.io.InputStream; @@ -33,6 +33,8 @@ import java.util.Map; import javax.xml.namespace.QName; import com.zaxxer.sparsebits.SparseBitSet; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.ooxml.POIXMLDocumentPart; import org.apache.poi.ooxml.POIXMLException; import org.apache.poi.openxml4j.opc.OPCPackage; @@ -50,8 +52,6 @@ import org.apache.poi.sl.usermodel.Sheet; import org.apache.poi.util.Beta; import org.apache.poi.util.IOUtils; import org.apache.poi.util.Internal; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; import org.apache.poi.util.Units; import org.apache.poi.xddf.usermodel.chart.XDDFChart; import org.apache.xmlbeans.XmlCursor; @@ -73,7 +73,7 @@ import org.openxmlformats.schemas.presentationml.x2006.main.CTShape; @Beta public abstract class XSLFSheet extends POIXMLDocumentPart implements XSLFShapeContainer, Sheet<XSLFShape,XSLFTextParagraph> { - private static POILogger LOG = POILogFactory.getLogger(XSLFSheet.class); + private static Logger LOG = LogManager.getLogger(XSLFSheet.class); private XSLFDrawing _drawing; private List<XSLFShape> _shapes; @@ -122,7 +122,7 @@ implements XSLFShapeContainer, Sheet<XSLFShape,XSLFTextParagraph> { @SuppressWarnings("WeakerAccess") protected void registerShapeId(final int shapeId) { if (shapeIds.get(shapeId)) { - LOG.log(POILogger.WARN, "shape id "+shapeId+" has been already used."); + LOG.atWarn().log("shape id {} has been already used.", box(shapeId)); } shapeIds.set(shapeId); } @@ -130,7 +130,7 @@ implements XSLFShapeContainer, Sheet<XSLFShape,XSLFTextParagraph> { @SuppressWarnings("WeakerAccess") protected void deregisterShapeId(final int shapeId) { if (!shapeIds.get(shapeId)) { - LOG.log(POILogger.WARN, "shape id "+shapeId+" hasn't been registered."); + LOG.atWarn().log("shape id {} hasn't been registered.", box(shapeId)); } shapeIds.clear(shapeId); } @@ -168,7 +168,7 @@ implements XSLFShapeContainer, Sheet<XSLFShape,XSLFTextParagraph> { CTGroupShape grp = CTGroupShape.Factory.parse(cur.newXMLStreamReader()); shapes.addAll(buildShapes(grp, parent)); } catch (XmlException e) { - LOG.log(POILogger.DEBUG, "unparsable alternate content", e); + LOG.atDebug().withThrowable(e).log("unparsable alternate content"); } } cur.pop(); @@ -726,7 +726,7 @@ implements XSLFShapeContainer, Sheet<XSLFShape,XSLFTextParagraph> { * @since POI 4.1.0 */ public void addChart(XSLFChart chart) { - Rectangle2D rect2D = new java.awt.Rectangle(XDDFChart.DEFAULT_X, XDDFChart.DEFAULT_Y, + Rectangle2D rect2D = new Rectangle(XDDFChart.DEFAULT_X, XDDFChart.DEFAULT_Y, XDDFChart.DEFAULT_WIDTH, XDDFChart.DEFAULT_HEIGHT); this.addChart(chart, rect2D); diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSimpleShape.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSimpleShape.java index 0f4448a3af..f7424d1807 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSimpleShape.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSimpleShape.java @@ -25,6 +25,8 @@ import java.awt.geom.Rectangle2D; 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.ooxml.util.POIXMLUnits; import org.apache.poi.openxml4j.opc.PackagePart; import org.apache.poi.sl.draw.DrawPaint; @@ -44,8 +46,6 @@ import org.apache.poi.sl.usermodel.StrokeStyle.LineCap; import org.apache.poi.sl.usermodel.StrokeStyle.LineCompound; import org.apache.poi.sl.usermodel.StrokeStyle.LineDash; import org.apache.poi.util.Beta; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; import org.apache.poi.util.Units; import org.apache.poi.xslf.model.PropertyFetcher; import org.apache.poi.xslf.usermodel.XSLFPropertiesDelegate.XSLFEffectProperties; @@ -61,7 +61,7 @@ import org.openxmlformats.schemas.drawingml.x2006.main.*; public abstract class XSLFSimpleShape extends XSLFShape implements SimpleShape<XSLFShape,XSLFTextParagraph> { private static final CTOuterShadowEffect NO_SHADOW = CTOuterShadowEffect.Factory.newInstance(); - private static final POILogger LOG = POILogFactory.getLogger(XSLFSimpleShape.class); + private static final Logger LOG = LogManager.getLogger(XSLFSimpleShape.class); /* package */XSLFSimpleShape(XmlObject shape, XSLFSheet sheet) { super(shape,sheet); @@ -115,7 +115,7 @@ public abstract class XSLFSimpleShape extends XSLFShape return ((CTShapeProperties)xo).addNewXfrm(); } else { // ... group shapes have their own getXfrm() - LOG.log(POILogger.WARN, getClass() +" doesn't have xfrm element."); + LOG.atWarn().log("{} doesn't have xfrm element.", getClass()); return null; } } @@ -715,8 +715,7 @@ public abstract class XSLFSimpleShape extends XSLFShape staxReader.close(); } catch (XMLStreamException e) { - LOG.log(POILogger.WARN, - "An error occurred while closing a Custom Geometry XML Stream Reader: " + e.getMessage()); + LOG.atWarn().log("An error occurred while closing a Custom Geometry XML Stream Reader: {}", e.getMessage()); } } else { geom = dict.get("rect"); @@ -1114,7 +1113,7 @@ public abstract class XSLFSimpleShape extends XSLFShape private static CTLineProperties getLn(XSLFShape shape, boolean create) { XmlObject pr = shape.getShapeProperties(); if (!(pr instanceof CTShapeProperties)) { - LOG.log(POILogger.WARN, shape.getClass() +" doesn't have line properties"); + LOG.atWarn().log("{} doesn't have line properties", shape.getClass()); return null; } diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextRun.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextRun.java index 930e9abfa3..ea1c179d66 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextRun.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextRun.java @@ -19,6 +19,8 @@ package org.apache.poi.xslf.usermodel; import java.awt.Color; import java.util.function.Consumer; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.common.usermodel.fonts.FontCharset; import org.apache.poi.common.usermodel.fonts.FontFamily; import org.apache.poi.common.usermodel.fonts.FontGroup; @@ -33,8 +35,6 @@ import org.apache.poi.sl.usermodel.PaintStyle.SolidPaint; import org.apache.poi.sl.usermodel.TextRun; import org.apache.poi.util.Beta; import org.apache.poi.util.Internal; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; import org.apache.poi.util.Units; import org.apache.poi.xslf.model.CharacterPropertyFetcher; import org.apache.poi.xslf.model.CharacterPropertyFetcher.CharPropFetcher; @@ -62,7 +62,7 @@ import org.openxmlformats.schemas.drawingml.x2006.main.STTextUnderlineType; */ @Beta public class XSLFTextRun implements TextRun { - private static final POILogger LOG = POILogFactory.getLogger(XSLFTextRun.class); + private static final Logger LOG = LogManager.getLogger(XSLFTextRun.class); private final XmlObject _r; private final XSLFTextParagraph _p; @@ -114,7 +114,7 @@ public class XSLFTextRun implements TextRun { @Override public void setFontColor(PaintStyle color) { if (!(color instanceof SolidPaint)) { - LOG.log(POILogger.WARN, "Currently only SolidPaint is supported!"); + LOG.atWarn().log("Currently only SolidPaint is supported!"); return; } SolidPaint sp = (SolidPaint)color; diff --git a/src/ooxml/java/org/apache/poi/xssf/binary/XSSFBRelation.java b/src/ooxml/java/org/apache/poi/xssf/binary/XSSFBRelation.java index e86fd58a88..94599bc5aa 100644 --- a/src/ooxml/java/org/apache/poi/xssf/binary/XSSFBRelation.java +++ b/src/ooxml/java/org/apache/poi/xssf/binary/XSSFBRelation.java @@ -17,14 +17,15 @@ package org.apache.poi.xssf.binary; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.ooxml.POIXMLRelation; import org.apache.poi.openxml4j.opc.PackageRelationshipTypes; import org.apache.poi.util.Internal; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; +import org.apache.poi.xssf.usermodel.XSSFRelation; /** - * Need to have this mirror class of {@link org.apache.poi.xssf.usermodel.XSSFRelation} + * Need to have this mirror class of {@link XSSFRelation} * because of conflicts with regular ooxml relations. * If we failed to break this into a separate class, in the cases of SharedStrings and Styles, * 2 parts would exist, and "Packages shall not contain equivalent part names..." @@ -33,7 +34,7 @@ import org.apache.poi.util.POILogger; */ @Internal public class XSSFBRelation extends POIXMLRelation { - private static final POILogger log = POILogFactory.getLogger(XSSFBRelation.class); + private static final Logger LOGGER = LogManager.getLogger(XSSFBRelation.class); static final XSSFBRelation SHARED_STRINGS_BINARY = new XSSFBRelation( "application/vnd.ms-excel.sharedStrings", diff --git a/src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFBReader.java b/src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFBReader.java index b1d7700082..6d4c2eb0b3 100644 --- a/src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFBReader.java +++ b/src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFBReader.java @@ -28,6 +28,8 @@ import java.util.List; import java.util.Set; import com.zaxxer.sparsebits.SparseBitSet; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import org.apache.poi.openxml4j.exceptions.OpenXML4JException; import org.apache.poi.openxml4j.opc.OPCPackage; @@ -38,8 +40,6 @@ import org.apache.poi.openxml4j.opc.PackageRelationshipCollection; import org.apache.poi.openxml4j.opc.PackagingURIHelper; 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.xssf.binary.XSSFBCommentsTable; import org.apache.poi.xssf.binary.XSSFBParseException; import org.apache.poi.xssf.binary.XSSFBParser; @@ -57,7 +57,7 @@ import org.apache.poi.xssf.usermodel.XSSFRelation; */ public class XSSFBReader extends XSSFReader { - private static final POILogger log = POILogFactory.getLogger(XSSFBReader.class); + private static final Logger LOGGER = LogManager.getLogger(XSSFBReader.class); private static final Set<String> WORKSHEET_RELS = Collections.unmodifiableSet(new HashSet<>( Arrays.asList(new String[]{ @@ -224,7 +224,7 @@ public class XSSFBReader extends XSSFReader { tryToAddWorksheet(data); } catch (XSSFBParseException e) { if (tryOldFormat(data)) { - log.log(POILogger.WARN, "This file was written with a beta version of Excel. "+ + LOGGER.atWarn().log("This file was written with a beta version of Excel. "+ "POI will try to parse the file as a regular xlsb."); } else { throw e; diff --git a/src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFReader.java b/src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFReader.java index 58dc00a5b0..d31c489e81 100644 --- a/src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFReader.java +++ b/src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFReader.java @@ -31,6 +31,8 @@ import java.util.Set; import javax.xml.parsers.ParserConfigurationException; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.ooxml.POIXMLException; import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import org.apache.poi.openxml4j.exceptions.OpenXML4JException; @@ -41,8 +43,6 @@ import org.apache.poi.openxml4j.opc.PackageRelationship; import org.apache.poi.openxml4j.opc.PackageRelationshipCollection; import org.apache.poi.openxml4j.opc.PackageRelationshipTypes; import org.apache.poi.openxml4j.opc.PackagingURIHelper; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; import org.apache.poi.util.XMLHelper; import org.apache.poi.xssf.model.CommentsTable; import org.apache.poi.xssf.model.SharedStringsTable; @@ -73,7 +73,7 @@ public class XSSFReader { XSSFRelation.CHARTSHEET.getRelation(), XSSFRelation.MACRO_SHEET_BIN.getRelation()) )); - private static final POILogger LOGGER = POILogFactory.getLogger(XSSFReader.class); + private static final Logger LOGGER = LogManager.getLogger(XSSFReader.class); protected OPCPackage pkg; protected PackagePart workbookPart; @@ -356,7 +356,7 @@ public class XSSFReader { return parseComments(commentsPart); } } catch (InvalidFormatException|IOException e) { - LOGGER.log(POILogger.WARN, e); + LOGGER.atWarn().withThrowable(e).log("Failed to load sheet comments"); return null; } return null; @@ -383,14 +383,14 @@ public class XSSFReader { PackagePart drawingsPart = sheetPkg.getPackage().getPart(drawingsName); if (drawingsPart == null) { //parts can go missing; Excel ignores them silently -- TIKA-2134 - LOGGER.log(POILogger.WARN, "Missing drawing: " + drawingsName + ". Skipping it."); + LOGGER.atWarn().log("Missing drawing: {}. Skipping it.", drawingsName); continue; } XSSFDrawing drawing = new XSSFDrawing(drawingsPart); shapes.addAll(drawing.getShapes()); } } catch (XmlException|InvalidFormatException|IOException e) { - LOGGER.log(POILogger.WARN, e); + LOGGER.atWarn().withThrowable(e).log("Failed to load shapes"); return null; } return shapes; diff --git a/src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFSheetXMLHandler.java b/src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFSheetXMLHandler.java index 302f22f89d..1cbb4d4fc3 100644 --- a/src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFSheetXMLHandler.java +++ b/src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFSheetXMLHandler.java @@ -22,12 +22,12 @@ import java.util.Iterator; import java.util.LinkedList; import java.util.Queue; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.ss.usermodel.BuiltinFormats; import org.apache.poi.ss.usermodel.DataFormatter; import org.apache.poi.ss.usermodel.RichTextString; import org.apache.poi.ss.util.CellAddress; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; import org.apache.poi.xssf.model.*; import org.apache.poi.xssf.usermodel.XSSFCellStyle; import org.apache.poi.xssf.usermodel.XSSFComment; @@ -48,7 +48,7 @@ import org.xml.sax.helpers.DefaultHandler; * you need to implement for reading information from a file. */ public class XSSFSheetXMLHandler extends DefaultHandler { - private static final POILogger LOG = POILogFactory.getLogger(XSSFSheetXMLHandler.class); + private static final Logger LOG = LogManager.getLogger(XSSFSheetXMLHandler.class); /** * These are the different kinds of cells we support. @@ -235,7 +235,7 @@ public class XSSFSheetXMLHandler extends DefaultHandler { // TODO Retrieve the shared formula and tweak it to // match the current cell if(formulasNotResults) { - LOG.log(POILogger.WARN, "shared formulas not yet supported!"); + LOG.atWarn().log("shared formulas not yet supported!"); } /*else { // It's a shared formula, so we can't get at the formula string yet // However, they don't care about the formula string, so that's ok! @@ -418,7 +418,7 @@ public class XSSFSheetXMLHandler extends DefaultHandler { thisStr = rtss.toString(); } catch (NumberFormatException ex) { - LOG.log(POILogger.ERROR, "Failed to parse SST index '", sstIndex, ex); + LOG.atError().withThrowable(ex).log("Failed to parse SST index '{}'", sstIndex); } break; diff --git a/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFBEventBasedExcelExtractor.java b/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFBEventBasedExcelExtractor.java index 9375572ab8..817ed64a1e 100644 --- a/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFBEventBasedExcelExtractor.java +++ b/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFBEventBasedExcelExtractor.java @@ -19,11 +19,11 @@ package org.apache.poi.xssf.extractor; import java.io.IOException; import java.io.InputStream; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.openxml4j.exceptions.OpenXML4JException; import org.apache.poi.openxml4j.opc.OPCPackage; import org.apache.poi.ss.usermodel.DataFormatter; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; import org.apache.poi.xssf.binary.XSSFBCommentsTable; import org.apache.poi.xssf.binary.XSSFBHyperlinksTable; import org.apache.poi.xssf.binary.XSSFBSharedStringsTable; @@ -44,7 +44,7 @@ import org.xml.sax.SAXException; */ public class XSSFBEventBasedExcelExtractor extends XSSFEventBasedExcelExtractor { - private static final POILogger LOGGER = POILogFactory.getLogger(XSSFBEventBasedExcelExtractor.class); + private static final Logger LOGGER = LogManager.getLogger(XSSFBEventBasedExcelExtractor.class); public static final XSSFRelation[] SUPPORTED_TYPES = new XSSFRelation[]{ XSSFRelation.XLSB_BINARY_WORKBOOK @@ -139,7 +139,7 @@ public class XSSFBEventBasedExcelExtractor extends XSSFEventBasedExcelExtractor return text.toString(); } catch (IOException | OpenXML4JException | SAXException e) { - LOGGER.log(POILogger.WARN, e); + LOGGER.atWarn().withThrowable(e).log("Failed to load text"); return null; } } diff --git a/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFEventBasedExcelExtractor.java b/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFEventBasedExcelExtractor.java index cfd295c2b9..35fcb58685 100644 --- a/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFEventBasedExcelExtractor.java +++ b/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFEventBasedExcelExtractor.java @@ -25,6 +25,8 @@ import java.util.Map; import javax.xml.parsers.ParserConfigurationException; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.ooxml.POIXMLDocument; import org.apache.poi.ooxml.POIXMLProperties; import org.apache.poi.ooxml.POIXMLProperties.CoreProperties; @@ -33,9 +35,9 @@ import org.apache.poi.ooxml.POIXMLProperties.ExtendedProperties; import org.apache.poi.ooxml.extractor.POIXMLTextExtractor; import org.apache.poi.openxml4j.exceptions.OpenXML4JException; import org.apache.poi.openxml4j.opc.OPCPackage; +import org.apache.poi.ss.extractor.ExcelExtractor; import org.apache.poi.ss.usermodel.DataFormatter; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; +import org.apache.poi.ss.usermodel.HeaderFooter; import org.apache.poi.util.XMLHelper; import org.apache.poi.xssf.eventusermodel.ReadOnlySharedStringsTable; import org.apache.poi.xssf.eventusermodel.XSSFReader; @@ -59,9 +61,9 @@ import org.xml.sax.XMLReader; * files that uses SAX event based parsing. */ public class XSSFEventBasedExcelExtractor - implements POIXMLTextExtractor, org.apache.poi.ss.extractor.ExcelExtractor { + implements POIXMLTextExtractor, ExcelExtractor { - private static final POILogger LOGGER = POILogFactory.getLogger(XSSFEventBasedExcelExtractor.class); + private static final Logger LOGGER = LogManager.getLogger(XSSFEventBasedExcelExtractor.class); protected final OPCPackage container; protected final POIXMLProperties properties; @@ -288,7 +290,7 @@ public class XSSFEventBasedExcelExtractor return text.toString(); } catch (IOException | OpenXML4JException | SAXException e) { - LOGGER.log(POILogger.WARN, e); + LOGGER.atWarn().withThrowable(e).log("Failed to load text"); return null; } } @@ -413,7 +415,7 @@ public class XSSFEventBasedExcelExtractor * they are appended in XSSFExcelExtractor. * * @see XSSFExcelExtractor#getText() - * @see org.apache.poi.hssf.extractor.ExcelExtractor#_extractHeaderFooter(org.apache.poi.ss.usermodel.HeaderFooter) + * @see org.apache.poi.hssf.extractor.ExcelExtractor#_extractHeaderFooter(HeaderFooter) */ void appendHeaderText(StringBuilder buffer) { appendHeaderFooterText(buffer, "firstHeader"); @@ -426,7 +428,7 @@ public class XSSFEventBasedExcelExtractor * they are appended in XSSFExcelExtractor. * * @see XSSFExcelExtractor#getText() - * @see org.apache.poi.hssf.extractor.ExcelExtractor#_extractHeaderFooter(org.apache.poi.ss.usermodel.HeaderFooter) + * @see org.apache.poi.hssf.extractor.ExcelExtractor#_extractHeaderFooter(HeaderFooter) */ void appendFooterText(StringBuilder buffer) { // append the text for each footer type in the same order diff --git a/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFExportToXml.java b/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFExportToXml.java index 3904b9fd19..d918ae1a65 100644 --- a/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFExportToXml.java +++ b/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFExportToXml.java @@ -38,12 +38,12 @@ import javax.xml.validation.Schema; import javax.xml.validation.SchemaFactory; import javax.xml.validation.Validator; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.ooxml.util.DocumentHelper; import org.apache.poi.ss.usermodel.CellType; import org.apache.poi.ss.usermodel.DateUtil; import org.apache.poi.util.LocaleUtil; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; import org.apache.poi.util.XMLHelper; import org.apache.poi.xssf.usermodel.XSSFCell; import org.apache.poi.xssf.usermodel.XSSFMap; @@ -79,7 +79,7 @@ import org.xml.sax.SAXException; * </ul> */ public class XSSFExportToXml implements Comparator<String>{ - private static final POILogger LOG = POILogFactory.getLogger(XSSFExportToXml.class); + private static final Logger LOG = LogManager.getLogger(XSSFExportToXml.class); @FunctionalInterface @@ -259,7 +259,7 @@ public class XSSFExportToXml implements Comparator<String>{ //if no exceptions where raised, the document is valid return true; } catch(IOException e) { - LOG.log(POILogger.ERROR, "document is not valid", e); + LOG.atError().withThrowable(e).log("document is not valid"); } return false; @@ -546,9 +546,9 @@ public class XSSFExportToXml implements Comparator<String>{ try { securityFeature.accept(name); } catch (Exception e) { - LOG.log(POILogger.WARN, "SchemaFactory feature unsupported", name, e); + LOG.atWarn().withThrowable(e).log("SchemaFactory feature ({}) unsupported", name); } catch (AbstractMethodError ame) { - LOG.log(POILogger.WARN, "Cannot set SchemaFactory feature because outdated XML parser in classpath", name, ame); + LOG.atWarn().withThrowable(ame).log("Cannot set SchemaFactory feature ({}) because outdated XML parser in classpath", name); } } } diff --git a/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFImportFromXML.java b/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFImportFromXML.java index 0295c3b707..4605ee04e0 100644 --- a/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFImportFromXML.java +++ b/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFImportFromXML.java @@ -35,13 +35,13 @@ import javax.xml.xpath.XPath; import javax.xml.xpath.XPathConstants; import javax.xml.xpath.XPathExpressionException; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.ooxml.util.DocumentHelper; import org.apache.poi.ooxml.util.XPathHelper; import org.apache.poi.ss.usermodel.DateUtil; import org.apache.poi.ss.util.CellReference; import org.apache.poi.util.LocaleUtil; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; import org.apache.poi.xssf.usermodel.XSSFCell; import org.apache.poi.xssf.usermodel.XSSFMap; import org.apache.poi.xssf.usermodel.XSSFRow; @@ -57,6 +57,8 @@ import org.w3c.dom.NodeList; import org.xml.sax.InputSource; import org.xml.sax.SAXException; +import static org.apache.logging.log4j.util.Unbox.box; + /** * Imports data from an external XML to an XLSX according to one of the mappings * defined.The output XML Schema must respect this limitations: @@ -70,7 +72,7 @@ public class XSSFImportFromXML { private final XSSFMap _map; - private static final POILogger LOG = POILogFactory.getLogger(XSSFImportFromXML.class); + private static final Logger LOG = LogManager.getLogger(XSSFImportFromXML.class); public XSSFImportFromXML(XSSFMap map) { _map = map; @@ -109,10 +111,9 @@ public class XSSFImportFromXML { // result can be null if value is optional (xsd:minOccurs=0), see bugzilla 55864 if (result != null) { String textContent = result.getTextContent(); - LOG.log(POILogger.DEBUG, "Extracting with xpath " + xpathString + " : value is '" + textContent + "'"); + LOG.atDebug().log("Extracting with xpath {} : value is '{}'", xpathString, textContent); XSSFCell cell = singleXmlCell.getReferencedCell(); - LOG.log(POILogger.DEBUG, "Setting '" + textContent + "' to cell " + cell.getColumnIndex() + "-" + cell.getRowIndex() + " in sheet " - + cell.getSheet().getSheetName()); + LOG.atDebug().log("Setting '{}' to cell {}-{} in sheet {}", textContent, box(cell.getColumnIndex()),box(cell.getRowIndex()),cell.getSheet().getSheetName()); setCellValue(textContent, cell, xmlDataType); } } @@ -147,7 +148,7 @@ public class XSSFImportFromXML { // TODO: convert the data to the cell format String value = (String) xpath.evaluate(localXPath, singleNode, XPathConstants.STRING); - LOG.log(POILogger.DEBUG, "Extracting with xpath " + localXPath + " : value is '" + value + "'"); + LOG.atDebug().log("Extracting with xpath {} : value is '{}'", localXPath, value); XSSFRow row = table.getXSSFSheet().getRow(rowId); if (row == null) { row = table.getXSSFSheet().createRow(rowId); @@ -157,8 +158,7 @@ public class XSSFImportFromXML { if (cell == null) { cell = row.createCell(columnId); } - LOG.log(POILogger.DEBUG, "Setting '" + value + "' to cell " + cell.getColumnIndex() + "-" + cell.getRowIndex() + " in sheet " - + table.getXSSFSheet().getSheetName()); + LOG.atDebug().log("Setting '{}' to cell {}-{} in sheet {}", value, box(cell.getColumnIndex()),box(cell.getRowIndex()),table.getXSSFSheet().getSheetName()); setCellValue(value, cell, xmlColumnPr.getXmlDataType()); } } diff --git a/src/ooxml/java/org/apache/poi/xssf/streaming/DeferredSXSSFWorkbook.java b/src/ooxml/java/org/apache/poi/xssf/streaming/DeferredSXSSFWorkbook.java index e3c66fa089..fb21c779c8 100644 --- a/src/ooxml/java/org/apache/poi/xssf/streaming/DeferredSXSSFWorkbook.java +++ b/src/ooxml/java/org/apache/poi/xssf/streaming/DeferredSXSSFWorkbook.java @@ -21,11 +21,11 @@ import java.io.IOException; import java.io.OutputStream; import java.util.Iterator; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.util.Beta; import org.apache.poi.util.NotImplemented; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; import org.apache.poi.xssf.usermodel.XSSFSheet; import org.apache.poi.xssf.usermodel.XSSFWorkbook; @@ -39,7 +39,7 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook; */ @Beta public class DeferredSXSSFWorkbook extends SXSSFWorkbook { - private static final POILogger LOG = POILogFactory.getLogger(DeferredSXSSFWorkbook.class); + private static final Logger LOG = LogManager.getLogger(DeferredSXSSFWorkbook.class); public DeferredSXSSFWorkbook() { this(null); @@ -161,7 +161,7 @@ public class DeferredSXSSFWorkbook extends SXSSFWorkbook { try { sxSheet.dispose(); } catch (IOException e) { - LOG.log(POILogger.WARN, e); + LOG.atWarn().withThrowable(e).log("Failed to cleanup old sheet"); } } } diff --git a/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFCreationHelper.java b/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFCreationHelper.java index 707b8ba365..d18177c032 100644 --- a/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFCreationHelper.java +++ b/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFCreationHelper.java @@ -17,6 +17,8 @@ package org.apache.poi.xssf.streaming; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.common.usermodel.HyperlinkType; import org.apache.poi.ss.usermodel.ClientAnchor; import org.apache.poi.ss.usermodel.CreationHelper; @@ -26,8 +28,6 @@ import org.apache.poi.ss.usermodel.Hyperlink; import org.apache.poi.ss.util.AreaReference; 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 org.apache.poi.xssf.usermodel.XSSFCreationHelper; import org.apache.poi.xssf.usermodel.XSSFRichTextString; @@ -37,7 +37,7 @@ import org.apache.poi.xssf.usermodel.XSSFRichTextString; * regular XSSF Workbook */ public class SXSSFCreationHelper implements CreationHelper { - private static final POILogger LOG = POILogFactory.getLogger(SXSSFCreationHelper.class); + private static final Logger LOG = LogManager.getLogger(SXSSFCreationHelper.class); private final SXSSFWorkbook wb; private final XSSFCreationHelper helper; @@ -55,7 +55,7 @@ public class SXSSFCreationHelper implements CreationHelper { @Override public XSSFRichTextString createRichTextString(String text) { - LOG.log(POILogger.INFO, "SXSSF doesn't support Rich Text Strings, any formatting information will be lost"); + LOG.atInfo().log("SXSSF doesn't support Rich Text Strings, any formatting information will be lost"); return new XSSFRichTextString(text); } diff --git a/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFFormulaEvaluator.java b/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFFormulaEvaluator.java index a846b48458..67fe562aac 100644 --- a/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFFormulaEvaluator.java +++ b/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFFormulaEvaluator.java @@ -17,6 +17,8 @@ package org.apache.poi.xssf.streaming; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.ss.formula.EvaluationCell; import org.apache.poi.ss.formula.IStabilityClassifier; import org.apache.poi.ss.formula.WorkbookEvaluator; @@ -25,16 +27,16 @@ import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.CellType; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; import org.apache.poi.xssf.usermodel.BaseXSSFFormulaEvaluator; +import static org.apache.logging.log4j.util.Unbox.box; + /** * Streaming-specific Formula Evaluator, which is able to * lookup cells within the current Window. */ public final class SXSSFFormulaEvaluator extends BaseXSSFFormulaEvaluator { - private static final POILogger LOG = POILogFactory.getLogger(SXSSFFormulaEvaluator.class); + private static final Logger LOG = LogManager.getLogger(SXSSFFormulaEvaluator.class); private final SXSSFWorkbook wb; @@ -111,7 +113,7 @@ public final class SXSSFFormulaEvaluator extends BaseXSSFFormulaEvaluator { int lastFlushedRowNum = ((SXSSFSheet) sheet).getLastFlushedRowNum(); if (lastFlushedRowNum > -1) { if (! skipOutOfWindow) throw new RowFlushedException(0); - LOG.log(POILogger.INFO, "Rows up to ", lastFlushedRowNum, " have already been flushed, skipping"); + LOG.atInfo().log("Rows up to {} have already been flushed, skipping", box(lastFlushedRowNum)); } } diff --git a/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFPicture.java b/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFPicture.java index 6711d82860..a39eb590c8 100644 --- a/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFPicture.java +++ b/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFPicture.java @@ -20,6 +20,8 @@ package org.apache.poi.xssf.streaming; import java.awt.Dimension; import java.io.IOException; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.openxml4j.opc.PackagePart; import org.apache.poi.ss.usermodel.Picture; import org.apache.poi.ss.usermodel.Row; @@ -28,8 +30,6 @@ import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.ss.util.ImageUtils; import org.apache.poi.util.Internal; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; import org.apache.poi.util.Units; import org.apache.poi.xssf.usermodel.XSSFAnchor; import org.apache.poi.xssf.usermodel.XSSFClientAnchor; @@ -50,7 +50,7 @@ import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCol; * The main change is to access the rows in the SXSSF sheet, not the always empty rows in the XSSF sheet when checking the row heights. */ public final class SXSSFPicture implements Picture { - private static final POILogger LOG = POILogFactory.getLogger(SXSSFPicture.class); + private static final Logger LOG = LogManager.getLogger(SXSSFPicture.class); /** * Column width measured as the number of characters of the maximum digit width of the * numbers 0, 1, 2, ..., 9 as rendered in the normal style's font. There are 4 pixels of margin @@ -109,7 +109,7 @@ public final class SXSSFPicture implements Picture { XSSFClientAnchor anchor = getClientAnchor(); XSSFClientAnchor pref = getPreferredSize(scale); if (anchor == null || pref == null) { - LOG.log(POILogger.WARN, "picture is not anchored via client anchor - ignoring resize call"); + LOG.atWarn().log("picture is not anchored via client anchor - ignoring resize call"); return; } @@ -144,7 +144,7 @@ public final class SXSSFPicture implements Picture { public XSSFClientAnchor getPreferredSize(double scale){ XSSFClientAnchor anchor = getClientAnchor(); if (anchor == null) { - LOG.log(POILogger.WARN, "picture is not anchored via client anchor - ignoring resize call"); + LOG.atWarn().log("picture is not anchored via client anchor - ignoring resize call"); return null; } @@ -222,7 +222,7 @@ public final class SXSSFPicture implements Picture { return ImageUtils.getImageDimension(part.getInputStream(), type); } catch (IOException e){ //return a "singulariry" if ImageIO failed to read the image - LOG.log(POILogger.WARN, e); + LOG.atWarn().withThrowable(e).log("Failed to read image"); return new Dimension(); } } diff --git a/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFWorkbook.java b/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFWorkbook.java index 42fc9c0584..a4a9a439e5 100644 --- a/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFWorkbook.java +++ b/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFWorkbook.java @@ -36,6 +36,8 @@ import org.apache.commons.compress.archivers.ArchiveOutputStream; import org.apache.commons.compress.archivers.zip.Zip64Mode; import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.openxml4j.opc.OPCPackage; import org.apache.poi.openxml4j.util.ZipArchiveThresholdInputStream; import org.apache.poi.openxml4j.util.ZipEntrySource; @@ -50,6 +52,7 @@ import org.apache.poi.ss.usermodel.DataFormat; import org.apache.poi.ss.usermodel.Font; import org.apache.poi.ss.usermodel.Name; import org.apache.poi.ss.usermodel.PictureData; +import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Row.MissingCellPolicy; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.SheetVisibility; @@ -58,8 +61,6 @@ import org.apache.poi.util.Beta; import org.apache.poi.util.IOUtils; import org.apache.poi.util.Internal; import org.apache.poi.util.NotImplemented; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; import org.apache.poi.util.Removal; import org.apache.poi.util.TempFile; import org.apache.poi.xssf.model.SharedStringsTable; @@ -102,7 +103,7 @@ public class SXSSFWorkbook implements Workbook { * via {@link SXSSFSheet#getRow} anymore. */ public static final int DEFAULT_WINDOW_SIZE = 100; - private static final POILogger LOG = POILogFactory.getLogger(SXSSFWorkbook.class); + private static final Logger LOG = LogManager.getLogger(SXSSFWorkbook.class); protected final XSSFWorkbook _wb; @@ -839,7 +840,7 @@ public class SXSSFWorkbook implements Workbook { try { sxSheet.dispose(); } catch (IOException e) { - LOG.log(POILogger.WARN, e); + LOG.atWarn().withThrowable(e).log("Failed to dispose old sheet"); } } @@ -935,9 +936,7 @@ public class SXSSFWorkbook implements Workbook { SheetDataWriter _writer = sheet.getSheetDataWriter(); if (_writer != null) _writer.close(); } catch (IOException e) { - LOG.log(POILogger.WARN, - "An exception occurred while closing sheet data writer for sheet " - + sheet.getSheetName() + ".", e); + LOG.atWarn().withThrowable(e).log("An exception occurred while closing sheet data writer for sheet {}.", sheet.getSheetName()); } } @@ -998,7 +997,7 @@ public class SXSSFWorkbook implements Workbook { try { success = sheet.dispose() && success; } catch (IOException e) { - LOG.log(POILogger.WARN, e); + LOG.atWarn().withThrowable(e).log("Failed to dispose sheet"); success = false; } } @@ -1139,7 +1138,7 @@ public class SXSSFWorkbook implements Workbook { * getting missing or blank cells from a row. * * This will then apply to all calls to - * {@link org.apache.poi.ss.usermodel.Row#getCell(int)}. See + * {@link Row#getCell(int)}. See * {@link MissingCellPolicy} */ @Override diff --git a/src/ooxml/java/org/apache/poi/xssf/streaming/SheetDataWriter.java b/src/ooxml/java/org/apache/poi/xssf/streaming/SheetDataWriter.java index 93f0b50410..f72b6a2ff3 100644 --- a/src/ooxml/java/org/apache/poi/xssf/streaming/SheetDataWriter.java +++ b/src/ooxml/java/org/apache/poi/xssf/streaming/SheetDataWriter.java @@ -32,13 +32,13 @@ import java.io.Writer; import java.nio.charset.StandardCharsets; import java.util.Iterator; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.CellStyle; import org.apache.poi.ss.usermodel.CellType; import org.apache.poi.ss.usermodel.FormulaError; import org.apache.poi.ss.util.CellReference; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; import org.apache.poi.util.StringCodepointsIterable; import org.apache.poi.util.TempFile; import org.apache.poi.xssf.model.SharedStringsTable; @@ -52,7 +52,7 @@ import org.openxmlformats.schemas.spreadsheetml.x2006.main.STCellType; * so that it was renamed to "SheetDataWriter" */ public class SheetDataWriter implements Closeable { - private static final POILogger LOG = POILogFactory.getLogger(SheetDataWriter.class); + private static final Logger LOG = LogManager.getLogger(SheetDataWriter.class); private final File _fd; protected final Writer _out; @@ -186,7 +186,7 @@ public class SheetDataWriter implements Closeable { @Override protected void finalize() throws Throwable { if (_fd.exists() && !_fd.delete()) { - LOG.log(POILogger.ERROR, "Can't delete temporary encryption file: ", _fd); + LOG.atError().log("Can't delete temporary encryption file: {}", _fd); } } diff --git a/src/ooxml/java/org/apache/poi/xssf/streaming/StreamingSheetWriter.java b/src/ooxml/java/org/apache/poi/xssf/streaming/StreamingSheetWriter.java index 065f585b54..ef5e6c3438 100644 --- a/src/ooxml/java/org/apache/poi/xssf/streaming/StreamingSheetWriter.java +++ b/src/ooxml/java/org/apache/poi/xssf/streaming/StreamingSheetWriter.java @@ -25,9 +25,9 @@ import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.Writer; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.util.Beta; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; /** * Unlike SheetDataWriter, this writer does not create a temporary file, it writes data directly @@ -36,7 +36,7 @@ import org.apache.poi.util.POILogger; */ @Beta public class StreamingSheetWriter extends SheetDataWriter { - private static final POILogger LOG = POILogFactory.getLogger(StreamingSheetWriter.class); + private static final Logger LOG = LogManager.getLogger(StreamingSheetWriter.class); public StreamingSheetWriter() throws IOException { throw new RuntimeException("StreamingSheetWriter requires OutputStream"); @@ -44,7 +44,7 @@ public class StreamingSheetWriter extends SheetDataWriter { public StreamingSheetWriter(OutputStream out) throws IOException { super(createWriter(out)); - LOG.log(POILogger.DEBUG, "Preparing SSXSSF sheet writer"); + LOG.atDebug().log("Preparing SSXSSF sheet writer"); } @Override diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDrawing.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDrawing.java index 8b437cb222..c781ca7285 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDrawing.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDrawing.java @@ -28,6 +28,8 @@ import java.util.List; import javax.xml.namespace.QName; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.ooxml.POIXMLDocumentPart; import org.apache.poi.ooxml.POIXMLException; import org.apache.poi.openxml4j.exceptions.InvalidFormatException; @@ -42,8 +44,6 @@ import org.apache.poi.ss.usermodel.Drawing; import org.apache.poi.ss.util.CellAddress; import org.apache.poi.ss.util.ImageUtils; import org.apache.poi.util.Internal; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; import org.apache.poi.util.Units; import org.apache.poi.xssf.model.CommentsTable; import org.apache.xmlbeans.XmlCursor; @@ -76,7 +76,7 @@ import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet; * Represents a SpreadsheetML drawing */ public final class XSSFDrawing extends POIXMLDocumentPart implements Drawing<XSSFShape> { - private static final POILogger LOG = POILogFactory.getLogger(XSSFDrawing.class); + private static final Logger LOG = LogManager.getLogger(XSSFDrawing.class); /** * Root element of the SpreadsheetML Drawing part @@ -90,7 +90,7 @@ public final class XSSFDrawing extends POIXMLDocumentPart implements Drawing<XSS /** * Create a new SpreadsheetML drawing * - * @see org.apache.poi.xssf.usermodel.XSSFSheet#createDrawingPatriarch() + * @see XSSFSheet#createDrawingPatriarch() */ protected XSSFDrawing() { super(); @@ -191,7 +191,7 @@ public final class XSSFDrawing extends POIXMLDocumentPart implements Drawing<XSS * @param pictureIndex * the index of the picture in the workbook collection of * pictures, - * {@link org.apache.poi.xssf.usermodel.XSSFWorkbook#getAllPictures()} + * {@link XSSFWorkbook#getAllPictures()} * . * * @return the newly created picture shape. @@ -226,7 +226,7 @@ public final class XSSFDrawing extends POIXMLDocumentPart implements Drawing<XSS * the client anchor describes how this chart is attached to the * sheet. * @return the newly created chart - * @see org.apache.poi.xssf.usermodel.XSSFDrawing#createChart(ClientAnchor) + * @see XSSFDrawing#createChart(ClientAnchor) */ public XSSFChart createChart(XSSFClientAnchor anchor) { RelationPart rp = createChartRelationPart(); @@ -283,7 +283,7 @@ public final class XSSFDrawing extends POIXMLDocumentPart implements Drawing<XSS * Add the indexed picture to this drawing relations * * @param pictureIndex the index of the picture in the workbook collection of pictures, - * {@link org.apache.poi.xssf.usermodel.XSSFWorkbook#getAllPictures()} . + * {@link XSSFWorkbook#getAllPictures()} . */ protected PackageRelationship addPictureReference(int pictureIndex) { XSSFWorkbook wb = (XSSFWorkbook) getParent().getParent(); @@ -643,8 +643,7 @@ public final class XSSFDrawing extends POIXMLDocumentPart implements Drawing<XSS } else if (obj instanceof CTGroupShape) { shape = new XSSFShapeGroup(this, (CTGroupShape) obj); } else if (obj instanceof XmlAnyTypeImpl) { - LOG.log(POILogger.WARN, - "trying to parse AlternateContent, this unlinks the returned Shapes from the underlying xml content, so those shapes can't be used to modify the drawing, i.e. modifications will be ignored!"); + LOG.atWarn().log("trying to parse AlternateContent, this unlinks the returned Shapes from the underlying xml content, so those shapes can't be used to modify the drawing, i.e. modifications will be ignored!"); // XmlAnyTypeImpl is returned for AlternateContent // parts, which might contain a CTDrawing @@ -661,7 +660,7 @@ public final class XSSFDrawing extends POIXMLDocumentPart implements Drawing<XSS addShapes(cur2, lst); } } catch (XmlException e) { - LOG.log(POILogger.WARN, "unable to parse CTDrawing in alternate content.", e); + LOG.atWarn().withThrowable(e).log("unable to parse CTDrawing in alternate content."); } finally { if (cur2 != null) { cur2.dispose(); diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFObjectData.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFObjectData.java index 0544800e67..16d04085f2 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFObjectData.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFObjectData.java @@ -23,6 +23,8 @@ import java.io.InputStream; import javax.xml.namespace.QName; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.ooxml.POIXMLDocumentPart; import org.apache.poi.ooxml.POIXMLException; import org.apache.poi.openxml4j.opc.PackagePart; @@ -32,8 +34,6 @@ import org.apache.poi.poifs.filesystem.FileMagic; import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.apache.poi.ss.usermodel.ObjectData; import org.apache.poi.util.IOUtils; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; import org.apache.xmlbeans.XmlCursor; import org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualDrawingProps; import org.openxmlformats.schemas.drawingml.x2006.main.CTOfficeArtExtension; @@ -52,8 +52,8 @@ import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTOleObject; * Represents binary object (i.e. OLE) data stored in the file. Eg. A GIF, JPEG etc... */ public class XSSFObjectData extends XSSFSimpleShape implements ObjectData { - private static final POILogger LOG = POILogFactory.getLogger(XSSFObjectData.class); - + private static final Logger LOG = LogManager.getLogger(XSSFObjectData.class); + /** * A default instance of CTShape used for creating new shapes. */ @@ -163,7 +163,7 @@ public class XSSFObjectData extends XSSFSimpleShape implements ObjectData { is = FileMagic.prepareToCheckMagic(is); return FileMagic.valueOf(is) == FileMagic.OLE2; } catch (IOException e) { - LOG.log(POILogger.WARN, "can't determine if directory entry exists", e); + LOG.atWarn().withThrowable(e).log("can't determine if directory entry exists"); return false; } finally { IOUtils.closeQuietly(is); diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPicture.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPicture.java index 1055d6bccc..86f3bd917b 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPicture.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPicture.java @@ -20,14 +20,14 @@ package org.apache.poi.xssf.usermodel; import java.awt.Dimension; import java.io.IOException; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.openxml4j.opc.PackagePart; import org.apache.poi.openxml4j.opc.PackageRelationship; import org.apache.poi.ss.usermodel.Picture; import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.ss.util.ImageUtils; import org.apache.poi.util.Internal; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; import org.openxmlformats.schemas.drawingml.x2006.main.CTBlipFillProperties; import org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualDrawingProps; import org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualPictureProperties; @@ -46,7 +46,7 @@ import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTPictureNo * @author Yegor Kozlov */ public final class XSSFPicture extends XSSFShape implements Picture { - private static final POILogger LOG = POILogFactory.getLogger(XSSFPicture.class); + private static final Logger LOG = LogManager.getLogger(XSSFPicture.class); /** * Column width measured as the number of characters of the maximum digit width of the @@ -170,15 +170,15 @@ public final class XSSFPicture extends XSSFShape implements Picture { * </p> * * @param scaleX the amount by which the image width is multiplied relative to the original width, - * when set to {@link java.lang.Double#MAX_VALUE} the width of the embedded image is used + * when set to {@link Double#MAX_VALUE} the width of the embedded image is used * @param scaleY the amount by which the image height is multiplied relative to the original height, - * when set to {@link java.lang.Double#MAX_VALUE} the height of the embedded image is used + * when set to {@link Double#MAX_VALUE} the height of the embedded image is used */ public void resize(double scaleX, double scaleY){ XSSFClientAnchor anchor = getClientAnchor(); XSSFClientAnchor pref = getPreferredSize(scaleX,scaleY); if (anchor == null || pref == null) { - LOG.log(POILogger.WARN, "picture is not anchored via client anchor - ignoring resize call"); + LOG.atWarn().log("picture is not anchored via client anchor - ignoring resize call"); return; } @@ -242,7 +242,7 @@ public final class XSSFPicture extends XSSFShape implements Picture { return ImageUtils.getImageDimension(part.getInputStream(), type); } catch (IOException e){ //return a "singulariry" if ImageIO failed to read the image - LOG.log(POILogger.WARN, e); + LOG.atWarn().withThrowable(e).log("Failed to read image"); return new Dimension(); } } diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java index fd5a06ec7c..571d4fb766 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java @@ -41,6 +41,8 @@ import javax.xml.namespace.QName; 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.ooxml.POIXMLDocumentPart; import org.apache.poi.ooxml.POIXMLException; import org.apache.poi.openxml4j.exceptions.InvalidFormatException; @@ -62,12 +64,14 @@ import org.apache.poi.ss.usermodel.DataValidation; import org.apache.poi.ss.usermodel.DataValidationHelper; import org.apache.poi.ss.usermodel.Font; import org.apache.poi.ss.usermodel.Footer; +import org.apache.poi.ss.usermodel.FormulaEvaluator; import org.apache.poi.ss.usermodel.Header; import org.apache.poi.ss.usermodel.IgnoredErrorType; import org.apache.poi.ss.usermodel.Name; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; 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.CellAddress; import org.apache.poi.ss.util.CellRangeAddress; @@ -78,8 +82,6 @@ import org.apache.poi.ss.util.SSCellRange; import org.apache.poi.ss.util.SheetUtil; import org.apache.poi.util.Beta; import org.apache.poi.util.Internal; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; import org.apache.poi.util.Units; import org.apache.poi.xssf.model.CommentsTable; import org.apache.poi.xssf.usermodel.XSSFPivotTable.PivotTableReferenceConfigurator; @@ -103,7 +105,7 @@ import org.openxmlformats.schemas.spreadsheetml.x2006.main.*; * </p> */ public class XSSFSheet extends POIXMLDocumentPart implements Sheet { - private static final POILogger LOG = POILogFactory.getLogger(XSSFSheet.class); + private static final Logger LOG = LogManager.getLogger(XSSFSheet.class); private static final double DEFAULT_ROW_HEIGHT = 15.0; private static final double DEFAULT_MARGIN_HEADER = 0.3; @@ -139,7 +141,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet { /** * Creates new XSSFSheet - called by XSSFWorkbook to create a sheet from scratch. * - * @see org.apache.poi.xssf.usermodel.XSSFWorkbook#createSheet() + * @see XSSFWorkbook#createSheet() */ protected XSSFSheet() { super(); @@ -556,7 +558,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet { break; } } - LOG.log(POILogger.ERROR, "Can't find drawing with id=", ctDrawing.getId(), " in the list of the sheet's relationships"); + LOG.atError().log("Can't find drawing with id={} in the list of the sheet's relationships", ctDrawing.getId()); } return null; } @@ -628,7 +630,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet { } } if(drawing == null){ - LOG.log(POILogger.ERROR, "Can't find VML drawing with id=", id, " in the list of the sheet's relationships"); + LOG.atError().log("Can't find VML drawing with id={} in the list of the sheet's relationships", id); } } return drawing; @@ -720,7 +722,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet { * * @param rownum row number * @return High level {@link XSSFRow} object representing a row in the sheet - * @see #removeRow(org.apache.poi.ss.usermodel.Row) + * @see #removeRow(Row) */ @Override public XSSFRow createRow(int rownum) { @@ -766,10 +768,10 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet { * @param leftmostColumn Left column visible in right pane. * @param activePane Active pane. One of: PANE_LOWER_RIGHT, * PANE_UPPER_RIGHT, PANE_LOWER_LEFT, PANE_UPPER_LEFT - * @see org.apache.poi.ss.usermodel.Sheet#PANE_LOWER_LEFT - * @see org.apache.poi.ss.usermodel.Sheet#PANE_LOWER_RIGHT - * @see org.apache.poi.ss.usermodel.Sheet#PANE_UPPER_LEFT - * @see org.apache.poi.ss.usermodel.Sheet#PANE_UPPER_RIGHT + * @see Sheet#PANE_LOWER_LEFT + * @see Sheet#PANE_LOWER_RIGHT + * @see Sheet#PANE_UPPER_LEFT + * @see Sheet#PANE_UPPER_RIGHT */ @Override public void createSplitPane(int xSplitPos, int ySplitPos, int leftmostColumn, int topRow, int activePane) { @@ -2022,20 +2024,20 @@ public class XSSFSheet extends POIXMLDocumentPart implements 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> * * <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. * </p> * @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) { @@ -4672,12 +4674,12 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet { } coo = coos.getOleObjectArray(0); } catch (XmlException e) { - LOG.log(POILogger.INFO, "can't parse CTOleObjects", e); + LOG.atInfo().withThrowable(e).log("can't parse CTOleObjects"); } finally { try { reader.close(); } catch (XMLStreamException e) { - LOG.log(POILogger.INFO, "can't close reader", e); + LOG.atInfo().withThrowable(e).log("can't close reader"); } } } diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFTableStyle.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFTableStyle.java index b51a92d5c3..852f91c62d 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFTableStyle.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFTableStyle.java @@ -22,11 +22,11 @@ import java.util.EnumMap; import java.util.List; import java.util.Map; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.ss.usermodel.DifferentialStyleProvider; import org.apache.poi.ss.usermodel.TableStyle; import org.apache.poi.ss.usermodel.TableStyleType; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; import org.apache.xmlbeans.XmlCursor; import org.apache.xmlbeans.XmlException; import org.apache.xmlbeans.XmlObject; @@ -41,7 +41,7 @@ import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTTableStyleElement; * Also used for built-in styles via dummy XML generated from presetTableStyles.xml. */ public class XSSFTableStyle implements TableStyle { - private static final POILogger LOG = POILogFactory.getLogger(XSSFTableStyle.class); + private static final Logger LOG = LogManager.getLogger(XSSFTableStyle.class); private final String name; private final int index; @@ -79,7 +79,7 @@ public class XSSFTableStyle implements TableStyle { } if (dxf != null) dxfList.add(dxf); } catch (XmlException e) { - LOG.log(POILogger.WARN, "Error parsing XSSFTableStyle", e); + LOG.atWarn().withThrowable(e).log("Error parsing XSSFTableStyle"); } } } diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java index fc019a8f30..f64ed3c4cd 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java @@ -43,6 +43,8 @@ import javax.xml.namespace.QName; import org.apache.commons.collections4.ListValuedMap; import org.apache.commons.collections4.multimap.ArrayListValuedHashMap; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.hpsf.ClassIDPredefined; import org.apache.poi.ooxml.POIXMLDocument; import org.apache.poi.ooxml.POIXMLDocumentPart; @@ -68,6 +70,7 @@ import org.apache.poi.ss.formula.SheetNameFormatter; import org.apache.poi.ss.formula.udf.AggregatingUDFFinder; import org.apache.poi.ss.formula.udf.IndexedUDFFinder; import org.apache.poi.ss.formula.udf.UDFFinder; +import org.apache.poi.ss.usermodel.DataFormat; import org.apache.poi.ss.usermodel.Date1904Support; import org.apache.poi.ss.usermodel.Name; import org.apache.poi.ss.usermodel.Row; @@ -81,8 +84,6 @@ import org.apache.poi.util.Beta; import org.apache.poi.util.IOUtils; import org.apache.poi.util.Internal; import org.apache.poi.util.NotImplemented; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; import org.apache.poi.util.Removal; import org.apache.poi.xssf.XLSBUnsupportedException; import org.apache.poi.xssf.model.CalculationChain; @@ -200,7 +201,7 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Date1904Su /** * The policy to apply in the event of missing or * blank cells when fetching from a row. - * See {@link org.apache.poi.ss.usermodel.Row.MissingCellPolicy} + * See {@link MissingCellPolicy} */ private MissingCellPolicy _missingCellPolicy = MissingCellPolicy.RETURN_NULL_AND_BLANK; @@ -214,7 +215,7 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Date1904Su */ private List<XSSFPictureData> pictures; - private static final POILogger LOG = POILogFactory.getLogger(XSSFWorkbook.class); + private static final Logger LOG = LogManager.getLogger(XSSFWorkbook.class); /** * cached instance of XSSFCreationHelper for this workbook @@ -415,7 +416,7 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Date1904Su for (CTExternalReference er : this.workbook.getExternalReferences().getExternalReferenceArray()) { ExternalLinksTable el = elIdMap.get(er.getId()); if(el == null) { - LOG.log(POILogger.WARN, "ExternalLinksTable with r:id ", er.getId(), " was defined, but didn't exist in package, skipping"); + LOG.atWarn().log("ExternalLinksTable with r:id {} was defined, but didn't exist in package, skipping", er.getId()); continue; } externalLinks.add(el); @@ -436,8 +437,7 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Date1904Su public void parseSheet(Map<String, XSSFSheet> shIdMap, CTSheet ctSheet) { XSSFSheet sh = shIdMap.get(ctSheet.getId()); if(sh == null) { - LOG.log(POILogger.WARN, "Sheet with name ", ctSheet.getName(), " and r:id ", - ctSheet.getId(), " was defined, but didn't exist in package, skipping"); + LOG.atWarn().log("Sheet with name {} and r:id {} was defined, but didn't exist in package, skipping", ctSheet.getName(), ctSheet.getId()); return; } sh.sheet = ctSheet; @@ -649,11 +649,11 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Date1904Su } CTWorksheet ct = clonedSheet.getCTWorksheet(); if(ct.isSetLegacyDrawing()) { - LOG.log(POILogger.WARN, "Cloning sheets with comments is not yet supported."); + LOG.atWarn().log("Cloning sheets with comments is not yet supported."); ct.unsetLegacyDrawing(); } if (ct.isSetPageSetup()) { - LOG.log(POILogger.WARN, "Cloning sheets with page setup is not yet supported."); + LOG.atWarn().log("Cloning sheets with page setup is not yet supported."); ct.unsetPageSetup(); } @@ -757,7 +757,7 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Date1904Su * Returns the workbook's data format table (a factory for creating data format strings). * * @return the XSSFDataFormat object - * @see org.apache.poi.ss.usermodel.DataFormat + * @see DataFormat */ @Override public XSSFDataFormat createDataFormat() { @@ -848,14 +848,14 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Date1904Su * </p> * * <p> - * See {@link org.apache.poi.ss.util.WorkbookUtil#createSafeSheetName(String nameProposal)} + * See {@link WorkbookUtil#createSafeSheetName(String nameProposal)} * for a safe way to create valid names * </p> * @param sheetname sheetname to set for the sheet. * @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 XSSFSheet createSheet(String sheetname) { @@ -1559,7 +1559,7 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Date1904Su * @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 sheetIndex, String sheetname) { diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/XSSFColumnShifter.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/XSSFColumnShifter.java index 8532c8b022..2acc8955f1 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/XSSFColumnShifter.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/XSSFColumnShifter.java @@ -17,11 +17,11 @@ package org.apache.poi.xssf.usermodel.helpers; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.ss.formula.FormulaShifter; import org.apache.poi.ss.usermodel.helpers.ColumnShifter; import org.apache.poi.util.Beta; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; import org.apache.poi.xssf.usermodel.XSSFSheet; /** @@ -33,7 +33,7 @@ import org.apache.poi.xssf.usermodel.XSSFSheet; // {@link org.apache.poi.hssf.usermodel.helpers.HSSFColumnShifter} @Beta public final class XSSFColumnShifter extends ColumnShifter { - private static final POILogger LOG = POILogFactory.getLogger(XSSFColumnShifter.class); + private static final Logger LOG = LogManager.getLogger(XSSFColumnShifter.class); public XSSFColumnShifter(XSSFSheet sh) { super(sh); diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/XSSFRowColShifter.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/XSSFRowColShifter.java index b15910bc9c..298fa3f48f 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/XSSFRowColShifter.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/XSSFRowColShifter.java @@ -17,6 +17,8 @@ package org.apache.poi.xssf.usermodel.helpers; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.ss.formula.FormulaShifter; import org.apache.poi.ss.formula.FormulaParser; import org.apache.poi.ss.formula.FormulaType; @@ -27,14 +29,14 @@ import org.apache.poi.ss.usermodel.*; import org.apache.poi.ss.usermodel.helpers.BaseRowColShifter; import org.apache.poi.ss.util.CellRangeAddress; import org.apache.poi.util.Internal; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; import org.apache.poi.xssf.usermodel.*; import org.openxmlformats.schemas.spreadsheetml.x2006.main.*; import java.util.ArrayList; import java.util.List; +import static org.apache.logging.log4j.util.Unbox.box; + /** * Class for code common to {@link XSSFRowShifter} and {@link XSSFColumnShifter} * @@ -42,7 +44,7 @@ import java.util.List; */ @Internal /*private*/ final class XSSFRowColShifter { - private static final POILogger LOG = POILogFactory.getLogger(XSSFRowColShifter.class); + private static final Logger LOG = LogManager.getLogger(XSSFRowColShifter.class); private XSSFRowColShifter() { /*no instances for static classes*/} @@ -151,7 +153,7 @@ import java.util.List; return shiftedFmla; } catch (FormulaParseException fpe) { // Log, but don't change, rather than breaking - LOG.log(POILogger.WARN, "Error shifting formula on row ", row.getRowNum(), fpe); + LOG.atWarn().withThrowable(fpe).log("Error shifting formula on row {}", box(row.getRowNum())); return formula; } } diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/XSSFRowShifter.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/XSSFRowShifter.java index 4de9c60625..ffbc570796 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/XSSFRowShifter.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/XSSFRowShifter.java @@ -17,11 +17,11 @@ package org.apache.poi.xssf.usermodel.helpers; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.ss.formula.FormulaShifter; import org.apache.poi.ss.usermodel.helpers.RowShifter; import org.apache.poi.util.Internal; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; import org.apache.poi.xssf.usermodel.XSSFRow; import org.apache.poi.xssf.usermodel.XSSFSheet; @@ -31,7 +31,7 @@ import org.apache.poi.xssf.usermodel.XSSFSheet; // non-Javadoc: When possible, code should be implemented in the RowShifter abstract class to avoid duplication with // {@link org.apache.poi.hssf.usermodel.helpers.HSSFRowShifter} public final class XSSFRowShifter extends RowShifter { - private static final POILogger LOG = POILogFactory.getLogger(XSSFRowShifter.class); + private static final Logger LOG = LogManager.getLogger(XSSFRowShifter.class); public XSSFRowShifter(XSSFSheet sh) { super(sh); diff --git a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java index 64b877060b..e454365b4d 100644 --- a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java +++ b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java @@ -36,6 +36,8 @@ import java.util.Map; import javax.xml.namespace.QName; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.ooxml.POIXMLDocument; import org.apache.poi.ooxml.POIXMLDocumentPart; import org.apache.poi.ooxml.POIXMLException; @@ -55,8 +57,6 @@ import org.apache.poi.openxml4j.opc.TargetMode; import org.apache.poi.poifs.crypt.HashAlgorithm; import org.apache.poi.util.IOUtils; import org.apache.poi.util.Internal; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; import org.apache.poi.wp.usermodel.HeaderFooterType; import org.apache.poi.xddf.usermodel.chart.XDDFChart; import org.apache.poi.xwpf.model.XWPFHeaderFooterPolicy; @@ -81,7 +81,7 @@ import org.openxmlformats.schemas.wordprocessingml.x2006.main.*; */ @SuppressWarnings("unused") public class XWPFDocument extends POIXMLDocument implements Document, IBody { - private static final POILogger LOG = POILogFactory.getLogger(XWPFDocument.class); + private static final Logger LOG = LogManager.getLogger(XWPFDocument.class); protected List<XWPFFooter> footers = new ArrayList<>(); protected List<XWPFHeader> headers = new ArrayList<>(); @@ -310,7 +310,7 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody { /** * returns an Iterator with paragraphs and tables * - * @see org.apache.poi.xwpf.usermodel.IBody#getBodyElements() + * @see IBody#getBodyElements() */ @Override public List<IBodyElement> getBodyElements() { @@ -322,7 +322,7 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody { } /** - * @see org.apache.poi.xwpf.usermodel.IBody#getParagraphs() + * @see IBody#getParagraphs() */ @Override public List<XWPFParagraph> getParagraphs() { @@ -330,7 +330,7 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody { } /** - * @see org.apache.poi.xwpf.usermodel.IBody#getTables() + * @see IBody#getTables() */ @Override public List<XWPFTable> getTables() { @@ -345,7 +345,7 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody { } /** - * @see org.apache.poi.xwpf.usermodel.IBody#getTableArray(int) + * @see IBody#getTableArray(int) */ @Override public XWPFTable getTableArray(int pos) { @@ -629,9 +629,9 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody { /** * Add a new paragraph at position of the cursor. The cursor must be on the - * {@link org.apache.xmlbeans.XmlCursor.TokenType#START} tag of an subelement + * {@link XmlCursor.TokenType#START} tag of an subelement * of the documents body. When this method is done, the cursor passed as - * parameter points to the {@link org.apache.xmlbeans.XmlCursor.TokenType#END} + * parameter points to the {@link XmlCursor.TokenType#END} * of the newly inserted paragraph. * * @param cursor The cursor-position where the new paragraph should be added. @@ -1010,7 +1010,7 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody { int level = Integer.parseInt(parStyle.substring("Heading".length())); toc.addRow(level, par.getText(), 1, "112723803"); } catch (NumberFormatException e) { - LOG.log(POILogger.ERROR, "can't format number in TOC heading", e); + LOG.atError().withThrowable(e).log("can't format number in TOC heading"); } } } @@ -1542,7 +1542,7 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody { * * @param ctTbl * @return a table by its CTTbl-Object or null - * @see org.apache.poi.xwpf.usermodel.IBody#getTable(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl) + * @see IBody#getTable(CTTbl) */ @Override public XWPFTable getTable(CTTbl ctTbl) { @@ -1565,7 +1565,7 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody { /** * Returns the paragraph that of position pos * - * @see org.apache.poi.xwpf.usermodel.IBody#getParagraphArray(int) + * @see IBody#getParagraphArray(int) */ @Override public XWPFParagraph getParagraphArray(int pos) { @@ -1580,7 +1580,7 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody { * Actually it is needed of the class XWPFTableCell. Because you have to know to which part the tableCell * belongs. * - * @see org.apache.poi.xwpf.usermodel.IBody#getPart() + * @see IBody#getPart() */ @Override public POIXMLDocumentPart getPart() { @@ -1592,7 +1592,7 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody { * get the PartType of the body, for example * DOCUMENT, HEADER, FOOTER, FOOTNOTE, * - * @see org.apache.poi.xwpf.usermodel.IBody#getPartType() + * @see IBody#getPartType() */ @Override public BodyType getPartType() { diff --git a/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestListParts.java b/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestListParts.java index 8e97627336..481ce98620 100644 --- a/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestListParts.java +++ b/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestListParts.java @@ -24,15 +24,15 @@ import java.io.IOException; import java.io.InputStream; import java.util.TreeMap; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.openxml4j.OpenXML4JTestDataSamples; import org.apache.poi.openxml4j.exceptions.InvalidFormatException; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; public final class TestListParts { - private static final POILogger LOG = POILogFactory.getLogger(TestListParts.class); + private static final Logger LOG = LogManager.getLogger(TestListParts.class); private TreeMap<PackagePartName, String> expectedValues; @@ -91,7 +91,7 @@ public final class TestListParts { for (PackagePart part : p.getParts()) { values.put(part.getPartName(), part.getContentType()); - LOG.log(POILogger.DEBUG, part.getPartName()); + LOG.atDebug().log(part.getPartName()); } // Compare expected values with values return by the package diff --git a/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackage.java b/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackage.java index 0d8b8360c8..9f297f66c6 100644 --- a/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackage.java +++ b/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackage.java @@ -58,6 +58,8 @@ import com.google.common.io.Files; import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream; import org.apache.commons.compress.archivers.zip.ZipFile; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.EncryptedDocumentException; import org.apache.poi.POIDataSamples; import org.apache.poi.POITestCase; @@ -78,8 +80,6 @@ import org.apache.poi.sl.usermodel.SlideShowFactory; import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.ss.usermodel.WorkbookFactory; import org.apache.poi.util.IOUtils; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; import org.apache.poi.util.TempFile; import org.apache.poi.xssf.XSSFTestDataSamples; import org.apache.poi.xssf.streaming.SXSSFWorkbook; @@ -98,7 +98,7 @@ import org.xml.sax.SAXException; import org.xml.sax.SAXParseException; public final class TestPackage { - private static final POILogger LOG = POILogFactory.getLogger(TestPackage.class); + private static final Logger LOG = LogManager.getLogger(TestPackage.class); private static final String NS_OOXML_WP_MAIN = "http://schemas.openxmlformats.org/wordprocessingml/2006/main"; private static final String CONTENT_EXT_PROPS = "application/vnd.openxmlformats-officedocument.extended-properties+xml"; private static final POIDataSamples xlsSamples = POIDataSamples.getSpreadSheetInstance(); @@ -458,7 +458,7 @@ public final class TestPackage { for (PackagePart part : p.getParts()) { values.put(part.getPartName(), part.getContentType()); - LOG.log(POILogger.DEBUG, part.getPartName()); + LOG.atDebug().log(part.getPartName()); } // Compare expected values with values return by the package @@ -492,7 +492,7 @@ public final class TestPackage { for (PackagePart part : p.getParts()) { values.put(part.getPartName(), part.getContentType()); - LOG.log(POILogger.DEBUG, part.getPartName()); + LOG.atDebug().log(part.getPartName()); } // Compare expected values with values return by the package diff --git a/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestRelationships.java b/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestRelationships.java index 38c13780b2..d80c88ae12 100644 --- a/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestRelationships.java +++ b/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestRelationships.java @@ -30,9 +30,9 @@ import java.io.InputStream; import java.net.URI; import java.util.regex.Pattern; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.openxml4j.OpenXML4JTestDataSamples; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; import org.junit.jupiter.api.Test; @@ -44,7 +44,7 @@ class TestRelationships { private static final String SHEET_WITH_COMMENTS = "/xl/worksheets/sheet1.xml"; - private static final POILogger LOG = POILogFactory.getLogger(TestPackageCoreProperties.class); + private static final Logger LOG = LogManager.getLogger(TestPackageCoreProperties.class); /** * Test relationships are correctly loaded. This at the moment fails (as of r499) @@ -56,7 +56,7 @@ class TestRelationships { void testLoadRelationships() throws Exception { InputStream is = openSampleStream("sample.xlsx"); try (OPCPackage pkg = OPCPackage.open(is)) { - LOG.log(POILogger.DEBUG, "1: " + pkg); + LOG.atDebug().log("1: {}", pkg); PackageRelationshipCollection rels = pkg.getRelationshipsByType(PackageRelationshipTypes.CORE_DOCUMENT); PackageRelationship coreDocRelationship = rels.getRelationship(0); PackagePart corePart = pkg.getPart(coreDocRelationship); diff --git a/src/ooxml/testcases/org/apache/poi/poifs/crypt/dsig/TestSignatureInfo.java b/src/ooxml/testcases/org/apache/poi/poifs/crypt/dsig/TestSignatureInfo.java index f8b7de4453..798b559047 100644 --- a/src/ooxml/testcases/org/apache/poi/poifs/crypt/dsig/TestSignatureInfo.java +++ b/src/ooxml/testcases/org/apache/poi/poifs/crypt/dsig/TestSignatureInfo.java @@ -78,6 +78,8 @@ import javax.xml.crypto.dsig.XMLSignatureException; import javax.xml.crypto.dsig.dom.DOMSignContext; import org.apache.jcp.xml.dsig.internal.dom.DOMSignedInfo; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.EncryptedDocumentException; import org.apache.poi.POIDataSamples; import org.apache.poi.ooxml.POIXMLDocument; @@ -101,8 +103,6 @@ import org.apache.poi.poifs.storage.RawDataUtil; import org.apache.poi.ss.usermodel.WorkbookFactory; import org.apache.poi.util.IOUtils; import org.apache.poi.util.LocaleUtil; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; import org.apache.poi.util.TempFile; import org.apache.poi.xssf.streaming.SXSSFWorkbook; import org.apache.poi.xssf.usermodel.XSSFClientAnchor; @@ -162,7 +162,7 @@ import org.w3.x2000.x09.xmldsig.SignatureDocument; import org.w3c.dom.Document; class TestSignatureInfo { - private static final POILogger LOG = POILogFactory.getLogger(TestSignatureInfo.class); + private static final Logger LOG = LogManager.getLogger(TestSignatureInfo.class); private static final POIDataSamples testdata = POIDataSamples.getXmlDSignInstance(); private static Calendar cal; @@ -357,7 +357,7 @@ class TestSignatureInfo { assertNotNull(result); assertEquals(1, result.size(), "test-file: " + testFile); X509Certificate signer = result.get(0); - LOG.log(POILogger.DEBUG, "signer: ", signer.getSubjectX500Principal()); + LOG.atDebug().log("signer: {}", signer.getSubjectX500Principal()); boolean b = si.verifySignature(); assertTrue(b, "test-file: " + testFile); @@ -385,8 +385,8 @@ class TestSignatureInfo { assertEquals(2, result.size(), "test-file: " + testFile); X509Certificate signer1 = result.get(0); X509Certificate signer2 = result.get(1); - LOG.log(POILogger.DEBUG, "signer 1: ", signer1.getSubjectX500Principal()); - LOG.log(POILogger.DEBUG, "signer 2: ", signer2.getSubjectX500Principal()); + LOG.atDebug().log("signer 1: {}", signer1.getSubjectX500Principal()); + LOG.atDebug().log("signer 2: {}", signer2.getSubjectX500Principal()); boolean b = si.verifySignature(); assertTrue(b, "test-file: " + testFile); @@ -527,8 +527,8 @@ class TestSignatureInfo { } else { TimeStampServiceValidator tspValidator = (validateChain, revocationData) -> { for (X509Certificate certificate : validateChain) { - LOG.log(POILogger.DEBUG, "certificate: ", certificate.getSubjectX500Principal()); - LOG.log(POILogger.DEBUG, "validity: ", certificate.getNotBefore(), " - ", certificate.getNotAfter()); + LOG.atDebug().log("certificate: {}", certificate.getSubjectX500Principal()); + LOG.atDebug().log("validity: {} - {}", certificate.getNotBefore(), certificate.getNotAfter()); } }; signatureConfig.setTspValidator(tspValidator); diff --git a/src/ooxml/testcases/org/apache/poi/ss/tests/TestWorkbookFactory.java b/src/ooxml/testcases/org/apache/poi/ss/tests/TestWorkbookFactory.java index 2232d9a37b..200407e3ef 100644 --- a/src/ooxml/testcases/org/apache/poi/ss/tests/TestWorkbookFactory.java +++ b/src/ooxml/testcases/org/apache/poi/ss/tests/TestWorkbookFactory.java @@ -34,6 +34,8 @@ import java.util.concurrent.Executors; import java.util.concurrent.Future; import java.util.stream.Stream; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.EmptyFileException; import org.apache.poi.EncryptedDocumentException; import org.apache.poi.POIDataSamples; @@ -44,9 +46,6 @@ import org.apache.poi.openxml4j.opc.PackageAccess; import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.ss.usermodel.WorkbookFactory; -import org.apache.poi.util.IOUtils; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; import org.apache.poi.util.SuppressForbidden; import org.apache.poi.util.TempFile; import org.apache.poi.xssf.usermodel.XSSFWorkbook; @@ -63,7 +62,7 @@ public final class TestWorkbookFactory { private static final String[] xlsx_protected = new String[]{"protected_passtika.xlsx", "tika"}; private static final String txt = "SampleSS.txt"; - private static final POILogger LOGGER = POILogFactory.getLogger(TestWorkbookFactory.class); + private static final Logger LOGGER = LogManager.getLogger(TestWorkbookFactory.class); /** * Closes the sample workbook read in from filename. @@ -95,8 +94,7 @@ public final class TestWorkbookFactory { xwb.close(); } else { // TODO: close() re-writes the sample-file?! Resort to revert() for now to close file handle... - LOGGER.log(POILogger.WARN, - "reverting XSSFWorkbook rather than closing it to avoid close() modifying the file on disk. Refer to bug 58779."); + LOGGER.atWarn().log("reverting XSSFWorkbook rather than closing it to avoid close() modifying the file on disk. Refer to bug 58779."); xwb.getPackage().revert(); } } else { diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestFormulaEvaluatorOnXSSF.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestFormulaEvaluatorOnXSSF.java index 3d820ccb52..600ce5c31d 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestFormulaEvaluatorOnXSSF.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestFormulaEvaluatorOnXSSF.java @@ -17,6 +17,7 @@ package org.apache.poi.xssf.usermodel; +import static org.apache.logging.log4j.util.Unbox.box; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.fail; @@ -28,6 +29,8 @@ import java.util.List; import java.util.Locale; import java.util.stream.Stream; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.hssf.HSSFTestDataSamples; import org.apache.poi.openxml4j.opc.OPCPackage; import org.apache.poi.openxml4j.opc.PackageAccess; @@ -40,8 +43,6 @@ 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.util.LocaleUtil; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; @@ -58,9 +59,9 @@ import org.junit.jupiter.params.provider.MethodSource; * */ public final class TestFormulaEvaluatorOnXSSF { - private static final POILogger LOG = POILogFactory.getLogger(TestFormulaEvaluatorOnXSSF.class); + private static final Logger LOG = LogManager.getLogger(TestFormulaEvaluatorOnXSSF.class); - private static XSSFWorkbook workbook; + private static XSSFWorkbook workbook; private static Sheet sheet; private static FormulaEvaluator evaluator; private static Locale userLocale; @@ -244,12 +245,12 @@ public final class TestFormulaEvaluatorOnXSSF { */ private static String getTargetFunctionName(Row r) { if(r == null) { - LOG.log(POILogger.WARN, "Warning - given null row, can't figure out function name"); + LOG.atWarn().log("Given null row, can't figure out function name"); return null; } Cell cell = r.getCell(SS.COLUMN_INDEX_FUNCTION_NAME); if(cell == null) { - LOG.log(POILogger.WARN, "Warning - Row " + r.getRowNum() + " has no cell " + SS.COLUMN_INDEX_FUNCTION_NAME + ", can't figure out function name"); + LOG.atWarn().log("Row {} has no cell " + SS.COLUMN_INDEX_FUNCTION_NAME + ", can't figure out function name", box(r.getRowNum())); return null; } if(cell.getCellType() == CellType.BLANK) { diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestMatrixFormulasFromXMLSpreadsheet.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestMatrixFormulasFromXMLSpreadsheet.java index d29fc2744e..b7f32acd67 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestMatrixFormulasFromXMLSpreadsheet.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestMatrixFormulasFromXMLSpreadsheet.java @@ -17,6 +17,7 @@ package org.apache.poi.xssf.usermodel; +import static org.apache.logging.log4j.util.Unbox.box; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -27,6 +28,8 @@ import java.util.List; import java.util.Locale; import java.util.stream.Stream; +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.functions.BaseTestNumeric; import org.apache.poi.ss.usermodel.Cell; @@ -36,8 +39,6 @@ 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.util.LocaleUtil; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; import org.apache.poi.xssf.XSSFTestDataSamples; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.params.ParameterizedTest; @@ -46,7 +47,7 @@ import org.junit.jupiter.params.provider.MethodSource; public final class TestMatrixFormulasFromXMLSpreadsheet { - private static final POILogger LOG = POILogFactory.getLogger(TestMatrixFormulasFromXMLSpreadsheet.class); + private static final Logger LOG = LogManager.getLogger(TestMatrixFormulasFromXMLSpreadsheet.class); private static XSSFWorkbook workbook; private static Sheet sheet; @@ -208,13 +209,13 @@ public final class TestMatrixFormulasFromXMLSpreadsheet { */ private static String getTargetFunctionName(Row r) { if(r == null) { - LOG.log(POILogger.WARN, "Warning - given null row, can't figure out function name"); + LOG.atWarn().log("Given null row, can't figure out function name"); return null; } Cell cell = r.getCell(Navigator.START_OPERATORS_COL_INDEX); - LOG.log(POILogger.DEBUG, String.valueOf(Navigator.START_OPERATORS_COL_INDEX)); + LOG.atDebug().log( box(Navigator.START_OPERATORS_COL_INDEX)); if(cell == null) { - LOG.log(POILogger.WARN, "Warning - Row " + r.getRowNum() + " has no cell " + Navigator.START_OPERATORS_COL_INDEX + ", can't figure out function name"); + LOG.atWarn().log("Row {} has no cell " + Navigator.START_OPERATORS_COL_INDEX + ", can't figure out function name", box(r.getRowNum())); return null; } diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestMultiSheetFormulaEvaluatorOnXSSF.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestMultiSheetFormulaEvaluatorOnXSSF.java index 91045bfbb7..4c458ea42b 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestMultiSheetFormulaEvaluatorOnXSSF.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestMultiSheetFormulaEvaluatorOnXSSF.java @@ -17,6 +17,9 @@ package org.apache.poi.xssf.usermodel; +import static org.apache.logging.log4j.util.Unbox.box; +import static org.apache.poi.xssf.usermodel.TestMultiSheetFormulaEvaluatorOnXSSF.SS.COLUMN_INDEX_FUNCTION_NAME; +import static org.apache.poi.xssf.usermodel.TestMultiSheetFormulaEvaluatorOnXSSF.SS.COLUMN_INDEX_TEST_NAME; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -28,6 +31,8 @@ import java.util.List; import java.util.Locale; import java.util.stream.Stream; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.hssf.HSSFTestDataSamples; import org.apache.poi.openxml4j.opc.OPCPackage; import org.apache.poi.openxml4j.opc.PackageAccess; @@ -38,8 +43,6 @@ import org.apache.poi.ss.usermodel.CellValue; 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.util.POILogFactory; -import org.apache.poi.util.POILogger; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; @@ -49,9 +52,9 @@ import org.junit.jupiter.params.provider.MethodSource; * Tests formulas for multi sheet reference (i.e. SUM(Sheet1:Sheet5!A1)) */ public final class TestMultiSheetFormulaEvaluatorOnXSSF { - private static final POILogger LOG = POILogFactory.getLogger(TestMultiSheetFormulaEvaluatorOnXSSF.class); + private static final Logger LOG = LogManager.getLogger(TestMultiSheetFormulaEvaluatorOnXSSF.class); - private static XSSFWorkbook workbook; + private static XSSFWorkbook workbook; private static Sheet sheet; private static FormulaEvaluator evaluator; @@ -211,12 +214,12 @@ public final class TestMultiSheetFormulaEvaluatorOnXSSF { */ private static String getTargetFunctionName(Row r) { if(r == null) { - LOG.log(POILogger.WARN, "Warning - given null row, can't figure out function name"); + LOG.atWarn().log("Given null row, can't figure out function name"); return null; } - Cell cell = r.getCell(SS.COLUMN_INDEX_FUNCTION_NAME); + Cell cell = r.getCell(COLUMN_INDEX_FUNCTION_NAME); if(cell == null) { - LOG.log(POILogger.WARN, "Warning - Row " + r.getRowNum() + " has no cell " + SS.COLUMN_INDEX_FUNCTION_NAME + ", can't figure out function name"); + LOG.atWarn().log("Row {} has no cell " + COLUMN_INDEX_FUNCTION_NAME + ", can't figure out function name", box(r.getRowNum())); return null; } @@ -232,12 +235,12 @@ public final class TestMultiSheetFormulaEvaluatorOnXSSF { */ private static String getTargetTestName(Row r) { if(r == null) { - LOG.log(POILogger.WARN, "Warning - given null row, can't figure out test name"); + LOG.atWarn().log("Given null row, can't figure out test name"); return null; } - Cell cell = r.getCell(SS.COLUMN_INDEX_TEST_NAME); + Cell cell = r.getCell(COLUMN_INDEX_TEST_NAME); if(cell == null) { - LOG.log(POILogger.WARN, "Warning - Row " + r.getRowNum() + " has no cell " + SS.COLUMN_INDEX_TEST_NAME + ", can't figure out test name"); + LOG.atWarn().log("Row {} has no cell " + COLUMN_INDEX_TEST_NAME + ", can't figure out test name", box(r.getRowNum())); return null; } CellType ct = cell.getCellType(); diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java index 650754e4c8..562fa9f246 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java @@ -17,6 +17,9 @@ package org.apache.poi.xssf.usermodel; +import static java.time.Duration.between; +import static java.time.Instant.now; +import static org.apache.logging.log4j.util.Unbox.box; import static org.apache.poi.extractor.ExtractorFactory.OOXML_PACKAGE; import static org.apache.poi.openxml4j.opc.TestContentType.isOldXercesActive; import static org.junit.jupiter.api.Assertions.*; @@ -31,7 +34,6 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.nio.charset.StandardCharsets; -import java.time.Duration; import java.time.Instant; import java.util.Arrays; import java.util.Calendar; @@ -45,6 +47,8 @@ import java.util.TreeMap; import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; import org.apache.commons.compress.archivers.zip.ZipFile; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.POIDataSamples; import org.apache.poi.common.usermodel.HyperlinkType; import org.apache.poi.hssf.HSSFITestDataProvider; @@ -96,8 +100,6 @@ import org.apache.poi.ss.util.CellReference; import org.apache.poi.ss.util.CellUtil; import org.apache.poi.util.LocaleUtil; import org.apache.poi.util.NullOutputStream; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; import org.apache.poi.util.TempFile; import org.apache.poi.util.XMLHelper; import org.apache.poi.xssf.SXSSFITestDataProvider; @@ -117,7 +119,6 @@ import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCalcCell; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCols; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDefinedName; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDefinedNames; -import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTIgnoredErrors; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTMergeCell; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTMergeCells; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet; @@ -127,7 +128,7 @@ import org.xml.sax.SAXParseException; import org.xml.sax.XMLReader; public final class TestXSSFBugs extends BaseTestBugzillaIssues { - private static final POILogger LOG = POILogFactory.getLogger(TestXSSFBugs.class); + private static final Logger LOG = LogManager.getLogger(TestXSSFBugs.class); public TestXSSFBugs() { super(XSSFITestDataProvider.instance); @@ -2033,7 +2034,6 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues { "DEC2BIN(A1), org.apache.poi.ss.formula.eval.StringEval [0]" }) void test57196_WorkbookEvaluator(String formula, String expValue) throws IOException { - String previousLogger = System.getProperty("org.apache.poi.util.POILogger"); try (XSSFWorkbook wb = new XSSFWorkbook()) { XSSFSheet sheet = wb.createSheet("Sheet1"); XSSFRow row = sheet.createRow(0); @@ -2051,13 +2051,6 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues { ValueEval ve = workbookEvaluator.evaluate(new XSSFEvaluationCell(cell)); assertEquals(expValue, ve.toString()); - } finally { - if (previousLogger == null) { - System.clearProperty("org.apache.poi.util.POILogger"); - } else { - System.setProperty("org.apache.poi.util.POILogger", previousLogger); - } - System.clearProperty("poi.log.level"); } } @@ -3429,24 +3422,24 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues { void test58896WithFile() throws IOException { try (Workbook wb = XSSFTestDataSamples.openSampleWorkbook("58896.xlsx")) { Sheet sheet = wb.getSheetAt(0); - Instant start = Instant.now(); + Instant start = now(); - LOG.log(POILogger.INFO, "Autosizing columns..."); + LOG.atInfo().log("Autosizing columns..."); for (int i = 0; i < 3; ++i) { - LOG.log(POILogger.INFO, "Autosize ", i, " - ", Duration.between(start, Instant.now())); + LOG.atInfo().log("Autosize {} - {}", box(i), between(start, now())); sheet.autoSizeColumn(i); } for (int i = 0; i < 69 - 35 + 1; ++i) for (int j = 0; j < 8; ++j) { int col = 3 + 2 + i * (8 + 2) + j; - LOG.log(POILogger.INFO, "Autosize ", col, " - ", Duration.between(start, Instant.now())); + LOG.atInfo().log("Autosize {} - {}", box(col), between(start, now())); sheet.autoSizeColumn(col); } - LOG.log(POILogger.INFO, Duration.between(start, Instant.now())); + LOG.atInfo().log(between(start, now())); - assertTrue(Duration.between(start, Instant.now()).getSeconds() < 25); + assertTrue(between(start, now()).getSeconds() < 25); } } diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFColGrouping.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFColGrouping.java index a86d72282b..227dc3627b 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFColGrouping.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFColGrouping.java @@ -23,8 +23,8 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.IOException; -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.xssf.XSSFTestDataSamples; import org.junit.jupiter.api.Test; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCol; @@ -43,7 +43,7 @@ import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCols; */ class TestXSSFColGrouping { - private static final POILogger LOG = POILogFactory.getLogger(TestXSSFColGrouping.class); + private static final Logger LOG = LogManager.getLogger(TestXSSFColGrouping.class); /** @@ -65,7 +65,7 @@ class TestXSSFColGrouping { sheet = wb2.getSheet("test"); CTCols cols = sheet.getCTWorksheet().getColsArray(0); - LOG.log(POILogger.DEBUG, "test52186/cols:" + cols); + LOG.atDebug().log("test52186/cols:{}", cols); for (CTCol col : cols.getColArray()) { assertTrue(col.isSetWidth(), "Col width attribute is unset: " + col); } @@ -91,7 +91,7 @@ class TestXSSFColGrouping { sheet.setColumnGroupCollapsed(4, true); CTCols cols = sheet.getCTWorksheet().getColsArray(0); - LOG.log(POILogger.DEBUG, "test52186_2/cols:" + cols); + LOG.atDebug().log("test52186_2/cols:{}", cols); try (XSSFWorkbook wb2 = XSSFTestDataSamples.writeOutAndReadBack(wb1, "testNoColsWithoutWidthWhenGroupingAndCollapsing")) { sheet = wb2.getSheet("test"); @@ -125,7 +125,7 @@ class TestXSSFColGrouping { sheet.groupColumn((short) 2, (short) 3); sheet.getCTWorksheet().getColsArray(0); - LOG.log(POILogger.DEBUG, "testMergingOverlappingCols_OVERLAPS_2_WRAPS/cols:" + cols); + LOG.atDebug().log("testMergingOverlappingCols_OVERLAPS_2_WRAPS/cols:{}", cols); assertEquals(0, cols.getColArray(0).getOutlineLevel()); assertEquals(2, cols.getColArray(0).getMin()); // 1 based @@ -173,7 +173,7 @@ class TestXSSFColGrouping { sheet.groupColumn((short) 1, (short) 5); cols = sheet.getCTWorksheet().getColsArray(0); - LOG.log(POILogger.DEBUG, "testMergingOverlappingCols_OVERLAPS_1_WRAPS/cols:" + cols); + LOG.atDebug().log("testMergingOverlappingCols_OVERLAPS_1_WRAPS/cols:{}", cols); assertEquals(1, cols.getColArray(0).getOutlineLevel()); assertEquals(2, cols.getColArray(0).getMin()); // 1 based @@ -221,7 +221,7 @@ class TestXSSFColGrouping { sheet.groupColumn((short) 3, (short) 5); cols = sheet.getCTWorksheet().getColsArray(0); - LOG.log(POILogger.DEBUG, "testMergingOverlappingCols_OVERLAPS_1_MINOR/cols:" + cols); + LOG.atDebug().log("testMergingOverlappingCols_OVERLAPS_1_MINOR/cols:{}", cols); assertEquals(0, cols.getColArray(0).getOutlineLevel()); assertEquals(3, cols.getColArray(0).getMin()); // 1 based @@ -270,7 +270,7 @@ class TestXSSFColGrouping { sheet.groupColumn((short) 1, (short) 3); cols = sheet.getCTWorksheet().getColsArray(0); - LOG.log(POILogger.DEBUG, "testMergingOverlappingCols_OVERLAPS_2_MINOR/cols:" + cols); + LOG.atDebug().log("testMergingOverlappingCols_OVERLAPS_2_MINOR/cols:{}", cols); assertEquals(1, cols.getColArray(0).getOutlineLevel()); assertEquals(2, cols.getColArray(0).getMin()); // 1 based diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheetMergeRegions.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheetMergeRegions.java index 983f36cd8c..1cce6eb861 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheetMergeRegions.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheetMergeRegions.java @@ -16,20 +16,21 @@ ==================================================================== */ package org.apache.poi.xssf.usermodel; +import static org.apache.logging.log4j.util.Unbox.box; import static org.junit.jupiter.api.Assertions.*; import java.io.IOException; import java.util.List; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.ss.util.CellRangeAddress; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; import org.apache.poi.xssf.XSSFTestDataSamples; import org.junit.jupiter.api.Test; class TestXSSFSheetMergeRegions { - private static final POILogger LOG = POILogFactory.getLogger(TestXSSFSheetMergeRegions.class); + private static final Logger LOG = LogManager.getLogger(TestXSSFSheetMergeRegions.class); @Test void testMergeRegionsSpeed() throws IOException { @@ -43,7 +44,7 @@ class TestXSSFSheetMergeRegions { if (millis < 2000) { break; } - LOG.log(POILogger.INFO, "Retry ", i, " because run-time is too high: ", millis); + LOG.atInfo().log("Retry {} because run-time is too high: {}", box(i),box(millis)); } boolean inGump = false; |