Added: 
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/helper/ZipCompressAction.java
URL: 
http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/helper/ZipCompressAction.java?rev=1096644&view=auto
==============================================================================
--- 
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/helper/ZipCompressAction.java
 (added)
+++ 
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/helper/ZipCompressAction.java
 Tue Apr 26 02:55:35 2011
@@ -0,0 +1,129 @@
+/*
+ * 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.appender.rolling.helper;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipOutputStream;
+
+
+/**
+ * Compresses a file using Zip compression.
+ */
+public final class ZipCompressAction extends ActionBase {
+    /**
+     * Source file.
+     */
+    private final File source;
+
+    /**
+     * Destination file.
+     */
+    private final File destination;
+
+    /**
+     * If true, attempt to delete file on completion.
+     */
+    private final boolean deleteSource;
+
+
+    /**
+     * Create new instance of GZCompressAction.
+     *
+     * @param source       file to compress, may not be null.
+     * @param destination  compressed file, may not be null.
+     * @param deleteSource if true, attempt to delete file on completion.  
Failure to delete
+     *                     does not cause an exception to be thrown or affect 
return value.
+     */
+    public ZipCompressAction(final File source, final File destination, final 
boolean deleteSource) {
+        if (source == null) {
+            throw new NullPointerException("source");
+        }
+
+        if (destination == null) {
+            throw new NullPointerException("destination");
+        }
+
+        this.source = source;
+        this.destination = destination;
+        this.deleteSource = deleteSource;
+    }
+
+    /**
+     * Compress.
+     *
+     * @return true if successfully compressed.
+     * @throws IOException on IO exception.
+     */
+    public boolean execute() throws IOException {
+        return execute(source, destination, deleteSource);
+    }
+
+    /**
+     * Compress a file.
+     *
+     * @param source       file to compress, may not be null.
+     * @param destination  compressed file, may not be null.
+     * @param deleteSource if true, attempt to delete file on completion.  
Failure to delete
+     *                     does not cause an exception to be thrown or affect 
return value.
+     * @return true if source file compressed.
+     * @throws IOException on IO exception.
+     */
+    public static boolean execute(final File source, final File destination, 
final boolean deleteSource)
+        throws IOException {
+        if (source.exists()) {
+            FileInputStream fis = new FileInputStream(source);
+            FileOutputStream fos = new FileOutputStream(destination);
+            ZipOutputStream zos = new ZipOutputStream(fos);
+
+            ZipEntry zipEntry = new ZipEntry(source.getName());
+            zos.putNextEntry(zipEntry);
+
+            byte[] inbuf = new byte[8102];
+            int n;
+
+            while ((n = fis.read(inbuf)) != -1) {
+                zos.write(inbuf, 0, n);
+            }
+
+            zos.close();
+            fis.close();
+
+            if (deleteSource && !source.delete()) {
+                logger.warn("Unable to delete " + source.toString() + ".");
+            }
+
+            return true;
+        }
+
+        return false;
+    }
+
+    /**
+     * Capture exception.
+     *
+     * @param ex exception.
+     */
+    protected void reportException(final Exception ex) {
+        logger.warn("Exception during compression of '" + source.toString() + 
"'.", ex);
+    }
+}

Added: 
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/helper/package.html
URL: 
http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/helper/package.html?rev=1096644&view=auto
==============================================================================
--- 
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/helper/package.html
 (added)
+++ 
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/helper/package.html
 Tue Apr 26 02:55:35 2011
@@ -0,0 +1,28 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<!--
+ 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.
+
+-->
+<html> <head>
+<title></title>
+</head>
+
+<body>
+
+<p>Internal helper classes used by {@link 
org.apache.logging.log4j.core.appender.rolling} package.</p>
+
+<hr>
+</body> </html>

Modified: 
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/plugins/PluginManager.java
URL: 
http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/plugins/PluginManager.java?rev=1096644&r1=1096643&r2=1096644&view=diff
==============================================================================
--- 
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/plugins/PluginManager.java
 (original)
+++ 
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/plugins/PluginManager.java
 Tue Apr 26 02:55:35 2011
@@ -33,6 +33,7 @@ public class PluginManager {
     private static CopyOnWriteArrayList<String> packages = new 
CopyOnWriteArrayList<String>();
 
     private final String type;
+    private final Class clazz;
 
     static {
         packages.add("org.apache.logging.log4j");
@@ -40,6 +41,13 @@ public class PluginManager {
 
     public PluginManager(String type) {
         this.type = type;
+        this.clazz = null;
+    }
+
+
+    public PluginManager(String type, Class clazz) {
+        this.type = type;
+        this.clazz = clazz;
     }
 
     public static void addPackage(String p) {
@@ -57,7 +65,7 @@ public class PluginManager {
 
     public void collectPlugins() {
         ResolverUtil<?> r = new ResolverUtil();
-        ResolverUtil.Test test = new PluginTest(type);
+        ResolverUtil.Test test = new PluginTest(type, clazz);
         for (String pkg : packages) {
             r.findInPackage(test, pkg);
         }
@@ -75,21 +83,36 @@ public class PluginManager {
      * is, then the test returns true, otherwise false.
      */
     public static class PluginTest extends ResolverUtil.ClassTest {
-        private String type;
+        private final String type;
+        private final Class isA;
 
         /** Constructs an AnnotatedWith test for the specified annotation 
type. */
         public PluginTest(String type) {
             this.type = type;
+            this.isA = null;
+        }
+
+
+        /** Constructs an AnnotatedWith test for the specified annotation 
type. */
+        public PluginTest(String type, Class isA) {
+            this.type = type;
+            this.isA = isA;
         }
 
         /** Returns true if the type is annotated with the class provided to 
the constructor. */
         public boolean matches(Class type) {
             return type != null && type.isAnnotationPresent(Plugin.class) &&
-                
this.type.equals(((Plugin)type.getAnnotation(Plugin.class)).type());
+                
this.type.equals(((Plugin)type.getAnnotation(Plugin.class)).type()) &&
+                (isA == null || isA.isAssignableFrom(type));
         }
 
         @Override public String toString() {
-            return "annotated with @" + Plugin.class.getSimpleName();
+            StringBuilder msg = new StringBuilder("annotated with @" + 
Plugin.class.getSimpleName());
+            if (isA != null) {
+                msg.append(" is assignable to " + isA.getSimpleName());
+            }
+            return msg.toString();
         }
     }
+
 }

Modified: 
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/layout/PatternLayout.java
URL: 
http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/layout/PatternLayout.java?rev=1096644&r1=1096643&r2=1096644&view=diff
==============================================================================
--- 
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/layout/PatternLayout.java
 (original)
+++ 
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/layout/PatternLayout.java
 Tue Apr 26 02:55:35 2011
@@ -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.PluginFactory;
 import org.apache.logging.log4j.core.helpers.OptionConverter;
+import org.apache.logging.log4j.core.pattern.LogEventPatternConverter;
 import org.apache.logging.log4j.core.pattern.PatternConverter;
 import org.apache.logging.log4j.core.pattern.PatternParser;
 
@@ -496,7 +497,7 @@ public class PatternLayout extends Layou
 
     private PatternParser createPatternParser() {
 
-        return new PatternParser(KEY);
+        return new PatternParser(KEY, LogEventPatternConverter.class);
     }
 
     public String toString() {

Modified: 
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/pattern/DatePatternConverter.java
URL: 
http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/pattern/DatePatternConverter.java?rev=1096644&r1=1096643&r2=1096644&view=diff
==============================================================================
--- 
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/pattern/DatePatternConverter.java
 (original)
+++ 
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/pattern/DatePatternConverter.java
 Tue Apr 26 02:55:35 2011
@@ -18,9 +18,12 @@
 package org.apache.logging.log4j.core.pattern;
 
 import org.apache.logging.log4j.core.LogEvent;
+import org.apache.logging.log4j.core.appender.rolling.RolloverFrequency;
 import org.apache.logging.log4j.core.config.plugins.Plugin;
 
+import java.text.ParseException;
 import java.text.SimpleDateFormat;
+import java.util.Calendar;
 import java.util.Date;
 import java.util.TimeZone;
 
@@ -160,4 +163,9 @@ public final class DatePatternConverter 
             toAppendTo.append(simpleFormat.format(date.getTime()));
         }
     }
+
+    public String getPattern() {
+        return simpleFormat.toPattern();
+    }
+
 }

Modified: 
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/pattern/FileDatePatternConverter.java
URL: 
http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/pattern/FileDatePatternConverter.java?rev=1096644&r1=1096643&r2=1096644&view=diff
==============================================================================
--- 
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/pattern/FileDatePatternConverter.java
 (original)
+++ 
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/pattern/FileDatePatternConverter.java
 Tue Apr 26 02:55:35 2011
@@ -39,8 +39,7 @@ public final class FileDatePatternConver
      * @param options options, may be null.
      * @return instance of pattern converter.
      */
-    public static PatternConverter newInstance(
-        final String[] options) {
+    public static PatternConverter newInstance(final String[] options) {
         if ((options == null) || (options.length == 0)) {
             return DatePatternConverter.newInstance(
                 new String[]{

Modified: 
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/pattern/LiteralPatternConverter.java
URL: 
http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/pattern/LiteralPatternConverter.java?rev=1096644&r1=1096643&r2=1096644&view=diff
==============================================================================
--- 
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/pattern/LiteralPatternConverter.java
 (original)
+++ 
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/pattern/LiteralPatternConverter.java
 Tue Apr 26 02:55:35 2011
@@ -24,24 +24,30 @@ import org.apache.logging.log4j.core.Log
  * Formats a string literal.
  */
 public final class LiteralPatternConverter extends LogEventPatternConverter {
-  /**
-   * String literal.
-   */
-  private final String literal;
+    /**
+     * String literal.
+     */
+    private final String literal;
 
-  /**
-   * Create a new instance.
-   * @param literal string literal.
-   */
-  public LiteralPatternConverter(final String literal) {
-    super("Literal", "literal");
-    this.literal = literal;
-  }
+    /**
+     * Create a new instance.
+     *
+     * @param literal string literal.
+     */
+    public LiteralPatternConverter(final String literal) {
+        super("Literal", "literal");
+        this.literal = literal;
+    }
 
-  /**
-   * {@inheritDoc}
-   */
-  public void format(final LogEvent event, final StringBuilder toAppendTo) {
-    toAppendTo.append(literal);
-  }
+    /**
+     * {@inheritDoc}
+     */
+    public void format(final LogEvent event, final StringBuilder toAppendTo) {
+        toAppendTo.append(literal);
+    }
+
+    @Override
+    public void format(final Object obj, final StringBuilder output) {
+        output.append(literal);
+    }
 }

Modified: 
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/pattern/PatternParser.java
URL: 
http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/pattern/PatternParser.java?rev=1096644&r1=1096643&r2=1096644&view=diff
==============================================================================
--- 
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/pattern/PatternParser.java
 (original)
+++ 
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/pattern/PatternParser.java
 Tue Apr 26 02:55:35 2011
@@ -76,12 +76,16 @@ public final class PatternParser {
     protected final static Logger logger = StatusLogger.getLogger();
 
 
+    public PatternParser(String converterKey) {
+        this(converterKey, null);
+    }
+
     /**
      * Constructor
      * @param converterKey The key to lookup the converters.
      */
-    public PatternParser(String converterKey) {
-        PluginManager manager = new PluginManager(converterKey);
+    public PatternParser(String converterKey, Class expected) {
+        PluginManager manager = new PluginManager(converterKey, expected);
         manager.collectPlugins();
         Map<String, PluginType> plugins = manager.getPlugins();
         Map<String, Class<PatternConverter>> converters = new HashMap<String, 
Class<PatternConverter>>();
@@ -107,7 +111,7 @@ public final class PatternParser {
         List<PatternConverter> converters = new ArrayList<PatternConverter>();
         List<FormattingInfo> fields = new ArrayList<FormattingInfo>();
 
-        parse(pattern, converters, fields, converterRules);
+        parse(pattern, converters, fields);
 
         LogEventPatternConverter[] patternConverters = new 
LogEventPatternConverter[converters.size()];
         FormattingInfo[] patternFields = new FormattingInfo[converters.size()];
@@ -209,11 +213,9 @@ public final class PatternParser {
      * @param pattern           pattern to parse.
      * @param patternConverters list to receive pattern converters.
      * @param formattingInfos   list to receive field specifiers corresponding 
to pattern converters.
-     * @param rules             map of stock pattern converters keyed by 
format specifier.
      */
     public void parse(final String pattern, final List<PatternConverter> 
patternConverters,
-            final List<FormattingInfo> formattingInfos,
-            final Map<String, Class<PatternConverter>> rules) {
+            final List<FormattingInfo> formattingInfos) {
         if (pattern == null) {
             throw new NullPointerException("pattern");
         }
@@ -290,7 +292,7 @@ public final class PatternParser {
                                 state = MIN_STATE;
                             } else {
                                 i = finalizeConverter(c, pattern, i, 
currentLiteral, formattingInfo,
-                                        rules, patternConverters, 
formattingInfos);
+                                        converterRules, patternConverters, 
formattingInfos);
 
                                 // Next pattern is assumed to be a literal.
                                 state = LITERAL_STATE;
@@ -312,7 +314,7 @@ public final class PatternParser {
                         state = DOT_STATE;
                     } else {
                         i = finalizeConverter(c, pattern, i, currentLiteral, 
formattingInfo,
-                                rules, patternConverters, formattingInfos);
+                                converterRules, patternConverters, 
formattingInfos);
                         state = LITERAL_STATE;
                         formattingInfo = FormattingInfo.getDefault();
                         currentLiteral.setLength(0);
@@ -345,7 +347,7 @@ public final class PatternParser {
                                 (formattingInfo.getMaxLength() * 10) + (c - 
'0'));
                     } else {
                         i = finalizeConverter(c, pattern, i, currentLiteral, 
formattingInfo,
-                                rules, patternConverters, formattingInfos);
+                                converterRules, patternConverters, 
formattingInfos);
                         state = LITERAL_STATE;
                         formattingInfo = FormattingInfo.getDefault();
                         currentLiteral.setLength(0);



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to