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.AbstractFaceletContext;
32 import org.apache.myfaces.view.facelets.FaceletCompositionContext;
33 import org.apache.myfaces.view.facelets.el.ELText;
34 import org.apache.myfaces.view.facelets.tag.jsf.ComponentSupport;
35 import org.apache.myfaces.view.facelets.util.FastWriter;
36
37
38
39
40
41 final class UITextHandler extends AbstractUIHandler
42 {
43
44 private final ELText txt;
45
46 private final String alias;
47
48 private final int length;
49
50 public UITextHandler(String alias, ELText txt)
51 {
52 this.alias = alias;
53 this.txt = txt;
54 this.length = txt.toString().length();
55 }
56
57 public void apply(FaceletContext ctx, UIComponent parent) throws IOException, FacesException, FaceletException,
58 ELException
59 {
60 if (parent != null)
61 {
62 try
63 {
64 ELText nt = this.txt.apply(ctx.getExpressionFactory(), ctx);
65 UIComponent c = new UIText(this.alias, nt);
66
67
68 UniqueIdVendor uniqueIdVendor = FaceletCompositionContext.getCurrentInstance(ctx).getUniqueIdVendorFromStack();
69 if (uniqueIdVendor == null)
70 {
71 uniqueIdVendor = ComponentSupport.getViewRoot(ctx, parent);
72 }
73 if (uniqueIdVendor != null)
74 {
75
76
77 String uid = uniqueIdVendor.createUniqueId(ctx.getFacesContext(), null);
78 c.setId(uid);
79 }
80 this.addComponent(ctx, parent, c);
81 }
82 catch (Exception e)
83 {
84 throw new ELException(this.alias + ": " + e.getMessage(), e.getCause());
85 }
86 }
87 }
88
89 public String toString()
90 {
91 return this.txt.toString();
92 }
93
94 public String getText()
95 {
96 return this.txt.toString();
97 }
98
99 public String getText(FaceletContext ctx)
100 {
101 Writer writer = new FastWriter(this.length);
102 try
103 {
104 this.txt.apply(ctx.getExpressionFactory(), ctx).write(writer, ctx);
105 }
106 catch (IOException e)
107 {
108 throw new ELException(this.alias + ": " + e.getMessage(), e.getCause());
109 }
110 return writer.toString();
111 }
112 }