/** * Returns a converter that first applies {@code other} then this converter. * * @param other The other converter. * @return A converter that first applies {@code other} then this converter. * @throws IllegalArgumentException When {@code other} is {@code null}. */ public default AttributeNameConverter compose(AttributeNameConverter other) { Checks.isNotNull(other, "other"); return (Element element, String name) -> convertAttributeName(element, other.convertAttributeName(element, name)); }
@Test public void testSetNameOfMatchingAttributes() throws IOException { final String source = XML + EOL + "<root x='a'>" + EOL + "<child y='a'/>" + EOL + "</root>"; final String expected = XML + EOL + "<root X='a'>" + EOL + "<child Y='a'/>" + EOL + "</root>"; final Document doc = XmlDataReader.load(source, StandardCharsets.UTF_8); DataUtil.setNameOfMatchingAttributes(doc, AttributePredicate.ANY_ATTRIBUTE, AttributeNameConverter.fromNameFunction(String::toUpperCase), DataUtil.RECURSE); final String target = XmlDataWriter.toString(doc, INDENT, XmlWriter.Feature.USE_SINGLE_QUOTE); assertEquals(expected, target); }
reader.setAttributeNameConverter(AttributeNameConverter.fromPathMap(margs.renamed)); reader.setElementNameConverter(ElementNameConverter.fromPathMap(margs.renamed)); DataUtil.setNameOfMatchingAttributes(document, AttributePredicate.ANY_ATTRIBUTE, AttributeNameConverter.fromPathMap(margs.renamed), DataUtil.RECURSE); DataUtil.setNameOfMatchingElements(document,
/** * Returns a converter that first applies this converter and then {@code other}. * * @param other The other converter. * @return A converter that first applies this converter and then {@code other}. * @throws IllegalArgumentException When {@code other} is {@code null}. */ public default AttributeNameConverter andThen(AttributeNameConverter other) { Checks.isNotNull(other, "other"); return (Element element, String name) -> other.convertAttributeName(element, convertAttributeName(element, name)); }
private final String convertAttributeName(Element element, String name) { return shareAttributeName(attributeNameConverter.convertAttributeName(element, name)); }
element.addAttribute(new Attribute(converter.convertAttributeName(element, att.getName()), att.getValue()));