/**
   * Handle tag <head>
   *
   * @param tag
   */
  private void handleHeadTag(ComponentTag tag) {
    // we found <head>
    if (tag.isOpen()) {
      if (foundHead) {
        throw new MarkupException(
            new MarkupStream(markup),
            "Tag <head> is not allowed at this position (do you have multiple <head> tags in your markup?).");
      }

      foundHead = true;

      if (tag.getId() == null) {
        tag.setId(HEADER_ID);
        tag.setAutoComponentTag(true);
        tag.setModified(true);
      }
    } else if (tag.isClose()) {
      if (foundHeaderItemsTag) {
        // revert the settings from above
        ComponentTag headOpenTag = tag.getOpenTag();
        // change the id because it is special. See HtmlHeaderResolver
        headOpenTag.setId(HEADER_ID + "-Ignored");
        headOpenTag.setAutoComponentTag(false);
        headOpenTag.setModified(false);
        headOpenTag.setFlag(ComponentTag.RENDER_RAW, true);
      }

      foundClosingHead = true;
    }
  }
  /** Insert &lt;head&gt; 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);
  }
Esempio n. 3
0
  /**
   * Appends specified {@code value} to the attribute
   *
   * @param key The key
   * @param value The value
   * @param separator The separator used to append the value
   */
  public final void append(String key, CharSequence value, String separator) {
    String current = getAttribute(key);
    if (Strings.isEmpty(current)) {
      xmlTag.put(key, value);
    } else {
      xmlTag.put(key, current + separator + value);
    }

    setModified(true);
  }
  /**
   * Handle tag &lt;wicket:header-items&gt;
   *
   * @param tag
   */
  private void handleHeaderItemsTag(ComponentTag tag) {
    if (foundHeaderItemsTag) {
      throw new MarkupException(
          new MarkupStream(markup),
          "More than one <wicket:header-items/> detected in the <head> element. Only one is allowed.");
    } else if (foundClosingHead) {
      throw new MarkupException(
          new MarkupStream(markup),
          "Detected <wicket:header-items/> after the closing </head> element.");
    }

    foundHeaderItemsTag = true;
    tag.setId(HEADER_ID);
    tag.setAutoComponentTag(true);
    tag.setModified(true);
  }
  @Override
  protected final MarkupElement onComponentTag(ComponentTag tag) throws ParseException {
    if (tag.isClose()) {
      return tag;
    }

    final String wicketMessageAttribute = tag.getAttributes().getString(getWicketMessageAttrName());

    if ((wicketMessageAttribute != null) && (wicketMessageAttribute.trim().length() > 0)) {
      // check if this tag is raw markup
      if (tag.getId() == null) {
        // if this is a raw tag we need to set the id to something so
        // that wicket will not merge this as raw markup and instead
        // pass it on to a resolver
        tag.setId(WICKET_MESSAGE_CONTAINER_ID);
        tag.setAutoComponentTag(true);
        tag.setModified(true);
      }
      tag.addBehavior(new AttributeLocalizer(getWicketMessageAttrName()));
    }

    return tag;
  }
Esempio n. 6
0
 /**
  * THIS METHOD IS NOT PART OF THE WICKET PUBLIC API. DO NOT CALL IT.
  *
  * @param type The new type
  */
 public final void setType(final TagType type) {
   if (type != xmlTag.getType()) {
     xmlTag.setType(type);
     setModified(true);
   }
 }
Esempio n. 7
0
 /**
  * @see org.apache.wicket.markup.parser.XmlTag#remove(String)
  * @param key The key to remove
  */
 public final void remove(String key) {
   xmlTag.remove(key);
   setModified(true);
 }
Esempio n. 8
0
 /**
  * @see org.apache.wicket.markup.parser.XmlTag#putAll(Map)
  * @param map a key/value map
  */
 public final void putAll(final Map<String, Object> map) {
   xmlTag.putAll(map);
   setModified(true);
 }
Esempio n. 9
0
 /**
  * @see org.apache.wicket.markup.parser.XmlTag#put(String, StringValue)
  * @param key The key
  * @param value The value
  */
 public final void put(String key, StringValue value) {
   xmlTag.put(key, value);
   setModified(true);
 }
Esempio n. 10
0
 /**
  * THIS METHOD IS NOT PART OF THE PUBLIC API, DO NOT CALL IT
  *
  * @see org.apache.wicket.markup.parser.XmlTag#put(String, CharSequence)
  * @param key The key
  * @param value The value
  */
 public final void putInternal(String key, CharSequence value) {
   xmlTag.put(key, value);
   setModified(true);
 }
Esempio n. 11
0
 /**
  * @see org.apache.wicket.markup.parser.XmlTag#put(String, int)
  * @param key The key
  * @param value The value
  */
 public final void put(final String key, final int value) {
   xmlTag.put(key, value);
   setModified(true);
 }
Esempio n. 12
0
  @Override
  protected MarkupElement onComponentTag(final ComponentTag tag) throws ParseException {
    // We only need ComponentTags
    if (tag instanceof WicketTag) {
      return tag;
    }

    // Has wicket:enclosure attribute?
    String enclosureAttr = getAttribute(tag, null);
    if (enclosureAttr != null) {
      if (tag.isOpen()) {
        // Make sure 'wicket:id' and 'id' are consistent
        String htmlId = tag.getAttribute("id");
        if ((tag.getId() != null) && !Strings.isEmpty(htmlId) && !htmlId.equals(tag.getId())) {
          throw new ParseException(
              "Make sure that 'id' and 'wicket:id' are the same if both are provided. Tag:"
                  + tag.toString(),
              tag.getPos());
        }

        // if it doesn't have a wicket-id already, then assign one now.
        if (Strings.isEmpty(tag.getId())) {
          if (Strings.isEmpty(htmlId)) {
            String id =
                getWicketNamespace() + "_" + INLINE_ENCLOSURE_ID_PREFIX + getRequestUniqueId();
            tag.setId(id);
          } else {
            tag.setId(htmlId);
          }

          tag.setAutoComponentTag(true);
          tag.setAutoComponentFactory(
              new ComponentTag.IAutoComponentFactory() {
                @Override
                public Component newComponent(MarkupContainer container, ComponentTag tag) {
                  String attributeName = getInlineEnclosureAttributeName(null);
                  String childId = tag.getAttribute(attributeName);
                  return new InlineEnclosure(tag.getId(), childId);
                }
              });
          tag.setModified(true);
        }

        // Put the enclosure on the stack. The most current one will be on top
        if (enclosures == null) {
          enclosures = new ArrayDeque<>();
        }
        enclosures.push(tag);
      } else {
        throw new ParseException(
            "Open-close tags don't make sense for InlineEnclosure. Tag:" + tag.toString(),
            tag.getPos());
      }
    }
    // Are we within an enclosure?
    else if ((enclosures != null) && (enclosures.size() > 0)) {
      // In case the enclosure tag did not provide a child component id, then assign the
      // first ComponentTag's id found as the controlling child to the enclosure.
      if (tag.isOpen()
          && (tag.getId() != null)
          && !(tag instanceof WicketTag)
          && !tag.isAutoComponentTag()) {
        Iterator<ComponentTag> componentTagIterator = enclosures.descendingIterator();
        while (componentTagIterator.hasNext()) {
          ComponentTag lastEnclosure = componentTagIterator.next();
          String attr = getAttribute(lastEnclosure, null);
          if (Strings.isEmpty(attr) == true) {
            lastEnclosure.getAttributes().put(getInlineEnclosureAttributeName(null), tag.getId());
            lastEnclosure.setModified(true);
          }
        }
      } else if (tag.isClose() && tag.closes(enclosures.peek())) {
        ComponentTag lastEnclosure = enclosures.pop();
        String attr = getAttribute(lastEnclosure, null);
        if (Strings.isEmpty(attr) == true) {
          throw new ParseException(
              "Did not find any child for InlineEnclosure. Tag:" + lastEnclosure.toString(),
              tag.getPos());
        }
      }
    }

    return tag;
  }