1 23 package com.sun.enterprise.tools.jsfext.layout.descriptor; 24 25 import com.sun.enterprise.tools.jsfext.component.ComponentUtil; 26 import com.sun.enterprise.tools.jsfext.event.handlers.Handler; 27 import com.sun.enterprise.tools.jsfext.event.handlers.HandlerContext; 28 import com.sun.enterprise.tools.jsfext.event.handlers.HandlerDefinition; 29 30 import java.io.IOException ; 31 import java.util.ArrayList ; 32 33 import javax.faces.component.UIComponent; 34 import javax.faces.context.FacesContext; 35 import javax.faces.context.ResponseWriter; 36 37 38 46 public class LayoutMarkup extends LayoutElementBase implements LayoutElement { 47 48 51 public LayoutMarkup(LayoutElement parent, String tag, String type) { 52 super(parent, tag); 53 _tag = tag; 54 _type = type; 55 56 if (!type.equals(TYPE_OPEN)) { 58 ArrayList handlers = new ArrayList (); 59 handlers.add(afterEncodeHandler); 60 setHandlers(AFTER_ENCODE, handlers); 61 } 62 } 63 64 67 public String getTag() { 68 return _tag; 69 } 70 71 74 public String getType() { 75 return _type; 76 } 77 78 88 protected boolean encodeThis(FacesContext context, UIComponent component) throws IOException { 89 if (getType().equals(TYPE_CLOSE)) { 90 return true; 91 } 92 93 ResponseWriter writer = context.getResponseWriter(); 95 96 Object value = resolveValue(context, component, getTag()); 98 if (value != null) { 99 writer.startElement(value.toString(), component); 100 } 101 102 return true; 104 } 105 106 111 public static void afterEncodeHandler(HandlerContext context) throws IOException { 112 ResponseWriter writer = context.getFacesContext().getResponseWriter(); 113 LayoutMarkup markup = (LayoutMarkup) context.getLayoutElement(); 114 Object value = ComponentUtil.resolveValue(context.getFacesContext(), 115 markup, (UIComponent) context.getEventObject().getSource(), 116 markup.getTag()); 117 if (value != null) { 118 writer.endElement(value.toString()); 119 } 120 } 121 122 125 public static final HandlerDefinition afterEncodeHandlerDef = 126 new HandlerDefinition("_markupAfterEncode"); 127 128 131 public static final Handler afterEncodeHandler = 132 new Handler(afterEncodeHandlerDef); 133 134 static { 135 afterEncodeHandlerDef.setHandlerMethod( 136 LayoutMarkup.class.getName(), "afterEncodeHandler"); 137 } 138 139 142 public static final String TYPE_BOTH = "both"; 143 144 147 public static final String TYPE_CLOSE = "close"; 148 149 152 public static final String TYPE_OPEN = "open"; 153 154 private String _tag = null; 155 private String _type = null; 156 } 157 | Popular Tags |