FunctionNameMappingImpl.java
2.13 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
56
57
58
59
60
61
62
63
64
65
66
67
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.forms.formcalc.support;
import com.adobe.forms.formcalc.api.FunctionNameMapping;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.util.HashMap;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class FunctionNameMappingImpl
implements FunctionNameMapping {
private static Logger logger = LoggerFactory.getLogger(FunctionNameMappingImpl.class);
private final Map<String, String> formcalcToJSFuncs = new HashMap<String, String>();
private final Map<String, String> formcalcToJSConst = new HashMap<String, String>();
public FunctionNameMappingImpl() {
this.init();
}
private void init() {
try {
this.loadPropertiesFile();
}
catch (IOException e) {
logger.debug("Error while loading properties file: ", (Throwable)e);
}
this.formcalcToJSConst.put("pi", "Math.PI");
}
private void loadPropertiesFile() throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(FunctionNameMappingImpl.class.getResourceAsStream("/com/adobe/forms/formcalc/support/functionsMapping.properties")));
String line = br.readLine();
while (line != null) {
int sep;
if (!line.startsWith("#") && (sep = line.indexOf(61)) >= 0) {
this.formcalcToJSFuncs.put(line.substring(0, sep).toLowerCase(), line.substring(sep + 1, line.length()));
}
line = br.readLine();
}
}
@Override
public String getJSFunctionIfAny(String formCalcFuntion) {
String jsFun = this.formcalcToJSFuncs.get(formCalcFuntion.toLowerCase());
if (jsFun != null) {
return jsFun;
}
return formCalcFuntion;
}
@Override
public String getFunctionToConst(String formCalcFuntion) {
return this.formcalcToJSConst.get(formCalcFuntion.toLowerCase());
}
}