Database Reference
In-Depth Information
Note that when you encapsulate an element in another, the order of the gener‐
ated events is reversed in the endElement method as compared to the startEle
ment method. In other words, the isbn element has to be ended before the
reference element, as the isbn element was started after the reference element.
Document triggers are incredibly powerful, and here we have barely scratched the
surface of what is possible. However, to further assist you we have included a more
complete example with this topic.
Example filtering trigger
An example class extending FilteringTrigger called exist.book.example.trig
ger.document.ExampleFilteringTrigger is supplied in the folder chapters/
advanced-topics/java-database-trigger/filtering-trigger-example of the book-code Git
repository (see “Getting the Source Code” on page 15 ).
The example is designed to show how you can build a path to the current element
even though you are processing a stream, and you can then use this path to make
decisions about whether to remove an element. The example also shows how to pass
in a significantly more complicated set of configuration parameters to the trigger
from the collection configuration document. These parameters are then used for
keeping a map of elements that should be renamed.
To compile the example, enter the java-database-trigger folder and run mvn package .
To deploy the ExampleFilteringTrigger to eXist, you need to:
1. Compile the code as described previously, and then copy all of the files from
java-database-trigger/filtering-trigger-example/target/filtering-trigger-
example-1.0-assembly to $EXIST_HOME/lib/user .
2. Restart eXist so that it picks up the new JAR files.
3. Create the collection /db/test-data .
4. Create the configuration collection /db/system/config/db/test-data .
5. Configure the trigger in a collection configuration document in the database,
which you should locate at /db/system/config/db/test-data/collection.xconf :
<collection xmlns= "http://exist-db.org/collection-config/1.0" >
<triggers>
<trigger
class= "exist.book.example.trigger.document.ExampleFilteringTrigger" >
<!-- paths to elements that should be dropped -->
<parameter name= "drop" value= "/a/b/c" />
<!-- map of elements that should be renamed -->
Search WWH ::




Custom Search