AnsweredAssumed Answered

create a file and apply custom model

Question asked by fhomasp on Apr 15, 2008
Hey,

I'm rather unsure on how to change my current implementation for creating a file through a content rule.  I'll explain my problem and my current, very poorly performing solution.

My own custom java program, embedded within Alfresco outputs a document in XML format.  It's basically modelled java classes serialized as XML using Suns standard API.  This XML file gets written in a centralized space which triggers a content rule and converts the XML data into html using a freemarker template.  This in its turn converts the html file to pdf, which of course is a chain of content rules, which performs rather poorly from user POV.  But before I'll address this issue I need the functionality to work, I can always do some optimalisation later.
So, now I take an xml file, convert it and write it in html form using alfrescos standard model (cm:content).  However I'd like to write it using my own custom model called (rls:cv) but I'm unsure how to do this.  Here's my current script:

var cvFolder=companyhome.childByNamePath("/XMLStore/HTMLStore");
if(cvFolder!=null && document.properties.content.mimetype=="text/xml")
{
  var fileName=document.name.substring(0,document.name.length()-4)+".html";
  var fileNode = cvFolder.childByNamePath(fileName);
  if(fileNode==null)
  {
    fileNode = cvFolder.createFile(fileName);  //it'll probably be here or below to get my custom model done, however createFile does not accept more than one argument.
  }
  fileNode.mimetype="text/html";
  fileNode.content=document.processTemplate(companyhome.childByNamePath("/Data Dictionary/Presentation Templates/cvs.ftl"));
  fileNode.addAspect("cm:versionable");
  //fileNode.addAspect("rls:skillable");
}

I noticed that I need my custom model applied before I can apply a custom aspect associated with the custom model, which is why its commented out.

Outcomes