Kawai Wiki

Rev

Rev 143 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 143 Rev 194
Line 4... Line 4...
4
4
5
import javax.servlet.http.HttpServletRequest;
5
import javax.servlet.http.HttpServletRequest;
6
import javax.servlet.jsp.JspException;
6
import javax.servlet.jsp.JspException;
7
import javax.servlet.jsp.PageContext;
7
import javax.servlet.jsp.PageContext;
8
8
-
 
9
/**
-
 
10
 * KCode class Image.
-
 
11
 *
-
 
12
 * @author Sergio Oliveira
-
 
13
 *
-
 
14
 */
9
public class Image implements KCode {
15
public class Image implements KCode {
10
       
-
 
11
        @Override
-
 
12
        public String getTag() {
-
 
13
                return "img";
-
 
14
        }
-
 
15
       
-
 
16
        @Override
-
 
17
        public boolean hasBody() {
-
 
18
                return false;
-
 
19
        }
-
 
20
       
-
 
21
        @Override
-
 
22
        public String process(PageContext pageContext, Map<String, String> attributes, String body) throws JspException {
-
 
23
                if (body != null) throw new JspException("contextPath tag cannot have a body!");
-
 
24
               
-
 
25
                String filename = attributes.get("file");
-
 
26
               
-
 
27
                if (filename == null) throw new JspException("file attribute is mandatory!");
-
 
28
               
-
 
29
                HttpServletRequest req = (HttpServletRequest) pageContext.getRequest();
-
 
30
                String cp = req.getContextPath();
-
 
31
               
-
 
32
                return "<img src=\"" + cp + "/uploads/images/" + filename + "\" border=\"0\" />";
-
 
33
        }
-
 
34
}
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
}