1 package com.atlassian.user.configuration.xml;
2
3 import org.dom4j.Element;
4 import org.dom4j.Attribute;
5
6 import java.util.HashMap;
7 import java.util.List;
8 import java.util.Map;
9
10 import com.atlassian.user.configuration.Configuration;
11
12
13
14
15 final class XMLConfigUtil
16 {
17
18
19 private XMLConfigUtil()
20 {
21 }
22
23
24
25
26
27
28
29
30
31 public static HashMap<String, String> parseRepositoryElementForClassNames(Element repositoryElement)
32 {
33 HashMap<String, String> values = new HashMap<String, String>();
34 Element classesElement = repositoryElement.element(Configuration.CLASSES);
35
36 if (classesElement == null)
37 return values;
38
39 List subElements = classesElement.elements();
40
41 for (Object subElement : subElements)
42 {
43 Element element = (Element) subElement;
44
45 if (element.getName().equals(Configuration.PARAM))
46 {
47 Attribute paramAttribute = element.attribute(Configuration.NAME);
48 values.put(paramAttribute.getText(), element.getText());
49 }
50 else
51 values.put(element.getName(), element.getText());
52 }
53
54 Attribute attr = repositoryElement.attribute(Configuration.CLASS);
55
56 if (attr != null)
57 {
58 values.put(Configuration.CLASS, attr.getText());
59 }
60
61 return values;
62 }
63
64
65
66
67
68
69
70
71 public static Map<String, String> parseRepositoryElementForStringData(Element repositoryElement)
72 {
73 HashMap<String, String> values = new HashMap<String, String>();
74
75 for (Object o : repositoryElement.attributes())
76 {
77 Attribute attr = (Attribute) o;
78
79 if (attr.getName().equals(Configuration.CLASS))
80 continue;
81
82 values.put(attr.getName(), attr.getText());
83 }
84
85 for (Object o : repositoryElement.elements())
86 {
87 Element element = (Element) o;
88
89 if (element.getName().equals(Configuration.CLASSES))
90 continue;
91
92 values.put(element.getName(), element.getText());
93 }
94
95 return values;
96 }
97
98 }