Esempio n. 1
0
 public String setTemplate(String vmFile) {
   Context context = ThreadContext.getContext();
   String name = "";
   String oldCurrentPath = context.getCurrentPath();
   //        String layout = context.getLayout();
   String filePath = DirectoryUtil.getDirectory(context.getCurrentPath(), vmFile);
   int i = filePath.indexOf(Configuration.getDeployPath());
   if (i >= 0) {
     name = filePath.substring(i + Configuration.getDeployPath().length());
   } else {
     name = filePath;
   }
   String groovyFile = (Configuration.getDeployPath() + name).replace(".vm", ".groovy");
   File file = new File(groovyFile);
   if (file.exists()) {
     try {
       //                context.setLayout(null);
       String content = codeRender.render(file, "execute");
       return content;
     } catch (Exception e) {
       return "<!-- control error " + e.getMessage() + "-->";
     } finally {
       context.setCurrentPath(oldCurrentPath); // 把当前目录会写回去
       //                context.setLayout(layout);
     }
   }
   if (StringUtils.isBlank(name)) {
     return "<!-- control error " + vmFile + "-->";
   }
   return velocityEngine.renderTemplate(name, context.getContextMap());
 }
Esempio n. 2
0
 public static Map<String, PageMethod> getAppPages() {
   return getAppPages(ThreadContext.getContext().getApp().getAppKey());
 }
Esempio n. 3
0
 public ControlTool addParameter(String key, Object value) {
   Context context = ThreadContext.getContext();
   context.putContext(key, value);
   return this;
 }