1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.kuali.rice.edl.impl.components;
18
19 import java.util.List;
20
21 import org.apache.commons.lang.StringUtils;
22 import org.kuali.rice.edl.impl.EDLContext;
23 import org.kuali.rice.edl.impl.EDLModelComponent;
24 import org.kuali.rice.edl.impl.EDLXmlUtils;
25 import org.kuali.rice.edl.impl.RequestParser;
26 import org.w3c.dom.Document;
27 import org.w3c.dom.Element;
28
29
30
31
32
33
34
35
36 public class PageHandler implements EDLModelComponent {
37
38 public static final String CURRENT_PAGE = "currentPage";
39 public static final String PREVIOUS_PAGE = "previousPage";
40 public static final String GOTO_PAGE = "edl.gotoPage";
41
42 public void updateDOM(Document dom, Element configElement, EDLContext edlContext) {
43 String currentPage = edlContext.getRequestParser().getParameterValue("edl." + CURRENT_PAGE);
44 String previousPage = edlContext.getRequestParser().getParameterValue("edl." + PREVIOUS_PAGE);
45 String gotoPage = findGotoPage(edlContext.getRequestParser(), currentPage);
46 if (!StringUtils.isBlank(gotoPage)) {
47 previousPage = currentPage;
48 currentPage = gotoPage;
49 }
50 establishCurrentPage(dom, currentPage);
51 establishPreviousPage(dom, previousPage);
52 }
53
54
55
56
57 private String findGotoPage(RequestParser requestParser, String currentPage) {
58 List<String> parameterNames = requestParser.getParameterNames();
59 for (String parameterName : parameterNames) {
60 if (parameterName.startsWith(GOTO_PAGE + ":")) {
61 return parameterName.split(":")[1];
62 }
63 }
64 return null;
65 }
66
67 private void establishCurrentPage(Document dom, String currentPage) {
68 if (!StringUtils.isBlank(currentPage)) {
69 Element currentPageElement = EDLXmlUtils.getOrCreateChildElement(dom.getDocumentElement(), CURRENT_PAGE, true);
70 currentPageElement.appendChild(dom.createTextNode(currentPage));
71 }
72 }
73
74
75 private void establishPreviousPage(Document dom, String previousPage) {
76 if (!StringUtils.isBlank(previousPage)) {
77 Element previousPageElement = EDLXmlUtils.getOrCreateChildElement(dom.getDocumentElement(), PREVIOUS_PAGE, true);
78 previousPageElement.appendChild(dom.createTextNode(previousPage));
79 }
80 }
81
82
83 }