/**
   * Renders head for embedded component, i.e. those who are not added directly to this container
   * but have the markup inside it.
   *
   * @param container The HtmlHeaderContainer
   */
  private void renderHeadForInnerSiblings(HtmlHeaderContainer container) {
    MarkupStream stream = new MarkupStream(getMarkup());

    while (stream.hasMore()) {
      MarkupElement childOpenTag = stream.nextOpenTag();

      if ((childOpenTag instanceof ComponentTag) && !stream.atCloseTag()) {
        // Get element as tag
        final ComponentTag tag = (ComponentTag) childOpenTag;

        // Get component id
        final String id = tag.getId();

        Component component = null;

        if (get(id) == null) {
          component = ComponentResolvers.resolveByComponentHierarchy(this, stream, tag);
        }

        if (component != null) {
          component.internalRenderHead(container);
        }

        // consider just direct children
        stream.skipToMatchingCloseTag(tag);
      }
    }
  }
示例#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;
  }