1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.myfaces.view.facelets.compiler;
20
21 import java.io.IOException;
22 import java.io.Writer;
23
24 import javax.el.ELException;
25 import javax.faces.FacesException;
26 import javax.faces.component.UIComponent;
27 import javax.faces.component.UniqueIdVendor;
28 import javax.faces.view.facelets.FaceletContext;
29 import javax.faces.view.facelets.FaceletException;
30
31 import org.apache.myfaces.view.facelets.FaceletCompositionContext;
32 import org.apache.myfaces.view.facelets.el.ELText;
33 import org.apache.myfaces.view.facelets.tag.jsf.ComponentSupport;
34 import org.apache.myfaces.view.facelets.util.FastWriter;
35
36
37
38
39
40 final class UITextHandler extends AbstractUIHandler
41 {
42
43 private final ELText txt;
44
45 private final String alias;
46
47 private final int length;
48
49 public UITextHandler(String alias, ELText txt)
50 {
51 this.alias = alias;
52 this.txt = txt;
53 this.length = txt.toString().length();
54 }
55
56 public void apply(FaceletContext ctx, UIComponent parent) throws IOException, FacesException, FaceletException,
57 ELException
58 {
59 if (parent != null)
60 {
61 try
62 {
63 ELText nt = this.txt.apply(ctx.getExpressionFactory(), ctx);
64 UIComponent c = new UIText(this.alias, nt);
65
66 UniqueIdVendor uniqueIdVendor
67 = FaceletCompositionContext.getCurrentInstance(ctx).getUniqueIdVendorFromStack();
68 if (uniqueIdVendor == null)
69 {
70 uniqueIdVendor = ComponentSupport.getViewRoot(ctx, parent);
71 }
72 if (uniqueIdVendor != null)
73 {
74
75
76 String uid = uniqueIdVendor.createUniqueId(ctx.getFacesContext(), null);
77 c.setId(uid);
78 }
79 this.addComponent(ctx, parent, c);
80 }
81 catch (Exception e)
82 {
83 throw new ELException(this.alias + ": " + e.getMessage(), e.getCause());
84 }
85 }
86 }
87
88 public String toString()
89 {
90 return this.txt.toString();
91 }
92
93 public String getText()
94 {
95 return this.txt.toString();
96 }
97
98 public String getText(FaceletContext ctx)
99 {
100 Writer writer = new FastWriter(this.length);
101 try
102 {
103 this.txt.apply(ctx.getExpressionFactory(), ctx).write(writer, ctx);
104 }
105 catch (IOException e)
106 {
107 throw new ELException(this.alias + ": " + e.getMessage(), e.getCause());
108 }
109 return writer.toString();
110 }
111 }