本文整理汇总了Java中org.apache.commons.jxpath.JXPathContext.iteratePointers方法的典型用法代码示例。如果您正苦于以下问题:Java JXPathContext.iteratePointers方法的具体用法?Java JXPathContext.iteratePointers怎么用?Java JXPathContext.iteratePointers使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.jxpath.JXPathContext
的用法示例。
在下文中一共展示了JXPathContext.iteratePointers方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
}
}
示例2: 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));
}
}
示例3: getValues
import org.apache.commons.jxpath.JXPathContext; //导入方法依赖的package包/类
protected Object getValues(String outputAttribute) {
// Parse if not already done
parseInputAttributes();
// Fetch the values strings, un parsed if expression.
String value = attributeMap.get(outputAttribute);
if (value == null) {
return(null);
}
Object parsedValue = null;
// Check if it's an expression
if (value.startsWith("[")) {
if (!value.endsWith("]")) {
throw new IllegalArgumentException("ERROR: Value expression must be ended with a ']' ");
}
String path = value.substring(1);
path = path.substring(0, path.length()-1);
JXPathContext context = getXPathContext();
Iterator<Pointer> pointers = (Iterator<Pointer>)context.iteratePointers(path);
while(pointers.hasNext()) {
Pointer pointer = pointers.next();
parsedValue = pointer.getValue();
// Migth warn here if there exists multiple.
}
} else {
// No need to parse this, will be a String representaion of the value.
parsedValue = value;
}
return(parsedValue);
}
示例4: getPathPointers
import org.apache.commons.jxpath.JXPathContext; //导入方法依赖的package包/类
public Iterator<Pointer> getPathPointers() {
JXPathContext context = getXPathContext();
return((Iterator<Pointer>)context.iteratePointers(getPath()));
}
示例5: getRelativePointers
import org.apache.commons.jxpath.JXPathContext; //导入方法依赖的package包/类
public Iterator<Pointer> getRelativePointers(Pointer p, String outputAttribute) {
JXPathContext relContext = getXPathContext().getRelativeContext(p);
return((Iterator<Pointer>)relContext.iteratePointers(outputAttribute));
}