use of freemarker.template.TemplateModelException in project PublicCMS-preview by sanluan.
the class MethodController method method.
/**
* 接口指令统一分发
*
* @param name
* @param appToken
* @param request
* @param response
* @return result
*/
@RequestMapping("method/{name}")
public Object method(@PathVariable String name, String appToken, HttpServletRequest request, HttpServletResponse response) {
BaseMethod method = methodMap.get(name);
if (null != method) {
try {
if (method.needAppToken()) {
SysAppToken token = appTokenService.getEntity(appToken);
if (null == token) {
return NEED_APP_TOKEN_MAP;
}
SysApp app = appService.getEntity(token.getAppId());
if (null == app) {
return NEED_APP_TOKEN_MAP;
}
}
Map<String, Object> map = new HashMap<>();
String[] paramters = request.getParameterValues("paramters");
if (CommonUtils.notEmpty(paramters) && paramters.length >= method.minParamtersNumber()) {
List<TemplateModel> list = new ArrayList<>();
for (String paramter : paramters) {
list.add(getObjectWrapper().wrap(paramter));
}
map.put("result", method.exec(list));
return map;
} else if (CommonUtils.empty(paramters) && 0 == method.minParamtersNumber()) {
map.put("result", method.exec(null));
return map;
} else {
map.put(ERROR, "paramtersError");
return map;
}
} catch (TemplateModelException e) {
log.error(e.getMessage(), e);
Map<String, String> map = new HashMap<>();
map.put(ERROR, ApiController.EXCEPTION);
return map;
}
} else {
return ApiController.NOT_FOUND_MAP;
}
}
use of freemarker.template.TemplateModelException in project ninja by ninjaframework.
the class TemplateEngineFreemarkerWebJarsAtMethod method exec.
public TemplateModel exec(List args) throws TemplateModelException {
if (args.size() == 0) {
throw new TemplateModelException("Error. You must specify a webjars asset URL.");
}
// Allow a boolean as second argument to force webjars usage
if (useCDN && (args.size() == 1 || !((TemplateBooleanModel) args.get(1)).getAsBoolean())) {
String filename = ((SimpleScalar) args.get(0)).getAsString();
return new SimpleScalar(JSDELIVER_CDN + filename);
} else {
List argsWithControllerAndMethod = new ArrayList();
argsWithControllerAndMethod.add(AssetsController.class.getName());
argsWithControllerAndMethod.add("serveWebJars");
argsWithControllerAndMethod.add("fileName");
argsWithControllerAndMethod.addAll(args);
return templateEngineFreemarkerReverseRouteHelper.computeReverseRoute(argsWithControllerAndMethod);
}
}
use of freemarker.template.TemplateModelException in project ninja by ninjaframework.
the class TemplateEngineFreemarkerAuthenticityFormDirective method execute.
@Override
public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException {
if (!params.isEmpty()) {
throw new TemplateModelException("This directive doesn't allow parameters.");
}
if (loopVars.length != 0) {
throw new TemplateModelException("This directive doesn't allow loop variables.");
}
Writer out = env.getOut();
out.append("<input type=\"hidden\" value=\"" + context.getSession().getAuthenticityToken() + "\" name=\"" + NinjaConstant.AUTHENTICITY_TOKEN + "\" />");
}
use of freemarker.template.TemplateModelException in project leopard by tanhaichao.
the class AbstractTemplateMethod method exec.
@Override
public Object exec(@SuppressWarnings("rawtypes") List arguments) throws TemplateModelException {
// arguments.toArray();
Object[] args = new Object[arguments.size()];
int i = 0;
for (Object obj : arguments) {
if (obj != null) {
if (obj instanceof SimpleDate) {
args[i] = ((SimpleDate) obj).getAsDate();
} else if (obj instanceof SimpleNumber) {
args[i] = ((SimpleNumber) obj).getAsNumber();
} else if (obj instanceof SimpleNumber) {
args[i] = ((SimpleNumber) obj).getAsNumber();
} else if (obj instanceof SimpleScalar) {
args[i] = ((SimpleScalar) obj).toString();
} else if (obj instanceof StringModel) {
args[i] = ((StringModel) obj);
} else {
logger.error("obj:" + obj.getClass());
args[i] = obj.toString();
}
}
i++;
}
try {
return this.execute(args);
} catch (TemplateModelException e) {
throw e;
} catch (RuntimeException e) {
logger.error("key:" + this.getKey() + " clazz:" + this.getClass().getName());
throw e;
} catch (Exception e) {
throw new TemplateModelException(e.getMessage(), e);
}
}
use of freemarker.template.TemplateModelException in project openj9 by eclipse.
the class Artifact method get.
public TemplateModel get(String arg0) throws TemplateModelException {
try {
if (arg0.equals("name")) {
return new ArtifactName(artifact);
}
if (arg0.equals("data")) {
return new ArtifactData(artifact);
}
if (arg0.equals("targetNameWithRelease")) {
return new SimpleScalar(UMA.getUma().getPlatform().getTargetNameWithRelease(artifact));
}
if (arg0.equals("exportNames")) {
return new ExportNames(artifact);
}
if (arg0.equals("bundledArtifacts")) {
return new Artifacts(artifact.getAllArtifactsInThisBundleInHashtable());
}
TemplateModel platformExtension = com.ibm.uma.UMA.getUma().getPlatform().getDataModelExtension("uma.spec.flags." + artifact.getTargetName(), arg0);
if (platformExtension != null)
return platformExtension;
TemplateModel configurationExtension = com.ibm.uma.UMA.getUma().getConfiguration().getDataModelExtension("uma.spec.flags." + artifact.getTargetName(), arg0);
if (configurationExtension != null)
return configurationExtension;
return null;
} catch (UMAException e) {
throw new TemplateModelException(e);
}
}
Aggregations