use of org.apache.wicket.markup.MarkupElement in project wicket by apache.
the class StyleAndScriptIdentifierTest method postProcess.
/**
* https://issues.apache.org/jira/browse/WICKET-4453
*
* This test wraps rawMarkup in org.apache.wicket.util.string.JavaScriptUtils#SCRIPT_CONTENT_PREFIX
* twice - once in Markup.of() and second in the explicit call to StyleAndScriptIdentifier.postProcess().
* The second time it realizes that the element body is already wrapped and skips it.
*/
@Test
public void postProcess() {
String rawMarkup = "<script>someJS()</script>";
Markup createMarkupElementsMarkup = Markup.of(rawMarkup);
Markup markup = new Markup(createMarkupElementsMarkup.getMarkupResourceStream());
for (MarkupElement markupElement : createMarkupElementsMarkup) {
markup.addMarkupElement(markupElement);
}
StyleAndScriptIdentifier filter = new StyleAndScriptIdentifier();
filter.postProcess(markup);
assertEquals("<script>\n/*<![CDATA[*/\nsomeJS()\n/*]]>*/\n</script>", markup.toString(true));
}
use of org.apache.wicket.markup.MarkupElement in project wicket by apache.
the class Component method internalRender.
/**
* Performs a render of this component as part of a Page level render process.
*/
private void internalRender() {
// Make sure there is a markup available for the Component
IMarkupFragment markup = getMarkup();
if (markup == null) {
throw new MarkupNotFoundException("Markup not found for Component: " + toString());
}
// MarkupStream is an Iterator for the markup
MarkupStream markupStream = new MarkupStream(markup);
MarkupElement elem = markup.get(0);
if (elem instanceof ComponentTag) {
// Guarantee that the markupStream is set and determineVisibility not yet tested
// See WICKET-2049
((ComponentTag) elem).onBeforeRender(this, markupStream);
}
// and the isVisible property.
if (determineVisibility()) {
setFlag(FLAG_HAS_BEEN_RENDERED, true);
// Rendering is beginning
if (log.isDebugEnabled()) {
log.debug("Begin render {}", this);
}
try {
notifyBehaviorsComponentBeforeRender();
onRender();
notifyBehaviorsComponentRendered();
// Component has been rendered
rendered();
} catch (RuntimeException ex) {
onException(ex);
}
if (log.isDebugEnabled()) {
log.debug("End render {}", this);
}
} else // elem is null when rendering a page
if ((elem != null) && (elem instanceof ComponentTag)) {
if (getFlag(FLAG_PLACEHOLDER)) {
renderPlaceholderTag((ComponentTag) elem, getResponse());
}
}
}
use of org.apache.wicket.markup.MarkupElement 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.MarkupElement in project wicket by apache.
the class OpenCloseTagExpander method nextElement.
@Override
public MarkupElement nextElement() throws ParseException {
// Did we hold back an elem? Than return that first
if (next != null) {
MarkupElement rtn = next;
next = null;
return rtn;
}
return super.nextElement();
}
use of org.apache.wicket.markup.MarkupElement in project wicket by apache.
the class StyleAndScriptIdentifier method postProcess.
@Override
public void postProcess(Markup markup) {
for (int i = 0; i < markup.size(); i++) {
MarkupElement elem = markup.get(i);
if (elem instanceof ComponentTag) {
ComponentTag open = (ComponentTag) elem;
if (shouldProcess(open)) {
if (open.isOpen() && ((i + 2) < markup.size())) {
MarkupElement body = markup.get(i + 1);
MarkupElement tag2 = markup.get(i + 2);
if ((body instanceof RawMarkup) && (tag2 instanceof ComponentTag)) {
ComponentTag close = (ComponentTag) tag2;
if (close.closes(open)) {
String text = body.toString().trim();
if (shouldWrapInCdata(text)) {
text = JavaScriptUtils.SCRIPT_CONTENT_PREFIX + body.toString() + JavaScriptUtils.SCRIPT_CONTENT_SUFFIX;
markup.replace(i + 1, new RawMarkup(text));
}
}
}
}
}
}
}
}
Aggregations