Kawai Wiki

Rev

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

Rev Author Line No. Line
143 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 Image.
11
 *
12
 * @author Sergio Oliveira
13
 *
14
 */
143 soliveira 15
public class Image implements KCode {
194 helio.frota 16
 
17
    /**
18
     * {@inheritDoc}.
19
     */
20
    @Override
21
    public String getTag() {
22
        return "img";
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
        if (body != null) throw new JspException("contextPath tag cannot have a body!");
39
 
40
        String filename = attributes.get("file");
41
 
42
        if (filename == null) throw new JspException("file attribute is mandatory!");
43
 
44
        HttpServletRequest req = (HttpServletRequest) pageContext.getRequest();
45
        String cp = req.getContextPath();
46
 
47
        return "<img src=\"" + cp + "/uploads/images/" + filename + "\" border=\"0\" />";
48
    }
49
}