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 | 0 | { |
51 | 0 | this.alias = alias; |
52 | 0 | this.txt = txt; |
53 | 0 | this.length = txt.toString().length(); |
54 | 0 | } |
55 | |
|
56 | |
public void apply(FaceletContext ctx, UIComponent parent) throws IOException, FacesException, FaceletException, |
57 | |
ELException |
58 | |
{ |
59 | 0 | if (parent != null) |
60 | |
{ |
61 | |
try |
62 | |
{ |
63 | 0 | ELText nt = this.txt.apply(ctx.getExpressionFactory(), ctx); |
64 | 0 | UIComponent c = new UIText(this.alias, nt); |
65 | |
|
66 | 0 | UniqueIdVendor uniqueIdVendor |
67 | |
= FaceletCompositionContext.getCurrentInstance(ctx).getUniqueIdVendorFromStack(); |
68 | 0 | if (uniqueIdVendor == null) |
69 | |
{ |
70 | 0 | uniqueIdVendor = ComponentSupport.getViewRoot(ctx, parent); |
71 | |
} |
72 | 0 | if (uniqueIdVendor != null) |
73 | |
{ |
74 | |
|
75 | |
|
76 | 0 | String uid = uniqueIdVendor.createUniqueId(ctx.getFacesContext(), null); |
77 | 0 | c.setId(uid); |
78 | |
} |
79 | 0 | this.addComponent(ctx, parent, c); |
80 | |
} |
81 | 0 | catch (Exception e) |
82 | |
{ |
83 | 0 | throw new ELException(this.alias + ": " + e.getMessage(), e.getCause()); |
84 | 0 | } |
85 | |
} |
86 | 0 | } |
87 | |
|
88 | |
public String toString() |
89 | |
{ |
90 | 0 | return this.txt.toString(); |
91 | |
} |
92 | |
|
93 | |
public String getText() |
94 | |
{ |
95 | 0 | return this.txt.toString(); |
96 | |
} |
97 | |
|
98 | |
public String getText(FaceletContext ctx) |
99 | |
{ |
100 | 0 | Writer writer = new FastWriter(this.length); |
101 | |
try |
102 | |
{ |
103 | 0 | this.txt.apply(ctx.getExpressionFactory(), ctx).write(writer, ctx); |
104 | |
} |
105 | 0 | catch (IOException e) |
106 | |
{ |
107 | 0 | throw new ELException(this.alias + ": " + e.getMessage(), e.getCause()); |
108 | 0 | } |
109 | 0 | return writer.toString(); |
110 | |
} |
111 | |
} |