geirm       01/04/22 11:17:44

  Modified:    src/java/org/apache/velocity/runtime VelocimacroManager.java
                        Runtime.java RuntimeConstants.java
  Log:
  Small changes to support per-template encoding.
  
  VelocimacroManager.java : small change for parse() interface
  Runtime.java : changed getTemplate(), getContent() and parse() to
  support...
  RuntimeConstants.java : added ENCODING_DEFAULT as we need it
  everywhere as a safety constant.
  
  Revision  Changes    Path
  1.10      +7 -5      
jakarta-velocity/src/java/org/apache/velocity/runtime/VelocimacroManager.java
  
  Index: VelocimacroManager.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-velocity/src/java/org/apache/velocity/runtime/VelocimacroManager.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- VelocimacroManager.java   2001/03/20 01:11:15     1.9
  +++ VelocimacroManager.java   2001/04/22 18:17:41     1.10
  @@ -56,8 +56,10 @@
   
   import java.util.Hashtable;
   import java.util.TreeMap;
  -import java.io.ByteArrayInputStream;
   
  +import java.io.StringReader;
  +import java.io.BufferedReader;
  +
   import org.apache.velocity.Template;
   import org.apache.velocity.runtime.directive.Directive;
   import org.apache.velocity.runtime.directive.VelocimacroProxy;
  @@ -82,7 +84,7 @@
    *
    * @author <a href="mailto:[EMAIL PROTECTED]">Geir Magnusson Jr.</a>
    * @author <a href="mailto:[EMAIL PROTECTED]">Jose Alberto Fernandez</a>
  - * @version $Id: VelocimacroManager.java,v 1.9 2001/03/20 01:11:15 jon Exp $ 
  + * @version $Id: VelocimacroManager.java,v 1.10 2001/04/22 18:17:41 geirm Exp $ 
    */
   public class VelocimacroManager
   {
  @@ -360,9 +362,9 @@
           {
               try 
               {
  -
  -                ByteArrayInputStream  inStream = new ByteArrayInputStream( 
macrobody.getBytes() );
  -                nodeTree = Runtime.parse( inStream, "VM:" + macroname );
  +                BufferedReader br = new BufferedReader( new StringReader( macrobody 
) );
  + 
  +                nodeTree = Runtime.parse( br, "VM:" + macroname );
                   nodeTree.init(ica,null);
               } 
               catch ( Exception e ) 
  
  
  
  1.108     +51 -9     
jakarta-velocity/src/java/org/apache/velocity/runtime/Runtime.java
  
  Index: Runtime.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-velocity/src/java/org/apache/velocity/runtime/Runtime.java,v
  retrieving revision 1.107
  retrieving revision 1.108
  diff -u -r1.107 -r1.108
  --- Runtime.java      2001/04/01 02:00:23     1.107
  +++ Runtime.java      2001/04/22 18:17:42     1.108
  @@ -58,8 +58,7 @@
   import java.io.File;
   import java.io.FileInputStream;
   import java.io.IOException;
  -import java.net.URL;
  -import java.net.MalformedURLException;
  +import java.io.Reader;
   
   import java.util.List;
   import java.util.ArrayList;
  @@ -142,7 +141,7 @@
    * @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a>
    * @author <a href="mailto:[EMAIL PROTECTED]">Jeff Bowden</a>
    * @author <a href="mailto:[EMAIL PROTECTED]">Geir Magusson Jr.</a>
  - * @version $Id: Runtime.java,v 1.107 2001/04/01 02:00:23 jon Exp $
  + * @version $Id: Runtime.java,v 1.108 2001/04/22 18:17:42 geirm Exp $
    */
   public class Runtime implements RuntimeConstants
   {    
  @@ -583,7 +582,7 @@
        * @param InputStream inputstream retrieved by a resource loader
        * @param String name of the template being parsed
        */
  -    public static SimpleNode parse(InputStream inputStream, String templateName )
  +    public static SimpleNode parse( Reader reader, String templateName )
           throws ParseException
       {
           SimpleNode ast = null;
  @@ -617,7 +616,7 @@
           {
               try
               {
  -                ast = parser.parse(inputStream, templateName);
  +                ast = parser.parse( reader, templateName );
               }
               finally
               {
  @@ -650,7 +649,10 @@
       }
       
       /**
  -     * Returns a <code>Template</code> from the resource manager
  +     * Returns a <code>Template</code> from the resource manager.
  +     * This method assumes that the character encoding of the 
  +     * template is set by the <code>input.encoding</code>
  +     * property.  The default is "ISO-8859-1"
        *
        * @param name The file name of the desired template.
        * @return     The template.
  @@ -663,13 +665,32 @@
       public static Template getTemplate(String name)
           throws ResourceNotFoundException, ParseErrorException, Exception
       {
  +        return getTemplate( name, Runtime.getString( INPUT_ENCODING, 
ENCODING_DEFAULT) );
  +    }
  +
  +    /**
  +     * Returns a <code>Template</code> from the resource manager
  +     *
  +     * @param name The  name of the desired template.
  +     * @param encoding Character encoding of the template
  +     * @return     The template.
  +     * @throws ResourceNotFoundException if template not found
  +     *          from any available source.
  +     * @throws ParseErrorException if template cannot be parsed due
  +     *          to syntax (or other) error.
  +     * @throws Exception if an error occurs in template initialization
  +     */
  +    public static Template getTemplate(String name, String  encoding)
  +        throws ResourceNotFoundException, ParseErrorException, Exception
  +    {
           return (Template) ResourceManager
  -            .getResource(name,ResourceManager.RESOURCE_TEMPLATE);
  +            .getResource(name,ResourceManager.RESOURCE_TEMPLATE, encoding);
       }
   
       /**
        * Returns a static content resource from the
  -     * resource manager.
  +     * resource manager.  Uses the current value
  +     * if INPUT_ENCODING as the character encoding.
        *
        * @param name Name of content resource to get
        * @return parsed ContentResource object ready for use
  @@ -679,8 +700,29 @@
       public static ContentResource getContent(String name)
           throws ResourceNotFoundException, ParseErrorException, Exception
       {
  +        /*
  +         *  the encoding is irrelvant as we don't do any converstion
  +         *  the bytestream should be dumped to the output stream
  +         */
  +
  +        return getContent( name,  Runtime.getString( INPUT_ENCODING, 
ENCODING_DEFAULT));
  +    }
  +
  +    /**
  +     * Returns a static content resource from the
  +     * resource manager.
  +     *
  +     * @param name Name of content resource to get
  +     * @param encoding Character encoding to use
  +     * @return parsed ContentResource object ready for use
  +     * @throws ResourceNotFoundException if template not found
  +     *          from any available source.
  +     */
  +    public static ContentResource getContent( String name, String encoding )
  +        throws ResourceNotFoundException, ParseErrorException, Exception
  +    {
           return (ContentResource) ResourceManager
  -            .getResource(name,ResourceManager.RESOURCE_CONTENT);
  +            .getResource(name,ResourceManager.RESOURCE_CONTENT, encoding );
       }
   
       /**
  
  
  
  1.25      +3 -1      
jakarta-velocity/src/java/org/apache/velocity/runtime/RuntimeConstants.java
  
  Index: RuntimeConstants.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-velocity/src/java/org/apache/velocity/runtime/RuntimeConstants.java,v
  retrieving revision 1.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- RuntimeConstants.java     2001/04/14 02:52:26     1.24
  +++ RuntimeConstants.java     2001/04/22 18:17:42     1.25
  @@ -62,7 +62,7 @@
    * @author <a href="mailto:[EMAIL PROTECTED]">Jon S. Stevens</a>
    * @author <a href="mailto:[EMAIL PROTECTED]">Geir Magnusson Jr.</a>
    * @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a>
  - * @version $Id: RuntimeConstants.java,v 1.24 2001/04/14 02:52:26 geirm Exp $
  + * @version $Id: RuntimeConstants.java,v 1.25 2001/04/22 18:17:42 geirm Exp $
    */
   public interface RuntimeConstants
   {
  @@ -341,6 +341,8 @@
        *  Encoding for the output stream.  Currently used by Anakia and 
VelocityServlet
        */
       public static final String OUTPUT_ENCODING = "output.encoding";
  +
  +    public static final String ENCODING_DEFAULT = "ISO-8859-1";
   
       /*
        * ----------------------------------------------------------------------
  
  
  

Reply via email to