本文整理汇总了Java中org.jdom2.xpath.XPathFactory.instance方法的典型用法代码示例。如果您正苦于以下问题:Java XPathFactory.instance方法的具体用法?Java XPathFactory.instance怎么用?Java XPathFactory.instance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jdom2.xpath.XPathFactory
的用法示例。
在下文中一共展示了XPathFactory.instance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: load
import org.jdom2.xpath.XPathFactory; //导入方法依赖的package包/类
@Override
public TestCaseData load() {
TestCaseData tcData = new TestCaseData();
XPathFactory xFactory = XPathFactory.instance();
Element testCase = xFactory.compile("//testcase[@name='" + name + "']", Filters.element()).evaluateFirst(xmlDocument);
List<Element> scenarios = testCase.getChildren();
for (Element scenario : scenarios) {
List<Element> parameters = scenario.getChildren();
ScenarioData testScenario = new ScenarioData(scenario.getName(), testCase.getName());
for (Element parameter : parameters) {
testScenario.putScenarioData(parameter.getName(), parameter.getValue());
}
tcData.addScenarioData(testScenario);
}
return tcData;
}
示例2: testToXML
import org.jdom2.xpath.XPathFactory; //导入方法依赖的package包/类
@Test
public void testToXML() throws Exception {
Document document = MCRSimpleModelXMLConverter.toXML(metsSimpleModel);
XPathFactory xPathFactory = XPathFactory.instance();
String documentAsString = new XMLOutputter(Format.getPrettyFormat()).outputString(document);
Arrays.asList(PATHS_TO_CHECK.split(";")).stream()
.map((String xpath) -> xPathFactory.compile(xpath, Filters.fboolean(), Collections.emptyMap(),
Namespace.getNamespace("mets", "http://www.loc.gov/METS/")))
.forEachOrdered(xPath -> {
Boolean evaluate = xPath.evaluateFirst(document);
Assert.assertTrue(
String.format("The xpath : %s is not true! %s %s", xPath, System.lineSeparator(), documentAsString),
evaluate);
});
}
示例3: getIdentifier
import org.jdom2.xpath.XPathFactory; //导入方法依赖的package包/类
@Override
public Optional<MCRPersistentIdentifier> getIdentifier(MCRBase obj, String additional)
throws MCRPersistentIdentifierException {
String xpath = getProperties().get("Xpath");
Document xml = obj.createXML();
XPathFactory xpfac = XPathFactory.instance();
XPathExpression<Text> xp = xpfac.compile(xpath, Filters.text());
List<Text> evaluate = xp.evaluate(xml);
if (evaluate.size() > 1) {
throw new MCRPersistentIdentifierException(
"Got " + evaluate.size() + " matches for " + obj.getId() + " with xpath " + xpath + "");
}
if (evaluate.size() == 0) {
return Optional.empty();
}
Text identifierText = evaluate.listIterator().next();
String identifierString = identifierText.getTextNormalize();
Optional<MCRDNBURN> parsedIdentifierOptional = PARSER.parse(identifierString);
return parsedIdentifierOptional.map(MCRPersistentIdentifier.class::cast);
}
示例4: HolidayEndpoint
import org.jdom2.xpath.XPathFactory; //导入方法依赖的package包/类
@Autowired
public HolidayEndpoint(HumanResourceService humanResourceService)
throws JDOMException, XPathFactoryConfigurationException,
XPathExpressionException {
this.humanResourceService = humanResourceService;
Namespace namespace = Namespace.getNamespace("hr", NAMESPACE_URI);
XPathFactory xPathFactory = XPathFactory.instance();
this.startDateExpression = xPathFactory.compile("//hr:StartDate",
Filters.element(), null, namespace);
this.endDateExpression = xPathFactory.compile("//hr:EndDate", Filters.element(),
null, namespace);
this.nameExpression = xPathFactory.compile(
"concat(//hr:FirstName,' ',//hr:LastName)", Filters.fstring(), null,
namespace);
}
示例5: getName
import org.jdom2.xpath.XPathFactory; //导入方法依赖的package包/类
private static String getName(Document doc) {
XPathFactory xFactory = XPathFactory.instance();
XPathExpression<Attribute> exprAttribute = xFactory.compile(
"/osm/relation" + "[member]" + "[tag/@k='name' and tag/@v]"
+ "[tag/@k='type' and tag/@v='site']"
+ "[tag/@k='site' and tag/@v='parking']"
+ "/tag[@k='name']/@v", Filters.attribute());
Attribute nameAttribute = exprAttribute.evaluateFirst(doc);
if (nameAttribute == null) {
exprAttribute = xFactory
.compile(
"/osm/way[tag/@k='amenity' and tag/@v='parking']/tag[@k='name']/@v",
Filters.attribute());
nameAttribute = exprAttribute.evaluateFirst(doc);
}
String name = nameAttribute.getValue();
return name;
}
示例6: getNodes
import org.jdom2.xpath.XPathFactory; //导入方法依赖的package包/类
private static Map<Integer, GeoNode> getNodes(Document doc) {
Map<Integer, GeoNode> nList = new HashMap<Integer, GeoNode>();
XPathFactory xFactory = XPathFactory.instance();
XPathExpression<Element> exprElement = xFactory.compile(
"/osm/node[@id and @lat and @lon]", Filters.element());
List<Element> nodesEle = exprElement.evaluate(doc);
for (Element nele : nodesEle) {
GeoNode n = null;
try {
int id = nele.getAttribute("id").getIntValue();
double lat = nele.getAttribute("lat").getDoubleValue();
double lon = nele.getAttribute("lon").getDoubleValue();
n = new GeoNode(id, lat, lon, 0);
} catch (DataConversionException e) {
e.printStackTrace();
}
nList.put(n.id, n);
}
return nList;
}
示例7: getNodes
import org.jdom2.xpath.XPathFactory; //导入方法依赖的package包/类
public static Map<Integer, GeoNode> getNodes(Document doc) {
Map<Integer, GeoNode> nList = new HashMap<Integer, GeoNode>();
XPathFactory xFactory = XPathFactory.instance();
XPathExpression<Element> exprElement = xFactory.compile(
"/osm/node[@id and @lat and @lon]", Filters.element());
List<Element> nodesEle = exprElement.evaluate(doc);
for (Element nele : nodesEle) {
GeoNode n = null;
try {
int id = nele.getAttribute("id").getIntValue();
double lat = nele.getAttribute("lat").getDoubleValue();
double lon = nele.getAttribute("lon").getDoubleValue();
n = new GeoNode(id, lat, lon, 0);
} catch (DataConversionException e) {
e.printStackTrace();
}
nList.put(n.id, n);
}
return nList;
}
示例8: Reader
import org.jdom2.xpath.XPathFactory; //导入方法依赖的package包/类
public Reader(File file, String name) {
SAXBuilder builder = new SAXBuilder();
try {
doc = (Document) builder.build(file);
Element root = doc.getRootElement();
// use the default implementation
XPathFactory xFactory = XPathFactory.instance();
// System.out.println(xFactory.getClass());
// select all data for motion sensor
XPathExpression<Element> expr = xFactory.compile(
"/SensorData/data[@" + Data.NAMETAG + "='" + name + "']",
Filters.element());
it = expr.evaluate(doc).iterator();
} catch (IOException io) {
System.out.println(io.getMessage());
} catch (JDOMException jdomex) {
System.out.println(jdomex.getMessage());
}
}
示例9: SumoSafeReader
import org.jdom2.xpath.XPathFactory; //导入方法依赖的package包/类
public SumoSafeReader(String safePath) throws JDOMException, IOException,
JAXBException {
SAXBuilder builder = new SAXBuilder();
safe = builder.build(new File(safePath));
xFactory = XPathFactory.instance();
this.safePath = safePath;
}
示例10: removeIdentifier
import org.jdom2.xpath.XPathFactory; //导入方法依赖的package包/类
@Override
public void removeIdentifier(MCRDNBURN identifier, MCRBase obj, String additional) {
String xpath = getProperties().get("Xpath");
Document xml = obj.createXML();
XPathFactory xPathFactory = XPathFactory.instance();
XPathExpression<Element> xp = xPathFactory.compile(xpath, Filters.element());
List<Element> elements = xp.evaluate(xml);
elements.stream()
.filter(element -> element.getTextTrim().equals(identifier.asString()))
.forEach(Element::detach);
}
示例11: HolidayEndpoint
import org.jdom2.xpath.XPathFactory; //导入方法依赖的package包/类
public HolidayEndpoint(HumanResourceService humanResourceService)
throws JDOMException, XPathFactoryConfigurationException,
XPathExpressionException {
this.humanResourceService = humanResourceService;
Namespace namespace = Namespace.getNamespace("hr", NAMESPACE_URI);
XPathFactory xPathFactory = XPathFactory.instance();
this.startDateExpression = xPathFactory.compile("//hr:StartDate",
Filters.element(), null, namespace);
this.endDateExpression = xPathFactory.compile("//hr:EndDate", Filters.element(),
null, namespace);
this.nameExpression = xPathFactory.compile(
"concat(//hr:FirstName,' ',//hr:LastName)", Filters.fstring(), null,
namespace);
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:15,代码来源:HolidayEndpoint.java
示例12: getWays
import org.jdom2.xpath.XPathFactory; //导入方法依赖的package包/类
private static Map<Integer, Way> getWays(Document doc,
Map<Integer, GeoNode> nodes) {
Map<Integer, Way> ways = new HashMap<Integer, Way>();
XPathFactory xFactory = XPathFactory.instance();
XPathExpression<Element> expway = xFactory.compile(
"/osm/way[tag/@k='highway' and tag/@v='service']",
Filters.element());
XPathExpression<Element> exponeway = xFactory.compile(
"tag[@k='oneway' and tag/@v='yes']", Filters.element());
XPathExpression<Attribute> expnd = xFactory.compile("nd/@ref",
Filters.attribute());
List<Element> waysEle = expway.evaluate(doc);
for (Element wayEle : waysEle) {
try {
Element oneway = exponeway.evaluateFirst(wayEle);
int wayId = wayEle.getAttribute("id").getIntValue();
List<Attribute> ndAttrs = expnd.evaluate(wayEle);
List<GeoNode> _ns = new LinkedList<GeoNode>();
for (Attribute ndAttr : ndAttrs) {
GeoNode _n = nodes.get(ndAttr.getIntValue());
_ns.add(_n);
}
Way way = new Way(wayId, _ns, oneway != null);
ways.put(wayId, way);
} catch (DataConversionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return ways;
}
示例13: getWays
import org.jdom2.xpath.XPathFactory; //导入方法依赖的package包/类
public static Map<Integer, Way> getWays(Document doc,
Map<Integer, GeoNode> nodes) {
Map<Integer, Way> ways = new HashMap<Integer, Way>();
XPathFactory xFactory = XPathFactory.instance();
XPathExpression<Element> expway = xFactory.compile(
"/osm/way[tag/@k='highway' and tag/@v='service']",
Filters.element());
XPathExpression<Element> exponeway = xFactory.compile(
"tag[@k='oneway' and tag/@v='yes']", Filters.element());
XPathExpression<Attribute> expnd = xFactory.compile("nd/@ref",
Filters.attribute());
List<Element> waysEle = expway.evaluate(doc);
for (Element wayEle : waysEle) {
try {
Element oneway = exponeway.evaluateFirst(wayEle);
int wayId = wayEle.getAttribute("id").getIntValue();
List<Attribute> ndAttrs = expnd.evaluate(wayEle);
List<GeoNode> _ns = new LinkedList<GeoNode>();
for (Attribute ndAttr : ndAttrs) {
GeoNode _n = nodes.get(ndAttr.getIntValue());
_ns.add(_n);
}
Way way = new Way(wayId, _ns, oneway != null);
ways.put(wayId, way);
} catch (DataConversionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return ways;
}
示例14: executeXPath
import org.jdom2.xpath.XPathFactory; //导入方法依赖的package包/类
/**
* Execute an XPath
*
* @param document
* the Document
* @param xpathStr
* the Xpath String
* @param namespaceStr
* the namespace str
* @param filter
* the filter
* @return the list<? extends content>
*/
static public List<? extends Content> executeXPath(final Object document,
final String xpathStr, final String namespaceStr,
final Filter<? extends Content> filter) {
final XPathFactory xpathFactory = XPathFactory.instance();
// XPathExpression<Object> expr = xpathFactory.compile(xpathStr);
XPathExpression<? extends Content> expr = null;
if (namespaceStr != null)
expr = xpathFactory.compile(xpathStr, filter, null,
Namespace.getNamespace("x", namespaceStr));
else
expr = xpathFactory.compile(xpathStr, filter);
List<? extends Content> xPathSearchedNodes = null;
try {
xPathSearchedNodes = expr.evaluate(document);
}
// TODO: Add better handling for these kinds of exceptions
catch (final Exception e) {
throw new CsfRuntimeException("Error in querying the message", e);
}
return xPathSearchedNodes;
/*
* for (int i = 0; i < xPathSearchedNodes.size(); i++) { Content content =
* xPathSearchedNodes.get(i); System.out.println("content: " + i + ": " +
* content.getValue()); }
*/
}
示例15: createXpathExpression
import org.jdom2.xpath.XPathFactory; //导入方法依赖的package包/类
private XPathExpression createXpathExpression() {
XPathFactory xpfac = XPathFactory.instance();
XPathExpression xp = null;
if (namespaces.isEmpty()) {
xp = xpfac.compile(xpath, Filters.fpassthrough());
} else {
xp = xpfac.compile(xpath, Filters.fpassthrough(), new LinkedHashMap<String, Object>(), namespaces.toArray(new Namespace[namespaces.size()]));
}
return xp;
}