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;
}
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;
}
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());
}
}
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;
}
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;
}
Aggregations