ResolverXPointerpublic 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). |
Fields Summary |
---|
static Logger | log{@link java.util.logging} logging facility | private static final String | XP | private static final int | XP_LENGTH |
Methods Summary |
---|
public boolean | engineCanResolve(org.w3c.dom.Attr uri, java.lang.String BaseURI)
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.XMLSignatureInput | engineResolve(org.w3c.dom.Attr uri, java.lang.String BaseURI)
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.String | getXPointerId(java.lang.String uri)Method getXPointerId
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 boolean | isXPointerId(java.lang.String uri)Method isXPointerId
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 boolean | isXPointerSlash(java.lang.String uri)Method isXPointerSlash
if (uri.equals("#xpointer(/)")) {
return true;
}
return false;
|
|