You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by dp...@apache.org on 2010/07/22 14:57:12 UTC

svn commit: r966632 - /jackrabbit/sandbox/jackrabbit-journalwalker/src/main/java/org/apache/jackrabbit/journalwalker/JournalWalker.java

Author: dpfister
Date: Thu Jul 22 12:57:12 2010
New Revision: 966632

URL: http://svn.apache.org/viewvc?rev=966632&view=rev
Log:
Formatting changes
- suppress property changes unless specified
- suppress namespace/nodetype/lock operations unless specified
- display timestamp in log
- suppress revision number in output unless specified
- suppress id in output unless specified

Modified:
    jackrabbit/sandbox/jackrabbit-journalwalker/src/main/java/org/apache/jackrabbit/journalwalker/JournalWalker.java

Modified: jackrabbit/sandbox/jackrabbit-journalwalker/src/main/java/org/apache/jackrabbit/journalwalker/JournalWalker.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-journalwalker/src/main/java/org/apache/jackrabbit/journalwalker/JournalWalker.java?rev=966632&r1=966631&r2=966632&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-journalwalker/src/main/java/org/apache/jackrabbit/journalwalker/JournalWalker.java (original)
+++ jackrabbit/sandbox/jackrabbit-journalwalker/src/main/java/org/apache/jackrabbit/journalwalker/JournalWalker.java Thu Jul 22 12:57:12 2010
@@ -18,6 +18,9 @@ package org.apache.jackrabbit.journalwal
 
 import java.io.File;
 import java.io.IOException;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Date;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
@@ -66,9 +69,14 @@ public class JournalWalker implements Re
     private static final String DEFAULT_PRODUCER = "JR";
 
     /**
+     * Date formatter.
+     */
+    private final DateFormat df = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
+
+    /**
      * Record deserializer.
      */
-    private ClusterRecordDeserializer deserializer = new ClusterRecordDeserializer();
+    private final ClusterRecordDeserializer deserializer = new ClusterRecordDeserializer();
 
     /**
      * Id.
@@ -91,6 +99,21 @@ public class JournalWalker implements Re
     private long revision;
 
     /**
+     * Flag indicating whether to show all records.
+     */
+    private boolean showAll;
+
+    /**
+     * Flag indicating whether to show properties in change log records.
+     */
+    private boolean showProperties;
+
+    /**
+     * Flag indicating whether to show ids in change log records.
+     */
+    private boolean showId;
+
+    /**
      * Map of registered name spaces.
      */
     private BidiMap namespaces = new DualHashBidiMap();
@@ -121,6 +144,18 @@ public class JournalWalker implements Re
         this.revision = revision;
     }
 
+    public void setShowAll(boolean showAll) {
+        this.showAll = showAll;
+    }
+
+    public void setShowProperties(boolean showProperties) {
+        this.showProperties = showProperties;
+    }
+
+    public void setShowId(boolean showId) {
+        this.showId = showId;
+    }
+
     /**
      * Walk a record log.
      *
@@ -147,19 +182,28 @@ public class JournalWalker implements Re
      * @param workspace workspace name
      * @param id item id
      */
-    public void log(char op, String userId, String workspace, ItemId id) {
+    public void log(String date, char op, String userId, String workspace, ItemId id) {
         StringBuffer buf = new StringBuffer();
+        if (date != null) {
+            buf.append(date);
+            buf.append(' ');
+        }
+        buf.append('[');
         buf.append(op);
-        buf.append("    ");
+        buf.append("] [");
         if (userId != null) {
             buf.append(userId);
             buf.append('@');
         }
         buf.append(workspace != null ? workspace : "version");
-        buf.append(":(");
-        buf.append(id);
-        buf.append(")");
+        buf.append(':');
+        if (showId) {
+            buf.append('(');
+            buf.append(id);
+            buf.append(')');
+        }
         buf.append(lookupPath(id));
+        buf.append("]");
         log(buf.toString());
     }
 
@@ -189,8 +233,10 @@ public class JournalWalker implements Re
 	    return;
         }
 
-        log("Updated to revision " + recordRevision + ".");
-        log("");
+        if (showAll) {
+            log("Updated to revision " + recordRevision + ".");
+            log("");
+        }
     }
 
     /**
@@ -214,6 +260,7 @@ public class JournalWalker implements Re
      */
     public void process(ChangeLogRecord record) {
         String userId = null;
+        String date = df.format(new Date(record.getTimestamp()));
 
         Iterator<EventState> iter = record.getEvents().iterator();
         while (iter.hasNext()) {
@@ -229,13 +276,25 @@ public class JournalWalker implements Re
 
         ChangeLog changes = record.getChanges();
         for (ItemState state : changes.deletedStates()) {
-            log('D', userId, record.getWorkspace(), state.getId());
+            ItemId id = state.getId();
+            if (id instanceof PropertyId && !showProperties) {
+                continue;
+            }
+            log(date, 'D', userId, record.getWorkspace(), state.getId());
         }
         for (ItemState state : changes.modifiedStates()) {
-            log('U', userId, record.getWorkspace(), state.getId());
+            ItemId id = state.getId();
+            if (id instanceof PropertyId && !showProperties) {
+                continue;
+            }
+            log(date, 'U', userId, record.getWorkspace(), state.getId());
         }
         for (ItemState state : changes.addedStates()) {
-            log('A', userId, record.getWorkspace(), state.getId());
+            ItemId id = state.getId();
+            if (id instanceof PropertyId && !showProperties) {
+                continue;
+            }
+            log(date, 'A', userId, record.getWorkspace(), state.getId());
         }
     }
 
@@ -243,31 +302,35 @@ public class JournalWalker implements Re
      * {@inheritDoc}
      */
     public void process(LockRecord record) {
-        log(record.isLock() ? 'L' : 'l', record.getOwner(),
-                record.getWorkspace(), record.getNodeId());
+        if (showAll) {
+            log(null, record.isLock() ? 'L' : 'l', record.getOwner(),
+                    record.getWorkspace(), record.getNodeId());
+        }
     }
 
     /**
      * {@inheritDoc}
      */
     public void process(NamespaceRecord record) {
-        String oldPrefix = record.getOldPrefix();
-        String newPrefix = record.getNewPrefix();
-        String uri = record.getUri();
+        if (showAll) {
+            String oldPrefix = record.getOldPrefix();
+            String newPrefix = record.getNewPrefix();
+            String uri = record.getUri();
 
-        if (oldPrefix != null) {
-            namespaces.remove(oldPrefix);
-        }
-        if (newPrefix != null) {
-            namespaces.put(newPrefix, uri);
-        }
+            if (oldPrefix != null) {
+                namespaces.remove(oldPrefix);
+            }
+            if (newPrefix != null) {
+                namespaces.put(newPrefix, uri);
+            }
 
-        StringBuffer buf = new StringBuffer();
-        buf.append("S    ");
-        buf.append(newPrefix);
-        buf.append("=");
-        buf.append(uri);
-        log(buf.toString());
+            StringBuffer buf = new StringBuffer();
+            buf.append("S    ");
+            buf.append(newPrefix);
+            buf.append("=");
+            buf.append(uri);
+            log(buf.toString());
+        }
     }
 
     /**
@@ -275,30 +338,32 @@ public class JournalWalker implements Re
      */
     @SuppressWarnings({"rawtypes"})
     public void process(NodeTypeRecord record) {
-        Iterator iter;
+        if (showAll) {
+            Iterator iter;
 
-        switch (record.getOperation()) {
-        case NodeTypeRecord.REGISTER:
-        case NodeTypeRecord.REREGISTER:
-            iter = record.getCollection().iterator();
-            while (iter.hasNext()) {
-                QNodeTypeDefinition ntd = (QNodeTypeDefinition) iter.next();
-                StringBuffer buf = new StringBuffer();
-                buf.append("R    ");
-                buf.append(nameToString(ntd.getName()));
-                log(buf.toString());
-            }
-            break;
-        case NodeTypeRecord.UNREGISTER:
-            iter = record.getCollection().iterator();
-            while (iter.hasNext()) {
-                Name name = (Name) iter.next();
-                StringBuffer buf = new StringBuffer();
-                buf.append("r    ");
-                buf.append(nameToString(name));
-                log(buf.toString());
+            switch (record.getOperation()) {
+            case NodeTypeRecord.REGISTER:
+            case NodeTypeRecord.REREGISTER:
+                iter = record.getCollection().iterator();
+                while (iter.hasNext()) {
+                    QNodeTypeDefinition ntd = (QNodeTypeDefinition) iter.next();
+                    StringBuffer buf = new StringBuffer();
+                    buf.append("R    ");
+                    buf.append(nameToString(ntd.getName()));
+                    log(buf.toString());
+                }
+                break;
+            case NodeTypeRecord.UNREGISTER:
+                iter = record.getCollection().iterator();
+                while (iter.hasNext()) {
+                    Name name = (Name) iter.next();
+                    StringBuffer buf = new StringBuffer();
+                    buf.append("r    ");
+                    buf.append(nameToString(name));
+                    log(buf.toString());
+                }
+                break;
             }
-            break;
         }
     }
 
@@ -433,7 +498,7 @@ public class JournalWalker implements Re
      * @param args program arguments
      */
     public static void main(String[] args) throws Exception {
-        boolean noMoreArgs = false;
+        boolean noMoreArgs = false, showAll = false, showProperties = false, showId = false;
         long revision = 0;
 
         int argc = 0;
@@ -449,6 +514,15 @@ public class JournalWalker implements Re
                 return;
             }
             switch (arg.charAt(1)) {
+            case 'a':
+                showAll = true;
+                break;
+            case 'i':
+                showId = true;
+                break;
+            case 'p':
+                showProperties = true;
+                break;
             case 'r':
                 if (argc == args.length) {
                     System.err.println("Option -r requires argument.");
@@ -467,7 +541,7 @@ public class JournalWalker implements Re
             }
         }
         if (argc == args.length) {
-            System.err.println("args: [ -r revision ] directory | files");
+            System.err.println("args: [ -a | -i | -p | -r revision] directory | files");
             System.exit(1);
             return;
         }
@@ -480,6 +554,9 @@ public class JournalWalker implements Re
                 journal.setDirectory(args[argc - 1]);
 
                 JournalWalker walker = new JournalWalker(DEFAULT_PRODUCER, revision);
+                walker.setShowAll(showAll);
+                walker.setShowProperties(showProperties);
+                walker.setShowId(showId);
                 journal.init("", walker);
                 journal.register(walker);
                 journal.sync();
@@ -489,6 +566,9 @@ public class JournalWalker implements Re
                     continue;
                 }
                 JournalWalker walker = new JournalWalker(recordLog, f, revision);
+                walker.setShowAll(showAll);
+                walker.setShowProperties(showProperties);
+                walker.setShowId(showId);
                 walker.walk();
             }
         }