001 package org.hackystat.projectbrowser.imageurl; 002 003 import org.apache.wicket.AttributeModifier; 004 import org.apache.wicket.markup.ComponentTag; 005 import org.apache.wicket.markup.html.WebComponent; 006 import org.apache.wicket.model.Model; 007 008 /** 009 * Provides a component for displaying a URL in an image tag. Taken from: 010 * http://cwiki.apache.org/WICKET/how-to-load-an-external-image.html 011 * 012 * @author Philip Johnson 013 * 014 */ 015 public class ImageUrl extends WebComponent { 016 017 /** The serialization id. */ 018 private static final long serialVersionUID = 1L; 019 020 /** 021 * Construct the component for displaying an image URL. 022 * 023 * @param id The wicket:id. 024 * @param imageUrl The URL to display. 025 */ 026 public ImageUrl(String id, String imageUrl) { 027 super(id); 028 add(new AttributeModifier("src", true, new Model(imageUrl))); 029 setVisible(!(imageUrl == null || imageUrl.equals(""))); 030 } 031 032 /** 033 * How to replace the markup. 034 * @param tag The wicket:id. 035 */ 036 @Override 037 protected void onComponentTag(ComponentTag tag) { 038 super.onComponentTag(tag); 039 checkComponentTag(tag, "img"); 040 } 041 042 }