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.comp.scripting.*; 31 import org.enhydra.barracuda.core.util.dom.*; 32 import org.enhydra.barracuda.core.view.*; 33 import org.enhydra.barracuda.plankton.*; 34 35 38 public class HTMLScriptRenderer extends DOMComponentRenderer { 39 40 protected static final Logger logger = Logger.getLogger(HTMLScriptRenderer.class.getName()); 41 42 protected EnabledHelper eh = new EnabledHelper(); 43 44 59 public Node createDefaultNode(Document doc, BComponent comp, ViewContext vc) throws UnsupportedFormatException { Node templateNode = vc.getTemplateNode(); 62 Node defaultNode = null; 63 defaultNode = templateNode.cloneNode(true); 64 if (logger.isInfoEnabled()) logger.info("Creating default node: "+defaultNode); 65 return defaultNode; 66 } 67 68 71 public void renderComponent(BComponent comp, View view, ViewContext vc) throws RenderException { 72 if (!(comp instanceof BScript)) throw new NoSuitableRendererException("This renderer can only render BScript components"); 75 BScript bsComp = (BScript) comp; 76 Node node = view.getNode(); 77 78 String jsattr = bsComp.getAttr(); 80 String jscmd = bsComp.getCmd(); 81 int mode = bsComp.getMode(); 82 if (jsattr==null || jscmd==null) return; 83 if (!(node instanceof Element)) return; 84 Element el = (Element) node; 85 86 super.renderComponent(comp, view, vc); 88 89 if (logger.isDebugEnabled()) showNodeInterfaces(view, logger); 91 92 96 if (!jscmd.endsWith(";")) jscmd = jscmd + "; "; 98 String cur_attr = el.getAttribute(jsattr); 99 if (cur_attr==null) mode = BScript.REPLACE; 100 if (mode==BScript.APPEND) { 102 if (!cur_attr.endsWith(";")) cur_attr = cur_attr + "; "; 103 el.setAttribute(jsattr, cur_attr+jscmd); 104 } else if (mode==BScript.PREPEND) { 106 el.setAttribute(jsattr, jscmd+cur_attr); 107 } else { 109 el.setAttribute(jsattr, jscmd); 110 } 111 112 List resources = bsComp.getResources(); 114 if (resources!=null) { 115 Iterator it = resources.iterator(); 116 while (it.hasNext()) { 117 String scr = (String ) it.next(); 118 BScriptResource bsr = new BScriptResource(scr); 119 bsr.setView(new DefaultView(node)); 120 bsComp.addStepChild(bsr, true); 121 } 122 } 123 124 } 128 129 } | Popular Tags |