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

            }
        }
       
        @Override
        public NamespaceContext getNamespaceContext() {
            return new NamespaceContext() {

                public String getNamespaceURI(String prefix) {
                    for (Map.Entry<String, String> entry : namespaceMap.entrySet()) {
                        if (entry.getValue().equals(prefix)) {
                            return entry.getKey();
View Full Code Here


        policySet.setAppliesTo(appliesTo);

        if (appliesTo != null) {
            try {
                XPath path = xpathHelper.newXPath();
                NamespaceContext nsContext = xpathHelper.getNamespaceContext(appliesTo, reader.getNamespaceContext());
                // path.setXPathFunctionResolver(new PolicyXPathFunctionResolver(context));
                XPathExpression expression = xpathHelper.compile(path, nsContext, appliesTo);
                policySet.setAppliesToXPathExpression(expression);
            } catch (XPathExpressionException e) {
                ContributionReadException ce = new ContributionReadException(e);
                error(monitor, "ContributionReadException", policySet, ce);
                //throw ce;
            }
        }

        String attachTo = reader.getAttributeValue(null, ATTACH_TO);
        if (attachTo != null) {
            try {
                XPath path = xpathHelper.newXPath();
                NamespaceContext nsContext = xpathHelper.getNamespaceContext(attachTo, reader.getNamespaceContext());
                path.setXPathFunctionResolver(new PolicyXPathFunctionResolver(nsContext));               
                                          
                attachTo = PolicyXPathFunction.normalize(attachTo,getSCAPrefix(nsContext));
                XPathExpression expression = xpathHelper.compile(path, nsContext, attachTo);
                policySet.setAttachTo(attachTo);
View Full Code Here

    protected XPathExpression getXPath(String expression) throws XPathExpressionException {
        XPathFactory xPathFactory = XPathFactory.newInstance();
        XPath xPath = xPathFactory.newXPath();
        xPath.setNamespaceContext(
                new NamespaceContext() {
                    @Override
                    public String getNamespaceURI(String prefix) {
                        if (WSSConstants.PREFIX_DSIG.equals(prefix)) {
                            return WSSConstants.NS_DSIG;
                        } else if (WSSConstants.PREFIX_SOAPENV.equals(prefix)) {
View Full Code Here

    SAXResult saxResult = new SAXResult(handler);
    transformer.transform(domSource, saxResult);

    OMElement root = result.getOMDocumentElement();
    assertEquals(2, getNamespaceCount(root));
    NamespaceContext namespaceContext = root.getNamespaceContext(false);
    assertEquals("http://www.springframework.org/spring-ws", namespaceContext.getNamespaceURI(XMLConstants.DEFAULT_NS_PREFIX));
    assertEquals("http://www.springframework.org/spring-ws/attr",
        namespaceContext.getNamespaceURI("attr"));

    OMElement child = root.getFirstElement();
    assertEquals(1, getNamespaceCount(child));
    namespaceContext = child.getNamespaceContext(false);
    assertEquals("http://www.springframework.org/spring-ws", namespaceContext.getNamespaceURI(XMLConstants.DEFAULT_NS_PREFIX));
    assertEquals("http://www.springframework.org/spring-ws/child", namespaceContext.getNamespaceURI("prefix"));
  }
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.
    protected 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 XPath getCruxPagesXPath()
  {
    XPathFactory factory = XPathFactory.newInstance();
    XPath findPath = factory.newXPath();
    findPath.setNamespaceContext(new NamespaceContext()
    {
      public String getNamespaceURI(String prefix)
      {
        if (prefix.equals("c"))
        {
View Full Code Here

   */
  public static XPath getHtmlXPath()
  {
    XPathFactory factory = XPathFactory.newInstance();
    XPath htmlPath = factory.newXPath();
    htmlPath.setNamespaceContext(new NamespaceContext()
    {
      public String getNamespaceURI(String prefix)
      {
        return "http://www.w3.org/1999/xhtml";
      }
View Full Code Here

   */
  public TemplateParser()
  {
    XPathFactory factory = XPathFactory.newInstance();
    XPath findTemplates = factory.newXPath();
    findTemplates.setNamespaceContext(new NamespaceContext()
    {
      public String getNamespaceURI(String prefix)
      {
        return "http://www.cruxframework.org/templates";
      }
View Full Code Here

      final String ns = "http://jboss.org/test/simple/bindings";
      String local = "test1";
      final String prefix = "p1";
      QName qName = new QName(ns, local, prefix);

      NamespaceContext nsCtx = new NamespaceContext()
      {
         public String getNamespaceURI(String p)
         {
            if(!prefix.equals(p))
            {
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.