Package org.apache.velocity.app

Examples of org.apache.velocity.app.VelocityEngine


            final String vlcText,
            final VelocityContext context) throws Exception {
        //-- raise event --//
        super.doEvent(new OnBeforeEvaluate(this, context));
        //-- evaluate template --//
        final VelocityEngine engine = this.getNativeEngine();
        final StringWriter writer = new StringWriter();
        engine.evaluate(context, writer, templateName, vlcText);

        return this.replaceUnsolvedVariables(writer.toString());
    }
View Full Code Here


            throw new IllegalArgumentException(gripe);
        }

        Properties p = loadConfiguration(context);

        VelocityEngine velocityEngine = new VelocityEngine();

        //  Set the velocity attribute for the servlet context
        //  if this is not set the webapp loader WILL NOT WORK
        velocityEngine.setApplicationAttribute(ServletContext.class.getName(),
                context);

        try {
            velocityEngine.init(p);
        } catch (Exception e) {
            String gripe = "Unable to instantiate VelocityEngine!";
            throw new StrutsException(gripe, e);
        }
View Full Code Here

        /*
         *  now initialize Velocity - we need to do that
         *  on change of stylesheet
         */

        ve = new VelocityEngine();

        /*
         * if there are user properties, set those first - carefully
         */

 
View Full Code Here

        return "velocity:" + getResourceUri();
    }

    private synchronized VelocityEngine getVelocityEngine() throws Exception {
        if (velocityEngine == null) {
            velocityEngine = new VelocityEngine();
            Properties properties = new Properties();
            // load the velocity properties from property file
            if (ObjectHelper.isNotEmpty(getPropertiesFile())) {
                Resource resource = getResourceLoader().getResource(getPropertiesFile());
                InputStream reader = resource.getInputStream();
View Full Code Here

        String logTag = getClass().getName();
        Map variableMap = ExchangeHelper.createVariableMap(exchange);
        Context velocityContext = new VelocityContext(variableMap);

        // let velocity parse and generate the result in buffer
        VelocityEngine engine = getVelocityEngine();
        if (log.isDebugEnabled()) {
            log.debug("Velocity is evaluating using velocity context: " + variableMap);
        }
        engine.evaluate(velocityContext, buffer, logTag, reader);

        // now lets output the results to the exchange
        Message out = exchange.getOut();
        out.setBody(buffer.toString());
View Full Code Here

        try
        {
            final Properties props = new Properties();
            props.setProperty("resource.loader", "classpath");
            props.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName());
            VelocityEngine engine = new VelocityEngine(props);
            engine.init();
            return engine;
        }
        catch( Exception e )
        {
            throw new MojoExecutionException("Unable to initialize velocity context.", e);
View Full Code Here

        try
        {
            final File file = new File(srcDirectory, className.replace('.', '/') + ".java");
            file.getParentFile().mkdirs();
            getLog().info("Generating source file " + file.getAbsolutePath() + "...");
            VelocityEngine engine = createVelocityEngine();
            final Template template = engine.getTemplate(templateName);
            final FileWriter fw = new FileWriter(file);
            template.merge(context, fw);
            fw.close();
        }
        catch( Exception e )
View Full Code Here

        String logTag = getClass().getName();
        Map variableMap = ExchangeHelper.createVariableMap(exchange);
        Context velocityContext = new VelocityContext(variableMap);

        // let velocity parse and generate the result in buffer
        VelocityEngine engine = getVelocityEngine();
        if (log.isDebugEnabled()) {
            log.debug("Velocity is evaluating using velocity context: " + variableMap);
        }
        engine.evaluate(velocityContext, buffer, logTag, reader);

        // now lets output the results to the exchange
        Message out = exchange.getOut(true);
        out.setBody(buffer.toString());
        out.setHeader("org.apache.camel.velocity.resource", resource);
View Full Code Here

        Reader reader = new InputStreamReader(getResource().getInputStream());
        StringWriter buffer = new StringWriter();
        String logTag = getClass().getName();
        Map variableMap = ExchangeHelper.createVariableMap(exchange);
        Context velocityContext = new VelocityContext(variableMap);
        VelocityEngine engine = getVelocityEngine();
        engine.evaluate(velocityContext, buffer, logTag, reader);

        // now lets output the results to the exchange
        Message out = exchange.getOut(true);
        out.setBody(buffer.toString());
        out.setHeader("org.apache.camel.velocity.resource", getResource());
View Full Code Here

     * template using the VelocityEngine instance.
     *
     * @since 1.2
     */
    private void initializeClassTemplate(String template) throws CayenneRuntimeException {
        VelocityEngine velocityEngine = new VelocityEngine();
        try {

            // use ClasspathResourceLoader for velocity templates lookup
            // if Cayenne URL is not null, load resource from this URL
            Properties props = new Properties();

            // null logger that will prevent velocity.log from being generated
            props.put(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS, NullLogSystem.class
                    .getName());

            props.put("resource.loader", "cayenne");

            props.put("cayenne.resource.loader.class", ClassGeneratorResourceLoader.class
                    .getName());
            velocityEngine.init(props);
        }
        catch (Exception ex) {
            throw new CayenneRuntimeException("Can't initialize Velocity", ex);
        }

        try {
            classTemplate = velocityEngine.getTemplate(template);
        }
        catch (Exception ex) {
            throw new CayenneRuntimeException("Can't create template: " + template, ex);
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.velocity.app.VelocityEngine

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.