public void onStart(String tagName, ElementBuilderBase<?> builder) { if (isEmpty) { isEmpty = false; } else if (stack.isEmpty()) { // Check that we aren't creating another top level element. throw new IllegalStateException("You can only build one top level element."); } else { // Check that the element supports children. assertEndTagNotForbidden("child elements"); if (!getCurrentBuilder().isChildElementSupported()) { throw new UnsupportedOperationException(getCurrentTagName() + " does not support child elements."); } } // Check that asElement hasn't already been called. if (isHtmlOrTextAdded) { throw new IllegalStateException("Cannot append an element after setting text of html."); } // Validate the tagName. assertValidTagName(tagName); maybeCloseStartTag(); stack.push(builder, tagName); isStartTagOpen = true; isStyleOpen = false; isStyleClosed = false; isHtmlOrTextAdded = false; }
public void text(String text) { assertStartTagOpen("text cannot be set on an element that already " + "contains other content or elements."); lockCurrentElement(); doTextImpl(text); }
/** * Close the start tag if it is still open. */ private void maybeCloseStartTag() { maybeCloseStyleAttribute(); if (isStartTagOpen) { isStartTagOpen = false; /* * Close the start tag, unless the end tag is forbidden. If the end tag is * forbidden, the only valid call is to #end(), which will self end the * start tag. */ if (!getCurrentBuilder().isEndTagForbidden()) { doCloseStartTagImpl(); } } }
/** * Lock the current element, preventing any additional changes to it. The only * valid option is to call {@link #end()}. */ protected void lockCurrentElement() { maybeCloseStartTag(); assertEndTagNotForbidden("html"); isHtmlOrTextAdded = true; }
/** * Assert that the builder is in a state where an attribute can be added. * * @throw {@link IllegalStateException} if the start tag is closed */ protected void assertCanAddAttributeImpl() { assertStartTagOpen("Attributes cannot be added after appending HTML or adding a child " + "element."); maybeCloseStyleAttribute(); }
/** * End the current element without checking the tag name. * * @param tagName the tag name to end */ private void endImpl(String tagName) { // Close the start tag. maybeCloseStartTag(); /* * End the tag. The tag name is safe because it comes from the stack, and * tag names are checked before they are added to the stack. */ if (getCurrentBuilder().isEndTagForbidden()) { doEndStartTagImpl(); } else { doEndTagImpl(tagName); } // Popup the item off the top of the stack. isStartTagOpen = false; // Closed because this element was added. isStyleClosed = true; // Too late to add styles. stack.pop(); /* * If this element was added, then we did not add html or text to the * parent. */ isHtmlOrTextAdded = false; }
public void html(SafeHtml html) { assertStartTagOpen("html cannot be set on an element that already " + "contains other content or elements."); lockCurrentElement(); doHtmlImpl(html); }
/** * Return the built DOM as an {@link Element}. * * @return the {@link Element} that was built */ public Element finish() { if (!GWT.isClient()) { throw new RuntimeException("asElement() can only be called from GWT client code."); } if (asElementCalled) { throw new IllegalStateException("asElement() can only be called once."); } asElementCalled = true; // End all open tags. endAllTags(); return doFinishImpl(); }
/** * Assert that a style property can be added, and setup the state as if one is * about to be added. */ protected void assertCanAddStylePropertyImpl() { assertStartTagOpen("Style properties cannot be added after appending HTML or adding a child " + "element."); // Check if a style attribute already exists. if (isStyleClosed) { throw new IllegalStateException( "Style properties must be added at the same time. If you already added style properties," + " you cannot add more after adding non-style attributes."); } // Open the style attribute. if (!isStyleOpen) { isStyleOpen = true; doOpenStyleImpl(); } }
/** * Close the style attribute if it is still open. */ private void maybeCloseStyleAttribute() { if (isStyleOpen) { isStyleOpen = false; isStyleClosed = true; doCloseStyleAttributeImpl(); } } }
/** * End the current element without checking the tag name. * * @param tagName the tag name to end */ private void endImpl(String tagName) { // Close the start tag. maybeCloseStartTag(); /* * End the tag. The tag name is safe because it comes from the stack, and * tag names are checked before they are added to the stack. */ if (getCurrentBuilder().isEndTagForbidden()) { doEndStartTagImpl(); } else { doEndTagImpl(tagName); } // Popup the item off the top of the stack. isStartTagOpen = false; // Closed because this element was added. isStyleClosed = true; // Too late to add styles. stack.pop(); /* * If this element was added, then we did not add html or text to the * parent. */ isHtmlOrTextAdded = false; }
public void html(SafeHtml html) { assertStartTagOpen("html cannot be set on an element that already " + "contains other content or elements."); lockCurrentElement(); doHtmlImpl(html); }
/** * Lock the current element, preventing any additional changes to it. The only * valid option is to call {@link #end()}. */ protected void lockCurrentElement() { maybeCloseStartTag(); assertEndTagNotForbidden("html"); isHtmlOrTextAdded = true; }
/** * Assert that the builder is in a state where an attribute can be added. * * @throw {@link IllegalStateException} if the start tag is closed */ protected void assertCanAddAttributeImpl() { assertStartTagOpen("Attributes cannot be added after appending HTML or adding a child " + "element."); maybeCloseStyleAttribute(); }
/** * Return the built DOM as an {@link Element}. * * @return the {@link Element} that was built */ public Element finish() { if (!GWT.isClient()) { throw new RuntimeException("asElement() can only be called from GWT client code."); } if (asElementCalled) { throw new IllegalStateException("asElement() can only be called once."); } asElementCalled = true; // End all open tags. endAllTags(); return doFinishImpl(); }
/** * Assert that a style property can be added, and setup the state as if one is * about to be added. */ protected void assertCanAddStylePropertyImpl() { assertStartTagOpen("Style properties cannot be added after appending HTML or adding a child " + "element."); // Check if a style attribute already exists. if (isStyleClosed) { throw new IllegalStateException( "Style properties must be added at the same time. If you already added style properties," + " you cannot add more after adding non-style attributes."); } // Open the style attribute. if (!isStyleOpen) { isStyleOpen = true; doOpenStyleImpl(); } }
/** * Close the style attribute if it is still open. */ private void maybeCloseStyleAttribute() { if (isStyleOpen) { isStyleOpen = false; isStyleClosed = true; doCloseStyleAttributeImpl(); } } }
public void onStart(String tagName, ElementBuilderBase<?> builder) { if (isEmpty) { isEmpty = false; } else if (stack.isEmpty()) { // Check that we aren't creating another top level element. throw new IllegalStateException("You can only build one top level element."); } else { // Check that the element supports children. assertEndTagNotForbidden("child elements"); if (!getCurrentBuilder().isChildElementSupported()) { throw new UnsupportedOperationException(getCurrentTagName() + " does not support child elements."); } } // Check that asElement hasn't already been called. if (isHtmlOrTextAdded) { throw new IllegalStateException("Cannot append an element after setting text of html."); } // Validate the tagName. assertValidTagName(tagName); maybeCloseStartTag(); stack.push(builder, tagName); isStartTagOpen = true; isStyleOpen = false; isStyleClosed = false; isHtmlOrTextAdded = false; }
/** * End the current element without checking the tag name. * * @param tagName the tag name to end */ private void endImpl(String tagName) { // Close the start tag. maybeCloseStartTag(); /* * End the tag. The tag name is safe because it comes from the stack, and * tag names are checked before they are added to the stack. */ if (getCurrentBuilder().isEndTagForbidden()) { doEndStartTagImpl(); } else { doEndTagImpl(tagName); } // Popup the item off the top of the stack. isStartTagOpen = false; // Closed because this element was added. isStyleClosed = true; // Too late to add styles. stack.pop(); /* * If this element was added, then we did not add html or text to the * parent. */ isHtmlOrTextAdded = false; }
public void text(String text) { assertStartTagOpen("text cannot be set on an element that already " + "contains other content or elements."); lockCurrentElement(); doTextImpl(text); }