08-29-2009 05:34 AM
public class RandomSelectWebScript extends AbstractRepositoryWebScript
{
public void execute(WebScriptRequest req, WebScriptResponse res)
throws IOException
{
try{
// get the referenced incoming node
NodeRef rootNodeRef = new NodeRef("avm://crweb–creator/-1;www;avm_webapps;ROOT;cms;83;NL");
System.out.println("rootNodeRef:::"+rootNodeRef);
// draw a random child
NodeRef childNodeRef = randomChild(rootNodeRef);
System.out.println("childNodeRef:::"+childNodeRef);
// stream child back
output(res, childNodeRef);
}
catch(Exception e){
e.printStackTrace();
}
}
protected NodeRef randomChild(NodeRef rootNodeRef)
{
// count the number of children
NodeRef nodeRef = null;
try{
System.out.println("call randomChild:::"+rootNodeRef);
List<FileInfo> files = this.services.getFileFolderService().listFiles(rootNodeRef);
int fileCount = files.size();
System.out.println("call fileCount:::"+fileCount);
// draw random number
int draw = (int) ((double)Math.random() * (double)fileCount);
System.out.println("call draw:::"+draw);
// our draw
FileInfo fileInfo = (FileInfo) files.get(draw);
System.out.println("call fileInfo:::"+fileInfo);
nodeRef = fileInfo.getNodeRef();
System.out.println("call nodeRef:::"+nodeRef);
}
catch(Exception e){
e.printStackTrace();
}
return nodeRef;
}
protected void output(WebScriptResponse res, NodeRef nodeRef)
{
System.out.println("call output:::"+nodeRef);
ContentReader reader = this.services.getContentService().getReader(nodeRef, ContentModel.PROP_CONTENT);
// stream back
try
{
reader.getContent(res.getOutputStream());
System.out.println("call output:::"+ res.getOutputStream());
}
catch (Exception e)
{
throw new WebScriptException("Unable to stream output");
}
}
} Now the requirement is that I want to access this content using REST based approach in web script, providing parmeters to search the content the way it is given in this path : cms, then 83, etc –>avm://crweb–creator/-1;www;avm_webapps;ROOT;cms;83;NL. Can I give it in my desc.xml file as parameters and then access them though req attribute in the controller java class? One more important thing is CAN I MAKE THIS CALL TO WEB SCRIPT AS HTTPS. Please help. Looking forward for your reply.08-31-2009 02:02 AM
09-01-2009 01:08 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.