use of org.apache.wicket.markup.WicketTag 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;
}
use of org.apache.wicket.markup.WicketTag in project wicket by apache.
the class Component method renderComponentTag.
/**
* Writes a simple tag out to the response stream. Any components that might be referenced by
* the tag are ignored. Also undertakes any tag attribute modifications if they have been added
* to the component.
*
* @param tag
* The tag to write
*/
protected final void renderComponentTag(ComponentTag tag) {
if (needToRenderTag(tag)) {
// apply behaviors that are attached to the component tag.
if (tag.hasBehaviors()) {
Iterator<? extends Behavior> tagBehaviors = tag.getBehaviors();
while (tagBehaviors.hasNext()) {
final Behavior behavior = tagBehaviors.next();
if (behavior.isEnabled(this)) {
behavior.onComponentTag(this, tag);
}
behavior.detach(this);
}
}
// Apply behavior modifiers
List<? extends Behavior> behaviors = getBehaviors();
if ((behaviors != null) && !behaviors.isEmpty() && !tag.isClose() && (isIgnoreAttributeModifier() == false)) {
tag = tag.mutable();
for (Behavior behavior : behaviors) {
// Components may reject some behavior components
if (isBehaviorAccepted(behavior)) {
behavior.onComponentTag(this, tag);
}
}
}
if ((tag instanceof WicketTag) && !tag.isClose() && !getFlag(FLAG_IGNORE_ATTRIBUTE_MODIFIER)) {
ExceptionSettings.NotRenderableErrorStrategy notRenderableErrorStrategy = ExceptionSettings.NotRenderableErrorStrategy.LOG_WARNING;
if (Application.exists()) {
notRenderableErrorStrategy = getApplication().getExceptionSettings().getNotRenderableErrorStrategy();
}
String tagName = tag.getNamespace() + ":" + tag.getName();
String componentId = getId();
if (getFlag(FLAG_OUTPUT_MARKUP_ID)) {
String message = String.format("Markup id set on a component that is usually not rendered into markup. " + "Markup id: %s, component id: %s, component tag: %s.", getMarkupId(), componentId, tagName);
if (notRenderableErrorStrategy == ExceptionSettings.NotRenderableErrorStrategy.THROW_EXCEPTION) {
throw new IllegalStateException(message);
}
log.warn(message);
}
if (getFlag(FLAG_PLACEHOLDER)) {
String message = String.format("Placeholder tag set on a component that is usually not rendered into markup. " + "Component id: %s, component tag: %s.", componentId, tagName);
if (notRenderableErrorStrategy == ExceptionSettings.NotRenderableErrorStrategy.THROW_EXCEPTION) {
throw new IllegalStateException(message);
}
log.warn(message);
}
}
// Write the tag
tag.writeOutput(getResponse(), !needToRenderTag(null), getMarkup().getMarkupResourceStream().getWicketNamespace());
}
}
use of org.apache.wicket.markup.WicketTag in project wicket by apache.
the class BorderBehavior method beforeRender.
@Override
public void beforeRender(final Component component) {
final MarkupStream stream = getMarkupStream(component);
final Response response = component.getResponse();
stream.setCurrentIndex(0);
boolean insideBorderMarkup = false;
while (stream.isCurrentIndexInsideTheStream()) {
MarkupElement elem = stream.get();
stream.next();
if (elem instanceof WicketTag) {
WicketTag wTag = (WicketTag) elem;
if (!insideBorderMarkup) {
if (wTag.isBorderTag() && wTag.isOpen()) {
insideBorderMarkup = true;
continue;
} else {
throw new WicketRuntimeException("Unexpected tag encountered in markup of component border " + getClass().getName() + ". Tag: " + wTag.toString() + ", expected tag: <wicket:border>");
}
} else {
if (wTag.isBodyTag()) {
break;
} else {
throw new WicketRuntimeException("Unexpected tag encountered in markup of component border " + getClass().getName() + ". Tag: " + wTag.toString() + ", expected tag: <wicket:body> or </wicket:body>");
}
}
}
if (insideBorderMarkup) {
response.write(elem.toCharSequence());
}
}
if (!stream.isCurrentIndexInsideTheStream()) {
throw new WicketRuntimeException("Markup for component border " + getClass().getName() + " ended prematurely, was expecting </wicket:border>");
}
}
use of org.apache.wicket.markup.WicketTag in project wicket by apache.
the class AutoLabelTextResolver method resolve.
@Override
public Component resolve(MarkupContainer container, MarkupStream markupStream, ComponentTag tag) {
if (tag instanceof WicketTag && "label".equals(tag.getName())) {
// We need to find a FormComponent...
Component related = null;
// ...which could be explicitly specified...
String forAttributeValue = tag.getAttribute("for");
if (forAttributeValue != null) {
Component component = AutoLabelResolver.findRelatedComponent(container, forAttributeValue);
related = component;
}
if (related == null) {
// ...or available through an AutoLabel, either directly above us...
if (container instanceof AutoLabel) {
related = ((AutoLabel) container).getRelatedComponent();
}
if (related == null) {
// ...or perhaps further up...
AutoLabel autoLabel = container.findParent(AutoLabel.class);
if (autoLabel != null) {
related = autoLabel.getRelatedComponent();
}
}
}
if (related == null) {
// ...or it might just not be available.
String forAttr = forAttributeValue != null ? " for=\"" + forAttributeValue + "\"" : "";
throw new ComponentNotFoundException("no related component found for <wicket:label" + forAttr + ">");
} else {
// ...found the form component, so we can return our label.
return new TextLabel(tag.getId(), related);
}
}
return null;
}
use of org.apache.wicket.markup.WicketTag in project wicket by apache.
the class WicketMessageResolver method resolve.
@Override
public Component resolve(final MarkupContainer container, final MarkupStream markupStream, final ComponentTag tag) {
if (tag instanceof WicketTag) {
WicketTag wtag = (WicketTag) tag;
if (wtag.isMessageTag()) {
IValueMap attributes = wtag.getAttributes();
String messageKey = attributes.getString(KEY_ATTRIBUTE);
if (Strings.isEmpty(messageKey)) {
throw new MarkupException("Wrong format of <wicket:message key='xxx'>: attribute 'key' is missing");
}
boolean escape = attributes.getBoolean(ESCAPE_ATTRIBUTE);
final String id = wtag.getId();
MessageContainer label = new MessageContainer(id, messageKey, escape);
label.setRenderBodyOnly(container.getApplication().getMarkupSettings().getStripWicketTags());
return label;
}
}
// We were not able to handle the tag
return null;
}
Aggregations