Search in sources :

Example 1 with EventType

use of org.apache.jackrabbit.webdav.observation.EventType in project jackrabbit by apache.

the class SubscriptionImpl method getJcrEventTypes.

/**
     * @return JCR compliant integer representation of the event types defined
     * for this {@link SubscriptionInfo}.
     */
int getJcrEventTypes() throws DavException {
    EventType[] eventTypes = info.getEventTypes();
    int events = 0;
    for (EventType eventType : eventTypes) {
        events |= getJcrEventType(eventType);
    }
    return events;
}
Also used : DefaultEventType(org.apache.jackrabbit.webdav.observation.DefaultEventType) EventType(org.apache.jackrabbit.webdav.observation.EventType)

Example 2 with EventType

use of org.apache.jackrabbit.webdav.observation.EventType in project jackrabbit by apache.

the class RepositoryServiceImpl method buildEventList.

private List<Event> buildEventList(Element bundleElement, SessionInfoImpl sessionInfo, String baseUri) throws RepositoryException {
    List<Event> events = new ArrayList<Event>();
    ElementIterator eventElementIterator = DomUtil.getChildren(bundleElement, ObservationConstants.N_EVENT);
    String userId = null;
    // get user id from enclosing Atom entry element in case this was a feed
    if (DomUtil.matches(bundleElement, AtomFeedConstants.N_ENTRY)) {
        Element authorEl = DomUtil.getChildElement(bundleElement, AtomFeedConstants.N_AUTHOR);
        Element nameEl = authorEl != null ? DomUtil.getChildElement(authorEl, AtomFeedConstants.N_NAME) : null;
        if (nameEl != null) {
            userId = DomUtil.getTextTrim(nameEl);
        }
    }
    while (eventElementIterator.hasNext()) {
        Element evElem = eventElementIterator.nextElement();
        Element typeEl = DomUtil.getChildElement(evElem, ObservationConstants.N_EVENTTYPE);
        EventType[] et = DefaultEventType.createFromXml(typeEl);
        if (et.length == 0 || et.length > 1) {
            // should not occur.
            log.error("Ambiguous event type definition: expected one single event type.");
            continue;
        }
        String href = DomUtil.getChildTextTrim(evElem, XML_HREF, NAMESPACE);
        int type = EventUtil.getJcrEventType(et[0].getName());
        Path eventPath = null;
        ItemId eventId = null;
        NodeId parentId = null;
        if (href != null) {
            href = resolve(baseUri, href);
            try {
                eventPath = uriResolver.getQPath(href, sessionInfo);
            } catch (RepositoryException e) {
                // should not occur
                log.error("Internal error while building Event: ()", e.getMessage());
                continue;
            }
            boolean isForNode = (type == Event.NODE_ADDED || type == Event.NODE_REMOVED || type == Event.NODE_MOVED);
            try {
                if (isForNode) {
                    eventId = uriResolver.getNodeIdAfterEvent(href, sessionInfo, type == Event.NODE_REMOVED);
                } else {
                    eventId = uriResolver.getPropertyId(href, sessionInfo);
                }
            } catch (RepositoryException e) {
                if (isForNode) {
                    eventId = idFactory.createNodeId((String) null, eventPath);
                } else {
                    try {
                        eventId = idFactory.createPropertyId(idFactory.createNodeId((String) null, eventPath.getAncestor(1)), eventPath.getName());
                    } catch (RepositoryException e1) {
                        log.warn("Unable to build event itemId: {}", e.getMessage());
                    }
                }
            }
            String parentHref = Text.getRelativeParent(href, 1, true);
            try {
                parentId = uriResolver.getNodeId(parentHref, sessionInfo);
            } catch (RepositoryException e) {
                log.warn("Unable to build event parentId: {}", e.getMessage());
            }
        }
        if (userId == null) {
            // user id not retrieved from container
            userId = DomUtil.getChildTextTrim(evElem, ObservationConstants.N_EVENTUSERID);
        }
        events.add(new EventImpl(eventId, eventPath, parentId, type, userId, evElem, getNamePathResolver(sessionInfo), getQValueFactory()));
    }
    return events;
}
Also used : Path(org.apache.jackrabbit.spi.Path) ElementIterator(org.apache.jackrabbit.webdav.xml.ElementIterator) DefaultEventType(org.apache.jackrabbit.webdav.observation.DefaultEventType) EventType(org.apache.jackrabbit.webdav.observation.EventType) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) RepositoryException(javax.jcr.RepositoryException) ItemId(org.apache.jackrabbit.spi.ItemId) NodeId(org.apache.jackrabbit.spi.NodeId) Event(org.apache.jackrabbit.spi.Event)

Aggregations

DefaultEventType (org.apache.jackrabbit.webdav.observation.DefaultEventType)2 EventType (org.apache.jackrabbit.webdav.observation.EventType)2 ArrayList (java.util.ArrayList)1 RepositoryException (javax.jcr.RepositoryException)1 Event (org.apache.jackrabbit.spi.Event)1 ItemId (org.apache.jackrabbit.spi.ItemId)1 NodeId (org.apache.jackrabbit.spi.NodeId)1 Path (org.apache.jackrabbit.spi.Path)1 ElementIterator (org.apache.jackrabbit.webdav.xml.ElementIterator)1 Element (org.w3c.dom.Element)1