本文整理汇总了Java中org.apache.commons.jxpath.JXPathContext类的典型用法代码示例。如果您正苦于以下问题:Java JXPathContext类的具体用法?Java JXPathContext怎么用?Java JXPathContext使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JXPathContext类属于org.apache.commons.jxpath包,在下文中一共展示了JXPathContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testToCsv
import org.apache.commons.jxpath.JXPathContext; //导入依赖的package包/类
@Test
public void testToCsv() {
final SimplePatientCsvFormat fmt = new SimplePatientCsvFormat();
Patient patient = newPatient();
JXPathContext patientCtx = JXPathContext.newContext(patient);
Pointer ptr = patientCtx.getPointer("identifier[system='SSN']");
assertNotNull(ptr);
Identifier id = (Identifier) ptr.getValue();
if (id != null) {
assertNotNull("ssn", id.getValue());
}
Object obj1 = ptr.getNode();
ptr = patientCtx.getPointer("name[use='official']");
assertNotNull(ptr);
Object obj2 = ptr.getValue();
ptr = patientCtx.getPointer("name[not(use)]");
assertNotNull(ptr);
obj2 = ptr.getValue();
String str = fmt.toCsv(patient);
LOG.info("CSV: {}", str);
assertTrue(str.length() > 0);
// Ensure the literal, null doesn't appear
assertTrue(!str.contains("null"));
// Ensure there is no sign of array delimiters
assertTrue(!str.contains("["));
// Ensure line doesn't end with a comma
assertTrue(!str.endsWith(","));
assertTrue(str.contains("Smith"));
List<ContactPoint> matches = ContactPointUtil.find(
patient.getTelecom(), ContactPointSystem.PHONE, ContactPointUse.WORK);
assertNotNull(matches);
assertNotNull(matches.get(0));
}
示例2: handle
import org.apache.commons.jxpath.JXPathContext; //导入依赖的package包/类
@Override
public Object handle(Object[] args) throws Exception {
String xPathQuery = (String) args[0];
Boolean visibleOnly = (Boolean) args[1];
AccessibilityElement localRootElement = (AccessibilityElement) args[2];
AccessibilityHelper accessibilityHelper = AccessibilityFactory.getAccessibilityHelper();
AccessibilityNodeInfo accessibilityRootNode = accessibilityHelper.getRootInActiveWindow();
UiRoot uiRoot = AccessibilityFactory.getUiRoot(accessibilityRootNode);
JXPathContext context = JXPathContext.newContext(uiRoot);
QueryExecutor executor = new QueryExecutor(context);
return executor.executeOnLocalRoot(localRootElement, xPathQuery, visibleOnly);
}
开发者ID:MusalaSoft,项目名称:atmosphere-uiautomator-bridge,代码行数:17,代码来源:UiElementXPathSuccessorRetriever.java
示例3: getValue
import org.apache.commons.jxpath.JXPathContext; //导入依赖的package包/类
@Override
public String getValue(String key) {
try {
if (NumberUtils.isDigits(key)) {
Integer.parseInt(key);
JSONObject jsonResponse = new JSONObject(this.response);
return (String) jsonResponse.get(key);
}
} catch (Exception e) {
}
try {
if (this.jsonMap == null) {
initialize();
}
String keyTrans = key.replace("@", "");
// note that indexing is 1 based not zero based
JXPathContext context = JXPathContext.newContext(this.jsonMap);
String output = URLDecoder.decode(String.valueOf(context.getValue(keyTrans)), "UTF-8");
if (output.equalsIgnoreCase("null"))
return "";
return output;
} catch (Exception ex) {
return "";
}
}
示例4: 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;
}
示例5: getXPathContext
import org.apache.commons.jxpath.JXPathContext; //导入依赖的package包/类
public JXPathContext getXPathContext() {
if (this.xPathContext == null) {
log.debug("Create new OneCMDbContext");
ISession session = this.oneCmdbContext.getSession(getAuth());
if (session == null) {
throw new SecurityException("No Session found! Try to do auth() first!");
}
/*
IModelService mSvc = (IModelService)session.getService(IModelService.class);
this.xPathContext = JXPathContext.newContext(new OneCMDBContext(new OneCMDBContextBeanProvider(mSvc)));
*/
this.context.put("session", session);
this.xPathContext = JXPathContext.newContext(new OneCMDBContext(this.context, session));
this.xPathContext.setFactory(new OneCMDBFactory());
}
return(this.xPathContext);
}
示例6: format
import org.apache.commons.jxpath.JXPathContext; //导入依赖的package包/类
public String format(final Object obj) {
final JXPathContext context = JXPathContext.newContext(obj);
context.setFunctions(new ClassFunctions(JXPathFormatExtension.class, "format"));
for(final Map.Entry<String,String> entry : this.namespaces.entrySet()) {
context.registerNamespace(entry.getKey(), entry.getValue());
}
if(this.locale != null) {
context.setLocale(this.locale);
context.setDecimalFormatSymbols(null, new DecimalFormatSymbols(this.locale));
}
if(this.expression == null) {
this.expression = context.compilePath(this.expressionString);
}
final Object val = this.expression.getValue(context);
return val == null ? null : val.toString();
}
示例7: 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);
}
示例8: 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);
}
示例9: 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);
}
示例10: testPerformanceFromJxPathModified
import org.apache.commons.jxpath.JXPathContext; //导入依赖的package包/类
@Test
public void testPerformanceFromJxPathModified() {
WorkInstanceOlemlDocBuilder docBuilder = new WorkInstanceOlemlDocBuilder();
List<SolrInputDocument> jxSolrDocs = new ArrayList<SolrInputDocument>();
List<SolrInputDocument> custSolrDocs = new ArrayList<SolrInputDocument>();
RequestDocument rd = new RequestDocument();
rd.setCategory(DocCategory.WORK.getCode());
rd.setType(DocType.INSTANCE.getCode());
rd.getContent().setContentObject(instance);
Long timeJxPath = System.currentTimeMillis();
JXPathContext instance1 = JXPathContext.newContext(instance);
for (int i = 0; i < 1; i++) {
docBuilder.buildSolrInputDocumentsForInstanceByJXPathTest(instance1, instance, jxSolrDocs);
docBuilder.buildSolrInputDocumentsForHoldingByJXPathTest(instance1, instance, jxSolrDocs);
docBuilder.buildSolrInputDocumentsForItemsByJXPathTest(instance1, instance, jxSolrDocs);
// if (i == 0)
// System.out.println("Modified JS SOLR DOCS: \n" + jxSolrDocs);
}
timeJxPath = System.currentTimeMillis() - timeJxPath;
System.out.println("testPerformanceFromJxPathModified " + timeJxPath);
}
示例11: 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;
}
示例12: 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);
}
}
}
示例13: 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;
}
示例14: 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));
}
}
示例15: getResourceNameStrdNames
import org.apache.commons.jxpath.JXPathContext; //导入依赖的package包/类
public Hashtable getResourceNameStrdNames() {
Hashtable resourceIdsByStrdName = null;
Iterator nodesIterator = null;
List mdResourceNodes = null;
Element mdResourceNode = null;
String thisResourceId = null;
String thisStrdName = null;
JXPathContext mdDocContext = JXPathContext.newContext(metaDataDocument);
mdResourceNodes = mdDocContext.selectNodes(msf_xPathQueryResources);
resourceIdsByStrdName = new Hashtable();
nodesIterator = mdResourceNodes.iterator();
while(nodesIterator.hasNext()) {
mdResourceNode = (Element)nodesIterator.next();
thisResourceId = mdResourceNode.getChildText(MetadataField.resourceIdResource);
thisStrdName = mdResourceNode.getChildText(MetadataField.standardNameResource);
resourceIdsByStrdName.put(thisStrdName, thisResourceId);
}
return resourceIdsByStrdName;
//return mdResourceNodes;
}