Kawai Wiki

Rev

Rev 99 | Rev 193 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
96 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
 
9
import org.kawai.action.PageAction;
10
import org.kawai.model.Page;
11
 
12
public class PageLink implements KCode {
13
 
14
        @Override
15
        public boolean hasBody() {
16
                return false;
17
        }
18
 
19
        @Override
20
        public String getTag() {
21
                return "pageLink";
22
        }
23
 
24
        @Override
25
        public String process(PageContext pageContext, Map<String, String> attrs, String html) throws JspException {
26
 
27
                HttpServletRequest req = (HttpServletRequest) pageContext.getRequest();
28
 
29
                String name = attrs.get("name");
30
                if (name == null) throw new JspException("Name attribute is mandatory for tag pageLink!");
31
 
32
                String text = attrs.get("text");
33
                if (text == null) throw new JspException("Text attribute is mandatory for tag pageLink!");
34
 
99 soliveira 35
                String linkClass = attrs.get("linkClass");
36
                String clickedClass = attrs.get("clickedClass");
98 soliveira 37
 
153 soliveira 38
                String sizeClass = attrs.get("class");
39
                if (sizeClass != null) {
40
                        linkClass = sizeClass;
41
                        clickedClass = sizeClass + "Clicked";
42
                }
43
 
96 soliveira 44
                // check if we are displaying that page...
45
                Page page = (Page) pageContext.findAttribute(PageAction.BODY_COLUMN_KEY);
46
                if (page != null && page.getName().equals(name)) {
99 soliveira 47
                        return "<span" + (clickedClass != null ? " class=\"" + clickedClass + "\"" : "") + ">" + text + "</span>";
96 soliveira 48
                } else {
99 soliveira 49
                        return "<a href=\"" + req.getContextPath() + "/Page.mtw?name=" + name + "\"" + (linkClass != null ? " class=\"" + linkClass + "\"" : "") + ">" + text + "</a>";
96 soliveira 50
                }
51
        }
52
 
53
}