1 14 15 package com.sun.facelets.compiler; 16 17 import java.io.IOException ; 18 import java.io.Writer ; 19 20 import java.util.ArrayList ; 21 import java.util.List ; 22 23 import javax.el.ELException; 24 import javax.faces.FacesException; 25 import javax.faces.component.UIComponent; 26 27 import com.sun.facelets.FaceletContext; 28 import com.sun.facelets.FaceletException; 29 import com.sun.facelets.FaceletHandler; 30 import com.sun.facelets.el.ELText; 31 import com.sun.facelets.tag.TextHandler; 32 import com.sun.facelets.tag.jsf.ComponentSupport; 33 import com.sun.facelets.util.FastWriter; 34 35 39 final class UIInstructionHandler implements FaceletHandler, TextHandler { 40 private final String alias; 41 42 private final ELText txt; 43 44 private final Instruction[] instructions; 45 46 private final int length; 47 48 private final boolean literal; 49 50 public UIInstructionHandler(String alias, Instruction[] instructions, ELText txt) { 51 this.alias = alias; 52 this.instructions = instructions; 53 this.txt = txt; 54 this.length = txt.toString().length(); 55 56 boolean literal = true; 57 int size = instructions.length; 58 59 for (int i = 0; i < size; i++) { 60 Instruction ins = (Instruction) this.instructions[i]; 61 if (!ins.isLiteral()) { 62 literal = false; 63 break; 64 } 65 } 66 67 this.literal = literal; 68 } 69 70 public void apply(FaceletContext ctx, UIComponent parent) 71 throws IOException , FacesException, FaceletException, ELException { 72 if (parent != null) { 73 Instruction[] applied; 74 if (this.literal) { 75 applied = this.instructions; 76 } else { 77 int size = this.instructions.length; 78 applied = new Instruction[size]; 79 Instruction ins; 82 for (int i = 0; i < size; i++) { 83 ins = this.instructions[i]; 84 applied[i] = ins.apply(ctx.getExpressionFactory(), ctx); 85 } 86 } 87 88 UIComponent c = new UIInstructions(txt, applied); 89 c.setId(ComponentSupport.getViewRoot(ctx, parent).createUniqueId()); 90 parent.getChildren().add(c); 91 } 92 } 93 94 public String toString() { 95 return this.txt.toString(); 96 } 97 98 public String getText() { 99 return this.txt.toString(); 100 } 101 102 public String getText(FaceletContext ctx) { 103 Writer writer = new FastWriter(this.length); 104 try { 105 this.txt.apply(ctx.getExpressionFactory(), ctx).write(writer, ctx); 106 } catch (IOException e) { 107 throw new ELException(this.alias + ": "+ e.getMessage(), e.getCause()); 108 } 109 return writer.toString(); 110 } 111 } 112 | Popular Tags |