geirm 01/04/13 19:50:19
Modified: src/java/org/apache/velocity/runtime/parser Parser.jjt
Log:
Added support for alternate character encoding in the inputstream's (templates...)
Revision Changes Path
1.58 +31 -2
jakarta-velocity/src/java/org/apache/velocity/runtime/parser/Parser.jjt
Index: Parser.jjt
===================================================================
RCS file:
/home/cvs/jakarta-velocity/src/java/org/apache/velocity/runtime/parser/Parser.jjt,v
retrieving revision 1.57
retrieving revision 1.58
diff -u -r1.57 -r1.58
--- Parser.jjt 2001/03/05 11:46:36 1.57
+++ Parser.jjt 2001/04/14 02:50:19 1.58
@@ -120,7 +120,7 @@
*
* @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Geir Magnusson Jr.</a>
- * @version $Id: Parser.jjt,v 1.57 2001/03/05 11:46:36 jvanzyl Exp $
+ * @version $Id: Parser.jjt,v 1.58 2001/04/14 02:50:19 geirm Exp $
*/
public class Parser
{
@@ -134,6 +134,11 @@
*/
String currentTemplateName = "";
+ /**
+ * encoding for the input stream.
+ */
+ private String inputEncoding = "ISO-8859-1";
+
/**
* This constructor was added to allow the re-use of parsers.
* The normal constructor takes a single argument which
@@ -144,6 +149,11 @@
public Parser()
{
this(new ByteArrayInputStream("\n".getBytes()));
+
+ /*
+ * get the encoding property. Default is ISO latin
+ */
+ inputEncoding = Runtime.getString( Runtime.INPUT_ENCODING, "ISO-8859-1");
}
/**
@@ -171,10 +181,29 @@
Runtime.dumpVMNamespace( currentTemplateName );
+ /*
+ * wrap in a reader so users can control the encoding
+ * of the template
+ */
+
+ BufferedReader br = null;
+
+ try
+ {
+ br = new BufferedReader( new InputStreamReader( stream, inputEncoding
) );
+ }
+ catch( UnsupportedEncodingException uce )
+ {
+ String msg = "Parser Exception: Unsupported input encoding : " +
inputEncoding
+ + " for template " + templateName;
+ Runtime.error( msg );
+ throw new ParseException( msg );
+ }
+
try
{
token_source.clearStateVars();
- ReInit(stream);
+ ReInit(br);
sn = process();
}
catch (ParseException pe)