String mapping = parts[i].substring(XNS_OPEN.length(),parts[i].length()-1);
int pos = mapping.indexOf('=');
if (pos <= 0 || pos >= mapping.length()-1)
throw new ResourceResolverException("malformed namespace part of XPointer expression",uri,BaseURI);
nsContext.addExtraPrefix(mapping.substring(0,pos),
mapping.substring(pos+1));
}
}
try
{
Node node = null;
NodeList nodes=null;
// plain ID reference.
if (i==0 && !parts[i].startsWith(XP_OPEN))
{
node = this.baseNode.getOwnerDocument().getElementById(parts[i]);
}
else
{
if (!parts[i].endsWith(")") || !parts[i].startsWith(XP_OPEN))
return null;
String xpathExpr = parts[i].substring(XP_OPEN.length(),parts[i].length()-1);
XObject xo;
if (nsContext != null)
xo = XPathAPI.eval(this.baseNode, xpathExpr,nsContext);
else
xo = XPathAPI.eval(this.baseNode, xpathExpr);
if (!(xo instanceof NodeSequence)) return null;
nodes = ((NodeSequence)xo).nodelist();
if (nodes.getLength() == 0) return null;
if (nodes.getLength() == 1)
node = nodes.item(0);
}
XMLSignatureInput result = null;
if (node != null)
{
result = new XMLSignatureInput(node);
}
else if (nodes !=null)
{
Set nodeSet = new HashSet(nodes.getLength());
for (int j=0 ; j<nodes.getLength(); ++j)
{
nodeSet.add(nodes.item(j));
}
result = new XMLSignatureInput(nodeSet);
}
else
return null;
result.setMIMEType("text/xml");
result.setExcludeComments(true);
result.setSourceURI((BaseURI != null) ? BaseURI.concat(v):v);
return result;
} catch (TransformerException e)
{
throw new ResourceResolverException("TransformerException inside XPointer expression",e,uri,BaseURI);
}
}