/**
   * Search the child's markup in the header section of the markup
   *
   * @param container
   * @param child
   * @return Null, if not found
   */
  public IMarkupFragment findMarkupInAssociatedFileHeader(
      final MarkupContainer container, final Component child) {
    // Get the associated markup
    IMarkupFragment markup = container.getAssociatedMarkup();
    IMarkupFragment childMarkup = null;

    // MarkupStream is good at searching markup
    MarkupStream stream = new MarkupStream(markup);
    while (stream.skipUntil(ComponentTag.class) && (childMarkup == null)) {
      ComponentTag tag = stream.getTag();
      if (TagUtils.isWicketHeadTag(tag)) {
        if (tag.getMarkupClass() == null) {
          // find() can still fail an return null => continue the search
          childMarkup = stream.getMarkupFragment().find(child.getId());
        }
      } else if (TagUtils.isHeadTag(tag)) {
        // find() can still fail an return null => continue the search
        childMarkup = stream.getMarkupFragment().find(child.getId());
      }

      // Must be a direct child. We are not interested in grand children
      if (tag.isOpen() && !tag.hasNoCloseTag()) {
        stream.skipToMatchingCloseTag(tag);
      }
      stream.next();
    }

    return childMarkup;
  }
Exemplo n.º 2
0
  /**
   * Resolves the child component which is the controller of this Enclosure
   *
   * @param markupStream the markup stream of this Enclosure
   * @param enclosureParent the non-auto parent component of this Enclosure
   * @return The component associated with the {@linkplain #childId}
   */
  private Component getChildComponent(
      final MarkupStream markupStream, MarkupContainer enclosureParent) {
    String fullChildId = getChildId();

    Component controller = enclosureParent.get(fullChildId);
    if (controller == null) {
      int orgIndex = markupStream.getCurrentIndex();
      try {
        while (markupStream.hasMore()) {
          markupStream.next();
          if (markupStream.skipUntil(ComponentTag.class)) {
            ComponentTag tag = markupStream.getTag();
            if ((tag != null) && (tag.isOpen() || tag.isOpenClose())) {
              String tagId = tag.getId();

              if (fullChildId.equals(tagId)) {
                ComponentTag fullComponentTag = new ComponentTag(tag);
                fullComponentTag.setId(childId.toString());

                controller =
                    ComponentResolvers.resolve(
                        enclosureParent,
                        markupStream,
                        fullComponentTag,
                        new ResolverFilter() {
                          @Override
                          public boolean ignoreResolver(final IComponentResolver resolver) {
                            return resolver instanceof EnclosureHandler;
                          }
                        });
                break;
              } else if (fullChildId.startsWith(tagId + PATH_SEPARATOR)) {
                fullChildId = Strings.afterFirst(fullChildId, PATH_SEPARATOR);
              }
            }
          }
        }
      } finally {
        markupStream.setCurrentIndex(orgIndex);
      }
    }

    checkChildComponent(controller);
    return controller;
  }
  /**
   * Search for <wicket:panel ...> on the same level.
   *
   * @param markup
   * @return null, if not found
   */
  private final IMarkupFragment findStartTag(final IMarkupFragment markup) {
    MarkupStream stream = new MarkupStream(markup);

    while (stream.skipUntil(ComponentTag.class)) {
      ComponentTag tag = stream.getTag();
      if (tag.isOpen() || tag.isOpenClose()) {
        if (tag instanceof WicketTag) {
          WicketTag wtag = (WicketTag) tag;
          if (tagName.equalsIgnoreCase(wtag.getName())) {
            return stream.getMarkupFragment();
          }
        }

        stream.skipToMatchingCloseTag(tag);
      }

      stream.next();
    }

    return null;
  }
Exemplo n.º 4
0
  @Override
  public IMarkupFragment getMarkup() {
    if (getParent() == null) {
      throw new WicketRuntimeException(
          "Bug: The Wicket internal instance of HtmlHeaderContainer is not connected to a parent");
    }

    // Get the page markup
    IMarkupFragment markup = getPage().getMarkup();
    if (markup == null) {
      throw new MarkupException("Unable to get page markup: " + getPage().toString());
    }

    // Find the markup fragment
    MarkupStream stream = new MarkupStream(markup);
    IMarkupFragment headerMarkup = null;
    while (stream.skipUntil(ComponentTag.class) && (headerMarkup == null)) {
      ComponentTag tag = stream.getTag();
      if (tag.isOpen() || tag.isOpenClose()) {
        if (tag instanceof WicketTag) {
          WicketTag wtag = (WicketTag) tag;
          if (wtag.isHeadTag()) {
            if (tag.getMarkupClass() == null) {
              headerMarkup = stream.getMarkupFragment();
            }
          }
        } else if (tag.getName().equalsIgnoreCase("head")) {
          headerMarkup = stream.getMarkupFragment();
        }
      }

      stream.next();
    }

    setMarkup(headerMarkup);
    return headerMarkup;
  }