|
| 1 | +/** |
| 2 | + * This Source Code Form is subject to the terms of the Mozilla Public License, |
| 3 | + * v. 2.0. If a copy of the MPL was not distributed with this file, You can |
| 4 | + * obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under |
| 5 | + * the terms of the Healthcare Disclaimer located at http://openmrs.org/license. |
| 6 | + * |
| 7 | + * Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS |
| 8 | + * graphic logo is a trademark of OpenMRS Inc. |
| 9 | + */ |
| 10 | +package org.openmrs.web; |
| 11 | + |
| 12 | +import jakarta.servlet.http.HttpServletRequest; |
| 13 | +import jakarta.servlet.http.HttpServletResponse; |
| 14 | +import org.springframework.web.servlet.ModelAndView; |
| 15 | +import org.springframework.web.servlet.mvc.Controller; |
| 16 | + |
| 17 | +public class StaticResourceDispatcher implements Controller { |
| 18 | + |
| 19 | + private Controller jstlContentController; |
| 20 | + |
| 21 | + private Controller staticContentController; |
| 22 | + |
| 23 | + @Override |
| 24 | + public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception { |
| 25 | + |
| 26 | + String fullPath = request.getRequestURI(); |
| 27 | + |
| 28 | + String ctx = request.getContextPath(); |
| 29 | + if (ctx != null && !ctx.isEmpty() && fullPath.startsWith(ctx)) { |
| 30 | + fullPath = fullPath.substring(ctx.length()); |
| 31 | + } |
| 32 | + |
| 33 | + String lastSegment; |
| 34 | + int slash = fullPath.lastIndexOf('/'); |
| 35 | + if (slash >= 0) { |
| 36 | + lastSegment = fullPath.substring(slash + 1); |
| 37 | + } else { |
| 38 | + lastSegment = fullPath; |
| 39 | + } |
| 40 | + |
| 41 | + if ("openmrsmessages.js".equals(lastSegment) || "drugOrder.js".equals(lastSegment)) { |
| 42 | + return jstlContentController.handleRequest(request, response); |
| 43 | + } |
| 44 | + |
| 45 | + return staticContentController.handleRequest(request, response); |
| 46 | + } |
| 47 | + |
| 48 | + public void setJstlContentController(Controller jstlContentController) { |
| 49 | + this.jstlContentController = jstlContentController; |
| 50 | + } |
| 51 | + |
| 52 | + public void setStaticContentController(Controller staticContentController) { |
| 53 | + this.staticContentController = staticContentController; |
| 54 | + } |
| 55 | +} |
0 commit comments