use of org.apache.wicket.markup.MarkupException in project wicket by apache.
the class Component method internalRenderComponent.
/**
* THIS METHOD IS NOT PART OF THE WICKET PUBLIC API. DO NOT USE IT!
* <p>
* Renders the component at the current position in the given markup stream. The method
* onComponentTag() is called to allow the component to mutate the start tag. The method
* onComponentTagBody() is then called to permit the component to render its body.
*/
protected final void internalRenderComponent() {
final IMarkupFragment markup = getMarkup();
if (markup == null) {
throw new MarkupException("Markup not found. Component: " + toString());
}
final MarkupStream markupStream = new MarkupStream(markup);
// Get mutable copy of next tag
final ComponentTag openTag = markupStream.getTag();
final ComponentTag tag = openTag.mutable();
// Call any tag handler
onComponentTag(tag);
// If we're an openclose tag
if (!tag.isOpenClose() && !tag.isOpen()) {
// We were something other than <tag> or <tag/>
markupStream.throwMarkupException("Method renderComponent called on bad markup element: " + tag);
}
if (tag.isOpenClose() && openTag.isOpen()) {
markupStream.throwMarkupException("You can not modify a open tag to open-close: " + tag);
}
try {
// Render open tag
boolean renderBodyOnly = getRenderBodyOnly();
if (renderBodyOnly) {
ExceptionSettings.NotRenderableErrorStrategy notRenderableErrorStrategy = ExceptionSettings.NotRenderableErrorStrategy.LOG_WARNING;
if (Application.exists()) {
notRenderableErrorStrategy = getApplication().getExceptionSettings().getNotRenderableErrorStrategy();
}
if (getFlag(FLAG_OUTPUT_MARKUP_ID)) {
String message = String.format("Markup id set on a component that renders its body only. " + "Markup id: %s, component id: %s.", getMarkupId(), getId());
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 renders its body only. " + "Component id: %s.", getId());
if (notRenderableErrorStrategy == ExceptionSettings.NotRenderableErrorStrategy.THROW_EXCEPTION) {
throw new IllegalStateException(message);
}
log.warn(message);
}
} else {
renderComponentTag(tag);
}
markupStream.next();
// Render the body only if open-body-close. Do not render if open-close.
if (tag.isOpen()) {
// Render the body. The default strategy will simply call the component's
// onComponentTagBody() implementation.
getMarkupSourcingStrategy().onComponentTagBody(this, markupStream, tag);
// Render close tag
if (openTag.isOpen()) {
renderClosingComponentTag(markupStream, tag, renderBodyOnly);
} else if (renderBodyOnly == false) {
if (needToRenderTag(openTag)) {
// Close the manually opened tag. And since the user might have changed the
// tag name ...
getResponse().write(tag.syntheticCloseTagString());
}
}
}
} catch (WicketRuntimeException wre) {
throw wre;
} catch (RuntimeException re) {
throw new WicketRuntimeException("Exception in rendering component: " + this, re);
}
}
use of org.apache.wicket.markup.MarkupException in project wicket by apache.
the class MarkupContainer method addedComponent.
/**
* @param child
* Component being added
*/
private void addedComponent(final Component child) {
// Check for degenerate case
Args.notNull(child, "child");
MarkupContainer parent = child.getParent();
if (parent != null && parent != this) {
parent.remove(child);
}
// Set child's parent
child.setParent(this);
final DebugSettings debugSettings = Application.get().getDebugSettings();
if (debugSettings.isLinePreciseReportingOnAddComponentEnabled() && debugSettings.getComponentUseCheck()) {
child.setMetaData(ADDED_AT_KEY, ComponentStrings.toString(child, new MarkupException("added")));
}
Page page = findPage();
if (page != null) {
// tell the page a component has been added first, to allow it to initialize
page.componentAdded(child);
// initialize the component
if (page.isInitialized()) {
child.internalInitialize();
}
}
// beforeRender on this component's children. So we need to initialize the newly added one
if (isPreparedForRender()) {
child.beforeRender();
}
}
use of org.apache.wicket.markup.MarkupException 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;
}
use of org.apache.wicket.markup.MarkupException 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.MarkupException in project wicket by apache.
the class ExceptionErrorPage method getErrorMessage.
/**
* Converts a Throwable to a string.
*
* @param throwable
* The throwable
* @return The string
*/
public String getErrorMessage(final Throwable throwable) {
if (throwable != null) {
StringBuilder sb = new StringBuilder(256);
// first print the last cause
List<Throwable> al = convertToList(throwable);
int length = al.size() - 1;
Throwable cause = al.get(length);
sb.append("Last cause: ").append(cause.getMessage()).append('\n');
if (throwable instanceof WicketRuntimeException) {
String msg = throwable.getMessage();
if ((msg != null) && (msg.equals(cause.getMessage()) == false)) {
if (throwable instanceof MarkupException) {
MarkupStream stream = ((MarkupException) throwable).getMarkupStream();
if (stream != null) {
String text = "\n" + stream.toString();
if (msg.endsWith(text)) {
msg = msg.substring(0, msg.length() - text.length());
}
}
}
sb.append("WicketMessage: ");
sb.append(msg);
sb.append("\n\n");
}
}
return sb.toString();
} else {
return "[Unknown]";
}
}
Aggregations