218 throw new XMLEncryptionException("empty", e);
219 }
220 }
221
222 protected static String createContext(String source, Node ctx) {
223 // Create the context to parse the document against
224 StringBuilder sb = new StringBuilder();
225 sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?><dummy");
226
227 // Run through each node up to the document node and find any xmlns: nodes
228 Map<String, String> storedNamespaces = new HashMap<String, String>();
229 Node wk = ctx;
230 while (wk != null) {
231 NamedNodeMap atts = wk.getAttributes();
232 if (atts != null) {
233 for (int i = 0; i < atts.getLength(); ++i) {
234 Node att = atts.item(i);
235 String nodeName = att.getNodeName();
236 if ((nodeName.equals("xmlns") || nodeName.startsWith("xmlns:"))
237 && !storedNamespaces.containsKey(att.getNodeName())) {
238 sb.append(" " + nodeName + "=\"" + att.getNodeValue() + "\"");
239 storedNamespaces.put(nodeName, att.getNodeValue());
240 }
241 }
242 }
243 wk = wk.getParentNode();
244 }
245 sb.append(">" + source + "</dummy>");
246 return sb.toString();
247 }
248
249 }
|
218 throw new XMLEncryptionException("empty", e);
219 }
220 }
221
222 protected static String createContext(String source, Node ctx) {
223 // Create the context to parse the document against
224 StringBuilder sb = new StringBuilder();
225 sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?><dummy");
226
227 // Run through each node up to the document node and find any xmlns: nodes
228 Map<String, String> storedNamespaces = new HashMap<String, String>();
229 Node wk = ctx;
230 while (wk != null) {
231 NamedNodeMap atts = wk.getAttributes();
232 if (atts != null) {
233 for (int i = 0; i < atts.getLength(); ++i) {
234 Node att = atts.item(i);
235 String nodeName = att.getNodeName();
236 if ((nodeName.equals("xmlns") || nodeName.startsWith("xmlns:"))
237 && !storedNamespaces.containsKey(att.getNodeName())) {
238 sb.append(' ').append(nodeName).append("=\"")
239 .append(att.getNodeValue()).append('"');
240 storedNamespaces.put(nodeName, att.getNodeValue());
241 }
242 }
243 }
244 wk = wk.getParentNode();
245 }
246 sb.append('>').append(source).append("</dummy>");
247 return sb.toString();
248 }
249
250 }
|