当前位置: 首页>>代码示例>>Java>>正文


Java XPathFactory.instance方法代码示例

本文整理汇总了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;
}
 
开发者ID:AgileTestingFramework,项目名称:atf-toolbox-java,代码行数:24,代码来源:XMLDataDriver.java

示例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);
        });
}
 
开发者ID:MyCoRe-Org,项目名称:mycore,代码行数:18,代码来源:MCRSimpleModelXMLConverterTest.java

示例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);
}
 
开发者ID:MyCoRe-Org,项目名称:mycore,代码行数:24,代码来源:MCRURNObjectXPathMetadataManager.java

示例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);
}
 
开发者ID:Nephilim84,项目名称:contestparser,代码行数:19,代码来源:HolidayEndpoint.java

示例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;

	}
 
开发者ID:ianmalcolm,项目名称:DeadReckoning,代码行数:21,代码来源:CarPark.java

示例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;
}
 
开发者ID:ianmalcolm,项目名称:DeadReckoning,代码行数:24,代码来源:CarPark.java

示例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;
}
 
开发者ID:ianmalcolm,项目名称:DeadReckoning,代码行数:24,代码来源:CarParkGraph.java

示例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());
	}
}
 
开发者ID:ianmalcolm,项目名称:DeadReckoning,代码行数:25,代码来源:Reader.java

示例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;
}
 
开发者ID:ec-europa,项目名称:sumo,代码行数:8,代码来源:SumoSafeReader.java

示例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);
}
 
开发者ID:MyCoRe-Org,项目名称:mycore,代码行数:13,代码来源:MCRURNObjectXPathMetadataManager.java

示例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;

}
 
开发者ID:ianmalcolm,项目名称:DeadReckoning,代码行数:38,代码来源:CarPark.java

示例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;

}
 
开发者ID:ianmalcolm,项目名称:DeadReckoning,代码行数:38,代码来源:CarParkGraph.java

示例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()); }
	 */
}
 
开发者ID:OpenSimulationSystems,项目名称:CABSF_Java,代码行数:42,代码来源:XMLUtilities.java

示例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;
}
 
开发者ID:fivesmallq,项目名称:web-data-extractor,代码行数:11,代码来源:XPathExtractor.java


注:本文中的org.jdom2.xpath.XPathFactory.instance方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。