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.
Source code for the content transform webscript
transform.get.desc.xml (descriptor):
1 2 3 4 5 6 7 8 | <webscript> <shortname>Transform and get content as an URL</shortname> <description>Transform and get transformed content as a downloadable URL</description> <url>/extalf/transform?{nodeRef=nodeRef}&{mimetype=mimetype}</url> <format default="json">argument</format> <authentication>user</authentication> <transaction>required</transaction> </webscript> |
transform.get.js (javascript runtime code):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | /* 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):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | <#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> <#if errorMessage?? > , "message":"${errorMessage?js_string}" </#if> } </#if> ] |
Alfresco forum: Transform content bugs
