private String getFileName(JXPathContext context, String xpath) throws Exception { Pointer pointer = context.getPointer(xpath); Object value = pointer.getValue(); return value.toString(); }
/** * Finds the first object that matches the specified XPath. It is equivalent * to <code>getPointer(xpath).getNode()</code>. Note that this method * produces the same result as <code>getValue()</code> on object models * like JavaBeans, but a different result for DOM/JDOM etc., because it * returns the Node itself, rather than its textual contents. * * @param xpath the xpath to be evaluated * @return the found object */ public Object selectSingleNode(String xpath) { Pointer pointer = getPointer(xpath); return pointer == null ? null : pointer.getNode(); }
/** * Query a collection JXPath and return a pointer. * * @return pointer to node */ // TODO: This does not belong here! public Pointer xpathPointer(Collection<?> collection, String query) { JXPathContext pathContext = JXPathContext.newContext(collection); Pointer result = null; try { result = pathContext.getPointer(query); } catch (JXPathNotFoundException e) { logger.warning(String.format("JXPath exception: %s", e.getMessage())); } return result; }
@Override public boolean filter(Event event) { JXPathContext context = JXPathContext.newContext(event); Pointer pointer = context.getPointer(expression); return (Boolean)pointer.getValue(); }
@Override public boolean apply(Object input) { JXPathContext jxpath = JXPathContext.newContext(input); // We should allow non-existing path, and let predicate handle it. jxpath.setLenient(true); Pointer pointer = jxpath.getPointer(xpath); return pointer != null && !(pointer instanceof NullPointer); }
/** * Parsing an UPNPdevice services list element (<device/serviceList>) in the description XML file * @param device the device object that will store the services list (UPNPService) objects * @param deviceCtx an XPath context for object population * @throws MalformedURLException if some URL provided in the description * file for a service entry is invalid */ private void fillUPNPServicesList( UPNPDevice device, JXPathContext deviceCtx ) throws MalformedURLException { Pointer serviceListPtr = deviceCtx.getPointer( "serviceList" ); JXPathContext serviceListCtx = deviceCtx.getRelativeContext( serviceListPtr ); Double arraySize = (Double)serviceListCtx.getValue( "count( service )" ); if ( log.isDebugEnabled() ) log.debug( "device services count is " + arraySize ); device.services = new ArrayList(); for ( int i = 1; i <= arraySize.intValue(); i++ ) { Pointer servicePtr = serviceListCtx.getPointer( "service["+i+"]" ); JXPathContext serviceCtx = serviceListCtx.getRelativeContext( servicePtr ); // TODO possibility of bugs if deviceDefLoc contains a file name URL base = URLBase != null ? URLBase : deviceDefLoc; UPNPService service = new UPNPService( serviceCtx, base, this ); device.services.add( service ); } }
/** * Narrows the scope on the form-model to the member widget-field, and * narrows the scope on the object-model to the member xpath-context * before continuing the binding over the child-bindings. */ public void doSave(Widget frmModel, JXPathContext jxpc) throws BindingException { AggregateField aggregate = (AggregateField) selectWidget(frmModel, this.widgetId); JXPathContext subContext = jxpc.getRelativeContext(jxpc.getPointer(this.xpath)); super.doSave(aggregate, subContext); if (getLogger().isDebugEnabled()) { getLogger().debug("Done saving " + this); } }
public RepeaterItem getItem(int i) { if (i < 0) return null; if (i >= jxCollection.getOriginalCollectionSize()) return null; if (this.sortedItems == null) { JXPathContext storageContext = this.jxCollection.getStorageContext(); Pointer pointer = storageContext.getPointer(binding.getRowPath() + "[" + (i+1) + "]"); JXPathContext rowContext = storageContext.getRelativeContext(pointer); RepeaterItem item = new RepeaterItem(new Integer(i + 1)); item.setContext(rowContext); return item; } else { return (RepeaterItem) sortedItems.get(i); } }
/** * Actively performs the binding from the ObjectModel wrapped in a jxpath * context to the CocoonForm. */ public void doLoad(Widget frmModel, JXPathContext jxpc) throws BindingException { Pointer ptr = jxpc.getPointer(this.xpath); if (ptr.getNode() != null) { JXPathContext subContext = jxpc.getRelativeContext(ptr); super.doLoad(frmModel, subContext); if (getLogger().isDebugEnabled()) { getLogger().debug("done loading " + this); } } else { if (getLogger().isDebugEnabled()) { getLogger().debug("non-existent path: skipping " + this); } } }
/** * Narrows the scope on the form-model to the member widget-field, and * narrows the scope on the object-model to the member xpath-context * before continuing the binding over the child-bindings. */ public void doLoad(Widget frmModel, JXPathContext jxpc) throws BindingException { Widget widget = selectWidget(frmModel, this.widgetId); JXPathContext subContext = jxpc.getRelativeContext(jxpc.getPointer(this.xpath)); if (!(widget instanceof Union)) { throw new RuntimeException("Binding: Expected Union widget, but received class: \"" + widget.getClass().getName() + "\"."); } Union unionWidget = (Union)widget; Binding[] subBindings = getChildBindings(); if (subBindings != null) { int size = subBindings.length; for (int i = 0; i < size; i++) { subBindings[i].loadFormFromModel(unionWidget, subContext); } } if (getLogger().isDebugEnabled()) { getLogger().debug("done loading " + this); } }
/** * Actively performs the binding from the CocoonForm to the ObjectModel * wrapped in a jxpath context. */ public void doSave(Widget frmModel, JXPathContext jxpc) throws BindingException { if (this.factory != null) { jxpc.setFactory(this.factory); } Pointer ptr = jxpc.getPointer(this.xpath); if (ptr.getNode() == null) { jxpc.createPath(this.xpath); // Need to recreate the pointer after creating the path ptr = jxpc.getPointer(this.xpath); } JXPathContext subContext = jxpc.getRelativeContext(ptr); super.doSave(frmModel, subContext); if (getLogger().isDebugEnabled()) { getLogger().debug("done saving " + this); } }
Pointer iconListPtr; try { iconListPtr = deviceCtx.getPointer( "iconList" ); } catch ( JXPathException ex ) {
/** * Narrows the scope on the form-model to the member widget-field, and * narrows the scope on the object-model to the member xpath-context * before continuing the binding over the child-bindings. */ public void doSave(Widget frmModel, JXPathContext jxpc) throws BindingException { Union unionWidget = (Union)selectWidget(frmModel, this.widgetId); JXPathContext subContext = jxpc.getRelativeContext(jxpc.getPointer(this.xpath)); Binding[] subBindings = getChildBindings(); if (subBindings != null) { int size = subBindings.length; for (int i = 0; i < size; i++) { subBindings[i].saveFormToModel(unionWidget, subContext); } } if (getLogger().isDebugEnabled()) { getLogger().debug("done saving " + this); } }
/** * Narrows the scope on the form-model to the member widget-field, and * narrows the scope on the object-model to the member xpath-context * before continuing the binding over the child-bindings. */ public void doLoad(Widget frmModel, JXPathContext jxpc) throws BindingException { AggregateField aggregate = (AggregateField) selectWidget(frmModel, this.widgetId); JXPathContext subContext = jxpc.getRelativeContext(jxpc.getPointer(this.xpath)); super.doLoad(aggregate, subContext); aggregate.combineFields(); if (getLogger().isDebugEnabled()) { getLogger().debug("Done loading " + this); } }
public void doLoad(Widget frmModel, JXPathContext jctx) { if (this.loadScript != null) { Widget widget = selectWidget(frmModel, this.id); // Move to widget context Pointer pointer = jctx.getPointer(this.path); Map objectModel = processInfoProvider.getObjectModel(); try { JXPathContext newCtx = pointer.getNode() == null ? null : jctx.getRelativeContext(pointer); JavaScriptHelper.callFunction(this.loadScript, widget, new Object[]{widget, pointer, newCtx, this.childBindings}, objectModel); } catch (RuntimeException re) { // rethrow throw re; } catch (Exception e) { throw new RuntimeException("Error invoking JavaScript event handler", e); } } else { if (getLogger().isInfoEnabled()) { getLogger().info("[Javascript Binding] - loadForm: No javascript code available. Widget id=" + this.getId()); } } }
Pointer ptr = jctx.getPointer(this.multiValuePath); if (ptr.getNode() != null) {
subContext = jxpc.getRelativeContext(jxpc.getPointer(this.xpath)); } catch (JXPathException e) {
Pointer ptr = jctx.getPointer(this.repeaterPath); if (ptr.getNode() != null) {
/** return the xpath for a particular object. * * @param target object to return xpath for. must be in object tree (or a similar object equivalent under equals()) * @return xpath for that object, or null * */ public final String getXPathFor(Object target) { // add variable we're looking for. JXPathContext cxt = this.accessJXPathContext(); cxt.getVariables().declareVariable("target",target); Pointer p = cxt.getPointer("//*[fn:matchTarget()]"); // tidyup cxt.getVariables().undeclareVariable("target"); // sanity check.. return p != null && p.getNode() != null ? p.asPath() : null; }
Pointer ptr = jxpc.getPointer(super.getRepeaterPath()); JXPathContext repeaterContext = jxpc.getRelativeContext(ptr); RepeaterJXPathCollection collection = rep.getCollection();