1 20 package org.enhydra.barracuda.core.comp.renderer.html; 21 22 import java.util.*; 23 24 import org.apache.log4j.*; 25 import org.w3c.dom.*; 26 import org.w3c.dom.html.*; 27 28 import org.enhydra.barracuda.core.comp.*; 29 import org.enhydra.barracuda.core.comp.renderer.*; 30 import org.enhydra.barracuda.core.util.dom.*; 31 import org.enhydra.barracuda.plankton.*; 32 33 40 public class HTMLTextRenderer extends HTMLComponentRenderer { 41 42 protected static final Logger logger = Logger.getLogger(HTMLTextRenderer.class.getName()); 43 44 protected EnabledHelper eh = new EnabledHelper(); 45 46 59 public Node createDefaultNode(Document doc, BComponent comp, ViewContext vc) throws UnsupportedFormatException { Node templateNode = vc.getTemplateNode(); 63 Node defaultNode = templateNode.cloneNode(true); 64 if (logger.isInfoEnabled()) logger.info("Creating default node:"+defaultNode); 65 return defaultNode; 66 } 68 69 72 public void renderComponent(BComponent comp, View view, ViewContext vc) throws RenderException { 73 if (!(comp instanceof BText)) throw new NoSuitableRendererException("This renderer can only render BText components"); 75 BText btext = (BText) comp; 76 Node node = view.getNode(); 77 String text = btext.getText(); 79 if (logger.isDebugEnabled()) showNodeInterfaces(view, logger); 81 82 super.renderComponent(comp, view, vc); 84 85 if (node instanceof HTMLDocument) { 88 if (logger.isInfoEnabled()) logger.info("Rendering based on HTMLDocument interface..."); 90 ((HTMLDocument) node).setTitle(btext.getText()); 91 92 } else if (node instanceof HTMLElement) { 102 103 if (node instanceof HTMLAreaElement) { 105 if (logger.isInfoEnabled()) logger.info("Rendering based on HTMLAreaElement interface..."); 106 if (text!=null) ((HTMLAreaElement) node).setAlt(text); 109 } else if (node instanceof HTMLImageElement) { 111 if (logger.isInfoEnabled()) logger.info("Rendering based on HTMLImageElement interface..."); 112 if (text!=null) ((HTMLImageElement) node).setAlt(text); 115 } else if (node instanceof HTMLInputElement) { 117 if (logger.isInfoEnabled()) logger.info("Rendering based on HTMLInputElement interface..."); 118 if (text!=null) ((HTMLInputElement) node).setValue(text); 121 } else if (node instanceof HTMLTitleElement) { 123 if (logger.isInfoEnabled()) logger.info("Rendering based on HTMLTitleElement interface..."); 124 if (text!=null) ((HTMLTitleElement) node).setText(text); 127 } else { 130 if (logger.isInfoEnabled()) logger.info("Rendering based on "+Classes.getShortClassName(node.getClass())+" interface in first child Text element..."); 131 if (text!=null) DOMUtil.setTextInNode((Element) node, text, btext.allowMarkupInText()); } 134 } else { 135 String errmsg = "Node does not implement HTMLElement or HTMLDocument and cannot be rendered: "+node; 136 logger.warn(errmsg); 137 throw new NoSuitableRendererException(errmsg); 138 } 139 140 eh.setEnabled(node, comp.isEnabled()); 142 } 143 144 } | Popular Tags |