Package javax.xml.namespace

Examples of javax.xml.namespace.NamespaceContext

All get*(*) methods operate in the current scope for Namespace URI and prefix resolution.

Note that a Namespace URI can be bound to multiple prefixes in the current scope. This can occur when multiple XMLConstants.XMLNS_ATTRIBUTE ("xmlns") Namespace declarations occur in the same Start-Tag and refer to the same Namespace URI. e.g.

 <element xmlns:prefix1="http://Namespace-name-URI" xmlns:prefix2="http://Namespace-name-URI"> 

This can also occur when the same Namespace URI is used in multiple XMLConstants.XMLNS_ATTRIBUTE ("xmlns") Namespace declarations in the logical parent element hierarchy. e.g.
 <parent xmlns:prefix1="http://Namespace-name-URI"> <child xmlns:prefix2="http://Namespace-name-URI"> ... </child> </parent> 

A prefix can only be bound to a single Namespace URI in the current scope.

@author JAXP Java Community Process @author JAXP Reference Implementation @version 1.0.proposed @see javax.xml.XMLConstants declarations of common XML values @see Namespaces in XML @see Namespaces in XML Errata @see XML Schema Part2: Datatypes

public class NamespaceUtilsTest {

    @Test
    public void getNamespaceContextMethod() throws NoSuchMethodException {
        Method method = getClass().getMethod("method");
        NamespaceContext namespaceContext = NamespaceUtils.getNamespaceContext(method);
        assertEquals("method1", namespaceContext.getNamespaceURI("prefix1"));
        assertEquals("method2", namespaceContext.getNamespaceURI(XMLConstants.DEFAULT_NS_PREFIX));

    }
View Full Code Here


    }
   
    @Test
    public void getNamespaceContextClass() throws NoSuchMethodException {
        Method method = getClass().getMethod("getNamespaceContextClass");
        NamespaceContext namespaceContext = NamespaceUtils.getNamespaceContext(method);
        assertEquals("class1", namespaceContext.getNamespaceURI("prefix1"));
        assertEquals("class2", namespaceContext.getNamespaceURI(XMLConstants.DEFAULT_NS_PREFIX));

    }
View Full Code Here

        Message mess = getMessage(mock);
        InputStream body = mess.getBody(InputStream.class);
        assertNotNull(body);
        XPathFactory xpathFactory = XPathFactory.newInstance();
        XPath xpath = xpathFactory.newXPath();
        NamespaceContext nc = new NamespaceContext() {

            @SuppressWarnings("rawtypes")
            @Override
            public Iterator getPrefixes(String namespaceURI) {
                return null;
View Full Code Here

    public static Map<String, String> getScrProperties(String xmlLocation, String componentName) throws Exception {
        Map<String, String> result = new HashMap<String, String>();
        final Document dom = readXML(new File(xmlLocation));
        final XPath xPath = XPathFactory.newInstance(XPathFactory.DEFAULT_OBJECT_MODEL_URI, "com.sun.org.apache.xpath.internal.jaxp.XPathFactoryImpl", null).newXPath();
        xPath.setNamespaceContext(new NamespaceContext() {
            @Override
            public String getNamespaceURI(String prefix) {
                switch (prefix) {
                    case "scr":
                        try {
View Full Code Here

        fel.getContext().set("$page_content", validXml);
        Document doc = builder.parse(new ByteArrayInputStream(validXml.getBytes()));
        XPathFactory xfactory = XPathFactoryImpl.newInstance();
        XPath xpathParser = xfactory.newXPath();
        //设置命名空间
        xpathParser.setNamespaceContext(new NamespaceContext() {
            public String getPrefix(String uri) {
                throw new UnsupportedOperationException();
            }
            public Iterator<?> getPrefixes(String uri) {
                throw new UnsupportedOperationException();
View Full Code Here

        final String expectedDigestAlgorithm = binding.getAlgorithmSuite().getDigest();
        final String expectedCanonAlgorithm  = binding.getAlgorithmSuite().getInclusiveC14n();
           
        XPathFactory factory = XPathFactory.newInstance();
        XPath xpath = factory.newXPath();
        final NamespaceContext nsContext = this.getNamespaceContext();
        xpath.setNamespaceContext(nsContext);
       
        // Signature Algorithm
        final XPathExpression sigAlgoExpr =
            xpath.compile("/s:Envelope/s:Header/wsse:Security/ds:Signature/ds:SignedInfo"
View Full Code Here

    // TODO: This method can be removed when runOutInterceptorAndValidateSamlTokenAttached
    // is cleaned up.
    private void verifySignatureCoversAssertion(Document signedDoc, String assertionId) throws Exception {
        XPathFactory factory = XPathFactory.newInstance();
        XPath xpath = factory.newXPath();
        final NamespaceContext nsContext = this.getNamespaceContext();
        xpath.setNamespaceContext(nsContext);
       
        // Find the SecurityTokenReference for the assertion
        final XPathExpression strExpr = xpath.compile(
            "/s:Envelope/s:Header/wsse:Security/wsse:SecurityTokenReference/wsse:KeyIdentifier");
       
        final NodeList strKeyIdNodes =
            (NodeList) strExpr.evaluate(signedDoc, XPathConstants.NODESET);
       
        String strId = null;
        for (int i = 0; i < strKeyIdNodes.getLength(); i++) {
            Node keyIdNode = (Node) strKeyIdNodes.item(i);
            String strKey = keyIdNode.getTextContent();
            if (strKey.equals(assertionId)) {
                Node strNode = (Node) keyIdNode.getParentNode();
                strId = strNode.getAttributes().
                    getNamedItemNS(nsContext.getNamespaceURI("wsu"), "Id").getNodeValue();
                break;
            }
        }
        assertNotNull("SecurityTokenReference for " + assertionId + " not found in security header.", strId);
       
View Full Code Here

    }

    public static String getUniquePrefix(XMLStreamWriter writer) {
        int n = 1;
       
        NamespaceContext nc = writer.getNamespaceContext();
        while (true) {
            String nsPrefix = "ns" + n;

            if (nc == null || nc.getNamespaceURI(nsPrefix) == null) {
                return nsPrefix;
            }

            n++;
        }
View Full Code Here

         */
        String xsiTypeQname = root.getAttributeValue(XmlConstants.XSI_NS, "type");
        if (xsiTypeQname != null) {
            Matcher m = QNAME_PATTERN.matcher(xsiTypeQname);
            if (m.matches()) {
                NamespaceContext nc = root.getNamespaceContext();
                this.xsiType = new QName(nc.getNamespaceURI(m.group(1)), m.group(2), m.group(1));
            } else {
                this.xsiType = new QName(this.namespace, xsiTypeQname, "");
            }
        }
    }
View Full Code Here

        if (prefix != null) {
            return null;
        } else {
           
            // Find an available prefix and bind it to the given uri
            NamespaceContext nsc = writer.getNamespaceContext();
            for (int i=1; ; i++) {
                prefix = "ns" + i;
                if (nsc.getNamespaceURI(prefix) == null) {
                    break;
                }
            }
            writer.setPrefix(prefix, uri);
            return prefix;
View Full Code Here

TOP

Related Classes of javax.xml.namespace.NamespaceContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.