Manfred J Lenz commented on Nov 12, 2012

Getting the status messages of a list of people using Adbera Client

//Some helpfull snippets

private Feed postGetMessagesFeed() {

Abdera abdera = new Abdera();

AbderaClient client = new AbderaClient(abdera);

// add credentials

client.addCredentials("https://myConnectionsserver", null, null, new UsernamePasswordCredentials(user, password));

//search messages of mailuser1.mydomain.com and mailuser1.mydomain.com

StringRequestEntity stringreq =

new StringRequestEntity("email=mailuser1.mydomain.com&email=mailuser1.mydomain.com",

"application/x-www-form-urlencoded", "utf-8");

RequestOptions options = client.getDefaultRequestOptions();

options.setContentType("application/x-www-form-urlencoded");

// URL: https://myConnectionsserver@mydomain.com/profiles/atom/mv/theboard/entries/all.do

response = client.post("https://myConnectionsserver@mydomain.com/profiles/atom/mv/theboard/entries/all.do",

stringreq, options);

if (response.getType() == ResponseType.SUCCESS) {

if (response.getStatus() == 200) {

Document feed_doc = response.getDocument();

//return the feed object

return feed = feed_doc.getRoot();

} else {

return null;

}

} catch (Exception e) {

//Logging

return null;

}

}

// Use adbera methods to get the feed info

public final String LN_CONTRIBUTOR = "contributor";

public final String LN_NAME = "name";

public final String LN_EMAIL = "email";

public final String SNX_USERID = "userid";

public final String SNX_NS = "http://www.ibm.com/xmlns/prod/sn";

public final String SNX_PREFIX = "snx";

public final QName CONTRIBUTOR = new QName(org.apache.abdera.util.Constants.ATOM_NS, LN_CONTRIBUTOR);

public final QName NAME = new QName(org.apache.abdera.util.Constants.ATOM_NS, LN_NAME);

public final QName EMAIL = new QName(org.apache.abdera.util.Constants.ATOM_NS, LN_EMAIL);

public final QName USERID = new QName(SNX_NS, SNX_USERID, SNX_PREFIX);

// Save the entries in a List of message objects... MessageObject is a simple class with

// definitions of variables and getters and setters

ConnectionsList messages = new ConnectionsList();

public void getMessages(Feed feed) {

try {

List entries = feed.getEntries();

for (Entry entry : entries) {

MessagesObject message = new MessagesObject(entry.getTitle());

message.setId(entry.getId());

// get Author inof

Person author = entry.getAuthor();

if (author != null) {

message.setAuthorMail(author.getEmail());

message.setAuthorName(author.getName());

message.setAuthorUserId(author.getSimpleExtension(USERID));

}

// get Contributor info

Element contributor = entry.getFirstChild(CONTRIBUTOR);

if (contributor != null) {

Element nameElement = contributor.getFirstChild(NAME);

message.setContributorName(nameElement.getText());

Element mailElement = contributor.getFirstChild(EMAIL);

message.setContributorMail(mailElement.getText());

Element userIdElement = contributor.getFirstChild(USERID);

message.setContributorUserId(userIdElement.getText());

}

// get Categories, all categories are saved in a sting with "," as delimiter

String categoriesStr ="";

List categories =entry.getCategories();

for (Category category : categories) {

categoriesStr = categoriesStr.concat(category.getTerm() + ",");

}

message.setCategory(categoriesStr);

// getContent

message setContent(entry.getContent());

// get Summary

message setSummary(entry.getSummary());

messages.add(message);

}

} catch (Exception e) {

/Logging

return null;

}

}