Home
Categories
Dictionary
Download
Project Details
Changes Log
FAQ
License

Scripting



The Tools menu has an Apply Script option allowing to execute a Groovy[1]
See groovy-lang.org for more information about the Groovy language
Script.

Script structure

The script has the following structure:

class Script
The Script

Modifier and Type Method and Description
void apply()
Execute the script. It is the only mandatory method
boolean showConsole()
Return false if the script console should be presented in the Editor message area. By default the messages are presented in a specific Script console

The apply() method is the only mandatory method. For example, the following script just echo a message:
      public void apply() {
        context.echo("Hello World!");
      }
Alternatively, if the script has no specified method, the apply() method declaration can be omitted. For example, the following code has the same result:
      context.echo("Hello World!");

Script context

The script has always by default access to a context object which has the following API:

class context
The Script context

Modifier and Type Method and Description
void abort(String message)
abort the script
void echo(String message)
print a message in the Script console
void echo(String message, String color)
print a message in the Script console, with a specific html color
void error(String message)
print an error message in the Script console
File getFile()
return the Script file
File getPath(String path)
return the File corresponding to a path relative to the script file

Example

      public void apply() {
        context.abort("Abort the script");
      }

Script helper

The script has always by default access to a helper object which has the following API:

class helper
The Script helper

Modifier and Type Method and Description
boolean checkXML(XMLContainer cont)
Check the well-formedness of an XML file
XMLFormatContainer getContainer(File file)
Return the container associated with a file
XMLFormatContainer getContainer(URL url)
Return the container associated with an URL
File openDirectoryDialog(String title, String extensions)
Open a directory dialog and return the directory
File openFileDialog(String title, String extensions)
Open an Open File dialog and return the file
XMLFormatContainer openXMLFile(File file)
Open an XML file in the editor
File saveFileDialog(String title, String extensions)
Open a Save File dialog and return the file
boolean transform(XMLContainer cont, File xsl, File outputFile)
Transform an XML file using an XSL file
boolean validate(XMLContainer cont)
Validate an XML file
boolean validateAgainstSchema(XMLContainer cont, File schema)
Validate an XML file against a Schema

Note that XMLContainers can be any type of XML file: XML, DTD, XSD, XSL.

Containers

  • The XMLContainer represents any XML file
  • The XSDContainer represents a Schema
  • The XSLContainer represents an XSL file
  • The DTDContainer represents a DTD

containers

Notes

  1. ^ See groovy-lang.org for more information about the Groovy language

Categories: general

Copyright 2006-2016 Hervé. All Rights Reserved. Documentation and source under the LGPL v2 and Apache 2.0 licences