本文整理汇总了Java中org.jdom.xpath.XPath类的典型用法代码示例。如果您正苦于以下问题:Java XPath类的具体用法?Java XPath怎么用?Java XPath使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
XPath类属于org.jdom.xpath包,在下文中一共展示了XPath类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: login
import org.jdom.xpath.XPath; //导入依赖的package包/类
private HttpClient login(PostMethod method) throws Exception {
HttpClient client = getHttpClient();
int status = client.executeMethod(method);
if (status != 200) {
throw new Exception("Error logging in: " + method.getStatusLine());
}
Document document = new SAXBuilder(false).build(method.getResponseBodyAsStream()).getDocument();
XPath path = XPath.newInstance("/response/token");
Element result = (Element)path.selectSingleNode(document);
if (result == null) {
Element error = (Element)XPath.newInstance("/response/error").selectSingleNode(document);
throw new Exception(error == null ? "Error logging in" : error.getText());
}
token = result.getTextTrim();
return client;
}
示例2: updateAlias
import org.jdom.xpath.XPath; //导入依赖的package包/类
private void updateAlias(String includeOrigin, String includeDestination, File ear) throws JDOMException, IOException, JDOMException {
TFile xmlTIBCO = new TFile(ear.getAbsolutePath() + File.separator + "TIBCO.xml");
String tempPath = ear.getParentFile().getAbsolutePath() + File.separator + "TIBCO.xml";
TFile xmlTIBCOTemp = new TFile(tempPath);
truezip.copyFile(xmlTIBCO, xmlTIBCOTemp);
File xmlTIBCOFile = new File(tempPath);
SAXBuilder sxb = new SAXBuilder();
Document document = sxb.build(xmlTIBCOFile);
XPath xpa = XPath.newInstance("//dd:NameValuePairs/dd:NameValuePair[starts-with(dd:name, 'tibco.alias') and dd:value='" + includeOrigin + "']/dd:value");
xpa.addNamespace("dd", "http://www.tibco.com/xmlns/dd");
Element singleNode = (Element) xpa.selectSingleNode(document);
if (singleNode != null) {
singleNode.setText(includeDestination);
XMLOutputter xmlOutput = new XMLOutputter();
xmlOutput.setFormat(Format.getPrettyFormat().setIndent(" "));
xmlOutput.output(document, new FileWriter(xmlTIBCOFile));
truezip.copyFile(xmlTIBCOTemp, xmlTIBCO);
}
updateAliasInPARs(includeOrigin, includeDestination, ear);
}
示例3: updateAliasInPARs
import org.jdom.xpath.XPath; //导入依赖的package包/类
private void updateAliasInPARs(String includeOrigin, String includeDestination, File ear) throws IOException, JDOMException {
TrueZipFileSet pars = new TrueZipFileSet();
pars.setDirectory(ear.getAbsolutePath());
pars.addInclude("*.par");
List<TFile> parsXML = truezip.list(pars);
for (TFile parXML : parsXML) {
TFile xmlTIBCO = new TFile(parXML, "TIBCO.xml");
String tempPath = ear.getParentFile().getAbsolutePath() + File.separator + "TIBCO.xml";
TFile xmlTIBCOTemp = new TFile(tempPath);
truezip.copyFile(xmlTIBCO, xmlTIBCOTemp);
File xmlTIBCOFile = new File(tempPath);
SAXBuilder sxb = new SAXBuilder();
Document document = sxb.build(xmlTIBCOFile);
XPath xpa = XPath.newInstance("//dd:NameValuePairs/dd:NameValuePair[dd:name='EXTERNAL_JAR_DEPENDENCY']/dd:value");
xpa.addNamespace("dd", "http://www.tibco.com/xmlns/dd");
Element singleNode = (Element) xpa.selectSingleNode(document);
if (singleNode != null) {
String value = singleNode.getText().replace(includeOrigin, includeDestination);
singleNode.setText(value);
XMLOutputter xmlOutput = new XMLOutputter();
xmlOutput.setFormat(Format.getPrettyFormat().setIndent(" "));
xmlOutput.output(document, new FileWriter(xmlTIBCOFile));
truezip.copyFile(xmlTIBCOTemp, xmlTIBCO);
}
}
}
示例4: 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;
}
}
示例5: getMoleculeMass
import org.jdom.xpath.XPath; //导入依赖的package包/类
public double getMoleculeMass(String a_strType, boolean a_bMonoisotopic) throws Exception, ParameterException
{
XPath xpath = XPath.newInstance("/defaults/molecules/small_molecules");
for (Iterator t_iterPersub = xpath.selectNodes( this.m_docDefaultMasses ).iterator(); t_iterPersub.hasNext();)
{
Element t_objElementMain = (Element) t_iterPersub.next();
if ( t_objElementMain.getChild("name").getTextTrim().equals(a_strType) )
{
Element t_objElementMass = null;
if ( a_bMonoisotopic )
{
t_objElementMass = t_objElementMain.getChild("mass_mono");
}
else
{
t_objElementMass = t_objElementMain.getChild("mass_avg");
}
return Double.parseDouble(t_objElementMass.getTextTrim());
}
}
throw new ParameterException("Unknown small molecule.");
}
示例6: getIonMass
import org.jdom.xpath.XPath; //导入依赖的package包/类
public double getIonMass(String a_strIon, boolean a_bMonoisotopic) throws ParameterException, Exception
{
XPath xpath = XPath.newInstance("/defaults/ions/ion");
for (Iterator t_iterIon = xpath.selectNodes( this.m_docDefaultMasses ).iterator(); t_iterIon.hasNext();)
{
Element t_objElementMain = (Element) t_iterIon.next();
if ( t_objElementMain.getChild("formula").getTextTrim().equals(a_strIon) )
{
Element t_objElementMass = null;
if ( a_bMonoisotopic )
{
t_objElementMass = t_objElementMain.getChild("mass_mono");
}
else
{
t_objElementMass = t_objElementMain.getChild("mass_avg");
}
return (Double.parseDouble(t_objElementMass.getTextTrim()) - this.getMassE(a_bMonoisotopic));
}
}
throw new ParameterException("Unknown ion.");
}
示例7: getIncrementMass
import org.jdom.xpath.XPath; //导入依赖的package包/类
/**
* Gives the mass of the increment
*
* @param a_strPerSub type of persubstitution
* @param a_bMonoIsotopic true if monoisotopic mass
* @return
* @throws JDOMException
* @throws ParameterException thrown if type of persubstitution is unknown
*/
public double getIncrementMass(Persubstitution a_strPerSub , boolean a_bMonoIsotopic) throws ParameterException, Exception
{
XPath xpath = XPath.newInstance("/defaults/persubstitutions/persubstitution");
for (Iterator t_iterPersub = xpath.selectNodes( this.m_docDefaultMasses ).iterator(); t_iterPersub.hasNext();)
{
Element t_objElementPersub = (Element) t_iterPersub.next();
if ( t_objElementPersub.getChild("name").getTextTrim().equals(a_strPerSub.getAbbr()) )
{
Element t_objElementMass = null;
if ( a_bMonoIsotopic )
{
t_objElementMass = t_objElementPersub.getChild("increment_mono");
}
else
{
t_objElementMass = t_objElementPersub.getChild("increment_avg");
}
return Double.parseDouble(t_objElementMass.getTextTrim());
}
}
throw new ParameterException("Unknown persubstitution.");
}
示例8: getIncrementMassAX
import org.jdom.xpath.XPath; //导入依赖的package包/类
/**
* Gives the mass of the increment for A/X fragments
*
* @param a_strPerSub type of persubstitution
* @param a_bMonoIsotopic true if monoisotopic mass
* @return
* @throws JDOMException
* @throws ParameterException thrown if type of persubstitution is unknown
*/
public double getIncrementMassAX(Persubstitution a_strPerSub , boolean a_bMonoIsotopic) throws ParameterException, Exception
{
XPath xpath = XPath.newInstance("/defaults/persubstitutions/persubstitution");
for (Iterator t_iterPersub = xpath.selectNodes( this.m_docDefaultMasses ).iterator(); t_iterPersub.hasNext();)
{
Element t_objElementPersub = (Element) t_iterPersub.next();
if ( t_objElementPersub.getChild("name").getTextTrim().equals(a_strPerSub.getAbbr()) )
{
if ( a_bMonoIsotopic )
{
return ( Double.parseDouble(t_objElementPersub.getChild("increment_mono").getTextTrim())
- Double.parseDouble(t_objElementPersub.getChild("mono").getTextTrim()));
}
else
{
return ( Double.parseDouble(t_objElementPersub.getChild("increment_avg").getTextTrim())
- Double.parseDouble(t_objElementPersub.getChild("avg").getTextTrim()));
}
}
}
throw new ParameterException("Unknown persubstitution.");
}
示例9: getNonReducingDifference
import org.jdom.xpath.XPath; //导入依赖的package包/类
public double getNonReducingDifference(Persubstitution a_objPersub, boolean a_bMonoisotopic) throws ParameterException, Exception
{
XPath xpath = XPath.newInstance("/defaults/persubstitutions/persubstitution");
for (Iterator t_iterPersub = xpath.selectNodes( this.m_docDefaultMasses ).iterator(); t_iterPersub.hasNext();)
{
Element t_objElementPersub = (Element) t_iterPersub.next();
if ( t_objElementPersub.getChild("name").getTextTrim().equals(a_objPersub.getAbbr()) )
{
Element t_objElementMass = null;
if ( a_bMonoisotopic )
{
t_objElementMass = t_objElementPersub.getChild("ergaenzung_nonred_mono");
}
else
{
t_objElementMass = t_objElementPersub.getChild("ergaenzung_nonred_avg");
}
if ( t_objElementMass == null )
{
throw new ParameterException("Unknown persubstitution type.");
}
return Double.parseDouble(t_objElementMass.getTextTrim());
}
}
throw new ParameterException("Unknown persubstitution type.");
}
示例10: 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);
}
}
示例11: 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();
}
}
示例12: 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();
}
示例13: 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()]);
}
示例14: testVersions
import org.jdom.xpath.XPath; //导入依赖的package包/类
@Test
public void testVersions() throws Exception {
XPath xpath = XPath.newInstance("/ns:project/ns:properties");
xpath.addNamespace(Namespace.getNamespace("ns", "http://maven.apache.org/POM/4.0.0"));
Element node = (Element) xpath.selectSingleNode(wfcRoot);
for (Object child : node.getChildren()) {
String wfcKey = ((Element) child).getName();
String wfcVal = ((Element) child).getText();
String targetVal = getTargetValue(wfcKey);
if (targetVal != null) {
if (!targetVal.equals(wfcVal) && !targetVal.startsWith(wfcVal + ".redhat")) {
problems.add(wfcKey + ": " + wfcVal + " => " + targetVal);
}
}
}
for (String line : problems) {
System.err.println(line);
}
Assert.assertEquals("Mapping problems", Collections.emptyList(), problems);
}
示例15: getTargetValue
import org.jdom.xpath.XPath; //导入依赖的package包/类
public String getTargetValue(String wfcKey) throws JDOMException {
Element rootNode;
if (wfcKey.startsWith("version.camel.")) {
rootNode = camelRoot;
} else if (wfcKey.startsWith("version.wildfly.")) {
rootNode = wfRoot;
} else {
return null;
}
String targetKey = mapping.get(wfcKey);
if (targetKey == null) {
problems.add("Cannot find mapping for: " + wfcKey);
return null;
}
XPath xpath = XPath.newInstance("/ns:project/ns:properties/ns:" + targetKey);
xpath.addNamespace(Namespace.getNamespace("ns", "http://maven.apache.org/POM/4.0.0"));
Element propNode = (Element) xpath.selectSingleNode(rootNode);
if (propNode == null) {
problems.add("Cannot obtain target property: " + targetKey);
return null;
}
return propNode.getText();
}