1 16 package org.apache.cocoon.woody.binding; 17 18 import org.apache.cocoon.woody.formmodel.Widget; 19 import org.apache.commons.jxpath.JXPathContext; 20 import org.apache.commons.jxpath.Pointer; 21 22 29 public class ContextJXPathBinding extends ComposedJXPathBindingBase { 30 31 34 private final String xpath; 35 36 39 public ContextJXPathBinding(JXPathBindingBuilderBase.CommonAttributes commonAtts, String contextPath, JXPathBindingBase[] childBindings) { 40 super(commonAtts, childBindings); 41 this.xpath = contextPath; 42 } 43 44 48 public void doLoad(Widget frmModel, JXPathContext jxpc) throws BindingException { 49 Pointer ptr = jxpc.getPointer(this.xpath); 50 if (ptr.getNode() != null) { 51 JXPathContext subContext = jxpc.getRelativeContext(ptr); 52 super.doLoad(frmModel, subContext); 53 if (getLogger().isDebugEnabled()) 54 getLogger().debug("done loading " + toString()); 55 } else { 56 if (getLogger().isDebugEnabled()) { 57 getLogger().debug("non-existent path: skipping " + toString()); 58 } 59 } 60 } 61 62 66 public void doSave(Widget frmModel, JXPathContext jxpc) throws BindingException { 67 Pointer ptr = jxpc.getPointer(this.xpath); 68 if (ptr.getNode() == null) { 69 jxpc.createPath(this.xpath); 70 ptr = jxpc.getPointer(this.xpath); 72 } 73 JXPathContext subContext = jxpc.getRelativeContext(ptr); 74 super.doSave(frmModel, subContext); 75 if (getLogger().isDebugEnabled()) { 76 getLogger().debug("done saving " + toString()); 77 } 78 } 79 80 public String toString() { 81 return "ContextJXPathBinding [xpath=" + this.xpath + "]"; 82 } 83 } 84 | Popular Tags |