1 4 7 package javax.xml.crypto.dom; 8 9 import javax.xml.crypto.KeySelector; 10 import javax.xml.crypto.URIDereferencer; 11 import javax.xml.crypto.XMLCryptoContext; 12 import java.util.Collections ; 13 import java.util.HashMap ; 14 import java.util.Iterator ; 15 import org.w3c.dom.Element ; 16 17 27 public class DOMCryptoContext implements XMLCryptoContext { 28 29 private HashMap nsMap = new HashMap (); 30 private HashMap idMap = new HashMap (); 31 private HashMap objMap = new HashMap (); 32 private String baseURI; 33 private KeySelector ks; 34 private URIDereferencer dereferencer; 35 private HashMap propMap = new HashMap (); 36 private String defaultPrefix; 37 38 41 protected DOMCryptoContext() {} 42 43 50 public String getNamespacePrefix(String namespaceURI, 51 String defaultPrefix) { 52 if (namespaceURI == null) { 53 throw new NullPointerException ("namespaceURI cannot be null"); 54 } 55 String prefix = (String ) nsMap.get(namespaceURI); 56 return (prefix != null ? prefix : defaultPrefix); 57 } 58 59 65 public String putNamespacePrefix(String namespaceURI, String prefix) { 66 if (namespaceURI == null) { 67 throw new NullPointerException ("namespaceURI is null"); 68 } 69 return (String ) nsMap.put(namespaceURI, prefix); 70 } 71 72 public String getDefaultNamespacePrefix() { 73 return defaultPrefix; 74 } 75 76 public void setDefaultNamespacePrefix(String defaultPrefix) { 77 this.defaultPrefix = defaultPrefix; 78 } 79 80 public String getBaseURI() { 81 return baseURI; 82 } 83 84 87 public void setBaseURI(String baseURI) { 88 if (baseURI != null) { 89 java.net.URI.create(baseURI); 90 } 91 this.baseURI = baseURI; 92 } 93 94 public URIDereferencer getURIDereferencer() { 95 return dereferencer; 96 } 97 98 public void setURIDereferencer(URIDereferencer dereferencer) { 99 this.dereferencer = dereferencer; 100 } 101 102 108 public Object getProperty(String name) { 109 if (name == null) { 110 throw new NullPointerException ("name is null"); 111 } 112 return propMap.get(name); 113 } 114 115 121 public Object setProperty(String name, Object value) { 122 if (name == null) { 123 throw new NullPointerException ("name is null"); 124 } 125 return propMap.put(name, value); 126 } 127 128 public KeySelector getKeySelector() { 129 return ks; 130 } 131 132 public void setKeySelector(KeySelector ks) { 133 this.ks = ks; 134 } 135 136 148 public Element getElementById(String idValue) { 149 if (idValue == null) { 150 throw new NullPointerException ("idValue is null"); 151 } 152 return (Element ) idMap.get(idValue); 153 } 154 155 173 public void setIdAttributeNS(Element element, String namespaceURI, 174 String localName) { 175 if (element == null) { 176 throw new NullPointerException ("element is null"); 177 } 178 if (localName == null) { 179 throw new NullPointerException ("localName is null"); 180 } 181 String idValue = element.getAttributeNS(namespaceURI, localName); 182 if (idValue == null || idValue.length() == 0) { 183 throw new IllegalArgumentException (localName + " is not an " + 184 "attribute"); 185 } 186 idMap.put(idValue, element); 187 } 188 189 201 public Iterator iterator() { 202 return Collections.unmodifiableMap(idMap).entrySet().iterator(); 203 } 204 205 209 public Object get(Object key) { 210 return objMap.get(key); 211 } 212 213 219 public Object put(Object key, Object value) { 220 return objMap.put(key, value); 221 } 222 } 223 | Popular Tags |