From 43169b08e61315e79bbb41740c6b308bf39d2a50 Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Fri, 26 Aug 2011 14:58:03 +0000 Subject: [PATCH] Switch the Links fetching webscript to be Java backed using the new service git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@30101 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../repository/links/link/link.get.js | 24 ------- .../web-scripts-application-context.xml | 6 ++ .../repo/web/scripts/links/LinkGet.java | 62 +++++++++++++++++++ 3 files changed, 68 insertions(+), 24 deletions(-) delete mode 100644 config/alfresco/templates/webscripts/org/alfresco/repository/links/link/link.get.js create mode 100644 source/java/org/alfresco/repo/web/scripts/links/LinkGet.java diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/links/link/link.get.js b/config/alfresco/templates/webscripts/org/alfresco/repository/links/link/link.get.js deleted file mode 100644 index d5d74c7aaa..0000000000 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/links/link/link.get.js +++ /dev/null @@ -1,24 +0,0 @@ - - - - - - -function main() -{ - // get requested node - var node = getRequestNode(); - if (status.getCode() != status.STATUS_OK) - { - return; - } - - // assign data - model.item = getLinksData(node); - - // fetch the contentLength param - var contentLength = args["contentLength"] != undefined ? parseInt(args["contentLength"]) : -1; - model.contentLength = isNaN(contentLength) ? -1 : contentLength; -} - -main(); \ No newline at end of file diff --git a/config/alfresco/web-scripts-application-context.xml b/config/alfresco/web-scripts-application-context.xml index a0f1aa7f2a..38ebb68d63 100644 --- a/config/alfresco/web-scripts-application-context.xml +++ b/config/alfresco/web-scripts-application-context.xml @@ -1519,6 +1519,12 @@ + + + + . + */ +package org.alfresco.repo.web.scripts.links; + +import java.util.HashMap; +import java.util.Map; + +import org.alfresco.service.cmr.links.LinkInfo; +import org.alfresco.service.cmr.site.SiteInfo; +import org.json.JSONObject; +import org.springframework.extensions.webscripts.Cache; +import org.springframework.extensions.webscripts.Status; +import org.springframework.extensions.webscripts.WebScriptException; +import org.springframework.extensions.webscripts.WebScriptRequest; + +/** + * This class is the controller for the link fetching link.get webscript. + * + * @author Nick Burch + * @since 4.0 + */ +public class LinkGet extends AbstractLinksWebScript +{ + @Override + protected Map executeImpl(SiteInfo site, String linkName, + WebScriptRequest req, JSONObject json, Status status, Cache cache) { + Map model = new HashMap(); + + // Try to find the link + LinkInfo link = linksService.getLink(site.getShortName(), linkName); + if(link == null) + { + String message = "No link found with that name"; + throw new WebScriptException(Status.STATUS_NOT_FOUND, message); + } + + // Build the model + model.put("item", renderLink(link)); + model.put("node", link.getNodeRef()); + model.put("siteId", site.getShortName()); + model.put("site", site); + + // All done + return model; + } +}