/** Insert <head> open and close tag (with empty body) to the current position. */
  private void insertHeadTag() {
    // Note: only the open-tag must be a AutoComponentTag
    final ComponentTag openTag = new ComponentTag(HEAD, TagType.OPEN);
    openTag.setId(HEADER_ID);
    openTag.setAutoComponentTag(true);
    openTag.setModified(true);

    final ComponentTag closeTag = new ComponentTag(HEAD, TagType.CLOSE);
    closeTag.setOpenTag(openTag);
    closeTag.setModified(true);

    // insert the tags into the markup stream
    markup.addMarkupElement(openTag);
    markup.addMarkupElement(closeTag);
  }
 public IMarkupFragment getMarkup() {
   IMarkupFragment enclosureMarkup = null;
   if (this.enclosureMarkupAsString == null) {
     final IMarkupFragment markup = super.getMarkup();
     if (markup != null && markup != Markup.NO_MARKUP) {
       enclosureMarkup = markup;
       this.enclosureMarkupAsString = markup.toString(true);
     }
   } else {
     enclosureMarkup = Markup.of(this.enclosureMarkupAsString);
   }
   return enclosureMarkup;
 }
  /**
   * Reads and parses markup from a file.
   *
   * @return The markup
   * @throws IOException
   * @throws ResourceStreamNotFoundException
   */
  public final Markup parse() throws IOException, ResourceStreamNotFoundException {
    // The root of all markup filters is the xml parser
    markupFilterChain = new RootMarkupFilter(xmlParser);

    // Convert the list of markup filters into a chain
    for (IMarkupFilter filter : getMarkupFilters()) {
      filter.setNextFilter(markupFilterChain);
      markupFilterChain = filter;
    }

    // Initialize the xml parser
    MarkupResourceStream markupResourceStream = markup.getMarkupResourceStream();
    xmlParser.parse(
        markupResourceStream.getResource().getInputStream(),
        markupSettings.getDefaultMarkupEncoding());

    // parse the xml markup and tokenize it into wicket relevant markup
    // elements
    parseMarkup();

    // markupResourceStream.setEncoding(xmlParser.getEncoding());
    markupResourceStream.setDoctype(xmlParser.getDoctype());

    if (xmlParser.getEncoding() == null) {
      String a = "The markup file does not have a XML declaration prolog with 'encoding' attribute";
      String b = ". E.g. <?xml version=\"1.0\" encoding=\"UTF-8\" ?>";

      if (markupSettings.getThrowExceptionOnMissingXmlDeclaration()) {
        throw new MarkupException(markupResourceStream.getResource(), a + b);
      } else {
        log.debug(a + ":" + markupResourceStream.getResource() + ". It is more save to use it" + b);
      }
    }

    return markup;
  }
 @Override
 public IMarkupFragment getMarkup() {
   return Markup.of(
       "<html><wicket:head></wicket:head><body><form wicket:id=\"form\"><input type=\"text\" wicket:id=\"amount\" /></form></body></html>");
 }
 /**
  * Construct.
  *
  * @param markup The Markup object being filled while reading the markup resource
  */
 public HtmlHeaderSectionHandler(final Markup markup) {
   super(markup.getMarkupResourceStream());
   this.markup = markup;
 }
 /** @see java.lang.Object#toString() */
 @Override
 public String toString() {
   return markup.toString();
 }
  /** Scans the given markup and extracts balancing tags. */
  private void parseMarkup() {
    try {
      // always remember the latest index (size)
      int size = markup.size();

      // Loop through tags
      MarkupElement elem;
      while (null != (elem = getNextTag())) {
        if (elem instanceof HtmlSpecialTag) {
          elem = new ComponentTag(((HtmlSpecialTag) elem).getXmlTag());
        }

        if (elem instanceof ComponentTag) {
          ComponentTag tag = (ComponentTag) elem;

          boolean add = (tag.getId() != null);
          if (!add && tag.isClose()) {
            add = ((tag.getOpenTag() != null) && (tag.getOpenTag().getId() != null));
          }

          // Add tag to list?
          if (add || /*tag.isModified() ||*/ (markup.size() != size)) {
            // Add text from last position to the current tag position
            CharSequence text = xmlParser.getInputFromPositionMarker(tag.getPos());
            if (text.length() > 0) {
              text = handleRawText(text.toString());

              // Make sure you add it at the correct location.
              // IMarkupFilters might have added elements as well.
              markup.addMarkupElement(size, new RawMarkup(text));
            }

            xmlParser.setPositionMarker();

            if (add) {
              // Add to the markup unless the tag has been flagged as
              // to be removed from the markup. (e.g. <wicket:remove>
              if (tag.isIgnore() == false) {
                markup.addMarkupElement(tag);
              }
            }
            /*else if (tag.isModified())
            {
            	markup.addMarkupElement(new RawMarkup(tag.toCharSequence()));
            }*/
            else {
              xmlParser.setPositionMarker(tag.getPos());
            }
          }

          // always remember the latest index (size)
          size = markup.size();
        }
      }
    } catch (final ParseException ex) {
      // Add remaining input string
      final CharSequence text = xmlParser.getInputFromPositionMarker(-1);
      if (text.length() > 0) {
        markup.addMarkupElement(new RawMarkup(text));
      }

      // markup.getMarkupResourceStream().setEncoding(xmlParser.getEncoding());
      markup.getMarkupResourceStream().setDoctype(xmlParser.getDoctype());

      final MarkupStream markupStream = new MarkupStream(markup);
      markupStream.setCurrentIndex(markup.size() - 1);
      throw new MarkupException(markupStream, ex.getMessage(), ex);
    }

    // Add tail?
    CharSequence text = xmlParser.getInputFromPositionMarker(-1);
    if (text.length() > 0) {
      text = handleRawText(text.toString());

      // Make sure you add it at the correct location.
      // IMarkupFilters might have added elements as well.
      markup.addMarkupElement(new RawMarkup(text));
    }

    postProcess(markup);

    // Make all tags immutable and the list of elements unmodifiable
    markup.makeImmutable();
  }
 /**
  * Applications which subclass initFilterChain() might also wish to access the markup resource
  * stream.
  *
  * @return The markup resource stream
  */
 protected MarkupResourceStream getMarkupResourceStream() {
   return markup.getMarkupResourceStream();
 }
 /**
  * In case you want to analyze markup which BY DEFAULT does not use "wicket" to find relevant
  * tags.
  *
  * @param namespace
  */
 public final void setWicketNamespace(final String namespace) {
   markup.getMarkupResourceStream().setWicketNamespace(namespace);
 }
 private static void render(BootstrapRadioChoice<String> choice, String initialMarkup) {
   MarkupStream stream = new MarkupStream(Markup.of(initialMarkup));
   stream.setCurrentIndex(1);
   choice.onComponentTagBody(stream, new ComponentTag("div", TagType.OPEN));
 }