HelloI had downloaded alfresco 3.4.c and successfully added few custom dashlets helloworld and weather dashlet. I need to write a java backed dashlet. I am trying from last 2 days without success.Can not figure out where to place the class file of SimpleWebScript in share/webinf/classes or alfresco/webinf/classes.Sample code of java backed dashlet will help.Can anybody plz share sample code……I was tring to add following sample:
package org.alfresco.module.demoscripts;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import org.json.JSONException;
import org.json.JSONObject;
import org.springframework.extensions.webscripts.AbstractWebScript;
import org.springframework.extensions.webscripts.WebScriptException;
import org.springframework.extensions.webscripts.WebScriptRequest;
import org.springframework.extensions.webscripts.WebScriptResponse;
public class SimpleWebScript extends AbstractWebScript {
public void execute(WebScriptRequest req, WebScriptResponse res)
throws IOException {
try {
// build a json object
JSONObject obj = new JSONObject();
System.err
.println("*************************************************");
System.err.println("Rahul is here");
System.err
.println("*************************************************");
// put some data on it
obj.put("field1", "data1");
File f = new File("C:\\Users\\rasharma\\Desktop\\test.txt");
FileOutputStream fop = new FileOutputStream(f);
if (f.exists()) {
String str = "This data is written through the program";
fop.write(str.getBytes());
fop.flush();
fop.close();
System.out.println("The data has been written");
}
else
System.out.println("This file is not exist");
// build a JSON string and send it back
String jsonString = obj.toString();
res.getWriter().write(jsonString);
} catch (JSONException e) {
throw new WebScriptException("Unable to serialize JSON");
}
}
}
<webscript>
<shortname>The World's Simplest Webscript</shortname>
<description>Hands back a little bit of JSON</description>
<url>/components/dashlets/simple</url>
<authentication>none</authentication>
<family>dashlet</family>
</webscript>
Thanks.Rahul