/*
 * Copyright 1999,2004 The Apache Software Foundation.
 * 
 * Licensed 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.log4j.pattern;

import org.apache.log4j.spi.LoggingEvent;

import java.util.*;


/**
 * Able to handle the contents of the LoggingEvent's Property bundle and either
 * output the entire contents of the properties in a similar format to the
 * java.util.Hashtable.toString(), or to output the value of a specific key 
 * within the property bundle
 * when this pattern converter has the option set.
 *
 * @author Paul Smith
 * @author Ceki G&uuml;lc&uuml;
 *@since 1.3
 */
public class PropertiesPatternConverter extends PatternConverter {

    public StringBuffer convert(LoggingEvent event) {

        StringBuffer buf = new StringBuffer(32);

        /**
         * if there is no additional options, we output every single
         * Key/Value pair for the MDC in a similar format to Hashtable.toString()
         */
        if (option == null) {
            buf.append("{");

            Set keySet = event.getPropertyKeySet();

            for (Iterator i = keySet.iterator(); i.hasNext();) {

                Object item = i.next();
                Object val = event.getProperty(item.toString());
                buf.append("{").append(item).append(",").append(val).append(
                    "}");
            }

            buf.append("}");

            return buf;
        }

        /**
         * otherwise they just want a single key output
         */
        Object val = event.getProperty(option);

        if (val != null) {

            return buf.append(val);
        }

        return buf;
    }
    
    public String getName()
    {
        return "Property";
    }
    
}

@@ -53,17 +53,16 @@
 tion.%0A *
- 
 %0A * Lice
@@ -234,17 +234,16 @@
 se at%0A *
- 
 %0A *     
@@ -288,17 +288,16 @@
 E-2.0%0A *
- 
 %0A * Unle
@@ -1173,19 +1173,37 @@
 erter %7B%0A
+  
 %0A  
+String name;%0A  %0A
   public
@@ -1243,28 +1243,24 @@
 t event) %7B%0A%0A
-    
     StringBu
@@ -1297,34 +1297,18 @@
 );%0A%0A    
-    /**%0A         *
+//
  if ther
@@ -1362,22 +1362,18 @@
 gle%0A    
-   
-  *
+//
  Key/Val
@@ -1436,32 +1436,16 @@
 tring()%0A
-         */%0A    
     if (
@@ -1464,30 +1464,24 @@
 ll) %7B%0A      
- 
-     
 buf.append(%22
@@ -1482,30 +1482,24 @@
 pend(%22%7B%22);%0A%0A
-      
       Set ke
@@ -1529,30 +1529,24 @@
 yKeySet();%0A%0A
-      
       for (I
@@ -1592,28 +1592,24 @@
 t();) %7B%0A
-%0A   
         
      Obj
@@ -1596,29 +1596,24 @@
 ) %7B%0A        
-     
 Object item 
@@ -1632,24 +1632,16 @@
         
-      
-  
 Object v
@@ -1681,24 +1681,16 @@
 ing());%0A
-        
         
@@ -1753,29 +1753,8 @@
 end(
-%0A                    
 %22%7D%22)
@@ -1761,31 +1761,19 @@
 ;%0A      
- 
-     %7D%0A%0A      
+%7D%0A%0A
       bu
@@ -1788,22 +1788,16 @@
 (%22%7D%22);%0A%0A
-      
       re
@@ -1806,20 +1806,16 @@
 rn buf;%0A
-    
     %7D%0A%0A 
@@ -1821,26 +1821,10 @@
     
-    /**%0A         *
+//
  oth
@@ -1869,24 +1869,8 @@
 put%0A
-         */%0A    
     
@@ -1910,20 +1910,16 @@
 tion);%0A%0A
-    
     if (
@@ -1937,21 +1937,14 @@
 ) %7B%0A
-%0A     
       
- 
 retu
@@ -1963,20 +1963,16 @@
 d(val);%0A
-    
     %7D%0A%0A 
@@ -1970,28 +1970,24 @@
 %0A    %7D%0A%0A    
- 
-   
 return buf;%0A
@@ -1990,21 +1990,13 @@
 uf;%0A
-  
   %7D%0A
-    %0A  
+%0A
   pu
@@ -2020,29 +2020,130 @@
 me()
+ %7B
 %0A    
-%7B%0A        return
+if(name == null) %7B%0A      if(option != null) %7B%0A        name += %22Property%7B%22+option+%22%7D%22;%0A      %7D else %7B%0A        name =
  %22Pr
@@ -2151,12 +2151,16 @@
 pert
-y
+ies
 %22;%0A
+  
     
@@ -2165,11 +2165,33 @@
   %7D%0A    
+%7D%0A    return name;%0A  %7D
 %0A%7D%0A

A bit more descriptive name.