ben wrote:
> 
> I cannot make a document hook work. According to the doc such a hook can
> be a script, but I have the following configuration error "unknown
> extension: bsh" (if I use a script with .bsh suffix). I've tried other
> extensions without any success.

Have you installed the BeanShell plug-in?

If you did that, it should be listed by the dialog box displayed by
Help|Plug-ins.

Otherwise, download the plug-in from
http://www.xmlmind.com/xmleditor/plugins.shtml and install it.



> Besides, I wonder how to write such a script so that an action is
> performed when opening and antother action is done on closing. BTW what
> are the expected arguments of the script? Is the first parameter is
> expected to be the file to parse? Shall the script write the result to
> the standard output?

Find attached to this document, tdochook.bsh, a skeleton of such script. 

Register it by adding documenthook.xxe somewhere XXE find its
configurations, for example, on Unix, in ~/.xxe2/config/. A document
hook can also be document type specific, in which case, add it to the
configuration file of the corresponding document type.

Use the Java API
http://www.xmlmind.com/xmleditor/_distrib/docs/api/com/xmlmind/xmleditapp/dochook/DocumentHook.html
and the developer's guide 
http://www.xmlmind.com/xmleditor/_distrib/docs/dev/ar01s06.html
to learn how to write a document hook. (The developer's documentation
can be freely downloaded from
http://www.xmlmind.com/xmleditor/download.shtml.)

Our advice is to write everything in Java rather than in a script
language, that's why use of scripting in XXE is not promoted at all. For
example, BeanShell, while pretty smart, is very, very, very slow and is
harder to debug than Java.
-------------- next part --------------
import java.net.URL;
import com.xmlmind.xmledit.doc.Document;
import com.xmlmind.xmledit.doctype.Diagnostic;

void creatingDocument(Object self, boolean copy, URL url) {
    System.err.println("creatingDocument '" + url + 
                       (copy? "' (copy)" : "' (prune)"));
}

void documentCreated(Object self, Document doc) {
    System.err.println("documentCreated '" + doc.getEntityURL() + "'");
}

void openingDocument(Object self, URL url) {
    System.err.println("openingDocument '" + url + "'");
}

void documentOpened(Object self, Document doc) {
    System.err.println("documentOpened '" + doc.getEntityURL() + "'");
}

void checkingDocument(Object self, Document doc) {
    System.err.println("checkingDocument '" + doc.getEntityURL() + "'");
}

Diagnostic[] documentChecked(Object self, Document doc,
                             Diagnostic[] diagnostics) {
    System.err.println("documentChecked '" + doc.getEntityURL() + "'");
    return diagnostics;
}

void savingDocument(Object self, Document doc) {
    System.err.println("savingDocument '" + doc.getEntityURL() + "'");
}

void documentSaved(Object self, Document doc) {
    System.err.println("documentSaved '" + doc.getEntityURL() + "'");
}

void documentClosed(Object self, Document doc) {
    System.err.println("documentClosed '" + doc.getEntityURL() + "'");
}

-------------- next part --------------
<?xml version='1.0' encoding='UTF-8'?>
<cfg:configuration
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
  xmlns:cfg="http://www.xmlmind.com/xmleditor/schema/configuration";>

<cfg:documentHook>
  <cfg:script>tdochook.bsh</cfg:script>
</cfg:documentHook>

</cfg:configuration>

Reply via email to