Package org.apache.velocity.runtime.resource

Examples of org.apache.velocity.runtime.resource.Resource


     * from.
     * @return The encoding to use when processing this directive.
     */
    protected String getInputEncoding(InternalContextAdapter context)
    {
        Resource current = context.getCurrentResource();
        if (current != null)
        {
            return current.getEncoding();
        }
        else
        {
            return (String) rsvc.getProperty(RuntimeConstants.INPUT_ENCODING);
        }
View Full Code Here


    public void testFetResource() throws Exception {
        SQLTemplateResourceManager rm = new SQLTemplateResourceManager();
        rm.initialize(new MockupRuntimeServices());

        Resource resource = rm.getResource(
                "abc",
                ResourceManager.RESOURCE_TEMPLATE,
                RuntimeConstants.ENCODING_DEFAULT);

        assertTrue(resource instanceof Template);
View Full Code Here

            rsvc.error( "Max recursion depth reached (" +
                templateStack.length + ")"  + " File stack:" + path );
            return false;
        }

        Resource current = context.getCurrentResource();

        /*
         *  get the resource, and assume that we use the encoding of the current template
         *  the 'current resource' can be null if we are processing a stream....
         */

        String encoding = null;

        if ( current != null)
        {
            encoding = current.getEncoding();
        }
        else
        {
            encoding = (String) rsvc.getProperty( RuntimeConstants.INPUT_ENCODING);
        }
View Full Code Here

        /*
         *  get the path
         */
        arg = value.toString();

        Resource resource = null;

        Resource current = context.getCurrentResource();

        try
        {
            /*
             *  get the resource, and assume that we use the encoding of the current template
             *  the 'current resource' can be null if we are processing a stream....
             */

            String encoding = null;

            if ( current != null)
            {
                encoding = current.getEncoding();
            }
            else
            {
                encoding = (String) rsvc.getProperty( RuntimeConstants.INPUT_ENCODING);
            }
View Full Code Here

        /*
         *  get the path
         */
        arg = value.toString();

        Resource resource = null;
       
        try
        {
            resource = Runtime.getContent(arg);
        }
        catch (Exception e)
        {
            Runtime.error("#include : cannot find " + arg + " template!");
        }           
       
        if ( resource == null )
            return false;
      
        writer.write((String)resource.getData());      
        return true;
    }
View Full Code Here

        /*
         *  get the path
         */
        arg = value.toString();

        Resource resource = null;

        Resource current = context.getCurrentResource();

        try
        {
            /*
             *  get the resource, and assume that we use the encoding of the current template
             */
            resource = Runtime.getContent(arg, current.getEncoding());
        }
        catch (Exception e)
        {
            Runtime.error("#include : cannot find " + arg + " template!");
        }           
View Full Code Here

        }
    }

    @Test
    public void isSourceModified() throws Exception {
        Resource templateResource = new Template();
        long lastModified = factory.getResource("/templates/test.vm").lastModified();

        // 资源/templates/test.vm支持lastModified,但时间不同
        templateResource.setLastModified(1);
        templateResource.setName("/test.vm");

        assertTrue(lastModified != templateResource.getLastModified());
        assertTrue(velocityLoader.isSourceModified(templateResource));

        // 资源/templates/test.vm支持lastModified,时间相同
        templateResource.setLastModified(lastModified);
        templateResource.setName("/test.vm");

        assertEquals(lastModified, templateResource.getLastModified());
        assertFalse(velocityLoader.isSourceModified(templateResource));

        // 资源/templates/notExist.vm不存在,看作被修改了
        templateResource.setLastModified(1);
        templateResource.setName("/notExist.vm");

        assertFalse(factory.getResource("/templates/notExist.vm").exists());
        assertTrue(velocityLoader.isSourceModified(templateResource));

        // 资源/templates/test2.vm存在,但不支持lastModified,看作未修改
        templateResource.setLastModified(1);
        templateResource.setName("/test2.vm");

        lastModified = factory.getResource("/templates/test2.vm").lastModified();

        assertEquals(0, lastModified);
        assertFalse(velocityLoader.isSourceModified(templateResource));

        // 模板名为空
        templateResource.setName(null);

        try {
            velocityLoader.isSourceModified(templateResource);
            fail();
        } catch (org.apache.velocity.exception.ResourceNotFoundException e) {
View Full Code Here

        }
    }

    @Test
    public void getLastModified() throws Exception {
        Resource templateResource = new Template();
        long lastModified = factory.getResource("/templates/test.vm").lastModified();

        // 资源/templates/test.vm支持lastModified
        templateResource.setName("/test.vm");
        assertEquals(lastModified, velocityLoader.getLastModified(templateResource));

        // 资源/templates/notExist.vm不存在,返回0
        templateResource.setName("/notExist.vm");
        assertEquals(0, velocityLoader.getLastModified(templateResource));

        // 资源/templates/test2.vm存在,但不支持lastModified,返回0
        templateResource.setName("/test2.vm");
        assertEquals(0, factory.getResource("/templates/test2.vm").lastModified());
        assertEquals(0, velocityLoader.getLastModified(templateResource));

        // 模板名为空
        templateResource.setName(null);

        try {
            velocityLoader.getLastModified(templateResource);
            fail();
        } catch (org.apache.velocity.exception.ResourceNotFoundException e) {
View Full Code Here

        }
    }

    @Test
    public void isSourceModified() throws Exception {
        Resource templateResource = new Template();
        long lastModified = factory.getResource("/templates/test.vm").lastModified();

        // 资源/templates/test.vm支持lastModified,但时间不同
        templateResource.setLastModified(1);
        templateResource.setName("/macros/a.vm");

        assertTrue(lastModified != templateResource.getLastModified());
        assertTrue(velocityLoader.isSourceModified(templateResource));

        // 资源/templates/test.vm支持lastModified,时间相同
        templateResource.setLastModified(lastModified);
        templateResource.setName("/macros/a.vm");

        assertEquals(lastModified, templateResource.getLastModified());
        assertFalse(velocityLoader.isSourceModified(templateResource));

        // 资源/templates/notExist.vm不存在,看作被修改了
        templateResource.setLastModified(1);
        templateResource.setName("/notExist.vm");

        assertFalse(factory.getResource("/templates/notExist.vm").exists());
        assertTrue(velocityLoader.isSourceModified(templateResource));

        // 资源/templates/test2.vm存在,但不支持lastModified,看作未修改
        templateResource.setLastModified(1);
        templateResource.setName("/macros/c.vm");

        lastModified = factory.getResource("/templates/test2.vm").lastModified();

        assertEquals(0, lastModified);
        assertFalse(velocityLoader.isSourceModified(templateResource));

        // 模板名为空
        templateResource.setName(null);

        try {
            velocityLoader.isSourceModified(templateResource);
            fail();
        } catch (org.apache.velocity.exception.ResourceNotFoundException e) {
View Full Code Here

        }
    }

    @Test
    public void getLastModified() throws Exception {
        Resource templateResource = new Template();
        long lastModified = factory.getResource("/templates/test.vm").lastModified();

        // 资源/templates/test.vm支持lastModified
        templateResource.setName("/macros/a.vm");
        assertEquals(lastModified, velocityLoader.getLastModified(templateResource));

        // 资源/templates/notExist.vm不存在,返回0
        templateResource.setName("/notExist.vm");
        assertEquals(0, velocityLoader.getLastModified(templateResource));

        // 资源/templates/test2.vm存在,但不支持lastModified,返回0
        templateResource.setName("/macros/c.vm");
        assertEquals(0, velocityLoader.getLastModified(templateResource));

        // 模板名为空
        templateResource.setName(null);

        try {
            velocityLoader.getLastModified(templateResource);
            fail();
        } catch (org.apache.velocity.exception.ResourceNotFoundException e) {
View Full Code Here

TOP

Related Classes of org.apache.velocity.runtime.resource.Resource

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.