org.jcp.xml.dsig.internal.dom.DOMURIDereferencer Maven / Gradle / Ivy
The newest version!
/* */ package org.jcp.xml.dsig.internal.dom;
/* */
/* */ import com.sun.org.apache.xml.internal.security.Init;
/* */ import com.sun.org.apache.xml.internal.security.signature.XMLSignatureInput;
/* */ import com.sun.org.apache.xml.internal.security.utils.IdResolver;
/* */ import com.sun.org.apache.xml.internal.security.utils.resolver.ResourceResolver;
/* */ import javax.xml.crypto.Data;
/* */ import javax.xml.crypto.URIDereferencer;
/* */ import javax.xml.crypto.URIReference;
/* */ import javax.xml.crypto.URIReferenceException;
/* */ import javax.xml.crypto.XMLCryptoContext;
/* */ import javax.xml.crypto.dom.DOMCryptoContext;
/* */ import javax.xml.crypto.dom.DOMURIReference;
/* */ import javax.xml.crypto.dsig.XMLSignContext;
/* */ import org.w3c.dom.Attr;
/* */ import org.w3c.dom.Element;
/* */ import org.w3c.dom.Node;
/* */
/* */ public class DOMURIDereferencer
/* */ implements URIDereferencer
/* */ {
/* 29 */ static final URIDereferencer INSTANCE = new DOMURIDereferencer();
/* */
/* */ private DOMURIDereferencer()
/* */ {
/* 34 */ Init.init();
/* */ }
/* */
/* */ public Data dereference(URIReference uriRef, XMLCryptoContext context)
/* */ throws URIReferenceException
/* */ {
/* 40 */ if (uriRef == null) {
/* 41 */ throw new NullPointerException("uriRef cannot be null");
/* */ }
/* 43 */ if (context == null) {
/* 44 */ throw new NullPointerException("context cannot be null");
/* */ }
/* */
/* 47 */ DOMURIReference domRef = (DOMURIReference)uriRef;
/* 48 */ Attr uriAttr = (Attr)domRef.getHere();
/* 49 */ String uri = uriRef.getURI();
/* 50 */ DOMCryptoContext dcc = (DOMCryptoContext)context;
/* */
/* 53 */ if ((uri != null) && (uri.length() != 0) && (uri.charAt(0) == '#')) {
/* 54 */ String id = uri.substring(1);
/* */
/* 56 */ if (id.startsWith("xpointer(id(")) {
/* 57 */ int i1 = id.indexOf('\'');
/* 58 */ int i2 = id.indexOf('\'', i1 + 1);
/* 59 */ id = id.substring(i1 + 1, i2);
/* */ }
/* */
/* 65 */ if ((context instanceof XMLSignContext)) {
/* 66 */ Node referencedElem = dcc.getElementById(id);
/* 67 */ if (referencedElem != null) {
/* 68 */ IdResolver.registerElementById((Element)referencedElem, id);
/* */ }
/* */ }
/* */ }
/* */ try
/* */ {
/* 74 */ String baseURI = context.getBaseURI();
/* 75 */ ResourceResolver apacheResolver = ResourceResolver.getInstance(uriAttr, baseURI);
/* */
/* 77 */ XMLSignatureInput in = apacheResolver.resolve(uriAttr, baseURI);
/* 78 */ if (in.isOctetStream()) {
/* 79 */ return new ApacheOctetStreamData(in);
/* */ }
/* 81 */ return new ApacheNodeSetData(in);
/* */ }
/* */ catch (Exception e) {
/* 84 */ throw new URIReferenceException(e);
/* */ }
/* */ }
/* */ }
/* Location: E:\HYN\Java\trunk\ref\lib-dep\xmldsig\xmldsig.jar
* Qualified Name: org.jcp.xml.dsig.internal.dom.DOMURIDereferencer
* JD-Core Version: 0.6.2
*/