@Override public void afterPropertiesSet() { Properties properties = new Properties(); // this is setup so that file takes preference over classpath, so that we can reload stuff in dev environment // and fallback to spring classloader in prod environment properties.setProperty(RESOURCE_LOADER, "file," + SpringResourceLoader.NAME); properties.setProperty(FILE_RESOURCE_LOADER_CACHE, "true"); properties.setProperty(EVENTHANDLER_REFERENCEINSERTION, org.apache.velocity.app.event.implement.EscapeHtmlReference.class.getName()); properties.setProperty(FILE_RESOURCE_LOADER_PATH, resourceBasePaths); properties.setProperty("file.resource.loader.modificationCheckInterval", String.valueOf(modificationCheckInterval)); properties.setProperty(SpringResourceLoader.SPRING_RESOURCE_LOADER_CLASS, SpringResourceLoader.class.getName()); properties.setProperty(SpringResourceLoader.SPRING_RESOURCE_LOADER_CACHE, "true"); if (modificationCheckInterval != 0) { properties.setProperty(VM_LIBRARY_AUTORELOAD, "true"); } properties.setProperty(VM_LIBRARY, "macros/urls.vm"); this.velocityEngine = new VelocityEngine(properties); this.velocityEngine.setApplicationAttribute(SpringResourceLoader.SPRING_RESOURCE_LOADER, resourceLoader); this.velocityEngine.setApplicationAttribute(SpringResourceLoader.SPRING_RESOURCE_LOADER_PATH, resourceBasePaths); }
/** * Provides a ClasspathResourceLoader in addition to any default or user-defined * loader in order to load the spring Velocity macros from the class path. * @see org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader * @param velocityEngine engine */ @Override protected void postProcessVelocityEngine(VelocityEngine velocityEngine) { velocityEngine.setApplicationAttribute(ServletContext.class.getName(), this.servletContext); }
VelocityEngine velocityEngine = new VelocityEngine(); velocityEngine.setApplicationAttribute("javax.servlet.ServletContext", context);
@PostConstruct public void init() { velocityEngine = new VelocityEngine(); velocityEngine.setProperty("resource.loader", "webapp"); velocityEngine.setProperty("webapp.resource.loader.class", "org.apache.velocity.tools.view.servlet.WebappLoader"); velocityEngine.setApplicationAttribute("javax.servlet.ServletContext", servletContext); velocityEngine.init(); }
private void renderView(HttpServletRequest request, HttpServletResponse response, SimpleTaskDescriptorBean task) throws ServletException { try { // use our own velocity instance, we can't use jira velocity manager // because it is in spring final VelocityEngine velocityEngine = new VelocityEngine(); Properties props = new Properties(); props.put("resource.loader", "class"); props.put("class.resource.loader.description", "Velocity Classpath Resource Loader"); props.put("class.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader"); VelocityEngineFactory.Default.enableDevMode(props); props.setProperty("runtime.log.logsystem.class", "org.apache.velocity.runtime.log.SimpleLog4JLogSystem"); props.setProperty("runtime.log.logsystem.log4j.category", "velocity"); props.setProperty("velocimacro.library", ""); velocityEngine.setApplicationAttribute("javax.servlet.ServletContext", servletContext); velocityEngine.init(props); final Template template = velocityEngine.getTemplate("/templates/jira/importprogress/dataimportprogress.vm"); VelocityContext context = new VelocityContext(); context.put("resourcesHtml", MetalResourcesManager.getMetalResources(request.getContextPath())); context.put("task", task); template.merge(context, response.getWriter()); } catch (Exception e) { throw new ServletException(e); } }
ve.setApplicationAttribute(SummonDirective.GUZZ_CONTEXT_NAME, this.guzzContext) ; ve.setApplicationAttribute("guzz_vts_templates_name", templates) ;
/** * Provides a ClasspathResourceLoader in addition to any default or user-defined * loader in order to load the spring Velocity macros from the class path. * @see ClasspathResourceLoader */ @Override protected void postProcessVelocityEngine(VelocityEngine velocityEngine) { velocityEngine.setApplicationAttribute(ServletContext.class.getName(), this.servletContext); velocityEngine.setProperty( SPRING_MACRO_RESOURCE_LOADER_CLASS, ClasspathResourceLoader.class.getName()); velocityEngine.addProperty( VelocityEngine.RESOURCE_LOADER, SPRING_MACRO_RESOURCE_LOADER_NAME); velocityEngine.addProperty( VelocityEngine.VM_LIBRARY, SPRING_MACRO_LIBRARY); if (logger.isInfoEnabled()) { logger.info("ClasspathResourceLoader with name '" + SPRING_MACRO_RESOURCE_LOADER_NAME + "' added to configured VelocityEngine"); } }
/** * Provides a ClasspathResourceLoader in addition to any default or user-defined * loader in order to load the spring Velocity macros from the class path. * @see ClasspathResourceLoader */ @Override protected void postProcessVelocityEngine(VelocityEngine velocityEngine) { velocityEngine.setApplicationAttribute(ServletContext.class.getName(), this.servletContext); velocityEngine.setProperty( SPRING_MACRO_RESOURCE_LOADER_CLASS, ClasspathResourceLoader.class.getName()); velocityEngine.addProperty( VelocityEngine.RESOURCE_LOADER, SPRING_MACRO_RESOURCE_LOADER_NAME); velocityEngine.addProperty( VelocityEngine.VM_LIBRARY, SPRING_MACRO_LIBRARY); if (logger.isInfoEnabled()) { logger.info("ClasspathResourceLoader with name '" + SPRING_MACRO_RESOURCE_LOADER_NAME + "' added to configured VelocityEngine"); } }
/** * Provides a ClasspathResourceLoader in addition to any default or user-defined * loader in order to load the spring Velocity macros from the class path. * @see org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader */ @Override protected void postProcessVelocityEngine(VelocityEngine velocityEngine) { velocityEngine.setApplicationAttribute(ServletContext.class.getName(), this.servletContext); velocityEngine.setProperty( SPRING_MACRO_RESOURCE_LOADER_CLASS, ClasspathResourceLoader.class.getName()); velocityEngine.addProperty( VelocityEngine.RESOURCE_LOADER, SPRING_MACRO_RESOURCE_LOADER_NAME); velocityEngine.addProperty( VelocityEngine.VM_LIBRARY, SPRING_MACRO_LIBRARY); if (logger.isInfoEnabled()) { logger.info("ClasspathResourceLoader with name '" + SPRING_MACRO_RESOURCE_LOADER_NAME + "' added to configured VelocityEngine"); } }
/** * Initialize a SpringResourceLoader for the given VelocityEngine. * <p>Called by {@code initVelocityResourceLoader}. * @param velocityEngine the VelocityEngine to configure * @param resourceLoaderPath the path to load Velocity resources from * @see SpringResourceLoader * @see #initVelocityResourceLoader */ protected void initSpringResourceLoader(VelocityEngine velocityEngine, String resourceLoaderPath) { velocityEngine.setProperty( RuntimeConstants.RESOURCE_LOADER, SpringResourceLoader.NAME); velocityEngine.setProperty( SpringResourceLoader.SPRING_RESOURCE_LOADER_CLASS, SpringResourceLoader.class.getName()); velocityEngine.setProperty( SpringResourceLoader.SPRING_RESOURCE_LOADER_CACHE, "true"); velocityEngine.setApplicationAttribute( SpringResourceLoader.SPRING_RESOURCE_LOADER, getResourceLoader()); velocityEngine.setApplicationAttribute( SpringResourceLoader.SPRING_RESOURCE_LOADER_PATH, resourceLoaderPath); }
@Override public void initialize(Properties overridingProperties) throws XWikiVelocityException { org.apache.velocity.app.VelocityEngine velocityEngine = new org.apache.velocity.app.VelocityEngine(); // Add the Component Manager to allow Velocity extensions to lookup components. velocityEngine.setApplicationAttribute(ComponentManager.class.getName(), this.componentManager); // Set up properties initializeProperties(velocityEngine, this.velocityConfiguration.getProperties(), overridingProperties); // Set up directives velocityEngine.loadDirective(TryCatchDirective.class.getName()); try { velocityEngine.init(); } catch (Exception e) { throw new XWikiVelocityException("Cannot start the Velocity engine", e); } this.engine = velocityEngine; }
/** * Initialize a SpringResourceLoader for the given VelocityEngine. * <p>Called by {@code initVelocityResourceLoader}. * @param velocityEngine the VelocityEngine to configure * @param resourceLoaderPath the path to load Velocity resources from * @see SpringResourceLoader * @see #initVelocityResourceLoader */ protected void initSpringResourceLoader(VelocityEngine velocityEngine, String resourceLoaderPath) { velocityEngine.setProperty( RuntimeConstants.RESOURCE_LOADER, SpringResourceLoader.NAME); velocityEngine.setProperty( SpringResourceLoader.SPRING_RESOURCE_LOADER_CLASS, SpringResourceLoader.class.getName()); velocityEngine.setProperty( SpringResourceLoader.SPRING_RESOURCE_LOADER_CACHE, "true"); velocityEngine.setApplicationAttribute( SpringResourceLoader.SPRING_RESOURCE_LOADER, getResourceLoader()); velocityEngine.setApplicationAttribute( SpringResourceLoader.SPRING_RESOURCE_LOADER_PATH, resourceLoaderPath); }
/** * Initialize a SpringResourceLoader for the given VelocityEngine. * <p>Called by {@code initVelocityResourceLoader}. * @param velocityEngine the VelocityEngine to configure * @param resourceLoaderPath the path to load Velocity resources from * @see SpringResourceLoader * @see #initVelocityResourceLoader */ protected void initSpringResourceLoader(VelocityEngine velocityEngine, String resourceLoaderPath) { velocityEngine.setProperty( RuntimeConstants.RESOURCE_LOADER, SpringResourceLoader.NAME); velocityEngine.setProperty( SpringResourceLoader.SPRING_RESOURCE_LOADER_CLASS, SpringResourceLoader.class.getName()); velocityEngine.setProperty( SpringResourceLoader.SPRING_RESOURCE_LOADER_CACHE, "true"); velocityEngine.setApplicationAttribute( SpringResourceLoader.SPRING_RESOURCE_LOADER, getResourceLoader()); velocityEngine.setApplicationAttribute( SpringResourceLoader.SPRING_RESOURCE_LOADER_PATH, resourceLoaderPath); }
/** * Initialize a SpringResourceLoader for the given VelocityEngine. * <p>Called by {@code initVelocityResourceLoader}. * @param velocityEngine the VelocityEngine to configure * @param resourceLoaderPath the path to load Velocity resources from * @see SpringResourceLoader * @see #initVelocityResourceLoader */ protected void initSpringResourceLoader(VelocityEngine velocityEngine, String resourceLoaderPath) { velocityEngine.setProperty( RuntimeConstants.RESOURCE_LOADER, SpringResourceLoader.NAME); velocityEngine.setProperty( SpringResourceLoader.SPRING_RESOURCE_LOADER_CLASS, SpringResourceLoader.class.getName()); velocityEngine.setProperty( SpringResourceLoader.SPRING_RESOURCE_LOADER_CACHE, "true"); velocityEngine.setApplicationAttribute( SpringResourceLoader.SPRING_RESOURCE_LOADER, getResourceLoader()); velocityEngine.setApplicationAttribute( SpringResourceLoader.SPRING_RESOURCE_LOADER_PATH, resourceLoaderPath); }
/** * Initialize a SpringResourceLoader for the given VelocityEngine. * <p> * Called by {@code initVelocityResourceLoader}. * * @param velocityEngine the VelocityEngine to configure * @param resourceLoaderPath the path to load Velocity resources from * @see SpringResourceLoader * @see #initVelocityResourceLoader */ protected void initSpringResourceLoader(VelocityEngine velocityEngine, String resourceLoaderPath) { velocityEngine.setProperty( RuntimeConstants.RESOURCE_LOADER, SpringResourceLoader.NAME); velocityEngine.setProperty( SpringResourceLoader.SPRING_RESOURCE_LOADER_CLASS, SpringResourceLoader.class.getName()); velocityEngine.setProperty( SpringResourceLoader.SPRING_RESOURCE_LOADER_CACHE, "true"); velocityEngine.setApplicationAttribute( SpringResourceLoader.SPRING_RESOURCE_LOADER, getResourceLoader()); velocityEngine.setApplicationAttribute( SpringResourceLoader.SPRING_RESOURCE_LOADER_PATH, resourceLoaderPath); }
public VelocityEngine getValue() { if (ve == null) { LOG.info("Ready to start velocity"); ve = new VelocityEngine(); ve.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS, "org.apache.velocity.runtime.log.Log4JLogChute"); ve.setProperty("runtime.log.logsystem.log4j.logger", LOGGER_NAME); ve.setProperty(RuntimeConstants.RESOURCE_LOADER, "webapp"); ve.setProperty("webapp.resource.loader.class", "org.apache.velocity.tools.view.WebappResourceLoader"); ve.setProperty("webapp.resource.loader.path", "/WEB-INF/vm/"); ve.setApplicationAttribute( "javax.servlet.ServletContext", servletContext); try { ve.init(); LOG.info("Velocity is loaded"); } catch (Exception e) { LOG.error("Error when initializing Velocity", e); } } return ve; } };
velocityEngine.setApplicationAttribute( INSTANCE_ID, id ); if ( logChute != null )
VelocityEngine.VM_LIBRARY, PLUGIN_MACRO_LIBRARY); velocityEngine.setApplicationAttribute(VelocityPluginResourceLoader.PLUGIN_MANAGER, pluginManager);
velocity.setApplicationAttribute(SERVLET_CONTEXT_KEY, getServletContext()); velocity.setProperty(VelocityEngine.RUNTIME_LOG_LOGSYSTEM_CLASS, "org.apache.velocity.tools.view.servlet.ServletLogger"); ExtendedProperties configuration = loadConfiguration(getServletConfig());
velocity.setApplicationAttribute(SERVLET_CONTEXT_KEY, getServletContext());