Package org.restlet.ext.velocity

Examples of org.restlet.ext.velocity.TemplateRepresentation


        // Representation approach
        Reference ref = LocalReference.createFileReference(testFile);
        ClientResource r = new ClientResource(ref);
        Representation templateFile = r.get();
        TemplateRepresentation tr = new TemplateRepresentation(templateFile,
                map, MediaType.TEXT_PLAIN);
        final String result = tr.getText();
        assertEquals("Value=myValue", result);

        // Clean-up
        BioUtils.delete(testFile);
        BioUtils.delete(testDir, true);
View Full Code Here


        final Map<String, Object> map = new TreeMap<String, Object>();
        map.put("value", "myValue");

        // Standard approach
        final TemplateRepresentation tr = new TemplateRepresentation(testFile
                .getName(), map, MediaType.TEXT_PLAIN);
        tr.getEngine().setProperty("file.resource.loader.path",
                testDir.getAbsolutePath());
        final String result = tr.getText();
        assertEquals("Value=myValue", result);

        // Clean-up
        BioUtils.delete(testFile);
        BioUtils.delete(testDir, true);
View Full Code Here

            }

            enrichedModel.put("encoder", new EncoderBean());
            enrichedModel.put("request", getRequest());

            return new TemplateRepresentation(template, enrichedModel, MediaType.TEXT_HTML);

        }
        else if (MediaType.TEXT_PLAIN.equals(variant.getMediaType()))
        {

            Map<String, Object> enrichedModel = new HashMap<String, Object>(getModel());

            Template template;
            try
            {
                VelocityEngine ve = new VelocityEngine();

                Properties p = new Properties();
                p.setProperty("resource.loader", "class");
                p.setProperty("class.resource.loader.description",
                        "Velocity Classpath Resource Loader");
                p.setProperty("class.resource.loader.class",
                        "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");

                ve.init(p);

                template =
                        ve.getTemplate("jminix/templates/"
                                + getTemplateName() + "-plain.vm");
            }
            catch (Exception e)
            {
                throw new RuntimeException(e);
            }

            enrichedModel.put("encoder", new EncoderBean());
            enrichedModel.put("request", getRequest());

            return new TemplateRepresentation(template, enrichedModel, MediaType.TEXT_PLAIN);

        }
        else if (MediaType.APPLICATION_JSON.equals(variant.getMediaType()))
        {
            // Translate known models, needs a refactoring to embed that in each resource...
View Full Code Here

TOP

Related Classes of org.restlet.ext.velocity.TemplateRepresentation

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.