|
1 | 1 | package org.openmrs.module.initializer.api.loaders;
|
2 | 2 |
|
3 |
| -import java.io.File; |
4 |
| - |
5 | 3 | import org.apache.commons.io.FileUtils;
|
6 | 4 | import org.apache.commons.lang3.StringUtils;
|
7 | 5 | import org.openmrs.EncounterType;
|
|
17 | 15 | import org.w3c.dom.Document;
|
18 | 16 | import org.w3c.dom.Node;
|
19 | 17 |
|
| 18 | +import java.io.File; |
| 19 | +import java.lang.reflect.Method; |
| 20 | + |
20 | 21 | @OpenmrsProfile(modules = { "htmlformentry:*" })
|
21 | 22 | public class HtmlFormsLoader extends BaseFileLoader {
|
22 | 23 |
|
@@ -57,6 +58,22 @@ protected String getFileExtension() {
|
57 | 58 | @Override
|
58 | 59 | protected void load(File file) throws Exception {
|
59 | 60 | String xmlData = FileUtils.readFileToString(file, "UTF-8");
|
| 61 | + // In HFE 5.5.0, a new service method was introduced to save or update an html form from xml |
| 62 | + // If this method is available, use it, otherwise fall back to the legacy implementation here |
| 63 | + try { |
| 64 | + Method method = HtmlFormEntryService.class.getDeclaredMethod("saveHtmlFormFromXml", String.class); |
| 65 | + method.invoke(htmlFormEntryService, xmlData); |
| 66 | + } |
| 67 | + catch (NoSuchMethodException e) { |
| 68 | + loadFromXmlData(xmlData); |
| 69 | + } |
| 70 | + } |
| 71 | + |
| 72 | + /** |
| 73 | + * Legacy implementation that loads an htmlform from XML. This has been moved and enhanced in the |
| 74 | + * HFE module |
| 75 | + */ |
| 76 | + protected void loadFromXmlData(String xmlData) throws Exception { |
60 | 77 | Document doc = HtmlFormEntryUtil.stringToDocument(xmlData);
|
61 | 78 | Node htmlFormNode = HtmlFormEntryUtil.findChild(doc, HTML_FORM_TAG);
|
62 | 79 |
|
|
0 commit comments