1 17 package com.sun.org.apache.xml.internal.security.utils.resolver.implementations; 18 19 20 21 import java.io.FileInputStream ; 22 23 import com.sun.org.apache.xml.internal.utils.URI; 24 import com.sun.org.apache.xml.internal.security.signature.XMLSignatureInput; 25 import com.sun.org.apache.xml.internal.security.utils.resolver.ResourceResolverException; 26 import com.sun.org.apache.xml.internal.security.utils.resolver.ResourceResolverSpi; 27 import org.w3c.dom.Attr ; 28 29 30 35 public class ResolverLocalFilesystem extends ResourceResolverSpi { 36 37 38 static java.util.logging.Logger log = 39 java.util.logging.Logger.getLogger( 40 ResolverLocalFilesystem.class.getName()); 41 42 45 public XMLSignatureInput engineResolve(Attr uri, String BaseURI) 46 throws ResourceResolverException { 47 48 try { 49 URI uriNew = new URI(new URI(BaseURI), uri.getNodeValue()); 50 51 URI uriNewNoFrag = new URI(uriNew); 53 54 uriNewNoFrag.setFragment(null); 55 56 String fileName = 57 ResolverLocalFilesystem 58 .translateUriToFilename(uriNewNoFrag.toString()); 59 FileInputStream inputStream = new FileInputStream (fileName); 60 XMLSignatureInput result = new XMLSignatureInput(inputStream); 61 62 result.setSourceURI(uriNew.toString()); 63 64 return result; 65 } catch (Exception e) { 66 throw new ResourceResolverException("generic.EmptyMessage", e, uri, 67 BaseURI); 68 } 69 } 70 71 77 private static String translateUriToFilename(String uri) { 78 79 String subStr = uri.substring("file:/".length()); 80 81 if (subStr.indexOf("%20") > -1) 82 { 83 int offset = 0; 84 int index = 0; 85 StringBuffer temp = new StringBuffer (subStr.length()); 86 do 87 { 88 index = subStr.indexOf("%20",offset); 89 if (index == -1) temp.append(subStr.substring(offset)); 90 else 91 { 92 temp.append(subStr.substring(offset,index)); 93 temp.append(' '); 94 offset = index+3; 95 } 96 } 97 while(index != -1); 98 subStr = temp.toString(); 99 } 100 101 if (subStr.charAt(1) == ':') { 102 return subStr; 104 } 105 return "/" + subStr; 107 } 108 109 112 public boolean engineCanResolve(Attr uri, String BaseURI) { 113 114 if (uri == null) { 115 return false; 116 } 117 118 String uriNodeValue = uri.getNodeValue(); 119 120 if (uriNodeValue.equals("") || (uriNodeValue.charAt(0)=='#')) { 121 return false; 122 } 123 124 try { 125 if (true) 127 if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "I was asked whether I can resolve " + uriNodeValue); 128 129 if ( uriNodeValue.startsWith("file:") || 130 BaseURI.startsWith("file:")) { 131 if (true) 132 if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "I state that I can resolve " + uriNodeValue); 133 134 return true; 135 } 136 } catch (Exception e) {} 137 138 if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "But I can't"); 139 140 return false; 141 } 142 } 143 | Popular Tags |