Coverage Report - net.sf.jolene.constants.Prefs
 
Classes in this File Line Coverage Branch Coverage Complexity
Prefs
82%
27/33
75%
6/8
0
 
 1  
 package net.sf.jolene.constants;
 2  
 
 3  
 import org.apache.log4j.LogManager;
 4  
 import org.apache.log4j.Logger;
 5  
 
 6  
 import java.lang.reflect.Field;
 7  
 import java.util.HashMap;
 8  
 import java.util.Map;
 9  
 
 10  
 /**
 11  
  * Defined preferences for jolene.properties file. TODO maybe conver to Enum.
 12  
  *
 13  
  * @author Dan Howard
 14  
  * @since Dec 31, 2005 10:40 PM
 15  
  */
 16  
 public class Prefs {
 17  
 
 18  1
     private static final Logger log = LogManager.getLogger(Prefs.class);
 19  
 
 20  
     /**
 21  
      * Default: 32. The initial size of the internal maps used to store documents.
 22  
      *
 23  
      * @see net.sf.jolene.factories.DocumentFactory
 24  
      */
 25  1
     public static final Prefs CacheSize = new Prefs("CacheSize", 32);
 26  
 
 27  
     /**
 28  
      * Default: true. Indicates whether or not document cacheing is enabled. Cached documents
 29  
      * are read once when requested and copies are returned from the DocumentFactory. If cacheing
 30  
      * is disabled then documents are read and parsed whenever they are requested.
 31  
      *
 32  
      * @see net.sf.jolene.factories.DocumentFactory
 33  
      */
 34  1
     public static final Prefs DocumentCaching = new Prefs("DocumentCaching", true);
 35  
 
 36  
     /**
 37  
      * When set to true /resources/application.properites file is updated based on the template labels.
 38  
      */
 39  1
     public static final Prefs GenerateLocaleStrings = new Prefs("GenerateLocaleStrings", false);
 40  
 
 41  
     /**
 42  
      * Default comma (,). Used by Multi-Select objects when setting or getting option values.
 43  
      */
 44  1
     public static final Prefs SelectValueSeperator = new Prefs("SelectValueSeperator", ",");
 45  
 
 46  
     /**
 47  
      * Default true. Indicates whether Label objects should stream back their label tags. You
 48  
      * might want to set this to false if you intend to use Labels to stream back arbitrary
 49  
      * HTML or JavaScript.  In these cases you could also use the Text object.
 50  
      *
 51  
      * @see net.sf.jolene.dom.Text
 52  
      */
 53  1
     public static final Prefs StreamLabelTags = new Prefs("StreamLabelTags", true);
 54  
 
 55  
     /**
 56  
      * Default false. Indicates whether or not the streaming engine and the string utilities should
 57  
      * output in XHTML or HTML format.  It does not affect the parser.
 58  
      */
 59  1
     public static final Prefs XHTMLStrict = new Prefs("XHTMLStrict", false);
 60  
 
 61  1
     private static Map<String, Prefs> prefMap = null;
 62  
 
 63  
 
 64  
     private final String name;
 65  
     private Object value;
 66  
 
 67  6
     private Prefs(String name, Object value) {
 68  6
         this.name = name;
 69  6
         this.value = value;
 70  6
     }
 71  
 
 72  
     @Override
 73  
     public String toString() {
 74  0
         return name;
 75  
     }
 76  
 
 77  
     public String getValue() {
 78  129645
         return value.toString();
 79  
     }
 80  
 
 81  
     public void setValue(Object value) {
 82  0
         this.value = value;
 83  0
     }
 84  
 
 85  
     public static Prefs valueOf(String name) throws IllegalArgumentException {
 86  2
         if (name == null) {
 87  0
             throw new IllegalArgumentException("valueOf parameter is null");
 88  
         }
 89  
 
 90  2
         if (prefMap == null) {
 91  1
             initPrefMap();
 92  
         }
 93  2
         return prefMap.get(name.toLowerCase());
 94  
     }
 95  
 
 96  
     /**
 97  
      * Create a map using the pref strings as keys.
 98  
      */
 99  
     private static void initPrefMap() {
 100  1
         Object o = new Object();
 101  1
         synchronized (o) {
 102  1
             prefMap = new HashMap<String, Prefs>(12);
 103  
 
 104  1
             Field[] fields = Prefs.class.getFields();
 105  7
             for (int j = 0; j < fields.length; j++) {
 106  
 
 107  
                 try {
 108  6
                     if (Prefs.class.equals(fields[j].getType())) {
 109  6
                         prefMap.put(fields[j].getName().toLowerCase(), (Prefs) fields[j].get(j));
 110  
                     }
 111  0
                 } catch (IllegalAccessException e) {
 112  0
                     log.error(e.getMessage(), e);
 113  6
                 }
 114  
             }
 115  1
         }
 116  1
     }
 117  
 }
 118