public void prepare(File pathToDocx, String templateKey) throws IOException { File dir = getTemplateUnzipFolder(templateKey); if (pathToDocx.exists() && pathToDocx.isFile()) { AntBuilder antBuilder = new AntBuilder(); HashMap<String, Object> params = new HashMap<String, Object>(); params.put("src", pathToDocx); params.put("dest", dir); params.put("overwrite", "true"); antBuilder.invokeMethod("unzip", params); } else { throw new FileNotFoundException(String.format("Cannot find docx template: '%s'", pathToDocx.getAbsolutePath())); } }
import groovy.util.AntBuilder ; import java.io.File ; import java.util.HashMap ; public class Test { public static void main( String[] args ) throws Exception { if( args.length != 2 ) { System.err.println( "Need 2 args. Input zip file and output folder" ) ; System.exit( 1 ) ; } final File file = new File( args[ 0 ] ) ; final File outputFolder = new File( args[ 1 ] ) ; AntBuilder ant = new AntBuilder() ; ant.invokeMethod( "unzip", new HashMap() {{ put( "src", file.getPath() ) ; put( "dest", outputFolder.getPath() ) ; }} ) ; } }
final AntBuilder ant = new AntBuilder(); ant.invokeMethod("echo", "copy & sync gestartet..."); ant.invokeMethod("sync", new Object[] { new HashMap<String, String>() { { this.put("todir", "./myordner2"); this.put("verbose", "yes"); } }, new Closure<Object>(null) { @Override public Object call(Object... args) { ant.invokeMethod("fileset", new Object[] { new HashMap<String, String>() { { this.put("dir", "c:/myordner1/test"); } }}); return null; } } });
return super.invokeMethod(name, arguments);
return super.invokeMethod(name, arguments);
return super.invokeMethod(name, arguments);
protected void processResult(File destDocx, String templateKey, TemplateContent content) throws IOException { File tmpProcessFolder = TemplateFileManager.getInstance().createTmpProcessFolder(); destDocx.delete(); FileUtils.deleteDirectory(tmpProcessFolder); FileUtils .copyDirectory(TemplateFileManager.getInstance().getTemplateUnzipFolder(templateKey), tmpProcessFolder); for (ContentItem item : content.getItems()) { FileUtils.writeStringToFile(new File(tmpProcessFolder, "word/" + item.getIdentifier()), item.getContent(), "UTF-8"); } AntBuilder antBuilder = new AntBuilder(); HashMap<String, Object> params1 = new HashMap<String, Object>(); params1.put("destfile", destDocx); params1.put("basedir", tmpProcessFolder); params1.put("includes", "**/*.*"); params1.put("excludes", ""); params1.put("encoding", "UTF-8"); antBuilder.invokeMethod("zip", params1); FileUtils.deleteDirectory(tmpProcessFolder); }