Kawai Wiki

Rev

Rev 146 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
146 soliveira 1
package org.kawai.tag.kcode;
2
 
3
import java.util.Map;
4
 
5
import javax.servlet.http.HttpServletRequest;
6
import javax.servlet.jsp.JspException;
7
import javax.servlet.jsp.PageContext;
8
 
194 helio.frota 9
/**
10
 * KCode class Download.
11
 *
12
 * @author Sergio Oliveira
13
 *
14
 */
146 soliveira 15
public class Download implements KCode {
194 helio.frota 16
 
17
    /**
18
     * {@inheritDoc}.
19
     */
20
    @Override
21
    public String getTag() {
22
        return "download";
23
    }
24
 
25
    /**
26
     * {@inheritDoc}.
27
     */
28
    @Override
29
    public boolean hasBody() {
30
        return false;
31
    }
32
 
33
    /**
34
     * {@inheritDoc}.
35
     */
36
    @Override
37
    public String process(PageContext pageContext, Map<String, String> attributes, String body) throws JspException {
38
 
39
        if (body != null) throw new JspException("contextPath tag cannot have a body!");
40
 
41
        String filename = attributes.get("file");
42
 
43
        if (filename == null) throw new JspException("file attribute is mandatory!");
44
 
45
        HttpServletRequest req = (HttpServletRequest) pageContext.getRequest();
46
        String cp = req.getContextPath();
47
 
48
        return "<a href=\"" + cp + "/uploads/archive/" + filename + "\">" + filename + "</a>";
49
    }
50
}