FileDocCategorySizeDatePackage
ResolverXPointer.javaAPI DocJava SE 6 API5963Tue Jun 10 00:23:04 BST 2008com.sun.org.apache.xml.internal.security.utils.resolver.implementations

ResolverXPointer

public class ResolverXPointer extends ResourceResolverSpi
Handles barename XPointer Reference URIs.
To retain comments while selecting an element by an identifier ID, use the following full XPointer: URI='#xpointer(id('ID'))'.
To retain comments while selecting the entire document, use the following full XPointer: URI='#xpointer(/)'. This XPointer contains a simple XPath expression that includes the root node, which the second to last step above replaces with all nodes of the parse tree (all descendants, plus all attributes, plus all namespaces nodes).
author
$Author: dims $

Fields Summary
static Logger
log
{@link java.util.logging} logging facility
private static final String
XP
private static final int
XP_LENGTH
Constructors Summary
Methods Summary
public booleanengineCanResolve(org.w3c.dom.Attr uri, java.lang.String BaseURI)

inheritDoc


      if (uri == null) {
         return false;
      }
	  String uriStr =uri.getNodeValue();
      if (isXPointerSlash(uriStr) || isXPointerId(uriStr)) {
         return true;
      }

      return false;
   
public com.sun.org.apache.xml.internal.security.signature.XMLSignatureInputengineResolve(org.w3c.dom.Attr uri, java.lang.String BaseURI)

inheritDoc


        
        
             

      Node resultNode = null;
      Document doc = uri.getOwnerElement().getOwnerDocument();

      	String uriStr=uri.getNodeValue();
         if (isXPointerSlash(uriStr)) {
            resultNode = doc;
               
         } else if (isXPointerId(uriStr)) {
            String id = getXPointerId(uriStr);
            resultNode =IdResolver.getElementById(doc, id);

            // if (log.isLoggable(java.util.logging.Level.FINE))                                     log.log(java.util.logging.Level.FINE, "Use #xpointer(id('" + id + "')) on element " + selectedElem);

            if (resultNode == null) {
               Object exArgs[] = { id };

               throw new ResourceResolverException(
                  "signature.Verification.MissingID", exArgs, uri, BaseURI);
            }
            /*
            resultNodes =
               cXPathAPI
                  .selectNodeList(selectedElem, Canonicalizer
                     .XPATH_C14N_WITH_COMMENTS_SINGLE_NODE);*/
         }
      

      XMLSignatureInput result = new XMLSignatureInput(resultNode);

      result.setMIMEType("text/xml");
      if (BaseURI != null && BaseURI.length() > 0) {
	  result.setSourceURI(BaseURI.concat(uri.getNodeValue()));      
      } else {
	  result.setSourceURI(uri.getNodeValue());      
      }

      return result;
   
private static java.lang.StringgetXPointerId(java.lang.String uri)
Method getXPointerId

param
uri
return
xpointerId to search.



      if (uri.startsWith(XP)
              && uri.endsWith("))")) {
         String idPlusDelim = uri.substring(XP_LENGTH,uri.length()
                                                     - 2);
		 int idLen=idPlusDelim.length() -1;
         if (((idPlusDelim.charAt(0) == '"") && (idPlusDelim
                 .charAt(idLen) == '"")) || ((idPlusDelim
                 .charAt(0) == '\'") && (idPlusDelim
                 .charAt(idLen) == '\'"))) {
            return idPlusDelim.substring(1, idLen);
         }
      }

      return null;
   
private static booleanisXPointerId(java.lang.String uri)
Method isXPointerId

param
uri
return
it it has an xpointer id

                  
        
      

      if (uri.startsWith(XP)
              && uri.endsWith("))")) {
         String idPlusDelim = uri.substring(XP_LENGTH,
                                                     uri.length()
                                                     - 2);

         // if (log.isLoggable(java.util.logging.Level.FINE))                                     log.log(java.util.logging.Level.FINE, "idPlusDelim=" + idPlusDelim);
		 int idLen=idPlusDelim.length() -1;
         if (((idPlusDelim.charAt(0) == '"") && (idPlusDelim
                 .charAt(idLen) == '"")) || ((idPlusDelim
                 .charAt(0) == '\'") && (idPlusDelim
                 .charAt(idLen) == '\'"))) {
            if (true)
            	if (log.isLoggable(java.util.logging.Level.FINE))                                     log.log(java.util.logging.Level.FINE, "Id="
                      + idPlusDelim.substring(1, idLen));

            return true;
         }
      }

      return false;
   
private static booleanisXPointerSlash(java.lang.String uri)
Method isXPointerSlash

param
uri
return
true if begins with xpointer


      if (uri.equals("#xpointer(/)")) {
         return true;
      }

      return false;