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


Java XPath.setNamespaceContext方法代码示例

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


在下文中一共展示了XPath.setNamespaceContext方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testAddLibraries

import javax.xml.xpath.XPath; //导入方法依赖的package包/类
public void testAddLibraries() throws Exception {
    SuiteProject suite = TestBase.generateSuite(getWorkDir(), "suite");
    TestBase.generateSuiteComponent(suite, "lib");
    TestBase.generateSuiteComponent(suite, "testlib");
    NbModuleProject clientprj = TestBase.generateSuiteComponent(suite, "client");
    Library lib = LibraryFactory.createLibrary(new LibImpl("lib"));
    FileObject src = clientprj.getSourceDirectory();
    assertTrue(ProjectClassPathModifier.addLibraries(new Library[] {lib}, src, ClassPath.COMPILE));
    assertFalse(ProjectClassPathModifier.addLibraries(new Library[] {lib}, src, ClassPath.COMPILE));
    Library testlib = LibraryFactory.createLibrary(new LibImpl("testlib"));
    FileObject testsrc = clientprj.getTestSourceDirectory("unit");
    assertTrue(ProjectClassPathModifier.addLibraries(new Library[] {testlib}, testsrc, ClassPath.COMPILE));
    assertFalse(ProjectClassPathModifier.addLibraries(new Library[] {testlib}, testsrc, ClassPath.COMPILE));
    InputSource input = new InputSource(clientprj.getProjectDirectory().getFileObject("nbproject/project.xml").toURL().toString());
    XPath xpath = XPathFactory.newInstance().newXPath();
    xpath.setNamespaceContext(nbmNamespaceContext());
    assertEquals("org.example.client", xpath.evaluate("//nbm:data/nbm:code-name-base", input)); // control
    assertEquals("org.example.lib", xpath.evaluate("//nbm:module-dependencies/*/nbm:code-name-base", input));
    assertEquals("org.example.testlib", xpath.evaluate("//nbm:test-dependencies/*/*/nbm:code-name-base", input));
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:ModuleProjectClassPathExtenderTest.java

示例2: testAddRoots

import javax.xml.xpath.XPath; //导入方法依赖的package包/类
public void testAddRoots() throws Exception {
    NbModuleProject prj = TestBase.generateStandaloneModule(getWorkDir(), "module");
    FileObject src = prj.getSourceDirectory();
    FileObject jar = TestFileUtils.writeZipFile(FileUtil.toFileObject(getWorkDir()), "a.jar", "entry:contents");
    URL root = FileUtil.getArchiveRoot(jar.toURL());
    assertTrue(ProjectClassPathModifier.addRoots(new URL[] {root}, src, ClassPath.COMPILE));
    assertFalse(ProjectClassPathModifier.addRoots(new URL[] {root}, src, ClassPath.COMPILE));
    FileObject releaseModulesExt = prj.getProjectDirectory().getFileObject("release/modules/ext");
    assertNotNull(releaseModulesExt);
    assertNotNull(releaseModulesExt.getFileObject("a.jar"));
    jar = TestFileUtils.writeZipFile(releaseModulesExt, "b.jar", "entry2:contents");
    root = FileUtil.getArchiveRoot(jar.toURL());
    assertTrue(ProjectClassPathModifier.addRoots(new URL[] {root}, src, ClassPath.COMPILE));
    assertFalse(ProjectClassPathModifier.addRoots(new URL[] {root}, src, ClassPath.COMPILE));
    assertEquals(2, releaseModulesExt.getChildren().length);
    String projectXml = prj.getProjectDirectory().getFileObject("nbproject/project.xml").toURL().toString();
    InputSource input = new InputSource(projectXml);
    XPath xpath = XPathFactory.newInstance().newXPath();
    xpath.setNamespaceContext(nbmNamespaceContext());
    assertEquals(projectXml, "ext/a.jar", xpath.evaluate("//nbm:class-path-extension[1]/nbm:runtime-relative-path", input));
    assertEquals(projectXml, "release/modules/ext/a.jar", xpath.evaluate("//nbm:class-path-extension[1]/nbm:binary-origin", input));
    assertEquals(projectXml, "ext/b.jar", xpath.evaluate("//nbm:class-path-extension[2]/nbm:runtime-relative-path", input));
    assertEquals(projectXml, "release/modules/ext/b.jar", xpath.evaluate("//nbm:class-path-extension[2]/nbm:binary-origin", input));
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:25,代码来源:ModuleProjectClassPathExtenderTest.java

示例3: unwrapSoapMessage

import javax.xml.xpath.XPath; //导入方法依赖的package包/类
public Element unwrapSoapMessage(Element soapElement) {
    XPath xpath = XPathFactory.newInstance().newXPath();
    NamespaceContextImpl context = new NamespaceContextImpl();
    context.startPrefixMapping("soapenv", "http://schemas.xmlsoap.org/soap/envelope/");
    context.startPrefixMapping("samlp", "urn:oasis:names:tc:SAML:2.0:protocol");
    context.startPrefixMapping("saml", "urn:oasis:names:tc:SAML:2.0:assertion");
    context.startPrefixMapping("ds", "http://www.w3.org/2000/09/xmldsig#");
    xpath.setNamespaceContext(context);
    try {
        final String expression = "/soapenv:Envelope/soapenv:Body/samlp:Response";
        Element element = (Element) xpath.evaluate(expression, soapElement, XPathConstants.NODE);

        if (element == null) {
            String errorMessage = format("Document{0}{1}{0}does not have element {2} inside it.", NEW_LINE,
                    writeToString(soapElement), expression);
            LOG.error(errorMessage);
            throw new IllegalArgumentException(errorMessage);
        }

        return element;
    } catch (XPathExpressionException e) {
        throw propagate(e);
    }
}
 
开发者ID:alphagov,项目名称:verify-hub,代码行数:25,代码来源:SoapMessageManager.java

示例4: shouldBuildDocumentFromSetOfXPaths

import javax.xml.xpath.XPath; //导入方法依赖的package包/类
@Test
public void shouldBuildDocumentFromSetOfXPaths()
        throws XPathExpressionException, TransformerException, IOException {
    Map<String, Object> xmlProperties = fixtureAccessor.getXmlProperties();
    Document document = documentBuilder.newDocument();
    document.setXmlStandalone(true);
    Document builtDocument = new XmlBuilder(namespaceContext)
            .putAll(xmlProperties.keySet())
            .build(document);

    for (Entry<String, Object> xpathToValuePair : xmlProperties.entrySet()) {
        XPath xpath = xpathFactory.newXPath();
        if (null != namespaceContext) {
            xpath.setNamespaceContext(namespaceContext);
        }
        assertThat(xpath.evaluate(xpathToValuePair.getKey(), builtDocument)).isNotNull();
    }
    assertThat(xmlToString(builtDocument)).isEqualTo(fixtureAccessor.getPutXml());
}
 
开发者ID:SimY4,项目名称:xpath-to-xml,代码行数:20,代码来源:XmlBuilderTest.java

示例5: shouldBuildDocumentFromSetOfXPathsAndSetValues

import javax.xml.xpath.XPath; //导入方法依赖的package包/类
@Test
public void shouldBuildDocumentFromSetOfXPathsAndSetValues()
        throws XPathExpressionException, TransformerException, IOException {
    Map<String, Object> xmlProperties = fixtureAccessor.getXmlProperties();
    Document document = documentBuilder.newDocument();
    document.setXmlStandalone(true);
    Document builtDocument = new XmlBuilder(namespaceContext)
            .putAll(xmlProperties)
            .build(document);

    for (Entry<String, Object> xpathToValuePair : xmlProperties.entrySet()) {
        XPath xpath = xpathFactory.newXPath();
        if (null != namespaceContext) {
            xpath.setNamespaceContext(namespaceContext);
        }
        assertThat(xpath.evaluate(xpathToValuePair.getKey(), builtDocument, XPathConstants.STRING))
                .isEqualTo(xpathToValuePair.getValue());
    }
    assertThat(xmlToString(builtDocument)).isEqualTo(fixtureAccessor.getPutValueXml());
}
 
开发者ID:SimY4,项目名称:xpath-to-xml,代码行数:21,代码来源:XmlBuilderTest.java

示例6: unwrapSoapMessage

import javax.xml.xpath.XPath; //导入方法依赖的package包/类
private Element unwrapSoapMessage(Element soapElement, SamlElementType samlElementType) {
    XPath xpath = XPathFactory.newInstance().newXPath();
    NamespaceContextImpl context = new NamespaceContextImpl();
    context.startPrefixMapping("soapenv", "http://schemas.xmlsoap.org/soap/envelope/");
    context.startPrefixMapping("samlp", "urn:oasis:names:tc:SAML:2.0:protocol");
    context.startPrefixMapping("saml", "urn:oasis:names:tc:SAML:2.0:assertion");
    context.startPrefixMapping("ds", "http://www.w3.org/2000/09/xmldsig#");
    xpath.setNamespaceContext(context);
    try {
        String expression = "//samlp:" + samlElementType.getElementName();
        Element element = (Element) xpath.evaluate(expression, soapElement, XPathConstants.NODE);

        if (element == null) {
            String errorMessage = format("Document{0}{1}{0}does not have element {2} inside it.", NEW_LINE,
                    XmlUtils.writeToString(soapElement), expression);
            LOG.error(errorMessage);
            throw new SoapUnwrappingException(errorMessage);
        }

        return element;
    } catch (XPathExpressionException e) {
        throw propagate(e);
    }
}
 
开发者ID:alphagov,项目名称:verify-matching-service-adapter,代码行数:25,代码来源:SoapMessageManager.java

示例7: runXPathQuery

import javax.xml.xpath.XPath; //导入方法依赖的package包/类
public static List<String> runXPathQuery(File parsedFile, String xpathExpr) throws Exception{
    List<String> result = new ArrayList<String>();
    XPath xpath = XPathFactory.newInstance().newXPath();
    xpath.setNamespaceContext(getNamespaceContext());
    
    InputSource inputSource = new InputSource(new FileInputStream(parsedFile));
    NodeList nodes = (NodeList) xpath.evaluate(xpathExpr, inputSource, XPathConstants.NODESET);
    if((nodes != null) && (nodes.getLength() > 0)){
        for(int i=0; i<nodes.getLength();i++){
            Node node = nodes.item(i);
            result.add(node.getNodeValue());
        }
    }
    return result;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:16,代码来源:Utilities.java

示例8: runXPathQuery

import javax.xml.xpath.XPath; //导入方法依赖的package包/类
public static List runXPathQuery(File parsedFile, String xpathExpr) throws Exception{
    List result = new ArrayList();
    XPath xpath = XPathFactory.newInstance().newXPath();
    xpath.setNamespaceContext(getNamespaceContext());
    
    InputSource inputSource = new InputSource(new FileInputStream(parsedFile));
    NodeList nodes = (NodeList) xpath.evaluate(xpathExpr, inputSource, XPathConstants.NODESET);
    if((nodes != null) && (nodes.getLength() > 0)){
        for(int i=0; i<nodes.getLength();i++){
            org.w3c.dom.Node node = nodes.item(i);
            result.add(node.getNodeValue());
        }
    }
    return result;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:16,代码来源:Util.java

示例9: getAttributeQuery

import javax.xml.xpath.XPath; //导入方法依赖的package包/类
private Element getAttributeQuery(Document document) throws XPathExpressionException {
    XPath xpath = XPathFactory.newInstance().newXPath();
    NamespaceContextImpl context = new NamespaceContextImpl();
    context.startPrefixMapping("soapenv", "http://schemas.xmlsoap.org/soap/envelope/");
    context.startPrefixMapping("samlp", "urn:oasis:names:tc:SAML:2.0:protocol");
    xpath.setNamespaceContext(context);

    return (Element) xpath.evaluate("//samlp:Response", document, XPathConstants.NODE);
}
 
开发者ID:alphagov,项目名称:verify-hub,代码行数:10,代码来源:SoapMessageManagerTest.java

示例10: getDubboInterfaces

import javax.xml.xpath.XPath; //导入方法依赖的package包/类
protected LinkedList<String> getDubboInterfaces() {
	LinkedList<String> result = new LinkedList<String>();
	try {
		String filePath = ((AbstractConfiguration) this.wrDoc
				.getConfiguration()).dubboconfigpath;
		if(!StringUtils.isEmpty(filePath)) {
			Document dubboConfig = readXMLConfig(((AbstractConfiguration) this.wrDoc
					.getConfiguration()).dubboconfigpath);
			XPath xPath = XPathFactory.newInstance().newXPath();
			xPath.setNamespaceContext(new UniversalNamespaceCache(dubboConfig,
					false));
			NodeList serviceNodes = (NodeList) xPath.evaluate(
					"//:beans/dubbo:service", dubboConfig,
					XPathConstants.NODESET);
			for (int i = 0; i < serviceNodes.getLength(); i++) {
				Node node = serviceNodes.item(i);
				String ifc = getAttributeValue(node, "interface");
				if (ifc != null)
					result.add(ifc);
			}
		}
	} catch (Exception e) {
		this.logger.error(e);
	}
	this.logger.debug("dubbo interface list:");
	for (String s : result) {
		this.logger.debug("interface: " + s);
	}
	return result;
}
 
开发者ID:WinRoad-NET,项目名称:wrdocletbase,代码行数:31,代码来源:DubboDocBuilder.java

示例11: getDubboProtocols

import javax.xml.xpath.XPath; //导入方法依赖的package包/类
/**
 * @param dubboConfigFilePath
 * @return HashMap, key protocol id, value "dubbo" or "http"
    */
protected static HashMap<String, String> getDubboProtocols(String dubboConfigFilePath) throws IOException, SAXException, ParserConfigurationException, XPathExpressionException {
	HashMap<String, String> result = new HashMap<>();
	if(!StringUtils.isEmpty(dubboConfigFilePath)) {
		Document dubboConfig = readXMLConfig(dubboConfigFilePath);
		XPath xPath = XPathFactory.newInstance().newXPath();
		xPath.setNamespaceContext(new UniversalNamespaceCache(dubboConfig,
				false));
		NodeList serviceNodes = (NodeList) xPath.evaluate(
				"//:beans/dubbo:protocol", dubboConfig,
				XPathConstants.NODESET);
		for (int i = 0; i < serviceNodes.getLength(); i++) {
			Node node = serviceNodes.item(i);
			String id = getAttributeValue(node, "id");
			String name = getAttributeValue(node, "name");
			String server = getAttributeValue(node, "server");
			if(StringUtils.isEmpty(id)) {
				id = name;
			}
			if("servlet".equalsIgnoreCase(server) || "jetty".equalsIgnoreCase(server)) {
				result.put(id, "http");
			} else {
				result.put(id, "dubbo");
			}
		}
	}
	return result;
}
 
开发者ID:WinRoad-NET,项目名称:wrdocletbase,代码行数:32,代码来源:DubboDocBuilder.java

示例12: evaluate

import javax.xml.xpath.XPath; //导入方法依赖的package包/类
void evaluate(boolean enableExt) throws XPathFactoryConfigurationException, XPathExpressionException {
    Document document = getDocument();

    XPathFactory xPathFactory = XPathFactory.newInstance();
    /**
     * Use of the extension function 'http://exslt.org/strings:tokenize' is
     * not allowed when the secure processing feature is set to true.
     * Attempt to use the new property to enable extension function
     */
    if (enableExt) {
        boolean isExtensionSupported = enableExtensionFunction(xPathFactory);
    }

    xPathFactory.setXPathFunctionResolver(new MyXPathFunctionResolver());
    if (System.getSecurityManager() == null) {
        xPathFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, false);
    }

    XPath xPath = xPathFactory.newXPath();
    xPath.setNamespaceContext(new MyNamespaceContext());

    String xPathResult = xPath.evaluate(XPATH_EXPRESSION, document);
    System.out.println(
            "XPath result (enableExtensionFunction == " + enableExt + ") = \""
            + xPathResult
            + "\"");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:28,代码来源:XPathExFuncTest.java

示例13: configure

import javax.xml.xpath.XPath; //导入方法依赖的package包/类
protected void configure(XPath xPath, NamespaceContext namespaceContext)
{
	xPath.setNamespaceContext(namespaceContext);
}
 
开发者ID:fluentxml4j,项目名称:fluentxml4j,代码行数:5,代码来源:XPathConfigurerAdapter.java

示例14: newXPath

import javax.xml.xpath.XPath; //导入方法依赖的package包/类
/**
 * Creates a new XPath object, specifying which prefix in the query is used for the
 * android namespace.
 * @param androidPrefix The namespace prefix.
 */
public static XPath newXPath(String androidPrefix) {
    XPath xpath = sFactory.newXPath();
    xpath.setNamespaceContext(new AndroidNamespaceContext(androidPrefix));
    return xpath;
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:11,代码来源:AndroidXPathFactory.java

示例15: query

import javax.xml.xpath.XPath; //导入方法依赖的package包/类
public static NodeList query(Node node, String searchString, XPathContext xpathcontext)
    throws XPathExpressionException {
  XPath xpath = XPathFactory.newInstance().newXPath();
  xpath.setNamespaceContext(xpathcontext);
  return (NodeList) xpath.evaluate(searchString, node, XPathConstants.NODESET);
}
 
开发者ID:ampool,项目名称:monarch,代码行数:7,代码来源:XmlUtils.java


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