本文整理汇总了Java中org.jdom2.xpath.XPathExpression.evaluateFirst方法的典型用法代码示例。如果您正苦于以下问题:Java XPathExpression.evaluateFirst方法的具体用法?Java XPathExpression.evaluateFirst怎么用?Java XPathExpression.evaluateFirst使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jdom2.xpath.XPathExpression
的用法示例。
在下文中一共展示了XPathExpression.evaluateFirst方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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());
}
示例2: 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());
}
示例3: 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());
}
示例4: transform
import org.jdom2.xpath.XPathExpression; //导入方法依赖的package包/类
protected InputStream transform(String xmlFile) throws Exception {
InputStream guiXML = getClass().getResourceAsStream(xmlFile);
if (guiXML == null) {
throw new WebApplicationException(Response.status(Status.INTERNAL_SERVER_ERROR).build());
}
SAXBuilder saxBuilder = new SAXBuilder();
Document webPage = saxBuilder.build(guiXML);
XPathExpression<Object> xpath = XPathFactory.instance().compile(
"/MyCoReWebPage/section/div[@id='mycore-acl-editor2']");
Object node = xpath.evaluateFirst(webPage);
MCRSession mcrSession = MCRSessionMgr.getCurrentSession();
String lang = mcrSession.getCurrentLanguage();
if (node != null) {
Element mainDiv = (Element) node;
mainDiv.setAttribute("lang", lang);
String bsPath = CONFIG.getString("MCR.bootstrap.path", "");
if (!bsPath.equals("")) {
bsPath = MCRFrontendUtil.getBaseURL() + bsPath;
Element item = new Element("link").setAttribute("href", bsPath).setAttribute("rel", "stylesheet")
.setAttribute("type", "text/css");
mainDiv.addContent(0, item);
}
}
MCRContent content = MCRJerseyUtil.transform(webPage, request);
return content.getInputStream();
}
示例5: getAncestorLabels
import org.jdom2.xpath.XPathExpression; //导入方法依赖的package包/类
/**
* Returns all labels of the ancestor axis for the given item within
* navigation.xml
*
* @param item a navigation item
* @return Label as String, like "labelRoot > labelChild >
* labelChildOfChild"
*/
public static String getAncestorLabels(Element item) {
StringBuilder label = new StringBuilder();
String lang = MCRSessionMgr.getCurrentSession().getCurrentLanguage().trim();
XPathExpression<Element> xpath;
Element ic = null;
xpath = XPATH_FACTORY.compile("//.[@href='" + getWebpageID(item) + "']", Filters.element());
ic = xpath.evaluateFirst(getNavi());
while (ic.getName().equals("item")) {
ic = ic.getParentElement();
String webpageID = getWebpageID(ic);
Element labelEl = null;
xpath = XPATH_FACTORY.compile("//.[@href='" + webpageID + "']/label[@xml:lang='" + lang + "']",
Filters.element());
labelEl = xpath.evaluateFirst(getNavi());
if (labelEl != null) {
if (label.length() == 0) {
label = new StringBuilder(labelEl.getTextTrim());
} else {
label.insert(0, labelEl.getTextTrim() + " > ");
}
}
}
return label.toString();
}
示例6: getName
import org.jdom2.xpath.XPathExpression; //导入方法依赖的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;
}
示例7: addDataFromScopusProfile
import org.jdom2.xpath.XPathExpression; //导入方法依赖的package包/类
private static void addDataFromScopusProfile(Element profile, String type, Institution institution) {
XPathExpression<Element> xPathInstitution;
XPathExpression<Element> xPathDepartment;
XPathExpression<Element> xPathAdress;
if (type.equals("short")) {
xPathInstitution = XPathFactory.instance().compile(pathToInstitutionInAuthorProfile, Filters.element());
xPathDepartment = XPathFactory.instance().compile(pathToDepartmentInAuthorProfile, Filters.element());
xPathAdress = XPathFactory.instance().compile(pathToAddressInAuthorProfile, Filters.element());
} else {
xPathInstitution = XPathFactory.instance().compile(pathToInstitutionInAffilResponse, Filters.element());
xPathDepartment = XPathFactory.instance().compile(pathToDepartmentnAffilResponse, Filters.element());
xPathAdress = XPathFactory.instance().compile(pathToAddressnAffilResponse, Filters.element());
}
Element institutionElement = xPathInstitution.evaluateFirst(profile);
Element departmentElement = xPathDepartment.evaluateFirst(profile);
if (institutionElement != null) {
institution.setDepartment(departmentElement.getText());
institution.setInstitution(institutionElement.getText());
} else if (departmentElement != null) {
institution.setInstitution(departmentElement.getText());
}
Element addressElement = xPathAdress.evaluateFirst(profile);
institution.setCity(addressElement.getChildText("city"));
institution.setCountry(addressElement.getChildText("country"));
if (profile.getChild("geoCoordinates") != null) {
XPathExpression<Element> xPathLatitude = XPathFactory.instance().compile(pathToLatitude, Filters.element());
XPathExpression<Element> xPathLongitude = XPathFactory.instance().compile(pathToLongitude, Filters.element());
String textLatitude = xPathLatitude.evaluateFirst(profile).getText();
String textLongitude = xPathLongitude.evaluateFirst(profile).getText();
institution.setLatitude(Double.parseDouble(textLatitude));
institution.setLongitude(Double.parseDouble(textLongitude));
}
}
示例8: CitationStatistics
import org.jdom2.xpath.XPathExpression; //导入方法依赖的package包/类
public CitationStatistics(Set<Element> mcrEntries, String source) throws HttpException, IOException, JDOMException, SAXException {
this.source = source;
totalCitations = 0;
uncited = 0;
numberOfDocumentsWithCitationData = 0;
hIndex = 0;
List<Namespace> namespaces = MCRConstants.getStandardNamespaces();
namespaces.add(DC_Namespace);
namespaces.add(ELSEVIER_Namespace);
List<Integer> citationCounts = new ArrayList<>();
for (Element mcrEntry : mcrEntries) {
LOGGER.info(mcrEntry);
XPathExpression<Element> xPath = XPathFactory.instance().compile(sourceIDScopus, Filters.element(),null, namespaces);
Element idenitiferElement = xPath.evaluateFirst(mcrEntry);
if (idenitiferElement != null) {
String scopusID = xPath.evaluateFirst(mcrEntry).getValue();
if (scopusID.contains("SCOPUS_ID:"))
scopusID = scopusID.replace("SCOPUS_ID:", "");
CitationGetter getter = new ScopusConnector();
Element citationInformation = getter.getCitationInformation(scopusID);
if (citationInformation != null) {
mcrEntry.addContent(citationInformation);
int numberOfCitations = Integer.parseInt(citationInformation.getChildText("count"));
citationCounts.add(numberOfCitations);
LOGGER.info("retrieved citation count " + numberOfCitations + " for document with scopus id " + scopusID);
if (numberOfCitations == 0)
uncited++;
totalCitations += numberOfCitations;
numberOfDocumentsWithCitationData++;
}
}
}
hIndex = calculateHIndex(citationCounts);
}
示例9: getPublicationByID
import org.jdom2.xpath.XPathExpression; //导入方法依赖的package包/类
public Element getPublicationByID(String id) throws IOException, JDOMException, SAXException {
//build API URL
String queryURL = API_URL + "objects/" + id;
String pathToMODS = "metadata/def.modsContainer/modsContainer/mods:mods";
XPathExpression<Element> xPath = XPathFactory.instance().compile(pathToMODS, Filters.element(),null,MCRConstants.getStandardNamespaces());
return xPath.evaluateFirst(getResponse(queryURL).asXML().detachRootElement().clone());
}
示例10: getGeoData
import org.jdom2.xpath.XPathExpression; //导入方法依赖的package包/类
public Element getGeoData(String location) throws JDOMException, HttpException, IOException, SAXException {
//build API URL
String queryURL = API_URL + "?address="+ urlEncode(location.replace(" ", "+")) + "&key="+ API_KEY;
LOGGER.info("Retrieving coordinates for " + location);
Element response = getResponse(queryURL).asXML().detachRootElement().clone();
XPathExpression<Element> xPathGeoData = XPathFactory.instance().compile(pathToGeoData,
Filters.element());
Element geodata = xPathGeoData.evaluateFirst(response);
return geodata;
}
示例11: getNumberOfPublications
import org.jdom2.xpath.XPathExpression; //导入方法依赖的package包/类
public int getNumberOfPublications(PublicationAuthor author)
throws JDOMException, IOException, SAXException {
if (!author.getScopusAuthorID().isEmpty()) {
String queryURL = API_URL + "/author/AUTHOR_ID:" + author.getScopusAuthorID()
+ "?start=0&count=200&view=DOCUMENTS&apikey=" + API_KEY;
XPathExpression<Element> xPath = XPathFactory.instance().compile(pathToNumber, Filters.element());
Element numberElement = xPath.evaluateFirst(getResponse(queryURL).asXML().detachRootElement().clone());
// read and return total number of publications from the Element
return Integer.parseInt(numberElement.getValue());
} else
return 0;
}
示例12: getCitationCount
import org.jdom2.xpath.XPathExpression; //导入方法依赖的package包/类
public int getCitationCount(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> xPath = XPathFactory.instance().compile(pathToCitationCount, Filters.element());
Element citationCountElement = xPath.evaluateFirst(getResponse(queryURL).asXML());
return Integer.parseInt(citationCountElement.getValue());
}
示例13: getPhysicalFile
import org.jdom2.xpath.XPathExpression; //导入方法依赖的package包/类
private static Element getPhysicalFile(Document mets, String matchId) {
XPathExpression<Element> xpath;
String physicalFileExistsXpathString = String
.format(
Locale.ROOT,
"mets:mets/mets:structMap[@TYPE='PHYSICAL']/mets:div[@TYPE='physSequence']/mets:div[mets:fptr/@FILEID='%s']",
matchId);
xpath = XPathFactory.instance().compile(physicalFileExistsXpathString, Filters.element(), null,
MCRConstants.METS_NAMESPACE, MCRConstants.XLINK_NAMESPACE);
return xpath.evaluateFirst(mets);
}
示例14: getDefaultSmLink
import org.jdom2.xpath.XPathExpression; //导入方法依赖的package包/类
/**
* Build the default smLink. The PhysicalSubDiv is simply linked to the root chapter of the mets document.
*
* @param mets the mets document
* @param div the PhysicalSubDiv which should be linked
* @return the default smLink
*/
private static SmLink getDefaultSmLink(Document mets, PhysicalSubDiv div) {
XPathExpression<Attribute> attributeXpath;
attributeXpath = XPathFactory.instance().compile("mets:mets/mets:structMap[@TYPE='LOGICAL']/mets:div/@ID",
Filters.attribute(), null, MCRConstants.METS_NAMESPACE);
Attribute idAttribute = attributeXpath.evaluateFirst(mets);
String rootID = idAttribute.getValue();
return new SmLink(rootID, div.getId());
}
示例15: getStructLink
import org.jdom2.xpath.XPathExpression; //导入方法依赖的package包/类
/**
* Gets the StructLink of a mets document
*
* @param mets the mets document
* @return the StructLink of a mets document
*/
private static Element getStructLink(Document mets) {
XPathExpression<Element> xpath;
xpath = XPathFactory.instance().compile("mets:mets/mets:structLink", Filters.element(), null,
MCRConstants.METS_NAMESPACE);
return xpath.evaluateFirst(mets);
}