| 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 | 0 | 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 | 0 | String currentPage = edlContext.getRequestParser().getParameterValue("edl." + CURRENT_PAGE); |
| 43 | 0 | String previousPage = edlContext.getRequestParser().getParameterValue("edl." + PREVIOUS_PAGE); |
| 44 | 0 | String gotoPage = findGotoPage(edlContext.getRequestParser(), currentPage); |
| 45 | 0 | if (!StringUtils.isBlank(gotoPage)) { |
| 46 | 0 | previousPage = currentPage; |
| 47 | 0 | currentPage = gotoPage; |
| 48 | |
} |
| 49 | 0 | establishCurrentPage(dom, currentPage); |
| 50 | 0 | establishPreviousPage(dom, previousPage); |
| 51 | 0 | } |
| 52 | |
|
| 53 | |
|
| 54 | |
|
| 55 | |
|
| 56 | |
private String findGotoPage(RequestParser requestParser, String currentPage) { |
| 57 | 0 | List<String> parameterNames = requestParser.getParameterNames(); |
| 58 | 0 | for (String parameterName : parameterNames) { |
| 59 | 0 | if (parameterName.startsWith(GOTO_PAGE + ":")) { |
| 60 | 0 | return parameterName.split(":")[1]; |
| 61 | |
} |
| 62 | |
} |
| 63 | 0 | return null; |
| 64 | |
} |
| 65 | |
|
| 66 | |
private void establishCurrentPage(Document dom, String currentPage) { |
| 67 | 0 | if (!StringUtils.isBlank(currentPage)) { |
| 68 | 0 | Element currentPageElement = EDLXmlUtils.getOrCreateChildElement(dom.getDocumentElement(), CURRENT_PAGE, true); |
| 69 | 0 | currentPageElement.appendChild(dom.createTextNode(currentPage)); |
| 70 | |
} |
| 71 | 0 | } |
| 72 | |
|
| 73 | |
|
| 74 | |
private void establishPreviousPage(Document dom, String previousPage) { |
| 75 | 0 | if (!StringUtils.isBlank(previousPage)) { |
| 76 | 0 | Element previousPageElement = EDLXmlUtils.getOrCreateChildElement(dom.getDocumentElement(), PREVIOUS_PAGE, true); |
| 77 | 0 | previousPageElement.appendChild(dom.createTextNode(previousPage)); |
| 78 | |
} |
| 79 | 0 | } |
| 80 | |
|
| 81 | |
|
| 82 | |
} |