Alfresco Webscript to load a properties file content to Alfresco

Alfresco Webscript to load a properties file content to Alfresco


Requirement:
Write a webscript which will load my .properties file "content" to alfresco.

Approach:
We can do this in many quick ways like:
1. Use the Java SDK of Alfresco to read the file entries and push it to repository.
2. Develop a webscript which will consume the property file or each of its element as input and author it in Alfresco.
3. Or ofcourse just "add content" the file using any of the available UIs of alfresco..

I want this component to be reused later so I am going for the second approach to construct a webscript.

Java or Javascript based?
In this scenario it is good to go for a java based webscript and read the properties after getting the file at server side and iterate, push the contents to Alfresco
But I want the program to be developed with Javascript based that I can use bundle it without Alfresco SDK dependency.

Let us start with a client java program to read a java property file.

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Enumeration;
import java.util.Properties;

public class PropertyReader {
public static void main(String[] args) {
try {
System.out.println(System.getProperty("user.dir"));
File file = new File(System.getProperty("user.dir")+"\\src\\com\\tcs\\ecmui\\test\\sample.properties");
FileInputStream fileInput = new FileInputStream(file);
Properties properties = new Properties();
properties.load(fileInput);
fileInput.close();

Enumeration enuKeys = properties.keys();
while (enuKeys.hasMoreElements()) {
String key = (String) enuKeys.nextElement();
String value = properties.getProperty(key);
System.out.println(key + ": " + value);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}

Ok now we have a program read the property file.

Let us make the webscript ready to consume this as the input and write it to repository..

Share this

Related Posts

Previous
Next Post »