リスト4 WindowRenderer.java

 1 package com.netpotlet.xul.renderkit;
 2
 3 import java.io.IOException;
 4
 5 import javax.faces.FacesException;
 6 import javax.faces.component.UIComponent;
 7 import javax.faces.context.FacesContext;
 8 import javax.faces.context.ResponseWriter;
 9 import javax.faces.render.Renderer;
10
11 import org.apache.commons.el.parser.ParseException;
12
13 import com.netpotlet.cove.el.CoveElResolver;
14 import com.netpotlet.xul.component.WindowComponent;
15 import com.netpotlet.xul.element.RNSContext;
16 import com.netpotlet.xul.element.URelaxer;
17
18 public class WindowRenderer extends Renderer {
19
20     public WindowRenderer() {
21         super();
22     }
23
24     public void encodeBegin(FacesContext context, UIComponent component)
25         throws IOException {
26         if ((context == null) || (component == null)) {
27             throw new NullPointerException();
28         }
29         WindowComponent window = (WindowComponent) component;
30         try {
31             char[] encoded = getEncodedBeginString(window);
32             ResponseWriter writer = context.getResponseWriter();
33             writer.writeText(encoded, 0, encoded.length);
34         } catch (ParseException e) {
35             throw new FacesException(e);
36         }
37     }
38
39     private char[] getEncodedBeginString(WindowComponent window)
40         throws ParseException {
41         String mixed = window.getTitle();
42         String title = CoveElResolver.getResolver().resolveExpression(mixed);
43         StringBuffer buffer = new StringBuffer();
44         RNSContext rNSContext_ = window.getRNSContext();
45         String prefix =
46             rNSContext_.getPrefixByUri(
47                 "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul");
48         buffer.append("<");
49         URelaxer.makeQName(prefix, "window", buffer);
50         rNSContext_.makeNSMappings(buffer);
51         if (window.getId() != null) {
52             buffer.append(" ");
53             buffer.append("id");
54             buffer.append("=\"");
55             buffer.append(
56                 URelaxer.escapeAttrQuot(URelaxer.getString(window.getId())));
57             buffer.append("\"");
58         }
59         if (title != null) {
60             buffer.append(" ");
61             buffer.append("title");
62             buffer.append("=\"");
63             buffer.append(URelaxer.escapeAttrQuot(URelaxer.getString(title)));
64             buffer.append("\"");
65         }
66         buffer.append(">");
67         return (new String(buffer)).toCharArray();
68     }
69
70     public void encodeChildren(FacesContext context, UIComponent component)
71         throws IOException {
72         if ((context == null) || (component == null)) {
73             throw new NullPointerException();
74         }
75     }
76
77     public void encodeEnd(FacesContext context, UIComponent component)
78         throws IOException {
79         if ((context == null) || (component == null)) {
80             throw new NullPointerException();
81         }
82         WindowComponent window = (WindowComponent) component;
83         char[] encoded = getEncodedEndString(window);
84         ResponseWriter writer = context.getResponseWriter();
85         writer.writeText(encoded, 0, encoded.length);
86     }
87
88     private char[] getEncodedEndString(WindowComponent window) {
89         StringBuffer buffer = new StringBuffer();
90         RNSContext rNSContext_ = window.getRNSContext();
91         String prefix =
92             rNSContext_.getPrefixByUri(
93                 "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul");
94         buffer.append("</");
95         URelaxer.makeQName(prefix, "window", buffer);
96         buffer.append(">");
97         return (new String(buffer)).toCharArray();
98     }
99 }