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