jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r498034 - in /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core: SearchManager.java observation/EventImpl.java
Date Sat, 20 Jan 2007 01:10:48 GMT
Author: jukka
Date: Fri Jan 19 17:10:47 2007
New Revision: 498034

URL: http://svn.apache.org/viewvc?view=rev&rev=498034
Log:
JCR-699: No need for path formatting when checking for excluded events.

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SearchManager.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/EventImpl.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SearchManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SearchManager.java?view=diff&rev=498034&r1=498033&r2=498034
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SearchManager.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SearchManager.java
Fri Jan 19 17:10:47 2007
@@ -30,9 +30,8 @@
 import org.apache.jackrabbit.core.state.ItemStateManager;
 import org.apache.jackrabbit.core.state.NodeState;
 import org.apache.jackrabbit.core.state.NodeStateIterator;
-import org.apache.jackrabbit.name.NoPrefixDeclaredException;
+import org.apache.jackrabbit.name.MalformedPathException;
 import org.apache.jackrabbit.name.Path;
-import org.apache.jackrabbit.name.PathFormat;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -268,21 +267,34 @@
         return query;
     }
 
+    /**
+     * Checks if the given event should be excluded based on the
+     * {@link #excludePath} setting.
+     *
+     * @param event observation event
+     * @return <code>true</code> if the event should be excluded,
+     *         <code>false</code> otherwise
+     */
+    private boolean isExcluded(EventImpl event) {
+        try {
+            return excludePath != null
+                && excludePath.isAncestorOf(event.getQPath());
+        } catch (MalformedPathException ex) {
+            log.error("Error filtering events.", ex);
+            return false;
+        } catch (RepositoryException ex) {
+            log.error("Error filtering events.", ex);
+            return false;
+        }
+
+    }
+
     //---------------< EventListener interface >--------------------------------
 
     public void onEvent(EventIterator events) {
         log.debug("onEvent: indexing started");
         long time = System.currentTimeMillis();
 
-        String exclude = "";
-        if (excludePath != null) {
-            try {
-                exclude = PathFormat.format(excludePath, nsReg);
-            } catch (NoPrefixDeclaredException e) {
-                log.error("Error filtering events.", e);
-            }
-        }
-
         // nodes that need to be removed from the index.
         final Set removedNodes = new HashSet();
         // nodes that need to be added to the index.
@@ -292,20 +304,15 @@
 
         while (events.hasNext()) {
             EventImpl e = (EventImpl) events.nextEvent();
-            try {
-                if (excludePath != null && e.getPath().startsWith(exclude)) {
-                    continue;
+            if (!isExcluded(e)) {
+                long type = e.getType();
+                if (type == Event.NODE_ADDED) {
+                    addedNodes.put(e.getChildId(), e);
+                } else if (type == Event.NODE_REMOVED) {
+                    removedNodes.add(e.getChildId());
+                } else {
+                    propEvents.add(e);
                 }
-            } catch (RepositoryException ex) {
-                log.error("Error filtering events.", ex);
-            }
-            long type = e.getType();
-            if (type == Event.NODE_ADDED) {
-                addedNodes.put(e.getChildId(), e);
-            } else if (type == Event.NODE_REMOVED) {
-                removedNodes.add(e.getChildId());
-            } else {
-                propEvents.add(e);
             }
         }
 

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/EventImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/EventImpl.java?view=diff&rev=498034&r1=498033&r2=498034
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/EventImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/EventImpl.java
Fri Jan 19 17:10:47 2007
@@ -19,9 +19,7 @@
 import org.apache.jackrabbit.core.NodeId;
 import org.apache.jackrabbit.core.SessionImpl;
 import org.apache.jackrabbit.name.MalformedPathException;
-import org.apache.jackrabbit.name.NoPrefixDeclaredException;
 import org.apache.jackrabbit.name.Path;
-import org.apache.jackrabbit.name.PathFormat;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -72,6 +70,8 @@
         this.eventState = eventState;
     }
 
+    //---------------------------------------------------------------< Event >
+
     /**
      * {@inheritDoc}
      */
@@ -83,27 +83,39 @@
      * {@inheritDoc}
      */
     public String getPath() throws RepositoryException {
+        return session.getJCRPath(getQPath());
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public String getUserID() {
+        return eventState.getUserId();
+    }
+
+    //-----------------------------------------------------------< EventImpl >
+
+    /**
+     * Returns the qualified path of this event.
+     *
+     * @return qualified path
+     * @throws RepositoryException if the path can't be constructed
+     */
+    public Path getQPath() throws RepositoryException {
         try {
-            Path p;
-            if (eventState.getChildRelPath().getIndex() > 0) {
-                p = Path.create(eventState.getParentPath(), eventState.getChildRelPath().getName(),
-                        eventState.getChildRelPath().getIndex(), false);
+            Path parent = eventState.getParentPath();
+            Path.PathElement child = eventState.getChildRelPath();
+            int index = child.getIndex();
+            if (index > 0) {
+                return Path.create(parent, child.getName(), index, false);
             } else {
-                p = Path.create(eventState.getParentPath(), eventState.getChildRelPath().getName(),
false);
+                return Path.create(parent, child.getName(), false);
             }
-            return session.getJCRPath(p);
         } catch (MalformedPathException e) {
             String msg = "internal error: malformed path for event";
             log.debug(msg);
             throw new RepositoryException(msg, e);
         }
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public String getUserID() {
-        return eventState.getUserId();
     }
 
     /**



Mime
View raw message