001 /****************************************************************
002 * Licensed to the Apache Software Foundation (ASF) under one *
003 * or more contributor license agreements. See the NOTICE file *
004 * distributed with this work for additional information *
005 * regarding copyright ownership. The ASF licenses this file *
006 * to you under the Apache License, Version 2.0 (the *
007 * "License"); you may not use this file except in compliance *
008 * with the License. You may obtain a copy of the License at *
009 * *
010 * http://www.apache.org/licenses/LICENSE-2.0 *
011 * *
012 * Unless required by applicable law or agreed to in writing, *
013 * software distributed under the License is distributed on an *
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
015 * KIND, either express or implied. See the License for the *
016 * specific language governing permissions and limitations *
017 * under the License. *
018 ****************************************************************/
019
020 package org.apache.hupa.shared.rpc;
021
022 import java.io.Serializable;
023
024 import net.customware.gwt.dispatch.shared.Result;
025
026 public class ContactsResult implements Result, Serializable {
027
028 public static class Contact implements Result, Serializable {
029 private static final long serialVersionUID = -8632580327693416473L;
030 public String mail;
031 public String realname;
032
033 public Contact() {
034 }
035
036 public Contact(String address) {
037 mail = address.replaceAll("^.*<([^>]+)>\\s*$", "$1");
038
039 realname = mail.equals(address) ? mail : address
040 // remove the email part
041 .replaceAll("<[^<>]+>\\s*$", "")
042 // remove start symbols in the name
043 .replaceAll("^[\\s\"'<]+", "")
044 // remove end symbols in the name
045 .replaceAll("[\\s\"'>]+$", "")
046 ;
047
048 if (realname.isEmpty())
049 realname = mail;
050 }
051
052 public Contact(String realname, String mail) {
053 this.realname = realname;
054 this.mail = mail;
055 }
056
057 public String toString() {
058 return (realname != null ? realname : "") + "<" + mail + ">";
059 }
060
061 public String toKey() {
062 return toString().replaceAll("[^\\w\\d<@>]+", "").toLowerCase();
063 }
064
065 }
066
067 private static final long serialVersionUID = -8740775403377441876L;
068 private Contact[] contacts;
069
070 public ContactsResult() {
071 }
072
073 public ContactsResult(Contact... contacts) {
074 this.contacts = contacts;
075 }
076
077 public Contact[] getContacts() {
078 return contacts;
079 }
080
081 public void setContacts(Contact[] contacts) {
082 this.contacts = contacts;
083 }
084
085 }