source: vlo/trunk/vlo_web_app/src/main/java/eu/clarin/cmdi/vlo/pages/ResourceLinkPanel.java @ 2829

Last change on this file since 2829 was 2829, checked in by keeloo, 11 years ago

Added support for search page type of resources.

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