1
|
package eu.dnetlib.xml.database.exist;
|
2
|
|
3
|
import javax.xml.xpath.XPathExpression;
|
4
|
import javax.xml.xpath.XPathExpressionException;
|
5
|
import javax.xml.xpath.XPathFactory;
|
6
|
|
7
|
import org.apache.commons.logging.Log;
|
8
|
import org.apache.commons.logging.LogFactory;
|
9
|
import org.exist.collections.triggers.SAXTrigger;
|
10
|
import org.exist.collections.triggers.TriggerException;
|
11
|
import org.exist.dom.persistent.DocumentImpl;
|
12
|
import org.exist.storage.DBBroker;
|
13
|
import org.exist.storage.txn.Txn;
|
14
|
import org.exist.xmldb.XmldbURI;
|
15
|
|
16
|
/**
|
17
|
* simple test trigger.
|
18
|
*
|
19
|
* @author marko
|
20
|
*
|
21
|
*/
|
22
|
public class TestExistTrigger extends SAXTrigger {
|
23
|
/**
|
24
|
* logger.
|
25
|
*/
|
26
|
private static final Log log = LogFactory.getLog(TestExistTrigger.class); // NOPMD by marko on 11/24/08 5:02 PM
|
27
|
/**
|
28
|
* expression.
|
29
|
*/
|
30
|
private transient XPathExpression expr;
|
31
|
|
32
|
/**
|
33
|
* useless.
|
34
|
*/
|
35
|
public TestExistTrigger() {
|
36
|
super();
|
37
|
|
38
|
try {
|
39
|
expr = XPathFactory.newInstance().newXPath().compile("//hello");
|
40
|
} catch (XPathExpressionException e) {
|
41
|
log.fatal("cannot parse xpath", e);
|
42
|
}
|
43
|
}
|
44
|
|
45
|
@Override
|
46
|
public void beforeCreateDocument(final DBBroker dbBroker, final Txn txn, final XmldbURI xmldbURI) throws TriggerException {
|
47
|
|
48
|
}
|
49
|
|
50
|
@Override
|
51
|
public void afterCreateDocument(final DBBroker dbBroker, final Txn txn, final DocumentImpl document) throws TriggerException {
|
52
|
try {
|
53
|
log.debug("created new document: " + expr.evaluate(document));
|
54
|
} catch (XPathExpressionException e) {
|
55
|
log.fatal("xpatthing", e);
|
56
|
}
|
57
|
}
|
58
|
|
59
|
@Override
|
60
|
public void beforeUpdateDocument(final DBBroker dbBroker, final Txn txn, final DocumentImpl document) throws TriggerException {
|
61
|
try {
|
62
|
log.info("old value: " + expr.evaluate(document));
|
63
|
|
64
|
} catch (XPathExpressionException e) {
|
65
|
log.fatal("xpatthing", e);
|
66
|
}
|
67
|
}
|
68
|
|
69
|
@Override
|
70
|
public void afterUpdateDocument(final DBBroker dbBroker, final Txn txn, final DocumentImpl document) throws TriggerException {
|
71
|
|
72
|
try {
|
73
|
log.info("new value: " + expr.evaluate(document));
|
74
|
} catch (XPathExpressionException e) {
|
75
|
log.fatal("xpatthing", e);
|
76
|
}
|
77
|
|
78
|
}
|
79
|
|
80
|
@Override
|
81
|
public void beforeUpdateDocumentMetadata(final DBBroker dbBroker, final Txn txn, final DocumentImpl document) throws TriggerException {
|
82
|
|
83
|
}
|
84
|
|
85
|
@Override
|
86
|
public void afterUpdateDocumentMetadata(final DBBroker dbBroker, final Txn txn, final DocumentImpl document) throws TriggerException {
|
87
|
|
88
|
}
|
89
|
|
90
|
@Override
|
91
|
public void beforeCopyDocument(final DBBroker dbBroker, final Txn txn, final DocumentImpl document, final XmldbURI xmldbURI) throws TriggerException {
|
92
|
|
93
|
}
|
94
|
|
95
|
@Override
|
96
|
public void afterCopyDocument(final DBBroker dbBroker, final Txn txn, final DocumentImpl document, final XmldbURI xmldbURI) throws TriggerException {
|
97
|
|
98
|
}
|
99
|
|
100
|
@Override
|
101
|
public void beforeMoveDocument(final DBBroker dbBroker, final Txn txn, final DocumentImpl document, final XmldbURI xmldbURI) throws TriggerException {
|
102
|
|
103
|
}
|
104
|
|
105
|
@Override
|
106
|
public void afterMoveDocument(final DBBroker dbBroker, final Txn txn, final DocumentImpl document, final XmldbURI xmldbURI) throws TriggerException {
|
107
|
|
108
|
}
|
109
|
|
110
|
@Override
|
111
|
public void beforeDeleteDocument(final DBBroker dbBroker, final Txn txn, final DocumentImpl document) throws TriggerException {
|
112
|
try {
|
113
|
log.debug("deleted document: " + expr.evaluate(document));
|
114
|
} catch (XPathExpressionException e) {
|
115
|
log.fatal("xpatthing", e);
|
116
|
}
|
117
|
}
|
118
|
|
119
|
@Override
|
120
|
public void afterDeleteDocument(final DBBroker dbBroker, final Txn txn, final XmldbURI xmldbURI) throws TriggerException {
|
121
|
|
122
|
}
|
123
|
}
|