mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Web Scripts - small refactor to template client url function - it's now a template method.
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@6018 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -92,7 +92,7 @@
|
|||||||
<#-- resolved path, filter and home.noderef required as arguments -->
|
<#-- resolved path, filter and home.noderef required as arguments -->
|
||||||
<script>
|
<script>
|
||||||
MySpaces.ServiceContext="${url.serviceContext}";
|
MySpaces.ServiceContext="${url.serviceContext}";
|
||||||
MySpaces.ScriptUrlEncoder=eval("MySpaces.ScriptUrlEncoder=" + unescape("${url.getClientUrlFunction("encUrl")}"));
|
MySpaces.ScriptUrlEncoder=eval("MySpaces.ScriptUrlEncoder=" + unescape("${clienturlfunction("encUrl")}"));
|
||||||
MySpaces.Path="${path?replace("\"","\\\"")}";
|
MySpaces.Path="${path?replace("\"","\\\"")}";
|
||||||
MySpaces.Filter="${filter}";
|
MySpaces.Filter="${filter}";
|
||||||
MySpaces.Home="${home.nodeRef}";
|
MySpaces.Home="${home.nodeRef}";
|
||||||
|
@@ -246,7 +246,7 @@ public abstract class AbstractWebScript implements WebScript
|
|||||||
// add web script context
|
// add web script context
|
||||||
model.put("args", createArgModel(req));
|
model.put("args", createArgModel(req));
|
||||||
model.put("guest", req.isGuest());
|
model.put("guest", req.isGuest());
|
||||||
model.put("url", new URLModel(req, res));
|
model.put("url", new URLModel(req));
|
||||||
model.put("server", new ServerModel(descriptorService.getServerDescriptor()));
|
model.put("server", new ServerModel(descriptorService.getServerDescriptor()));
|
||||||
|
|
||||||
// add custom model
|
// add custom model
|
||||||
@@ -298,12 +298,13 @@ public abstract class AbstractWebScript implements WebScript
|
|||||||
// add web script context
|
// add web script context
|
||||||
model.put("args", createArgModel(req));
|
model.put("args", createArgModel(req));
|
||||||
model.put("guest", req.isGuest());
|
model.put("guest", req.isGuest());
|
||||||
model.put("url", new URLModel(req, res));
|
model.put("url", new URLModel(req));
|
||||||
model.put("server", new ServerModel(descriptorService.getServerDescriptor()));
|
model.put("server", new ServerModel(descriptorService.getServerDescriptor()));
|
||||||
|
|
||||||
// add template support
|
// add template support
|
||||||
model.put("absurl", new AbsoluteUrlMethod(req.getServerPath()));
|
model.put("absurl", new AbsoluteUrlMethod(req.getServerPath()));
|
||||||
model.put("scripturl", new ScriptUrlMethod(req, res));
|
model.put("scripturl", new ScriptUrlMethod(req, res));
|
||||||
|
model.put("clienturlfunction", new ClientUrlFunctionMethod(res));
|
||||||
model.put("date", new Date());
|
model.put("date", new Date());
|
||||||
model.put(TemplateService.KEY_IMAGE_RESOLVER, getWebScriptRegistry().getTemplateImageResolver());
|
model.put(TemplateService.KEY_IMAGE_RESOLVER, getWebScriptRegistry().getTemplateImageResolver());
|
||||||
|
|
||||||
|
@@ -0,0 +1,75 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2005-2007 Alfresco Software Limited.
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public License
|
||||||
|
* as published by the Free Software Foundation; either version 2
|
||||||
|
* of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
|
* As a special exception to the terms and conditions of version 2.0 of
|
||||||
|
* the GPL, you may redistribute this Program in connection with Free/Libre
|
||||||
|
* and Open Source Software ("FLOSS") applications as described in Alfresco's
|
||||||
|
* FLOSS exception. You should have recieved a copy of the text describing
|
||||||
|
* the FLOSS exception, and it is also available here:
|
||||||
|
* http://www.alfresco.com/legal/licensing"
|
||||||
|
*/
|
||||||
|
package org.alfresco.web.scripts;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import freemarker.template.TemplateMethodModelEx;
|
||||||
|
import freemarker.template.TemplateModelException;
|
||||||
|
import freemarker.template.TemplateScalarModel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author David Caruana
|
||||||
|
*
|
||||||
|
* Custom FreeMarker Template language method.
|
||||||
|
* <p>
|
||||||
|
* Render a client side javascript function to build urls to this service.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* Usage: clientUrlFunction(String funcName)
|
||||||
|
*/
|
||||||
|
public final class ClientUrlFunctionMethod implements TemplateMethodModelEx
|
||||||
|
{
|
||||||
|
WebScriptResponse res;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct
|
||||||
|
*/
|
||||||
|
public ClientUrlFunctionMethod(WebScriptResponse res)
|
||||||
|
{
|
||||||
|
this.res = res;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see freemarker.template.TemplateMethodModel#exec(java.util.List)
|
||||||
|
*/
|
||||||
|
public Object exec(List args) throws TemplateModelException
|
||||||
|
{
|
||||||
|
String result = "";
|
||||||
|
|
||||||
|
if (args.size() != 0)
|
||||||
|
{
|
||||||
|
Object arg0 = args.get(0);
|
||||||
|
if (arg0 instanceof TemplateScalarModel)
|
||||||
|
{
|
||||||
|
String arg = ((TemplateScalarModel)arg0).getAsString();
|
||||||
|
result = res.getEncodeScriptUrlFunction(arg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
@@ -33,7 +33,6 @@ package org.alfresco.web.scripts;
|
|||||||
public class URLModel
|
public class URLModel
|
||||||
{
|
{
|
||||||
private WebScriptRequest req;
|
private WebScriptRequest req;
|
||||||
private WebScriptResponse res;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct
|
* Construct
|
||||||
@@ -41,10 +40,9 @@ public class URLModel
|
|||||||
* @param req
|
* @param req
|
||||||
* @param res
|
* @param res
|
||||||
*/
|
*/
|
||||||
URLModel(WebScriptRequest req, WebScriptResponse res)
|
URLModel(WebScriptRequest req)
|
||||||
{
|
{
|
||||||
this.req = req;
|
this.req = req;
|
||||||
this.res = res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -157,15 +155,4 @@ public class URLModel
|
|||||||
return getExtension();
|
return getExtension();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the client url encoding function script
|
|
||||||
*
|
|
||||||
* @param name name of the function object to return
|
|
||||||
*
|
|
||||||
* @return script to encode urls on the client
|
|
||||||
*/
|
|
||||||
public String getClientUrlFunction(String name)
|
|
||||||
{
|
|
||||||
return res.getEncodeScriptUrlFunction(name);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -204,7 +204,7 @@ public abstract class WebScriptRuntime
|
|||||||
WebScriptResponse res = createResponse();
|
WebScriptResponse res = createResponse();
|
||||||
Map<String, Object> model = new HashMap<String, Object>();
|
Map<String, Object> model = new HashMap<String, Object>();
|
||||||
model.put("status", status);
|
model.put("status", status);
|
||||||
model.put("url", new URLModel(req, res));
|
model.put("url", new URLModel(req));
|
||||||
|
|
||||||
// locate status template
|
// locate status template
|
||||||
// NOTE: search order...
|
// NOTE: search order...
|
||||||
|
Reference in New Issue
Block a user