[prev in list] [next in list] [prev in thread] [next in thread] 

List:       velocity-dev
Subject:    [jira] [Created] (VELOCITY-809) RuntimeInstance returns template
From:       "Dark Mortal (JIRA)" <dev () velocity ! apache ! org>
Date:       2011-08-16 11:40:27
Message-ID: 757857785.41059.1313494827194.JavaMail.tomcat () hel ! zones ! apache ! org
[Download RAW message or body]

RuntimeInstance returns template with incorrect encoding (if not specified) when not \
                initialized before
-------------------------------------------------------------------------------------------------------


                 Key: VELOCITY-809
                 URL: https://issues.apache.org/jira/browse/VELOCITY-809
             Project: Velocity
          Issue Type: Bug
          Components: Engine
    Affects Versions: 1.7
            Reporter: Dark Mortal


RuntimeInstance has 

public Template getTemplate(String name)
        throws ResourceNotFoundException, ParseErrorException
{
        return getTemplate(name, getDefaultEncoding());
}

so if RuntimeInstance was not initialized before this method was called then it \
provides default encoding (ENCODING_DEFAULT = "ISO-8859-1") for getDefaultEncoding() \
instead of those that was set using

.setProperty(RuntimeConstants.INPUT_ENCODING, "UTF-8")

and Template contents incorrectly loaded.

This is so because initialization is done one step after a call of \
getDefaultEncoding() inside method

public Template getTemplate(String name, String  encoding)
        throws ResourceNotFoundException, ParseErrorException
{
        requireInitialization();

        return (Template)
                resourceManager.getResource(name,
                    ResourceManager.RESOURCE_TEMPLATE, encoding);
}

Solution is to add requireInitialization(); before  return getTemplate(name, \
getDefaultEncoding()); line in the first method. OR
accept encoding == null in the second method:

public Template getTemplate(String name)
        throws ResourceNotFoundException, ParseErrorException
{
        return getTemplate(name, null);
}

public Template getTemplate(String name, String  encoding)
        throws ResourceNotFoundException, ParseErrorException
{
        requireInitialization();

        if (encoding == null)
                encoding = getDefaultEncoding();

        return (Template)
                resourceManager.getResource(name,
                    ResourceManager.RESOURCE_TEMPLATE, encoding);
}

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@velocity.apache.org
For additional commands, e-mail: dev-help@velocity.apache.org


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic