Package javax.jcr.observation

Examples of javax.jcr.observation.Event


         *
         * @see javax.jcr.observation.EventListener#onEvent(EventIterator)
         */
        public void onEvent(EventIterator events) {
            while (events.hasNext()) {
                Event ev = events.nextEvent();
                try {
                    String evPath = ev.getPath();
                    String repGroups = session.getJCRName(UserConstants.P_GROUPS);
                    // TODO: add better evaluation.
                    if (repGroups.equals(Text.getName(evPath)) &&
                            userNodePath.equals(Text.getRelativeParent(evPath, 1))) {
                        // recalculate the is...Admin flags
                        switch (ev.getType()) {
                            case Event.PROPERTY_REMOVED:
                                isUserAdmin = false;
                                isGroupAdmin = false;
                                break;
                            case Event.PROPERTY_ADDED:
View Full Code Here


            Element bundle = DomUtil.createElement(document, XML_EVENTBUNDLE, NAMESPACE);
            if (transactionId != null) {
                DomUtil.setAttribute(bundle, XML_EVENT_TRANSACTION_ID, NAMESPACE, transactionId);
            }
            while (events.hasNext()) {
                Event event = events.nextEvent();
                Element eventElem = DomUtil.addChildElement(bundle, XML_EVENT, NAMESPACE);
                // href
                String eHref = "";
                try {
                    boolean isCollection = (event.getType() == Event.NODE_ADDED || event.getType() == Event.NODE_REMOVED);
                    eHref = locator.getFactory().createResourceLocator(locator.getPrefix(), locator.getWorkspacePath(), event.getPath(), false).getHref(isCollection);
                } catch (RepositoryException e) {
                    // should not occur....
                    log.error(e.getMessage());
                }
                eventElem.appendChild(DomUtil.hrefToXml(eHref, document));
                // eventtype
                Element eType = DomUtil.addChildElement(eventElem, XML_EVENTTYPE, NAMESPACE);
                eType.appendChild(getEventType(event.getType()).toXml(document));
                // user id
                DomUtil.addChildElement(eventElem, XML_EVENTUSERID, NAMESPACE, event.getUserID());

                // Additional JCR 2.0 event information
                // userdata
                try {
                    DomUtil.addChildElement(eventElem, XML_EVENTUSERDATA, NAMESPACE, event.getUserData());
                } catch (RepositoryException e) {
                    log.error("Internal error while retrieving event user data.", e.getMessage());
                }
                // timestamp
                try {
                    DomUtil.addChildElement(eventElem, XML_EVENTDATE, NAMESPACE, String.valueOf(event.getDate()));
                } catch (RepositoryException e) {
                    log.error("Internal error while retrieving event date.", e.getMessage());
                }
                // identifier
                try {
                    DomUtil.addChildElement(eventElem, XML_EVENTIDENTIFIER, NAMESPACE, event.getIdentifier());
                } catch (RepositoryException e) {
                    log.error("Internal error while retrieving event identifier.", e.getMessage());
                }
                // info
                Element info = DomUtil.addChildElement(eventElem, XML_EVENTINFO, NAMESPACE);
                try {
                    Map m = event.getInfo();
                    for (Iterator it = m.keySet().iterator(); it.hasNext();) {
                        String key = it.next().toString();
                        Object value = m.get(key);
                        if (value != null) {
                            DomUtil.addChildElement(info, key, Namespace.EMPTY_NAMESPACE, value.toString());
View Full Code Here

         * @see EventListener#onEvent(javax.jcr.observation.EventIterator)
         */
        public void onEvent(EventIterator events) {
            while (events.hasNext()) {
                try {
                    Event e = events.nextEvent();
                    DavResourceLocator loc = getLocatorFromItemPath(e.getPath());
                    DavResource res = createResourceFromLocator(loc);
                    ms.addResponse(new MultiStatusResponse(res, propNameSet));

                } catch (DavException e) {
                    // should not occur
                    log.error("Error while building MultiStatusResponse from Event: " + e.getMessage());
                } catch (RepositoryException e) {
                    // should not occur
                    log.error("Error while building MultiStatusResponse from Event: " + e.getMessage());
                }
            }
        }
View Full Code Here

            Element bundle = DomUtil.createElement(document, XML_EVENTBUNDLE, NAMESPACE);
            if (transactionId != null) {
                DomUtil.setAttribute(bundle, XML_EVENT_TRANSACTION_ID, NAMESPACE, transactionId);
            }
            while (events.hasNext()) {
                Event event = events.nextEvent();
                Element eventElem = DomUtil.addChildElement(bundle, XML_EVENT, NAMESPACE);
                // href
                String eHref = "";
                try {
                    boolean isCollection = (event.getType() == Event.NODE_ADDED || event.getType() == Event.NODE_REMOVED);
                    eHref = locator.getFactory().createResourceLocator(locator.getPrefix(), locator.getWorkspacePath(), event.getPath(), false).getHref(isCollection);
                } catch (RepositoryException e) {
                    // should not occur....
                    log.error(e.getMessage());
                }
                eventElem.appendChild(DomUtil.hrefToXml(eHref, document));
                // event type
                Element eType = DomUtil.addChildElement(eventElem, XML_EVENTTYPE, NAMESPACE);
                eType.appendChild(getEventType(event.getType()).toXml(document));
                // user id
                DomUtil.addChildElement(eventElem, XML_EVENTUSERID, NAMESPACE, event.getUserID());

                // Additional JCR 2.0 event information
                // user data
                try {
                    DomUtil.addChildElement(eventElem, XML_EVENTUSERDATA, NAMESPACE, event.getUserData());
                } catch (RepositoryException e) {
                    log.error("Internal error while retrieving event user data.", e.getMessage());
                }
                // time stamp
                try {
                    DomUtil.addChildElement(eventElem, XML_EVENTDATE, NAMESPACE, String.valueOf(event.getDate()));
                } catch (RepositoryException e) {
                    log.error("Internal error while retrieving event date.", e.getMessage());
                }
                // identifier
                try {
                    DomUtil.addChildElement(eventElem, XML_EVENTIDENTIFIER, NAMESPACE, event.getIdentifier());
                } catch (RepositoryException e) {
                    log.error("Internal error while retrieving event identifier.", e.getMessage());
                }
                // info
                Element info = DomUtil.addChildElement(eventElem, XML_EVENTINFO, NAMESPACE);
                try {
                    @SuppressWarnings({"RawUseOfParameterizedType"}) Map m = event.getInfo();
                    for (Object o : m.keySet()) {
                        String key = o.toString();
                        Object value = m.get(key);
                        if (value != null) {
                            DomUtil.addChildElement(info, key, Namespace.EMPTY_NAMESPACE, value.toString());
View Full Code Here

        // collect the ids of all access controlled nodes that have been affected
        // by the events and thus need their cache entries updated or cleared.
        while (events.hasNext()) {
            try {
                Event ev = events.nextEvent();
                String identifier = ev.getIdentifier();
                String path = ev.getPath();

                switch (ev.getType()) {
                    case Event.NODE_ADDED:
                        NodeImpl n = (NodeImpl) systemSession.getNodeByIdentifier(identifier);
                        if (n.isNodeType(NT_REP_ACL)) {
                            // a new ACL was added -> use the added node to update
                            // the cache.
View Full Code Here

        // collect the paths of all access controlled nodes that have been affected
        // by the events and thus need their cache entries updated or cleared.
        while (events.hasNext()) {
            try {
                Event ev = events.nextEvent();
                String identifier = ev.getIdentifier();
                String path = ev.getPath();

                switch (ev.getType()) {
                    case Event.NODE_ADDED:
                        NodeImpl n = (NodeImpl) systemSession.getNodeByIdentifier(identifier);
                        if (n.isNodeType(NT_REP_ACL)) {
                            // a new ACL was added -> use the added node to update
                            // the cache.
View Full Code Here

     */
    public void onEvent(EventIterator eventIterator) {
        // evaluate if the membership cache needs to be cleared;
        boolean clear = false;
        while (eventIterator.hasNext() && !clear) {
            Event ev = eventIterator.nextEvent();
            try {
                if (pMembers.equals(Text.getName(ev.getPath()))) {
                    // simple case: a rep:members property that is affected
                    clear = true;
                } else if (useMembersNode) {
                    // test if it affects a property defined by rep:Members node type.
                    int type = ev.getType();
                    if (type == Event.PROPERTY_ADDED || type == Event.PROPERTY_CHANGED) {
                        Property p = systemSession.getProperty(ev.getPath());
                        Name declNtName = ((NodeTypeImpl) p.getDefinition().getDeclaringNodeType()).getQName();
                        clear = NT_REP_MEMBERS.equals(declNtName);
                    } else {
                        // PROPERTY_REMOVED
                        // test if the primary node type of the parent node is rep:Members
                        // this could potentially by some other property as well as the
                        // rep:Members node are not protected and could changed by
                        // adding a mixin type.
                        // ignoring this and simply clear the cache
                        String parentId = ev.getIdentifier();
                        Node n = systemSession.getNodeByIdentifier(parentId);
                        Name ntName = ((NodeTypeImpl) n.getPrimaryNodeType()).getQName();
                        clear = (UserConstants.NT_REP_MEMBERS.equals(ntName));
                    }
                }
View Full Code Here

         *
         * @see javax.jcr.observation.EventListener#onEvent(EventIterator)
         */
        public void onEvent(EventIterator events) {
            while (events.hasNext()) {
                Event ev = events.nextEvent();
                try {
                    String evPath = ev.getPath();
                    String repMembers = session.getJCRName(UserConstants.P_MEMBERS);
                    if (repMembers.equals(Text.getName(evPath))) {
                        // invalidate the cached results
                        clearCache();
                        // only need to clear the cache once. stop processing
                        break;
                    } else if (!membersInProperty) {
                        /* the affected property is not rep:Members and members are
                           stored in a tree structure (user manager configuration.
                           test if the parent node is of type rep:Members in order
                           to determine if any membership modification occurred.*/
                        Node parent = session.getNodeByIdentifier(ev.getIdentifier());
                        if (UserConstants.NT_REP_MEMBERS.equals(((NodeTypeImpl) parent.getPrimaryNodeType()).getQName())) {
                            clearCache();
                        }

                    } // else: not interested.
View Full Code Here

        }
        EventBundle bundle = getCurrentBundle();
        // above hasNext() call ensures that there is bundle with an event state
        assert bundle != null && bundle.events.hasNext();

        Event next = (Event) bundle.events.next();
        if (!bundle.events.hasNext()) {
            // done with this bundle -> remove from buffer
            eventBundleBuffer.remove(0);
        }
        position++;
View Full Code Here

                } catch (InterruptedException e) {
                    // ignore
                }
            }
            while (events.hasNext()) {
                Event event = events.nextEvent();
                try {
                    String path = event.getPath();
                    try {
                        Item item = session.getItem(path);
                        if (item.isNode()) {
                            Node n = (Node) item;
                            recurse(n, testDelay);
View Full Code Here

TOP

Related Classes of javax.jcr.observation.Event

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.