Package ninja.template
Class TemplateEngineJsonP
- java.lang.Object
-
- ninja.template.TemplateEngineJsonP
-
- All Implemented Interfaces:
TemplateEngine
public class TemplateEngineJsonP extends Object implements TemplateEngine
JSONP engine. Outputs the given result as JSONP output: Javascript callback with data as a parameter. Contains JSONP validation regular expression to test the validness of the JSONP callback. The valid callbacks are simple functions like myJsFunction or simple object path looking like: something1.something2.something3 . See ninja.template.TemplateEngineJsonPValidatorTest for supported cases tests. This is a subset of rules from the following article:- See Also:
- Sanitizing JSONP callbacks
-
-
Constructor Summary
Constructors Constructor Description TemplateEngineJsonP(com.fasterxml.jackson.databind.ObjectMapper objectMapper, NinjaProperties properties)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description String
getContentType()
Get the content type this template engine rendersString
getSuffixOfTemplatingEngine()
For instance returns ".ftl.html" Or .ftl.json.void
invoke(Context context, Result result)
Render the given object to the given contextstatic boolean
isThisASecureCallbackName(String callback)
Tests whether the given function name is a valid JSONP function name/path.
-
-
-
Constructor Detail
-
TemplateEngineJsonP
@Inject public TemplateEngineJsonP(com.fasterxml.jackson.databind.ObjectMapper objectMapper, NinjaProperties properties)
-
-
Method Detail
-
invoke
public void invoke(Context context, Result result)
Description copied from interface:TemplateEngine
Render the given object to the given context- Specified by:
invoke
in interfaceTemplateEngine
- Parameters:
context
- The context to render toresult
- The result to render
-
getContentType
public String getContentType()
Description copied from interface:TemplateEngine
Get the content type this template engine renders- Specified by:
getContentType
in interfaceTemplateEngine
- Returns:
- The content type this template engine renders
-
getSuffixOfTemplatingEngine
public String getSuffixOfTemplatingEngine()
Description copied from interface:TemplateEngine
For instance returns ".ftl.html" Or .ftl.json.Or anything else. To display error messages in a nice way...
But Gson for instance does not use a template to render stuff. Therefore it will return null
- Specified by:
getSuffixOfTemplatingEngine
in interfaceTemplateEngine
- Returns:
- name of suffix or null if engine is not using a template on disk.
-
isThisASecureCallbackName
public static boolean isThisASecureCallbackName(String callback)
Tests whether the given function name is a valid JSONP function name/path.- Parameters:
callback
- Callback value to test.- Returns:
- Whether the given function name is a valid JSONP function name/path.
-
-