| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 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 |
|
|
|
|
|
| 69.1% |
Uncovered Elements: 17 (55) |
Complexity: 17 |
Complexity Density: 0.5 |
|
| 26 |
|
public class DefaultPreferences implements Preferences |
| 27 |
|
{ |
| 28 |
|
static Preferences _instance; |
| 29 |
|
private PropertySet backingPS; |
| 30 |
|
|
|
|
|
| 73.5% |
Uncovered Elements: 9 (34) |
Complexity: 8 |
Complexity Density: 0.33 |
|
| 31 |
1
|
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 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
| 72 |
10
|
public static Preferences getPreferences()... |
| 73 |
|
{ |
| 74 |
10
|
if (_instance == null) |
| 75 |
|
{ |
| 76 |
1
|
_instance = new DefaultPreferences(); |
| 77 |
|
} |
| 78 |
|
|
| 79 |
10
|
return _instance; |
| 80 |
|
} |
| 81 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 82 |
7
|
public long getLong(String key)... |
| 83 |
|
{ |
| 84 |
7
|
return backingPS.getLong(key); |
| 85 |
|
} |
| 86 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 87 |
1
|
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 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 92 |
1
|
public String getString(String key)... |
| 93 |
|
{ |
| 94 |
1
|
return backingPS.getString(key); |
| 95 |
|
} |
| 96 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 97 |
0
|
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 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 102 |
0
|
public boolean getBoolean(String key)... |
| 103 |
|
{ |
| 104 |
0
|
return backingPS.getBoolean(key); |
| 105 |
|
} |
| 106 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 107 |
0
|
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 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 112 |
0
|
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 |
|
} |