As of Alfresco Enterprise 3.2r, Web Script-based portlets have SSO support and can be deployed rather easily.
Read this tutorial to learn more about this new Alfresco portlet development option.
This portlet alleviates the need for having to deploy all of Alfresco inside the portal as is the case when using Alfresco's OOTB (out-of-the-box) Web script portlet. http://forge.rivetlogic.com/Forge/Rivets/Alfresco-Web-script-Portlet
The Apache Adbdera library may be used to parse the ATOM-formated CMIS responses but here's a sample of a portlet that uses a basic XML parser to do the same:
package training;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.Writer;
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.GenericPortlet;
import javax.portlet.PortletException;
import javax.portlet.PortletSecurityException;
import javax.portlet.PortletSession;
import javax.portlet.PortletURL;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
import javax.xml.parsers.DocumentBuilderFactory;
import org.apache.commons.httpclient.Credentials;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.UsernamePasswordCredentials;
import org.apache.commons.httpclient.auth.AuthScope;
import org.apache.commons.httpclient.methods.GetMethod;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
public class AlfrescoTrainingPortlet extends GenericPortlet {
@Override
protected void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException {
response.setContentType("text/html");
HttpClient client = new HttpClient();
client.getParams().setAuthenticationPreemptive(true);
Credentials defaultcreds = new UsernamePasswordCredentials("admin", "admin");
client.getState().setCredentials(AuthScope.ANY, defaultcreds);
String url;
String objectIdParam = (String) request.getPortletSession().getAttribute("objectId", PortletSession.PORTLET_SCOPE);
if (objectIdParam == null) {
url = "[http://localhost:8080/alfresco/s/api/path/workspace/SpacesStore/Company%20Home/children";]
} else {
url = "[http://localhost:8080/alfresco/s/api/node/workspace/SpacesStore/"] + objectIdParam + "/children";
}
GetMethod method = new GetMethod(url);
client.executeMethod(method);
PortletURL actionURL = response.createActionURL();
PrintWriter writer = response.getWriter();
try {
Document dom = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(method.getResponseBodyAsStream());
NodeList list = dom.getElementsByTagName("cmis:propertyId");
int len = list.getLength();
for (int i = 0; i < len; i++) {
Element element = (Element) list.item(i);
String propertyName = element.getAttribute("cmis:name");
String objectId = null;
if (propertyName.equals("ObjectId")) {
objectId = element.getElementsByTagName("cmis:value").item(0).getTextContent();
objectId = objectId.replaceAll("workspace://SpacesStore/", "");
writer.println("<p>" + objectId);
}
if (objectId == null) {
continue;
}
NodeList stringList = ((Element) element.getParentNode()).getElementsByTagName("cmis:propertyString");
int stringSize = stringList.getLength();
for (int j = 0; j < stringSize; j++) {
Element strElem = ((Element) stringList.item(j));
String strName = strElem.getAttribute("cmis:name");
if (strName.equals("Name")) {
actionURL.setParameter("objectId", objectId);
writer.println("<a href='" + actionURL.toString() + "'>" + strElem.getTextContent() + "</a>");
break;
}
}
}
} catch (Exception exc) {
exc.printStackTrace();
}
//response.getWriter().println(method.getResponseBodyAsString());
}
@Override
public void processAction(ActionRequest request, ActionResponse response)
throws PortletException, PortletSecurityException, IOException {
String objectId = request.getParameter("objectId");
if (objectId != null) {
request.getPortletSession().setAttribute("objectId", objectId, PortletSession.PORTLET_SCOPE);
}
}
}
RAAr is open source and is currently maintained by Rivet Logic Corporation. It provides most (if not all) of the Alfresco Foundation Service methods. It can be used to do anything that the Alfresco web client can do.
More information about RAAr can be found at this url: http://wiki.rivetlogic.com/display/RAAr
An example demo web client written by Rivet Logic that makes use of RAAr can be found at this location: http://scar.rivetlogic.com
This method consists on creating an API which communicates with Alfresco, this API is independent from Liferay, you can use it in a portlet, a servlet or a normal java application and this API allows you to search, delete, send documents...etc to Alfreso through Web Services. You can find all the libraries you need for communicating with Alfresco here: http://sourceforge.net/project/showfiles.php?group_id=143373&package_id=178146&release_id=524563
For example, you can search in a space (filtering by one property) and you obtain a list with all the documents found. Then, in your Liferay Portlet you can work with that list as you prefer.
The main advantage is that allows you to have Liferay and Alfresco in different machines, which is very positive, as they are heavy applications. The main disadvantage is that Web Services is quite slow.
Some examples can be found at the following link: http://svn.alfresco.com/repos/alfresco-open-mirror/alfresco/HEAD/root/projects/sdk/samples/WebServiceSamples/source/org/alfresco/sample/webservice/
Some references from Alfresco can be found here: http://wiki.alfresco.com/wiki/Alfresco_Content_Management_Web_Services
0 Attachments | Average (0 Votes) ![]() ![]() ![]() ![]() |