1.18. Element invoke

<invoke
  method = Qualified name of a Java static method
  arguments = string : ""
/>

Invokes specified Javastatic method, passing it specified string as an argument.

Examples:

<invoke method="TestInvoke.echo" 
        arguments="args={%*} doc='%D' pwd='%W' conf='%C'" />

<invoke method="TestInvoke.echo2" />

<invoke method="TestInvoke.gzip" arguments="__doc.xml" />

Static methods invoked by the above examples:

public final class TestInvoke {
    public static void echo(String arguments, File workingDir,
                            Console console) {
        console.showMessage("arguments='" + arguments + "'", Console.INFO);
        console.showMessage("workingDir='" + workingDir + "'", Console.INFO);
    }

    public static void echo2(String arguments, File workingDir,
                             Console console, Document docBeingEdited) {
        echo(arguments, workingDir, console);
        console.showMessage("docBeingEdited='" + docBeingEdited.getLocation() 
                            + "'", Console.INFO);
    }

    public static File gzip(String arguments, File workingDir) 
        throws IOException {
        File inFile = new File(workingDir, arguments.trim());
        if (!inFile.isFile())
            throw new FileNotFoundException(inFile.getPath());
        File outFile = new File(inFile.getPath() + ".gz");
        FileInputStream in = new FileInputStream(inFile);

        try {
            GZIPOutputStream out = 
                new GZIPOutputStream(new FileOutputStream(outFile));

            byte[] bytes = new byte[8192];
            int count;

            while ((count = in.read(bytes)) != -1) 
                out.write(bytes, 0, count);

            out.finish();
            out.close();
        } finally {
            in.close();
        }

        return outFile;
    }
}