本文整理汇总了Java中org.apache.commons.jxpath.JXPathContext.getValue方法的典型用法代码示例。如果您正苦于以下问题:Java JXPathContext.getValue方法的具体用法?Java JXPathContext.getValue怎么用?Java JXPathContext.getValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.jxpath.JXPathContext
的用法示例。
在下文中一共展示了JXPathContext.getValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getAttribute
import org.apache.commons.jxpath.JXPathContext; //导入方法依赖的package包/类
public static Object getAttribute(Object object, String key) {
try {
Object event = object;
if (object instanceof String) {
ObjectMapper mapper = new ObjectMapper();
event = mapper.readValue(object.toString(), HashMap.class);
}
if (event != null) {
JXPathContext context = JXPathContext.newContext(event);
context.setLenient(true);
return context.getValue(key);
}
}
catch (Exception e) { // NOPMD
return null;
}
return null;
}
示例2: testGetPIXAddReqObject_by_ValidDomainXMLFile
import org.apache.commons.jxpath.JXPathContext; //导入方法依赖的package包/类
@Test
public void testGetPIXAddReqObject_by_ValidDomainXMLFile()
throws JAXBException, IOException {
// Arrange
// PRPAIN201301UV02 pRPAIN201301UV02Mock = mock(PRPAIN201301UV02.class);
String expectedItVersion = "XML_1.0";
String expectedFirstName = "WILMA";
// Act
PRPAIN201301UV02 pRPAIN201301UV02 = cstl.getPIXAddReqObject(
"xml/PRPA_IN201301UV02_PIXADD_VD1_Req.xml", encodeString);
String actualItversion = pRPAIN201301UV02.getITSVersion();
JXPathContext context = JXPathContext.newContext(pRPAIN201301UV02);
String actualFirstName = (String) context
.getValue("controlActProcess/subject[1]/registrationEvent/subject1/patient/patientPerson/value/name[1]/content[2]/value/content");
// Assert
assertEquals(expectedItVersion, actualItversion);
assertEquals(expectedFirstName, actualFirstName);
}
示例3: testGetPIXUpdateReqObject_by_ValidDomainXMLFile
import org.apache.commons.jxpath.JXPathContext; //导入方法依赖的package包/类
@Test
public void testGetPIXUpdateReqObject_by_ValidDomainXMLFile()
throws JAXBException, IOException {
// Arrange
// PRPAIN201301UV02 pRPAIN201301UV02Mock = mock(PRPAIN201301UV02.class);
String expectedItVersion = "XML_1.0";
String expectedFirstName = "WILMA";
// Act
PRPAIN201302UV02 pRPAIN201302UV02 = cstl.getPIXUpdateReqObject(
"xml/PRPA_IN201302UV02_PIXUpdate_Addr_Req.xml", encodeString);
String actualItversion = pRPAIN201302UV02.getITSVersion();
JXPathContext context = JXPathContext.newContext(pRPAIN201302UV02);
String actualFirstName = (String) context
.getValue("controlActProcess/subject[1]/registrationEvent/subject1/patient/patientPerson/value/name[1]/content[2]/value/content");
// Assert
assertEquals(expectedItVersion, actualItversion);
assertEquals(expectedFirstName, actualFirstName);
}
示例4: testGetPIXQueryReqObject_by_ValidDomainXMLFile
import org.apache.commons.jxpath.JXPathContext; //导入方法依赖的package包/类
@Test
public void testGetPIXQueryReqObject_by_ValidDomainXMLFile()
throws JAXBException, IOException {
// Arrange
// PRPAIN201301UV02 pRPAIN201301UV02Mock = mock(PRPAIN201301UV02.class);
String expectedItVersion = "XML_1.0";
String expectedId = "JW-824-v3";
// Act
PRPAIN201309UV02 pRPAIN201309UV02 = cstl
.getPIXQueryReqObject(
"xml/PRPA_IN201309UV02_PIXQuery_VD1INALL_Req.xml",
encodeString);
String actualItversion = pRPAIN201309UV02.getITSVersion();
JXPathContext context = JXPathContext.newContext(pRPAIN201309UV02);
String actualId = (String) context
.getValue("controlActProcess/queryByParameter/value/parameterList/patientIdentifier[1]/value[1]/extension");
// Assert
assertEquals(expectedItVersion, actualItversion);
assertEquals(expectedId, actualId);
}
示例5: addRowData
import org.apache.commons.jxpath.JXPathContext; //导入方法依赖的package包/类
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;
// 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;
}
示例6: fillCollectionSet
import org.apache.commons.jxpath.JXPathContext; //导入方法依赖的package包/类
/**
* Fill collection set.
*
* @param agent the agent
* @param collectionSet the collection set
* @param source the source
* @param json the JSON Object
* @throws ParseException the parse exception
*/
@SuppressWarnings("unchecked")
protected void fillCollectionSet(CollectionAgent agent, XmlCollectionSet collectionSet, XmlSource source, JSONObject json) throws ParseException {
JXPathContext context = JXPathContext.newContext(json);
for (XmlGroup group : source.getXmlGroups()) {
log().debug("fillCollectionSet: getting resources for XML group " + group.getName() + " using XPATH " + group.getResourceXpath());
Date timestamp = getTimeStamp(context, group);
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 " + resourceName);
XmlCollectionResource collectionResource = getCollectionResource(agent, resourceName, group.getResourceType(), timestamp);
AttributeGroupType attribGroupType = new AttributeGroupType(group.getName(), group.getIfType());
for (XmlObject object : group.getXmlObjects()) {
String value = (String) relativeContext.getValue(object.getXpath());
XmlCollectionAttributeType attribType = new XmlCollectionAttributeType(object, attribGroupType);
collectionResource.setAttributeValue(attribType, value);
}
processXmlResource(collectionResource, attribGroupType);
collectionSet.getCollectionResources().add(collectionResource);
}
}
}
示例7: getTimeStamp
import org.apache.commons.jxpath.JXPathContext; //导入方法依赖的package包/类
/**
* Gets the time stamp.
*
* @param context the JXPath context
* @param group the group
* @return the time stamp
*/
protected Date getTimeStamp(JXPathContext context, XmlGroup group) {
if (group.getTimestampXpath() == null) {
return null;
}
String pattern = group.getTimestampFormat() == null ? "yyyy-MM-dd HH:mm:ss" : group.getTimestampFormat();
log().debug("getTimeStamp: retrieving custom timestamp to be used when updating RRDs using XPATH " + group.getTimestampXpath() + " and pattern " + pattern);
Date date = null;
String value = (String)context.getValue(group.getTimestampXpath());
try {
DateTimeFormatter dtf = DateTimeFormat.forPattern(pattern);
DateTime dateTime = dtf.parseDateTime(value);
date = dateTime.toDate();
} catch (Exception e) {
log().warn("getTimeStamp: can't convert custom timetime " + value + " using pattern " + pattern);
}
return date;
}
示例8: testXpath
import org.apache.commons.jxpath.JXPathContext; //导入方法依赖的package包/类
/**
* 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));
}
}
示例9: main2
import org.apache.commons.jxpath.JXPathContext; //导入方法依赖的package包/类
public static void main2(String[] args) {
Phone p1 = new Phone(1);
Phone p2 = new Phone(2);
List<Phone> phones = new ArrayList<>();
phones.add(p1);
phones.add(p2);
JXPathContext ctx = JXPathContext.newContext(phones);
System.out.println(phones);
long phone1 = (long) ctx.getValue("/*[type='br.eti.kinoshita.commons.jxpath.Phone']");
System.out.println(phone1);
}
示例10: transfer
import org.apache.commons.jxpath.JXPathContext; //导入方法依赖的package包/类
@Override
public void transfer(OutputStream out) {
this.context.put("create", true);
JXPathContext xPathContext = getXPathContext();
xPathContext.setLenient(true);
Object o = xPathContext.getValue(getPath());
if (o != null) {
throw new IllegalArgumentException("Path '" + getPath() + "' exists.");
}
setupTX();
Pointer p = xPathContext.createPath(getPath());
JXPathContext relContext = getRelativeContext(p);
for (String outputAttribute : getInputAttributeNameAsArray()) {
/*
Iterator<Pointer> outputAttrPointersIter = context.iteratePointers(outputAttribute);
while(outputAttrPointersIter.hasNext()) {
Pointer vPointer = outputAttrPointersIter.next();
Object values = getValues(outputAttribute);
//NodePointer nP = (NodePointer)vPointer;
//nP.getImmediateValuePointer().setValue(values);
vPointer.setValue(values);
}
*/
Object values = getValues(outputAttribute);
relContext.setValue(outputAttribute, values);
}
processTX();
}
示例11: testGetPIXAddReqObject_Throws_IOException
import org.apache.commons.jxpath.JXPathContext; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void testGetPIXAddReqObject_Throws_IOException()
throws JAXBException, IOException {
// Arrange
// PRPAIN201301UV02 pRPAIN201301UV02Mock = mock(PRPAIN201301UV02.class);
String expectedItVersion = "XML_1.0";
String expectedFirstName = "WILMA";
when(
marshaller.unmarshallFromXml(
PRPAIN201301UV02.class,
IOUtils.toString(getClass()
.getClassLoader()
.getResourceAsStream(
"xml/PRPA_IN201301UV02_PIXADD_VD1_Req.xml"))))
.thenThrow(IOException.class);
thrown.expect(IOException.class);
// Act
PRPAIN201301UV02 pRPAIN201301UV02 = cstl.getPIXAddReqObject(
"xml/PRPA_IN201301UV02_PIXADD_VD1_Req.xml", encodeString);
String actualItversion = pRPAIN201301UV02.getITSVersion();
JXPathContext context = JXPathContext.newContext(pRPAIN201301UV02);
String actualFirstName = (String) context
.getValue("controlActProcess/subject[1]/registrationEvent/subject1/patient/patientPerson/value/name[1]/content[2]/value/content");
// Assert
assertEquals(expectedItVersion, actualItversion);
assertEquals(expectedFirstName, actualFirstName);
}
示例12: testGetPIXAddReqObject_Throws_JAXBException2
import org.apache.commons.jxpath.JXPathContext; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void testGetPIXAddReqObject_Throws_JAXBException2()
throws JAXBException, IOException {
// Arrange
// PRPAIN201301UV02 pRPAIN201301UV02Mock = mock(PRPAIN201301UV02.class);
String expectedItVersion = "XML_1.0";
String expectedFirstName = "WILMA";
when(
marshaller.unmarshallFromXml(
PRPAIN201301UV02.class,
IOUtils.toString(getClass()
.getClassLoader()
.getResourceAsStream(
"xml/PRPA_IN201301UV02_PIXADD_VD1_Req.xml"))))
.thenThrow(JAXBException.class);
thrown.expect(JAXBException.class);
// Act
PRPAIN201301UV02 pRPAIN201301UV02 = cstl.getPIXAddReqObject(
"xml/PRPA_IN201301UV02_PIXADD_VD1_Req.xml", encodeString);
String actualItversion = pRPAIN201301UV02.getITSVersion();
JXPathContext context = JXPathContext.newContext(pRPAIN201301UV02);
String actualFirstName = (String) context
.getValue("controlActProcess/subject[1]/registrationEvent/subject1/patient/patientPerson/value/name[1]/content[2]/value/content");
// Assert
assertEquals(expectedItVersion, actualItversion);
assertEquals(expectedFirstName, actualFirstName);
}
示例13: getProtoValue
import org.apache.commons.jxpath.JXPathContext; //导入方法依赖的package包/类
@Override
public Object getProtoValue(final JXPathContext context, final Context vars, final Config.Entry entry) {
final Object object = context.getValue(entry.getPath());
if (null == object) {
return null;
}
return parseDate(object.toString());
}
示例14: setMetaDataXML
import org.apache.commons.jxpath.JXPathContext; //导入方法依赖的package包/类
public boolean setMetaDataXML(String MetaDataResponse) throws Exception{
JDOMParser domParser = new JDOMParser();
InputStream metadataInputStream = MetadataUtils.InputStreamFromString(MetaDataResponse);
metaDataDocument = (Document)domParser.parseXML(metadataInputStream);
boolean isXmlLoaded = false;
if (metaDataDocument != null ) {
JXPathContext docContext = JXPathContext.newContext(metaDataDocument);
String thisClassSysName = null;
try {
isXmlLoaded = true;
thisClassSysName = (String)docContext.getValue(msf_xPathQueryStandardResourceNames);
if (log.isDebugEnabled()) {
log.debug("SUCCESS - FOUND a class with System Name: " + thisClassSysName);
}
} catch (JXPathException je) {
log.error("JXPath ERROR: " + je.getMessage());
log.error(je);
throw je;
} catch (Exception e) {
log.error("JXPath ERROR: " + e.getMessage());
log.error(e);
throw e;
}
}
return isXmlLoaded;
}
示例15: queryStrings
import org.apache.commons.jxpath.JXPathContext; //导入方法依赖的package包/类
public static Collection<String> queryStrings(Queriable context,String jxpath) {
JXPathContext ctx = JXPathContext.newContext(context);
Object o;
try {
o = ctx.getValue(jxpath);
} catch(JXPathException e){
log.debug(e.getMessage(), e);
o = null;
}
if(o instanceof StringValue) {
return Collections.singleton(((StringValue)o).getValue());
} else if (o instanceof String) {
return Collections.singleton((String)o);
} else if (o instanceof Collection<?>) {
List<String> v = new ArrayList<String>();
for(Object o1 : ((Collection<?>) o)) {
if(o1 instanceof StringValue) {
v.add(((StringValue) o1).getValue());
} else if (o1 instanceof String) {
v.add((String)o1);
}
}
return v;
} else {
return new ArrayList<String>();
}
}