public abstract class Script extends java.lang.Object implements OptionHandler, java.io.Serializable
| Modifier and Type | Class and Description |
|---|---|
static class |
Script.ScriptThread
The Thread for running a script.
|
| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
BACKUP_EXTENSION
the backup extension.
|
protected javax.swing.text.Document |
m_Document
the document this script is a wrapper around.
|
protected java.io.File |
m_Filename
the filename of the script.
|
protected java.util.HashSet<ScriptExecutionListener> |
m_FinishedListeners
optional listeners when the script finishes.
|
protected boolean |
m_Modified
whether the script is modified.
|
protected java.lang.String |
m_NewLine
the newline used on this platform.
|
protected Script.ScriptThread |
m_ScriptThread
the current script thread.
|
| Constructor and Description |
|---|
Script()
Initializes the script.
|
Script(javax.swing.text.Document doc)
Initializes the script.
|
Script(javax.swing.text.Document doc,
java.io.File file)
Initializes the script.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addScriptFinishedListener(ScriptExecutionListener l)
Adds the given listener to its internal list.
|
protected abstract boolean |
canExecuteScripts()
Returns whether scripts can be executed.
|
protected boolean |
checkExtension(java.io.File file)
Checks whether the extension of the file is a known one.
|
void |
empty()
Empties the document.
|
protected void |
execute(java.lang.String[] args)
Executes the script.
|
java.lang.String |
getContent()
Returns the content.
|
abstract java.lang.String |
getDefaultExtension()
Returns the default extension.
|
java.io.File |
getFilename()
Returns the current filename.
|
abstract ExtensionFileFilter[] |
getFilters()
Returns the extension filters for this type of script.
|
java.lang.String |
getNewLine()
Returns the new line string in use.
|
java.lang.String[] |
getOptions()
Gets the current settings of the script.
|
protected void |
initialize()
Initializes the script.
|
boolean |
isModified()
Returns whether the script is modified.
|
boolean |
isRunning()
Returns whether the script is still running.
|
java.util.Enumeration<Option> |
listOptions()
Returns an enumeration describing the available options.
|
protected static java.lang.String |
makeOptionString(Script script)
Make up the help string giving all the command line options.
|
abstract Script.ScriptThread |
newThread(java.lang.String[] args)
Returns a new thread to execute.
|
protected void |
notifyScriptFinishedListeners(ScriptExecutionEvent e)
Notifies all listeners.
|
boolean |
open(java.io.File file)
Tries to open the file.
|
protected void |
preCheck(java.lang.String[] args)
Performs pre-execution checks:
whether a script is currently running.
|
void |
removeScriptFinishedListener(ScriptExecutionListener l)
Removes the given listener from its internal list.
|
void |
run(java.io.File file,
java.lang.String[] args)
Executes the script without loading it first.
|
static void |
runScript(Script script,
java.lang.String[] args)
Runs the specified script.
|
boolean |
save()
Saves the file under with the current filename.
|
boolean |
saveAs(java.io.File file)
Saves the file under with the given filename (and updates the internal
filename).
|
void |
setContent(java.lang.String value)
Sets the content.
|
void |
setOptions(java.lang.String[] options)
Parses a given list of options.
|
void |
start(java.lang.String[] args)
Executes the script.
|
void |
stop()
Stops the execution of the script.
|
java.lang.String |
toString()
Returns the content as string.
|
public static final java.lang.String BACKUP_EXTENSION
protected javax.swing.text.Document m_Document
protected java.io.File m_Filename
protected java.lang.String m_NewLine
protected boolean m_Modified
protected transient Script.ScriptThread m_ScriptThread
protected java.util.HashSet<ScriptExecutionListener> m_FinishedListeners
public Script()
public Script(javax.swing.text.Document doc)
doc - the document to use as basispublic Script(javax.swing.text.Document doc,
java.io.File file)
doc - the document to use as basisfile - the file to load (if not null)protected void initialize()
public java.util.Enumeration<Option> listOptions()
listOptions in interface OptionHandlerpublic void setOptions(java.lang.String[] options)
throws java.lang.Exception
setOptions in interface OptionHandleroptions - the list of options as an array of stringsjava.lang.Exception - if an option is not supportedpublic java.lang.String[] getOptions()
getOptions in interface OptionHandlerpublic abstract ExtensionFileFilter[] getFilters()
public abstract java.lang.String getDefaultExtension()
saveAs(File)public java.io.File getFilename()
public java.lang.String getNewLine()
public boolean isModified()
public java.lang.String getContent()
public void setContent(java.lang.String value)
value - the new contentprotected boolean checkExtension(java.io.File file)
file - the file to checkpublic void empty()
public boolean open(java.io.File file)
file - the file to openpublic boolean save()
public boolean saveAs(java.io.File file)
file - the filename to write the content toprotected abstract boolean canExecuteScripts()
public abstract Script.ScriptThread newThread(java.lang.String[] args)
args - optional commandline argumentsprotected void preCheck(java.lang.String[] args)
throws java.lang.Exception
args - optional commandline argumentsjava.lang.Exception - if checks failprotected void execute(java.lang.String[] args)
args - optional commandline argumentspublic void start(java.lang.String[] args)
throws java.lang.Exception
args - optional commandline arguments, can be nulljava.lang.Exception - if checks or execution failpublic void stop()
public void run(java.io.File file,
java.lang.String[] args)
file - the script to executeargs - the commandline parameters for the scriptpublic boolean isRunning()
public void addScriptFinishedListener(ScriptExecutionListener l)
l - the listener to addpublic void removeScriptFinishedListener(ScriptExecutionListener l)
l - the listener to removeprotected void notifyScriptFinishedListeners(ScriptExecutionEvent e)
e - the event to send to all listenerspublic java.lang.String toString()
toString in class java.lang.Objectprotected static java.lang.String makeOptionString(Script script)
script - the script to include options forpublic static void runScript(Script script, java.lang.String[] args) throws java.lang.Exception
script - the script object to useargs - the commandline argumentsjava.lang.Exception - if execution fails