1 | |
---|
2 | package eu.clarin.cmdi.vlo.pages; |
---|
3 | |
---|
4 | import eu.clarin.cmdi.vlo.CommonUtils; |
---|
5 | import eu.clarin.cmdi.vlo.FacetConstants; |
---|
6 | import java.util.HashMap; |
---|
7 | import java.util.Map; |
---|
8 | import org.apache.wicket.AttributeModifier; |
---|
9 | import org.apache.wicket.behavior.SimpleAttributeModifier; |
---|
10 | import org.apache.wicket.markup.html.basic.Label; |
---|
11 | import org.apache.wicket.markup.html.image.Image; |
---|
12 | import org.apache.wicket.markup.html.link.ExternalLink; |
---|
13 | import org.apache.wicket.resource.ContextRelativeResource; |
---|
14 | import org.slf4j.Logger; |
---|
15 | import org.slf4j.LoggerFactory; |
---|
16 | |
---|
17 | |
---|
18 | /** |
---|
19 | * Panel showing a resource link. |
---|
20 | * |
---|
21 | * In the extension of the link panel class, this class adds a label text and |
---|
22 | * an icon that is specific for search page links. |
---|
23 | */ |
---|
24 | public class ResourceLinkPanel extends LinkPanel { |
---|
25 | |
---|
26 | private final static Logger LOG = |
---|
27 | LoggerFactory.getLogger(ResourceLinkPanel.class); |
---|
28 | |
---|
29 | private static final long serialVersionUID = 1L; |
---|
30 | |
---|
31 | private final static String URN_NBN_RESOLVER_URL = |
---|
32 | "http://www.nbn-resolving.org/redirect/"; |
---|
33 | |
---|
34 | private final static ImageResource ANNOTATION = new ImageResource("Images/text-x-log.png", "Annotation file"); |
---|
35 | private final static ImageResource AUDIO = new ImageResource("Images/audio-x-generic.png", "Audio file"); |
---|
36 | private final static ImageResource IMAGE = new ImageResource("Images/image-x-generic.png", "Image file"); |
---|
37 | private final static ImageResource TEXT = new ImageResource("Images/text-x-generic.png", "Text file"); |
---|
38 | private final static ImageResource VIDEO = new ImageResource("Images/video-x-generic.png", "Video file"); |
---|
39 | |
---|
40 | private final static Map<String, ImageResource> ICON_MAP = new |
---|
41 | HashMap<String, ImageResource>(); |
---|
42 | static { |
---|
43 | ICON_MAP.put(FacetConstants.RESOURCE_TYPE_AUDIO, AUDIO); |
---|
44 | ICON_MAP.put(FacetConstants.RESOURCE_TYPE_VIDEO, VIDEO); |
---|
45 | ICON_MAP.put(FacetConstants.RESOURCE_TYPE_TEXT, TEXT); |
---|
46 | ICON_MAP.put(FacetConstants.RESOURCE_TYPE_IMAGE, IMAGE); |
---|
47 | ICON_MAP.put(FacetConstants.RESOURCE_TYPE_ANNOTATION, ANNOTATION); |
---|
48 | } |
---|
49 | |
---|
50 | /** |
---|
51 | * Panel constructor |
---|
52 | * |
---|
53 | * @param id Wicket mark up identifier |
---|
54 | * @param mimeType mime type of the resource indicated |
---|
55 | * @param resourceLink URL to pointing to the resource |
---|
56 | */ |
---|
57 | public ResourceLinkPanel(String id, String mimeType, String resourceLink) { |
---|
58 | super(id); |
---|
59 | ImageResource imageResouce = getImage(mimeType); |
---|
60 | Image resourceImg = new Image("resourceImage", imageResouce.getResource()); |
---|
61 | String title = imageResouce.getTitle() + " (" + mimeType + ")"; |
---|
62 | resourceImg.add(new AttributeModifier("title", title)); |
---|
63 | resourceImg.add(new AttributeModifier("alt", title)); |
---|
64 | String href = getHref(resourceLink); |
---|
65 | String name = getNameFromLink(resourceLink); |
---|
66 | ExternalLink link = new ExternalLink("resourceLink", href); |
---|
67 | link.add(resourceImg); |
---|
68 | link.add(new Label("resourceLabel", name)); |
---|
69 | add(link); |
---|
70 | } |
---|
71 | |
---|
72 | private ImageResource getImage(String mimeType) { |
---|
73 | ImageResource image = ICON_MAP.get(CommonUtils.normalizeMimeType(mimeType)); |
---|
74 | if (image == null) { |
---|
75 | image = TEXT; //unknow defaults to TEXT |
---|
76 | } |
---|
77 | return image; |
---|
78 | } |
---|
79 | } |
---|