You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by an...@apache.org on 2008/04/11 02:19:03 UTC

svn commit: r647019 - in /lenya/sandbox/modules/diff/java/src/org/apache/lenya/modules/diff: ChangeNotifier.java SimpleTreeDiff.java

Author: andreas
Date: Thu Apr 10 17:18:54 2008
New Revision: 647019

URL: http://svn.apache.org/viewvc?rev=647019&view=rev
Log:
Don't send notification if no difference was found, removed logging to System.out.

Modified:
    lenya/sandbox/modules/diff/java/src/org/apache/lenya/modules/diff/ChangeNotifier.java
    lenya/sandbox/modules/diff/java/src/org/apache/lenya/modules/diff/SimpleTreeDiff.java

Modified: lenya/sandbox/modules/diff/java/src/org/apache/lenya/modules/diff/ChangeNotifier.java
URL: http://svn.apache.org/viewvc/lenya/sandbox/modules/diff/java/src/org/apache/lenya/modules/diff/ChangeNotifier.java?rev=647019&r1=647018&r2=647019&view=diff
==============================================================================
--- lenya/sandbox/modules/diff/java/src/org/apache/lenya/modules/diff/ChangeNotifier.java (original)
+++ lenya/sandbox/modules/diff/java/src/org/apache/lenya/modules/diff/ChangeNotifier.java Thu Apr 10 17:18:54 2008
@@ -131,34 +131,36 @@
             DifferencesWriter writer = new DifferencesWriter();
             difference.traverse(writer);
 
-            Notifier notifier = null;
-            try {
-                String title = DublinCoreHelper.getTitle(doc, true);
-                String[] subjectParams = { title };
-
-                String url = doc.getCanonicalWebappURL();
-
-                LinkRewriter rewriter = new OutgoingLinkRewriter(this.manager, doc.getSession(),
-                        url, false, false, false);
-                String documentUrl = rewriter.rewrite(url);
-                
-                String userId = rev2.getUserId();
-                User user = getUser(url, userId);
-                String userParam = user == null ? userId : user.getName() + " (" + userId + ")";
-                
-                String[] bodyParams = { title, documentUrl, userParam, writer.toString() };
-                User sender = getUser(url, this.sender);
-                User recipient = getUser(url, this.recipient);
-                User[] recipients = { recipient };
-
-                Message message = new Message(SUBJECT, subjectParams, BODY, bodyParams, sender,
-                        recipients);
-
-                notifier = (Notifier) this.manager.lookup(Notifier.ROLE);
-                notifier.notify(message);
-            } finally {
-                if (notifier != null) {
-                    this.manager.release(notifier);
+            if (writer.isDifferent()) {
+                Notifier notifier = null;
+                try {
+                    String title = DublinCoreHelper.getTitle(doc, true);
+                    String[] subjectParams = { title };
+
+                    String url = doc.getCanonicalWebappURL();
+
+                    LinkRewriter rewriter = new OutgoingLinkRewriter(this.manager,
+                            doc.getSession(), url, false, false, false);
+                    String documentUrl = rewriter.rewrite(url);
+
+                    String userId = rev2.getUserId();
+                    User user = getUser(url, userId);
+                    String userParam = user == null ? userId : user.getName() + " (" + userId + ")";
+
+                    String[] bodyParams = { title, documentUrl, userParam, writer.toString() };
+                    User sender = getUser(url, this.sender);
+                    User recipient = getUser(url, this.recipient);
+                    User[] recipients = { recipient };
+
+                    Message message = new Message(SUBJECT, subjectParams, BODY, bodyParams, sender,
+                            recipients);
+
+                    notifier = (Notifier) this.manager.lookup(Notifier.ROLE);
+                    notifier.notify(message);
+                } finally {
+                    if (notifier != null) {
+                        this.manager.release(notifier);
+                    }
                 }
             }
         }
@@ -173,6 +175,7 @@
         protected static final String DIFFERENCE_SEPARATOR = "\n----\n";
         protected static final String BEFORE_AFTER_SEPARATOR = "\n--\n";
         private StringBuffer buffer = new StringBuffer();
+        private boolean isDifferent = false;
 
         public void visit(DifferenceNode node) {
             Comparable left = node.getLeftSide();
@@ -181,11 +184,13 @@
                 this.buffer.append(DIFFERENCE_SEPARATOR);
                 this.buffer.append("Added: " + node.getPath() + "\n");
                 this.buffer.append(toString(right));
+                this.isDifferent = true;
             }
             if (left != null && right == null) {
                 this.buffer.append(DIFFERENCE_SEPARATOR);
                 this.buffer.append("Removed: " + node.getPath() + "\n");
                 this.buffer.append(toString(left));
+                this.isDifferent = true;
             }
             if (left != null && right != null && !left.equals(right)) {
                 this.buffer.append(DIFFERENCE_SEPARATOR);
@@ -194,6 +199,7 @@
                 this.buffer.append(toString(left));
                 this.buffer.append(BEFORE_AFTER_SEPARATOR);
                 this.buffer.append(toString(right));
+                this.isDifferent = true;
             }
         }
 
@@ -205,6 +211,10 @@
         public String toString() {
             this.buffer.append(DIFFERENCE_SEPARATOR);
             return this.buffer.toString();
+        }
+
+        public boolean isDifferent() {
+            return this.isDifferent;
         }
 
     }

Modified: lenya/sandbox/modules/diff/java/src/org/apache/lenya/modules/diff/SimpleTreeDiff.java
URL: http://svn.apache.org/viewvc/lenya/sandbox/modules/diff/java/src/org/apache/lenya/modules/diff/SimpleTreeDiff.java?rev=647019&r1=647018&r2=647019&view=diff
==============================================================================
--- lenya/sandbox/modules/diff/java/src/org/apache/lenya/modules/diff/SimpleTreeDiff.java (original)
+++ lenya/sandbox/modules/diff/java/src/org/apache/lenya/modules/diff/SimpleTreeDiff.java Thu Apr 10 17:18:54 2008
@@ -125,7 +125,7 @@
     }
 
     protected void log(String message) {
-        System.out.println(message);
+        //System.out.println(message);
     }
 
     protected void applySkippedNodes(DifferenceNodeImpl parent, Queue leftSkipped,



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@lenya.apache.org
For additional commands, e-mail: commits-help@lenya.apache.org