1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.myfaces.view.facelets;
21
22 import java.util.regex.Matcher;
23 import java.util.regex.Pattern;
24
25 import javax.faces.component.UIViewRoot;
26
27 import org.apache.myfaces.view.facelets.util.FastWriter;
28 import org.apache.myfaces.test.mock.MockResponseWriter;
29 import org.junit.Test;
30
31 public class EncodingTestCase extends FaceletTestCase
32 {
33
34 @Override
35 protected void setupComponents() throws Exception
36 {
37 application.addComponent(UIViewRoot.COMPONENT_TYPE, UIViewRoot.class
38 .getName());
39 }
40
41 @Override
42 protected void setupConvertersAndValidators() throws Exception
43 {
44 }
45
46 @Override
47 protected void setupRenderers() throws Exception
48 {
49 }
50
51 @Test
52 public void testPattern() throws Exception
53 {
54 Pattern p = Pattern
55 .compile("^<\\?xml.+?version=['\"](.+?)['\"](.+?encoding=['\"]((.+?))['\"])?.*?\\?>");
56 String[] d = new String[] { "<?xml version=\"1.0\" ?>",
57 "<?xml version='1.0' ?>",
58 "<?xml version='1.0' encoding='iso-8859-1'?>" };
59 for (int i = 0; i < d.length; i++)
60 {
61 Matcher m = p.matcher(d[i]);
62
63 if (m.matches())
64 {
65 for (int j = 0; j < m.groupCount(); j++)
66 {
67
68 }
69 }
70 }
71 }
72
73 @Test
74 public void testEncoding() throws Exception
75 {
76 request.setAttribute("name", "Mr. Hookom");
77 UIViewRoot root = facesContext.getViewRoot();
78 vdl.buildView(facesContext, root, "encoding.xml");
79 FastWriter fw = new FastWriter();
80 MockResponseWriter mrw = new MockResponseWriter(fw);
81 facesContext.setResponseWriter(mrw);
82 root.encodeAll(facesContext);
83
84 }
85
86 }