Content can be written to the wcm repository by simply using the AVMService class. The instance of this service is available through the instance of ServiceRegistry class. I’ll again point out that if you are starting with Java backed web-scripts to read/write content from/to alfresco wcm, then the example script at http://wiki.alfresco.com/wiki/Java-backed_Web_Scripts_Samples is a good place to start. The Abstract class that it defines can be used as a base for other web-scripts. The specific method that can be used to create a node in our web project is the createFile method in the AVMService. This method returns the outputStream to the newly created object. The parameters for the createFile method are;
• Path: It is the path to the directory in which the file is to be created.
• FileName: It is the name with which the file will be created.
Once we have the output stream for the newly created file, we can just write the contents to the file using the write method (it is used to write a byte array to the stream).
Thus creating the file can be done in three (simple) steps:-
1. Create a file using the createFile method of AVMService.
2. Write the contents in the form of byte array to the output stream returned by the method called in 1.
3. Close the output stream.
Your feedback and suggestions are welcome.