Paging preview in Alfresco Explorer

I’m just playing with Alfresco release 3.4.c – here is an example to show document preview in Afresco Explorer’s Custom View, with paging and zooming!

It’s no too complicated, let’s create following elements:
– a custom template with Share’s WebPreview module
– an action script to add “cm:templatable” aspect with new template id to node
– a recursive inbound rule for spaces to store documents required to preview…

Content transform webscript for Alfresco

You can find a simple content transform webscript for Alfresco here.

It’s looks like a working example, but points some shameless Alfresco bugs:

  • – an unhandled DuplicateChildNodeNameException received when a target node name already exists, not just a null return
  • – when a transformation error presents – transformDocument or transformImage returns with null – output node with new name already created, and contains the content of the source node
  • – transformation requires an installed, and configured OpenOffice.org in Alfresco;
    INFO [alfresco.util.OpenOfficeConnectionTester] The OpenOffice connection was re-established.
    but the relaunch of – an exited – OOo is not works, just avoid upcoming transformation processes;
    ERROR [alfresco.util.OpenOfficeConnectionTester] The OpenOffice connection has been lost.

Content transform GUI

Source code for the content transform webscript

transform.get.desc.xml (descriptor):


  Transform and get content as an URL
  Transform and get transformed content as a downloadable URL
  /extalf/transform?{nodeRef=nodeRef}&{mimetype=mimetype}
  argument
  user
  required

transform.get.js (javascript runtime code):

/*
 Content transform and presents it's URL to download
 @author: louise@louise.hu
 
 Parameters:
  - nodeRef: nodeRef of the source content node
  - mimetype: mimetype to transform source content
 */

var node = search.findNode(args.nodeRef);
var outputFolder = node.parent;

if (node == null) {
	model.errorCode = "1";
	model.errorMessage = "The content node could not be found";
}
else {
	// Transform content
	var m = node.mimetype;
	if (m.substr(0, 5) == "image") {
		// transform an image
		var transformed = node.transformImage(args.mimetype, outputFolder);
	} else {
		// transform a document
		var transformed = node.transformDocument(args.mimetype, outputFolder);
	}
	
	if (transformed == null) {
		model.errorCode = "2";
		model.errorMessage = "Unable to transform content";
		
		// TODO: alfresco 3.0 bug exists here, the target node already
		// created, but contains the source node's content :(
	}
	else {
		// return with the transformed node
		model.node = transformed;
	}
}

transform.get.json.ftl (FreeMarker template for output):

<#setting locale="en_US">
[
<#if node?? >
{
"success":"true",
"name":"${node.name?js_string}",
"nodeRef":"${node.nodeRef}",
"qnamePath":"${node.qnamePath}",
"store_type":"${node.nodeRef.storeRef.protocol}",
"store_id":"${node.nodeRef.storeRef.identifier}",
"id":"${node.nodeRef.id}",
"downloadUrl":"${node.downloadUrl}"
}
<#else>
{
"success":"false"
<#if errorCode?? >
, "error":"${errorCode}"

<#if errorMessage?? >
, "message":"${errorMessage?js_string}"

}

]

Alfresco forum: Transform content bugs