use of org.apache.wicket.markup.WicketTag in project wicket by apache.
the class InlineEnclosureHandler method onComponentTag.
@Override
protected MarkupElement onComponentTag(final ComponentTag tag) throws ParseException {
// We only need ComponentTags
if (tag instanceof WicketTag) {
return tag;
}
// Has wicket:enclosure attribute?
String enclosureAttr = getAttribute(tag, null);
if (enclosureAttr != null) {
if (tag.isOpen()) {
// Make sure 'wicket:id' and 'id' are consistent
String htmlId = tag.getAttribute("id");
if ((tag.getId() != null) && !Strings.isEmpty(htmlId) && !htmlId.equals(tag.getId())) {
throw new ParseException("Make sure that 'id' and 'wicket:id' are the same if both are provided. Tag:" + tag.toString(), tag.getPos());
}
// if it doesn't have a wicket-id already, then assign one now.
if (Strings.isEmpty(tag.getId())) {
if (Strings.isEmpty(htmlId)) {
String id = getWicketNamespace() + "_" + INLINE_ENCLOSURE_ID_PREFIX + getRequestUniqueId();
tag.setId(id);
} else {
tag.setId(htmlId);
}
tag.setAutoComponentTag(true);
tag.setAutoComponentFactory(new ComponentTag.IAutoComponentFactory() {
@Override
public Component newComponent(MarkupContainer container, ComponentTag tag) {
String attributeName = getInlineEnclosureAttributeName(null);
String childId = tag.getAttribute(attributeName);
return new InlineEnclosure(tag.getId(), childId);
}
});
tag.setModified(true);
}
// Put the enclosure on the stack. The most current one will be on top
if (enclosures == null) {
enclosures = new ArrayDeque<>();
}
enclosures.push(tag);
} else {
throw new ParseException("Open-close tags don't make sense for InlineEnclosure. Tag:" + tag.toString(), tag.getPos());
}
} else // Are we within an enclosure?
if ((enclosures != null) && (enclosures.size() > 0)) {
// first ComponentTag's id found as the controlling child to the enclosure.
if (tag.isOpen() && (tag.getId() != null) && !(tag instanceof WicketTag) && !tag.isAutoComponentTag()) {
Iterator<ComponentTag> componentTagIterator = enclosures.descendingIterator();
while (componentTagIterator.hasNext()) {
ComponentTag lastEnclosure = componentTagIterator.next();
String attr = getAttribute(lastEnclosure, null);
if (Strings.isEmpty(attr) == true) {
lastEnclosure.getAttributes().put(getInlineEnclosureAttributeName(null), tag.getId());
lastEnclosure.setModified(true);
}
}
} else if (tag.isClose() && tag.closes(enclosures.peek())) {
ComponentTag lastEnclosure = enclosures.pop();
String attr = getAttribute(lastEnclosure, null);
if (Strings.isEmpty(attr) == true) {
throw new ParseException("Did not find any child for InlineEnclosure. Tag:" + lastEnclosure.toString(), tag.getPos());
}
}
}
return tag;
}
use of org.apache.wicket.markup.WicketTag in project wicket by apache.
the class OpenCloseTagExpander method onComponentTag.
@Override
protected MarkupElement onComponentTag(final ComponentTag tag) throws ParseException {
if (tag.isOpenClose()) {
String name = tag.getName();
if (contains(name)) {
if (onFound(tag)) {
next = new ComponentTag(tag.getName(), TagType.CLOSE);
if (getWicketNamespace().equals(tag.getNamespace())) {
next = new WicketTag(next);
}
next.setNamespace(tag.getNamespace());
next.setOpenTag(tag);
next.setModified(true);
}
}
}
return tag;
}
use of org.apache.wicket.markup.WicketTag in project wicket by apache.
the class FragmentMarkupSourcingStrategy method getMarkup.
/**
* Search for the child's markup in the fragment markup.
*/
@Override
public IMarkupFragment getMarkup(final MarkupContainer container, final Component child) {
// Get the markup to search for the fragment markup
IMarkupFragment markup = chooseMarkup(container);
if (markup == null) {
throw new MarkupException("The fragments markup provider has no associated markup. " + "No markup to search for fragment markup with id: " + markupId);
}
// Search for the fragment markup
IMarkupFragment childMarkup = TagUtils.findTagMarkup(markup, markupId, FRAGMENT, 1);
if (childMarkup == null) {
// There is one more option if the markup provider has associated markup
MarkupContainer markupProvider = getMarkupProvider(container);
Markup associatedMarkup = markupProvider.getAssociatedMarkup();
if (associatedMarkup != null) {
markup = associatedMarkup;
if (markup != null) {
childMarkup = markup.find(markupId);
}
}
}
if (childMarkup == null) {
throw new MarkupNotFoundException("No Markup found for Fragment " + markupId + " in providing markup container " + getMarkupProvider(container));
} else {
MarkupElement fragmentTag = childMarkup.get(0);
if ((fragmentTag instanceof WicketTag && ((WicketTag) fragmentTag).isFragmentTag()) == false) {
throw new MarkupNotFoundException("Markup found for Fragment '" + markupId + "' in providing markup container " + getMarkupProvider(container) + " is not a <wicket:fragment> tag");
}
}
if (child == null) {
return childMarkup;
}
// search for the child inside the fragment markup
return childMarkup.find(child.getId());
}
use of org.apache.wicket.markup.WicketTag in project wicket by apache.
the class MarkupContainer method renderNext.
/**
* THIS METHOD IS NOT PART OF THE WICKET PUBLIC API. DO NOT USE OR OVERWRITE IT.
*
* Renders the next element of markup in the given markup stream.
*
* @param markupStream
* The markup stream
* @return true, if element was rendered as RawMarkup
*/
protected boolean renderNext(final MarkupStream markupStream) {
// Get the current markup element
final MarkupElement element = markupStream.get();
// If it's a tag like <wicket..> or <span wicket:id="..." >
if ((element instanceof ComponentTag) && !markupStream.atCloseTag()) {
// Get element as tag
final ComponentTag tag = (ComponentTag) element;
if (tag instanceof WicketTag && ((WicketTag) tag).isFragmentTag()) {
return false;
}
// Get component id
final String id = tag.getId();
// Get the component for the id from the given container
Component component = get(id);
if (component == null) {
component = ComponentResolvers.resolve(this, markupStream, tag, null);
if ((component != null) && (component.getParent() == null)) {
autoAdd(component, markupStream);
} else if (component != null) {
component.setMarkup(markupStream.getMarkupFragment());
}
}
// Failed to find it?
if (component != null) {
component.render();
} else if (tag.getFlag(ComponentTag.RENDER_RAW)) {
// No component found, but "render as raw markup" flag found
if (canRenderRawTag(tag)) {
getResponse().write(element.toCharSequence());
}
return true;
} else {
throwException(markupStream, tag);
}
} else {
// Render as raw markup
if (canRenderRawTag(element)) {
getResponse().write(element.toCharSequence());
}
return true;
}
return false;
}
use of org.apache.wicket.markup.WicketTag in project wicket by apache.
the class MarkupContainer method renderAssociatedMarkup.
/**
* Renders the entire associated markup for a container such as a Border or Panel. Any leading
* or trailing raw markup in the associated markup is skipped.
*
* @param openTagName
* the tag to render the associated markup for
* @param exceptionMessage
* message that will be used for exceptions
*/
public final void renderAssociatedMarkup(final String openTagName, final String exceptionMessage) {
// Get associated markup file for the Border or Panel component
final MarkupStream associatedMarkupStream = new MarkupStream(getMarkup(null));
// Get open tag in associated markup of border component
MarkupElement elem = associatedMarkupStream.get();
if ((elem instanceof ComponentTag) == false) {
associatedMarkupStream.throwMarkupException("Expected the open tag. " + exceptionMessage);
}
// Check for required open tag name
ComponentTag associatedMarkupOpenTag = (ComponentTag) elem;
if (!(associatedMarkupOpenTag.isOpen() && (associatedMarkupOpenTag instanceof WicketTag))) {
associatedMarkupStream.throwMarkupException(exceptionMessage);
}
try {
setIgnoreAttributeModifier(true);
renderComponentTag(associatedMarkupOpenTag);
associatedMarkupStream.next();
String className = null;
final boolean outputClassName = getApplication().getDebugSettings().isOutputMarkupContainerClassName();
if (outputClassName) {
className = Classes.name(getClass());
getResponse().write("<!-- MARKUP FOR ");
getResponse().write(className);
getResponse().write(" BEGIN -->");
}
renderComponentTagBody(associatedMarkupStream, associatedMarkupOpenTag);
if (outputClassName) {
getResponse().write("<!-- MARKUP FOR ");
getResponse().write(className);
getResponse().write(" END -->");
}
renderClosingComponentTag(associatedMarkupStream, associatedMarkupOpenTag, false);
} finally {
setIgnoreAttributeModifier(false);
}
}
Aggregations