1 14 15 package com.sun.facelets.compiler; 16 17 18 import java.io.IOException ; 19 import java.util.List ; 20 21 import javax.el.ELContext; 22 import javax.el.ELException; 23 import javax.el.ExpressionFactory; 24 25 import javax.faces.context.FacesContext; 26 import javax.faces.context.ResponseWriter; 27 28 import com.sun.facelets.el.ELAdaptor; 29 import com.sun.facelets.el.ELText; 30 31 final class AttributeInstruction implements Instruction { 32 private final String alias; 33 34 private final String attr; 35 36 private final ELText txt; 37 38 39 public AttributeInstruction(String alias, String attr, ELText txt) { 40 this.alias = alias; 41 this.attr = attr; 42 this.txt = txt; 43 } 44 45 public void write(FacesContext context) throws IOException { 46 ResponseWriter out = context.getResponseWriter(); 47 try { 48 ELContext elContext = ELAdaptor.getELContext(context); 49 String val = txt.toString(elContext); 50 51 out.writeAttribute(attr, val, null); 52 } catch (ELException e) { 53 throw new ELException(this.alias + ": " + e.getMessage(), e.getCause()); 54 } catch (Exception e) { 55 throw new ELException(this.alias + ": " + e.getMessage(), e); 56 } 57 } 58 59 public Instruction apply(ExpressionFactory factory, ELContext ctx) { 60 ELText nt = this.txt.apply(factory, ctx); 61 if (nt == this.txt) { 62 return this; 63 } 64 65 return new AttributeInstruction(alias, attr, nt); 66 } 67 68 public boolean isLiteral() { 69 return txt.isLiteral(); 70 } 71 } 72 | Popular Tags |