Kawai Wiki

Rev

Rev 193 | Rev 218 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 193 Rev 206
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
import org.kawai.AppManager;
9
import org.kawai.action.PageAction;
10
import org.kawai.action.PageAction;
10
import org.kawai.model.Page;
11
import org.kawai.model.Page;
-
 
12
import org.mentawai.util.HttpUtils;
11
13
12
/**
14
/**
13
 * KCode class PageLink.
15
 * KCode class PageLink.
14
 *
16
 *
15
 * @author Sergio Oliveira
17
 * @author Sergio Oliveira
16
 *
18
 *
17
 */
19
 */
18
public class PageLink implements KCode {
-
 
-
 
20
public class PageLink extends AbstractKCode {
19
21
20
    /**
22
    /**
21
     * {@inheritDoc}
23
     * {@inheritDoc}
22
     */
24
     */
23
    @Override
25
    @Override
Line 37... Line 39...
37
     * {@inheritDoc}
39
     * {@inheritDoc}
38
     */
40
     */
39
    @Override
41
    @Override
40
    public String process(PageContext pageContext, Map<String, String> attrs, String html) throws JspException {
42
    public String process(PageContext pageContext, Map<String, String> attrs, String html) throws JspException {
41
43
42
        HttpServletRequest req = (HttpServletRequest) pageContext.getRequest();
-
 
-
 
44
        HttpServletRequest req = getRequest(pageContext);
43
45
44
        String name = attrs.get("name");
46
        String name = attrs.get("name");
45
        if (name == null) throw new JspException("Name attribute is mandatory for tag pageLink!");
47
        if (name == null) throw new JspException("Name attribute is mandatory for tag pageLink!");
46
48
47
        String text = attrs.get("text");
49
        String text = attrs.get("text");
48
        if (text == null) throw new JspException("Text attribute is mandatory for tag pageLink!");
50
        if (text == null) throw new JspException("Text attribute is mandatory for tag pageLink!");
-
 
51
       
-
 
52
        String pretty = attrs.get("pretty");
-
 
53
        boolean isPretty = false;
-
 
54
        if (pretty != null) {
-
 
55
                isPretty = Boolean.parseBoolean(pretty);
-
 
56
        }
49
57
50
        String linkClass = attrs.get("linkClass");
58
        String linkClass = attrs.get("linkClass");
51
        String clickedClass = attrs.get("clickedClass");
59
        String clickedClass = attrs.get("clickedClass");
52
60
53
        String sizeClass = attrs.get("class");
61
        String sizeClass = attrs.get("class");
Line 59... Line 67...
59
        // check if we are displaying that page...
67
        // check if we are displaying that page...
60
        Page page = (Page) pageContext.findAttribute(PageAction.BODY_COLUMN_KEY);
68
        Page page = (Page) pageContext.findAttribute(PageAction.BODY_COLUMN_KEY);
61
        if (page != null && page.getName().equals(name)) {
69
        if (page != null && page.getName().equals(name)) {
62
            return "<span" + (clickedClass != null ? " class=\"" + clickedClass + "\"" : "") + ">" + text + "</span>";
70
            return "<span" + (clickedClass != null ? " class=\"" + clickedClass + "\"" : "") + ">" + text + "</span>";
63
        } else {
71
        } else {
64
            return "<a href=\"" + req.getContextPath() + "/Page.mtw?name=" + name + "\"" + (linkClass != null ? " class=\"" + linkClass + "\"" : "") + ">" + text + "</a>";
-
 
-
 
72
                if (isPretty) {
-
 
73
                        String prettyURL = HttpUtils.getPrettyURL("Page", null, name);
-
 
74
                        return "<a href=\"" + req.getContextPath() + prettyURL + "\"" + (linkClass != null ? " class=\"" + linkClass + "\"" : "") + ">" + text + "</a>";
-
 
75
                } else {
-
 
76
                        return "<a href=\"" + req.getContextPath() + "/Page." + AppManager.EXTENSION + "?name=" + name + "\"" + (linkClass != null ? " class=\"" + linkClass + "\"" : "") + ">" + text + "</a>";
-
 
77
                }
65
        }
78
        }
66
    }
79
    }
67
80
68
}
81
}