source: vlo/branches/to-wicket-1.6-twagoo/vlo_web_app/src/main/java/eu/clarin/cmdi/vlo/pages/ResourceLinkPanel.java @ 4212

Last change on this file since 4212 was 4212, checked in by twagoo, 10 years ago

Branched off keeloo's wicket-6 conversion branch.
Applied a number of fixes to make code properly compilable, runnable (app still doesn't start properly).
To be merged back with keeloo's work.

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