本文整理汇总了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);
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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());
}
}
示例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);
}
示例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;
}
示例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;
}
示例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()); }
*/
}
示例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;
}
示例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();
}
}
示例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();
}
示例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)));
}