-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClientInfo.java
More file actions
55 lines (43 loc) · 1.53 KB
/
ClientInfo.java
File metadata and controls
55 lines (43 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package client.domain;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
public class ClientInfo {
String key;
public ClientInfo() {
loadProperties();
}
private void loadProperties() {
try (InputStream input = getClass().getClassLoader().getResourceAsStream("application.properties")) {
Properties properties = new Properties();
properties.load(input);
key = properties.getProperty("client.key");
} catch (IOException e) {
e.printStackTrace();
}
}
public String getKey() {
return key;
}
public Document toXmlDocument() {
try {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.newDocument();
Element rootElement = document.createElement("ClientInfo");
document.appendChild(rootElement);
Element keyElement = document.createElement("key");
keyElement.appendChild(document.createTextNode(key));
rootElement.appendChild(keyElement);
return document;
} catch (ParserConfigurationException e) {
e.printStackTrace();
return null;
}
}
}