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


Java XPathFactory.compile方法代码示例

本文整理汇总了Java中org.jdom2.xpath.XPathFactory.compile方法的典型用法代码示例。如果您正苦于以下问题:Java XPathFactory.compile方法的具体用法?Java XPathFactory.compile怎么用?Java XPathFactory.compile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.jdom2.xpath.XPathFactory的用法示例。


在下文中一共展示了XPathFactory.compile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: 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

示例6: 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

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

示例8: 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

示例9: 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

示例10: 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

示例11: 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

示例12: 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

示例13: timeMLToNAFNER

import org.jdom2.xpath.XPathFactory; //导入方法依赖的package包/类
private static void timeMLToNAFNER(KAFDocument kaf, String fileName, String language) {
  //reading the TimeML xml file
  SAXBuilder sax = new SAXBuilder();
  XPathFactory xFactory = XPathFactory.instance();
  try {
    Document doc = sax.build(fileName);
    Element rootElement = doc.getRootElement();
    XPathExpression<Element> timexExpr = xFactory.compile("//TIMEX3",
        Filters.element());
    List<Element> timexElems = timexExpr.evaluate(doc);
    XPathExpression<Element> eventExpr = xFactory.compile("//EVENT", Filters.element());
    
    //getting the Document Creation Time
    Element dctElement = rootElement.getChild("DCT");
    Element dctTimex = dctElement.getChild("TIMEX3");
    String dctTimexValue = dctTimex.getAttributeValue("value");
    kaf.createFileDesc().creationtime = dctTimexValue;
    //getting the TEXT
    Element textElement = rootElement.getChild("TEXT");
    List<Content> textElements = textElement.getContent();
    //we need to iterate over single content of the text element
    //to get the text and the relevant attributes from TIMEX and
    //EVENT elements
    for (Content textElem : textElements) {
      if (textElem.getCType().equals(CType.Element)) {
        System.out.println(textElem.getValue());
      }
    }
  } catch (JDOMException | IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
  }
}
 
开发者ID:ragerri,项目名称:ixa-pipe-convert,代码行数:34,代码来源:TimeMLToNAF.java

示例14: absa2015ToWFs

import org.jdom2.xpath.XPathFactory; //导入方法依赖的package包/类
public static String absa2015ToWFs(String fileName, String language) {
  KAFDocument kaf = new KAFDocument("en", "v1.naf");
  SAXBuilder sax = new SAXBuilder();
  XPathFactory xFactory = XPathFactory.instance();
  try {
    Document doc = sax.build(fileName);
    XPathExpression<Element> expr = xFactory.compile("//sentence",
        Filters.element());
    List<Element> sentences = expr.evaluate(doc);

    int counter = 1;
    for (Element sent : sentences) {
      String sentId = sent.getAttributeValue("id");
      String sentString = sent.getChildText("text");
      List<List<Token>> segmentedSentences = StringUtils
          .tokenizeSentence(sentString, language);
      for (List<Token> sentence : segmentedSentences) {
        for (Token token : sentence) {
          WF wf = kaf.newWF(token.startOffset(), token.getTokenValue(),
              counter);
          wf.setXpath(sentId);
        }
      }
      counter++;
    }
  } catch (JDOMException | IOException e) {
    e.printStackTrace();
  }
  return kaf.toString();
}
 
开发者ID:ragerri,项目名称:ixa-pipe-convert,代码行数:31,代码来源:AbsaSemEval.java

示例15: form

import org.jdom2.xpath.XPathFactory; //导入方法依赖的package包/类
@GetMapping(path = {"/forms/{formId:\\w+}/{formVersion:\\d+}/manifest",
        "/formList/{formId:\\w+}/{formVersion:\\d+}/manifest"}, produces = "text/xml")
public ResponseEntity<InputStreamResource> form(@PathVariable String formId, @PathVariable String formVersion,
                                                HttpServletRequest req, HttpServletResponse rsp)
        throws IOException, JDOMException {

    String manifestPath = String.format("%s/%s/%s/%s", formsDir, formId, formVersion, MEDIA_MANIFEST);

    SAXBuilder builder = new SAXBuilder();
    org.springframework.core.io.Resource manifestResource = new FileSystemResource(manifestPath);
    Document manifestDoc = builder.build(manifestResource.getInputStream());

    String formBaseUrl = buildFullRequestUrl(req).replaceFirst("manifest$", "");

    // need to define a prefix for namespace for xpath to work
    Namespace nsWithPrefix = Namespace.getNamespace("mf", "http://openrosa.org/xforms/xformsManifest");
    Namespace nsNoPrefix = Namespace.getNamespace("http://openrosa.org/xforms/xformsManifest");

    // replace
    XPathFactory xpathFactory = XPathFactory.instance();
    XPathExpression<Element> xpathExpression = xpathFactory.compile("//mf:" + MEDIA_FILE, Filters.element(), null, nsWithPrefix);
    List<Element> files = xpathExpression.evaluate(manifestDoc);
    for (Element file : files) {
        Element filenameElem = file.getChild(FILENAME, nsNoPrefix), downloadUrlElem = new Element(DOWNLOAD_URL, nsNoPrefix);
        downloadUrlElem.setText(formBaseUrl + filenameElem.getText());
        file.addContent(downloadUrlElem);
    }

    byte[] body = getOutputter().outputString(manifestDoc).getBytes();

    addOpenRosaHeaders(rsp);
    return ResponseEntity
            .ok()
            .contentType(MediaType.TEXT_XML)
            .contentLength(body.length)
            .body(new InputStreamResource(new ByteArrayInputStream(body)));
}
 
开发者ID:cims-bioko,项目名称:cims-server,代码行数:38,代码来源:ODKFormsResource.java


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