Example usage for org.apache.wicket.markup ComponentTag toUserDebugString

List of usage examples for org.apache.wicket.markup ComponentTag toUserDebugString

Introduction

In this page you can find the example usage for org.apache.wicket.markup ComponentTag toUserDebugString.

Prototype

@Override
public final String toUserDebugString() 

Source Link

Document

Converts this object to a string representation including useful information for debugging

Usage

From source file:com.visural.wicket.component.codebox.CodeBox.java

License:Apache License

@Override
protected void onComponentTag(ComponentTag tag) {
    super.onComponentTag(tag);
    // check applied to code/pre (need to bring some code in from parent as can apply to either)
    if (!tag.getName().equalsIgnoreCase("pre") && !tag.getName().equalsIgnoreCase("code")) {
        findMarkupStream().throwMarkupException("Component " + getId()
                + " must be applied to a tag of type 'code' or 'pre', not " + tag.toUserDebugString());
    }//from  w  w w.  j  av a  2 s.c o  m
    // change display class
    if (getLanguageOverride() == null) {
        tag.put("class", "prettyprint");
    } else {
        tag.put("class", "prettyprint " + getLanguageOverride().getCSSClass());
    }
}

From source file:name.martingeisse.wicket.component.sprite.SpriteImage.java

License:Open Source License

@Override
protected void onComponentTag(ComponentTag tag) {

    // check for allowed tags
    final String originalTagName = tag.getName();
    if (!originalTagName.equalsIgnoreCase("img") && !originalTagName.equalsIgnoreCase("span")
            && !originalTagName.equalsIgnoreCase("div")) {
        String msg = String.format(
                "Component [%s] (path = [%s]) must be applied to a tag of type IMG, SPAN or DIV, not: %s",
                getId(), getPath(), tag.toUserDebugString());
        findMarkupStream().throwMarkupException(msg);
    }//from w w  w .  j a v  a 2  s  .co m

    // make the image generate its resource reference (e.g. from a specified path), ignoring the tag name for now
    try {
        tag.setName("img");
        super.onComponentTag(tag);
    } finally {
        tag.setName(originalTagName);
    }

    // localize the resource reference (including a fallback mechanism for nonexisting resource files)
    ResourceReference resourceReference = getImageResourceReference();
    ResourceReference.UrlAttributes urlAttributes = resourceReference.getUrlAttributes();
    ResourceReference.Key spriteKey = new ResourceReference.Key(resourceReference.getScope().getName(),
            resourceReference.getName(), urlAttributes.getLocale(), urlAttributes.getStyle(),
            urlAttributes.getVariation());

    // look up the sprite and fall back to default behavior if not found
    ApplicationSpriteSupport applicationSpriteSupport = ApplicationSpriteSupport.get(getApplication());
    if (applicationSpriteSupport == null) {
        super.onComponentTag(tag);
        return;
    }
    SpriteRegistry spriteRegistry = applicationSpriteSupport.getSpriteRegistry();
    SpriteReference spriteReference = spriteRegistry.lookup(spriteKey);
    if (spriteReference == null) {
        super.onComponentTag(tag);
        return;
    }

    // IMG tags cannot handle CSS sprites. They're inline, so we convert to a SPAN.
    if (tag.getName().equalsIgnoreCase("img")) {
        tag.setName("span");
    }

    // remove the SRC attribute -- it doesn't hurt, but it's ugly
    tag.getAttributes().remove("src");

    // prepare modification of the style attribute
    StringBuilder styleBuilder;
    String previousStyle = tag.getAttribute("style");
    if (previousStyle == null) {
        styleBuilder = new StringBuilder();
    } else {
        styleBuilder = new StringBuilder(previousStyle).append("; ");
    }

    // SPAN tags must be styled as inline-block to support width/height properly
    if (tag.getName().equalsIgnoreCase("span")) {
        styleBuilder.append("display: inline-block; ");
    }

    // modify the style attribute according to the sprite reference
    styleBuilder.append("background-image: url(").append(spriteReference.getAtlas().getUrl());
    styleBuilder.append("); background-position: -").append(spriteReference.getX());
    styleBuilder.append("px -").append(spriteReference.getY());
    styleBuilder.append("px; width: ").append(spriteReference.getWidth());
    styleBuilder.append("px; height: ").append(spriteReference.getHeight());
    styleBuilder.append("px; ");

    // store modified style
    tag.getAttributes().put("style", styleBuilder.toString());

}

From source file:name.martingeisse.wicketbits.sprite.SpriteImage.java

License:Open Source License

@Override
protected void onComponentTag(ComponentTag tag) {

    // check for allowed tags
    final String originalTagName = tag.getName();
    if (!originalTagName.equalsIgnoreCase("img") && !originalTagName.equalsIgnoreCase("span")
            && !originalTagName.equalsIgnoreCase("div")) {
        String msg = String.format(
                "Component [%s] (path = [%s]) must be applied to a tag of type IMG, SPAN or DIV, not: %s",
                getId(), getPath(), tag.toUserDebugString());
        findMarkupStream().throwMarkupException(msg);
    }//from   w  ww  . j av a 2  s. com

    // make the image generate its resource reference (e.g. from a specified path), ignoring the tag name for now
    try {
        tag.setName("img");
        super.onComponentTag(tag);
    } finally {
        tag.setName(originalTagName);
    }

    // localize the resource reference (including a fallback mechanism for nonexisting resource files)
    ResourceReference resourceReference = getImageResourceReference();
    ResourceReference.UrlAttributes urlAttributes = resourceReference.getUrlAttributes();
    ResourceReference.Key spriteKey = new ResourceReference.Key(resourceReference.getScope().getName(),
            resourceReference.getName(), urlAttributes.getLocale(), urlAttributes.getStyle(),
            urlAttributes.getVariation());

    // look up the sprite and fall back to default behavior if not found
    SpriteRegistry spriteRegistry = ApplicationSpriteSupport.get(getApplication()).getSpriteRegistry();
    SpriteReference spriteReference = spriteRegistry.lookup(spriteKey);
    if (spriteReference == null) {
        super.onComponentTag(tag);
        return;
    }

    // IMG tags cannot handle CSS sprites. They're inline, so we convert to a SPAN.
    if (tag.getName().equalsIgnoreCase("img")) {
        tag.setName("span");
    }

    // remove the SRC attribute -- it doesn't hurt, but it's ugly
    tag.getAttributes().remove("src");

    // prepare modification of the style attribute
    StringBuilder styleBuilder;
    String previousStyle = tag.getAttribute("style");
    if (previousStyle == null) {
        styleBuilder = new StringBuilder();
    } else {
        styleBuilder = new StringBuilder(previousStyle).append("; ");
    }

    // SPAN tags must be styled as inline-block to support width/height properly
    if (tag.getName().equalsIgnoreCase("span")) {
        styleBuilder.append("display: inline-block; ");
    }

    // modify the style attribute according to the sprite reference
    styleBuilder.append("background-image: url(").append(spriteReference.getAtlas().getUrl());
    styleBuilder.append("); background-position: -").append(spriteReference.getX());
    styleBuilder.append("px -").append(spriteReference.getY());
    styleBuilder.append("px; width: ").append(spriteReference.getWidth());
    styleBuilder.append("px; height: ").append(spriteReference.getHeight());
    styleBuilder.append("px; ");

    // store modified style
    tag.getAttributes().put("style", styleBuilder.toString());

}

From source file:net.dontdrinkandroot.wicket.component.basic.AbstractList.java

License:Apache License

protected final void checkComponentTag(final ComponentTag tag, String... names) {

    for (String name : names) {
        if (tag.getName().equals(name)) {
            return;
        }/*from   ww  w  .  j ava 2  s .com*/
    }

    String joinedNames = Strings.join(",", names);
    String msg = String.format("Component [%s] (path = [%s]) must be applied to a tag of type [%s], not: %s",
            this.getId(), this.getPath(), joinedNames, tag.toUserDebugString());

    this.findMarkupStream().throwMarkupException(msg);
}

From source file:org.odlabs.wiquery.ui.button.ButtonBehavior.java

License:Open Source License

@Override
public void onComponentTag(ComponentTag tag) {
    String tagname = tag.getName();

    if (!tagname.equalsIgnoreCase("input") && !tagname.equalsIgnoreCase("button")
            && !tagname.equalsIgnoreCase("submit") && !tagname.equalsIgnoreCase("reset")
            && !tagname.equalsIgnoreCase("a")) {
        throw new WicketRuntimeException("Component " + getComponent().getId()
                + " must be applied to a tag of type 'input', 'button' or 'a', not " + tag.toUserDebugString());
    }/*from  w  w w.  j a  va 2s. c o  m*/

    super.onComponentTag(tag);
}

From source file:org.wicketstuff.jasperreports.EmbeddedJRReport.java

License:Apache License

/**
 * Make sure we work only with object tags
 * /*from   w ww.  j a v  a2  s  .  c  o  m*/
 * @param tag
 *            tag applied to component.
 * @see org.apache.wicket.Component#onComponentTag(org.apache.wicket.markup.ComponentTag)
 */
@Override
protected void onComponentTag(ComponentTag tag) {
    if (!"object".equalsIgnoreCase(tag.getName())) {
        findMarkupStream().throwMarkupException("Component " + getId()
                + " must be applied to a tag of type 'object' not " + tag.toUserDebugString());
    }
    tag.put("data", getResponse().encodeURL(urlFor(IResourceListener.INTERFACE, null)));
    tag.put("type", resource.getContentType());
    super.onComponentTag(tag);
}

From source file:wicket.contrib.jasperreports.view.EmbeddedJRReport.java

License:Apache License

/**
 * @see wicket.Component#onComponentTag(wicket.markup.ComponentTag)
 *//*from   w  w w.j av  a 2s  .c  om*/
protected void onComponentTag(ComponentTag tag) {
    if (!"embed".equalsIgnoreCase(tag.getName())) {
        findMarkupStream().throwMarkupException("Component " + getId()
                + " must be applied to a tag of type 'object' not " + tag.toUserDebugString());
    }
    tag.put("src", getResponse().encodeURL(urlFor(IResourceListener.INTERFACE)));
    tag.put("type", resource.getContentType());
    super.onComponentTag(tag);

}