This wiki does not contain official documentation and is currently deprecated and read only. Please try reading the documentation on the Liferay Developer Network, the new site dedicated to Liferay documentation. DISCOVER Build your web site, collaborate with your colleagues, manage your content, and more. DEVELOP Build applications that run inside Liferay, extend the features provided out of the box with Liferay's APIs. DISTRIBUTE Let the world know about your app by publishing it in Liferay's marketplace. PARTICIPATE Become a part of Liferay's community, meet other Liferay users, and get involved in the open source project. Blogs Atom Collection
Table of Contents [-]
List blogs #
Blogs collection is located here: http://localhost:8080/tunnel-web/secure/atom/blogs. There are 3 different collection views:
- Group blog entries, if request parameter 'groupId' is provided. This collection is most advanced, since it supports pagination, using 'page' and 'max' request parameters.
- Organization blog entries, when 'organizationId' is provided. Only 'max' entries are shown.
- Company blog entries, default or when 'companyId' parameter is specified. Only 'max' entries are shown.
Here is an example XML with pagination enabled (http://localhost:8080/tunnel-web/secure/atom/blogs?groupId=10175&page=1).
As expected, this XML can be viewed in any Atom feed reader (e.g. Firefox):
Create new blog entry #
Blogs collection can be manipulated using AtomPub protocol. We can use Abdera on client side as well to build atom xml, that can be posted with HTTPCommons. Here is a code snipped that POST new blog entry to the collection:
Abdera abdera = new Abdera();
Factory factory = abdera.getFactory();
Entry entry = factory.newEntry();
entry.setId(FOMHelper.generateUuid());
entry.setUpdated(new java.util.Date());
entry.addAuthor("James");
entry.setTitle("Posting to Liferay Blogs");
entry.setSummary("This is a summary");
entry.setContentAsHtml("<p>This is an <b>example</b> post.</p>");
AbderaClient client = new AbderaClient(abdera);
RequestOptions options = createRequestOptions(client);
BaseRequestEntity requestEntity = new BaseRequestEntity(entry, false);
Response response = client.post(URL + "?groupId=10175", requestEntity, options);
Method createRequestOptions() just prepares auth data, something like this:
private static RequestOptions createRequestOptions(AbderaClient client) {
String encodedCredential = Base64.encode("test@liferay.com:test".getBytes());
RequestOptions options = client.getDefaultRequestOptions();
options.setHeader("Authorization", "Basic " + encodedCredential);
return options;
}
This will result with new blog post in your portals blog.
Update blog entry #
Updating is similar as adding, just different HTTP method is used: PUT. Here is code snippet that updates existing blog entry:
Abdera abdera = new Abdera();
Entry entry = abdera.newEntry();
entry.setId("tag:liferay.com:blogs:entry:16503");
entry.setUpdated(new java.util.Date());
entry.addAuthor("Thomas Man");
entry.setTitle("Updated title");
entry.setSummary("Updated summary");
entry.setContentAsHtml("<p>This is an <b>UPDATE</b>!!!</p>");
AbderaClient client = new AbderaClient(abdera);
RequestOptions options = createRequestOptions(client);
BaseRequestEntity requestEntity = new BaseRequestEntity(entry, false);
Response response = client.put(URL + "/16503?companyId=10146", requestEntity, options);
One note: when updating a blog entry (actually, any portals entry available through atom), it is necessary to specify the entry ID.
Delete #
And finally, deleting blogs entry through AtomPub is trivial: it's all about sending DELETE request to entry URL:
Abdera abdera = new Abdera(); AbderaClient client = new AbderaClient(abdera); RequestOptions options = createRequestOptions(client); Response response = client.delete(URL + "/11512?companyId=10146", options);