Search in sources :

Example 1 with WicketTag

use of org.apache.wicket.markup.WicketTag in project wicket by apache.

the class HtmlHeaderContainer method getMarkup.

@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)) {
        ComponentTag tag = stream.getTag();
        if (tag.isOpen() || tag.isOpenClose()) {
            if (tag instanceof WicketTag) {
                WicketTag wtag = (WicketTag) tag;
                if (wtag.isHeadTag() || wtag.isHeaderItemsTag()) {
                    headerMarkup = stream.getMarkupFragment();
                    break;
                }
            } else if (tag.getName().equalsIgnoreCase("head") && tag.isAutoComponentTag()) {
                headerMarkup = stream.getMarkupFragment();
                break;
            }
        }
        stream.next();
    }
    setMarkup(headerMarkup);
    return headerMarkup;
}
Also used : WicketTag(org.apache.wicket.markup.WicketTag) ComponentTag(org.apache.wicket.markup.ComponentTag) WicketRuntimeException(org.apache.wicket.WicketRuntimeException) MarkupStream(org.apache.wicket.markup.MarkupStream) IMarkupFragment(org.apache.wicket.markup.IMarkupFragment) MarkupException(org.apache.wicket.markup.MarkupException)

Example 2 with WicketTag

use of org.apache.wicket.markup.WicketTag in project wicket by apache.

the class MarkupUtil method findStartTag.

/**
 * Searches for {@code tagName} in the given {@code markup}.
 *
 * @param markup
 * @param tagName
 * @return The {@link IMarkupFragment} corresponding to {@code tagName}. Null, if such {@code tagName} is not found
 */
public static IMarkupFragment findStartTag(final IMarkupFragment markup, final String tagName) {
    MarkupStream stream = new MarkupStream(markup);
    while (stream.skipUntil(WicketTag.class)) {
        ComponentTag tag = stream.getTag();
        if (tag.isOpen() || tag.isOpenClose()) {
            WicketTag wtag = (WicketTag) tag;
            if (tagName.equalsIgnoreCase(wtag.getName())) {
                return stream.getMarkupFragment();
            }
            stream.skipToMatchingCloseTag(tag);
        }
        stream.next();
    }
    return null;
}
Also used : WicketTag(org.apache.wicket.markup.WicketTag) ComponentTag(org.apache.wicket.markup.ComponentTag) MarkupStream(org.apache.wicket.markup.MarkupStream)

Example 3 with WicketTag

use of org.apache.wicket.markup.WicketTag in project wicket by apache.

the class BorderBehavior method afterRender.

@Override
public void afterRender(final Component component) {
    final MarkupStream stream = getMarkupStream(component);
    final Response response = component.getResponse();
    while (stream.isCurrentIndexInsideTheStream()) {
        MarkupElement elem = stream.get();
        stream.next();
        if (elem instanceof WicketTag) {
            WicketTag wTag = (WicketTag) elem;
            if (wTag.isBorderTag() && wTag.isClose()) {
                break;
            } else {
                throw new WicketRuntimeException("Unexpected tag encountered in markup of component border " + getClass().getName() + ". Tag: " + wTag.toString() + ", expected tag: </wicket:border>");
            }
        }
        response.write(elem.toCharSequence());
    }
}
Also used : Response(org.apache.wicket.request.Response) WicketTag(org.apache.wicket.markup.WicketTag) WicketRuntimeException(org.apache.wicket.WicketRuntimeException) MarkupStream(org.apache.wicket.markup.MarkupStream) MarkupElement(org.apache.wicket.markup.MarkupElement)

Example 4 with WicketTag

use of org.apache.wicket.markup.WicketTag in project wicket by apache.

the class EnclosureHandler method onComponentTag.

@Override
protected final MarkupElement onComponentTag(ComponentTag tag) throws ParseException {
    final boolean isWicketTag = tag instanceof WicketTag;
    final boolean isEnclosureTag = isWicketTag && ((WicketTag) tag).isEnclosureTag();
    // If wicket:enclosure
    if (isEnclosureTag) {
        // If open tag, than put the tag onto the stack
        if (tag.isOpen()) {
            tag.setId(tag.getId() + getRequestUniqueId());
            tag.setModified(true);
            tag.setAutoComponentFactory(FACTORY);
            if (stack == null) {
                stack = new ArrayDeque<>();
            }
            stack.push(tag);
        } else // the child attribute of the open tag if required
        if (tag.isClose()) {
            if (stack == null) {
                throw new WicketParseException("Missing open tag for Enclosure:", tag);
            }
            // Remove the open tag from the stack
            ComponentTag lastEnclosure = stack.pop();
            // then ...
            if (childId != null) {
                lastEnclosure.put(CHILD_ATTRIBUTE, childId);
                lastEnclosure.setModified(true);
                childId = null;
            }
            if (stack.size() == 0) {
                stack = null;
            }
        } else {
            throw new WicketParseException("Open-close tag not allowed for Enclosure:", tag);
        }
    } else // Are we inside a wicket:enclosure tag?
    if (stack != null) {
        ComponentTag lastEnclosure = stack.getFirst();
        // If the enclosure tag has NO child attribute, then ...
        if (Strings.isEmpty(lastEnclosure.getAttribute(CHILD_ATTRIBUTE))) {
            String id = tag.getAttribute(getWicketNamespace() + ":id");
            if (id != null) {
                // isVisible() to => Exception
                if (childId != null) {
                    throw new WicketParseException("Use <" + getWicketNamespace() + ":enclosure child='xxx'> to name the child component:", tag);
                }
                // Remember the child id. The open tag will be updated
                // once the close tag is found. See above.
                childId = id;
            }
        }
    }
    return tag;
}
Also used : WicketTag(org.apache.wicket.markup.WicketTag) ComponentTag(org.apache.wicket.markup.ComponentTag) WicketParseException(org.apache.wicket.markup.WicketParseException)

Example 5 with WicketTag

use of org.apache.wicket.markup.WicketTag in project wicket by apache.

the class WicketLinkTagHandler method onComponentTag.

@Override
protected final MarkupElement onComponentTag(ComponentTag tag) throws ParseException {
    // parser through Application.newMarkupParser().
    if ((autolinking == true) && (analyzeAutolinkCondition(tag) == true)) {
        // Mark it as autolink enabled
        tag.enableAutolink(true);
        // Just a dummy name. The ComponentTag will not be forwarded.
        tag.setId(AUTOLINK_ID + getRequestUniqueId());
        tag.setAutoComponentTag(true);
        tag.setModified(true);
        return tag;
    }
    // current autolink status.
    if (tag instanceof WicketTag) {
        final WicketTag wtag = (WicketTag) tag;
        if (wtag.isLinkTag()) {
            // Beginning of the region
            if (tag.isOpen() || tag.isOpenClose()) {
                if (tag.isOpen()) {
                    if (autolinkStatus == null) {
                        autolinkStatus = new ArrayListStack<>();
                    }
                    // remember the current setting to be reset after the
                    // region
                    autolinkStatus.push(autolinking);
                }
                // html allows to represent true in different ways
                final String autolink = tag.getAttributes().getString("autolink");
                try {
                    autolinking = Strings.isEmpty(autolink) || Strings.isTrue(autolink);
                } catch (StringValueConversionException e) {
                    throw new WicketRuntimeException("Invalid autolink attribute value \"" + autolink + "\"");
                }
            } else if (tag.isClose()) {
                // restore the autolink setting from before the region
                autolinking = autolinkStatus.pop();
            }
            return wtag;
        }
    }
    return tag;
}
Also used : WicketTag(org.apache.wicket.markup.WicketTag) StringValueConversionException(org.apache.wicket.util.string.StringValueConversionException) WicketRuntimeException(org.apache.wicket.WicketRuntimeException)

Aggregations

WicketTag (org.apache.wicket.markup.WicketTag)15 ComponentTag (org.apache.wicket.markup.ComponentTag)7 MarkupElement (org.apache.wicket.markup.MarkupElement)5 MarkupStream (org.apache.wicket.markup.MarkupStream)5 WicketRuntimeException (org.apache.wicket.WicketRuntimeException)4 MarkupException (org.apache.wicket.markup.MarkupException)3 Component (org.apache.wicket.Component)2 MarkupContainer (org.apache.wicket.MarkupContainer)2 IMarkupFragment (org.apache.wicket.markup.IMarkupFragment)2 WicketParseException (org.apache.wicket.markup.WicketParseException)2 Response (org.apache.wicket.request.Response)2 ParseException (java.text.ParseException)1 Iterator (java.util.Iterator)1 Behavior (org.apache.wicket.behavior.Behavior)1 ComponentNotFoundException (org.apache.wicket.core.request.handler.ComponentNotFoundException)1 Markup (org.apache.wicket.markup.Markup)1 MarkupNotFoundException (org.apache.wicket.markup.MarkupNotFoundException)1 AutoLabel (org.apache.wicket.markup.html.form.AutoLabelResolver.AutoLabel)1 InlineEnclosure (org.apache.wicket.markup.html.internal.InlineEnclosure)1 ExceptionSettings (org.apache.wicket.settings.ExceptionSettings)1