1 17 package com.sun.org.apache.xml.internal.security.utils.resolver.implementations; 18 19 20 21 import com.sun.org.apache.xml.internal.security.signature.XMLSignatureInput; 22 import com.sun.org.apache.xml.internal.security.utils.IdResolver; 23 import com.sun.org.apache.xml.internal.security.utils.resolver.ResourceResolverException; 24 import com.sun.org.apache.xml.internal.security.utils.resolver.ResourceResolverSpi; 25 import org.w3c.dom.Attr ; 26 import org.w3c.dom.Document ; 27 import org.w3c.dom.Node ; 28 29 30 38 public class ResolverFragment extends ResourceResolverSpi { 39 40 41 static java.util.logging.Logger log = 42 java.util.logging.Logger.getLogger( 43 ResolverFragment.class.getName()); 44 45 55 public XMLSignatureInput engineResolve(Attr uri, String BaseURI) 56 throws ResourceResolverException 57 { 58 59 String uriNodeValue = uri.getNodeValue(); 60 Document doc = uri.getOwnerElement().getOwnerDocument(); 61 62 63 Node selectedElem = null; 64 if (uriNodeValue.equals("")) { 65 66 70 71 if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "ResolverFragment with empty URI (means complete document)"); 72 selectedElem = doc; 73 } else { 74 75 83 String id = uriNodeValue.substring(1); 84 85 selectedElem = IdResolver.getElementById(doc, id); 87 if (selectedElem==null) { 88 Object exArgs[] = { id }; 89 throw new ResourceResolverException( 90 "signature.Verification.MissingID", exArgs, uri, BaseURI); 91 } 92 if (true) 93 if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "Try to catch an Element with ID " + id + " and Element was " + selectedElem); 94 } 95 96 XMLSignatureInput result = new XMLSignatureInput(selectedElem); 97 result.setExcludeComments(true); 98 99 result.setMIMEType("text/xml"); 101 result.setSourceURI((BaseURI != null) ? BaseURI.concat(uri.getNodeValue()) : 102 uri.getNodeValue()); 103 return result; 104 } 105 106 113 public boolean engineCanResolve(Attr uri, String BaseURI) { 114 115 if (uri == null) { 116 if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "Quick fail for null uri"); 117 return false; 118 } 119 120 String uriNodeValue = uri.getNodeValue(); 121 122 if (uriNodeValue.equals("") 123 || ((uriNodeValue.charAt(0)=='#') 124 &&!uriNodeValue.startsWith("#xpointer("))) { 125 if (true) 126 if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "State I can resolve reference: \"" + uriNodeValue + "\""); 127 return true; 128 } 129 if (true) 130 if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "Do not seem to be able to resolve reference: \"" + uriNodeValue + "\""); 131 return false; 132 } 133 134 } 135 | Popular Tags |