/** * 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); } }
JXPathContext iconListCtx = deviceCtx.getRelativeContext( iconListPtr ); Double arraySize = (Double)iconListCtx.getValue( "count( icon )" ); if ( log.isDebugEnabled() ) log.debug( "device icons count is " + arraySize );
/** * 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 doSave(Widget frmModel, JXPathContext jctx) throws BindingException { if (this.saveScript != null) { Widget widget = selectWidget(frmModel, this.id); // Move to widget context and create the path if needed Pointer pointer = jctx.createPath(this.path); JXPathContext widgetCtx = jctx.getRelativeContext(pointer); try { Map objectModel = processInfoProvider.getObjectModel(); JavaScriptHelper.callFunction(this.saveScript, widget, new Object[]{widget, pointer, widgetCtx, 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] - saveForm: No code available on the javascript binding with id '" + getId() + "'"); } } } }
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()); } } }
JXPathContext multiValueContext = jctx.getRelativeContext(ptr);
JXPathContext repeaterContext = jctx.getRelativeContext(ptr); JXPathContext rowContext = repeaterContext.getRelativeContext(jxp);
/** * 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); } }
public void doSave(Widget frmModel, JXPathContext jctx) throws BindingException { // Find the repeater Repeater repeater = (Repeater) selectWidget(frmModel, this.repeaterId); if (repeater.getSize() == 0 && this.deleteIfEmpty) { // Repeater is empty : erase all jctx.removeAll(this.repeaterPath); } else { // Repeater is not empty // Move to repeater context and create the path if needed JXPathContext repeaterContext = jctx.getRelativeContext(jctx.createPath(this.repeaterPath)); // Delete all that is already present repeaterContext.removeAll(this.rowPath); for (int i = 0; i < repeater.getSize(); i++) { Pointer rowPtr = repeaterContext.createPath( this.rowPath + '[' + (i+1) + ']'); JXPathContext rowContext = repeaterContext.getRelativeContext(rowPtr); this.rowBinding.saveFormToModel(repeater.getRow(i), rowContext); } } }
subContext = jxpc.getRelativeContext(jxpc.getPointer(this.xpath)); } catch (JXPathException e) {
Object[] values = (Object[])widget.getValue(); JXPathContext multiValueContext = jctx.getRelativeContext(jctx.createPath(this.multiValuePath));
rep.doPageSave(); Pointer ptr = jxpc.getPointer(super.getRepeaterPath()); JXPathContext repeaterContext = jxpc.getRelativeContext(ptr); RepeaterJXPathCollection collection = rep.getCollection(); super.getInsertRowPath() + "[" + indexCount + "]"); JXPathContext newRowContext = repeaterContext.getRelativeContext(newRowContextPointer);
Iterator<Pointer> itr = context.iteratePointers(group.getResourceXpath()); while (itr.hasNext()) { JXPathContext relativeContext = context.getRelativeContext(itr.next()); String resourceName = getResourceName(relativeContext, group); LOG.debug("fillCollectionSet: processing XML resource {} of type {}", resourceName, group.getResourceType());
Iterator<Pointer> itr = context.iteratePointers(group.getResourceXpath()); while (itr.hasNext()) { JXPathContext relativeContext = context.getRelativeContext(itr.next()); String resourceName = getResourceName(relativeContext, group); LOG.debug("fillCollectionSet: processing XML resource {} of type {}", resourceName, group.getResourceType());
/** * Test to verify XPath content. * * @throws Exception the exception */ @Test @SuppressWarnings("unchecked") public void testXpath() throws Exception { JSONObject json = MockDocumentBuilder.getJSONDocument(); JXPathContext context = JXPathContext.newContext(json); Iterator<Pointer> itr = context.iteratePointers("/zones/zone"); while (itr.hasNext()) { Pointer resPtr = itr.next(); JXPathContext relativeContext = context.getRelativeContext(resPtr); String resourceName = (String) relativeContext.getValue("@name"); Assert.assertNotNull(resourceName); String value = (String) relativeContext.getValue("parameter[@key='nproc']/@value"); Assert.assertNotNull(Integer.valueOf(value)); } }