P15GEN2\59518
2025-10-10 9f6890646993d16260d4201d613c092132856127
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package foundation.server.config;
 
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
 
import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
 
public class SecretMap {
    
    private static SecretMap instance;
    private Map<String, String> secrets;
    
    public static SecretMap getInstance() {
        if (instance == null) {
            instance = new SecretMap();
        }
 
        return instance;
    }
 
    
    public SecretMap() {
        this.secrets = new HashMap<String, String>();
    }
 
 
    public void loadOneFile(File file) throws Exception {
        try {
            InputStream inputStream = new FileInputStream(file);
 
            try {
                SAXReader reader = new SAXReader();
                reader.setValidation(false);
 
                Document doc = reader.read(inputStream);
                Element root = doc.getRootElement();
 
                loadParams(root);
            } 
            finally {
                try {
                    inputStream.close();
                } catch (IOException e) {
                }
            }
        } catch (Exception e) {
            throw e;
        }
    }
    
    private void loadParams(Element root) throws Exception {
        Iterator<?> iterator = root.elementIterator("secret");
 
        while (iterator.hasNext()) {
            Element element = (Element) iterator.next();
 
            String name = element.attributeValue("systemId");
            String value = element.attributeValue("secret");
 
            secrets.put(name, value);
        }
    }
    
    public static String getSecret(String systemId) {
        return instance.secrets.get(systemId);
    }
}