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 {
41 _alias = alias;
42 _attr = attr;
43 _txt = txt;
44 }
45
46 public void write(FacesContext context) throws IOException
47 {
48 ResponseWriter out = context.getResponseWriter();
49 try
50 {
51 out.writeAttribute(_attr, _txt.toString(context.getELContext()), null);
52 }
53 catch (ELException e)
54 {
55 throw new ELException(_alias + ": " + e.getMessage(), e.getCause());
56 }
57 catch (Exception e)
58 {
59 throw new ELException(_alias + ": " + e.getMessage(), e);
60 }
61 }
62
63 public Instruction apply(ExpressionFactory factory, ELContext ctx)
64 {
65 ELText nt = _txt.apply(factory, ctx);
66 if (nt == _txt)
67 {
68 return this;
69 }
70
71 return new AttributeInstruction(_alias, _attr, nt);
72 }
73
74 public boolean isLiteral()
75 {
76 return _txt.isLiteral();
77 }
78 }