01: package com.bostechcorp.cbesb.common.util.macro;
02:
03: import java.io.IOException;
04: import java.io.InputStream;
05: import java.util.HashMap;
06: import java.util.Properties;
07:
08: import com.bostechcorp.cbesb.common.util.ErrorUtil;
09:
10: public class UserMacroResolverImpl implements IMacroResolver {
11:
12: private static HashMap<String, String> macroMap = new HashMap<String, String>();
13:
14: public UserMacroResolverImpl() {
15: super ();
16: }
17:
18: public boolean addMacro(String name, String value) {
19: macroMap.put(name, value);
20: return true;
21: }
22:
23: public void loadMacro(InputStream macroFile) {
24: Properties properties = new Properties();
25: try {
26: properties.load(macroFile);
27: } catch (IOException e) {
28: e.printStackTrace();
29: ErrorUtil.printError("Load macro error:", e);
30: }
31:
32: for (Object key : properties.keySet()) {
33: macroMap.put((String) key, properties
34: .getProperty((String) key));
35: }
36: }
37:
38: public String resolveMacro(String macroStr, String originalStr) {
39: return macroMap.get(macroStr);
40: }
41:
42: public void clearMacro() {
43: macroMap.clear();
44: }
45:
46: }
|