org.exist.collections.triggers
Class XQueryTrigger

java.lang.Object
  extended by org.exist.collections.triggers.FilteringTrigger
      extended by org.exist.collections.triggers.XQueryTrigger
All Implemented Interfaces:
DocumentTrigger, Trigger, ContentHandler, LexicalHandler

public class XQueryTrigger
extends FilteringTrigger

A trigger that executes a user XQuery statement when invoked. The XQuery source executed is the value of the parameter named "query" or the query at the URL indicated by the parameter named "url". Any additional parameters will be declared as external variables with the type xs:string These external variables for the Trigger are accessible to the user XQuery statement xxx:eventType : the type of event for the Trigger. Either "prepare" or "finish" xxx:collectionName : the name of the collection from which the event is triggered xxx:documentName : the name of the document from which the event is triggered xxx:triggerEvent : the kind of triggered event xxx:document : the document from which the event is triggered xxx is the namespace prefix within the XQuery, can be set by the variable "bindingPrefix"

Author:
Pierrick Brihaye , Adam Retter

Field Summary
static String PEPARE_EXCEIPTION_MESSAGE
           
 
Fields inherited from interface org.exist.collections.triggers.Trigger
CREATE_COLLECTION_EVENT, DELETE_COLLECTION_EVENT, REMOVE_DOCUMENT_EVENT, RENAME_COLLECTION_EVENT, STORE_DOCUMENT_EVENT, UPDATE_DOCUMENT_EVENT
 
Constructor Summary
XQueryTrigger()
           
 
Method Summary
 void configure(DBBroker broker, Collection parent, Map parameters)
          Configure the trigger.
 void endDocument()
           
static String eventToString(int event)
          Returns a String representation of the Trigger event
 void finish(int event, DBBroker broker, Txn transaction, XmldbURI documentPath, DocumentImpl document)
          This method is called after the operation completed.
 void prepare(int event, DBBroker broker, Txn transaction, XmldbURI documentPath, DocumentImpl existingDocument)
          This method is called once before the database will actually parse the input data.
 void startDocument()
           
 
Methods inherited from class org.exist.collections.triggers.FilteringTrigger
characters, comment, endCDATA, endDTD, endElement, endEntity, endPrefixMapping, getCollection, getInputHandler, getLexicalInputHandler, getLexicalOutputHandler, getLogger, getOutputHandler, ignorableWhitespace, isValidating, processingInstruction, setDocumentLocator, setLexicalOutputHandler, setOutputHandler, setValidating, skippedEntity, startCDATA, startDTD, startElement, startEntity, startPrefixMapping
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PEPARE_EXCEIPTION_MESSAGE

public static final String PEPARE_EXCEIPTION_MESSAGE
See Also:
Constant Field Values
Constructor Detail

XQueryTrigger

public XQueryTrigger()
Method Detail

configure

public void configure(DBBroker broker,
                      Collection parent,
                      Map parameters)
               throws CollectionConfigurationException
Description copied from class: FilteringTrigger
Configure the trigger. The default implementation just stores the parent collection reference into the field collection. Use method getCollection to later retrieve the collection.

Specified by:
configure in interface Trigger
Overrides:
configure in class FilteringTrigger
Parameters:
broker - the database instance used to load the collection configuration. The broker object is required for all database actions. Please note: the broker instance used for configuration is probably different from the one passed to the prepare method. Don't store the broker object in your class.
parent - the collection to which this trigger belongs.
parameters - a Map containing any key/value parameters defined in the configuration file.
Throws:
CollectionConfigurationException - if the trigger cannot be initialized.

prepare

public void prepare(int event,
                    DBBroker broker,
                    Txn transaction,
                    XmldbURI documentPath,
                    DocumentImpl existingDocument)
             throws TriggerException
Description copied from interface: DocumentTrigger
This method is called once before the database will actually parse the input data. You may take any action here, using the supplied broker instance.

Parameters:
event - the type of event that triggered this call (see the constants defined in this interface). The ContentHandler instance for the output.
broker - the database instance used to process the current action.
transaction - the current transaction context
documentPath - the full absolute path of the document currently processed.
existingDocument - optional: if event is a Trigger.UPDATE_DOCUMENT_EVENT, existingDocument will contain the Document object for the old document, which will be overwritten. Otherwise, the parameter is null.
Throws:
TriggerException - throwing a TriggerException will abort the current action.

finish

public void finish(int event,
                   DBBroker broker,
                   Txn transaction,
                   XmldbURI documentPath,
                   DocumentImpl document)
Description copied from interface: DocumentTrigger
This method is called after the operation completed. At this point, the document has already been stored.

Parameters:
event - the type of event that triggered this call (see the constants defined in this interface).
broker - the database instance used to process the current action.
transaction - the current transaction context
documentPath - the path of the document, if removed the old path of the document
document - the stored document or null if the document is removed

startDocument

public void startDocument()
                   throws SAXException
Specified by:
startDocument in interface ContentHandler
Overrides:
startDocument in class FilteringTrigger
Throws:
SAXException

endDocument

public void endDocument()
                 throws SAXException
Specified by:
endDocument in interface ContentHandler
Overrides:
endDocument in class FilteringTrigger
Throws:
SAXException

eventToString

public static String eventToString(int event)
Returns a String representation of the Trigger event

Parameters:
event - The Trigger event
Returns:
The String representation


Copyright (C) Wolfgang Meier. All rights reserved.