@Override public void updateElementAttributes(E element, Map<String, String> attrs) { getDelegate().updateElementAttributes(element, attrs); }
@Override public void set(Map<K, V> values) { Map<String, String> valueStrings = CollectionUtils.newHashMap(); for (Map.Entry<K, V> entry : values.entrySet()) { String valueStr = serializer.toString(entry.getValue()); valueStrings.put(entry.getKey().toString(), valueStr); } document.updateElementAttributes(element, valueStrings); }
@SuppressWarnings("unchecked") public void doTestAttributes() { String a = "<p>abc<b>def</b></p>"; create(a); Element elem = (Element) doc.getDocumentElement().getFirstChild(); Attributes attrs = attrs("x", "1", "y", "2", "z", "3"); doc.setElementAttributes(elem, attrs); checkEvents(am(elem, pairs("x", null, "y", null, "z", null), attrs)); Attributes updates = attrs("w", "4", "x", "1", "y", "5"); doc.updateElementAttributes(elem, updates); // x omitted because no change. checkEvents(am(elem, pairs("w", null, "y", "2"), attrs("w", "4", "y", "5"))); Map<String, String> updates2 = pairs("w", null); doc.updateElementAttributes(elem, updates2); // x omitted because no change. checkEvents(am(elem, pairs("w", "4"), pairs("w", null))); Attributes sets = attrs("x", "1", "y", "6", "v", "7"); doc.setElementAttributes(elem, sets); // x omitted because no change. checkEvents(am(elem, pairs("y", "5", "z", "3", "v", null), pairs("y", "6", "z", null, "v", "7"))); // tests lack of concurrent modification exception: Attributes sets2 = attrs("x", "1", "y", "6", "v", "7"); doc.setElementAttributes(elem, sets2); checkEvents(am(elem, pairs(), pairs())); }
@SuppressWarnings("unchecked") public void doTestAttributes() { String a = "<p>abc<b>def</b></p>"; create(a); Element elem = (Element) doc.getDocumentElement().getFirstChild(); Attributes attrs = attrs("x", "1", "y", "2", "z", "3"); doc.setElementAttributes(elem, attrs); checkEvents(am(elem, pairs("x", null, "y", null, "z", null), attrs)); Attributes updates = attrs("w", "4", "x", "1", "y", "5"); doc.updateElementAttributes(elem, updates); // x omitted because no change. checkEvents(am(elem, pairs("w", null, "y", "2"), attrs("w", "4", "y", "5"))); Map<String, String> updates2 = pairs("w", null); doc.updateElementAttributes(elem, updates2); // x omitted because no change. checkEvents(am(elem, pairs("w", "4"), pairs("w", null))); Attributes sets = attrs("x", "1", "y", "6", "v", "7"); doc.setElementAttributes(elem, sets); // x omitted because no change. checkEvents(am(elem, pairs("y", "5", "z", "3", "v", null), pairs("y", "6", "z", null, "v", "7"))); // tests lack of concurrent modification exception: Attributes sets2 = attrs("x", "1", "y", "6", "v", "7"); doc.setElementAttributes(elem, sets2); checkEvents(am(elem, pairs(), pairs())); }