1 14 15 package com.sun.facelets.tag.ui; 16 17 import java.io.IOException ; 18 import java.util.ArrayList ; 19 import java.util.HashMap ; 20 import java.util.Iterator ; 21 import java.util.List ; 22 import java.util.Map ; 23 import java.util.logging.Level ; 24 import java.util.logging.Logger ; 25 26 import javax.el.ELException; 27 import javax.el.VariableMapper; 28 import javax.faces.FacesException; 29 import javax.faces.component.UIComponent; 30 31 import com.sun.facelets.FaceletContext; 32 import com.sun.facelets.FaceletException; 33 import com.sun.facelets.FaceletHandler; 34 import com.sun.facelets.TemplateClient; 35 import com.sun.facelets.el.VariableMapperWrapper; 36 import com.sun.facelets.tag.TagAttribute; 37 import com.sun.facelets.tag.TagConfig; 38 import com.sun.facelets.tag.TagHandler; 39 40 44 public final class DecorateHandler extends TagHandler implements TemplateClient { 45 46 private final Logger log = Logger.getLogger("facelets.tag.ui.decorate"); 47 48 private final TagAttribute template; 49 50 private final Map handlers; 51 52 private final ParamHandler[] params; 53 54 57 public DecorateHandler(TagConfig config) { 58 super(config); 59 this.template = this.getRequiredAttribute("template"); 60 this.handlers = new HashMap (); 61 62 Iterator itr = this.findNextByType(DefineHandler.class); 63 DefineHandler d = null; 64 while (itr.hasNext()) { 65 d = (DefineHandler) itr.next(); 66 this.handlers.put(d.getName(), d); 67 if (log.isLoggable(Level.FINE)) { 68 log.fine(tag + " found Define[" + d.getName() + "]"); 69 } 70 } 71 List paramC = new ArrayList (); 72 itr = this.findNextByType(ParamHandler.class); 73 while (itr.hasNext()) { 74 paramC.add(itr.next()); 75 } 76 if (paramC.size() > 0) { 77 this.params = new ParamHandler[paramC.size()]; 78 for (int i = 0; i < this.params.length; i++) { 79 this.params[i] = (ParamHandler) paramC.get(i); 80 } 81 } else { 82 this.params = null; 83 } 84 } 85 86 92 public void apply(FaceletContext ctx, UIComponent parent) 93 throws IOException , FacesException, FaceletException, ELException { 94 VariableMapper orig = ctx.getVariableMapper(); 95 if (this.params != null) { 96 VariableMapper vm = new VariableMapperWrapper(orig); 97 ctx.setVariableMapper(vm); 98 for (int i = 0; i < this.params.length; i++) { 99 this.params[i].apply(ctx, parent); 100 } 101 } 102 103 ctx.extendClient(this); 104 try { 105 ctx.includeFacelet(parent, this.template.getValue(ctx)); 106 } finally { 107 ctx.setVariableMapper(orig); 108 ctx.popClient(this); 109 } 110 } 111 112 public boolean apply(FaceletContext ctx, UIComponent parent, String name) throws IOException , FacesException, FaceletException, ELException { 113 if (name != null) { 114 FaceletHandler handler = (FaceletHandler) this.handlers.get(name); 115 if (handler != null) { 116 handler.apply(ctx, parent); 117 return true; 118 } else { 119 return false; 120 } 121 } else { 122 this.nextHandler.apply(ctx, parent); 123 return false; 124 } 125 } 126 } 127 | Popular Tags |