示例#1
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;
  }
  @Override
  public Component resolve(MarkupContainer container, MarkupStream markupStream, ComponentTag tag) {
    // localize any raw markup that has wicket:message attrs
    if ((tag != null) && (tag.getId().startsWith(WICKET_MESSAGE_CONTAINER_ID))) {
      Component wc = null;
      int autoIndex = container.getPage().getAutoIndex();
      String id = WICKET_MESSAGE_CONTAINER_ID + autoIndex;

      if (tag.isOpenClose()) {
        wc = new WebComponent(id);
      } else {
        wc = new TransparentWebMarkupContainer(id);
      }

      return wc;
    }
    return null;
  }
  /**
   * 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;
  }
示例#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;
  }