Getting the content for a document
So far in this chapter, we have created the content in Alfresco based on in-memory text or from a file stored locally. Now, we will see how the content in the repository can be extracted and stored locally in a file. We will use an existing Alfresco e-mail template to demonstrate this. So if you are not running an Alfresco server, the path to the document will have to be changed in the following example.
To get the content of a document, we first have to get the Document
object via path and then get the content stream. In this example, we want to get the content for the invite-email.html.ftl
file located in the /Company Home/Data Dictionary/Email Templates/invite
folder in Alfresco. Then write the content of this file to a new local file with the same name. It will be written to the local directory from which we are running the application.
The following is the code:
public void getContentForDocumentAndStoreInFile(Session session) { // This is one of the...