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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package fr.opensagres.xdocreport.template.freemarker.internal;
 
import java.text.ParseException;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
 
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
 
import foundation.dao.PackageStringMap;
import foundation.util.Util;
import fr.opensagres.xdocreport.template.IContext;
import fr.opensagres.xdocreport.template.utils.TemplateUtils;
 
public class XDocFreemarkerContext implements IContext {
    
    protected static Logger logger;
    private Map<String, Object> contextMap;
    private Map<String, Object> dataMap;
 
    static {
        logger = LogManager.getLogger(XDocFreemarkerContext.class);
    }
    
    public XDocFreemarkerContext() {
        this(new HashMap<String, Object>());
    }
 
    public XDocFreemarkerContext(Map<String, Object> contextMap) {
        this.contextMap = contextMap;
    }
 
    public Object put(String key, Object value) {
        Object result = TemplateUtils.putContextForDottedKey(this, key, value);
        
        if (result == null) {
            return this.contextMap.put(key, value);
        }
        
        return result;
    }
 
    public Object get(String key) {
        Object result = this.contextMap.get(key);
        
        if (result != null) {
            return result;
        }
        
        if (dataMap == null || key.startsWith("__")) {
            return null;
        }
        
        int pos = key.indexOf(PackageStringMap.Spliter);
        int formatPos = key.indexOf("___");
        
        if (pos > 0 && formatPos < 0) {
            result = dataMap.get(key);
        }
        else if (pos > 0 && formatPos > 0) {
            result = dataMap.get(key.substring(0, formatPos));
            String formater = key.substring(formatPos + 3);
            if (isDateFormat(formater)) {
                Date value;
                try {
                    value = Util.StringToDate((String)result);
                    result = Util.DataTimeToString(value, formater);
                } catch (ParseException e) {
                    e.printStackTrace();
                }
            }
        }
        
        return result;
    }
 
    private boolean isDateFormat(String formater) {
        return true;
    }
 
    public void putMap(Map<String, Object> contextMap) {
        this.contextMap.putAll(contextMap);
    }
 
    public Map<String, Object> getContextMap() {
        return this.contextMap;
    }
 
    public void setDataMap(Map<String, Object> dataMap) {
        this.dataMap = dataMap;
    }
    
}