1 16 package org.apache.cocoon.woody.binding; 17 18 import org.apache.cocoon.woody.binding.JXPathBindingManager.Assistant; 19 import org.apache.cocoon.woody.util.DomHelper; 20 import org.apache.cocoon.woody.util.JavaScriptHelper; 21 import org.mozilla.javascript.Script; 22 import org.w3c.dom.Element ; 23 24 57 public class JavaScriptJXPathBindingBuilder extends JXPathBindingBuilderBase { 58 59 public JXPathBindingBase buildBinding(Element element, Assistant assistant) throws BindingException { 60 try { 61 CommonAttributes commonAtts = JXPathBindingBuilderBase.getCommonAttributes(element); 62 63 String id = DomHelper.getAttribute(element, "id"); 64 String path = DomHelper.getAttribute(element, "path"); 65 66 Script loadScript = null; 67 if (commonAtts.loadEnabled) { 68 Element loadElem = DomHelper.getChildElement(element, BindingManager.NAMESPACE, "load-form"); 69 if (loadElem == null) { 70 throw new BindingException("Element \"load-form\" is missing (" + 71 DomHelper.getLocation(element) + ")"); 72 } 73 loadScript = JavaScriptHelper.buildScript(loadElem); 74 } 75 76 Script saveScript = null; 77 if (commonAtts.saveEnabled) { 78 Element saveElem = DomHelper.getChildElement(element, BindingManager.NAMESPACE, "save-form"); 79 if (saveElem == null) { 80 throw new BindingException("Element \"save-form\" is missing (" + 81 DomHelper.getLocation(element) + ")"); 82 } 83 saveScript = JavaScriptHelper.buildScript(saveElem); 84 } 85 86 return new JavaScriptJXPathBinding(commonAtts, id, path, loadScript, saveScript); 87 88 } catch(Exception e) { 89 throw new BindingException("Cannot build binding at " + DomHelper.getLocation(element), e); 90 } 91 } 92 } 93 | Popular Tags |