List of usage examples for org.apache.commons.jxpath JXPathContext getValue
public abstract Object getValue(String xpath);
From source file:org.xchain.javassist.CommandEngineeringTest.java
@Test public void testWrappingExecute() throws Exception { Command command = getWrappingCommand("org.xchain.javassist.SimpleCommand"); // create a context. JXPathContext context = JXPathContext.newContext(new Object()); // execute the command command.execute(context);/*from w ww . j a v a 2 s . c o m*/ // assert that the namespace was defined while the command executed. assertEquals("The namespace returned was not correct.", (Object) "http://www.xchain.org/test", context.getValue("$namespace")); // assert that the namespace is no longer defined on the context. assertEquals("The namespace was still defined on the context.", (String) null, context.getNamespaceURI("test")); }
From source file:org.xchain.javassist.CommandEngineeringTest.java
@Test public void testWrappingInnerExecute() throws Exception { Command command = getWrappingInnerCommand("org.xchain.javassist.InnerClassCommand"); // create a context. JXPathContext context = JXPathContext.newContext(new Object()); // execute the command command.execute(context);/*from w w w . ja v a 2 s .c om*/ // assert that the namespace was defined while the command executed. assertEquals("The namespace returned was not correct.", (Object) "http://www.xchain.org/test", context.getValue("$namespace")); assertEquals("The namespace returned was not correct.", (Object) "http://www.xchain.org/test-inner", context.getValue("$inner-namespace")); assertEquals("The namespace returned was not correct.", (Object) "http://www.xchain.org/test-static-inner", context.getValue("$static-inner-namespace")); // assert that the namespace is no longer defined on the context. assertEquals("The namespace was still defined on the context.", (String) null, context.getNamespaceURI("test")); }
From source file:org.xchain.namespaces.hibernate.PersistCommand.java
/** * Persist the entity at the given QName. Note that persist will only perform an * insert if it is within a transaction. *///www . java2s.c o m public boolean execute(JXPathContext context) throws Exception { if (!hasEntity()) throw new Exception("A persist command must reference an entity."); // Get the session from the context. Session session = HibernateLifecycle.getCurrentSession(getName(context)); // Get the entity. Object entity = context.getValue(getEntity(context)); if (entity == null) throw new Exception("Unable to find entity at: " + getEntity(context)); // Perform the persist. session.persist(entity); // The persist is executed. return false; }
From source file:org.xchain.namespaces.hibernate.SaveCommand.java
/** * Save the entity at the given QName. Note that save will perform an insert * immediately, no matter if this is inside or outside a transaction. */// w w w . ja v a2 s. c om public boolean execute(JXPathContext context) throws Exception { if (!hasEntity()) throw new Exception("A save command must reference an entity."); // Get the session from the context. Session session = HibernateLifecycle.getCurrentSession(getName(context)); // Get the entity. Object entity = context.getValue(getEntity(context)); if (entity == null) throw new Exception("Unable to find entity at: " + getEntity(context)); // Perform the save. session.save(entity); // The save is executed. return false; }
From source file:org.xchain.namespaces.hibernate.test.command.TestTransaction2.java
public boolean execute(JXPathContext context) throws Exception { boolean result = false; Transaction transaction = (Transaction) context.getValue("$test-success-1"); // test commit of transaction if (transaction != null && transaction.wasCommitted()) { // assert that the command succeeded. context.getVariables().declareVariable("test-success-2", "true"); }//from w w w . ja v a 2 s .c om // execute the chain return super.execute(context); }
From source file:org.xiforge.pentaho.di.trans.step.parsejsonstring.ParseJsonString.java
private Object[] addRowData(Object[] r) throws KettleException { // Parsing field final JSON json = JSONSerializer.toJSON(r[data.fieldPos].toString()); final JXPathContext context = JXPathContext.newContext(json); final String[] fieldNames = meta.getFieldName(); final RowMetaInterface rowMeta = data.outputRowMeta; // Parsing each path into otuput rows for (int i = 0; i < fieldNames.length; i++) { final String fieldPath = meta.getXPath()[i]; final String fieldName = meta.getFieldName()[i]; final Object fieldValue = context.getValue(fieldPath); final Integer fieldIndex = rowMeta.indexOfValue(fieldNames[i]); final ValueMetaInterface valueMeta = rowMeta.getValueMeta(fieldIndex); final DateFormat df = (valueMeta.getType() == ValueMetaInterface.TYPE_DATE) ? new SimpleDateFormat(meta.getFieldFormat()[i]) : null;//ww w. j a v a 2 s.c o m // safely add the unique field at the end of the output row r = RowDataUtil.addValueData(r, fieldIndex, getRowDataValue(fieldName, valueMeta, valueMeta, fieldValue, df)); } return r; }
From source file:org.xsystem.bpm2machineservice.impl.execution.AssociationsResolver.java
public void resolve(List<DataAssociation> associations) { JXPathContext fromdata = scriptingService.makeJXPathContext(fromCtx); JXPathContext todata = scriptingService.makeJXPathContext(toCtx); associations.stream().flatMap(association -> association.getAssignment().stream()).forEach(assignment -> { FormalExpression fromExp = (FormalExpression) assignment.getFrom(); String from = fromExp.getBody(); Object fromValue = fromdata.getValue(from); FormalExpression toExp = (FormalExpression) assignment.getTo(); String to = toExp.getBody(); todata.setValue(to, fromValue);/*w w w. j av a2s. c o m*/ }); }
From source file:org.xsystem.bpm2machineservice.impl.ExecutionService.java
boolean checkSubscription(String processId, Map<String, Object> messageData, Object testExpr) { List<Map<String, String>> expList = (List) testExpr; if (Auxilary.isEmptyOrNull(expList)) { return true; }//from w w w .java 2s. c om boolean ok = true; Map processContext = getProcessContext(processId, null); JXPathContext msgContext = scriptingService.makeJXPathContext(messageData); JXPathContext procContext = scriptingService.makeJXPathContext(processContext); for (Map<String, String> row : expList) { String fromExp = row.get("from"); String toExp = row.get("to"); Object fromValue = msgContext.getValue(fromExp); Object toValue = procContext.getValue(toExp); if (!fromValue.equals(toValue)) { return false; } } return ok; }
From source file:org.xsystem.sql2.http.impl.HttpHelper.java
public static int getThumb(FileFormat fileFormat, Map<String, Object> reqContext) { if (fileFormat == null) { return -1; }/* ww w . j a v a 2 s. c o m*/ String eval = fileFormat.getPreview(); if (eval.isEmpty()) { return 200; } JXPathContext context = JXPathContext.newContext(reqContext); context.setLenient(true); Object obj = context.getValue(eval); if (obj == null) { return 200; } Integer ret = Integer.valueOf(obj.toString().trim()); return ret; }
From source file:org.xsystem.sql2.http.impl.HttpHelper.java
public static FileTransfer getFileTransfer(FileFormat fileFormat, Object value, BiFunction<String, Object, byte[]> bi) { Map row = null;// ww w. j av a 2s . c om if (value instanceof List) { List lst = (List) value; if (!lst.isEmpty()) { Object test = lst.get(0); if (test instanceof Map) { row = (Map) test; } } } else if (value instanceof Map) { row = (Map) value; } if (row == null) { return null; } String evalContenttype = fileFormat.getContenttype(); String evalFilename = fileFormat.getFilename(); String evalContent = fileFormat.getContent(); String evalFormat = fileFormat.getFormat(); JXPathContext context = JXPathContext.newContext(row); context.setLenient(true); String contenttype = (String) context.getValue(evalContenttype); String filename = (String) context.getValue(evalFilename); //byte[] content = (byte[]) context.getValue(evalContent); String format = (String) context.getValue(evalFormat); Object data = context.getValue(evalContent); byte[] content = bi.apply(fileFormat.getStorage(), data); if (content == null) { return null; } FileTransfer ret = new FileTransfer(); ret.setContentType(contenttype); ret.setData(content); ret.setFileName(filename); ret.setFileType(format); return ret; }