1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package net.sf.dexterim.msn;
20
21 import java.io.IOException;
22 import java.util.ArrayList;
23 import java.util.Iterator;
24 import java.util.List;
25
26 import org.apache.commons.logging.Log;
27 import org.apache.commons.logging.LogFactory;
28 import org.jdom.Document;
29 import org.jdom.Element;
30 import org.jdom.JDOMException;
31 import org.jdom.input.SAXBuilder;
32
33
34 /***
35 * @author christoph
36 *
37 */
38 public class MsnConfiguration {
39 private static final Log log = LogFactory.getLog(MsnConfiguration.class);
40
41 private static MsnConfiguration instance;
42 private List versions;
43 private String hostInformation;
44 private String challengeMagic;
45
46 private MsnConfiguration() {
47
48 SAXBuilder builder = new SAXBuilder();
49
50 try {
51 Document doc = builder.build(MsnConfiguration.class.getResource("protocol.xml"));
52
53 Element root = doc.getRootElement();
54
55 for (Iterator iter = root.getChildren().iterator(); iter.hasNext();) {
56 Element element = (Element) iter.next();
57
58 if ("versions".equals(element.getName())) {
59 versions = parseProtocolVersions(element);
60 }
61
62 if ("hostinformation".equals(element.getName())) {
63 hostInformation = element.getAttributeValue("id");
64 }
65
66 if ("challenge".equals(element.getName())) {
67 this.challengeMagic = element.getAttributeValue("magic");
68 }
69 }
70 }
71 catch (JDOMException e) {
72 log.fatal("Could not parse Msn protocol configuration file", e);
73 }
74 catch (IOException e) {
75 log.fatal("Could not open Msn protocol configuration file", e);
76 }
77
78
79
80 }
81
82 private List parseProtocolVersions(Element versionsElement) {
83 List versions = new ArrayList();
84
85 for (Iterator iter = versionsElement.getChildren().iterator(); iter.hasNext();) {
86 Element version = (Element) iter.next();
87
88 versions.add(version.getAttributeValue("id"));
89 }
90
91 return versions;
92 }
93
94 public List getVersions() {
95 return versions;
96 }
97
98 public static synchronized MsnConfiguration getInstance() {
99 if (instance == null) {
100 instance = new MsnConfiguration();
101 }
102
103 return instance;
104 }
105
106 /***
107 * @return Returns the hostInformation.
108 */
109 public String getHostInformation() {
110 return hostInformation;
111 }
112
113 /***
114 * @return Returns the challengeMagic.
115 */
116 public String getChallengeMagic() {
117 return challengeMagic;
118 }
119 }