public B addPreparedElement(XMLElement preparedElement) { checkReset(); currentElement.innerFragments.add(preparedElement); return (B) this; }
/** * the stanza can only be retrieved once * @return retrieves the XML element and invalidates the builder */ public T build() { checkReset(); XMLElement returnStanza = resultingElement; resultingElement = null; isReset = true; // reset stack.clear(); return (T) returnStanza; }
public B endInnerElement() { checkReset(); if (stack.isEmpty()) throw new IllegalStateException("cannot end beyond top element"); stack.pop(); // take current off stack and forget (it was added to its parent before) currentElement = stack.peek(); // we again deal with parent, which can be receive additions return (B) this; }
public B startInnerElement(String name, String namespaceURI) { checkReset(); startNewElement(name, namespaceURI, null); stack.peek().innerFragments.add(currentElement.element); // add new one to its parent stack.push(currentElement); return (B) this; }
public B addText(String text) { checkReset(); currentElement.innerFragments.add(new XMLText(text)); return (B) this; }
public B addAttribute(Attribute attribute) { checkReset(); // check if attribute already exists for(Attribute existing : currentElement.attributes) { if(existing.getName().equals(attribute.getName()) && existing.getNamespaceUri().equals(attribute.getNamespaceUri())) { currentElement.attributes.remove(existing); break; } } currentElement.attributes.add(attribute); return (B) this; }