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

ResolverLocalFilesystem

public class ResolverLocalFilesystem extends ResourceResolverSpi
A simple ResourceResolver for requests into the local filesystem.
author
$Author: raul $

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

inheritDoc


      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.XMLSignatureInputengineResolve(org.w3c.dom.Attr uri, java.lang.String BaseURI)

inheritDoc


        
        
             

     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.StringtranslateUriToFilename(java.lang.String uri)
Method translateUriToFilename

param
uri
return
the string of the filename


      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;