Search in sources :

Example 1 with WicketParseException

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

the class TagStack method assertOpenTagFor.

/**
 * Bind close tag with its open tag and pop it from the stack.
 *
 * @param closeTag
 * @throws ParseException
 */
private void assertOpenTagFor(ComponentTag closeTag) throws ParseException {
    // Check that there is something on the stack
    if (stack.size() > 0) {
        // Pop the top tag off the stack
        ComponentTag top = stack.pop();
        // If the name of the current close tag does not match the
        // tag on the stack then we may have a mismatched close tag
        boolean mismatch = !hasEqualTagName(top, closeTag);
        if (mismatch) {
            top.setHasNoCloseTag(true);
            // Pop any simple tags off the top of the stack
            while (mismatch && !requiresCloseTag(top.getName())) {
                top.setHasNoCloseTag(true);
                // Pop simple tag
                if (stack.isEmpty()) {
                    break;
                }
                top = stack.pop();
                // Does new top of stack mismatch too?
                mismatch = !hasEqualTagName(top, closeTag);
            }
            // it must be a real mismatch.
            if (mismatch) {
                throw new ParseException("Tag " + top.toUserDebugString() + " has a mismatched close tag at " + closeTag.toUserDebugString(), top.getPos());
            }
        }
        // Tag matches, so add pointer to matching tag
        closeTag.setOpenTag(top);
    } else {
        throw new WicketParseException("Tag does not have a matching open tag:", closeTag);
    }
}
Also used : ComponentTag(org.apache.wicket.markup.ComponentTag) WicketParseException(org.apache.wicket.markup.WicketParseException) WicketParseException(org.apache.wicket.markup.WicketParseException) ParseException(java.text.ParseException)

Example 2 with WicketParseException

use of org.apache.wicket.markup.WicketParseException 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 3 with WicketParseException

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

the class WicketTagIdentifier method onComponentTag.

/**
 * Get the next tag from the next MarkupFilter in the chain and search for Wicket specific tags.
 * <p>
 * Note: The xml parser - the next MarkupFilter in the chain - returns XmlTags which are a
 * subclass of MarkupElement. The implementation of this filter will return either ComponentTag
 * or WicketTag. Both are subclasses of MarkupElement and both maintain a
 * reference to the XmlTag. But no XmlTag is returned.
 *
 * @see org.apache.wicket.markup.parser.IMarkupFilter#nextElement()
 * @return The next tag from markup to be processed. If {@code null} then no more tags are available
 */
@Override
protected MarkupElement onComponentTag(ComponentTag tag) throws ParseException {
    final String namespace = getWicketNamespace();
    // If the form <tag wicket:id = "value"> is used
    final String wicketIdValue = tag.getAttributes().getString(namespace + ":id");
    // Identify tags with Wicket namespace
    if (namespace.equalsIgnoreCase(tag.getNamespace())) {
        // It is <wicket:...>
        tag = new WicketTag(tag.getXmlTag());
        if (Strings.isEmpty(wicketIdValue)) {
            // Make it a Wicket component.
            tag.setId(namespace + "_" + tag.getName() + getRequestUniqueId());
            tag.setUserData(CONTAINER_INFO, getMarkupResourceStream().getContainerInfo());
            tag.setUserData(MARKUP_CACHE_KEY, getMarkupResourceStream().getCacheKey());
            tag.setModified(true);
            if (isRaw(tag)) {
                tag.setFlag(ComponentTag.RENDER_RAW, true);
            } else if (tag.isClose() == false) {
                tag.setAutoComponentTag(true);
            }
        }
        // If the tag is not a well-known wicket namespace tag
        if (!isWellKnown(tag)) {
            // give up
            throw new WicketParseException("Unknown tag name with Wicket namespace: '" + tag.getName() + "'. Might be you haven't installed the appropriate resolver?", tag);
        }
    }
    if (wicketIdValue != null) {
        if (wicketIdValue.trim().length() == 0) {
            throw new WicketParseException("The wicket:id attribute value must not be empty. May be unmatched quotes?!?", tag);
        }
        // Make it a wicket component. Otherwise it would be RawMarkup
        tag.setId(wicketIdValue);
    }
    return tag;
}
Also used : WicketTag(org.apache.wicket.markup.WicketTag) WicketParseException(org.apache.wicket.markup.WicketParseException)

Example 4 with WicketParseException

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

the class HtmlHandler method onComponentTag.

@Override
protected MarkupElement onComponentTag(final ComponentTag tag) throws ParseException {
    // Check tag type
    if (tag.isOpen()) {
        // Check if open tags contains a "wicket:id" component
        setContainsWicketIdFlag(tag);
        // Push onto stack
        stack.push(tag);
    } else if (tag.isClose()) {
        // Check that there is something on the stack
        if (stack.size() > 0) {
            // Pop the top tag off the stack
            ComponentTag top = stack.pop();
            // If the name of the current close tag does not match the
            // tag on the stack then we may have a mismatched close tag
            boolean mismatch = !hasEqualTagName(top, tag);
            if (mismatch) {
                // Pop any simple tags off the top of the stack
                while (mismatch && !requiresCloseTag(top.getName())) {
                    top.setHasNoCloseTag(true);
                    top.setContainsWicketId(false);
                    // Pop simple tag
                    if (stack.isEmpty()) {
                        break;
                    }
                    top = stack.pop();
                    // Does new top of stack mismatch too?
                    mismatch = !hasEqualTagName(top, tag);
                }
                // it must be a real mismatch.
                if (mismatch) {
                    throw new ParseException("Tag " + top.toUserDebugString() + " has a mismatched close tag at " + tag.toUserDebugString(), top.getPos());
                }
            }
            // Tag matches, so add pointer to matching tag
            tag.setOpenTag(top);
        } else {
            throw new WicketParseException("Tag does not have a matching open tag:", tag);
        }
    } else if (tag.isOpenClose()) {
        // Tag closes itself
        tag.setOpenTag(tag);
    }
    return tag;
}
Also used : ComponentTag(org.apache.wicket.markup.ComponentTag) WicketParseException(org.apache.wicket.markup.WicketParseException) WicketParseException(org.apache.wicket.markup.WicketParseException) ParseException(java.text.ParseException)

Aggregations

WicketParseException (org.apache.wicket.markup.WicketParseException)4 ComponentTag (org.apache.wicket.markup.ComponentTag)3 ParseException (java.text.ParseException)2 WicketTag (org.apache.wicket.markup.WicketTag)2