Clover Coverage Report - Atlassian Core
Coverage timestamp: Sun Nov 30 2008 18:33:35 CST
34   116   17   3.78
12   93   0.5   9
9     1.89  
1    
 
 
  DefaultPreferences       Line # 26 34 17 69.1% 0.6909091
 
  (8)
 
1    /*
2    * Atlassian Source Code Template.
3    * User: owen
4    * Date: Oct 15, 2002
5    * Time: 11:06:58 AM
6    * CVS Revision: $Revision: 1.10 $
7    * Last CVS Commit: $Date: 2003/10/20 04:53:30 $
8    * Author of last CVS Commit: $Author: amazkovoi $
9    */
10    package com.atlassian.core.user.preferences;
11   
12    import com.atlassian.core.AtlassianCoreException;
13    import com.atlassian.core.util.ClassLoaderUtils;
14    import com.atlassian.core.util.XMLUtils;
15    import com.opensymphony.module.propertyset.PropertySet;
16    import com.opensymphony.module.propertyset.PropertySetManager;
17    import org.w3c.dom.Document;
18    import org.w3c.dom.Element;
19    import org.w3c.dom.NodeList;
20   
21    import javax.xml.parsers.DocumentBuilder;
22    import javax.xml.parsers.DocumentBuilderFactory;
23    import java.io.IOException;
24    import java.io.InputStream;
25   
 
26    public class DefaultPreferences implements Preferences
27    {
28    static Preferences _instance;
29    private PropertySet backingPS;
30   
 
31  1 toggle public DefaultPreferences()
32    {
33  1 backingPS = PropertySetManager.getInstance("memory", null);
34   
35  1 InputStream defaults = ClassLoaderUtils.getResourceAsStream("preferences-default.xml", this.getClass());
36  1 try
37    {
38  1 DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
39  1 Document xmlDoc = db.parse(defaults);
40  1 Element root = xmlDoc.getDocumentElement();
41  1 NodeList preferences = root.getElementsByTagName("preference");
42  3 for (int i = 0; i < preferences.getLength(); i++)
43    {
44  2 Element preference = (Element) preferences.item(i);
45  2 String operation = preference.getAttribute("type");
46  2 if (operation == null)
47  0 operation = "String";
48  2 String name = XMLUtils.getContainedText(preference, "name");
49  2 String value = XMLUtils.getContainedText(preference, "value");
50  2 if ("String".equals(operation))
51  1 backingPS.setString(name, value);
52  1 else if ("Long".equals(operation))
53  1 backingPS.setLong(name, new Long(value).longValue());
54  0 else if ("Boolean".equals(operation))
55  0 backingPS.setBoolean(name, new Boolean(value).booleanValue());
56    }
57    }
58    catch (Exception e)
59    {
60  0 e.printStackTrace();
61    }
62  1 try
63    {
64  1 defaults.close();
65    }
66    catch (IOException e)
67    {
68  0 e.printStackTrace();
69    }
70    }
71   
 
72  10 toggle public static Preferences getPreferences()
73    {
74  10 if (_instance == null)
75    {
76  1 _instance = new DefaultPreferences();
77    }
78   
79  10 return _instance;
80    }
81   
 
82  7 toggle public long getLong(String key)
83    {
84  7 return backingPS.getLong(key);
85    }
86   
 
87  1 toggle public void setLong(String key, long value) throws AtlassianCoreException
88    {
89  1 throw new AtlassianCoreException("Trying to set a Default preference this is not allowed");
90    }
91   
 
92  1 toggle public String getString(String key)
93    {
94  1 return backingPS.getString(key);
95    }
96   
 
97  0 toggle public void setString(String key, String value) throws AtlassianCoreException
98    {
99  0 throw new AtlassianCoreException("Trying to set a Default preference this is not allowed");
100    }
101   
 
102  0 toggle public boolean getBoolean(String key)
103    {
104  0 return backingPS.getBoolean(key);
105    }
106   
 
107  0 toggle public void setBoolean(String key, boolean b) throws AtlassianCoreException
108    {
109  0 throw new AtlassianCoreException("Trying to set a Default preference this is not allowed");
110    }
111   
 
112  0 toggle public void remove(String key) throws AtlassianCoreException
113    {
114  0 throw new AtlassianCoreException("Trying to set a Default preference this is not allowed");
115    }
116    }