07-07-2011 05:03 PM
System.out.println("ticketFromApplet given to content handler is: " + ticketFromApplet);
System.out.println("NodeRef given to content handler is: " + nodeRef);
Ticket ticket = new Ticket("http://<host>:8080/alfresco", ticketFromApplet);
StoreRef storeRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore");
HttpServletRequest request = (HttpServletRequest) MessageContext.getCurrentContext() .getProperty(HTTPConstants.MC_HTTP_SERVLETREQUEST);
ServletContext sc = request.getSession().getServletContext();
WebApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(sc);
// get registry of services
final ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
SearchService searchService = serviceRegistry.getSearchService();
ResultSet rs = searchService.query(storeRef,SerchService.LANGUAGE_LUCENE, "ID:\"" + nodeRef + "\"");
ResultSetRow row = rs.getRow(0);
NodeRef docRef = row.getNodeRef();
ContentServiceImpl contentService = new ContentServiceImpl();
contentService.readContentIntoStream(ticket, docRef, QName.createQName("cm:content"), outputStream);10-01-2011 08:43 AM
10-03-2011 06:02 PM
// now get the content and pass it on to Applet
/*String ticketFromApplet = contentHandlerInput.getDocumentId();
String nodeRef = contentHandlerInput.getClientInstanceId();
System.out.println("ticketFromApplet given to content handler is: " +
ticketFromApplet);
System.out.println("NodeRef given to content handler is: " +
nodeRef);
System.out.println("Getting servlet context…");
ServletContext objContext = getServletConfig().getServletContext();
System.out.println("Creating noderef…");
// NodeRef of the document
NodeRef objRef = new NodeRef(nodeRef);
System.out.println("Getting context…");
// Get webapplication context
WebApplicationContext wc = WebApplicationContextUtils.getRequiredWebApplicationContext(objContext);
System.out.println("Getting Service registry…");
ServiceRegistry serviceRegistry = (ServiceRegistry) wc.getBean(ServiceRegistry.SERVICE_REGISTRY);
System.out.println("Getting Authentication service…");
// Get authentication service
AuthenticationService objService = serviceRegistry.getAuthenticationService();
System.out.println(
"Validating ticket using authentication service…");
// MUST TO AVOID THE ERROR - a valid SecureContext was not provided in the RequestContext
// example : req.getParameter("alf_ticket") = TICKET_2fa55c64371087b642fdf8107083456f81fd1e1f
objService.validate(ticketFromApplet);
System.out.println("Getting Content service…");
ContentService contentService = serviceRegistry.getContentService();
System.out.println("Getting Content reader for the given node…");
// Get the content reader
ContentReader contentReader = contentService.getReader(objRef,
ContentModel.PROP_CONTENT);
System.out.println("Getting content as bytes…");
InputStream in = contentReader.getContentInputStream();
try {
int nextChar;
while ((nextChar = in.read()) != -1) {
outputStream.write((char) nextChar);
}
} catch (Exception ex) {
ex.printStackTrace();
}
byte[] binaryData = outputStream.toByteArray();
10-05-2011 03:20 AM
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.