List of usage examples for org.apache.commons.jxpath JXPathContext getPointer
public abstract Pointer getPointer(String xpath);
From source file:blueprint.sdk.util.JXPathHelper.java
/** * @param xpath XPath to evaluate/*from w w w .j a v a 2 s.com*/ * @param context target context, JXPathContext.newContext(Node) * @return Pointer or null(not found) */ @SuppressWarnings("WeakerAccess") public static Pointer evaluatePointer(String xpath, JXPathContext context) { Pointer result = null; try { result = context.getPointer(xpath); } catch (JXPathNotFoundException ignored) { } return result; }
From source file:blueprint.sdk.util.JXPathHelper.java
/** * @param xpath XPath to evaluate//ww w.j av a 2 s.c om * @param context target context, JXPathContext.newContext(Node) * @return Pointer or null(not found) */ @SuppressWarnings("WeakerAccess") public static Node evaluateNode(String xpath, JXPathContext context) { Node result = null; try { Pointer ptr = context.getPointer(xpath); if (ptr != null) { result = (Node) ptr.getNode(); } } catch (JXPathNotFoundException ignored) { } return result; }
From source file:com.yahoo.xpathproto.JXPathCopier.java
public static JXPathContext getRelativeContext(JXPathContext context, String path) { Pointer pointer = context.getPointer(path); if ((pointer == null) || (pointer.getNode() == null)) { return null; }/* w ww. ja va2 s .c o m*/ return context.getRelativeContext(pointer); }
From source file:jp.go.nict.langrid.bpel.deploy.BPRDeployer.java
/** * //from w w w. j a v a 2s .c o m * */ static DeploymentResult parseResult(String aResult) throws SAXException, IOException { DeploymentResult result = new DeploymentResult(); result.setSourceString(aResult); JXPathContext context = JXPathUtil.newXMLContext(aResult); context.setLenient(true); JXPathContext summary = JXPathContext.newContext(context, context.getPointer("/deploymentSummary").getNode()); result.setSummaryErrorCount(Integer.parseInt(summary.getValue("/@numErrors").toString())); result.setSummaryWarningCount(Integer.parseInt(summary.getValue("/@numWarnings").toString())); result.setSummaryMessages(summary.getValue("/globalMessages").toString()); summary.setLenient(true); Node deploymentInfoNode = (Node) summary.getPointer("/deploymentInfo").getNode(); if (deploymentInfoNode != null) { JXPathContext info = JXPathContext.newContext(summary, deploymentInfoNode); result.setDeploymentErrorCount(Integer.parseInt(info.getValue("/@numErrors").toString())); result.setDeploymentWarningCount(Integer.parseInt(info.getValue("/@numWarnings").toString())); result.setDeployed(Boolean.parseBoolean(info.getValue("/@deployed").toString())); result.setPddFilename(info.getValue("/@pddName").toString()); result.setDeploymentLog(info.getValue("/log").toString()); } return result; }
From source file:com.opera.core.systems.scope.AbstractService.java
/** * Query a collection JXPath and return a pointer FIXME: This does not belong * here!/*from www .ja va2s. c om*/ * * @param collection * @param query * @return Pointer to node */ public Pointer xpathPointer(Collection<?> collection, String query) { JXPathContext pathContext = JXPathContext.newContext(collection); Pointer result = null; try { result = pathContext.getPointer(query); } catch (JXPathNotFoundException e) { logger.log(Level.WARNING, "JXPath exception: {0}", e.getMessage()); } return result; }
From source file:com.idega.chiba.web.xml.xforms.elements.action.IdegaDeleteAction.java
/** * Performs the <code>delete</code> action for all nodes. * //from ww w .ja va 2 s. co m * @throws XFormsException * if an error occurred during <code>delete</code> processing. */ public void perform() throws XFormsException { super.perform(); // get instance and nodeset information Instance instance = this.model.getInstance(getInstanceId()); String pathExpression = getLocationPath(); int contextSize = instance.countNodeset(pathExpression); if (contextSize == 0) { getLogger().warn(this + " perform: nodeset '" + pathExpression + "' is empty"); return; } String path = null; // since jxpath doesn't provide a means for evaluating an expression // in a certain context, we use a trick here: the expression will be // evaluated during getPointer and the result stored as a variable JXPathContext context = instance.getInstanceContext(); boolean lenient = context.isLenient(); context.setLenient(true); context.getPointer(pathExpression + "[chiba:declare('delete-position', 1)]"); context.setLenient(lenient); // since jxpath's round impl is buggy (returns 0 for NaN) we perform // 'round' manually double value = ((Double) context.getValue("number(chiba:undeclare('delete-position'))")).doubleValue(); long position = Math.round(value); if (Double.isNaN(value) || position < 1 || position > contextSize) { getLogger().warn(this + " perform: expression '1' does not point to an existing node"); return; } path = new StringBuffer(pathExpression).append('[').append(position).append(']').toString(); // delete specified node and dispatch notification event while (instance.existsNode(path)) { try { instance.deleteNode(path); getLogger().info("Node deleted in delete action:" + path); } catch (JXPathException e) { getLogger().warn("Unable to delete:" + path); } } if (StringUtil.isEmpty(path)) { return; } this.container.dispatch(instance.getTarget(), XFormsEventNames.DELETE, path); // update behaviour doRebuild(true); doRecalculate(true); doRevalidate(true); doRefresh(true); }
From source file:net.sf.oval.ogn.ObjectGraphNavigatorJXPathImpl.java
public ObjectGraphNavigationResult navigateTo(final Object root, final String xpath) throws InvalidConfigurationException { Assert.argumentNotNull("root", root); Assert.argumentNotNull("xpath", xpath); try {//w w w . j ava 2 s .c o m final JXPathContext ctx = JXPathContext.newContext(root); ctx.setLenient(true); // do not throw an exception if object graph is incomplete, e.g. contains null-values Pointer pointer = ctx.getPointer(xpath); // no match found or invalid xpath if (pointer instanceof NullPropertyPointer || pointer instanceof NullPointer) return null; if (pointer instanceof BeanPointer) { final Pointer parent = ((BeanPointer) pointer).getImmediateParentPointer(); if (parent instanceof PropertyPointer) { pointer = parent; } } if (pointer instanceof PropertyPointer) { final PropertyPointer pp = (PropertyPointer) pointer; final Class<?> beanClass = pp.getBean().getClass(); AccessibleObject accessor = ReflectionUtils.getField(beanClass, pp.getPropertyName()); if (accessor == null) { accessor = ReflectionUtils.getGetter(beanClass, pp.getPropertyName()); } return new ObjectGraphNavigationResult(root, xpath, pp.getBean(), accessor, pointer.getValue()); } throw new InvalidConfigurationException("Don't know how to handle pointer [" + pointer + "] of type [" + pointer.getClass().getName() + "] for xpath [" + xpath + "]"); } catch (final JXPathNotFoundException ex) { // thrown if the xpath is invalid throw new InvalidConfigurationException(ex); } }
From source file:net.sbbi.upnp.services.UPNPService.java
private void parseServiceStateVariables(JXPathContext rootContext) { Pointer serviceStateTablePtr = rootContext.getPointer("serviceStateTable"); JXPathContext serviceStateTableCtx = rootContext.getRelativeContext(serviceStateTablePtr); Double arraySize = (Double) serviceStateTableCtx.getValue("count( stateVariable )"); UPNPServiceStateVariables = new HashMap(); for (int i = 1; i <= arraySize.intValue(); i++) { ServiceStateVariable srvStateVar = new ServiceStateVariable(); String sendEventsLcl = null; try {/*from w ww . j a va 2s .c om*/ sendEventsLcl = (String) serviceStateTableCtx.getValue("stateVariable[" + i + "]/@sendEvents"); } catch (JXPathException defEx) { // sendEvents not provided defaulting according to specs to "yes" sendEventsLcl = "yes"; } srvStateVar.parent = this; srvStateVar.sendEvents = sendEventsLcl.equalsIgnoreCase("no") ? false : true; srvStateVar.name = (String) serviceStateTableCtx.getValue("stateVariable[" + i + "]/name"); srvStateVar.dataType = (String) serviceStateTableCtx.getValue("stateVariable[" + i + "]/dataType"); try { srvStateVar.defaultValue = (String) serviceStateTableCtx .getValue("stateVariable[" + i + "]/defaultValue"); } catch (JXPathException defEx) { // can happend since default value is not } Pointer allowedValuesPtr = null; try { allowedValuesPtr = serviceStateTableCtx.getPointer("stateVariable[" + i + "]/allowedValueList"); } catch (JXPathException ex) { // there is no allowed values list. } if (allowedValuesPtr != null) { JXPathContext allowedValuesCtx = serviceStateTableCtx.getRelativeContext(allowedValuesPtr); Double arraySizeAllowed = (Double) allowedValuesCtx.getValue("count( allowedValue )"); srvStateVar.allowedvalues = new HashSet(); for (int z = 1; z <= arraySizeAllowed.intValue(); z++) { String allowedValue = (String) allowedValuesCtx.getValue("allowedValue[" + z + "]"); srvStateVar.allowedvalues.add(allowedValue); } } Pointer allowedValueRangePtr = null; try { allowedValueRangePtr = serviceStateTableCtx .getPointer("stateVariable[" + i + "]/allowedValueRange"); } catch (JXPathException ex) { // there is no allowed values list, can happen } if (allowedValueRangePtr != null) { srvStateVar.minimumRangeValue = (String) serviceStateTableCtx .getValue("stateVariable[" + i + "]/allowedValueRange/minimum"); srvStateVar.maximumRangeValue = (String) serviceStateTableCtx .getValue("stateVariable[" + i + "]/allowedValueRange/maximum"); try { srvStateVar.stepRangeValue = (String) serviceStateTableCtx .getValue("stateVariable[" + i + "]/allowedValueRange/step"); } catch (JXPathException stepEx) { // can happend since step is not mandatory } } UPNPServiceStateVariables.put(srvStateVar.getName(), srvStateVar); } }
From source file:net.sbbi.upnp.services.UPNPService.java
private void parseSCPD() { try {/*from www . java 2s . com*/ DocumentContainer.registerXMLParser(DocumentContainer.MODEL_DOM, new JXPathParser()); UPNPService = new DocumentContainer(SCPDURL, DocumentContainer.MODEL_DOM); JXPathContext context = JXPathContext.newContext(this); Pointer rootPtr = context.getPointer("UPNPService/scpd"); JXPathContext rootCtx = context.getRelativeContext(rootPtr); specVersionMajor = Integer.parseInt((String) rootCtx.getValue("specVersion/major")); specVersionMinor = Integer.parseInt((String) rootCtx.getValue("specVersion/minor")); parseServiceStateVariables(rootCtx); Pointer actionsListPtr = rootCtx.getPointer("actionList"); JXPathContext actionsListCtx = context.getRelativeContext(actionsListPtr); Double arraySize = (Double) actionsListCtx.getValue("count( action )"); UPNPServiceActions = new HashMap(); for (int i = 1; i <= arraySize.intValue(); i++) { ServiceAction action = new ServiceAction(); action.name = (String) actionsListCtx.getValue("action[" + i + "]/name"); action.parent = this; Pointer argumentListPtr = null; try { argumentListPtr = actionsListCtx.getPointer("action[" + i + "]/argumentList"); } catch (JXPathException ex) { // there is no arguments list. } if (argumentListPtr != null) { JXPathContext argumentListCtx = actionsListCtx.getRelativeContext(argumentListPtr); Double arraySizeArgs = (Double) argumentListCtx.getValue("count( argument )"); List orderedActionArguments = new ArrayList(); for (int z = 1; z <= arraySizeArgs.intValue(); z++) { ServiceActionArgument arg = new ServiceActionArgument(); arg.name = (String) argumentListCtx.getValue("argument[" + z + "]/name"); String direction = (String) argumentListCtx.getValue("argument[" + z + "]/direction"); arg.direction = direction.equals(ServiceActionArgument.DIRECTION_IN) ? ServiceActionArgument.DIRECTION_IN : ServiceActionArgument.DIRECTION_OUT; String stateVarName = (String) argumentListCtx .getValue("argument[" + z + "]/relatedStateVariable"); ServiceStateVariable stateVar = (ServiceStateVariable) UPNPServiceStateVariables .get(stateVarName); if (stateVar == null) { throw new IllegalArgumentException( "Unable to find any state variable named " + stateVarName + " for service " + getServiceId() + " action " + action.name + " argument " + arg.name); } arg.relatedStateVariable = stateVar; orderedActionArguments.add(arg); } if (arraySizeArgs.intValue() > 0) { action.setActionArguments(orderedActionArguments); } } UPNPServiceActions.put(action.getName(), action); } parsedSCPD = true; } catch (Throwable t) { throw new RuntimeException("Error during lazy SCDP file parsing at " + SCPDURL, t); } }
From source file:net.sbbi.upnp.devices.UPNPRootDevice.java
/** * 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 *//*from w w w. j a v a2 s .c o m*/ 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); } }