本文整理汇总了Java中org.jdom2.xpath.XPathExpression类的典型用法代码示例。如果您正苦于以下问题:Java XPathExpression类的具体用法?Java XPathExpression怎么用?Java XPathExpression使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
XPathExpression类属于org.jdom2.xpath包,在下文中一共展示了XPathExpression类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: readMesasurementFilesFromSafe
import org.jdom2.xpath.XPathExpression; //导入依赖的package包/类
/**
* Return the mesaurements
*
* @return
*/
public void readMesasurementFilesFromSafe() {
XPathExpression<Element> expr = xFactory
.compile(
"/xfdu:XFDU/dataObjectSection/dataObject[@repID='s1Level1ProductSchema']/byteStream/fileLocation",
Filters.element(), null, xfdu);
List<Element> values = expr.evaluate(safe);
this.measurements=new File[values.size()];
File safefile = new File(safePath);
String measurementPath = safefile.getParent() + "/measurement";
for (int i = 0; i < values.size(); i++) {
Element e = values.get(i);
String href = e.getAttributeValue("href");
if (href.startsWith("./"))
href = href.substring(2);
measurements[i] = new File(measurementPath + "/" + href);
System.out.println(measurements[i]);
}
}
示例2: readGeneralProductInformation
import org.jdom2.xpath.XPathExpression; //导入依赖的package包/类
/**
* Read the generalProductInformation:
* productType,instrumentConfigurationID,
* missionDataTakeID,transmitterReceiverPolarisation
* ,productTimelinessCategory,sliceProductFlag
*
* @throws JAXBException
* @throws SAXException
*/
public void readGeneralProductInformation() throws JAXBException,
SAXException {
String xPathGenProdInfo = "/xfdu:XFDU/metadataSection/metadataObject/metadataWrap/xmlData/*[name()='generalProductInformation']";
String xPathStandAloneInfo = "/xfdu:XFDU/metadataSection/metadataObject/metadataWrap/xmlData/s1sarl1:standAloneProductInformation']";
XPathExpression<Element> expr = xFactory.compile(xPathGenProdInfo,
Filters.element(), null, xfdu);
List<Element> value = expr.evaluate(safe);
if (value == null || value.isEmpty()) {
expr = xFactory.compile(xPathStandAloneInfo, Filters.element(),
null, s1sarl1, xfdu);
value = expr.evaluate(safe);
}
List<Element> informationsNode = value.get(0).getChildren();
productInformation = new ProductInformation();
for (Element e : informationsNode) {
String name = e.getName();
String val = e.getValue();
productInformation.putValueInfo(name, val);
}
}
示例3: readAcquisitionPeriod
import org.jdom2.xpath.XPathExpression; //导入依赖的package包/类
/**
* Read the acquisition period
*
* @throws JAXBException
* @throws SAXException
*/
public void readAcquisitionPeriod() throws JAXBException, SAXException {
acquPeriod = new AcquisitionPeriod();
String xPathStartTime = "/xfdu:XFDU/metadataSection/metadataObject/metadataWrap/xmlData//*[name()='safe:startTime']";
String xPathStopTime = "/xfdu:XFDU/metadataSection/metadataObject/metadataWrap/xmlData//*[name()='safe:stopTime']";
XPathExpression<Element> expr = xFactory.compile(xPathStartTime,
Filters.element(), null, xfdu, safeNs);
Element e = expr.evaluateFirst(safe);
if (e != null)
acquPeriod.setStartTime(e.getValue());
expr = xFactory.compile(xPathStopTime, Filters.element(), null, xfdu,
safeNs);
e = expr.evaluateFirst(safe);
if (e != null)
acquPeriod.setStopTime(e.getValue());
}
示例4: readMesasurementFilesFromSafe
import org.jdom2.xpath.XPathExpression; //导入依赖的package包/类
public void readMesasurementFilesFromSafe() {
XPathExpression<Element> expr = xFactory
.compile(
"/xfdu:XFDU/dataObjectSection/dataObject[@repID='s1Level1ProductSchema']/byteStream/fileLocation",
Filters.element(), null, xfdu);
List<Element> values = expr.evaluate(safe);
this.measurements=new File[values.size()];
String measurementPath = safefile.getParent() + "/measurement";
for (int i = 0; i < values.size(); i++) {
Element e = values.get(i);
String href = e.getAttributeValue("href");
if (href.startsWith("./"))
href = href.substring(2);
measurements[i] = new File(measurementPath + "/" + href);
System.out.println(measurements[i]);
}
}
示例5: readGeneralProductInformation
import org.jdom2.xpath.XPathExpression; //导入依赖的package包/类
public void readGeneralProductInformation() throws JAXBException,
SAXException {
String xPathGenProdInfo = "/xfdu:XFDU/metadataSection/metadataObject/metadataWrap/xmlData/*[name()='generalProductInformation']";
String xPathStandAloneInfo = "/xfdu:XFDU/metadataSection/metadataObject/metadataWrap/xmlData/s1sarl1:standAloneProductInformation";
XPathExpression<Element> expr = xFactory.compile(xPathGenProdInfo,
Filters.element(), null, xfdu);
List<Element> value = expr.evaluate(safe);
if (value == null || value.isEmpty()) {
expr = xFactory.compile(xPathStandAloneInfo, Filters.element(),
null, s1sarl1, xfdu);
value = expr.evaluate(safe);
}
List<Element> informationsNode = value.get(0).getChildren();
productInformation = new ProductInformation();
for (Element e : informationsNode) {
String name = e.getName();
String val = e.getValue();
productInformation.putValueInfo(name, val);
}
}
示例6: readAcquisitionPeriod
import org.jdom2.xpath.XPathExpression; //导入依赖的package包/类
public void readAcquisitionPeriod() throws JAXBException, SAXException {
acquPeriod = new AcquisitionPeriod();
String xPathStartTime = "/xfdu:XFDU/metadataSection/metadataObject/metadataWrap/xmlData//*[name()='safe:startTime']";
String xPathStopTime = "/xfdu:XFDU/metadataSection/metadataObject/metadataWrap/xmlData//*[name()='safe:stopTime']";
XPathExpression<Element> expr = xFactory.compile(xPathStartTime,
Filters.element(), null, xfdu, safeNs);
Element e = expr.evaluateFirst(safe);
if (e != null)
acquPeriod.setStartTime(e.getValue());
expr = xFactory.compile(xPathStopTime, Filters.element(), null, xfdu,
safeNs);
e = expr.evaluateFirst(safe);
if (e != null)
acquPeriod.setStopTime(e.getValue());
}
示例7: getPublicationsForAuthor
import org.jdom2.xpath.XPathExpression; //导入依赖的package包/类
public Set<Element> getPublicationsForAuthor(PublicationAuthor author)
throws IOException, JDOMException, SAXException {
if (!author.getScopusAuthorID().isEmpty()) {
Set<Element> publications = new HashSet<>();
String queryURL = API_URL + "/author/AUTHOR_ID:" + author.getScopusAuthorID()
+ "?start=0&count=200&view=DOCUMENTS&apikey=" + API_KEY;
XPathExpression<Element> xPath = XPathFactory.instance().compile(pathToDocumentIdentifier,
Filters.element());
List<Element> identifierElements = xPath
.evaluate(getResponse(queryURL).asXML().detachRootElement().clone());
for (Element idElement : identifierElements) {
publications.add(getPublicationByID(idElement.getValue()));
}
return publications;
} else
return null;
}
示例8: getCitationInformation
import org.jdom2.xpath.XPathExpression; //导入依赖的package包/类
public Element getCitationInformation(String scopusID)
throws IOException, JDOMException, SAXException {
// build API URL
String queryURL = API_URL + "/abstract/citation-count?scopus_id=" + scopusID + "&apikey=" + API_KEY
+ "&httpAccept=application%2Fxml";
XPathExpression<Element> xPathCount = XPathFactory.instance().compile(pathToCitationCount, Filters.element());
XPathExpression<Element> xPathLink = XPathFactory.instance().compile(pathToCitationLink, Filters.element());
XPathExpression<Element> xPathArticleLink = XPathFactory.instance().compile(pathToArticleLink, Filters.element());
Element response = getResponse(queryURL).asXML().detachRootElement().clone();
String citationCount = xPathCount.evaluateFirst(response).getValue();
String citationLink = xPathLink.evaluateFirst(response).getAttributeValue("href");
String articleLink = xPathArticleLink.evaluateFirst(response).getAttributeValue("href");
Element citationInformation = new Element("citationInformation");
citationInformation.addContent(new Element("count").setText(citationCount));
citationInformation.addContent(new Element("citationLink").setText(citationLink));
citationInformation.addContent(new Element("articleLink").setText(articleLink));
return citationInformation;
}
示例9: bind
import org.jdom2.xpath.XPathExpression; //导入依赖的package包/类
private void bind(String xPath, boolean buildIfNotExists, String initialValue) throws JaxenException {
this.xPath = xPath;
Map<String, Object> variables = buildXPathVariables();
XPathExpression<Object> xPathExpr = XPathFactory.instance().compile(xPath, Filters.fpassthrough(), variables,
MCRConstants.getStandardNamespaces());
boundNodes.addAll(xPathExpr.evaluate(parent.getBoundNodes()));
for (Object boundNode : boundNodes)
if (!(boundNode instanceof Element || boundNode instanceof Attribute || boundNode instanceof Document))
throw new RuntimeException(
"XPath MUST only bind either element, attribute or document nodes: " + xPath);
LOGGER.debug("Bind to {} selected {} node(s)", xPath, boundNodes.size());
if (boundNodes.isEmpty() && buildIfNotExists) {
MCRNodeBuilder builder = new MCRNodeBuilder(variables);
Object built = builder.buildNode(xPath, initialValue, (Parent) (parent.getBoundNode()));
LOGGER.debug("Bind to {} generated node {}", xPath, MCRXPathBuilder.buildXPath(built));
boundNodes.add(built);
trackNodeCreated(builder.getFirstNodeBuilt());
}
}
示例10: testUpdate
import org.jdom2.xpath.XPathExpression; //导入依赖的package包/类
@Test
public void testUpdate() throws IOException, URISyntaxException, MCRPersistenceException,
MCRActiveLinkException, JDOMException, SAXException, MCRAccessException {
MCRObject seriesNew = new MCRObject(getResourceAsURL(seriesID + "-updated.xml").toURI());
MCRMetadataManager.update(seriesNew);
Document bookNew = MCRXMLMetadataManager.instance().retrieveXML(bookID);
XPathBuilder<Element> builder = new XPathBuilder<>(
"/mycoreobject/metadata/def.modsContainer/modsContainer/mods:mods/mods:relatedItem/mods:titleInfo/mods:title",
Filters.element());
builder.setNamespace(MCRConstants.MODS_NAMESPACE);
XPathExpression<Element> seriesTitlePath = builder.compileWith(XPathFactory.instance());
Element titleElement = seriesTitlePath.evaluateFirst(bookNew);
Assert.assertNotNull(
"No title element in related item: " + new XMLOutputter(Format.getPrettyFormat()).outputString(bookNew),
titleElement);
Assert.assertEquals("Title update from series was not promoted to book of series.",
"Updated series title", titleElement.getText());
}
示例11: extractModsMetadata
import org.jdom2.xpath.XPathExpression; //导入依赖的package包/类
@Override
public List<MCRIIIFMetadata> extractModsMetadata(Element xmlData) {
Map<String, String> elementLabelMap = new HashMap<>();
elementLabelMap.put("title", "mods:mods/mods:titleInfo/mods:title/text()");
elementLabelMap.put("genre", "mods:mods/mods:genre/text()");
// TODO: add some more metadata
return elementLabelMap.entrySet().stream().map(entry -> {
XPathExpression<Text> pathExpression = XPathFactory.instance().compile(entry.getValue(), Filters.text(),
null, MCRConstants.MODS_NAMESPACE);
List<Text> texts = pathExpression.evaluate(xmlData);
if (texts.size() == 0) {
return null;
}
return new MCRIIIFMetadata(entry.getKey(),
texts.stream().map(Text::getText).collect(Collectors.joining(", ")));
}).filter(Objects::nonNull)
.collect(Collectors.toList());
}
示例12: searchFileInGroup
import org.jdom2.xpath.XPathExpression; //导入依赖的package包/类
/**
* Searches a file in a group, which matches a filename.
*
* @param mets the mets file to search
* @param path the path to the alto file (e.g. "alto/alto_file.xml" when searching in DEFAULT_FILE_GROUP_USE or
* "image_file.jpg" when searchin in ALTO_FILE_GROUP_USE)
* @param searchFileGroup
* @return the id of the matching file or null if there is no matching file
*/
private static String searchFileInGroup(Document mets, String path, String searchFileGroup) {
XPathExpression<Element> xpath;// first check all files in default file group
String relatedFileExistPathString = String.format(Locale.ROOT,
"mets:mets/mets:fileSec/mets:fileGrp[@USE='%s']/mets:file/mets:FLocat", searchFileGroup);
xpath = XPathFactory.instance().compile(relatedFileExistPathString, Filters.element(), null,
MCRConstants.METS_NAMESPACE, MCRConstants.XLINK_NAMESPACE);
List<Element> fileLocList = xpath.evaluate(mets);
String matchId = null;
// iterate over all files
path = getCleanPath(path);
for (Element fileLoc : fileLocList) {
Attribute hrefAttribute = fileLoc.getAttribute("href", MCRConstants.XLINK_NAMESPACE);
String hrefAttributeValue = hrefAttribute.getValue();
String hrefPath = getCleanPath(removeExtension(hrefAttributeValue));
if (hrefPath.equals(removeExtension(path))) {
matchId = ((Element) fileLoc.getParent()).getAttributeValue("ID");
break;
}
}
return matchId;
}
示例13: getIdentifier
import org.jdom2.xpath.XPathExpression; //导入依赖的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);
}
示例14: writeXML
import org.jdom2.xpath.XPathExpression; //导入依赖的package包/类
/**
* Output xml
* @param eRoot - the root element
* @param lang - the language which should be filtered or null for no filter
* @return a string representation of the XML
* @throws IOException
*/
private static String writeXML(Element eRoot, String lang) throws IOException {
StringWriter sw = new StringWriter();
if (lang != null) {
// <label xml:lang="en" text="part" />
XPathExpression<Element> xpE = XPathFactory.instance().compile("//label[@xml:lang!='" + lang + "']",
Filters.element(), null, Namespace.XML_NAMESPACE);
for (Element e : xpE.evaluate(eRoot)) {
e.getParentElement().removeContent(e);
}
}
XMLOutputter xout = new XMLOutputter(Format.getPrettyFormat());
Document docOut = new Document(eRoot.detach());
xout.output(docOut, sw);
return sw.toString();
}
示例15: createXMLForSubdirectories
import org.jdom2.xpath.XPathExpression; //导入依赖的package包/类
private static void createXMLForSubdirectories(MCRPath mcrPath, Element currentElement, int currentDepth,
int maxDepth) {
if (currentDepth < maxDepth) {
XPathExpression<Element> xp = XPathFactory.instance().compile("./children/child[@type='directory']",
Filters.element());
for (Element e : xp.evaluate(currentElement)) {
String name = e.getChildTextNormalize("name");
try {
MCRPath pChild = (MCRPath) mcrPath.resolve(name);
Document doc = MCRPathXML.getDirectoryXML(pChild);
Element eChildren = doc.getRootElement().getChild("children");
if (eChildren != null) {
e.addContent(eChildren.detach());
createXMLForSubdirectories(pChild, e, currentDepth + 1, maxDepth);
}
} catch (IOException ex) {
//ignore
}
}
}
}