Revision: 1866
Author: [email protected]
Date: Thu Mar 11 06:22:53 2010
Log: Merged fix for issue 257 to release for new rc2, to obfuscate email addresses (merge from trunk rev.1864/1865)
http://code.google.com/p/simal/source/detail?r=1866

Added:
/branches/0.2.3/uk.ac.osswatch.simal.core/src/test/java/uk/ac/osswatch/simal/model/jena/TestInternetAddress.java
Modified:
 /branches/0.2.3/uk.ac.osswatch.simal.core/pom.xml
/branches/0.2.3/uk.ac.osswatch.simal.core/src/main/java/uk/ac/osswatch/simal/model/IInternetAddress.java /branches/0.2.3/uk.ac.osswatch.simal.core/src/main/java/uk/ac/osswatch/simal/model/jena/InternetAddress.java /branches/0.2.3/uk.ac.osswatch.simal.core/src/test/java/uk/ac/osswatch/simal/integrationTest/model/repository/BaseRepositoryTest.java
 /branches/0.2.3/uk.ac.osswatch.simal.rest/pom.xml
 /branches/0.2.3/uk.ac.osswatch.simal.web/pom.xml
/branches/0.2.3/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/markup/html/list/InternetAddressListView.java /branches/0.2.3/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/panel/PersonListPanel.java

=======================================
--- /dev/null
+++ /branches/0.2.3/uk.ac.osswatch.simal.core/src/test/java/uk/ac/osswatch/simal/model/jena/TestInternetAddress.java Thu Mar 11 06:22:53 2010
@@ -0,0 +1,87 @@
+/*
+ * Copyright 2010 University of Oxford
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package uk.ac.osswatch.simal.model.jena;
+
+import static junit.framework.Assert.*;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import uk.ac.osswatch.simal.SimalRepositoryFactory;
+import uk.ac.osswatch.simal.model.IInternetAddress;
+import uk.ac.osswatch.simal.model.IPerson;
+import uk.ac.osswatch.simal.model.ModelSupport;
+import uk.ac.osswatch.simal.rdf.ISimalRepository;
+import uk.ac.osswatch.simal.rdf.SimalRepositoryException;
+
+/**
+ * Test the class uk.ac.osswatch.simal.model.jena.InternetAddress, especially
+ * the method getObfuscatedAddress()
+ */
+public class TestInternetAddress {
+
+  protected static ISimalRepository repository;
+
+ private static final String TEST_OSS_WATCH_DOAP = "testData/ossWatchDOAP.xml";
+
+ private static final String TEST_DEVELOPER_SEE_ALSO = "http://people.apache.org/~rgardler/foaf.rdf.xml";;
+
+ private static final Map<String, String> EXPECTED_OBFUSCATED_EMAILS = new HashMap<String, String>();
+
+  @BeforeClass
+  public static void setUpBeforeClass() throws Exception {
+    repository = SimalRepositoryFactory
+        .getInstance(SimalRepositoryFactory.JENA);
+    if (!repository.isInitialised()) {
+      repository.initialise(null);
+    }
+
+ repository.addProject(ISimalRepository.class.getClassLoader().getResource(
+        TEST_OSS_WATCH_DOAP), ModelSupport.TEST_FILE_BASE_URL);
+    EXPECTED_OBFUSCATED_EMAILS.put("mailto:[email protected]";,
+        "mailto:rgardler [at] apache...org");
+    EXPECTED_OBFUSCATED_EMAILS.put("mailto:[email protected]";,
+        "mailto:ross.gardler [at] oucs...ox...ac...uk");
+  }
+
+  @Test
+  public void testInternetAddress() {
+    try {
+      IPerson developer = SimalRepositoryFactory.getPersonService()
+          .findBySeeAlso(TEST_DEVELOPER_SEE_ALSO);
+      if (developer != null) {
+        Set<IInternetAddress> allEmailAddresses = developer.getEmail();
+        for (IInternetAddress testAddress : allEmailAddresses) {
+          assertEquals("Obfuscated addresses don't match.",
+              EXPECTED_OBFUSCATED_EMAILS.get(testAddress.getAddress()),
+              testAddress.getObfuscatedAddress());
+        }
+      } else {
+        fail("Could not find right developer using seeAlso "
+            + TEST_DEVELOPER_SEE_ALSO);
+      }
+    } catch (SimalRepositoryException e) {
+      fail("Could not retreive test developer: " + e.getMessage());
+    }
+  }
+}
=======================================
--- /branches/0.2.3/uk.ac.osswatch.simal.core/pom.xml Thu Feb 18 06:13:21 2010 +++ /branches/0.2.3/uk.ac.osswatch.simal.core/pom.xml Thu Mar 11 06:22:53 2010
@@ -26,7 +26,7 @@

   <groupId>uk.ac.osswatch</groupId>
   <artifactId>simal-core</artifactId>
-  <version>0.2.3-rc1</version>
+  <version>0.2.3-rc2</version>
   <packaging>jar</packaging>

   <name>Simal core</name>
=======================================
--- /branches/0.2.3/uk.ac.osswatch.simal.core/src/main/java/uk/ac/osswatch/simal/model/IInternetAddress.java Tue Nov 24 16:08:08 2009 +++ /branches/0.2.3/uk.ac.osswatch.simal.core/src/main/java/uk/ac/osswatch/simal/model/IInternetAddress.java Thu Mar 11 06:22:53 2010
@@ -29,4 +29,11 @@
    */
   public String getAddress();

-}
+  /**
+   * Get the complete email address in a way that is not.
+   * directly machine-readable.
+   * @return
+   */
+  public String getObfuscatedAddress();
+
+}
=======================================
--- /branches/0.2.3/uk.ac.osswatch.simal.core/src/main/java/uk/ac/osswatch/simal/model/jena/InternetAddress.java Thu Sep 18 14:53:18 2008 +++ /branches/0.2.3/uk.ac.osswatch.simal.core/src/main/java/uk/ac/osswatch/simal/model/jena/InternetAddress.java Thu Mar 11 06:22:53 2010
@@ -30,6 +30,24 @@
   public InternetAddress(com.hp.hpl.jena.rdf.model.Resource resource) {
     super(resource);
   }
+
+  public String getObfuscatedAddress() {
+    String address = getURI();
+    if (address != null) {
+      int atPosition = address.indexOf("@");
+      if (atPosition > -1) {
+        StringBuffer obfuscatedAddress = new StringBuffer();
+
+        obfuscatedAddress.append(address.substring(0, atPosition));
+        obfuscatedAddress.append(" [at] ");
+ obfuscatedAddress.append(address.substring(atPosition + 1).replaceAll(
+            "[.]", "..."));
+        address = obfuscatedAddress.toString();
+      }
+    }
+
+    return address;
+  }

   public String getAddress() {
     return getURI();
=======================================
--- /branches/0.2.3/uk.ac.osswatch.simal.core/src/test/java/uk/ac/osswatch/simal/integrationTest/model/repository/BaseRepositoryTest.java Sun Jul 12 11:57:46 2009 +++ /branches/0.2.3/uk.ac.osswatch.simal.core/src/test/java/uk/ac/osswatch/simal/integrationTest/model/repository/BaseRepositoryTest.java Thu Mar 11 06:22:53 2010
@@ -132,7 +132,7 @@
project1 = SimalRepositoryFactory.getProjectService().findProjectBySeeAlso(TEST_PROJECT_URI); IPerson developer = SimalRepositoryFactory.getPersonService().findBySeeAlso("http://foo.org/~developer/#me";);
     testDeveloperID = developer.getUniqueSimalID();
-    testDeveloperEMail = developer.getEmail().toArray()[0].toString();
+ testDeveloperEMail = developer.getEmail().iterator().next().getAddress();

IPerson documentor = SimalRepositoryFactory.getPersonService().findBySeeAlso("http://foo.org/~documentor/#me";);
     String documentorID = documentor.getUniqueSimalID();
=======================================
--- /branches/0.2.3/uk.ac.osswatch.simal.rest/pom.xml Thu Feb 18 06:13:21 2010 +++ /branches/0.2.3/uk.ac.osswatch.simal.rest/pom.xml Thu Mar 11 06:22:53 2010
@@ -5,7 +5,7 @@
   <groupId>uk.ac.osswatch</groupId>
   <artifactId>simal-rest</artifactId>
   <packaging>jar</packaging>
-  <version>0.2.3-rc1</version>
+  <version>0.2.3-rc2</version>
   <name>Simal Rest API</name>
   <url>http://simal.oss-watch.ac.uk/rest</url>

@@ -89,7 +89,7 @@
     <dependency>
       <groupId>uk.ac.osswatch</groupId>
       <artifactId>simal-core</artifactId>
-      <version>0.2.3-rc1</version>
+      <version>0.2.3-rc2</version>
     </dependency>

     <dependency>
=======================================
--- /branches/0.2.3/uk.ac.osswatch.simal.web/pom.xml Thu Feb 18 06:13:21 2010 +++ /branches/0.2.3/uk.ac.osswatch.simal.web/pom.xml Thu Mar 11 06:22:53 2010
@@ -6,7 +6,7 @@
   <groupId>uk.ac.osswatch</groupId>
   <artifactId>simal-webapp</artifactId>
   <packaging>war</packaging>
-  <version>0.2.3-rc1</version>
+  <version>0.2.3-rc2</version>
   <name>Simal Web Application</name>
   <url>http://simal.oss-watch.ac.uk/web</url>
   <description>
@@ -114,13 +114,13 @@
     <dependency>
       <groupId>uk.ac.osswatch</groupId>
       <artifactId>simal-core</artifactId>
-      <version>0.2.3-rc1</version>
+      <version>0.2.3-rc2</version>
     </dependency>

     <dependency>
       <groupId>uk.ac.osswatch</groupId>
       <artifactId>simal-rest</artifactId>
-      <version>0.2.3-rc1</version>
+      <version>0.2.3-rc2</version>
     </dependency>

     <dependency>
=======================================
--- /branches/0.2.3/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/markup/html/list/InternetAddressListView.java Thu May 21 13:47:54 2009 +++ /branches/0.2.3/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/markup/html/list/InternetAddressListView.java Thu Mar 11 06:22:53 2010
@@ -58,8 +58,8 @@
    */
   protected void populateItem(ListItem<IInternetAddress> listItem) {
final IInternetAddress addr = (IInternetAddress) listItem.getModelObject(); - ExternalLink externalLink = new ExternalLink("linkURL", addr.getAddress());
-    String href = addr.getLabel();
+ ExternalLink externalLink = new ExternalLink("linkURL", addr.getObfuscatedAddress());
+    String href = addr.getObfuscatedAddress();
     if (href.startsWith("mailto")) {
        href = href.substring(7);
     }
=======================================
--- /branches/0.2.3/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/panel/PersonListPanel.java Thu Feb 18 03:50:36 2010 +++ /branches/0.2.3/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/panel/PersonListPanel.java Thu Mar 11 06:22:53 2010
@@ -28,7 +28,6 @@
 import org.apache.wicket.markup.html.basic.Label;
 import org.apache.wicket.markup.html.form.Form;
 import org.apache.wicket.markup.html.form.TextField;
-import org.apache.wicket.markup.html.link.ExternalLink;
 import org.apache.wicket.markup.html.panel.Panel;
 import org.apache.wicket.markup.repeater.Item;
 import org.apache.wicket.model.CompoundPropertyModel;
@@ -128,36 +127,36 @@
   @SuppressWarnings("unchecked")
 private void addPersonList(Set<IPerson> people, int numberOfPeople) {
     List<AbstractColumn> columns = new ArrayList<AbstractColumn>();
- columns.add(new NameLinkPropertyColumn(new Model("Name"), "label", "label"));
-
-    columns.add(new PropertyColumn(new Model("EMail"), "email", "email") {
-               private static final long serialVersionUID = 1L;
-
-               @Override
- public void populateItem(Item cellItem, String componentId, IModel model) { - Iterator<IInternetAddress> emails = ((IPerson)model.getObject()).getEmail().iterator();
-               if (emails.hasNext()) {
-                       while (emails.hasNext()) {
-                               IInternetAddress email = emails.next();
-                               String label = email.getLabel();
-                               if (label.startsWith("mailto:";)) {
-                                       label = label.substring(7);
-                               }
-                       ExternalLink link = new ExternalLink(componentId,
-                         email.getAddress(),
-                         label);
-
-                       cellItem.add(link);
-                       break;
-                       }
-               } else {
-                       cellItem.add(new Label(componentId, ""));
-               }
-               }
-    });
-
- columns.add(new ProjectsPropertyColumn(new Model("Project"), "projects", "projects"));
-
+    columns
+ .add(new NameLinkPropertyColumn(new Model("Name"), "label", "label"));
+
+    columns.add(new PropertyColumn(new Model("Email"), "email",
+        "email") {
+      private static final long serialVersionUID = 1L;
+
+      @Override
+ public void populateItem(Item cellItem, String componentId, IModel model) {
+        Iterator<IInternetAddress> emails = ((IPerson) model.getObject())
+            .getEmail().iterator();
+        if (emails.hasNext()) {
+          while (emails.hasNext()) {
+            IInternetAddress email = emails.next();
+            String label = email.getObfuscatedAddress();
+            if (label.startsWith("mailto:";)) {
+              label = label.substring(7);
+            }
+            cellItem.add(new Label(componentId, label));
+            break;
+          }
+        } else {
+          cellItem.add(new Label(componentId, ""));
+        }
+      }
+    });
+
+ columns.add(new ProjectsPropertyColumn(new Model("Project"), "projects",
+        "projects"));
+
     dataProvider = new SortablePersonDataProvider(people);
dataProvider.setSort(SortablePersonDataProvider.SORT_PROPERTY_LABEL, true); add(new AjaxFallbackDefaultDataTable("dataTable", columns, dataProvider, numberOfPeople));

--
You received this message because you are subscribed to the Google Groups "Simal 
Commits" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/simal-commits?hl=en.

Reply via email to