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


Java XPathExpression.evaluate方法代码示例

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


在下文中一共展示了XPathExpression.evaluate方法的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]);
	}

}
 
开发者ID:ec-europa,项目名称:sumo,代码行数:28,代码来源:SumoSafeReader.java

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

}
 
开发者ID:ec-europa,项目名称:sumo,代码行数:34,代码来源:SumoSafeReader.java

示例3: 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]);
	}

}
 
开发者ID:ec-europa,项目名称:sumo,代码行数:22,代码来源:SumoXPathSafeReader.java

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

}
 
开发者ID:ec-europa,项目名称:sumo,代码行数:25,代码来源:SumoXPathSafeReader.java

示例5: 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;
}
 
开发者ID:ETspielberg,项目名称:bibliometrics,代码行数:18,代码来源:ScopusConnector.java

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

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

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

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

        }
    }
}
 
开发者ID:MyCoRe-Org,项目名称:mycore,代码行数:23,代码来源:MCRRestAPIObjectsHelper.java

示例10: getNodes

import org.jdom2.xpath.XPathExpression; //导入方法依赖的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

示例11: getNodes

import org.jdom2.xpath.XPathExpression; //导入方法依赖的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

示例12: listDatapoints

import org.jdom2.xpath.XPathExpression; //导入方法依赖的package包/类
/**
 * List all datapoints of a functionality
 * 
 * @param p_functionality
 *            The name of the group to perform the action on. For example in
 *            the url kitchen_light.ground.home.com the functionality would
 *            be kitchen_light
 * @param p_location
 *            The middle dns name of the url without the top level domain.
 *            For example in the url kitchen_light.ground.home.com the
 *            location would be ground.home
 * @return An ArrayList of datapoints descriptions
 */
public ArrayList<DatapointDescription> listDatapoints(
		String p_functionality, String p_location) {
	ArrayList<DatapointDescription> l_dps = new ArrayList<DatapointDescription>();
	// Create the xpath expression to find the datapoint
	XPathExpression<Element> l_xpath = XPathFactory
			.instance()
			.compile(
					"/datapoints/datapoint[lower-case(@location)='"
							+ p_location.toLowerCase()
							+ "' and translate(lower-case(@name), 'àäâéèêëüûùôöò', 'aaaeeeeuuuooo')='"
							+ p_functionality.toLowerCase() + "']",
					Filters.element());
	List<Element> l_elements = l_xpath.evaluate(m_Document);
	for (int i = 0; i < l_elements.size(); i++) {
		l_dps.add(new DatapointDescription(l_elements.get(i)
				.getAttributeValue("actionName"), l_elements.get(i)
				.getAttributeValue("dptID"), l_elements.get(i)
				.getAttributeValue("actionDesc"), l_elements.get(i)
				.getAttributeValue("dptDesc"), Integer.parseInt(l_elements
				.get(i).getAttributeValue("dptBitsSize"))));
	}

	return l_dps;
}
 
开发者ID:heia-fr,项目名称:wot_gateways,代码行数:38,代码来源:DatapointLocator.java

示例13: extractList

import org.jdom2.xpath.XPathExpression; //导入方法依赖的package包/类
@Override
public List<String> extractList(String data) {
    List<String> stringList = new LinkedList<>();
    try {
        Document doc = createDom(data);
        XPathExpression xp = createXpathExpression();
        List<Object> texts = xp.evaluate(doc);
        for (Object text : texts) {
            String result = wrap(text);
            stringList.add(result);
        }
    } catch (Exception e) {
        throw new ExtractException(e);
    }
    return stringList;
}
 
开发者ID:fivesmallq,项目名称:web-data-extractor,代码行数:17,代码来源:XPathExtractor.java

示例14: doFilter

import org.jdom2.xpath.XPathExpression; //导入方法依赖的package包/类
private LinkedList<String> doFilter(String in, Set<String> xpaths) throws IOException {
    LinkedList<String> result = new LinkedList<String>();
    try {
        Document doc = new SAXBuilder(XMLReaders.NONVALIDATING).build(new StringReader(in));
        XMLOutputter out = new XMLOutputter();

        for (String xp : xpaths) {
            XPathExpression<Content> xpath = XPathFactory.instance().compile(xp, Filters.content());
            for (Content node : xpath.evaluate(doc)) {
                if(node instanceof Element) {
                    result.add(out.outputString((Element) node));
                } else if(node instanceof Text) {
                    result.add(out.outputString((Text) node));
                }
            }
        }
        return result;
    } catch (JDOMException xpe) {
        throw new IllegalArgumentException("error while processing xpath expressions: '" + xpaths + "'", xpe);
    }
}
 
开发者ID:apache,项目名称:marmotta,代码行数:22,代码来源:XPathFunction.java

示例15: setOnNode

import org.jdom2.xpath.XPathExpression; //导入方法依赖的package包/类
/**
 * Executes an Xpath for an element and executes the consumer
 *
 * @param element Element the xpath is executed against
 * @param expressionStr Xpath
 * @param consumer Consumer to execute if the xpath matches
 * @param filter Filter to apply for the xpath
 * @param selectOne Whether to execute for the first match or multiple matches
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
void setOnNode(Element element, String expressionStr,
				Consumer consumer, Filter<?> filter, boolean selectOne) {
	XPathExpression<?> expression = XPathFactory.instance().compile(expressionStr, filter, null,  xpathNs);

	if (selectOne) {
		Optional.ofNullable(expression.evaluateFirst(element)).ifPresent(consumer);
	} else {
		List<?> elems = expression.evaluate(element);
		Optional.ofNullable(elems)
				.ifPresent(notNullElems -> notNullElems.forEach(consumer));
	}
}
 
开发者ID:CMSgov,项目名称:qpp-conversion-tool,代码行数:23,代码来源:XmlInputDecoder.java


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