本文整理了Java中javax.jcr.observation.Event
类的一些代码示例,展示了Event
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Event
类的具体详情如下:
包路径:javax.jcr.observation.Event
类名称:Event
[英]An event fired by the observation mechanism.
[中]由观察机制触发的事件。
代码示例来源:origin: joerghoh/cq5-healthcheck
/**
* Do the event handling, calculate delay and drop the node afterwards.
*/
@Override
public void onEvent(EventIterator events) {
try {
while (events.hasNext()) {
Event e = events.nextEvent();
if (e.getPath().startsWith(tempDir)) {
Node foundNode = listenSession.getNode(e.getPath());
long now = System.currentTimeMillis();
long timestamp = foundNode.getProperty("timestamp")
.getLong();
lastDelay = now - timestamp;
log.debug("Current observation delay: {} ms", lastDelay);
removeNode(foundNode.getPath());
}
}
} catch (RepositoryException e) {
log.error("Cannot handle event", e);
}
}
代码示例来源:origin: org.apache.jackrabbit/jackrabbit-core
public void onEvent(EventIterator events) {
// NOTE: simplified event handling as all listeners just clear
// the cache in case of any move event. therefore there is currently
// no need to process all events and using the rootID as marker.
while (events.hasNext()) {
Event event = events.nextEvent();
if (event.getType() == Event.NODE_MOVED) {
Map<NodeId, Integer> m = Collections.singletonMap(rootID, AccessControlObserver.MOVE);
AccessControlModifications<NodeId> mods = new AccessControlModifications<NodeId>(m);
notifyListeners(mods);
break;
} //else: illegal event-type: should never occur. ignore
}
}
}
代码示例来源:origin: apache/jackrabbit
public void testPropertyChanged() throws RepositoryException {
Node n = testRootNode.addNode(nodeName1, testNodeType);
final Property prop = n.setProperty(propertyName1, "test");
testRootNode.getSession().save();
Event[] events = getEvents(new Callable(){
public void call() throws RepositoryException {
prop.setValue("modified");
testRootNode.getSession().save();
}
}, Event.PROPERTY_CHANGED);
assertEquals(n.getIdentifier(), getEventByPath(events, prop.getPath()).getIdentifier());
}
代码示例来源:origin: org.apache.sling/org.apache.sling.distribution.core
String getNodePathFromEvent(Event event) throws RepositoryException {
String eventPath = event.getPath();
int type = event.getType();
if (eventPath == null) {
return null;
}
if (Event.PROPERTY_REMOVED == type || Event.PROPERTY_CHANGED == type || Event.PROPERTY_ADDED == type) {
eventPath = eventPath.substring(0, eventPath.lastIndexOf('/'));
}
return eventPath;
}
代码示例来源:origin: stackoverflow.com
public ArrayList<String> getEventTitle(CivilDate date) {
ArrayList<String> events = new ArrayList<String>();
for (Event event : events) {
if (event.getDate().equals(date)) {
// trim XML whitespaces and newlines
events.add(event.getTitle().replaceAll("\n", "").trim());
}
}
return events ;
代码示例来源:origin: ModeShape/modeshape
/**
* @see PropertyChangedTest#testSinglePropertyChangedWithAdded()
* @throws Exception
*/
@Test
public void shouldTestPropertyChangedTests_testSinglePropertyChangedWithAdded() throws Exception {
// setup
Node node = getRoot().addNode("node1", UNSTRUCTURED);
Property prop1 = node.setProperty("prop1", "prop1 content");
save();
// register listener
SimpleListener listener = addListener(1, Event.PROPERTY_CHANGED, null, false, null, null, false);
// change the property
prop1.setValue("prop1 modified content");
node.setProperty("prop2", "prop2 content"); // property added event should not be received
save();
// event handling
listener.waitForEvents();
removeListener(listener);
// tests
checkResults(listener);
assertTrue("Path for changed property is wrong: actual=" + listener.getEvents().get(0).getPath() + ", expected="
+ prop1.getPath(),
containsPath(listener, prop1.getPath()));
}
代码示例来源:origin: apache/jackrabbit
public void testNodeMoved() throws RepositoryException {
final Node n = testRootNode.addNode(nodeName1, testNodeType);
testRootNode.getSession().save();
Event[] events = getEvents(new Callable(){
public void call() throws RepositoryException {
superuser.getWorkspace().move(n.getPath(), testRoot + "/" + nodeName2);
}
}, Event.NODE_MOVED);
String path = testRootNode.getNode(nodeName2).getPath();
assertEquals(n.getIdentifier(), getEventByPath(events, path).getIdentifier());
}
代码示例来源:origin: org.apache.sling/org.apache.sling.distribution.core
if (!session.nodeExists(nuggetsPath)) {
initializeNuggetsPath(session);
if (session.hasPermission(nuggetsPath, Session.ACTION_ADD_NODE)) {
log.debug("persisting event under {}", nuggetsPath);
Node nuggetsNode = session.getNode(nuggetsPath);
if (nuggetsNode != null) {
String nodeName = String.valueOf(System.nanoTime());
Node createdNode = nuggetsNode.addNode(nodeName, "nt:unstructured");
if (createdNode != null) {
String path = createdNode.getPath();
createdNode.setProperty("identifier", event.getIdentifier());
createdNode.setProperty("path", event.getPath());
createdNode.setProperty("date", event.getDate());
createdNode.setProperty("type", event.getType());
createdNode.setProperty("userData", event.getUserData());
createdNode.setProperty("userID", event.getUserID());
Set<Map.Entry> set = event.getInfo().entrySet();
Collection<String> values = new ArrayList<String>();
for (@SuppressWarnings("rawtypes") Map.Entry entry : set) {
代码示例来源:origin: ModeShape/modeshape
session2.getWorkspace().getObservationManager().setUserData(userData);
Node addedNode = session2.getRootNode().addNode("node1", UNSTRUCTURED);
session2.save();
assertTrue("Path for added node is wrong: actual=" + listener.getEvents().get(0).getPath() + ", expected="
+ addedNode.getPath(),
containsPath(listener, addedNode.getPath()));
String eventUserData = event.getUserData();
assertThat(eventUserData, is(userData));
代码示例来源:origin: apache/jackrabbit
public void testPropertyChanged() throws RepositoryException {
Node n = testRootNode.addNode(nodeName1, testNodeType);
final Property prop = n.setProperty(propertyName1, "test");
testRootNode.getSession().save();
Event[] events = getEvents(new Callable(){
public void call() throws RepositoryException {
prop.setValue("modified");
prop.getSession().save();
}
}, Event.PROPERTY_CHANGED);
for (int i = 0; i < events.length; i++) {
Set<?> unexpectedKeys = getUnexpectedKeys(events[i].getInfo());
assertEquals("info map must be empty: " + unexpectedKeys, 0, unexpectedKeys.size());
}
}
代码示例来源:origin: apache/jackrabbit
/**
* Tests if {@link javax.jcr.observation.Event#PROPERTY_ADDED} is triggered
* for system generated property jcr:primaryType.
*/
public void testSystemGenerated() throws RepositoryException {
EventResult result = new EventResult(log);
addEventListener(result, Event.PROPERTY_ADDED);
testRootNode.addNode(nodeName1, testNodeType);
testRootNode.getSession().save();
Event[] events = result.getEvents(DEFAULT_WAIT_TIMEOUT);
removeEventListener(result);
List<String> paths = new ArrayList<String>();
for (int i = 0; i < events.length; i++) {
paths.add(events[i].getPath());
}
String jcrPrimaryTypePath = testRoot + "/" + nodeName1 + "/" + jcrPrimaryType;
assertTrue("No event generated for jcr:primaryType.", paths.contains(jcrPrimaryTypePath));
}
代码示例来源:origin: ModeShape/modeshape
@FixFor( "MODE-1370" )
@Test
public void shouldReceiveUserDataWithEventWhenObservationSessionIsSameThatMadeChange() throws Exception {
// register listener
SimpleListener listener = addListener(1, Event.NODE_ADDED, null, false, null, null, false);
// add node
Node addedNode = getRoot().addNode("node1", UNSTRUCTURED);
// Add user-data to the observation manager ...
String userData = "my user data";
getRoot().getSession().getWorkspace().getObservationManager().setUserData(userData);
save();
// event handling
listener.waitForEvents();
removeListener(listener);
// tests
checkResults(listener);
assertTrue("Path for added node is wrong: actual=" + listener.getEvents().get(0).getPath() + ", expected="
+ addedNode.getPath(),
containsPath(listener, addedNode.getPath()));
// Now check the userdata in the events ...
for (Event event : listener.events) {
String eventUserData = event.getUserData();
assertThat(eventUserData, is(userData));
}
// Now check the userdata ...
assertThat(listener.userData.size(), is(not(0)));
for (String receivedUserData : listener.userData) {
assertThat(receivedUserData, is(userData));
}
}
代码示例来源:origin: ModeShape/modeshape
@FixFor( " MODE-1315 " )
@Test
public void shouldReceiveEventWhenPropertyDeletedOnCustomNode() throws Exception {
session.getWorkspace()
.getNodeTypeManager()
.registerNodeTypes(getClass().getClassLoader().getResourceAsStream("cars.cnd"), true);
Node car = getRoot().addNode("car", "car:Car");
car.setProperty("car:maker", "Audi");
session.save();
SimpleListener listener = addListener(1, Event.PROPERTY_REMOVED, null, true, null, new String[] {"car:Car"}, false);
Property carMakerProperty = car.getProperty("car:maker");
String propertyPath = carMakerProperty.getPath();
carMakerProperty.remove();
session.save();
listener.waitForEvents();
checkResults(listener);
Event receivedEvent = listener.getEvents().get(0);
assertEquals(Event.PROPERTY_REMOVED, receivedEvent.getType());
assertEquals(propertyPath, receivedEvent.getPath());
}
代码示例来源:origin: apache/jackrabbit
public void testPropertyAdded() throws RepositoryException {
Event[] events = getEvents(new Callable(){
public void call() throws RepositoryException {
testRootNode.addNode(nodeName1, testNodeType).setProperty(propertyName1, "test");
testRootNode.getSession().save();
}
}, Event.PROPERTY_ADDED);
Node n = testRootNode.getNode(nodeName1);
Property prop = n.getProperty(propertyName1);
assertEquals(n.getIdentifier(), getEventByPath(events, prop.getPath()).getIdentifier());
}
代码示例来源:origin: apache/jackrabbit
/**
* Tests if {@link javax.jcr.observation.Event#getUserID()} returns the same
* value as {@link javax.jcr.Session#getUserID()}.
*/
public void testGetUserId() throws RepositoryException{
EventResult result = new EventResult(log);
addEventListener(result, Event.NODE_ADDED);
testRootNode.addNode(nodeName1, testNodeType);
testRootNode.getSession().save();
Event[] events = result.getEvents(DEFAULT_WAIT_TIMEOUT);
removeEventListener(result);
assertEquals("Wrong number of events returned", 1, events.length);
String userId = events[0].getUserID();
String sessionUId = superuser.getUserID();
assertEquals("UserId of event is not equal to userId of session", userId, sessionUId);
}
代码示例来源:origin: apache/jackrabbit
public Event fromJCREvent(javax.jcr.observation.Event e)
throws RepositoryException {
Path p = e.getPath() != null ? resolver.getQPath(e.getPath()) : null;
Path parent = p != null ? p.getAncestor(1) : null;
int type = e.getType();
String identifier = e.getIdentifier();
ItemId itemId;
Node node = null;
if (identifier != null) {
itemId = idFactory.fromJcrIdentifier(e.getIdentifier());
try {
node = session.getItem(e.getPath()).getParent();
} catch (RepositoryException re) {
case Event.NODE_ADDED:
case Event.NODE_MOVED:
node = session.getItem(e.getPath()).getParent();
case Event.NODE_REMOVED:
itemId = idFactory.createNodeId((String) null, p);
case Event.PROPERTY_ADDED:
case Event.PROPERTY_CHANGED:
node = session.getItem(e.getPath()).getParent();
case Event.PROPERTY_REMOVED:
itemId = idFactory.createPropertyId(parentId, p.getName());
Map<String, Object> jcrInfo = e.getInfo();
for (Map.Entry<String, Object> entry : jcrInfo.entrySet()) {
String key = entry.getKey();
代码示例来源:origin: apache/jackrabbit
/**
* Tests if getType() returns the correct value.
*/
public void testGetType() throws RepositoryException{
EventResult result = new EventResult(log);
addEventListener(result, Event.NODE_ADDED);
testRootNode.addNode(nodeName1, testNodeType);
testRootNode.getSession().save();
Event[] events = result.getEvents(DEFAULT_WAIT_TIMEOUT);
removeEventListener(result);
assertEquals("Wrong number of events returned", 1, events.length);
int type = events[0].getType();
assertEquals("Event did not return correct event type", Event.NODE_ADDED, type);
}
}
代码示例来源:origin: apache/jackrabbit
public void testNodeAdded() throws RepositoryException {
Event[] events = getEvents(new Callable(){
public void call() throws RepositoryException {
testRootNode.addNode(nodeName1, testNodeType);
testRootNode.getSession().save();
}
}, Event.NODE_ADDED);
Node n = testRootNode.getNode(nodeName1);
assertEquals(n.getIdentifier(), getEventByPath(events, n.getPath()).getIdentifier());
}
代码示例来源:origin: info.magnolia/magnolia-module-observation
@Override
public void onEvent(EventIterator events) {
logger.info("EventListener Test: Text Message");
Event event;
while(events.hasNext()){
event = events.nextEvent();
// depends of the type of event
try {
systemContext.getJCRSession("website").getNode(event.getPath());
} catch (RepositoryException e) {
logger.error("Could not retrieve node.", e);
}
}
logger.info("EventListener Test: Text Message2");
}
代码示例来源:origin: apache/jackrabbit
public void testUserData() throws RepositoryException {
testRootNode.addNode(nodeName1);
String data = createRandomString(5);
obsMgr.setUserData(data);
journal = obsMgr.getEventJournal();
skipToNow();
superuser.save();
assertTrue("no more events", journal.hasNext());
assertEquals("Wrong user data", data, journal.nextEvent().getUserData());
}
内容来源于网络,如有侵权,请联系作者删除!