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 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

transform.get.js (javascript runtime code):

 Content transform and presents it's URL to download
  - 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?? >
<#if errorCode?? >
, "error":"${errorCode}"

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



Alfresco forum: Transform content bugs

2 thoughts on “Content transform webscript for Alfresco”

Leave a Reply

Your email address will not be published. Required fields are marked *