Examples of 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
  • net.sf.toxicity.util.NamespaceContext
    @author Stefan Podkowinski
  • org.apache.commons.jxpath.ri.axes.NamespaceContext
    EvalContext that walks the "namespace::" axis. @author Dmitri Plotnikov @version $Revision: 1.7 $ $Date: 2003/03/11 00:59:20 $
  • org.apache.ws.util.xml.NamespaceContext
    Interface for read only XML Namespace context processing. @author Ian Springer (ian DOT springer AT hp DOT com)
  • org.apache.xerces.xni.NamespaceContext
    Represents an interface to query namespace information. @author Andy Clark, IBM @version $Id: NamespaceContext.java,v 1.3 2001/12/12 22:33:47 elena Exp $
  • org.apache.xmlbeans.impl.values.NamespaceContext
  • org.custommonkey.xmlunit.NamespaceContext
    Interface used by XpathEngine in order to map prefixes to namespace URIs.

    This is modelled after javax.xml.namespace.NamespaceContext but reduced to our needs.

  • org.jaxen.NamespaceContext
    Resolves namespace prefixes to namespace URIs.

    The prefixes used within an XPath expression are independant of those used within any target document. When evaluating an XPath against a document, only the resolved namespace URIs are compared, not their prefixes.

    A NamespaceContext is responsible for translating prefixes as they appear in XPath expressions into URIs for comparison. A document's prefixes are resolved internal to the document based upon its own namespace nodes.

    @see BaseXPath @see Navigator#getElementNamespaceUri @see Navigator#getAttributeNamespaceUri @author bob mcwhirter
  • org.wso2.carbon.humantask.utils.NamespaceContext

  • Examples of javax.xml.namespace.NamespaceContext

        public static String getUniquePrefix(XMLStreamWriter writer, String namespaceURI)
            throws XMLStreamException {
            return getUniquePrefix(writer, namespaceURI, false);
        }
        public static String getUniquePrefix(XMLStreamWriter writer) {
            NamespaceContext nc = writer.getNamespaceContext();
            if (nc == null) {
                return DEF_PREFIXES[0];
            }
            for (String t : DEF_PREFIXES) {
                String uri = nc.getNamespaceURI(t);
                if (StringUtils.isEmpty(uri)) {
                    return t;
                }
            }

            int n = 10;
            while (true) {
                String nsPrefix = "ns" + n;
                String uri = nc.getNamespaceURI(nsPrefix);
                if (StringUtils.isEmpty(uri)) {
                    return nsPrefix;
                }
                n++;
            }
    View Full Code Here

    Examples of javax.xml.namespace.NamespaceContext

                super(reader);
            }
           
            @Override
            public NamespaceContext getNamespaceContext() {
                final NamespaceContext ctx = super.getNamespaceContext();
                return new NamespaceContext() {
                    public String getNamespaceURI(String prefix) {
                        String ns = ctx.getNamespaceURI(prefix);
                        if (namespace.equals(ns)) {
                            ns = jaxbNamespace;
                        }                       
                        return ns;
                    }

                    public String getPrefix(String namespaceURI) {
                        if (jaxbNamespace.equals(namespaceURI)) {
                            return ctx.getPrefix(namespace);
                        }
                        return ctx.getPrefix(namespaceURI);
                    }

                    @SuppressWarnings("rawtypes")
                    public Iterator getPrefixes(String namespaceURI) {
                        if (jaxbNamespace.equals(namespaceURI)) {
                            return ctx.getPrefixes(namespace);
                        }
                        return ctx.getPrefixes(namespaceURI);
                    }
                };
            }
    View Full Code Here

    Examples of javax.xml.namespace.NamespaceContext

        }

        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

    Examples of javax.xml.namespace.NamespaceContext

        public DataHandler getDataHandler(String blobcid) {
            return ((OMXMLStreamReader)getParent()).getDataHandler(blobcid);
        }

        public NamespaceContext getNamespaceContext() {
            NamespaceContext namespaceContext = super.getNamespaceContext();
            if (namespaceContextWrapper == null || namespaceContextWrapper.getParent() != namespaceContext) {
                namespaceContextWrapper = new NamespaceURIInterningNamespaceContextWrapper(namespaceContext);
            }
            return namespaceContextWrapper;
        }
    View Full Code Here

    Examples of javax.xml.namespace.NamespaceContext

            for (int i=0; i<reader.getNamespaceCount(); i++) {
                assertInterned(reader.getNamespaceURI(i));
            }
            reader.nextTag();
            assertInterned(reader.getNamespaceURI("p"));
            NamespaceContext nc = reader.getNamespaceContext();
            assertInterned(nc.getNamespaceURI("p"));
        }
    View Full Code Here

    Examples of javax.xml.namespace.NamespaceContext

                }
               
                // It is possible that the namespace is associated with multiple prefixes,
                // So try getting the namespace as a second step.
                if (writerPrefix != null) {
                    NamespaceContext nsContext = writer.getNamespaceContext();
                    if(nsContext != null) {
                        String writerNS = nsContext.getNamespaceURI(prefix);
                        return namespace.equals(writerNS);
                    }
                }
                return false;
            } else {
                // UNQUALIFIED NAMESPACE
               
                // Neither XML 1.0 nor XML 1.1 allow to associate a prefix with an unqualified name (see also AXIOM-372).
                if (prefix.length() > 0) {
                    throw new OMException("Invalid namespace declaration: Prefixed namespace bindings may not be empty.")
                }
               
                // Get the namespace associated with the prefix.
                // It is illegal to call getPrefix with null, but the specification is not
                // clear on what happens if called with "".  So the following code is
                // protected
                try {
                    String writerPrefix = writer.getPrefix("");
                    if (writerPrefix != null && writerPrefix.length() == 0) {
                        return true;
                    }
                } catch (Throwable t) {
                    if (log.isDebugEnabled()) {
                        log.debug("Caught exception from getPrefix(\"\"). Processing continues: " + t);
                    }
                }
               
               
               
                // Fallback to using the namespace context
                NamespaceContext nsContext = writer.getNamespaceContext();
                if (nsContext != null) {
                    String writerNS = nsContext.getNamespaceURI("");
                    if (writerNS != null && writerNS.length() > 0) {
                        return false;
                    }
                }
                return true;
    View Full Code Here

    Examples of javax.xml.namespace.NamespaceContext

    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

    Examples of javax.xml.namespace.NamespaceContext

        }
       
        @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

    Examples of javax.xml.namespace.NamespaceContext

            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

    Examples of javax.xml.namespace.NamespaceContext

        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
    TOP
    Copyright © 2018 www.massapi.com. 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.