ResolverLocalFilesystempublic class ResolverLocalFilesystem extends ResourceResolverSpi A simple ResourceResolver for requests into the local filesystem. |
Fields Summary |
---|
static Logger | log{@link java.util.logging} logging facility |
Methods Summary |
---|
public boolean | engineCanResolve(org.w3c.dom.Attr uri, java.lang.String BaseURI)
if (uri == null) {
return false;
}
String uriNodeValue = uri.getNodeValue();
if (uriNodeValue.equals("") || (uriNodeValue.charAt(0)=='#")) {
return false;
}
try {
//URI uriNew = new URI(new URI(BaseURI), uri.getNodeValue());
if (true)
if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "I was asked whether I can resolve " + uriNodeValue/*uriNew.toString()*/);
if ( uriNodeValue.startsWith("file:") ||
BaseURI.startsWith("file:")/*uriNew.getScheme().equals("file")*/) {
if (true)
if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "I state that I can resolve " + uriNodeValue/*uriNew.toString()*/);
return true;
}
} catch (Exception e) {}
if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "But I can't");
return false;
| public com.sun.org.apache.xml.internal.security.signature.XMLSignatureInput | engineResolve(org.w3c.dom.Attr uri, java.lang.String BaseURI)
try {
URI uriNew = new URI(new URI(BaseURI), uri.getNodeValue());
// if the URI contains a fragment, ignore it
URI uriNewNoFrag = new URI(uriNew);
uriNewNoFrag.setFragment(null);
String fileName =
ResolverLocalFilesystem
.translateUriToFilename(uriNewNoFrag.toString());
FileInputStream inputStream = new FileInputStream(fileName);
XMLSignatureInput result = new XMLSignatureInput(inputStream);
result.setSourceURI(uriNew.toString());
return result;
} catch (Exception e) {
throw new ResourceResolverException("generic.EmptyMessage", e, uri,
BaseURI);
}
| private static java.lang.String | translateUriToFilename(java.lang.String uri)Method translateUriToFilename
String subStr = uri.substring("file:/".length());
if (subStr.indexOf("%20") > -1)
{
int offset = 0;
int index = 0;
StringBuffer temp = new StringBuffer(subStr.length());
do
{
index = subStr.indexOf("%20",offset);
if (index == -1) temp.append(subStr.substring(offset));
else
{
temp.append(subStr.substring(offset,index));
temp.append(' ");
offset = index+3;
}
}
while(index != -1);
subStr = temp.toString();
}
if (subStr.charAt(1) == ':") {
// we're running M$ Windows, so this works fine
return subStr;
}
// we're running some UNIX, so we have to prepend a slash
return "/" + subStr;
|
|