/** * Creates a page and sets up the velocity engine to render */ public Page(final HttpServletRequest request, final HttpServletResponse response, final VelocityEngine engine, final String template) { this.request = Utils.nonNull(request); this.response = Utils.nonNull(response); this.engine = Utils.nonNull(engine); this.template = Utils.nonNull(template); this.context = new VelocityContext(); this.context.put("esc", new EscapeTool()); this.context.put("session", request.getSession(true)); this.context.put("context", request.getContextPath()); }
/** * Gets an instance of the velocity context * * Add the utility instances that are commonly used in many templates. * * @return the instance */ public static VelocityContext getInstance() { final VelocityContext context = new VelocityContext(); context.put("esc", new EscapeTool()); final WebUtils utils = new WebUtils(); context.put("utils", utils); return context; } }
ctx.put("valueSet", theValueSetTm); ctx.put("packageBase", thePackageBase); ctx.put("esc", new EscapeTool());
ctx.put("version", myVersion.replace(".", "")); ctx.put("versionEnumName", determineVersionEnum().name()); ctx.put("esc", new EscapeTool()); ctx.put("isRi", determineVersionEnum().isRi()); ctx.put("package_suffix", packageSuffix);
ctx.put("version", version); ctx.put("package_suffix", packageSuffix); ctx.put("esc", new EscapeTool()); if (BaseStructureSpreadsheetParser.determineVersionEnum(version).isRi()) { ctx.put("resourcePackage", "org.hl7.fhir." + version + ".model");
ctx.put("searchParamsWithoutComposite", (theResource.getSearchParametersWithoutComposite())); ctx.put("includes", (theResource.getIncludes())); ctx.put("esc", new EscapeTool()); ctx.put("isRi", determineVersionEnum().isRi());
ctx.put("version", configuration.getVersion()); ctx.put("package_suffix", configuration.getPackageSuffix()); ctx.put("esc", new EscapeTool());
ctx.put("isRi", BaseStructureSpreadsheetParser.determineVersionEnum(version).isRi()); ctx.put("hash", "#"); ctx.put("esc", new EscapeTool()); if (BaseStructureSpreadsheetParser.determineVersionEnum(version).isRi()) { ctx.put("resourcePackage", "org.hl7.fhir." + version + ".model");
ctx.put("isRi", BaseStructureSpreadsheetParser.determineVersionEnum(version).isRi()); ctx.put("hash", "#"); ctx.put("esc", new EscapeTool()); if (BaseStructureSpreadsheetParser.determineVersionEnum(version).isRi()) { ctx.put("resourcePackage", "org.hl7.fhir." + version + ".model");
public AjaxRequestServiceImpl(Map<String,AjaxAction> objects, VelocityEngine velocityEngine) { this.actions = objects; this.velocityEngine = velocityEngine; this.velocityEscTool = new EscapeTool(); }
public AjaxRequestServiceImpl(Map<String,AjaxAction> objects, VelocityEngine velocityEngine, String urlParameterName) { this.actions = objects; this.velocityEngine = velocityEngine; this.urlParameterName = urlParameterName; this.velocityEscTool = new EscapeTool(); }
private VelocityContext getVelocityContext(MavenProject mavenProject, List<Violation> violations) { VelocityContext context = new VelocityContext(); context.put("project", mavenProject); context.put("violations", violations); context.put("esc", new EscapeTool()); return context; }
private VelocityContext getVelocityContext(HttpServletRequest request, String pageTitle) { final VelocityContext ctx = new VelocityContext(); ctx.put("title", getServletInfo() + " - " + pageTitle); ctx.put("contextPath", request.getContextPath()); ctx.put("cssPath", request.getContextPath() + mountPath + "/benchmark.css"); ctx.put("esc", new EscapeTool()); return ctx; }
/** * Loads the internal {@link #velocityContext} from the * given Map of template objects. * * @param templateObjects Map containing objects to add to the template context. */ private void loadVelocityContext(final Map<String, Object> templateObjects) { if (templateObjects != null) { // copy the templateObjects to the velocityContext for (Map.Entry<String, Object> entry : templateObjects.entrySet()) { this.velocityContext.put(entry.getKey(), entry.getValue()); } } // add velocity tools (Escape tool) this.velocityContext.put("esc", new EscapeTool()); }
protected VelocityContext getVelocityContext( Discovery discovery, List<Action> actions, int version, String filter) { VelocityContext context = new VelocityContext(); ObjectiveCUtil objectiveCUtil = new ObjectiveCUtil(); StringBuilder className = new StringBuilder("LR"); className.append(objectiveCUtil.getServiceClassName(filter)); className.append("_v"); className.append(version); context.put(ACTIONS, actions); context.put(BOOL, ObjectiveCUtil.BOOL); context.put(CLASS_NAME, className.toString()); context.put(DISCOVERY, discovery); context.put(ESCAPE_TOOL, new EscapeTool()); context.put(JSON_OBJECT_WRAPPER, ObjectiveCUtil.LR_JSON_OBJECT_WRAPPER); context.put(LANGUAGE_UTIL, objectiveCUtil); context.put(LR_UPLOAD_DATA, objectiveCUtil.LR_UPLOAD_DATA); context.put(VOID, LanguageUtil.VOID); return context; }
protected VelocityContext getVelocityContext( Discovery discovery, List<Action> actions, String packageName, int version, String filter) { VelocityContext context = new VelocityContext(); CSharpUtil cSharpUtil = new CSharpUtil(); StringBuilder sb = new StringBuilder(packageName); sb.append(".V"); sb.append(version); sb.append(CharPool.PERIOD); sb.append(cSharpUtil.getServicePackageName(filter)); packageName = sb.toString(); context.put(CLASS_NAME, cSharpUtil.getServiceClassName(filter)); context.put(DISCOVERY, discovery); context.put(ACTIONS, actions); context.put(ESCAPE_TOOL, new EscapeTool()); context.put(JSON_OBJECT_WRAPPER, CSharpUtil.JSON_OBJECT_WRAPPER); context.put(LANGUAGE_UTIL, cSharpUtil); context.put(PACKAGE, packageName); context.put(STREAM, CSharpUtil.STREAM); context.put(VOID, LanguageUtil.VOID); return context; }
protected VelocityContext getVelocityContext( Discovery discovery, List<Action> actions, String packageName, int version, String filter) { VelocityContext context = new VelocityContext(); JavaUtil javaUtil = new JavaUtil(); StringBuilder sb = new StringBuilder(packageName); sb.append(".v"); sb.append(version); sb.append("."); sb.append(filter); packageName = sb.toString(); String className = javaUtil.getServiceClassName(filter); context.put(BYTE_ARRAY, LanguageUtil.BYTE_ARRAY); context.put(CLASS_NAME, className); context.put(DISCOVERY, discovery); context.put(ACTIONS, excludeMethods(className, actions)); context.put(ESCAPE_TOOL, new EscapeTool()); context.put(UPLOAD_DATA, JavaUtil.UPLOAD_DATA); context.put(INTEGER, JavaUtil.INTEGER); context.put(JSON_OBJECT_WRAPPER, JavaUtil.JSON_OBJECT_WRAPPER); context.put(LANGUAGE_UTIL, javaUtil); context.put(PACKAGE, packageName); context.put(VOID, LanguageUtil.VOID); return context; }
ModelMap model = new ModelMap(); model.put("esc", new EscapeTool()); VelocityEngineUtils.mergeTemplateIntoString( velocityEngine, "template.vm", "UTF-8", model)
/** * Create map with default objects needed in velocity template (e.g. request, current user, messages bundle etc.) * * @param request HttpServletRequest * * @return Map which will be passed into velocity template */ private Map<String, Object> getDefaultModel(HttpServletRequest request) { Map<String, Object> model = new HashMap<>(); model.put("request", request); model.put("dateTool", new JodaDateTimeTool(request)); model.put("esc", new EscapeTool()); JCUser currentUser = getUserReader().getCurrentUser(); PermissionTool tool = new PermissionTool(applicationContext); model.put("currentUser", currentUser); model.put("messages", getLocalizedMessagesBundle(request)); model.put("permissionTool", tool); model.put("propertiesHolder", PropertiesHolder.getInstance()); return model; }
public Generator initEngine() { Context context = createEngineContext(); // 添加公共内置对象 context.setProperty(GENERATOR_TOOL, GeneratorUtils.class); context.setProperty(JAVA_CLASS, Class.class); context.setProperty(INLINE_SOURCE, false); velocityEngine = new VelocityEngine(); if(config.useClasspathResourceLoader()){ // 从classpath加载模板 velocityEngine.setProperty(VelocityEngine.RESOURCE_LOADER, "class"); velocityEngine.setProperty("class.resource.loader.description", "Velocity Multi Class path Resource Loader"); //velocityEngine.setProperty("class.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader"); // 使用自定义的 ResourceLoader velocityEngine.setProperty("class.resource.loader.class", MultiClasspathResourceLoader.class.getName()); velocityEngine.setProperty("class.resource.loader.path", config.getTemplateRoot()); }else{ // 从文件系统加载模板 velocityEngine.setProperty(VelocityEngine.FILE_RESOURCE_LOADER_PATH, config.getTemplateRoot()); } velocityEngine.setProperty(VelocityEngine.INPUT_ENCODING, "UTF-8"); velocityEngine.setProperty(VelocityEngine.OUTPUT_ENCODING, "UTF-8"); velocityContext = new VelocityContext(context.getContext()); // 字符串转义工具 velocityContext.put(VELOCITY_ESC, new EscapeTool()); // 排序工具 velocityContext.put(VELOCITY_SORTER, new SortTool()); return this; }