Author: gvanmatre
Date: Wed Sep 27 19:19:25 2006
New Revision: 450667

URL: http://svn.apache.org/viewvc?view=rev&rev=450667
Log:
Reported by Tom Pasierb - Clay doesn't consider file's encoding when 
loading/parsing html templates (SHALE-292).

The encoding is now determined with the following steps:
1) Look at the top of the template for the token comment containing the 
charset. 
2) If not found, look for the app wide config option for template encoding. If 
found use the encoding for reading the template.
3) If not found use the vm's default "file.encoding".
4) Read the template in with the determined encoding


Added:
    
shale/framework/trunk/shale-clay/src/test/java/org/apache/shale/clay/config/CharsetTestCase.java
   (with props)
    
shale/framework/trunk/shale-clay/src/test/resources/org/apache/shale/clay/config/some-utf-8.html
   (with props)
Modified:
    
shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/config/ClayTemplateParser.java
    
shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/config/Globals.java
    
shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/parser/Parser.java
    
shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/parser/builder/JsfDefaultBuilder.java
    
shale/framework/trunk/shale-clay/src/main/resources/org/apache/shale/clay/Bundle.properties
    
shale/framework/trunk/shale-clay/src/test/java/org/apache/shale/clay/parser/ParserTestCase.java

Modified: 
shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/config/ClayTemplateParser.java
URL: 
http://svn.apache.org/viewvc/shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/config/ClayTemplateParser.java?view=diff&rev=450667&r1=450666&r2=450667
==============================================================================
--- 
shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/config/ClayTemplateParser.java
 (original)
+++ 
shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/config/ClayTemplateParser.java
 Wed Sep 27 19:19:25 2006
@@ -19,11 +19,15 @@
  */
 package org.apache.shale.clay.config;
 
+import java.io.BufferedReader;
 import java.io.IOException;
-import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.StringWriter;
 import java.net.URL;
+import java.nio.charset.Charset;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -32,8 +36,10 @@
 import org.apache.shale.clay.config.beans.ConfigBean;
 import org.apache.shale.clay.config.beans.ElementBean;
 import org.apache.shale.clay.config.beans.TemplateConfigBean;
+import org.apache.shale.clay.parser.AttributeTokenizer;
 import org.apache.shale.clay.parser.Node;
 import org.apache.shale.clay.parser.Parser;
+import org.apache.shale.clay.parser.Token;
 import org.apache.shale.clay.parser.builder.Builder;
 import org.apache.shale.util.Messages;
 import org.xml.sax.SAXException;
@@ -150,17 +156,7 @@
 
         // generate the document
 
-        InputStream inputStream = null;
-        StringBuffer buffer = null;
-
-        try {
-            inputStream = templateURL.openStream();
-            buffer = loadTemplate(inputStream, templateName);
-        } finally {
-            if (inputStream != null) {
-                inputStream.close();
-            }
-        }
+        StringBuffer buffer = loadTemplate(templateURL);
 
         List roots = new Parser().parse(buffer);
         Iterator ri = roots.iterator();
@@ -196,43 +192,142 @@
     }
 
     /**
-     * <p>
-     * Loads the template into a <code>StringBuffer</code> using the
-     * <code>inputStream</code> and <code>templateName</code> parameters.
+     * <p>Loads the template file respecting the encoding type.
+     * The file encoding type is determined by calling
+     * the <code>getCharacterEncoding()</code> method.
      * </p>
      *
-     * @param inputStream
-     *            template file
-     * @param templateName
-     *            jsfid
-     * @return loaded template file
-     * @exception IOException
-     *                loading template file
+     * @param templateURL target template to load
+     * @return content of the template
+     * @throws IOException error loading the template
      */
-    protected StringBuffer loadTemplate(InputStream inputStream,
-            String templateName) throws IOException {
+    public StringBuffer loadTemplate(URL templateURL) throws IOException {
 
         StringBuffer buff = new StringBuffer();
+        BufferedReader in = null;
+        String enc = getCharacterEncoding(templateURL);
+
+        if (log.isDebugEnabled()) {
+           log.debug(messages.getMessage("template.encoding",
+               new Object[] { enc, templateURL.getFile() }));
+        }
 
         try {
-            int c = 0;
-            done: while (true) {
-                c = inputStream.read();
-                if (c > -1) {
-                    buff.append((char) c);
-                } else {
-                    break done;
-                }
 
+            in = new BufferedReader(new 
InputStreamReader(templateURL.openStream(), enc));
+            while (in.ready()) {
+               buff.append(in.readLine()).append("\n");
             }
+
         } catch (IOException e) {
             log.error(messages.getMessage("loading.template.exception",
-                    new Object[] { templateName }), e);
+                    new Object[] { templateURL.getFile() }), e);
             throw e;
+        } finally {
+           if (in != null) {
+              in.close();
+           }
         }
 
         return buff;
 
+    }
+
+
+    /**
+     * <p>Returns the encoding type used to open the <code>templateURL</code>.
+     * The template encoding type is resolved using three overrides.  The first
+     * step is to look in the target template for a comment token that defines
+     * the charset. The first 512 chars of the <code>templateURL</code> are 
read
+     * and scanned for a special comment token.<br/></br/>
+     *
+     * For example: &lt;-- ### clay:page charset="UTF-8" /### --><br/><br/>
+     *
+     * If the Clay page directive is not found, the next override is an
+     * initialization parameter in the web.xml.  The value of this parameter
+     * is a global override for all templates.<br/><br/>
+     *
+     * For example:<br/>
+     * &lt;context-param&gt;<br/>
+     * 
&nbsp;&nbsp;&lt;param-name&gt;org.apache.shale.clay.HTML_TEMPLATE_CHARSET
+     * &lt;/param-name&gt;<br/>
+     * &nbsp;&nbsp;&lt;param-value&gt;UTF-8&lt;/param-value&gt;<br/>
+     * &lt;/context-param&gt;<br/><br/>
+     *
+     * Otherwise, the defaut is the VM's "<code>file.encoding</code>"
+     * system parameter.
+     *
+     * @param templateURL template URL
+     * @return charset encoding used to read the template
+     * @throws IOException unable to read the template document
+     */
+    public String getCharacterEncoding(URL templateURL) throws IOException {
+
+        InputStreamReader in = null;
+        StringWriter snippet = new StringWriter();
+        char[] chars = new char[512];
+        String enc = null;
+
+
+        try {
+            // read in the top of the template
+            in = new InputStreamReader(templateURL.openStream());
+            int n = in.read(chars);
+            snippet.write(chars, 0, n);
+
+            // look for the comment page directive containing the charset
+            int s = snippet.getBuffer().indexOf(Parser.START_CHARSET_TOKEN);
+            if (s > -1) {
+               int e = snippet.getBuffer().indexOf(Parser.END_CHARSET_TOKEN, 
s);
+               AttributeTokenizer tokenizer = new 
AttributeTokenizer(snippet.getBuffer(), s, e, 1, 0);
+               Iterator ti = tokenizer.iterator();
+               while (ti.hasNext()) {
+                   Map.Entry attribute = (Map.Entry) ti.next();
+                   Token key = (Token) attribute.getKey();
+                   //check the attribute name, we are only interested
+                   //in "charset"
+                   if (key != null && key.getRawText() != null
+                       && key.getRawText().equalsIgnoreCase("charset")) {
+                       Token value = (Token) attribute.getValue();
+
+                       //look for the value of the charset attribute
+                       if (value != null && value.getRawText() != null) {
+                          // if it is supported, use the value for the encoding
+                          if (Charset.isSupported(value.getRawText())) {
+                              enc = value.getRawText();
+                          } else {
+                              
log.error(messages.getMessage("template.encoding.notsupported",
+                                      new Object[] { value.getRawText() }));
+                          }
+                       }
+                   }
+               }
+            }
+
+
+        } finally {
+            if (in != null) {
+               in.close();
+            }
+            if (snippet != null) {
+               snippet.close();
+            }
+        }
+
+        if (enc == null) {
+            enc = 
getConfig().getServletContext().getInitParameter(Globals.CLAY_HTML_CHARSET);
+            if (enc != null) {
+               if (!Charset.isSupported(enc)) {
+                  
log.error(messages.getMessage("template.encoding.notsupported",
+                           new Object[] { enc }));
+                  enc = System.getProperty("file.encoding");
+               }
+            } else {
+               enc = System.getProperty("file.encoding");
+            }
+        }
+
+        return enc;
     }
 
 }

Modified: 
shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/config/Globals.java
URL: 
http://svn.apache.org/viewvc/shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/config/Globals.java?view=diff&rev=450667&r1=450666&r2=450667
==============================================================================
--- 
shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/config/Globals.java
 (original)
+++ 
shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/config/Globals.java
 Wed Sep 27 19:19:25 2006
@@ -117,6 +117,15 @@
     public static final String CLASSPATH_PREFIX = "classpath*:";
 
     /**
+     * <p>The name of the initializtion parameter in the web deployment 
descriptor that
+     * defines the default charset for all html templates.  If not specified, 
the 
+     * "<code>file.encoding</code>" system parameter is the default.  The 
charset can
+     * be overridden for each template file using a special comment directive,
+     * <code>"&lt;!-- ### clay:page charset="UTF-8" /### --&gt;"</code>.</p>
+     */
+    public static final String CLAY_HTML_CHARSET = 
"org.apache.shale.clay.HTML_TEMPLATE_CHARSET";
+
+    /**
      * <p>The default subview configuration file containing the base supported
      * components.
      *</p>

Modified: 
shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/parser/Parser.java
URL: 
http://svn.apache.org/viewvc/shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/parser/Parser.java?view=diff&rev=450667&r1=450666&r2=450667
==============================================================================
--- 
shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/parser/Parser.java
 (original)
+++ 
shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/parser/Parser.java
 Wed Sep 27 19:19:25 2006
@@ -268,6 +268,18 @@
     private static final String END_REMOVE_TOKEN = "<!-- ### /clay:remove ### 
-->";
 
     /**
+     * <p>The start of the comment token used to override the template
+     * encoding type.</p>
+     */
+    public static final String START_CHARSET_TOKEN = "<!-- ### clay:page ";
+
+    /**
+     * <p>The end of the comment token used to override the template
+     * encoding type.</p>
+     */
+    public static final String END_CHARSET_TOKEN = "/### -->";
+
+    /**
      * <p>
      * Parse a document fragment into graphs of [EMAIL PROTECTED] Node}. The 
resulting
      * type is a list because the fragment might not be well-formed.
@@ -293,6 +305,11 @@
             // self contained comment matching the begin/end remove token 
delimiter
             // skip all tokens within the remove block
             if (node.isComment() && node.isStart() && node.isEnd()) {
+
+                //ignore start page charset token if not in a remove comment 
block
+                if (!isWithinRemoveBlock && 
node.getToken().getRawText().startsWith(START_CHARSET_TOKEN)) {
+                   continue next;
+                }
 
                 if (isWithinRemoveBlock && 
node.getToken().getRawText().equals(END_REMOVE_TOKEN)) {
 

Modified: 
shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/parser/builder/JsfDefaultBuilder.java
URL: 
http://svn.apache.org/viewvc/shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/parser/builder/JsfDefaultBuilder.java?view=diff&rev=450667&r1=450666&r2=450667
==============================================================================
--- 
shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/parser/builder/JsfDefaultBuilder.java
 (original)
+++ 
shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/parser/builder/JsfDefaultBuilder.java
 Wed Sep 27 19:19:25 2006
@@ -98,23 +98,23 @@
     private Map validatorsByType = null;
     {
       validatorsByType = new TreeMap();
-      validatorsByType.put("required","s:commonsValidatorRequired");
-      validatorsByType.put("maxlength","s:commonsValidatorMaxlength");
-      validatorsByType.put("minlength","s:commonsValidatorMinlength");
-      validatorsByType.put("mask","s:commonsValidatorMask");
-      validatorsByType.put("byte","s:commonsValidatorByte");
-      validatorsByType.put("short","s:commonsValidatorShort");
-      validatorsByType.put("integer","s:commonsValidatorInteger");
-      validatorsByType.put("long","s:commonsValidatorLong");
-      validatorsByType.put("float","s:commonsValidatorFloat");
-      validatorsByType.put("double","s:commonsValidatorDouble");
-      validatorsByType.put("date","s:commonsValidatorDate");
-      validatorsByType.put("intRange","s:commonsValidatorIntRange");
-      validatorsByType.put("floatRange","s:commonsValidatorFloatRange");
-      validatorsByType.put("doubleRange","s:commonsValidatorDoubleRange");
-      validatorsByType.put("creditCard","s:commonsValidatorCreditCard");
-      validatorsByType.put("email","s:commonsValidatorEmail");
-      validatorsByType.put("url","s:commonsValidatorUrl");  
+      validatorsByType.put("required", "s:commonsValidatorRequired");
+      validatorsByType.put("maxlength", "s:commonsValidatorMaxlength");
+      validatorsByType.put("minlength", "s:commonsValidatorMinlength");
+      validatorsByType.put("mask", "s:commonsValidatorMask");
+      validatorsByType.put("byte", "s:commonsValidatorByte");
+      validatorsByType.put("short", "s:commonsValidatorShort");
+      validatorsByType.put("integer", "s:commonsValidatorInteger");
+      validatorsByType.put("long", "s:commonsValidatorLong");
+      validatorsByType.put("float", "s:commonsValidatorFloat");
+      validatorsByType.put("double", "s:commonsValidatorDouble");
+      validatorsByType.put("date", "s:commonsValidatorDate");
+      validatorsByType.put("intRange", "s:commonsValidatorIntRange");
+      validatorsByType.put("floatRange", "s:commonsValidatorFloatRange");
+      validatorsByType.put("doubleRange", "s:commonsValidatorDoubleRange");
+      validatorsByType.put("creditCard", "s:commonsValidatorCreditCard");
+      validatorsByType.put("email", "s:commonsValidatorEmail");
+      validatorsByType.put("url", "s:commonsValidatorUrl");
     }
 
     /**
@@ -205,7 +205,7 @@
         if (node.getAttributes().containsKey("extends") || 
!jsfid.equals("validator")) {
             realizeComponent(node, targetValidator);
         }
-        
+
         //attach to the target element
         target.addValidator(targetValidator);
 

Modified: 
shale/framework/trunk/shale-clay/src/main/resources/org/apache/shale/clay/Bundle.properties
URL: 
http://svn.apache.org/viewvc/shale/framework/trunk/shale-clay/src/main/resources/org/apache/shale/clay/Bundle.properties?view=diff&rev=450667&r1=450666&r2=450667
==============================================================================
--- 
shale/framework/trunk/shale-clay/src/main/resources/org/apache/shale/clay/Bundle.properties
 (original)
+++ 
shale/framework/trunk/shale-clay/src/main/resources/org/apache/shale/clay/Bundle.properties
 Wed Sep 27 19:19:25 2006
@@ -135,6 +135,10 @@
 loading.template=Loading clay HTML template {0}
 loading.template.exception=Unable to load template file {0}
 
+#org.apache.shale.clay.config.ClayTemplateParser
+template.encoding.notsupported=The charset override "{0}" is not supported.
+template.encoding=Using charset "{0}" loading template file "{1}".
+
 #org.apache.shale.clay.parser.builder.Builder
 encode.begin=Begin encoding node: {0}
 encode.end=End encoding node: {0}

Added: 
shale/framework/trunk/shale-clay/src/test/java/org/apache/shale/clay/config/CharsetTestCase.java
URL: 
http://svn.apache.org/viewvc/shale/framework/trunk/shale-clay/src/test/java/org/apache/shale/clay/config/CharsetTestCase.java?view=auto&rev=450667
==============================================================================
--- 
shale/framework/trunk/shale-clay/src/test/java/org/apache/shale/clay/config/CharsetTestCase.java
 (added)
+++ 
shale/framework/trunk/shale-clay/src/test/java/org/apache/shale/clay/config/CharsetTestCase.java
 Wed Sep 27 19:19:25 2006
@@ -0,0 +1,210 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.shale.clay.config;
+
+import java.io.StringWriter;
+import java.net.URL;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.faces.context.ResponseWriter;
+import javax.faces.render.Renderer;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.apache.shale.clay.component.Clay;
+import org.apache.shale.clay.parser.Node;
+import org.apache.shale.clay.parser.Parser;
+
+// test logic to handle encoding types in document templates
+public class CharsetTestCase extends AbstractTestCaseConfig {
+
+    // Construct a new instance of this test case.
+    public CharsetTestCase(String name) {
+        super(name);
+    }
+
+    // Return the tests included in this test case.
+    public static Test suite() {
+
+        return (new TestSuite(CharsetTestCase.class));
+
+    }
+
+    //family, renderer type, Myfaces Impl, Sun RI Impl
+    protected String[][] RENDERERS = {
+            {"javax.faces.Output", "javax.faces.Text", 
+             "org.apache.myfaces.renderkit.html.HtmlTextRenderer", 
+             "com.sun.faces.renderkit.html_basic.TextRenderer",},        
+            {"javax.faces.Input", "javax.faces.Text", 
+             "org.apache.myfaces.renderkit.html.HtmlTextRenderer", 
+             "com.sun.faces.renderkit.html_basic.TextRenderer"},
+            {"javax.faces.Output", "javax.faces.Label", 
+             "org.apache.myfaces.renderkit.html.HtmlLabelRenderer",
+             "com.sun.faces.renderkit.html_basic.LabelRenderer"}
+            
+    };
+    
+    protected void setUp() throws Exception {
+        super.setUp();
+                        
+        //loads the RI or myfaces renderers from the RENDERERS static array.
+        for (int i = 0; i < RENDERERS.length; i++) {
+            
+            Renderer renderer = null;
+            renderer: for (int j = 2; j < 4; j++) {
+                try {
+                    Class clazz = Class.forName(RENDERERS[i][j]);
+                    if (clazz != null) {
+                        renderer = (Renderer) clazz.newInstance();
+                        if (renderer != null) {
+                            //System.out.println(RENDERERS[i][j]);
+                            break renderer;
+                        }
+                    }
+                } catch (ClassNotFoundException e) {
+                } catch (InstantiationException e) {
+                } catch (IllegalAccessException e) {
+                }
+            }
+            
+            if (renderer != null) {
+                facesContext.getRenderKit().addRenderer(RENDERERS[i][0], 
RENDERERS[i][1],
+                        renderer);
+            }
+        }        
+        
+    }
+
+    public void testFindCharacterEncoding() throws Exception {
+        //done by the startup context listener
+        loadConfigFiles(null, null);
+          
+        ClayTemplateParser parser = new ClayTemplateParser();
+        parser.setConfig(htmlTemplateConfigBean);
+
+        
+        URL noOverrideURL = 
facesContext.getExternalContext().getResource("/org/apache/shale/clay/config/comment.html");
+        String enc = parser.getCharacterEncoding(noOverrideURL);
+        assertEquals("VM default", System.getProperty("file.encoding"), enc);
+        
+        servletContext.addInitParameter(Globals.CLAY_HTML_CHARSET, "UTF-16");
+        enc = parser.getCharacterEncoding(noOverrideURL);
+        assertEquals("web.xml override", "UTF-16", enc);
+
+        servletContext.addInitParameter(Globals.CLAY_HTML_CHARSET, "BOGUS");
+        enc = parser.getCharacterEncoding(noOverrideURL);
+        assertEquals("web.xml bogus override", 
System.getProperty("file.encoding"), enc);
+            
+        URL overrideURL = 
facesContext.getExternalContext().getResource("/org/apache/shale/clay/config/some-utf-8.html");
+        enc = parser.getCharacterEncoding(overrideURL);
+        assertEquals("template override", "UTF-8", enc);
+
+    }
+    
+    
+    public void testUtf8() throws Exception{
+        
+        //done by the startup context listener
+        loadConfigFiles(null, null);
+        response.setCharacterEncoding("UTF-8");
+        
+        
+        Clay clay = (Clay) 
application.createComponent("org.apache.shale.clay.component.Clay");    
+        clay.setId("test");
+        clay.setJsfid("/org/apache/shale/clay/config/some-utf-8.html");
+        clay.setManagedBeanName("test");
+                
+        //builds a buffer to write the page to
+        StringWriter writer = new StringWriter();
+        //create a buffered response writer
+        ResponseWriter buffResponsewriter = facesContext.getRenderKit()
+                        .createResponseWriter(writer, null, 
response.getCharacterEncoding());
+        //push buffered writer to the faces context
+        facesContext.setResponseWriter(buffResponsewriter);
+        //start a document
+        buffResponsewriter.startDocument();
+        
+        //render HTML
+        clay.encodeBegin(facesContext);
+        clay.encodeChildren(facesContext);
+        clay.encodeEnd(facesContext);
+        
+        //end the document
+        buffResponsewriter.endDocument();
+        
+        Parser p = new Parser();
+        List nodes = p.parse(writer.getBuffer());
+        assertEquals("2 root node", 2, nodes.size());
+
+        Node paragraph = (Node) nodes.get(1);
+        assertNotNull(paragraph);
+        
+        // contact rendered output into a buffer
+        StringBuffer snippet = concatText(paragraph);
+        assertNotNull(snippet);
+        
+        int i = snippet.indexOf("\u0119");
+        assertTrue("polish language char \u0119", i > -1);        
+                
+        i = snippet.indexOf("\u00f3");
+        assertTrue("polish language char \u00f3", i > -1);        
+                
+        i = snippet.indexOf("\u0107");
+        assertTrue("polish language char \u0107", i > -1);        
+        
+        i = snippet.indexOf("\u017a");
+        assertTrue("polish language char \u017a", i > -1);        
+
+        i = snippet.indexOf("\u017c");
+        assertTrue("polish language char \u017c", i > -1);        
+
+        i = snippet.indexOf("\u015b");
+        assertTrue("polish language char \u015b", i > -1);        
+
+        i = snippet.indexOf("\u0105");
+        assertTrue("polish language char \u0105", i > -1);        
+
+        i = snippet.indexOf("\u221e");
+        assertTrue("infinity char \u221e", i > -1);        
+        
+        i = snippet.indexOf("\u03c6");
+        assertTrue("small greek letter Phi char \u03c6", i > -1);        
+
+        i = snippet.indexOf("\u03c6");
+        assertTrue("integral sign char \u03c6", i > -1);        
+
+        writer.close();
+        
+    } 
+    
+    private StringBuffer concatText(Node node) {
+        
+        StringBuffer buff = new StringBuffer();
+        buff.append(node.getToken().getRawText());
+        Iterator ci = node.getChildren().iterator();
+        while (ci.hasNext()) {
+            Node child = (Node) ci.next();
+            buff.append(child.getToken().getRawText());    
+        } 
+        
+        return buff;
+    }
+    
+           
+
+}

Propchange: 
shale/framework/trunk/shale-clay/src/test/java/org/apache/shale/clay/config/CharsetTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
shale/framework/trunk/shale-clay/src/test/java/org/apache/shale/clay/config/CharsetTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Modified: 
shale/framework/trunk/shale-clay/src/test/java/org/apache/shale/clay/parser/ParserTestCase.java
URL: 
http://svn.apache.org/viewvc/shale/framework/trunk/shale-clay/src/test/java/org/apache/shale/clay/parser/ParserTestCase.java?view=diff&rev=450667&r1=450666&r2=450667
==============================================================================
--- 
shale/framework/trunk/shale-clay/src/test/java/org/apache/shale/clay/parser/ParserTestCase.java
 (original)
+++ 
shale/framework/trunk/shale-clay/src/test/java/org/apache/shale/clay/parser/ParserTestCase.java
 Wed Sep 27 19:19:25 2006
@@ -818,5 +818,23 @@
         
     }
 
+    
+    public void testRemoveCharset() {
+        Parser p = new Parser();
+        StringBuffer doc = new StringBuffer();
+        doc.append("<!-- ### clay:page charset=\"UTF-8\" ### -->")
+           .append("<html></html>");
+
+        List roots = p.parse(doc);
+        assertNotNull(roots);
+        
+        //charset comment should be removed
+        assertEquals("root nodes", 1, roots.size());
+
+        Node root = (Node) roots.get(0); 
+        assertEquals("root node", "html", root.getName());
+
+    }
+    
 
 }

Added: 
shale/framework/trunk/shale-clay/src/test/resources/org/apache/shale/clay/config/some-utf-8.html
URL: 
http://svn.apache.org/viewvc/shale/framework/trunk/shale-clay/src/test/resources/org/apache/shale/clay/config/some-utf-8.html?view=auto&rev=450667
==============================================================================
--- 
shale/framework/trunk/shale-clay/src/test/resources/org/apache/shale/clay/config/some-utf-8.html
 (added)
+++ 
shale/framework/trunk/shale-clay/src/test/resources/org/apache/shale/clay/config/some-utf-8.html
 [UTF-8] Wed Sep 27 19:19:25 2006
@@ -0,0 +1,16 @@
+<!-- ### clay:page charset="UTF-8" /### -->
+<!-- ### clay:remove ### -->
+<html>
+<head>
+<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
+</head>
+<body>
+<!-- ### /clay:remove ### -->
+<p>BEGINNING OF HTML TEMPLATE<br />
+some Polish language specific characters from html template: ąśżźżćłóę<br />
+some other utf-8 encoded characters: infinity: ∞ , small greek letter Phi: φ, 
intergral sign: ∫
+<br />END OF HTML TEMPLATE</p>
+<!-- ### clay:remove ### -->
+</body>
+</html>
+<!-- ### /clay:remove ### -->
\ No newline at end of file

Propchange: 
shale/framework/trunk/shale-clay/src/test/resources/org/apache/shale/clay/config/some-utf-8.html
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
shale/framework/trunk/shale-clay/src/test/resources/org/apache/shale/clay/config/some-utf-8.html
------------------------------------------------------------------------------
    svn:mime-type = text/plain; charset=UTF-8


Reply via email to