Package javax.jcr.observation

Examples of javax.jcr.observation.Event


            return;
        }

        synchronized (repProps) {
            while (events.hasNext()) {
                Event event = events.nextEvent();
                long type = event.getType();
                if ((type & Event.NODE_ADDED) == Event.NODE_ADDED) {
                    nodesCount++;
                    repProps.setProperty(STATS_NODE_COUNT_PROPERTY, Long.toString(nodesCount));
                }
                if ((type & Event.NODE_REMOVED) == Event.NODE_REMOVED) {
View Full Code Here


    }

    public void onEvent(EventIterator eventIterator) {
        final Set<String> nodes = new HashSet<String>();
        while (eventIterator.hasNext()) {
            Event event = eventIterator.nextEvent();
            try {
                if (isExternal(event)) {
                    continue;
                }

                String path = event.getPath();
                String parentPath = path.substring(0, path.lastIndexOf('/'));
                String name = path.substring(path.lastIndexOf('/') + 1);
                String parentName = parentPath.substring(parentPath.lastIndexOf('/') + 1);
                if ((event.getType() == Event.NODE_ADDED || event.getType() == Event.NODE_REMOVED) && name.equals("j:acl")) {
                    nodes.add(parentPath);
                }
                if ((event.getType() == Event.PROPERTY_ADDED || event.getType() == Event.PROPERTY_CHANGED) && parentName.equals("j:acl")) {
                    parentPath = parentPath.substring(0, parentPath.lastIndexOf('/'));
                    nodes.add(parentPath);
                }
                if (event.getType() == Event.PROPERTY_CHANGED && name.equals("j:fullpath")) {
                    // invalidate container HTML cache when the file is moved/renamed
                    nodes.add(parentPath);
                }
                if ((event.getType() == Event.PROPERTY_ADDED || event.getType() == Event.PROPERTY_CHANGED) && parentName.equals("jcr:content")) {
                    parentPath = parentPath.substring(0, parentPath.lastIndexOf('/'));
                    nodes.add(parentPath);
                }
                if ((event.getType() == Event.NODE_REMOVED) && name.indexOf(':') == -1) {
                    nodes.add(path);
                }
            } catch (RepositoryException e) {
                logger.error(e.getMessage(), e);
            }
View Full Code Here

     * @param events The event set received.
     */
    public void onEvent(EventIterator events) {
        while (events.hasNext()) {
            try {
                Event event = events.nextEvent();
                switch (event.getType()) {
                    case Event.NODE_ADDED:
                        loggingService.logContentEvent(event.getUserID(), "", "", event.getIdentifier(), event.getPath(), "", "nodeCreated",
                                new JSONObject(event.getInfo()).toString());
                        break;
                    case Event.NODE_MOVED:
                        /* From the JCR 2.0 Spec :
                           12.3.3 Event Information on Move and Order

                           On a NODE_MOVED event, the Map object returned by Event.getInfo() contains parameter
                           information from the method that caused the event. There are three JCR methods that cause
                           this event type: Session.move, Workspace.move and Node.orderBefore.

                           If the method that caused the NODE_MOVE event was a Session.move or Workspace.move then the
                           returned Map has keys srcAbsPath and destAbsPath with values corresponding to the parameters
                           passed to the move method, as specified in the Javadoc.

                           If the method that caused the NODE_MOVE event was a Node.orderBefore then the returned Map
                           has keys srcChildRelPath and destChildRelPath with values corresponding to the parameters
                           passed to the orderBefore method, as specified in the Javadoc.
                        */
                        loggingService.logContentEvent(event.getUserID(), "", "", event.getIdentifier(), event.getPath(), "", "nodeMoved",
                                new JSONObject(event.getInfo()).toString());
                        break;
                    case Event.NODE_REMOVED:
                        loggingService.logContentEvent(event.getUserID(), "", "", event.getIdentifier(), event.getPath(), "", "nodeDeleted",
                                new JSONObject(event.getInfo()).toString());
                        break;
                    case Event.PROPERTY_ADDED:
                        loggingService.logContentEvent(event.getUserID(), "", "", event.getIdentifier(), event.getPath(), "", "propertyAdded",
                                new JSONObject(event.getInfo()).toString());
                        break;
                    case Event.PROPERTY_CHANGED:
                        // @todo we might want to add the new value if available, so that we can track updates more finely ?
                        loggingService.logContentEvent(event.getUserID(), "", "", event.getIdentifier(), event.getPath(), "", "propertyChanged",
                                new JSONObject(event.getInfo()).toString());
                        break;
                    case Event.PROPERTY_REMOVED:
                        loggingService.logContentEvent(event.getUserID(), "", "", event.getIdentifier(), event.getPath(), "", "propertyRemoved",
                                new JSONObject(event.getInfo()).toString());
                        break;
                }
            } catch (RepositoryException e) {
                logger.error(e.getMessage(), e);
            }
View Full Code Here

        try {
            JCRTemplate.getInstance().doExecuteWithSystemSession(new JCRCallback<Object>() {
                public Object doInJCR(JCRSessionWrapper s) throws RepositoryException {
                    try {
                        while (eventIterator.hasNext()) {
                            Event event = eventIterator.nextEvent();
                            if (isExternal(event)) {
                                continue;
                            }

                            // skip /jcr:system path
                            if (event.getPath().startsWith("/jcr:system")) {
                                continue;
                            }

                            // is it a binary property?
                            Property p = (Property) s.getItem(event.getPath());
                            if (p.getType() != PropertyType.BINARY) {
                                continue;
                            }

                            doHandle(p.getParent(), event, s);
View Full Code Here

            }
            JCRTemplate.getInstance().doExecuteWithSystemSession(userId, workspace, new JCRCallback<Object>() {
                public Object doInJCR(JCRSessionWrapper s) throws RepositoryException {
                    final Set<Session> sessions = new HashSet<Session>();
                    while (eventIterator.hasNext()) {
                        Event event = eventIterator.nextEvent();
                        if (isExternal(event)) {
                            continue;
                        }
                        try {
                            JCRNodeWrapper n = null;
                            String eventPath = event.getPath();
                            if (event.getType() == Event.NODE_ADDED) {
                                try {
                                    n = (JCRNodeWrapper) s.getItem(eventPath);
                                } catch (PathNotFoundException e) {
                                    continue;
                                }
View Full Code Here

        }
        try {
            JCRTemplate.getInstance().doExecuteWithSystemSession(userId, workspace, new JCRCallback<Object>() {
                public Object doInJCR(JCRSessionWrapper session) throws RepositoryException {
                    while (events.hasNext()) {
                        Event event = events.nextEvent();

                        if (isExternal(event)) {
                            continue;
                        }

                        String path = event.getPath();
                        if (path.startsWith("/jcr:system/")) {
                            continue;
                        }
                        if ((event.getType() & Event.PROPERTY_CHANGED + Event.PROPERTY_ADDED + Event.PROPERTY_REMOVED) != 0) {
                            if (propertiesToIgnore.contains(StringUtils.substringAfterLast(path, "/"))) {
                                continue;
                            }
                        }
                        String username = StringUtils.substringAfterLast(StringUtils.substringBeforeLast(path,"/"), "/");
View Full Code Here

            }

            JCRTemplate.getInstance().doExecuteWithSystemSession(userId, workspace, new JCRCallback<Object>() {
                public Object doInJCR(JCRSessionWrapper session) throws RepositoryException {
                    while (events.hasNext()) {
                        Event event = events.nextEvent();

                        if (isExternal(event)) {
                            continue;
                        }

                        String path = event.getPath();
                        if (event.getType() == Event.NODE_ADDED) {
                            nodeAdded(session, path);
                        } else if (event.getType() == Event.NODE_REMOVED) {
                            nodeRemoved(session, path);
                        } else if (event.getType() == Event.NODE_MOVED) {
                            nodeMoved(session, path);
                        }
                    }
                    return null
                }
View Full Code Here

     * @param events The event set received.
     */
    public void onEvent(EventIterator events) {

        while (events.hasNext()) {
            Event event = (Event) events.next();
            try {
                String path = event.getPath();
                if (!path.startsWith("/jcr:system")) {
                    boolean flushRoles = false;
                    final int type = event.getType();
                    if (renderService == null) {
                        renderService = (RenderService) SpringContextSingleton.getBean("RenderService");
                    }
                    if (renderService != null) {
                        if (path.contains("/templates") || path.startsWith("/templateSets")) {
View Full Code Here

    public void onEvent(EventIterator events) {
        final Cache depCache = cacheProvider.getDependenciesCache();
        final Cache regexpDepCache = cacheProvider.getRegexpDependenciesCache();
        final Set<String> flushed = new HashSet<String>();
        while (events.hasNext()) {
            Event event = (Event) events.next();
            try {
                String path = event.getPath();
                if (!path.startsWith("/jcr:system")) {
                    boolean flushParent = false;
                    boolean flushRoles = false;
                    if (path.contains("j:view")) {
                        flushParent = true;
                    }
                    final int type = event.getType();
                    if (type == Event.PROPERTY_ADDED || type == Event.PROPERTY_CHANGED || type == Event.PROPERTY_REMOVED) {
                        if (path.endsWith("/j:published")) {
                            flushParent = true;
                        }
                        if(path.endsWith("j:roles")) {
View Full Code Here

        final List<Object> list = new ArrayList<Object>();

        try {
            final List<Event> events = new ArrayList<Event>();
            while (eventIterator.hasNext()) {
                Event event = eventIterator.nextEvent();
                events.add(event);
            }
            JCRTemplate.getInstance().doExecuteWithSystemSession(userId, workspace, locale, new JCRCallback<Object>() {
                public Object doInJCR(JCRSessionWrapper s) throws RepositoryException {
                    Iterator<Event> it = events.iterator();

                    while (it.hasNext()) {
                        Event event = it.next();
                        if (isExternal(event)) {
                            continue;
                        }
                        try {
                            if (!event.getPath().startsWith("/jcr:system/")) {
                                if (event.getType() == Event.NODE_ADDED) {
                                    JCRNodeWrapper n = s.getNode(event.getPath());
                                    if (n.isNodeType("jmix:observable") && !n.isNodeType("jnt:translation")) {
                                        final String identifier = n.getIdentifier();
                                        AddedNodeFact rn = eventsMap.get(identifier);
                                        if (rn == null) {
                                            rn = new AddedNodeFact(n);
                                            eventsMap.put(identifier, rn);
                                        }
                                        list.add(rn);
                                    }
                                } else if (event.getType() == Event.PROPERTY_ADDED ||
                                        event.getType() == Event.PROPERTY_CHANGED) {
                                    String path = event.getPath();
                                    String propertyName = path.substring(path.lastIndexOf('/') + 1);
                                    if (!propertiesToIgnore.contains(propertyName)) {
                                        try {
                                            JCRPropertyWrapper p = (JCRPropertyWrapper) s.getItem(path);

                                            JCRNodeWrapper parent = p.getParent();
                                            if (parent.isNodeType("jnt:translation")) {
                                                parent = parent.getParent();
                                            }
                                            if (parent.isNodeType(Constants.NT_RESOURCE) ||
                                                    parent.isNodeType("jmix:observable")) {
                                                AddedNodeFact rn;
                                                if (parent.isNodeType(Constants.MIX_REFERENCEABLE)) {
                                                    final String identifier = parent.getIdentifier();
                                                    rn = eventsMap.get(identifier);
                                                    if (rn == null) {
                                                        rn = new AddedNodeFact(parent);
                                                        eventsMap.put(identifier, rn);
                                                    }
                                                } else {
                                                    rn = new AddedNodeFact(parent);
                                                }
                                                list.add(new ChangedPropertyFact(rn, p));
                                            }
                                        } catch (PathNotFoundException pnfe) {
                                            if (logger.isDebugEnabled()) {
                                                logger.debug("Path " + path + " not found, might be normal if using VFS", pnfe);
                                            }
                                            logger.warn("Couldn't access path " + path + ", ignoring it since it's not supported on some external repositories... ");
                                        }
                                    }
                                } else if (event.getType() == Event.NODE_REMOVED) {
                                    String parentPath = null;
                                    try {
                                        parentPath = StringUtils.substringBeforeLast(event.getPath(), "/");
                                        JCRNodeWrapper parent = s.getNode(parentPath);
                                        final String identifier = parent.getIdentifier();
                                        AddedNodeFact w = eventsMap.get(identifier);
                                        if (w == null) {
                                            w = new AddedNodeFact(parent);
                                            eventsMap.put(identifier, w);
                                        }

                                        final DeletedNodeFact e = new DeletedNodeFact(w, event.getPath());
                                        e.setIdentifier(event.getIdentifier());
                                        e.setSession(s);
                                        list.add(e);
                                    } catch (PathNotFoundException e) {
                                    }
                                } else if (event.getType() == Event.PROPERTY_REMOVED) {
                                    String path = event.getPath();
                                    int index = path.lastIndexOf('/');
                                    String nodePath = path.substring(0, index);
                                    String propertyName = path.substring(index + 1);
                                    if (!propertiesToIgnore.contains(propertyName)) {
                                        try {
                                            JCRNodeWrapper n = s.getNode(nodePath);
                                            String key = n.isNodeType(Constants.MIX_REFERENCEABLE) ? n.getIdentifier() :
                                                    n.getPath();
                                            AddedNodeFact rn = eventsMap.get(key);
                                            if (rn == null) {
                                                rn = new AddedNodeFact(n);
                                                eventsMap.put(key, rn);
                                            }
                                            list.add(new DeletedPropertyFact(rn, propertyName));
                                        } catch (PathNotFoundException e) {
                                            // ignore if parent has also been deleted ?
                                        }
                                    }
                                }
                            }
                        } catch (PathNotFoundException pnfe) {
                            logger.error("Error when executing event. Unable to find node or property for path: " +
                                    event.getPath(), pnfe);
                        } catch (Exception e) {
                            logger.error("Error when executing event", e);
                        }
                    }
                    if (!list.isEmpty()) {
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.