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


Java Document.getElementsByTagNameNS方法代码示例

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


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

示例1: newKeySelector_keyinfoEmpty

import org.w3c.dom.Document; //导入方法依赖的package包/类
@Test
public void newKeySelector_keyinfoEmpty() throws Exception {
    // given
    String response = Strings
            .textFileToString("javares/openamResponse.xml");
    response = response.replaceAll(System.lineSeparator(), "").replaceAll(
            "<ds:KeyInfo>.*</ds:KeyInfo>", "<ds:KeyInfo></ds:KeyInfo>");
    Document document = XMLConverter.convertToDocument(response, true);
    NodeList nl = document.getElementsByTagNameNS(XMLSignature.XMLNS,
            "Signature");

    // when
    try {
        factory.newKeySelector(nl.item(0));
        fail();
    } catch (DigitalSignatureValidationException e) {
        assertTrue(e.getMessage().contains(
                "Only RSA/DSA KeyValue and are X509Data supported"));
    }
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:21,代码来源:KeySelectorFactoryTest.java

示例2: newKeySelector_keyinfoMissing

import org.w3c.dom.Document; //导入方法依赖的package包/类
@Test
public void newKeySelector_keyinfoMissing() throws Exception {
    // given
    String response = Strings
            .textFileToString("javares/openamResponse.xml");
    response = response.replaceAll(System.lineSeparator(), "").replaceAll(
            "<ds:KeyInfo>.*</ds:KeyInfo>", "");
    Document document = XMLConverter.convertToDocument(response, true);
    NodeList nl = document.getElementsByTagNameNS(XMLSignature.XMLNS,
            "Signature");

    try {
        // when
        factory.newKeySelector(nl.item(0));
        fail();
    } catch (DigitalSignatureValidationException e) {
        // then
        assertTrue(e.getMessage().contains(
                "No KeyInfo element found in SAML assertion"));
    }
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:22,代码来源:KeySelectorFactoryTest.java

示例3: newKeySelector_firstFound

import org.w3c.dom.Document; //导入方法依赖的package包/类
@Test
public void newKeySelector_firstFound() throws Exception {
    // given
    String response = Strings
            .textFileToString("javares/openamResponse.xml");
    Document document = XMLConverter.convertToDocument(
            addKeyValueAfterX509Data(response), true);
    NodeList nl = document.getElementsByTagNameNS(XMLSignature.XMLNS,
            "Signature");

    // when
    KeySelector keySelector = factory.newKeySelector(nl.item(0));

    // then
    assertTrue(keySelector instanceof X509KeySelector);
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:17,代码来源:KeySelectorFactoryTest.java

示例4: validateXSD

import org.w3c.dom.Document; //导入方法依赖的package包/类
protected void validateXSD(Document signedDoc) throws SAXException, IOException {
    NodeList nodeList = signedDoc.getElementsByTagNameNS(RedactableXMLSignature.XML_NAMESPACE, "Signature");
    assertEquals(1, nodeList.getLength());

    Node signature = nodeList.item(0);
    NodeList childNodes = signature.getChildNodes();
    int actualNodes = 0;
    for (int i = 0; i < childNodes.getLength(); i++) {
        if (childNodes.item(i).getNodeType() == Node.ELEMENT_NODE) {
            ++actualNodes;
        }
    }
    assertEquals(3, actualNodes);

    SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
    Schema schema = schemaFactory.newSchema(new File("xmlrss_schema.xsd"));
    Validator validator = schema.newValidator();
    validator.validate(new DOMSource(signature));
}
 
开发者ID:woefe,项目名称:xmlrss,代码行数:20,代码来源:AbstractXMLRSSTest.java

示例5: deserializeMembers

import org.w3c.dom.Document; //导入方法依赖的package包/类
/**
 * Deserializes member elements from the given XML document.
 *
 * @param doc XML document to be deserialized
 * @return list of ConsumerMember objects
 * @throws XRd4JException if there's a XRd4J error
 */
private List<ConsumerMember> deserializeMembers(final Document doc)
        throws XRd4JException {
    List<ConsumerMember> results = new ArrayList<>();
    LOGGER.debug("Deserialize \"{}\".", Constants.NS_XRD_ELEM_CLIENT_LIST);

    NodeList list = doc.getElementsByTagNameNS(Constants.NS_XRD_URL, Constants.NS_XRD_ELEM_ID);
    LOGGER.debug("Found {} {} elements from XML. ", list.getLength(), Constants.NS_XRD_ELEM_ID);
    for (int i = 0; i < list.getLength(); i++) {
        // Client object type
        ObjectType clientObjectType = super.deserializeObjectType(list.item(i));
        // Client headers
        Map<String, String> client = SOAPHelper.nodesToMap(list.item(i).getChildNodes());
        LOGGER.trace("Element found : \"{}\"", Constants.NS_XRD_ELEM_ID);
        results.add(super.getConsumerMember(client, clientObjectType));
    }
    LOGGER.debug("Deserialized {} \"{}\" elements from the given XML document.", results.size(), Constants.NS_XRD_ELEM_ID);
    return results;
}
 
开发者ID:vrk-kpa,项目名称:xrd4j,代码行数:26,代码来源:ListClientsResponseDeserializer.java

示例6: deserializeCentralServices

import org.w3c.dom.Document; //导入方法依赖的package包/类
/**
 * Deserializes centralService elements from the given XML document.
 *
 * @param doc XML document to be deserialized
 * @return list of ProducerMember objects
 * @throws XRd4JException if there's a XRd4J error
 */
private List<ProducerMember> deserializeCentralServices(final Document doc)
        throws XRd4JException {
    List<ProducerMember> results = new ArrayList<>();
    LOGGER.debug("Deserialize \"{}\".", Constants.NS_XRD_ELEM_CENTRAL_SERVICE_LIST);

    NodeList list = doc.getElementsByTagNameNS(Constants.NS_XRD_URL, Constants.NS_XRD_ELEM_CENTRAL_SERVICE);
    LOGGER.debug("Found {} {} elements from XML. ", list.getLength(), Constants.NS_XRD_ELEM_CENTRAL_SERVICE);
    for (int i = 0; i < list.getLength(); i++) {
        // Client object type
        ObjectType clientObjectType = super.deserializeObjectType(list.item(i));
        // Client headers
        Map<String, String> service = SOAPHelper.nodesToMap(list.item(i).getChildNodes());
        LOGGER.trace("Element found : \"{}\"", Constants.NS_XRD_ELEM_CENTRAL_SERVICE);
        results.add(super.getProducerMember(service, clientObjectType));
    }
    LOGGER.debug("Found \"{}\" \"{}\" elements from the given XML document.", results.size(), Constants.NS_XRD_ELEM_CENTRAL_SERVICE);
    return results;
}
 
开发者ID:vrk-kpa,项目名称:xrd4j,代码行数:26,代码来源:ListCentralServicesResponseDeserializer.java

示例7: testNamespaceAware

import org.w3c.dom.Document; //导入方法依赖的package包/类
@Test
public void testNamespaceAware() throws Exception {
    Document document = createDOM("ElementSample02.xml");

    NodeList nl = document.getElementsByTagNameNS("urn:BooksAreUs.org:BookInfo", "author");
    assertNull(nl.item(0));

    nl = document.getDocumentElement().getElementsByTagNameNS("urn:BooksAreUs.org:BookInfo", "author");
    assertNull(nl.item(0));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:11,代码来源:ElementTest.java

示例8: testAddNewAttributeNode

import org.w3c.dom.Document; //导入方法依赖的package包/类
@Test
public void testAddNewAttributeNode() throws Exception {
    Document document = createDOMWithNS("DocumentTest01.xml");

    NodeList nodeList = document.getElementsByTagNameNS("http://www.w3.org/TR/REC-html40", "body");
    NodeList childList = nodeList.item(0).getChildNodes();
    Element child = (Element) childList.item(1);
    Attr a = document.createAttributeNS("urn:BooksAreUs.org:BookInfo", "attributeNew");
    child.setAttributeNode(a);
    assertNotNull(child.getAttributeNodeNS("urn:BooksAreUs.org:BookInfo", "attributeNew"));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:12,代码来源:DocumentTest.java

示例9: testAddNewElement

import org.w3c.dom.Document; //导入方法依赖的package包/类
@Test
public void testAddNewElement() throws Exception {
    Document document = createDOMWithNS("DocumentTest01.xml");

    NodeList nodeList = document.getElementsByTagNameNS("http://www.w3.org/TR/REC-html40", "body");
    NodeList childList = nodeList.item(0).getChildNodes();
    Element child = (Element) childList.item(1);
    Element elem = document.createElementNS("urn:BooksAreUs.org:BookInfonew", "newElement");
    assertNotNull(child.appendChild(elem));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:11,代码来源:DocumentTest.java

示例10: main

import org.w3c.dom.Document; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    dbf.setNamespaceAware(true);
    dbf.setValidating(false);
    dbf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, Boolean.TRUE);
    Document doc = dbf.newDocumentBuilder().parse(new File(SIGNATURE));
    NodeList nl = doc.getElementsByTagNameNS(XMLSignature.XMLNS,
            "Signature");
    if (nl.getLength() == 0) {
        throw new RuntimeException("Couldn't find 'Signature' element");
    }
    Element element = (Element) nl.item(0);

    byte[] keyBytes = Base64.getDecoder().decode(validationKey);
    X509EncodedKeySpec spec = new X509EncodedKeySpec(keyBytes);
    KeyFactory kf = KeyFactory.getInstance("RSA");
    PublicKey key = kf.generatePublic(spec);
    KeySelector ks = KeySelector.singletonKeySelector(key);

    DOMValidateContext vc = new DOMValidateContext(ks, element);

    // disable secure validation mode
    vc.setProperty("org.jcp.xml.dsig.secureValidation", Boolean.FALSE);

    // set a dummy dereferencer to be able to get content by references
    vc.setURIDereferencer(dereferencer);

    XMLSignatureFactory factory = XMLSignatureFactory.getInstance();
    XMLSignature signature = factory.unmarshalXMLSignature(vc);

    // run validation
    signature.validate(vc);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:34,代码来源:ErrorHandlerPermissions.java

示例11: loadWSDL

import org.w3c.dom.Document; //导入方法依赖的package包/类
/**
 * Parses a set of schemas inside a WSDL file.
 *
 * A WSDL file may contain multiple &lt;xsd:schema> elements.
 */
private XSSchemaSet loadWSDL()
    throws SAXException {


    // build DOMForest just like we handle XML Schema
    DOMForest forest = buildDOMForest( new XMLSchemaInternalizationLogic() );

    DOMForestScanner scanner = new DOMForestScanner(forest);

    XSOMParser xsomParser = createXSOMParser( forest );

    // find <xsd:schema>s and parse them individually
    for( InputSource grammar : opt.getGrammars() ) {
        Document wsdlDom = forest.get( grammar.getSystemId() );
        if (wsdlDom == null) {
            String systemId = Options.normalizeSystemId(grammar.getSystemId());
            if (forest.get(systemId) != null) {
                grammar.setSystemId(systemId);
                wsdlDom = forest.get( grammar.getSystemId() );
            }
        }

        NodeList schemas = wsdlDom.getElementsByTagNameNS(XMLConstants.W3C_XML_SCHEMA_NS_URI,"schema");
        for( int i=0; i<schemas.getLength(); i++ )
            scanner.scan( (Element)schemas.item(i), xsomParser.getParserHandler() );
    }
    return xsomParser.getResult();
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:34,代码来源:ModelLoader.java

示例12: validate

import org.w3c.dom.Document; //导入方法依赖的package包/类
private static void validate(String data, boolean pass) throws Exception {
    System.out.println("Validating " + data);
    File file = new File(DIR, data);

    Document doc = dbf.newDocumentBuilder().parse(file);
    NodeList nl =
        doc.getElementsByTagNameNS(Constants.SignatureSpecNS, "Signature");
    if (nl.getLength() == 0) {
        throw new Exception("Couldn't find signature Element");
    }
    Element sigElement = (Element) nl.item(0);
    XMLSignature signature = new XMLSignature
        (sigElement, file.toURI().toString());
    SecretKey sk = signature.createSecretKey("secret".getBytes("ASCII"));
    try {
        System.out.println
            ("Validation status: " + signature.checkSignatureValue(sk));
        if (!pass) {
            System.out.println("FAILED");
            atLeastOneFailed = true;
        } else {
            System.out.println("PASSED");
        }
    } catch (XMLSignatureException xse) {
        System.out.println(xse.getMessage());
        if (!pass) {
            System.out.println("PASSED");
        } else {
            System.out.println("FAILED");
            atLeastOneFailed = true;
        }
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:34,代码来源:TruncateHMAC.java

示例13: validate

import org.w3c.dom.Document; //导入方法依赖的package包/类
boolean validate(String fn, KeySelector ks, URIDereferencer ud,
    boolean cache) throws Exception {

    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    dbf.setNamespaceAware(true);
    dbf.setValidating(false);
    Document doc = dbf.newDocumentBuilder().parse(new File(dir, fn));
    NodeList nl =
        doc.getElementsByTagNameNS(XMLSignature.XMLNS, "Signature");
    if (nl.getLength() == 0) {
        throw new Exception("Couldn't find signature Element");
    }
    Element sigElement = (Element) nl.item(0);
    DOMValidateContext vc = new DOMValidateContext(ks, sigElement);
    vc.setBaseURI(dir.toURI().toString());
    if (cache) {
        vc.setProperty("javax.xml.crypto.dsig.cacheReference", Boolean.TRUE);
    }
    XMLSignatureFactory factory = XMLSignatureFactory.getInstance();
    XMLSignature signature = factory.unmarshalXMLSignature(vc);
    if (ud != null) {
        vc.setURIDereferencer(ud);
    }
    boolean coreValidity = signature.validate(vc);

    // Check reference cache
    if (cache) {
        Iterator i = signature.getSignedInfo().getReferences().iterator();
        for (int j=0; i.hasNext(); j++) {
            Reference ref = (Reference) i.next();
            if (!digestInputEqual(ref)) {
                throw new Exception
                    ("cached data for Reference[" + j + "] is not correct");
            }
            // check that dereferenced data does not contain comment nodes
            if (ref.getURI() == "") {
                System.out.println("checking deref data");
                NodeSetData data = (NodeSetData) ref.getDereferencedData();
                Iterator ni = data.iterator();
                while (ni.hasNext()) {
                    Node n = (Node) ni.next();
                    if (n.getNodeType() == Node.COMMENT_NODE) {
                        throw new Exception("dereferenced data for " +
                            " Reference[" + j + " contains comment node");
                    }
                }
            }
        }
    }
    return coreValidity;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:52,代码来源:SignatureValidator.java

示例14: testGetElementsByTagNameNS

import org.w3c.dom.Document; //导入方法依赖的package包/类
@Test(dataProvider = "elementName")
public void testGetElementsByTagNameNS(String localName, int number) throws Exception {
    Document document = createDOMWithNS("DocumentTest01.xml");
    NodeList nodeList = document.getElementsByTagNameNS("urn:BooksAreUs.org:BookInfo", localName);
    assertEquals(nodeList.getLength(), number);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:7,代码来源:DocumentTest.java

示例15: createDocumentMap

import org.w3c.dom.Document; //导入方法依赖的package包/类
private Map<String,String> createDocumentMap(MetadataFinder forest, File baseDir, final String rootWsdl, Set<String> externalReferences) {
    Map<String,String> map = new HashMap<String,String>();
    String rootWsdlFileName = rootWsdl;
    String rootWsdlName;

    int slashIndex = rootWsdl.lastIndexOf("/");
    if( slashIndex >= 0) {
        rootWsdlFileName = rootWsdl.substring(slashIndex+1);
    }
    if(!rootWsdlFileName.endsWith(WSDL_FILE_EXTENSION)) {
        Document rootWsdlDoc =  forest.get(rootWsdl);
        NodeList serviceNodes = rootWsdlDoc.getElementsByTagNameNS(WSDLConstants.QNAME_SERVICE.getNamespaceURI(),WSDLConstants.QNAME_SERVICE.getLocalPart());
        if (serviceNodes.getLength() == 0) {
            rootWsdlName = "Service";
        } else {
            Node serviceNode = serviceNodes.item(0);
            String serviceName = ((Element)serviceNode).getAttribute( WSDLConstants.ATTR_NAME);
            rootWsdlName = serviceName;
        }
        rootWsdlFileName = rootWsdlName+ WSDL_FILE_EXTENSION;
    } else {
        rootWsdlName = rootWsdlFileName.substring(0,rootWsdlFileName.length()-5);
    }

    map.put(rootWsdl,sanitize(rootWsdlFileName));

    int i =1;
    for(String ref: externalReferences) {
        Document refDoc =  forest.get(ref);
        Element rootEl = refDoc.getDocumentElement();
        String fileExtn;
        String fileName = null;
        int index = ref.lastIndexOf("/");
        if (index >= 0) {
            fileName = ref.substring(index + 1);
        }
        if(rootEl.getLocalName().equals(WSDLConstants.QNAME_DEFINITIONS.getLocalPart()) && rootEl.getNamespaceURI().equals(WSDLConstants.NS_WSDL)) {
          fileExtn = WSDL_FILE_EXTENSION;
        } else if(rootEl.getLocalName().equals(WSDLConstants.QNAME_SCHEMA.getLocalPart()) && rootEl.getNamespaceURI().equals(WSDLConstants.NS_XMLNS)) {
          fileExtn = SCHEMA_FILE_EXTENSION;
        } else {
            fileExtn = ".xml";
        }
        if(fileName != null && (fileName.endsWith(WSDL_FILE_EXTENSION) || fileName.endsWith(SCHEMA_FILE_EXTENSION))) {
            map.put(ref, rootWsdlName+"_"+fileName);
        } else {
            map.put(ref, rootWsdlName+"_metadata"+ (i++) + fileExtn);
        }
    }
    return map;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:52,代码来源:WSDLFetcher.java


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