From 3f107708f86cd319beefd3387b18d8d50f9c6ca9 Mon Sep 17 00:00:00 2001 From: David Caruana Date: Fri, 22 Jun 2007 16:39:43 +0000 Subject: [PATCH] - AVM Web Script Sample (browse stores, folders, content) - Fix Web Script issue where urls contained ; (due to tomcat) - Allow AVMScriptStore to be passed through script converters (add serializable) git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@6071 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- config/alfresco/bootstrap/webScripts.xml | 80 +++++++++++++++++++ .../webscripts/avmbrowse.get.desc.xml | 8 ++ .../webscripts/avmbrowse.get.html.ftl | 31 +++++++ .../bootstrap/webscripts/avmbrowse.get.js | 36 +++++++++ .../webscripts/avmstores.get.desc.xml | 8 ++ .../webscripts/avmstores.get.html.ftl | 18 +++++ .../alfresco/repo/jscript/AVMScriptStore.java | 2 +- 7 files changed, 182 insertions(+), 1 deletion(-) create mode 100644 config/alfresco/bootstrap/webscripts/avmbrowse.get.desc.xml create mode 100644 config/alfresco/bootstrap/webscripts/avmbrowse.get.html.ftl create mode 100644 config/alfresco/bootstrap/webscripts/avmbrowse.get.js create mode 100644 config/alfresco/bootstrap/webscripts/avmstores.get.desc.xml create mode 100644 config/alfresco/bootstrap/webscripts/avmstores.get.html.ftl diff --git a/config/alfresco/bootstrap/webScripts.xml b/config/alfresco/bootstrap/webScripts.xml index b166cdeb71..487cb78ac4 100644 --- a/config/alfresco/bootstrap/webScripts.xml +++ b/config/alfresco/bootstrap/webScripts.xml @@ -323,6 +323,86 @@ + + + + + + + + true + + contentUrl=classpath:alfresco/bootstrap/webscripts/avmstores.get.desc.xml|mimetype=text/xml|size=|encoding=UTF-8|locale=en_US_ + avmstores.get.desc.xml + + avmstores.get.desc.xml + + + + + + + + + + + true + + contentUrl=classpath:alfresco/bootstrap/webscripts/avmstores.get.html.ftl|mimetype=text/plain|size=|encoding=UTF-8|locale=en_US_ + avmstores.get.html.ftl + + avmstores.get.html.ftl + + + + + + + + + + + true + + contentUrl=classpath:alfresco/bootstrap/webscripts/avmbrowse.get.js|mimetype=application/x-javascript|size=|encoding=UTF-8|locale=en_US_ + avmbrowse.get.js + + avmbrowse.get.js + + + + + + + + + + + true + + contentUrl=classpath:alfresco/bootstrap/webscripts/avmbrowse.get.desc.xml|mimetype=text/xml|size=|encoding=UTF-8|locale=en_US_ + avmbrowse.get.desc.xml + + avmbrowse.get.desc.xml + + + + + + + + + + + true + + contentUrl=classpath:alfresco/bootstrap/webscripts/avmbrowse.get.html.ftl|mimetype=text/plain|size=|encoding=UTF-8|locale=en_US_ + avmbrowse.get.html.ftl + + avmbrowse.get.html.ftl + + + diff --git a/config/alfresco/bootstrap/webscripts/avmbrowse.get.desc.xml b/config/alfresco/bootstrap/webscripts/avmbrowse.get.desc.xml new file mode 100644 index 0000000000..d3e55fd766 --- /dev/null +++ b/config/alfresco/bootstrap/webscripts/avmbrowse.get.desc.xml @@ -0,0 +1,8 @@ + + AVM Browse Sample + Sample demonstrating the listing of AVM folder contents + /sample/avm/path/{storeid}/{path} + argument + guest + required + diff --git a/config/alfresco/bootstrap/webscripts/avmbrowse.get.html.ftl b/config/alfresco/bootstrap/webscripts/avmbrowse.get.html.ftl new file mode 100644 index 0000000000..f3df594ca9 --- /dev/null +++ b/config/alfresco/bootstrap/webscripts/avmbrowse.get.html.ftl @@ -0,0 +1,31 @@ + + + AVM Folder: ${folder.displayPath}/${folder.name} + + + AVM Store: ${store.id} +
+
+ AVM Folder: ${folder.displayPath}/${folder.name} +
+
+ + <#if folder.parent?exists> + + + +<#list folder.children as child> + + <#if child.isContainer> + + +
${folder.parent.properties.creator} ${folder.parent.size} ${folder.parent.properties.modified?datetime} .. +
${child.properties.creator} ${child.size} ${child.properties.modified?datetime} >${child.name} + <#else> + ${child.properties.creator} ${child.size} ${child.properties.modified?datetime} ${child.name} + +
+ + + +<#macro encodepath node><#if node.parent?exists><@encodepath node=node.parent/>/${node.name?url} \ No newline at end of file diff --git a/config/alfresco/bootstrap/webscripts/avmbrowse.get.js b/config/alfresco/bootstrap/webscripts/avmbrowse.get.js new file mode 100644 index 0000000000..6e3c98c731 --- /dev/null +++ b/config/alfresco/bootstrap/webscripts/avmbrowse.get.js @@ -0,0 +1,36 @@ +script: +{ + // extract avm store id and path + var fullpath = url.extension.split("/"); + if (fullpath.length == 0) + { + status.code = 400; + status.message = "Store id has not been provided."; + status.redirect = true; + break script; + } + var storeid = fullpath[0]; + var path = (fullpath.length == 1 ? "/" : "/" + fullpath.slice(1).join("/")); + + // locate avm node from path + var store = avm.lookupStore(storeid); + if (store == undefined) + { + status.code = 404; + status.message = "Store " + storeid + " not found."; + status.redirect = true; + break script; + } + var node = avm.lookupNode(storeid + ":" + path); + if (node == undefined) + { + status.code = 404; + status.message = "Path " + path + " within store " + storeid + " not found."; + status.redirect = true; + break script; + } + + // setup model for templates + model.store = store; + model.folder = node; +} \ No newline at end of file diff --git a/config/alfresco/bootstrap/webscripts/avmstores.get.desc.xml b/config/alfresco/bootstrap/webscripts/avmstores.get.desc.xml new file mode 100644 index 0000000000..22d81a7438 --- /dev/null +++ b/config/alfresco/bootstrap/webscripts/avmstores.get.desc.xml @@ -0,0 +1,8 @@ + + AVM Stores Sample + Sample demonstrating the listing of AVM stores + /sample/avm/stores + + admin + required + diff --git a/config/alfresco/bootstrap/webscripts/avmstores.get.html.ftl b/config/alfresco/bootstrap/webscripts/avmstores.get.html.ftl new file mode 100644 index 0000000000..bf465c5743 --- /dev/null +++ b/config/alfresco/bootstrap/webscripts/avmstores.get.html.ftl @@ -0,0 +1,18 @@ + + + AVM Stores + + + AVM Stores +
+
+ + +<#list avm.stores as store> + + + +
${store.creator} ${store.createdDate?datetime} ${store.id} +
+ + diff --git a/source/java/org/alfresco/repo/jscript/AVMScriptStore.java b/source/java/org/alfresco/repo/jscript/AVMScriptStore.java index 4611cc3329..1b81b327d8 100644 --- a/source/java/org/alfresco/repo/jscript/AVMScriptStore.java +++ b/source/java/org/alfresco/repo/jscript/AVMScriptStore.java @@ -43,7 +43,7 @@ import org.mozilla.javascript.Scriptable; /** * @author Kevin Roast */ -public class AVMScriptStore +public class AVMScriptStore implements Serializable { private ServiceRegistry services; private AVMStoreDescriptor descriptor;