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 | |
|
23 | |
import javax.el.ELContext; |
24 | |
import javax.el.ELException; |
25 | |
import javax.el.ExpressionFactory; |
26 | |
import javax.faces.context.FacesContext; |
27 | |
import javax.faces.context.ResponseWriter; |
28 | |
|
29 | |
import org.apache.myfaces.view.facelets.el.ELText; |
30 | |
|
31 | |
final class AttributeInstruction implements Instruction |
32 | |
{ |
33 | |
private final String _alias; |
34 | |
|
35 | |
private final String _attr; |
36 | |
|
37 | |
private final ELText _txt; |
38 | |
|
39 | |
public AttributeInstruction(String alias, String attr, ELText txt) |
40 | 0 | { |
41 | 0 | _alias = alias; |
42 | 0 | _attr = attr; |
43 | 0 | _txt = txt; |
44 | 0 | } |
45 | |
|
46 | |
public void write(FacesContext context) throws IOException |
47 | |
{ |
48 | 0 | ResponseWriter out = context.getResponseWriter(); |
49 | |
try |
50 | |
{ |
51 | 0 | out.writeAttribute(_attr, _txt.toString(context.getELContext()), null); |
52 | |
} |
53 | 0 | catch (ELException e) |
54 | |
{ |
55 | 0 | throw new ELException(_alias + ": " + e.getMessage(), e.getCause()); |
56 | |
} |
57 | 0 | catch (Exception e) |
58 | |
{ |
59 | 0 | throw new ELException(_alias + ": " + e.getMessage(), e); |
60 | 0 | } |
61 | 0 | } |
62 | |
|
63 | |
public Instruction apply(ExpressionFactory factory, ELContext ctx) |
64 | |
{ |
65 | 0 | ELText nt = _txt.apply(factory, ctx); |
66 | 0 | if (nt == _txt) |
67 | |
{ |
68 | 0 | return this; |
69 | |
} |
70 | |
|
71 | 0 | return new AttributeInstruction(_alias, _attr, nt); |
72 | |
} |
73 | |
|
74 | |
public boolean isLiteral() |
75 | |
{ |
76 | 0 | return _txt.isLiteral(); |
77 | |
} |
78 | |
} |