KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tonbeller > tbutils > res > StringDumper


1 package com.tonbeller.tbutils.res;
2
3 import java.util.ArrayList JavaDoc;
4 import java.util.Collections JavaDoc;
5 import java.util.Iterator JavaDoc;
6 import java.util.List JavaDoc;
7
8 /** dumps into StringBuffer */
9
10 public class StringDumper implements Dumper {
11   
12   private static final String JavaDoc SEP = "===================================\n";
13   StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
14   
15   public StringDumper() {
16   }
17   
18   /**
19    * return false for properties that should not be visible in the log file,
20    * e.g. passwords etc.
21    */

22   protected boolean accept(String JavaDoc name) {
23     return true;
24   }
25   
26   public void dump(ResourceProvider p) {
27     if (p == null)
28       return;
29     sb.append(SEP);
30     sb.append(p.getClass().getName()).append(": ").append(p.getName()).append("\n");
31     sb.append(SEP);
32     List JavaDoc keys = new ArrayList JavaDoc();
33     keys.addAll(p.keySet());
34     Collections.sort(keys);
35     for (Iterator JavaDoc it = keys.iterator(); it.hasNext();) {
36       String JavaDoc key = (String JavaDoc) it.next();
37       if (!accept(key))
38         continue;
39       String JavaDoc val = p.getString(key);
40       sb.append(key).append(" = ").append(val).append("\n");
41     }
42   }
43   
44   public String JavaDoc toString() {
45     return sb.toString();
46   }
47
48 }
49
Popular Tags