jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1163409 - in /jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src: main/java/org/apache/jackrabbit/spi2microkernel/ main/java/org/apache/jackrabbit/spi2microkernel/util/ test/java/org/apache/jackrabbit/spi2microkernel/
Date Tue, 30 Aug 2011 21:38:49 GMT
Author: mduerig
Date: Tue Aug 30 21:38:49 2011
New Revision: 1163409

URL: http://svn.apache.org/viewvc?rev=1163409&view=rev
Log:
Microkernel based Jackrabbit prototype (WIP)
set correct userId for observation events (cleanup)

Added:
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/CommitMessage.java
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Text.java
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/CommitMessageTest.java
Modified:
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/SubscriptionImpl.java

Added: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/CommitMessage.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/CommitMessage.java?rev=1163409&view=auto
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/CommitMessage.java
(added)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/CommitMessage.java
Tue Aug 30 21:38:49 2011
@@ -0,0 +1,78 @@
+package org.apache.jackrabbit.spi2microkernel;
+
+import org.apache.jackrabbit.spi2microkernel.util.Text;
+
+public class CommitMessage {
+    private final String userId;
+    private final String userData;
+
+    private static final char ESCAPE_CHAR = '\\';
+    private static final char SEPARATOR_CHAR = ':';
+
+    public static CommitMessage parse(String s) {
+        int k = s.indexOf(SEPARATOR_CHAR);
+        while (k > 0 && s.charAt(k - 1) == ESCAPE_CHAR) {
+            k = s.indexOf(SEPARATOR_CHAR, k + 1);
+        }
+
+        if (k == -1) {
+            throw new IllegalArgumentException(s);
+        }
+
+        return new CommitMessage(unescape(s.substring(0, k)), unescape(s.substring(k + 1,
s.length())));
+    }
+
+    public CommitMessage(String userId, String userData) {
+        if (userId == null) {
+            throw new IllegalArgumentException("UserId is null");
+        }
+        if (userData == null) {
+            throw new IllegalArgumentException("UserData is null");
+        }
+
+        this.userId = userId;
+        this.userData = userData;
+    }
+
+    public String getUserId() {
+        return userId;
+    }
+
+    public String getUserData() {
+        return userData;
+    }
+
+    public String encode() {
+        return escape(userId) + SEPARATOR_CHAR + escape(userData);
+    }
+
+    @Override
+    public int hashCode() {
+        return 37 * (37 * 17 + userId.hashCode()) + userData.hashCode();
+    }
+
+    @Override
+    public boolean equals(Object other) {
+        return other == this || other instanceof CommitMessage && ((CommitMessage)
other).equals(this);
+    }
+
+    @Override
+    public String toString() {
+        return encode();
+    }
+
+    //------------------------------------------< private >---
+
+    protected boolean equals(CommitMessage other) {
+        return other.userId.equals(userId) && other.userData.equals(userData);
+    }
+
+    private static String escape(String s) {
+        return Text.escape(s, SEPARATOR_CHAR, ESCAPE_CHAR);
+    }
+
+    private static String unescape(String s) {
+        return Text.unescape(s, ESCAPE_CHAR);
+    }
+        
+}

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java?rev=1163409&r1=1163408&r2=1163409&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java
(original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java
Tue Aug 30 21:38:49 2011
@@ -821,7 +821,8 @@ public class RepositoryServiceImpl exten
                     String rev = microKernel.getHeadRevision();
                     String userId = sessionInfo.getUserID();
                     String userData = ((SessionInfoImpl) sessionInfo).getUserData();
-                    return microKernel.commit("/", jsop.toString(), rev, userId + ":" + userData);
// fixme encode properly
+                    CommitMessage commitMessage = new CommitMessage(userId, userData == null
? "" : userData);
+                    return microKernel.commit("/", jsop.toString(), rev, commitMessage.encode());
                 }
             });
         }

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/SubscriptionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/SubscriptionImpl.java?rev=1163409&r1=1163408&r2=1163409&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/SubscriptionImpl.java
(original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/SubscriptionImpl.java
Tue Aug 30 21:38:49 2011
@@ -293,8 +293,7 @@ public class SubscriptionImpl implements
         private EventBundle createEventBundle(JSONObject jsonObject) throws RepositoryException
{
             String revisionId = getString(jsonObject, "id", false);
             String msg = getString(jsonObject, "msg", true);
-            String userId = msg.substring(0, msg.indexOf(":"));   // fixme decode properly
-            String userData = msg.substring(msg.indexOf(":") + 1);  // fixme decode properly
+            CommitMessage commitMessage = CommitMessage.parse(msg);
             long timeStamp = getLong(jsonObject, "ts");
             String changes = getString(jsonObject, "changes", false);
             log.debug("Creating event bundle from changes in revision " + revisionId + "
at " + timeStamp);
@@ -302,8 +301,8 @@ public class SubscriptionImpl implements
 
             EventTemplate eventTemplate = new EventTemplate()
                     .setTimestamp(timeStamp)
-                    .setUserId(userId)
-                    .setUserData(userData);
+                    .setUserId(commitMessage.getUserId())
+                    .setUserData(commitMessage.getUserData());
 
             Collection<Event> events = getEvents(changes, eventTemplate);
 

Added: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Text.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Text.java?rev=1163409&view=auto
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Text.java
(added)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Text.java
Tue Aug 30 21:38:49 2011
@@ -0,0 +1,46 @@
+package org.apache.jackrabbit.spi2microkernel.util;
+
+public final class Text {
+    private Text() {}
+
+    public static String escape(String s, char target, char escape) {
+        if (s == null) {
+            return null;
+        }
+
+        StringBuilder sb = new StringBuilder();
+        for (int k = 0; k < s.length(); k++) {
+            char c = s.charAt(k);
+            if (c == target || c == escape) {
+                sb.append(escape);
+            }
+            sb.append(c);
+        }
+
+        return sb.toString();
+    }
+
+    public static String unescape(String s, char escape) {
+        if (s == null) {
+            return null;
+        }
+
+        boolean escaping = false;
+        StringBuilder sb = new StringBuilder();
+        for (int k = 0; k < s.length(); k++) {
+            char c = s.charAt(k);
+            if (escaping) {
+                sb.append(c);
+                escaping = false;
+            }
+            else if (c == escape) {
+                escaping = true;
+            }
+            else {
+                sb.append(c);
+            }
+        }
+
+        return sb.toString();
+    }
+}

Added: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/CommitMessageTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/CommitMessageTest.java?rev=1163409&view=auto
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/CommitMessageTest.java
(added)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/CommitMessageTest.java
Tue Aug 30 21:38:49 2011
@@ -0,0 +1,48 @@
+package org.apache.jackrabbit.spi2microkernel;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class CommitMessageTest {
+
+    @Test
+    public void testEncode() {
+        CommitMessage msg = new CommitMessage("user", "data");
+        assertEquals("user", msg.getUserId());
+        assertEquals("data", msg.getUserData());
+        assertEquals("user:data", msg.encode());
+        assertEquals(msg, CommitMessage.parse(msg.encode()));
+
+        msg = new CommitMessage("us:er", "data");
+        assertEquals("us:er", msg.getUserId());
+        assertEquals("data", msg.getUserData());
+        assertEquals("us\\:er:data", msg.encode());
+        assertEquals(msg, CommitMessage.parse(msg.encode()));
+
+        msg = new CommitMessage("", "data");
+        assertEquals("", msg.getUserId());
+        assertEquals("data", msg.getUserData());
+        assertEquals(":data", msg.encode());
+        assertEquals(msg, CommitMessage.parse(msg.encode()));
+
+        msg = new CommitMessage("user", "");
+        assertEquals("user", msg.getUserId());
+        assertEquals("", msg.getUserData());
+        assertEquals("user:", msg.encode());
+        assertEquals(msg, CommitMessage.parse(msg.encode()));
+
+        msg = new CommitMessage("", "");
+        assertEquals("", msg.getUserId());
+        assertEquals("", msg.getUserData());
+        assertEquals(":", msg.encode());
+        assertEquals(msg, CommitMessage.parse(msg.encode()));
+
+        msg = new CommitMessage(":", ":");
+        assertEquals(":", msg.getUserId());
+        assertEquals(":", msg.getUserData());
+        assertEquals("\\::\\:", msg.encode());
+        assertEquals(msg, CommitMessage.parse(msg.encode()));
+
+    }
+}



Mime
View raw message