本文整理汇总了Java中org.jdom.xpath.XPath.selectNodes方法的典型用法代码示例。如果您正苦于以下问题:Java XPath.selectNodes方法的具体用法?Java XPath.selectNodes怎么用?Java XPath.selectNodes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jdom.xpath.XPath
的用法示例。
在下文中一共展示了XPath.selectNodes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: GetElementList
import org.jdom.xpath.XPath; //导入方法依赖的package包/类
/**
* Retrieves the text elements for a given xpath expression
*
* @param xPathExpression
* @return
*/
public ArrayList<String> GetElementList(String xPathExpression) {
try {
ArrayList<String> values = new ArrayList<String>();
List<?> nodeList = XPath.selectNodes(this.xmlDocument, xPathExpression);
Iterator<?> iter = nodeList.iterator();
while (iter.hasNext()) {
org.jdom.Element element = (org.jdom.Element) iter.next();
values.add(element.getText());
}
return values;
} catch (Exception ex) {
LOG.error("Error in handler: " + ex.getMessage(), ex);
return null;
}
}
示例2: preProcessResources
import org.jdom.xpath.XPath; //导入方法依赖的package包/类
private void
preProcessResources(Element the_manifest,
DefaultHandler the_handler) {
XPath path;
List<Attribute> results;
try {
path = XPath.newInstance(FILE_QUERY);
path.addNamespace(ns.getNs());
results = path.selectNodes(the_manifest);
for (Attribute result : results) {
the_handler.preProcessFile(result.getValue());
}
} catch (JDOMException | ClassCastException e) {
log.info("Error processing xpath for files", e);
}
}
示例3: convertAffiliations
import org.jdom.xpath.XPath; //导入方法依赖的package包/类
/**
* Converts XML affiliations into map of avro objects.
* Never returns null.
* @param source main XML element
*/
private static Map<String, Affiliation> convertAffiliations(Element source) {
try {
XPath xPath = XPath.newInstance("/article/front//contrib-group/aff");
@SuppressWarnings("unchecked")
List<Element> nodeList = xPath.selectNodes(source);
if (nodeList == null || nodeList.isEmpty()) {
return Collections.emptyMap();
}
Map<String, Affiliation> affiliations = new LinkedHashMap<String, Affiliation>();
for (Element node : nodeList) {
CermineAffiliation cAff = cermineAffiliationBuilder.build(node);
affiliations.put(node.getAttributeValue("id"), cermineToMetadataAffConverter.convert(cAff));
}
return affiliations;
} catch (JDOMException ex) {
return Collections.emptyMap();
}
}
示例4: getPortInfo
import org.jdom.xpath.XPath; //导入方法依赖的package包/类
@Override
protected String getPortInfo() {
String portInfo = getProperty("jetty.port");
if (!StringUtil.isEmptyOrSpaces(portInfo)) return portInfo;
try {
final String portPath = "connectors/connector/port";
List list = XPath.selectNodes(plugin.getConfigurationElement(), portPath);
for (Object e : list) {
Content content = (Content) e;
if (!StringUtil.isEmptyOrSpaces(content.getValue())) {
return content.getValue();
}
}
} catch (JDOMException ignore) {
}
return super.getPortInfo();
}
示例5: getCases
import org.jdom.xpath.XPath; //导入方法依赖的package包/类
private Task[] getCases(String q) throws Exception {
HttpClient client = login(getLoginMethod());
PostMethod method = new PostMethod(getUrl() + "/api.asp");
method.addParameter("token", token);
method.addParameter("cmd", "search");
method.addParameter("q", q);
method.addParameter("cols", "sTitle,fOpen,dtOpened,dtLastUpdated,ixCategory");
int status = client.executeMethod(method);
if (status != 200) {
throw new Exception("Error listing cases: " + method.getStatusLine());
}
Document document = new SAXBuilder(false).build(method.getResponseBodyAsStream()).getDocument();
XPath path = XPath.newInstance("/response/cases/case");
final XPath commentPath = XPath.newInstance("events/event");
@SuppressWarnings("unchecked") final List<Element> nodes = (List<Element>)path.selectNodes(document);
final List<Task> tasks = ContainerUtil.mapNotNull(nodes, new NotNullFunction<Element, Task>() {
@NotNull
@Override
public Task fun(Element element) {
return createCase(element, commentPath);
}
});
return tasks.toArray(new Task[tasks.size()]);
}
示例6: removeSubmitter
import org.jdom.xpath.XPath; //导入方法依赖的package包/类
public void removeSubmitter(Submitter submitterToRemove) {
log.warn("removeSubmitter() instructed to remove submitter from document: "+submitterToRemove.getName());
SubmitterJDOM jdomSubmitter = getSubmitterJDOM(submitterToRemove.getId());
jdomSubmitter.getElement().detach();
submitters.remove(submitterToRemove.getId());
// invalidate links to this submitter
try {
List references = XPath.selectNodes(doc, "//*[@REF=\""+submitterToRemove.getId()+"\"]");
log.debug("while removing submitter("+submitterToRemove.getId()+"), found these references:"+references);
for (Iterator iter = references.iterator(); iter.hasNext();) {
Element element = (Element) iter.next();
element.detach();
}
} catch (JDOMException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
update(this, submitterToRemove);
}
示例7: removeIndividual
import org.jdom.xpath.XPath; //导入方法依赖的package包/类
public void removeIndividual(Individual individualToRemove) {
log.warn("removeIndividual() instructed to remove individual from document: "+individualToRemove.getFullName());
IndividualJDOM jdomIndividual = getIndividualJDOM(individualToRemove.getId());
jdomIndividual.getElement().detach();
individuals.remove(individualToRemove.getId());
if (primaryIndividual.getId().equals(individualToRemove.getId())) {
chooseNewPrimaryIndividual();
}
// invalidate links to this person
// the only links that should exist are in family records
try {
List references = XPath.selectNodes(doc, "//*[@REF=\""+individualToRemove.getId()+"\"]");
log.debug("while removing individual("+individualToRemove.getId()+"), found these references:"+references);
for (Iterator iter = references.iterator(); iter.hasNext();) {
Element element = (Element) iter.next();
element.detach();
}
} catch (JDOMException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
update(this, individualToRemove);
}
示例8: removeFamily
import org.jdom.xpath.XPath; //导入方法依赖的package包/类
public void removeFamily (Family familyToRemove) {
log.warn("removeFamily() instructed to remove family from document: "+familyToRemove.toString());
FamilyJDOM jdomFamily = getFamilyJDOM(familyToRemove.getId());
jdomFamily.getElement().detach();
families.remove(familyToRemove.getId());
// invalidate links to this person
// the only links that should exist are in family records
try {
List references = XPath.selectNodes(doc, "//*[@REF=\""+familyToRemove.getId()+"\"]");
log.debug("while removing family("+familyToRemove.getId()+"), found these references:"+references);
for (Iterator iter = references.iterator(); iter.hasNext();) {
Element element = (Element) iter.next();
element.detach();
}
} catch (JDOMException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
update(this, familyToRemove);
}
示例9: findProperties
import org.jdom.xpath.XPath; //导入方法依赖的package包/类
private List<String> findProperties(File antFile) throws Exception {
SAXBuilder saxBuilder=new SAXBuilder("org.apache.xerces.parsers.SAXParser");
Document jdomDocument=saxBuilder.build(antFile);
List<String> propertyNameList = new ArrayList<String>();
List nodeList =XPath.selectNodes(jdomDocument,
"//property");
Iterator iter=nodeList.iterator();
while(iter.hasNext()) {
Element element=(Element)iter.next();
String propertyName = element.getAttributeValue("name");
if(propertyName!=null) {
System.out.println("propertyName:"+propertyName);
propertyNameList.add(propertyName);
}
}
return propertyNameList;
}
示例10: matchToOriginal
import org.jdom.xpath.XPath; //导入方法依赖的package包/类
/**
* Checks if the path matches for the original element
*
* @param element
* the original element
* @param xPath
* the path
*
* @return <code>true</code> if it matches, otherwise <code>false</code>
*/
protected boolean matchToOriginal(final Element element, final String xPath) {
try {
@SuppressWarnings("unchecked")
final List<Object> l = XPath.selectNodes(element, xPath);
for (final Object o : l) {
if (element.equals(o)) {
return true;
}
}
return false;
} catch (final JDOMException e) {
return false;
}
}
示例11: cleanUpProjectForImport
import org.jdom.xpath.XPath; //导入方法依赖的package包/类
protected void cleanUpProjectForImport(@NotNull File projectPath) {
File dotIdeaFolderPath = new File(projectPath, DIRECTORY_BASED_PROJECT_DIR);
if (dotIdeaFolderPath.isDirectory()) {
File modulesXmlFilePath = new File(dotIdeaFolderPath, "modules.xml");
if (modulesXmlFilePath.isFile()) {
SAXBuilder saxBuilder = new SAXBuilder();
try {
Document document = saxBuilder.build(modulesXmlFilePath);
XPath xpath = XPath.newInstance("//*[@fileurl]");
//noinspection unchecked
List<Element> modules = xpath.selectNodes(document);
int urlPrefixSize = "file://$PROJECT_DIR$/".length();
for (Element module : modules) {
String fileUrl = module.getAttributeValue("fileurl");
if (!StringUtil.isEmpty(fileUrl)) {
String relativePath = toSystemDependentName(fileUrl.substring(urlPrefixSize));
File imlFilePath = new File(projectPath, relativePath);
if (imlFilePath.isFile()) {
delete(imlFilePath);
}
// It is likely that each module has a "build" folder. Delete it as well.
File buildFilePath = new File(imlFilePath.getParentFile(), "build");
if (buildFilePath.isDirectory()) {
delete(buildFilePath);
}
}
}
}
catch (Throwable ignored) {
// if something goes wrong, just ignore. Most likely it won't affect project import in any way.
}
}
delete(dotIdeaFolderPath);
}
}
示例12: selectTasksList
import org.jdom.xpath.XPath; //导入方法依赖的package包/类
@NotNull
@Override
protected List<Object> selectTasksList(@NotNull String response, int max) throws Exception {
Document document = new SAXBuilder(false).build(new StringReader(response));
Element root = document.getRootElement();
XPath xPath = lazyCompile(getSelector(TASKS).getPath());
@SuppressWarnings("unchecked")
List<Object> rawTaskElements = xPath.selectNodes(root);
if (!rawTaskElements.isEmpty() && !(rawTaskElements.get(0) instanceof Element)) {
throw new Exception(String.format("Expression '%s' should match list of XML elements. Got '%s' instead.",
xPath.getXPath(), rawTaskElements.toString()));
}
return rawTaskElements.subList(0, Math.min(rawTaskElements.size(), max));
}
示例13: resultXpathSingleAttribute
import org.jdom.xpath.XPath; //导入方法依赖的package包/类
public String resultXpathSingleAttribute (String query, String element) throws JDOMException
{
XPath xpath = null;
xpath = XPath.newInstance(query);
List resultSet = xpath.selectNodes( doc );
Iterator b = resultSet.iterator();
if (b.hasNext())
{
Element oNode = (Element) b.next();
return (oNode.getAttributeValue(element));
}
return null;
}
示例14: evaluate
import org.jdom.xpath.XPath; //导入方法依赖的package包/类
private static List evaluate(XPath xpath, Document document) {
try {
return xpath.selectNodes(document);
} catch (JDOMException e) {
return emptyList();
}
}
示例15: getBugs
import org.jdom.xpath.XPath; //导入方法依赖的package包/类
@SuppressWarnings("rawtypes")
@Override
public List<Bug> getBugs() throws JDOMException, IOException {
System.out.println("Parsing Bugzilla XML file...");
List<Bug> bugs = new ArrayList<Bug>();
for (String file : filename) {
SAXBuilder builder = new SAXBuilder();
Document xml = builder.build(new File(file));
XPath bugPath = XPath.newInstance("//bug");
List bug_nodes = bugPath.selectNodes(xml);
Iterator it = bug_nodes.iterator();
while (it.hasNext()) {
Element bugElement = (Element) it.next();
String id = bugElement.getChild("bug_id").getTextTrim();
Bug bug = new Bug(id);
XPath desc = XPath.newInstance("long_desc/thetext");
List text_nodes = desc.selectNodes(bugElement);
Iterator text_it = text_nodes.iterator();
while (text_it.hasNext()) {
Element desc_element = (Element) text_it.next();
String text = desc_element.getTextTrim();
bug.addText(text);
}
bugs.add(bug);
}
}
return bugs;
}