]> source.dussan.org Git - poi.git/commitdiff
Update JavaDoc for logging and marshalling
authorDominik Stadler <centic@apache.org>
Sun, 8 Mar 2020 08:28:11 +0000 (08:28 +0000)
committerDominik Stadler <centic@apache.org>
Sun, 8 Mar 2020 08:28:11 +0000 (08:28 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1874965 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/util/CommonsLogger.java
src/java/org/apache/poi/util/NullLogger.java
src/java/org/apache/poi/util/POILogger.java
src/java/org/apache/poi/util/SystemOutLogger.java
src/ooxml/java/org/apache/poi/openxml4j/opc/PackagePart.java
src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java
src/ooxml/java/org/apache/poi/openxml4j/opc/internal/marshallers/DefaultMarshaller.java
src/ooxml/java/org/apache/poi/openxml4j/opc/internal/marshallers/ZipPartMarshaller.java
src/testcases/org/apache/poi/util/DummyPOILogger.java

index c5a4374fc8eab2a9a25b51470bfd8d936b932b8e..cdc4f92804f9f16405d964abb14371053ce30da0 100644 (file)
@@ -1,4 +1,3 @@
-
 /* ====================================================================
    Licensed to the Apache Software Foundation (ASF) under one or more
    contributor license agreements.  See the NOTICE file distributed with
    See the License for the specific language governing permissions and
    limitations under the License.
 ==================================================================== */
-        
-
 package org.apache.poi.util;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
 /**
- * A logger class that strives to make it as easy as possible for
- * developers to write log calls, while simultaneously making those
- * calls as cheap as possible by performing lazy evaluation of the log
- * message.<p>
+ * An implementation of the {@link POILogger} using the
+ * Apache Commons Logging framework. Which itself can be configured to
+ * send log to various different log frameworks and even allows to create
+ * a small wrapper for custom log frameworks.
  */
 public class CommonsLogger implements POILogger
 {
@@ -36,8 +33,8 @@ public class CommonsLogger implements POILogger
     @Override
     public void initialize(final String cat) {
         this.log = _creator.getInstance(cat);
-    }   
-     
+    }
+
     /**
      * Log a message
      *
@@ -81,7 +78,7 @@ public class CommonsLogger implements POILogger
                 break;
         }
     }
-    
+
     /**
      * Log a message
      *
index e4fab3903bdcbfacb22672ae13deed5b236eaa19..8a9daeaa0b481b3729b57eac780e2974c6ae1be3 100644 (file)
 package org.apache.poi.util;
 
 /**
- * A logger class that strives to make it as easy as possible for
- * developers to write log calls, while simultaneously making those
- * calls as cheap as possible by performing lazy evaluation of the log
- * message.<p>
+ * An empty-implementation of the {@link POILogger}.
+ *
+ * This can be used to not log anything, however the suggested approach
+ * in production systems is to use the {@link CommonsLogger} and configure
+ * proper log-handling via Apache Commons Logging.
  */
 @Internal
 public class NullLogger implements POILogger {
@@ -66,7 +67,7 @@ public class NullLogger implements POILogger {
         // do nothing
     }
 
-    
+
     /**
      * Check if a logger is enabled to log at the specified level
      *
index 627f83743e22cd7db419bde8c3e843ff230d06ba..fa52baabd518f71c3f1fe375e975d2fe72c17690 100644 (file)
@@ -22,6 +22,19 @@ package org.apache.poi.util;
  * developers to write log calls, while simultaneously making those
  * calls as cheap as possible by performing lazy evaluation of the log
  * message.
+ *
+ * A logger can be selected via system properties, e.g.
+ * <code>
+ *     -Dorg.apache.poi.util.POILogger=org.apache.poi.util.SystemOutLogger
+ * </code>
+ *
+ * The following Logger-implementations are provided:
+ *
+ * <ul>
+ *     <li>NullLogger</li>
+ *     <li>CommonsLogger</li>
+ *     <li>SystemOutLogger</li>
+ * </ul>
  */
 @Internal
 public interface POILogger {
@@ -62,7 +75,7 @@ public interface POILogger {
      * Check if a logger is enabled to log at the specified level
      * This allows code to avoid building strings or evaluating functions in
      * the arguments to log.
-     * 
+     *
      * An example:
      * <code><pre>
      * if (logger.check(POILogger.INFO)) {
@@ -92,11 +105,11 @@ public interface POILogger {
                 sb.append(objs[i]);
             }
         }
-        
+
         String msg = sb.toString();
         // log forging escape
         msg = msg.replaceAll("[\r\n]+", " ");
-        
+
         if (lastEx == null) {
             _log(level, msg);
         } else {
index 8eba4b00638ef836c463bf408a08fdba6f8c7de4..3567c40808be88b8fc86d02a3156f646dc986835 100644 (file)
    See the License for the specific language governing permissions and
    limitations under the License.
 ==================================================================== */
-
 package org.apache.poi.util;
 
-
-
 /**
- * A logger class that strives to make it as easy as possible for
- * developers to write log calls, while simultaneously making those
- * calls as cheap as possible by performing lazy evaluation of the log
- * message.
+ * An implementation of the {@link POILogger} which uses System.out.println.
+ *
+ * This can be used to provide simply output from applications, however the
+ * suggested approach in production systems is to use the {@link CommonsLogger}
+ * and configure proper log-handling via Apache Commons Logging.
  */
 public class SystemOutLogger implements POILogger {
     /**
index 1b04417ee2793b284d00dd870703a3a4a91ed545..0fdacdd2148b30d3c9f9674ba7aa663f49dbddf9 100644 (file)
@@ -466,7 +466,7 @@ public abstract class PackagePart implements RelationshipSource, Comparable<Pack
    /**
     * Get the PackagePart that is the target of a relationship.
     *
-    * @param rel A relationship from this part to another one 
+    * @param rel A relationship from this part to another one
     * @return The target part of the relationship
     * @throws InvalidFormatException
     *             If the specified URI is not valid.
@@ -698,7 +698,8 @@ public abstract class PackagePart implements RelationshipSource, Comparable<Pack
      *
      * @param zos
      *            Output stream to save this part.
-     * @return boolean flag that shows if the save succeeded
+     * @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}
      * @throws OpenXML4JException
      *             If any exception occur.
      */
@@ -709,8 +710,8 @@ public abstract class PackagePart implements RelationshipSource, Comparable<Pack
      *
      * @param ios
      *            The input stream of the content to load.
-     * @return <b>true</b> if the content has been successfully loaded, else
-     *         <b>false</b>.
+     * @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}
      * @throws InvalidFormatException
      *             Throws if the content format is invalid.
      */
index a1a891045686543b913ec23998227697ebd6f51a..5cd3a14598125192f7541fe836a4fb349d74cee9 100644 (file)
@@ -539,8 +539,9 @@ public final class ZipPackage extends OPCPackage {
 
                                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 ";
-                    throw new OpenXML4JException(errMsg + pm);
+                    String errMsg = "The part " + ppn.getURI() + " failed to be saved in the stream with marshaller " + pm +
+                            ". Enable logging via POILogger for more details.";
+                    throw new OpenXML4JException(errMsg);
                 }
                        }
 
index 8cd2f7d245315b42997d2f8e87e5abdfb656af47..16a5917ad3e48f1bd2749843460d61707adfdaf0 100644 (file)
@@ -33,8 +33,12 @@ import org.apache.poi.openxml4j.opc.internal.PartMarshaller;
 public final class DefaultMarshaller implements PartMarshaller {
 
        /**
-        * Save part in the output stream by using the save() method of the part.
+        * Save the given part in the output stream by using the save() method of the part.
         *
+        * @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}
         * @throws OpenXML4JException
         *             If any error occur.
         */
index a1ba382ff8cfc676af5e8d8b63e0056b68904f64..7ff1c74abd04d93564d4999e7efb6a98263c3dfa 100644 (file)
@@ -50,10 +50,15 @@ public final class ZipPartMarshaller implements PartMarshaller {
        private final static POILogger logger = POILogFactory.getLogger(ZipPartMarshaller.class);
 
        /**
-        * Save the specified part.
+        * Save the specified part to the given stream.
         *
+        * @param part The {@link PackagePart} to save
+        * @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.
         * @throws OpenXML4JException
-        *             Throws if an internal exception is thrown.
+        *      Throws if the stream cannot be written to or an internal exception is thrown.
         */
        @Override
        public boolean marshall(PackagePart part, OutputStream os)
@@ -61,10 +66,10 @@ public final class ZipPartMarshaller implements PartMarshaller {
                if (!(os instanceof ZipArchiveOutputStream)) {
                        logger.log(POILogger.ERROR,"Unexpected class " + os.getClass().getName());
                        throw new OpenXML4JException("ZipOutputStream expected !");
-                       // Normally should happen only in developement phase, so just throw
+                       // Normally should happen only in development phase, so just throw
                        // exception
                }
-               
+
                // check if there is anything to save for some parts. We don't do this for all parts as some code
                // might depend on empty parts being saved, e.g. some unit tests verify this currently.
                if(part.getSize() == 0 && part.getPartName().getName().equals(XSSFRelation.SHARED_STRINGS.getDefaultFileName())) {
@@ -98,8 +103,8 @@ public final class ZipPartMarshaller implements PartMarshaller {
 
                        marshallRelationshipPart(part.getRelationships(),
                                        relationshipPartName, zos);
-
                }
+
                return true;
        }
 
@@ -113,6 +118,9 @@ public final class ZipPartMarshaller implements PartMarshaller {
         * @param zos
         *            Zip output stream in which to save the XML content of the
         *            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.
         */
        public static boolean marshallRelationshipPart(
                        PackageRelationshipCollection rels, PackagePartName relPartName,
index e220cc0a0c0666c1dc80325900cba8bbd942a1d3..bb6526be2ded11a861b882beb7ca21e4ec8038cb 100644 (file)
@@ -20,7 +20,7 @@ import java.util.ArrayList;
 import java.util.List;
 
 /**
- * POILogger which logs into an ArrayList, so that 
+ * {@link POILogger} which logs into an ArrayList so that
  *  tests can see what got logged
  */
 @Internal
@@ -30,7 +30,7 @@ public class DummyPOILogger implements POILogger {
        public void reset() {
                logged = new ArrayList<>();
        }
-       
+
     @Override
        public boolean check(int level) {
                return true;