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