geirm       01/04/13 19:51:17

  Modified:    src/java/org/apache/velocity/runtime/parser Parser.java
                        Parser.jj
  Log:
  parser.jjt followers
  
  Revision  Changes    Path
  1.58      +49 -20    
jakarta-velocity/src/java/org/apache/velocity/runtime/parser/Parser.java
  
  Index: Parser.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-velocity/src/java/org/apache/velocity/runtime/parser/Parser.java,v
  retrieving revision 1.57
  retrieving revision 1.58
  diff -u -r1.57 -r1.58
  --- Parser.java       2001/03/01 03:31:26     1.57
  +++ Parser.java       2001/04/14 02:51:16     1.58
  @@ -21,7 +21,7 @@
    *
    * @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a>
    * @author <a href="mailto:[EMAIL PROTECTED]">Geir Magnusson Jr.</a>
  - * @version $Id: Parser.java,v 1.57 2001/03/01 03:31:26 geirm Exp $ 
  + * @version $Id: Parser.java,v 1.58 2001/04/14 02:51:16 geirm Exp $ 
   */
   public class Parser/*@bgen(jjtree)*/implements ParserTreeConstants, ParserConstants 
{/*@bgen(jjtree)*/
     protected JJTParserState jjtree = new JJTParserState();/**
  @@ -34,6 +34,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 
  @@ -44,6 +49,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");
       }
   
       /** 
  @@ -71,10 +81,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)
  @@ -2202,18 +2231,6 @@
       return retval;
     }
   
  -  final private boolean jj_3_5() {
  -    if (jj_scan_token(WHITESPACE)) return true;
  -    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
  -    return false;
  -  }
  -
  -  final private boolean jj_3R_66() {
  -    if (jj_scan_token(RCURLY)) return true;
  -    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
  -    return false;
  -  }
  -
     final private boolean jj_3R_19() {
       if (jj_3R_32()) return true;
       if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
  @@ -2488,6 +2505,12 @@
       return false;
     }
   
  +  final private boolean jj_3R_55() {
  +    if (jj_scan_token(WHITESPACE)) return true;
  +    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
  +    return false;
  +  }
  +
     final private boolean jj_3R_21() {
       Token xsp;
       xsp = jj_scanpos;
  @@ -2523,12 +2546,6 @@
       return false;
     }
   
  -  final private boolean jj_3R_55() {
  -    if (jj_scan_token(WHITESPACE)) return true;
  -    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
  -    return false;
  -  }
  -
     final private boolean jj_3R_90() {
       if (jj_scan_token(DIVIDE)) return true;
       if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
  @@ -2940,6 +2957,18 @@
   
     final private boolean jj_3R_63() {
       if (jj_3R_67()) return true;
  +    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
  +    return false;
  +  }
  +
  +  final private boolean jj_3_5() {
  +    if (jj_scan_token(WHITESPACE)) return true;
  +    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
  +    return false;
  +  }
  +
  +  final private boolean jj_3R_66() {
  +    if (jj_scan_token(RCURLY)) return true;
       if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
       return false;
     }
  
  
  
  1.56      +32 -3     
jakarta-velocity/src/java/org/apache/velocity/runtime/parser/Parser.jj
  
  Index: Parser.jj
  ===================================================================
  RCS file: 
/home/cvs/jakarta-velocity/src/java/org/apache/velocity/runtime/parser/Parser.jj,v
  retrieving revision 1.55
  retrieving revision 1.56
  diff -u -r1.55 -r1.56
  --- Parser.jj 2001/03/01 03:31:26     1.55
  +++ Parser.jj 2001/04/14 02:51:16     1.56
  @@ -2,7 +2,7 @@
   /*@egen*//*
    * The Apache Software License, Version 1.1
    *
  - * Copyright (c) 2000 The Apache Software Foundation.  All rights
  + * Copyright (c) 2001 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -96,7 +96,7 @@
    *
    * @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a>
    * @author <a href="mailto:[EMAIL PROTECTED]">Geir Magnusson Jr.</a>
  - * @version $Id: Parser.jj,v 1.55 2001/03/01 03:31:26 geirm Exp $ 
  + * @version $Id: Parser.jj,v 1.56 2001/04/14 02:51:16 geirm Exp $ 
   */
   public class Parser/*@bgen(jjtree)*/implements ParserTreeConstants/*@egen*/
   {/*@bgen(jjtree)*/
  @@ -113,6 +113,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 
  @@ -123,6 +128,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");
       }
   
       /** 
  @@ -150,10 +160,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)
  
  
  

Reply via email to