com.clickntap.tool.doc.ScriptableSmartPdf Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of Stripecube Show documentation
Show all versions of Stripecube Show documentation
Stripecube is an open source Java framework for Web Applications
package com.clickntap.tool.doc;
import com.clickntap.tool.script.ScriptEngine;
import com.clickntap.utils.ConstUtils;
import org.apache.commons.io.FileUtils;
import java.io.File;
import java.io.FileOutputStream;
import java.util.HashMap;
import java.util.Map;
public class ScriptableSmartPdf extends SmartPdf {
private ScriptEngine engine;
private String outName;
public ScriptableSmartPdf() throws Exception {
// this.engine = new WebmacroScriptEngine();
// ((WebmacroScriptEngine) engine).start();
this.outName = "out.pdf";
}
public void setEngine(ScriptEngine engine) {
this.engine = engine;
}
public void exec(File template) throws Exception {
Map ctx = new HashMap();
ctx.put(ConstUtils.THIS, this);
engine.evalScript(ctx, FileUtils.readFileToString(template));
FileOutputStream out = new FileOutputStream(template.getParentFile().getCanonicalPath() + ConstUtils.SLASH + getOutName());
copyTo(out);
out.close();
}
public String getOutName() {
return outName;
}
public void setOutName(String outName) {
this.outName = outName;
}
}