aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2013-01-06 14:33:40 +0100
committerTrygve Laugstøl <trygvis@inamo.no>2013-01-06 14:33:40 +0100
commit7663c88dba4da60afde4691fc925e2f4cf6e3c4b (patch)
tree0cc5625b3b837cd7f8e4c52acf016de80c41225e /src/main/java
parent37207267bf3a1149f78a5022ed8e016cac6b85ca (diff)
downloadesper-testing-7663c88dba4da60afde4691fc925e2f4cf6e3c4b.tar.gz
esper-testing-7663c88dba4da60afde4691fc925e2f4cf6e3c4b.tar.bz2
esper-testing-7663c88dba4da60afde4691fc925e2f4cf6e3c4b.tar.xz
esper-testing-7663c88dba4da60afde4691fc925e2f4cf6e3c4b.zip
o Much better person list.
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/io/trygvis/esper/testing/util/Gravatar.java28
-rwxr-xr-xsrc/main/java/io/trygvis/esper/testing/web/resource/CoreResource.java2
-rwxr-xr-xsrc/main/java/io/trygvis/esper/testing/web/resource/PersonJson.java9
3 files changed, 37 insertions, 2 deletions
diff --git a/src/main/java/io/trygvis/esper/testing/util/Gravatar.java b/src/main/java/io/trygvis/esper/testing/util/Gravatar.java
new file mode 100644
index 0000000..c98662d
--- /dev/null
+++ b/src/main/java/io/trygvis/esper/testing/util/Gravatar.java
@@ -0,0 +1,28 @@
+package io.trygvis.esper.testing.util;
+
+import java.io.*;
+import java.security.*;
+
+public class Gravatar {
+ public static String hex(byte[] array) {
+ StringBuilder sb = new StringBuilder();
+ for (byte anArray : array) {
+ sb.append(Integer.toHexString((anArray & 0xFF) | 0x100).substring(1, 3));
+ }
+ return sb.toString();
+ }
+
+ public static String md5Hex(String message) {
+ try {
+ MessageDigest md = MessageDigest.getInstance("MD5");
+ return hex(md.digest(message.getBytes("CP1252")));
+ } catch (NoSuchAlgorithmException e) {
+ } catch (UnsupportedEncodingException e) {
+ }
+ return null;
+ }
+
+ public static String gravatar(String mail) {
+ return "http://www.gravatar.com/avatar/" + md5Hex(mail.trim().toLowerCase());
+ }
+}
diff --git a/src/main/java/io/trygvis/esper/testing/web/resource/CoreResource.java b/src/main/java/io/trygvis/esper/testing/web/resource/CoreResource.java
index 4ab95c6..22290d9 100755
--- a/src/main/java/io/trygvis/esper/testing/web/resource/CoreResource.java
+++ b/src/main/java/io/trygvis/esper/testing/web/resource/CoreResource.java
@@ -148,7 +148,7 @@ public class CoreResource extends AbstractResource {
protected final SqlF<PersonDto, PersonJson> getPersonJson = new SqlF<PersonDto, PersonJson>() {
public PersonJson apply(PersonDto person) throws SQLException {
- return new PersonJson(person.uuid, person.name);
+ return new PersonJson(person.uuid, person.name, person.mail);
}
};
diff --git a/src/main/java/io/trygvis/esper/testing/web/resource/PersonJson.java b/src/main/java/io/trygvis/esper/testing/web/resource/PersonJson.java
index 65b081c..285ae8e 100755
--- a/src/main/java/io/trygvis/esper/testing/web/resource/PersonJson.java
+++ b/src/main/java/io/trygvis/esper/testing/web/resource/PersonJson.java
@@ -4,13 +4,20 @@ import io.trygvis.esper.testing.*;
import java.util.*;
+import static io.trygvis.esper.testing.util.Gravatar.*;
+
public class PersonJson {
public final Uuid uuid;
public final String name;
+ public final String mail;
+ public final String gravatar;
- public PersonJson(Uuid uuid, String name) {
+ public PersonJson(Uuid uuid, String name, String mail) {
this.uuid = uuid;
this.name = name;
+ this.mail = mail;
+
+ gravatar = gravatar(mail);
}
}