logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject svn commit: r1501219 - in /logging/log4j/log4j2/trunk: core/src/main/java/org/apache/logging/log4j/core/appender/db/jdbc/ core/src/main/java/org/apache/logging/log4j/core/appender/db/jpa/ core/src/main/java/org/apache/logging/log4j/core/appender/db/jpa...
Date Tue, 09 Jul 2013 12:28:01 GMT
Author: ggregory
Date: Tue Jul  9 12:28:00 2013
New Revision: 1501219

URL: http://svn.apache.org/r1501219
Log:
Refactor String pattern 'foo == null || foo.length() == 0' into a new helper API Strings.isEmpty(CharSequence)
copied from Apache Commons Lang.

Added:
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/helpers/Strings.java
  (with props)
Modified:
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/db/jdbc/ColumnConfig.java
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/db/jdbc/DataSourceConnectionSource.java
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/db/jdbc/DriverManagerConnectionSource.java
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/db/jdbc/FactoryMethodConnectionSource.java
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/db/jdbc/JDBCAppender.java
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/db/jpa/JPAAppender.java
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/db/jpa/converter/ContextMapJsonAttributeConverter.java
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/db/jpa/converter/ContextStackJsonAttributeConverter.java
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/db/jpa/converter/MarkerAttributeConverter.java
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/db/jpa/converter/MessageAttributeConverter.java
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/db/jpa/converter/StackTraceElementAttributeConverter.java
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/db/jpa/converter/ThrowableAttributeConverter.java
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/db/nosql/NoSQLAppender.java
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/db/nosql/couch/CouchDBProvider.java
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/LoggerConfig.java
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/helpers/Transform.java
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/lookup/StrMatcher.java
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/net/DatagramSocketManager.java
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/net/SMTPManager.java
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/net/TCPSocketManager.java
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/pattern/PatternParser.java
    logging/log4j/log4j2/trunk/flume-ng/src/main/java/org/apache/logging/log4j/flume/appender/FlumeEmbeddedManager.java
    logging/log4j/log4j2/trunk/flume-ng/src/main/java/org/apache/logging/log4j/flume/appender/FlumePersistentManager.java

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/db/jdbc/ColumnConfig.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/db/jdbc/ColumnConfig.java?rev=1501219&r1=1501218&r2=1501219&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/db/jdbc/ColumnConfig.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/db/jdbc/ColumnConfig.java
Tue Jul  9 12:28:00 2013
@@ -22,6 +22,7 @@ import org.apache.logging.log4j.core.con
 import org.apache.logging.log4j.core.config.plugins.PluginAttr;
 import org.apache.logging.log4j.core.config.plugins.PluginConfiguration;
 import org.apache.logging.log4j.core.config.plugins.PluginFactory;
+import org.apache.logging.log4j.core.helpers.Strings;
 import org.apache.logging.log4j.core.layout.PatternLayout;
 import org.apache.logging.log4j.status.StatusLogger;
 
@@ -103,7 +104,7 @@ public final class ColumnConfig {
                                                   @PluginAttr("isEventTimestamp") final String
eventTimestamp,
                                                   @PluginAttr("isUnicode") final String unicode,
                                                   @PluginAttr("isClob") final String clob)
{
-        if (name == null || name.length() == 0) {
+        if (Strings.isEmpty(name)) {
             LOGGER.error("The column config is not valid because it does not contain a column
name.");
             return null;
         }
@@ -111,7 +112,7 @@ public final class ColumnConfig {
         final boolean isPattern = pattern != null && pattern.length() > 0;
         final boolean isLiteralValue = literalValue != null && literalValue.length()
> 0;
         final boolean isEventTimestamp = eventTimestamp != null && Boolean.parseBoolean(eventTimestamp);
-        final boolean isUnicode = unicode == null || unicode.length() == 0 || Boolean.parseBoolean(unicode);
+        final boolean isUnicode = Strings.isEmpty(unicode) || Boolean.parseBoolean(unicode);
         final boolean isClob = clob != null && Boolean.parseBoolean(clob);
 
         if ((isPattern && isLiteralValue) || (isPattern && isEventTimestamp)
|| (isLiteralValue && isEventTimestamp)) {

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/db/jdbc/DataSourceConnectionSource.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/db/jdbc/DataSourceConnectionSource.java?rev=1501219&r1=1501218&r2=1501219&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/db/jdbc/DataSourceConnectionSource.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/db/jdbc/DataSourceConnectionSource.java
Tue Jul  9 12:28:00 2013
@@ -18,6 +18,7 @@ package org.apache.logging.log4j.core.ap
 
 import java.sql.Connection;
 import java.sql.SQLException;
+
 import javax.naming.InitialContext;
 import javax.naming.NamingException;
 import javax.sql.DataSource;
@@ -26,6 +27,7 @@ import org.apache.logging.log4j.Logger;
 import org.apache.logging.log4j.core.config.plugins.Plugin;
 import org.apache.logging.log4j.core.config.plugins.PluginAttr;
 import org.apache.logging.log4j.core.config.plugins.PluginFactory;
+import org.apache.logging.log4j.core.helpers.Strings;
 import org.apache.logging.log4j.status.StatusLogger;
 
 /**
@@ -62,7 +64,7 @@ public final class DataSourceConnectionS
      */
     @PluginFactory
     public static DataSourceConnectionSource createConnectionSource(@PluginAttr("jndiName")
final String jndiName) {
-        if (jndiName == null || jndiName.length() == 0) {
+        if (Strings.isEmpty(jndiName)) {
             LOGGER.error("No JNDI name provided.");
             return null;
         }

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/db/jdbc/DriverManagerConnectionSource.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/db/jdbc/DriverManagerConnectionSource.java?rev=1501219&r1=1501218&r2=1501219&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/db/jdbc/DriverManagerConnectionSource.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/db/jdbc/DriverManagerConnectionSource.java
Tue Jul  9 12:28:00 2013
@@ -26,6 +26,7 @@ import org.apache.logging.log4j.core.con
 import org.apache.logging.log4j.core.config.plugins.PluginAttr;
 import org.apache.logging.log4j.core.config.plugins.PluginFactory;
 import org.apache.logging.log4j.core.helpers.NameUtil;
+import org.apache.logging.log4j.core.helpers.Strings;
 import org.apache.logging.log4j.status.StatusLogger;
 
 /**

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/db/jdbc/FactoryMethodConnectionSource.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/db/jdbc/FactoryMethodConnectionSource.java?rev=1501219&r1=1501218&r2=1501219&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/db/jdbc/FactoryMethodConnectionSource.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/db/jdbc/FactoryMethodConnectionSource.java
Tue Jul  9 12:28:00 2013
@@ -20,12 +20,14 @@ import java.io.PrintWriter;
 import java.lang.reflect.Method;
 import java.sql.Connection;
 import java.sql.SQLException;
+
 import javax.sql.DataSource;
 
 import org.apache.logging.log4j.Logger;
 import org.apache.logging.log4j.core.config.plugins.Plugin;
 import org.apache.logging.log4j.core.config.plugins.PluginAttr;
 import org.apache.logging.log4j.core.config.plugins.PluginFactory;
+import org.apache.logging.log4j.core.helpers.Strings;
 import org.apache.logging.log4j.status.StatusLogger;
 
 /**
@@ -68,7 +70,7 @@ public final class FactoryMethodConnecti
     @PluginFactory
     public static FactoryMethodConnectionSource createConnectionSource(@PluginAttr("class")
final String className,
                                                                        @PluginAttr("method")
final String methodName) {
-        if (className == null || className.length() == 0 || methodName == null || methodName.length()
== 0) {
+        if (Strings.isEmpty(className) || Strings.isEmpty(methodName)) {
             LOGGER.error("No class name or method name specified for the connection factory
method.");
             return null;
         }

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/db/jdbc/JDBCAppender.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/db/jdbc/JDBCAppender.java?rev=1501219&r1=1501218&r2=1501219&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/db/jdbc/JDBCAppender.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/db/jdbc/JDBCAppender.java
Tue Jul  9 12:28:00 2013
@@ -22,6 +22,7 @@ import org.apache.logging.log4j.core.con
 import org.apache.logging.log4j.core.config.plugins.PluginAttr;
 import org.apache.logging.log4j.core.config.plugins.PluginElement;
 import org.apache.logging.log4j.core.config.plugins.PluginFactory;
+import org.apache.logging.log4j.core.helpers.Strings;
 
 /**
  * This Appender writes logging events to a relational database using standard JDBC mechanisms.
It takes a list of
@@ -73,7 +74,7 @@ public final class JDBCAppender extends 
                                               @PluginElement("columnConfigs") final ColumnConfig[]
columnConfigs) {
         int bufferSizeInt;
         try {
-            bufferSizeInt = bufferSize == null || bufferSize.length() == 0 ? 0 : Integer.parseInt(bufferSize);
+            bufferSizeInt = Strings.isEmpty(bufferSize) ? 0 : Integer.parseInt(bufferSize);
         } catch (final NumberFormatException e) {
             LOGGER.warn("Buffer size [" + bufferSize + "] not an integer, using no buffer.");
             bufferSizeInt = 0;

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/db/jpa/JPAAppender.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/db/jpa/JPAAppender.java?rev=1501219&r1=1501218&r2=1501219&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/db/jpa/JPAAppender.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/db/jpa/JPAAppender.java
Tue Jul  9 12:28:00 2013
@@ -25,6 +25,7 @@ import org.apache.logging.log4j.core.con
 import org.apache.logging.log4j.core.config.plugins.PluginAttr;
 import org.apache.logging.log4j.core.config.plugins.PluginElement;
 import org.apache.logging.log4j.core.config.plugins.PluginFactory;
+import org.apache.logging.log4j.core.helpers.Strings;
 
 /**
  * This Appender writes logging events to a relational database using the Java Persistence
API. It requires a
@@ -69,15 +70,14 @@ public final class JPAAppender extends A
                                              @PluginAttr("bufferSize") final String bufferSize,
                                              @PluginAttr("entityClassName") final String
entityClassName,
                                              @PluginAttr("persistenceUnitName") final String
persistenceUnitName) {
-        if (entityClassName == null || entityClassName.length() == 0 ||
-                persistenceUnitName == null || persistenceUnitName.length() == 0) {
+        if (Strings.isEmpty(entityClassName) || Strings.isEmpty(persistenceUnitName)) {
             LOGGER.error("Attributes entityClassName and persistenceUnitName are required
for JPA Appender.");
             return null;
         }
 
         int bufferSizeInt;
         try {
-            bufferSizeInt = bufferSize == null || bufferSize.length() == 0 ? 0 : Integer.parseInt(bufferSize);
+            bufferSizeInt = Strings.isEmpty(bufferSize) ? 0 : Integer.parseInt(bufferSize);
         } catch (final NumberFormatException e) {
             LOGGER.warn("Buffer size [" + bufferSize + "] not an integer, using no buffer.");
             bufferSizeInt = 0;

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/db/jpa/converter/ContextMapJsonAttributeConverter.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/db/jpa/converter/ContextMapJsonAttributeConverter.java?rev=1501219&r1=1501218&r2=1501219&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/db/jpa/converter/ContextMapJsonAttributeConverter.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/db/jpa/converter/ContextMapJsonAttributeConverter.java
Tue Jul  9 12:28:00 2013
@@ -18,9 +18,12 @@ package org.apache.logging.log4j.core.ap
 
 import java.io.IOException;
 import java.util.Map;
+
 import javax.persistence.AttributeConverter;
 import javax.persistence.PersistenceException;
 
+import org.apache.logging.log4j.core.helpers.Strings;
+
 import com.fasterxml.jackson.core.type.TypeReference;
 import com.fasterxml.jackson.databind.ObjectMapper;
 
@@ -50,7 +53,7 @@ public class ContextMapJsonAttributeConv
 
     @Override
     public Map<String, String> convertToEntityAttribute(final String s) {
-        if (s == null || s.length() == 0) {
+        if (Strings.isEmpty(s)) {
             return null;
         }
         try {

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/db/jpa/converter/ContextStackJsonAttributeConverter.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/db/jpa/converter/ContextStackJsonAttributeConverter.java?rev=1501219&r1=1501218&r2=1501219&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/db/jpa/converter/ContextStackJsonAttributeConverter.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/db/jpa/converter/ContextStackJsonAttributeConverter.java
Tue Jul  9 12:28:00 2013
@@ -18,10 +18,12 @@ package org.apache.logging.log4j.core.ap
 
 import java.io.IOException;
 import java.util.List;
+
 import javax.persistence.AttributeConverter;
 import javax.persistence.PersistenceException;
 
 import org.apache.logging.log4j.ThreadContext;
+import org.apache.logging.log4j.core.helpers.Strings;
 import org.apache.logging.log4j.spi.DefaultThreadContextStack;
 
 import com.fasterxml.jackson.core.type.TypeReference;
@@ -50,7 +52,7 @@ public class ContextStackJsonAttributeCo
 
     @Override
     public ThreadContext.ContextStack convertToEntityAttribute(final String s) {
-        if (s == null || s.length() == 0) {
+        if (Strings.isEmpty(s)) {
             return null;
         }
 

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/db/jpa/converter/MarkerAttributeConverter.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/db/jpa/converter/MarkerAttributeConverter.java?rev=1501219&r1=1501218&r2=1501219&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/db/jpa/converter/MarkerAttributeConverter.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/db/jpa/converter/MarkerAttributeConverter.java
Tue Jul  9 12:28:00 2013
@@ -21,6 +21,7 @@ import javax.persistence.Converter;
 
 import org.apache.logging.log4j.Marker;
 import org.apache.logging.log4j.MarkerManager;
+import org.apache.logging.log4j.core.helpers.Strings;
 
 /**
  * A JPA 2.1 attribute converter for {@link Marker}s in {@link org.apache.logging.log4j.core.LogEvent}s.
This
@@ -55,7 +56,7 @@ public class MarkerAttributeConverter im
 
     @Override
     public Marker convertToEntityAttribute(final String s) {
-        if (s == null || s.length() == 0) {
+        if (Strings.isEmpty(s)) {
             return null;
         }
 

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/db/jpa/converter/MessageAttributeConverter.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/db/jpa/converter/MessageAttributeConverter.java?rev=1501219&r1=1501218&r2=1501219&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/db/jpa/converter/MessageAttributeConverter.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/db/jpa/converter/MessageAttributeConverter.java
Tue Jul  9 12:28:00 2013
@@ -19,6 +19,7 @@ package org.apache.logging.log4j.core.ap
 import javax.persistence.AttributeConverter;
 import javax.persistence.Converter;
 
+import org.apache.logging.log4j.core.helpers.Strings;
 import org.apache.logging.log4j.message.Message;
 import org.apache.logging.log4j.status.StatusLogger;
 
@@ -41,7 +42,7 @@ public class MessageAttributeConverter i
 
     @Override
     public Message convertToEntityAttribute(final String s) {
-        if (s == null || s.length() == 0) {
+        if (Strings.isEmpty(s)) {
             return null;
         }
 

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/db/jpa/converter/StackTraceElementAttributeConverter.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/db/jpa/converter/StackTraceElementAttributeConverter.java?rev=1501219&r1=1501218&r2=1501219&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/db/jpa/converter/StackTraceElementAttributeConverter.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/db/jpa/converter/StackTraceElementAttributeConverter.java
Tue Jul  9 12:28:00 2013
@@ -18,6 +18,8 @@ package org.apache.logging.log4j.core.ap
 
 import javax.persistence.AttributeConverter;
 
+import org.apache.logging.log4j.core.helpers.Strings;
+
 /**
  * A JPA 2.1 attribute converter for {@link StackTraceElement}s in {@link org.apache.logging.log4j.core.LogEvent}s.
This
  * converter is capable of converting both to and from {@link String}s.
@@ -38,7 +40,7 @@ public class StackTraceElementAttributeC
 
     @Override
     public StackTraceElement convertToEntityAttribute(final String s) {
-        if (s == null || s.length() == 0) {
+        if (Strings.isEmpty(s)) {
             return null;
         }
 

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/db/jpa/converter/ThrowableAttributeConverter.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/db/jpa/converter/ThrowableAttributeConverter.java?rev=1501219&r1=1501218&r2=1501219&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/db/jpa/converter/ThrowableAttributeConverter.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/db/jpa/converter/ThrowableAttributeConverter.java
Tue Jul  9 12:28:00 2013
@@ -22,9 +22,12 @@ import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 import java.util.ListIterator;
+
 import javax.persistence.AttributeConverter;
 import javax.persistence.Converter;
 
+import org.apache.logging.log4j.core.helpers.Strings;
+
 /**
  * A JPA 2.1 attribute converter for {@link Throwable}s in {@link org.apache.logging.log4j.core.LogEvent}s.
This
  * converter is capable of converting both to and from {@link String}s.
@@ -72,7 +75,7 @@ public class ThrowableAttributeConverter
 
     @Override
     public Throwable convertToEntityAttribute(final String s) {
-        if (s == null || s.length() == 0) {
+        if (Strings.isEmpty(s)) {
             return null;
         }
 

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/db/nosql/NoSQLAppender.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/db/nosql/NoSQLAppender.java?rev=1501219&r1=1501218&r2=1501219&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/db/nosql/NoSQLAppender.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/db/nosql/NoSQLAppender.java
Tue Jul  9 12:28:00 2013
@@ -22,6 +22,7 @@ import org.apache.logging.log4j.core.con
 import org.apache.logging.log4j.core.config.plugins.PluginAttr;
 import org.apache.logging.log4j.core.config.plugins.PluginElement;
 import org.apache.logging.log4j.core.config.plugins.PluginFactory;
+import org.apache.logging.log4j.core.helpers.Strings;
 
 /**
  * This Appender writes logging events to a NoSQL database using a configured NoSQL provider.
It requires
@@ -75,7 +76,7 @@ public final class NoSQLAppender extends
 
         int bufferSizeInt;
         try {
-            bufferSizeInt = bufferSize == null || bufferSize.length() == 0 ? 0 : Integer.parseInt(bufferSize);
+            bufferSizeInt = Strings.isEmpty(bufferSize) ? 0 : Integer.parseInt(bufferSize);
         } catch (final NumberFormatException e) {
             LOGGER.warn("Buffer size [" + bufferSize + "] not an integer, using no buffer.");
             bufferSizeInt = 0;

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/db/nosql/couch/CouchDBProvider.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/db/nosql/couch/CouchDBProvider.java?rev=1501219&r1=1501218&r2=1501219&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/db/nosql/couch/CouchDBProvider.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/db/nosql/couch/CouchDBProvider.java
Tue Jul  9 12:28:00 2013
@@ -24,6 +24,7 @@ import org.apache.logging.log4j.core.con
 import org.apache.logging.log4j.core.config.plugins.PluginAttr;
 import org.apache.logging.log4j.core.config.plugins.PluginFactory;
 import org.apache.logging.log4j.core.helpers.NameUtil;
+import org.apache.logging.log4j.core.helpers.Strings;
 import org.apache.logging.log4j.status.StatusLogger;
 import org.lightcouch.CouchDbClient;
 import org.lightcouch.CouchDbProperties;
@@ -147,12 +148,12 @@ public final class CouchDBProvider imple
                 LOGGER.warn("No port specified, using default port [{}] for protocol [{}].",
portInt, protocol);
             }
 
-            if (server == null || server.length() == 0) {
+            if (Strings.isEmpty(server)) {
                 server = "localhost";
                 LOGGER.warn("No server specified, using default server localhost.");
             }
 
-            if (username == null || username.length() == 0 || password == null || password.length()
== 0) {
+            if (Strings.isEmpty(username) || Strings.isEmpty(password)) {
                 LOGGER.error("You must provide a username and password for the CouchDB provider.");
                 return null;
             }

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/LoggerConfig.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/LoggerConfig.java?rev=1501219&r1=1501218&r2=1501219&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/LoggerConfig.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/LoggerConfig.java
Tue Jul  9 12:28:00 2013
@@ -45,6 +45,7 @@ import org.apache.logging.log4j.core.con
 import org.apache.logging.log4j.core.filter.AbstractFilterable;
 import org.apache.logging.log4j.core.helpers.Constants;
 import org.apache.logging.log4j.core.helpers.Loader;
+import org.apache.logging.log4j.core.helpers.Strings;
 import org.apache.logging.log4j.core.impl.DefaultLogEventFactory;
 import org.apache.logging.log4j.core.impl.LogEventFactory;
 import org.apache.logging.log4j.core.lookup.StrSubstitutor;
@@ -428,7 +429,7 @@ public class LoggerConfig extends Abstra
 
     @Override
     public String toString() {
-        return name == null || name.length() == 0 ? "root" : name;
+        return Strings.isEmpty(name) ? "root" : name;
     }
 
     /**

Added: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/helpers/Strings.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/helpers/Strings.java?rev=1501219&view=auto
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/helpers/Strings.java
(added)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/helpers/Strings.java
Tue Jul  9 12:28:00 2013
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+package org.apache.logging.log4j.core.helpers;
+
+public class Strings {
+
+    /**
+     * <p>Checks if a CharSequence is empty ("") or null.</p>
+     *
+     * <pre>
+     * Strings.isEmpty(null)      = true
+     * Strings.isEmpty("")        = true
+     * Strings.isEmpty(" ")       = false
+     * Strings.isEmpty("bob")     = false
+     * Strings.isEmpty("  bob  ") = false
+     * </pre>
+     *
+     * <p>NOTE: This method changed in Lang version 2.0.
+     * It no longer trims the CharSequence.
+     * That functionality is available in isBlank().</p>
+     * 
+     * <p>Copied from Apache Commons Lang org.apache.commons.lang3.StringUtils.isEmpty(CharSequence)</p>
+     *
+     * @param cs  the CharSequence to check, may be null
+     * @return {@code true} if the CharSequence is empty or null
+     */
+    public static boolean isEmpty(final CharSequence cs) {
+        return cs == null || cs.length() == 0;
+    }
+
+}

Propchange: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/helpers/Strings.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/helpers/Strings.java
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/helpers/Transform.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/helpers/Transform.java?rev=1501219&r1=1501218&r2=1501219&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/helpers/Transform.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/helpers/Transform.java
Tue Jul  9 12:28:00 2013
@@ -44,8 +44,7 @@ public final class Transform {
         //Check if the string is null, zero length or devoid of special characters
         // if so, return what was sent in.
 
-        if (input == null
-            || input.length() == 0
+        if (Strings.isEmpty(input)
             || (input.indexOf('"') == -1 &&
             input.indexOf('&') == -1 &&
             input.indexOf('<') == -1 &&

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/lookup/StrMatcher.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/lookup/StrMatcher.java?rev=1501219&r1=1501218&r2=1501219&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/lookup/StrMatcher.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/lookup/StrMatcher.java
Tue Jul  9 12:28:00 2013
@@ -18,6 +18,8 @@ package org.apache.logging.log4j.core.lo
 
 import java.util.Arrays;
 
+import org.apache.logging.log4j.core.helpers.Strings;
+
 /**
  * A matcher class that can be queried to determine if a character array
  * portion matches.
@@ -186,7 +188,7 @@ public abstract class StrMatcher {
      * @return a new Matcher for the given characters
      */
     public static StrMatcher charSetMatcher(final String chars) {
-        if (chars == null || chars.length() == 0) {
+        if (Strings.isEmpty(chars)) {
             return NONE_MATCHER;
         }
         if (chars.length() == 1) {
@@ -202,7 +204,7 @@ public abstract class StrMatcher {
      * @return a new Matcher for the given String
      */
     public static StrMatcher stringMatcher(final String str) {
-        if (str == null || str.length() == 0) {
+        if (Strings.isEmpty(str)) {
             return NONE_MATCHER;
         }
         return new StringMatcher(str);

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/net/DatagramSocketManager.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/net/DatagramSocketManager.java?rev=1501219&r1=1501218&r2=1501219&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/net/DatagramSocketManager.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/net/DatagramSocketManager.java
Tue Jul  9 12:28:00 2013
@@ -24,6 +24,7 @@ import java.util.Map;
 
 import org.apache.logging.log4j.core.Layout;
 import org.apache.logging.log4j.core.appender.ManagerFactory;
+import org.apache.logging.log4j.core.helpers.Strings;
 
 /**
  * Socket Manager for UDP connections.
@@ -54,7 +55,7 @@ public class DatagramSocketManager exten
      * @return A DatagramSocketManager.
      */
     public static DatagramSocketManager getSocketManager(final String host, final int port,
final Layout layout) {
-        if (host == null || host.length() == 0) {
+        if (Strings.isEmpty(host)) {
             throw new IllegalArgumentException("A host name is required");
         }
         if (port <= 0) {

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/net/SMTPManager.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/net/SMTPManager.java?rev=1501219&r1=1501218&r2=1501219&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/net/SMTPManager.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/net/SMTPManager.java
Tue Jul  9 12:28:00 2013
@@ -21,6 +21,7 @@ import java.io.IOException;
 import java.io.OutputStream;
 import java.util.Date;
 import java.util.Properties;
+
 import javax.activation.DataSource;
 import javax.mail.Authenticator;
 import javax.mail.Message;
@@ -43,6 +44,7 @@ import org.apache.logging.log4j.core.app
 import org.apache.logging.log4j.core.helpers.CyclicBuffer;
 import org.apache.logging.log4j.core.helpers.NameUtil;
 import org.apache.logging.log4j.core.helpers.NetUtils;
+import org.apache.logging.log4j.core.helpers.Strings;
 import org.apache.logging.log4j.util.PropertiesUtil;
 
 /**
@@ -77,7 +79,7 @@ public class SMTPManager extends Abstrac
                                              final String subject, String protocol, final
String host,
                                              final int port, final String username, final
String password,
                                              final boolean isDebug, final String filterName,
final int numElements) {
-        if (protocol == null || protocol.length() == 0) {
+        if (Strings.isEmpty(protocol)) {
             protocol = "smtp";
         }
 

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/net/TCPSocketManager.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/net/TCPSocketManager.java?rev=1501219&r1=1501218&r2=1501219&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/net/TCPSocketManager.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/net/TCPSocketManager.java
Tue Jul  9 12:28:00 2013
@@ -31,6 +31,7 @@ import org.apache.logging.log4j.core.Lay
 import org.apache.logging.log4j.core.appender.AppenderRuntimeException;
 import org.apache.logging.log4j.core.appender.ManagerFactory;
 import org.apache.logging.log4j.core.appender.OutputStreamManager;
+import org.apache.logging.log4j.core.helpers.Strings;
 
 /**
  * Manager of TCP Socket connections.
@@ -94,7 +95,7 @@ public class TCPSocketManager extends Ab
      */
     public static TCPSocketManager getSocketManager(final String host, int port, int delay,
                                                     final boolean immediateFail, final Layout
layout ) {
-        if (host == null || host.length() == 0) {
+        if (Strings.isEmpty(host)) {
             throw new IllegalArgumentException("A host name is required");
         }
         if (port <= 0) {

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/pattern/PatternParser.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/pattern/PatternParser.java?rev=1501219&r1=1501218&r2=1501219&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/pattern/PatternParser.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/pattern/PatternParser.java
Tue Jul  9 12:28:00 2013
@@ -28,6 +28,7 @@ import org.apache.logging.log4j.Logger;
 import org.apache.logging.log4j.core.config.Configuration;
 import org.apache.logging.log4j.core.config.plugins.PluginManager;
 import org.apache.logging.log4j.core.config.plugins.PluginType;
+import org.apache.logging.log4j.core.helpers.Strings;
 import org.apache.logging.log4j.status.StatusLogger;
 
 /**
@@ -534,9 +535,8 @@ public final class PatternParser {
         if (pc == null) {
             StringBuilder msg;
 
-            if (converterId == null || converterId.length() == 0) {
-                msg =
-                    new StringBuilder("Empty conversion specifier starting at position ");
+            if (Strings.isEmpty(converterId)) {
+                msg = new StringBuilder("Empty conversion specifier starting at position
");
             } else {
                 msg = new StringBuilder("Unrecognized conversion specifier [");
                 msg.append(converterId);

Modified: logging/log4j/log4j2/trunk/flume-ng/src/main/java/org/apache/logging/log4j/flume/appender/FlumeEmbeddedManager.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/flume-ng/src/main/java/org/apache/logging/log4j/flume/appender/FlumeEmbeddedManager.java?rev=1501219&r1=1501218&r2=1501219&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/flume-ng/src/main/java/org/apache/logging/log4j/flume/appender/FlumeEmbeddedManager.java
(original)
+++ logging/log4j/log4j2/trunk/flume-ng/src/main/java/org/apache/logging/log4j/flume/appender/FlumeEmbeddedManager.java
Tue Jul  9 12:28:00 2013
@@ -27,6 +27,7 @@ import org.apache.logging.log4j.core.app
 import org.apache.logging.log4j.core.config.ConfigurationException;
 import org.apache.logging.log4j.core.config.Property;
 import org.apache.logging.log4j.core.helpers.NameUtil;
+import org.apache.logging.log4j.core.helpers.Strings;
 import org.apache.logging.log4j.util.PropertiesUtil;
 
 /**
@@ -259,7 +260,7 @@ public class FlumeEmbeddedManager extend
                 for (final Property property : properties) {
                     final String key = property.getName();
 
-                    if (key == null || key.length() == 0) {
+                    if (Strings.isEmpty(key)) {
                         final String msg = "A property name must be provided";
                         LOGGER.error(msg);
                         throw new ConfigurationException(msg);
@@ -282,7 +283,7 @@ public class FlumeEmbeddedManager extend
                     }
 
                     final String value = property.getValue();
-                    if (value == null || value.length() == 0) {
+                    if (Strings.isEmpty(value)) {
                         final String msg = "A value for property " + key + " must be provided";
                         LOGGER.error(msg);
                         throw new ConfigurationException(msg);

Modified: logging/log4j/log4j2/trunk/flume-ng/src/main/java/org/apache/logging/log4j/flume/appender/FlumePersistentManager.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/flume-ng/src/main/java/org/apache/logging/log4j/flume/appender/FlumePersistentManager.java?rev=1501219&r1=1501218&r2=1501219&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/flume-ng/src/main/java/org/apache/logging/log4j/flume/appender/FlumePersistentManager.java
(original)
+++ logging/log4j/log4j2/trunk/flume-ng/src/main/java/org/apache/logging/log4j/flume/appender/FlumePersistentManager.java
Tue Jul  9 12:28:00 2013
@@ -32,6 +32,7 @@ import java.util.concurrent.LinkedBlocki
 import java.util.concurrent.ThreadFactory;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicInteger;
+
 import javax.crypto.Cipher;
 import javax.crypto.SecretKey;
 
@@ -44,6 +45,7 @@ import org.apache.logging.log4j.core.con
 import org.apache.logging.log4j.core.config.plugins.PluginType;
 import org.apache.logging.log4j.core.helpers.FileUtils;
 import org.apache.logging.log4j.core.helpers.SecretKeyProvider;
+import org.apache.logging.log4j.core.helpers.Strings;
 
 import com.sleepycat.je.Cursor;
 import com.sleepycat.je.CursorConfig;
@@ -141,7 +143,7 @@ public class FlumePersistentManager exte
         if (batchSize <= 0) {
             batchSize = 1;
         }
-        final String dataDirectory = dataDir == null || dataDir.length() == 0 ? DEFAULT_DATA_DIR
: dataDir;
+        final String dataDirectory = Strings.isEmpty(dataDir) ? DEFAULT_DATA_DIR : dataDir;
 
         final StringBuilder sb = new StringBuilder("FlumePersistent[");
         boolean first = true;



Mime
View raw message