@@ -0,0 +1,1880 @@
+package org.springframework.roo.support.util;%0A%0Aimport org.w3c.dom.Document;%0Aimport org.w3c.dom.Element;%0A%0A/**%0A * Very simple convenience Builder for XML %7B@code Element%7Ds%0A * %0A * @author Stefan Schmidt%0A * @since 1.0%0A *%0A */%0Apublic class XmlElementBuilder %7B%09%0A%0A%09private Element element;%0A%0A%09/**%0A%09 * Create a new Element instance.%0A%09 * %0A%09 * @param name The name of the element (required, not empty)%0A%09 * @param document The parent document (required)%0A%09 */%0A%09public XmlElementBuilder (String name, Document document) %7B%09%0A%09%09Assert.hasText(name, %22Element name required.%22);%0A%09%09Assert.notNull(document, %22Owner document required%22);%0A%09%09element = document.createElement(name);%0A%09%7D%0A%0A%09/**%0A%09 * Add an attribute to the current element.%0A%09 * %0A%09 * @param qName The attribute name (required, not empty)%0A%09 * @param value The value of the attribute (required)%0A%09 * @return%0A%09 */%0A%09public XmlElementBuilder addAttribute(String qName, String value) %7B%0A%09%09Assert.hasText(qName, %22Attribute qName required.%22);%0A%09%09Assert.notNull(value, %22Attribute value required.%22);%0A%09%09element.setAttribute(qName, value);%0A%09%09return this;%0A%09%7D%0A%0A%09/**%0A%09 * Add a child element to the current element.%0A%09 * %0A%09 * @param element The new element (required)%0A%09 * @return The builder for the current element%0A%09 */%0A%09public XmlElementBuilder addChild(Element element) %7B%0A%09%09Assert.notNull(element, %22Element required.%22);%0A%09%09this.element.appendChild(element);%0A%09%09return this;%0A%09%7D%0A%0A%09/**%0A%09 * Add text contents to the current element. This will overwrite%0A%09 * any previous text content.%0A%09 * %0A%09 * @param element The text content (required, not empty)%0A%09 * @return The builder for the current element%0A%09 */%0A%09public XmlElementBuilder setText(String text) %7B%0A%09%09Assert.hasText(text, %22Text content required.%22);%0A%09%09element.setTextContent(text);%0A%09%09return this;%0A%09%7D%0A%09%0A%09/**%0A%09 * Get the element instance.%0A%09 * %0A%09 * @return The element.%0A%09 */%0A%09public Element build() %7B%0A%09%09return element;%0A%09%7D%0A%7D%0A

Introduce simple XML Element builder to improve DOM generation tasks