Пример #1
0
 @SuppressWarnings("unchecked")
 public static void _render(
     Map<?, ?> args, Closure body, PrintWriter out, ExecutableTemplate template, int fromLine) {
   try {
     if (!args.containsKey("arg") || args.get("arg") == null) {
       throw new TemplateExecutionException(
           template.template,
           fromLine,
           "Specify a template name",
           new TagInternalException("Specify a template name"));
     }
     String name = args.get("arg").toString();
     if (name.startsWith("./")) {
       String ct = BaseTemplate.currentTemplate.get().name;
       if (ct.matches("^/lib/[^/]+/app/views/.*")) {
         ct = ct.substring(ct.indexOf("/", 5));
       }
       ct = ct.substring(0, ct.lastIndexOf("/"));
       name = ct + name.substring(1);
     }
     args.remove("arg");
     BaseTemplate t = (BaseTemplate) TemplateLoader.load(name);
     Map<String, Object> newArgs = new HashMap<String, Object>();
     newArgs.putAll((Map<? extends String, ? extends Object>) args);
     newArgs.put("_isInclude", true);
     newArgs.put("out", out);
     t.internalRender(newArgs);
   } catch (TemplateNotFoundException e) {
     throw new TemplateNotFoundException(e.getPath(), template.template, fromLine);
   }
 }
Пример #2
0
 public void invokeTag(Integer fromLine, String tag, Map<String, Object> attrs, Closure body) {
     String templateName = tag.replace(".", "/");
     String callerExtension = "tag";
     if (template.name.indexOf(".") > 0) {
         callerExtension = template.name.substring(template.name.lastIndexOf(".") + 1);
     }
     BaseTemplate tagTemplate = null;
     try {
         tagTemplate = (BaseTemplate)TemplateLoader.load("tags/" + templateName + "." + callerExtension);
     } catch (TemplateNotFoundException e) {
         try {
             tagTemplate = (BaseTemplate)TemplateLoader.load("tags/" + templateName + ".tag");
         } catch (TemplateNotFoundException ex) {
             if (callerExtension.equals("tag")) {
                 throw new TemplateNotFoundException("tags/" + templateName + ".tag", template, fromLine);
             }
             throw new TemplateNotFoundException("tags/" + templateName + "." + callerExtension + " or tags/" + templateName + ".tag", template, fromLine);
         }
     }
     TagContext.enterTag(tag);
     Map<String, Object> args = new HashMap<String, Object>();
     args.put("session", getBinding().getVariables().get("session"));
     args.put("flash", getBinding().getVariables().get("flash"));
     args.put("request", getBinding().getVariables().get("request"));
     args.put("params", getBinding().getVariables().get("params"));
     args.put("play", getBinding().getVariables().get("play"));
     args.put("lang", getBinding().getVariables().get("lang"));
     args.put("messages", getBinding().getVariables().get("messages"));
     args.put("out", getBinding().getVariable("out"));
     args.put("_attrs", attrs);
     // all other vars are template-specific
     args.put("_caller", getBinding().getVariables());
     if (attrs != null) {
         for (Map.Entry<String, Object> entry : attrs.entrySet()) {
             args.put("_" + entry.getKey(), entry.getValue());
         }
     }
     args.put("_body", body);
     try {
         tagTemplate.render(args);
     } catch (TagInternalException e) {
         throw new TemplateExecutionException(template, fromLine, e.getMessage(), template.cleanStackTrace(e));
     } catch (TemplateNotFoundException e) {
         throw new TemplateNotFoundException(e.getPath(), template, fromLine);
     }
     TagContext.exitTag();
 }
Пример #3
0
 public static void _extends(
     Map<?, ?> args, Closure body, PrintWriter out, ExecutableTemplate template, int fromLine) {
   try {
     if (!args.containsKey("arg") || args.get("arg") == null) {
       throw new TemplateExecutionException(
           template.template,
           fromLine,
           "Specify a template name",
           new TagInternalException("Specify a template name"));
     }
     String name = args.get("arg").toString();
     if (name.startsWith("./")) {
       String ct = BaseTemplate.currentTemplate.get().name;
       if (ct.matches("^/lib/[^/]+/app/views/.*")) {
         ct = ct.substring(ct.indexOf("/", 5));
       }
       ct = ct.substring(0, ct.lastIndexOf("/"));
       name = ct + name.substring(1);
     }
     BaseTemplate.layout.set((BaseTemplate) TemplateLoader.load(name));
   } catch (TemplateNotFoundException e) {
     throw new TemplateNotFoundException(e.getPath(), template.template, fromLine);
   }
 }