1 14 15 package com.sun.facelets.compiler; 16 17 import java.io.IOException ; 18 import java.io.StringWriter ; 19 import java.io.Writer ; 20 21 import javax.el.ELException; 22 import javax.faces.FacesException; 23 import javax.faces.component.UIComponent; 24 25 import com.sun.facelets.FaceletContext; 26 import com.sun.facelets.FaceletException; 27 import com.sun.facelets.FaceletHandler; 28 import com.sun.facelets.el.ELText; 29 import com.sun.facelets.tag.TextHandler; 30 import com.sun.facelets.tag.jsf.ComponentSupport; 31 import com.sun.facelets.util.FastWriter; 32 33 37 final class UITextHandler implements FaceletHandler, TextHandler { 38 39 private final ELText txt; 40 41 private final String alias; 42 43 private final int length; 44 45 public UITextHandler(String alias, ELText txt) { 46 this.alias = alias; 47 this.txt = txt; 48 this.length = txt.toString().length(); 49 } 50 51 public void apply(FaceletContext ctx, UIComponent parent) 52 throws IOException , FacesException, FaceletException, ELException { 53 if (parent != null) { 54 try { 55 ELText nt = this.txt.apply(ctx.getExpressionFactory(), ctx); 56 UIComponent c = new UIText(this.alias, nt); 57 c.setId(ComponentSupport.getViewRoot(ctx, parent).createUniqueId()); 58 parent.getChildren().add(c); 60 } catch (Exception e) { 61 throw new ELException(this.alias + ": "+ e.getMessage(), e.getCause()); 62 } 63 } 64 } 65 66 public String toString() { 67 return this.txt.toString(); 68 } 69 70 public String getText() { 71 return this.txt.toString(); 72 } 73 74 public String getText(FaceletContext ctx) { 75 Writer writer = new FastWriter(this.length); 76 try { 77 this.txt.apply(ctx.getExpressionFactory(), ctx).write(writer, ctx); 78 } catch (IOException e) { 79 throw new ELException(this.alias + ": "+ e.getMessage(), e.getCause()); 80 } 81 return writer.toString(); 82 } 83 } 84 | Popular Tags |