Package javax.jcr.observation

Examples of javax.jcr.observation.Event


            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


                new EventListener() {

                    public void onEvent(EventIterator events) {
                        try {
                            while (events.hasNext()) {
                                Event event = events.nextEvent();
                                Properties properties = new Properties();
                                String topic;
                                if (event.getType() == Event.NODE_ADDED) {
                                    topic = SlingConstants.TOPIC_RESOURCE_ADDED;
                                } else if (event.getType() == Event.NODE_MOVED) {
                                    topic = SlingConstants.TOPIC_RESOURCE_CHANGED;
                                } else if (event.getType() == Event.NODE_REMOVED) {
                                    topic = SlingConstants.TOPIC_RESOURCE_REMOVED;
                                } else {
                                    topic = SlingConstants.TOPIC_RESOURCE_CHANGED;
                                }
                                try {
                                    properties.put("path", event.getPath());
                                    org.osgi.service.event.Event osgiEvent = new org.osgi.service.event.Event(
                                            topic, properties);
                                    votingHandler.handleEvent(osgiEvent);
                                } catch (RepositoryException e) {
                                    logger.warn("RepositoryException: " + e, e);
View Full Code Here

        when(bundleContext.getServiceReferences(anyString(), anyString())).thenReturn(serviceRefs);
        when(bundleContext.getService(serviceRef)).thenReturn(eventAdmin);

        jcrResourceListener = new JcrResourceListener("/", new ObservationListenerSupport(bundleContext, repository));

        Event event = mock(MockEvent.class);
        events = mock(EventIterator.class);
        when(events.hasNext()).thenReturn(true);
        when(event.getPath()).thenCallRealMethod();
        when(event.getType()).thenReturn(Event.NODE_ADDED);
        when(events.nextEvent()).thenReturn(event);
    }
View Full Code Here

        }
        final Map<String, Map<String, Object>> addedEvents = new HashMap<String, Map<String, Object>>();
        final Map<String, ChangedAttributes> changedEvents = new HashMap<String, ChangedAttributes>();
        final Map<String, Map<String, Object>> removedEvents = new HashMap<String, Map<String, Object>>();
        while ( events.hasNext() ) {
            final Event event = events.nextEvent();
            try {
                final String eventPath;
                if ( this.mountPrefix != null ) {
                    eventPath = this.mountPrefix + event.getPath();
                } else {
                    eventPath = event.getPath();
                }
                if ( event.getType() == Event.PROPERTY_ADDED
                     || event.getType() == Event.PROPERTY_REMOVED
                     || event.getType() == Event.PROPERTY_CHANGED ) {
                    final int lastSlash = eventPath.lastIndexOf('/');
                    final String nodePath = eventPath.substring(0, lastSlash);
                    final String propName = eventPath.substring(lastSlash + 1);
                    this.updateChangedEvent(changedEvents, nodePath, event, propName);

                } else if ( event.getType() == Event.NODE_ADDED ) {
                    addedEvents.put(eventPath, createEventProperties(event));

                } else if ( event.getType() == Event.NODE_REMOVED) {
                    // remove is the strongest operation, therefore remove all removed
                    // paths from added
                    addedEvents.remove(eventPath);
                    removedEvents.put(eventPath, createEventProperties(event));
                }
View Full Code Here

    }

    private EventIterator prepareNodeCreateEvent(Resource pResource) throws RepositoryException {
        String resourcePath = pResource.getPath();

        Event nodeEvent = mock(Event.class);
        when(nodeEvent.getType()).thenReturn(Event.NODE_ADDED);
        when(nodeEvent.getPath()).thenReturn(resourcePath);

        Event propertyEvent = mock(Event.class);
        when(propertyEvent.getType()).thenReturn(Event.PROPERTY_ADDED);
        when(propertyEvent.getPath()).thenReturn(resourcePath + "/" + SuperimposingResourceProvider.PROP_SUPERIMPOSE_SOURCE_PATH);

        EventIterator eventIterator = mock(EventIterator.class);
        when(eventIterator.hasNext()).thenReturn(true, true, false);
        when(eventIterator.nextEvent()).thenReturn(nodeEvent, propertyEvent);
        return eventIterator;
View Full Code Here

    }

    private EventIterator prepareNodeChangeEvent(Resource pResource) throws RepositoryException {
        String resourcePath = pResource.getPath();

        Event propertyEvent = mock(Event.class);
        when(propertyEvent.getType()).thenReturn(Event.PROPERTY_CHANGED);
        when(propertyEvent.getPath()).thenReturn(resourcePath + "/" + SuperimposingResourceProvider.PROP_SUPERIMPOSE_SOURCE_PATH);

        EventIterator eventIterator = mock(EventIterator.class);
        when(eventIterator.hasNext()).thenReturn(true, false);
        when(eventIterator.nextEvent()).thenReturn(propertyEvent);
        return eventIterator;
View Full Code Here

    }

    private EventIterator prepareNodeRemoveEvent(Resource pResource) throws RepositoryException {
        String resourcePath = pResource.getPath();

        Event nodeEvent = mock(Event.class);
        when(nodeEvent.getType()).thenReturn(Event.NODE_REMOVED);
        when(nodeEvent.getPath()).thenReturn(resourcePath);

        EventIterator eventIterator = mock(EventIterator.class);
        when(eventIterator.hasNext()).thenReturn(true, false);
        when(eventIterator.nextEvent()).thenReturn(nodeEvent);
        return eventIterator;
View Full Code Here

    }

    private EventIterator prepareNodeMoveEvent(Resource pResource, String pOldPath) throws RepositoryException {
        String resourcePath = pResource.getPath();

        Event nodeRemoveEvent = mock(Event.class);
        when(nodeRemoveEvent.getType()).thenReturn(Event.NODE_REMOVED);
        when(nodeRemoveEvent.getPath()).thenReturn(pOldPath);

        Event nodeCreateEvent = mock(Event.class);
        when(nodeCreateEvent.getType()).thenReturn(Event.NODE_ADDED);
        when(nodeCreateEvent.getPath()).thenReturn(resourcePath);

        EventIterator eventIterator = mock(EventIterator.class);
        when(eventIterator.hasNext()).thenReturn(true, true, false);
        when(eventIterator.nextEvent()).thenReturn(nodeRemoveEvent, nodeCreateEvent);
        return eventIterator;
View Full Code Here

            // collect all actions to be performed for this event
            final Map<String, Boolean> actions = new HashMap<String, Boolean>();
            boolean nodeAdded = false;
            boolean nodeRemoved = false;
            while (events.hasNext()) {
                final Event event = events.nextEvent();
                final String path = event.getPath();
                final String name = ResourceUtil.getName(path);
                if (event.getType() == Event.NODE_ADDED) {
                    nodeAdded = true;
                } else if (event.getType() == Event.NODE_REMOVED && superimposingProviders.containsKey(path)) {
                    nodeRemoved = true;
                    actions.put(path, false);
                } else if (StringUtils.equals(name, PROP_SUPERIMPOSE_SOURCE_PATH)
                        || StringUtils.equals(name, PROP_SUPERIMPOSE_REGISTER_PARENT)
                        || StringUtils.equals(name, PROP_SUPERIMPOSE_OVERLAYABLE)) {
View Full Code Here

            this.requestHandler = requestHandler;
        }

        public void onEvent(EventIterator eventIterator) {
            while (eventIterator.hasNext()) {
                Event event = eventIterator.nextEvent();
                try {
                    if (ReplicationJcrUtils.isSafe(event)) {
                        ReplicationRequest request = processEvent(event);
                        if (request != null) {
                            requestHandler.handle(request);
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.