01-16-2011 12:17 PM
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>
01-18-2011 12:25 PM
01-18-2011 04:47 PM
04-05-2011 07:57 AM
public class Active extends DeclarativeWebScript{
Map<String, Object> model = new HashMap<String, Object>();
public Map<String, Object> executeImpl(WebScriptRequest req, WebScriptResponse res) throws IOException {
model.put("content", "value");
return model;
}
}
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>
<beans>
<bean id="webscript.site-webscripts.org.alfresco.components.dashlets.simple.active.active.get"
class="simple.Active" parent="webscript">
</bean>
</beans>
<webscript>
<shortname>active-dashlet</shortname>
<description>active dashlet</description>
<family>user-dashlet</family>
<url>/active</url>
</webscript>
RESULT !!! <#if content?exists>${content}</#if>
04-05-2011 11:13 AM
04-05-2011 11:32 AM
11-19-2011 07:44 AM
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.