01: package com.sun.facelets;
02:
03: import java.util.regex.Matcher;
04: import java.util.regex.Pattern;
05:
06: import javax.faces.component.UIViewRoot;
07: import javax.faces.context.FacesContext;
08:
09: 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 {
15: Pattern p = Pattern
16: .compile("^<\\?xml.+?version=['\"](.+?)['\"](.+?encoding=['\"]((.+?))['\"])?.*?\\?>");
17: String[] d = new String[] { "<?xml version=\"1.0\" ?>",
18: "<?xml version='1.0' ?>",
19: "<?xml version='1.0' encoding='iso-8859-1'?>" };
20: for (int i = 0; i < d.length; i++) {
21: Matcher m = p.matcher(d[i]);
22: System.out.println(d[i] + " " + m.matches());
23: if (m.matches()) {
24: for (int j = 0; j < m.groupCount(); j++) {
25: System.out.println('\t' + m.group(j));
26: }
27: }
28: }
29: }
30:
31: public void testEncoding() throws Exception {
32: FaceletFactory ff = FaceletFactory.getInstance();
33: FacesContext faces = FacesContext.getCurrentInstance();
34:
35: Facelet f = ff.getFacelet("encoding.xml");
36:
37: this .servletRequest.setAttribute("name", "Mr. Hookom");
38:
39: UIViewRoot root = faces.getViewRoot();
40: f.apply(faces, root);
41:
42: FastWriter fw = new FastWriter();
43: MockResponseWriter mrw = new MockResponseWriter(fw);
44: faces.setResponseWriter(mrw);
45: root.encodeAll(faces);
46: System.out.println(fw);
47: }
48:
49: }
|