package com.theqsync.page;
import java.io.IOException;
import java.net.URL;
import javax.faces.component.UIForm;
import javax.servlet.http.HttpSession;
import com.google.gdata.client.contacts.ContactsService;
import com.google.gdata.data.contacts.ContactEntry;
import com.google.gdata.data.contacts.ContactFeed;
import com.google.gdata.data.contacts.GroupMembershipInfo;
import com.google.gdata.data.extensions.Email;
import com.google.gdata.data.extensions.ExtendedProperty;
import com.google.gdata.data.extensions.Im;
import com.google.gdata.util.ServiceException;
import com.theqsync.resource.util.AbstractPage;
import com.theqsync.resource.util.GoogleUtil;
public class GooglePage extends AbstractPage {
private static final long serialVersionUID = 1L;
public GooglePage() {
if (!isPostBack()) {
HttpSession session = getRequest().getSession(true);
String sessionKey = (String) session
.getAttribute(GoogleUtil.SESSION_KEY);
ContactsService service = new ContactsService(
GoogleUtil.SESSION_KEY);
try {
info(sessionKey);
service.setAuthSubToken(sessionKey);
URL feedUrl = null;
try {
feedUrl = new URL(
"https://www.google.com/m8/feeds/contacts/keklikhasan@gmail.com/full");
} catch (Exception e) {
error(e);
}
ContactFeed resultFeed = null;
try {
resultFeed = service.getFeed(feedUrl, ContactFeed.class);
} catch (IOException e) {
error(e);
} catch (ServiceException e) {
error(e);
}
info(resultFeed.getTitle().getPlainText());
for (int i = 0; i < resultFeed.getEntries().size(); i++) {
ContactEntry entry = resultFeed.getEntries().get(i);
info("\t" + entry.getTitle().getPlainText());
info("Email addresses:");
for (Email email : entry.getEmailAddresses()) {
info(" " + email.getAddress());
if (email.getRel() != null) {
info(" rel:" + email.getRel());
}
if (email.getLabel() != null) {
info(" label:" + email.getLabel());
}
}
info("IM addresses:");
for (Im im : entry.getImAddresses()) {
info(" " + im.getAddress());
if (im.getLabel() != null) {
info(" label:" + im.getLabel());
}
if (im.getLabel() != null) {
info(" rel:" + im.getLabel());
}
if (im.getProtocol() != null) {
System.out.print(" protocol:" + im.getProtocol());
}
}
info("Groups:");
for (GroupMembershipInfo group : entry
.getGroupMembershipInfos()) {
String groupHref = group.getHref();
info(" Id: " + groupHref);
}
info("Extended Properties:");
for (ExtendedProperty property : entry
.getExtendedProperties()) {
if (property.getValue() != null) {
info(" " + property.getName() + "(value) = "
+ property.getValue());
} else if (property.getXmlBlob() != null) {
info(" " + property.getName() + "(xmlBlob)= "
+ property.getXmlBlob().getBlob());
}
}
String photoLink = entry.getContactPhotoLink().getHref();
info("Photo Link: " + photoLink);
// if (photoLink.getEtag() != null) {
// System.out.println("Contact Photo's ETag: "
// + photoLink.getEtag());
// }
// System.out.println("Contact's ETag: " + entry.getEtag());
}
} catch (Exception e) {
error(e);
}
}
}
public UIForm form;
public UIForm getForm() {
return form;
}
public void setForm(UIForm form) {
this.form = form;
}
}