FormcalTransformerImpl.java
1.88 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
/*
* Decompiled with CFR 0_118.
*/
package com.adobe.forms.formcalc;
import com.adobe.forms.formcalc.CalcTransParser;
import com.adobe.forms.formcalc.CalcTransParserVisitor;
import com.adobe.forms.formcalc.FormCalc2JSVisitor;
import com.adobe.forms.formcalc.Node;
import com.adobe.forms.formcalc.ParseException;
import com.adobe.forms.formcalc.SimpleNode;
import com.adobe.forms.formcalc.api.FormcalcTransformer;
import com.adobe.forms.formcalc.api.FunctionNameMapping;
import com.adobe.forms.formcalc.api.TransformContext;
import com.adobe.forms.formcalc.api.TransformException;
import com.adobe.forms.formcalc.support.FunctionNameMappingImpl;
import java.io.PrintWriter;
import java.io.Reader;
import java.io.StringReader;
import java.io.StringWriter;
import java.io.Writer;
public class FormcalTransformerImpl
implements FormcalcTransformer {
private static final String EMPTY_SCRIPT = "";
@Override
public String transform(String formCalc, TransformContext context) throws TransformException {
if (formCalc == null) {
return "";
}
CalcTransParser cp = new CalcTransParser(new StringReader(formCalc));
try {
cp.parse();
}
catch (ParseException e) {
throw new TransformException("Error on parsing FormCalculation expression", e);
}
SimpleNode rootNode = (SimpleNode)cp.rootNode();
if (rootNode == null) {
return "";
}
StringWriter swriter = new StringWriter();
PrintWriter output = new PrintWriter(swriter);
FormCalc2JSVisitor visitor = this.createVisitor(new FunctionNameMappingImpl(), output);
rootNode.jjtAccept(visitor, null);
return swriter.toString();
}
FormCalc2JSVisitor createVisitor(FunctionNameMapping fm, PrintWriter output) {
return new FormCalc2JSVisitor(new FunctionNameMappingImpl(), output);
}
}