KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > facelets > EncodingTestCase


1 package com.sun.facelets;
2
3 import java.util.regex.Matcher JavaDoc;
4 import java.util.regex.Pattern JavaDoc;
5
6 import javax.faces.component.UIViewRoot;
7 import javax.faces.context.FacesContext;
8
9 import com.sun.facelets.mock.MockResponseWriter;
10 import com.sun.facelets.util.FastWriter;
11
12 public class EncodingTestCase extends FaceletTestCase {
13     
14     public void testPattern() throws Exception JavaDoc {
15         Pattern JavaDoc p = Pattern.compile("^<\\?xml.+?version=['\"](.+?)['\"](.+?encoding=['\"]((.+?))['\"])?.*?\\?>");
16         String JavaDoc[] d = new String JavaDoc[] { "<?xml version=\"1.0\" ?>", "<?xml version='1.0' ?>", "<?xml version='1.0' encoding='iso-8859-1'?>" };
17         for (int i = 0; i < d.length; i++) {
18             Matcher JavaDoc m = p.matcher(d[i]);
19             System.out.println(d[i] + " " + m.matches());
20             if (m.matches()) {
21                 for (int j = 0; j < m.groupCount(); j++) {
22                     System.out.println('\t' + m.group(j));
23                 }
24             }
25         }
26     }
27
28     public void testEncoding() throws Exception JavaDoc {
29         FaceletFactory ff = FaceletFactory.getInstance();
30         FacesContext faces = FacesContext.getCurrentInstance();
31         
32         Facelet f = ff.getFacelet("encoding.xml");
33         
34         this.servletRequest.setAttribute("name", "Mr. Hookom");
35         
36         UIViewRoot root = faces.getViewRoot();
37         f.apply(faces, root);
38         
39         FastWriter fw = new FastWriter();
40         MockResponseWriter mrw = new MockResponseWriter(fw);
41         faces.setResponseWriter(mrw);
42         root.encodeAll(faces);
43         System.out.println(fw);
44     }
45
46 }
47
Popular Tags