List of usage examples for org.apache.wicket.markup MarkupStream next
public MarkupElement next()
From source file:com.lyndir.lhunath.snaplog.webapp.view.MediaView.java
License:Apache License
/** * @param id The wicket ID of this component. * @param model The model that will provide the {@link Media} to show in this view. * @param quality The quality at which to show the {@link Media}. * @param clickable <code>true</code>: The media will be clickable. When clicked, the {@link #onClick(AjaxRequestTarget)} will be * fired.<br> <code>false</code>: The media will not be clickable. There is no need to implement {@link * #onClick(AjaxRequestTarget)}. *///from w w w . j a v a 2 s . com public MediaView(final String id, final IModel<Media> model, final Quality quality, final boolean clickable) { super(id, model); // The media container. WebMarkupContainer media = new WebMarkupContainer("media"); add(media.add(new AttributeAppender("class", new Model<String>(quality.getName()), " "))); // The media image link/container. WebMarkupContainer image; if (clickable) { image = new AjaxFallbackLink<Media>("image", getModel()) { @Override public void onClick(final AjaxRequestTarget target) { MediaView.this.onClick(target); } @Override public boolean isVisible() { return getModelObject() != null; } }; media.add(new CSSClassAttributeAppender("link")); } else image = new WebMarkupContainer("image") { @Override public boolean isVisible() { return getModelObject() != null; } }; media.add(image); media.add(new WebMarkupContainer("tools") { { add(new ExternalLink("original", new LoadableDetachableModel<String>() { @Override protected String load() { try { URL resourceURL = sourceDelegate.findResourceURL(SnaplogSession.get().newToken(), getModelObject(), Quality.ORIGINAL); if (resourceURL == null) // TODO: May want to display something useful to the user like a specific "not-found" thumbnail. return null; return resourceURL.toExternalForm(); } catch (PermissionDeniedException ignored) { // TODO: May want to display something useful to the user like a specific "denied" thumbnail. return null; } } }) { @Override protected void onComponentTagBody(final MarkupStream markupStream, final ComponentTag openTag) { if (!renderAsMini(markupStream, openTag)) super.onComponentTagBody(markupStream, openTag); } }); add(new AjaxLink<Media>("share", getModel()) { @Override public void onClick(final AjaxRequestTarget target) { try { Tab.SHARED.activateWithState(new SharedTabPanel.SharedTabState(getModelObject())); } catch (PermissionDeniedException e) { error(e.getLocalizedMessage()); } } @Override protected void onComponentTagBody(final MarkupStream markupStream, final ComponentTag openTag) { if (!renderAsMini(markupStream, openTag)) super.onComponentTagBody(markupStream, openTag); } @Override public boolean isVisible() { return securityService.hasAccess(Permission.ADMINISTER, SnaplogSession.get().newToken(), getModelObject()); } }); add(new WebMarkupContainer("permissions") { @Override protected void onComponentTagBody(final MarkupStream markupStream, final ComponentTag openTag) { if (!renderAsMini(markupStream, openTag)) super.onComponentTagBody(markupStream, openTag); } @Override public boolean isVisible() { return securityService.hasAccess(Permission.ADMINISTER, SnaplogSession.get().newToken(), getModelObject()); } }); add(new Link<Media>("delete", getModel()) { @Override public void onClick() { try { sourceDelegate.delete(SnaplogSession.get().newToken(), getModelObject()); } catch (PermissionDeniedException e) { error(e.getLocalizedMessage()); } } @Override protected void onComponentTagBody(final MarkupStream markupStream, final ComponentTag openTag) { if (!renderAsMini(markupStream, openTag)) super.onComponentTagBody(markupStream, openTag); } @Override public boolean isVisible() { return securityService.hasAccess(Permission.ADMINISTER, SnaplogSession.get().newToken(), getModelObject()); } }); add(CSSClassAttributeAppender.of(new LoadableDetachableModel<String>() { @Override protected String load() { return isMini(quality) ? "mini" : null; } })); } @Override public boolean isVisible() { return getModelObject() != null; } private boolean renderAsMini(final MarkupStream markupStream, final ComponentTag openTag) { if (isMini(quality)) { // Discard all elements from the markup stream until our close tag. while (markupStream.hasMore()) if (markupStream.next().closes(openTag)) break; replaceComponentTagBody(markupStream, openTag, ""); return true; } return false; } }); image.add(new AttributeModifier("style", true, new LoadableDetachableModel<String>() { @Override protected String load() { try { URL resourceURL = sourceDelegate.findResourceURL(SnaplogSession.get().newToken(), getModelObject(), quality); if (resourceURL == null) // TODO: May want to display something useful to the user like a specific "not-found" thumbnail. return null; return String.format("background-image: url('%s')", resourceURL.toExternalForm()); } catch (PermissionDeniedException ignored) { // TODO: May want to display something useful to the user like a specific "denied" thumbnail. return null; } } })); image.add(new ContextImage("thumb", new LoadableDetachableModel<String>() { @Override protected String load() { logger.dbg("Loading Media: %s, Quality: %s", getModelObject(), quality); try { URL resourceURL = sourceDelegate.findResourceURL(SnaplogSession.get().newToken(), getModelObject(), Quality.THUMBNAIL); if (resourceURL == null) // TODO: May want to display something useful to the user like a specific "not-found" thumbnail. return null; return resourceURL.toExternalForm(); } catch (PermissionDeniedException ignored) { // TODO: May want to display something useful to the user like a specific "denied" thumbnail. return null; } } })); image.add(new ContextImage("full", new LoadableDetachableModel<String>() { @Override protected String load() { try { URL resourceURL = sourceDelegate.findResourceURL(SnaplogSession.get().newToken(), getModelObject(), quality); if (resourceURL == null) // TODO: May want to display something useful to the user like a specific "not-found" thumbnail. return null; return resourceURL.toExternalForm(); } catch (PermissionDeniedException ignored) { // TODO: May want to display something useful to the user like a specific "denied" thumbnail. return null; } } }) { @Override public boolean isVisible() { return quality == Quality.FULLSCREEN; } }); image.add(new Label("caption", new LoadableDetachableModel<String>() { @Override protected String load() { return getCaptionString(); } }) { @Override public boolean isVisible() { return getModelObject() != null; } }); }
From source file:com.servoy.j2db.server.headlessclient.dataui.SortableCellViewHeaders.java
License:Open Source License
/** * Renders the next element of markup in the given markup stream. * /*from w w w. j av a 2 s .c om*/ * @param markupStream The markup stream */ private final void _renderNext(final MarkupStream markupStream) { // Get the current markup element final MarkupElement element = markupStream.get(); // If it a tag like <wicket..> or <span wicket:id="..." > if ((element instanceof ComponentTag) && !markupStream.atCloseTag()) { // Get element as tag final ComponentTag tag = (ComponentTag) element; // Get component id final String id = tag.getId(); // Get the component for the id from the given container final Component component = get(id); // Failed to find it? if (component != null && orderedHeaders.get(renderColumnIdx) != null) { if (component instanceof SortableCellViewHeader) { int currentIdx = markupStream.getCurrentIndex(); renderHeader(renderColumnIdx, markupStream); renderColumnIdx++; markupStream.setCurrentIndex(currentIdx); markupStream.skipComponent(); } } else { // 2rd try: Components like Border and Panel might implement // the ComponentResolver interface as well. MarkupContainer container = this; while (container != null) { if (container instanceof SortableCellViewHeaders) { // we should created the corect header, use the id from the orderedHeaders String headerId = orderedHeaderIds.get(renderColumnIdx); renderColumnIdx++; if (resolve(markupStream, tag, headerId)) { return; } } if (container instanceof IComponentResolver) { if (((IComponentResolver) container).resolve(this, markupStream, tag)) { return; } } container = container.findParent(MarkupContainer.class); } // 3rd try: Try application's component resolvers final List<IComponentResolver> componentResolvers = getApplication().getPageSettings() .getComponentResolvers(); final Iterator<IComponentResolver> iterator = componentResolvers.iterator(); while (iterator.hasNext()) { final IComponentResolver resolver = iterator.next(); if (resolver.resolve(this, markupStream, tag)) { return; } } if (tag instanceof WicketTag) { if (((WicketTag) tag).isChildTag()) { markupStream.throwMarkupException("Found " + tag.toString() + " but no <wicket:extend>"); //$NON-NLS-1$ //$NON-NLS-2$ } else { markupStream.throwMarkupException("Failed to handle: " + tag.toString()); //$NON-NLS-1$ } } // No one was able to handle the component id markupStream.throwMarkupException("Unable to find component with id '" + id + "' in " + this //$NON-NLS-1$//$NON-NLS-2$ + ". This means that you declared wicket:id=" + //$NON-NLS-1$ id + " in your markup, but that you either did not add the " //$NON-NLS-1$ + "component to your page at all, or that the hierarchy does not match."); //$NON-NLS-1$ } } else { getResponse().write(element.toCharSequence()); markupStream.next(); } }
From source file:com.servoy.j2db.server.headlessclient.dataui.SortableCellViewHeaders.java
License:Open Source License
private void renderHeader(int headerIdx, final MarkupStream markupStream) { Component header = orderedHeaders.get(headerIdx); markupStream.setCurrentIndex(headerMarkupStartIdx); boolean found = false; MarkupElement element;/*from w w w . j a va 2 s. com*/ while (!found) { element = markupStream.next(); if ((element instanceof ComponentTag) && !markupStream.atCloseTag()) { // Get element as tag final ComponentTag tag = (ComponentTag) element; // Get component id final String id = tag.getId(); // Get the component for the id from the given container final Component component = get(id); // Failed to find it? if (component != null) { if (component.equals(header)) { component.render(markupStream); found = true; } } } } }
From source file:fiftyfive.wicket.prototype.TruncatedRawMarkup.java
License:Apache License
@Override public void onComponentTagBody(MarkupStream markup, ComponentTag tag) { // We assume the body of the component is raw HTML // (i.e. not nested wicket components or wicket tags). RawMarkup raw = (RawMarkup) markup.get(); getResponse().write(getTruncateHelper().truncate(raw.toString(), this.length)); markup.next(); }
From source file:org.artifactory.common.wicket.component.template.HtmlTemplate.java
License:Open Source License
public static String readBodyMarkup(MarkupStream markupStream, ComponentTag openTag) { StringBuilder innerMarkup = new StringBuilder(); while (markupStream.hasMore()) { if (markupStream.get().closes(openTag)) { return innerMarkup.toString(); }//ww w .java 2s. co m innerMarkup.append(markupStream.get().toCharSequence().toString()); markupStream.next(); } throw new MarkupException(markupStream, "Expected close tag for " + openTag); }
From source file:org.efaps.ui.wicket.components.AbstractParentMarkupContainer.java
License:Apache License
/** * @see org.apache.wicket.MarkupContainer#onRender(org.apache.wicket.markup.MarkupStream) *///from ww w . j av a 2 s. c o m @Override public void onRender() { final IMarkupFragment markup = getMarkup(); final MarkupStream markupStream = new MarkupStream(markup); final int markupStart = markupStream.getCurrentIndex(); // Get mutable copy of next tag final ComponentTag openTag = markupStream.getTag(); final ComponentTag tag = openTag.mutable(); // Call any tag handler onComponentTag(tag); // Render open tag if (!getRenderBodyOnly()) { renderComponentTag(tag); } markupStream.next(); // Render the body only if open-body-close. Do not render if // open-close. if (tag.isOpen()) { // Render the body onComponentTagBody(markupStream, tag); } markupStream.setCurrentIndex(markupStart); final Iterator<?> childs = this.iterator(); while (childs.hasNext()) { markupStream.setCurrentIndex(markupStart); final Component child = (Component) childs.next(); child.rendered(); } markupStream.setCurrentIndex(markupStart); markupStream.next(); // Render close tag if (tag.isOpen()) { if (openTag.isOpen()) { // Get the close tag from the stream ComponentTag closeTag = markupStream.getTag(); // If the open tag had its id changed if (tag.isAutoComponentTag()) { // change the id of the close tag closeTag = closeTag.mutable(); closeTag.setName(tag.getName()); } // Render the close tag renderComponentTag(closeTag); markupStream.next(); } } }
From source file:org.efaps.ui.wicket.components.LabelComponent.java
License:Apache License
/** * Method is overwritten to prevent the annoing warnings from Component to come up. * The warning come up due to the reason that this component moves the tags from parent * element to its child./* w w w.ja v a 2 s . co m*/ */ @Override protected void onRender() { 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); } markupStream.next(); getMarkupSourcingStrategy().onComponentTagBody(this, markupStream, tag); }
From source file:org.wicketstuff.datatable_autocomplete.radio.DTARadio.java
License:Apache License
@Override public void onComponentTagBody(MarkupStream markupStream, ComponentTag openTag) { openTag.setName("input"); markupStream.next(); }