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


Java XPath.newInstance方法代码示例

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


在下文中一共展示了XPath.newInstance方法的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;
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:17,代码来源:FogBugzRepository.java

示例2: 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();
       }
}
 
开发者ID:openaire,项目名称:iis,代码行数:24,代码来源:NlmToDocumentWithBasicMetadataConverter.java

示例3: 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.");
}
 
开发者ID:glycoinfo,项目名称:eurocarbdb,代码行数:23,代码来源:DefaultMasses.java

示例4: 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.");
}
 
开发者ID:glycoinfo,项目名称:eurocarbdb,代码行数:32,代码来源:DefaultMasses.java

示例5: 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.");
}
 
开发者ID:glycoinfo,项目名称:eurocarbdb,代码行数:27,代码来源:DefaultMasses.java

示例6: 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()]);
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:25,代码来源:FogBugzRepository.java

示例7: 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);
 }
}
 
开发者ID:sakaiproject,项目名称:sakai,代码行数:17,代码来源:Parser.java

示例8: 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);
}
 
开发者ID:wildfly-extras,项目名称:wildfly-camel,代码行数:22,代码来源:VersionsValidatorTest.java

示例9: 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();
    }
 
开发者ID:wildfly-extras,项目名称:wildfly-camel,代码行数:26,代码来源:VersionsValidatorTest.java

示例10: init

import org.jdom.xpath.XPath; //导入方法依赖的package包/类
private void init() throws IOException {
	Document request = MyUtils.toDocument(wsdlDoc
			.generateRequest(parentOperation));
	setDocumentation();
	String expression = "//*[local-name()='" + name + "'][1]/text()";
	try {
		XPath xp = XPath.newInstance(expression);
		Text t = (Text) xp.selectSingleNode(request);
		String value = t.getText();
		if (value.equals("?")) {
			defaultValue = "";
		} else if (value.startsWith("cid:")) {
			binary = true;
			defaultValue = "";
		} else {
			defaultValue = value;
		}

	} catch (JDOMException e) {
		throw new IOException("Could not read the generated SOAP using "
				+ expression, e);
	}
}
 
开发者ID:impactcentre,项目名称:iif-generic-soap-client,代码行数:24,代码来源:SoapInput.java

示例11: setValue

import org.jdom.xpath.XPath; //导入方法依赖的package包/类
private void setValue() {

		try {
			SAXBuilder parser = new SAXBuilder();
			Document jdomDoc = parser.build(new ByteArrayInputStream(response
					.getBytes()));
			String expression = "//*[local-name()='" + name + "'][1]/text()";
			XPath xp = XPath.newInstance(expression);
			Text t = (Text) xp.selectSingleNode(jdomDoc);
			if (t != null)
				value = t.getText();

		} catch (JDOMException | IOException e) {
			logger.error("Could not set value for output " + name, e);
		}

    }
 
开发者ID:impactcentre,项目名称:iif-generic-soap-client,代码行数:18,代码来源:SoapOutput.java

示例12: addJarsToClassLoader

import org.jdom.xpath.XPath; //导入方法依赖的package包/类
/**
  * Extract all JAR elements from the given JDOM document and add the jars they
  * reference to the GateClassLoader.
  * 
  * @param jdomDoc
  *          JDOM document representing a parsed creole.xml file.
  */
public void addJarsToClassLoader(GateClassLoader gcl, Document jdomDoc) throws IOException {
	try {
		XPath jarXPath = XPath.newInstance("//*[translate(local-name(), 'ivy', 'IVY') = 'IVY']");
		if (jarXPath.selectNodes(jdomDoc).size() > 0) {
			throw new IOException("Using Ivy for dependency management is no longer supported");
		}
	} catch (JDOMException e) {
		throw new IOException("Unable to load plugin", e);
	}

	addJarsToClassLoader(gcl, jdomDoc.getRootElement());
}
 
开发者ID:GateNLP,项目名称:gate-core,代码行数:20,代码来源:CreoleAnnotationHandler.java

示例13: getOperationsByView

import org.jdom.xpath.XPath; //导入方法依赖的package包/类
/**
 * Selects operations that use interval inputs on the axes listed in the view
 *
 * @param view a string containing an ordered subset of xyzt.
 * @return operations a list of operation elements that use this view
 * @throws JDOMException
 * @deprecated
 */
public ArrayList<NameValuePair> getOperationsByView(String view) throws JDOMException {
    ArrayList<NameValuePair> ops = new ArrayList<NameValuePair>();
    String path = "/lasdata/operations/operation[@intervals='"+view+"']";
    XPath xpath = XPath.newInstance(path);
    for (Iterator nodes = xpath.selectNodes(this).iterator(); nodes.hasNext(); ) {
        Element op = (Element)nodes.next();
        ops.add(new NameValuePair(op.getAttributeValue("name"), op.getAttributeValue("ID")));
    }
    return ops;
}
 
开发者ID:NOAA-PMEL,项目名称:LAS,代码行数:19,代码来源:LASConfig.java

示例14: getElementByXPath

import org.jdom.xpath.XPath; //导入方法依赖的package包/类
/**
 * A utility class that returns an element based on the XPath to that element.
 * @param xpathValue the XPath string of the element to be found.
 * @return the element specified by the XPath.
 * @throws JDOMException
 */
public Element getElementByXPath(String xpathValue) throws JDOMException {
    // E.g. xpathValue="/lasdata/operations/operation[@ID='Plot']"
	String xpv = Encode.forJava(xpathValue);
    Object jdomO = this;
    XPath xpath = XPath.newInstance(xpv);
    return (Element) xpath.selectSingleNode(jdomO);   
}
 
开发者ID:NOAA-PMEL,项目名称:LAS,代码行数:14,代码来源:IOSPDocument.java

示例15: 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);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:36,代码来源:GuiTestCase.java


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