0% found this document useful (0 votes)
102 views

Equalize-Xpi-Modules - JSON2XMLConverter - Java at Master Engswee - Equalize-Xpi-Modules GitHub

This document contains the source code for a JSON2XMLConverter Java class. The class extends an AbstractModuleConverter class and contains methods to retrieve module parameters from a ParameterHelper, parse JSON input contents, and generate an XML byte array output by constructing a ConversionDOMOutput object and passing the JSON contents to its generateDOMOutput method. Exceptions are caught and logged to an AuditLogHelper.

Uploaded by

mohananudeep
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
102 views

Equalize-Xpi-Modules - JSON2XMLConverter - Java at Master Engswee - Equalize-Xpi-Modules GitHub

This document contains the source code for a JSON2XMLConverter Java class. The class extends an AbstractModuleConverter class and contains methods to retrieve module parameters from a ParameterHelper, parse JSON input contents, and generate an XML byte array output by constructing a ConversionDOMOutput object and passing the JSON contents to its generateDOMOutput method. Exceptions are caught and logged to an AuditLogHelper.

Uploaded by

mohananudeep
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

12/23/2020 equalize-xpi-modules/JSON2XMLConverter.

java at master · engswee/equalize-xpi-modules · GitHub

engswee / equalize-xpi-modules

Code Issues Pull requests 1 Actions Projects Security Insigh

master

equalize-xpi-modules / com.equalize.xpi.af.modules.ejb / ejbModule / com / equalize / xpi / af /


modules / json / JSON2XMLConverter.java / Jump to

engswee Introduce end-of-line normalization History

1 contributor

Raw Blame

82 lines (73 sloc) 3.36 KB

1 package com.equalize.xpi.af.modules.json;
2 import java.io.ByteArrayOutputStream;
3 import java.util.ArrayList;
4
5 import com.equalize.xpi.af.modules.util.AbstractModuleConverter;
6 import com.equalize.xpi.af.modules.util.AuditLogHelper;
7 import com.equalize.xpi.af.modules.util.DynamicConfigurationHelper;
8 import com.equalize.xpi.af.modules.util.ParameterHelper;
9 import com.equalize.xpi.util.converter.ConversionDOMOutput;
10 import com.equalize.xpi.util.converter.ConversionJSONInput;
11 import com.equalize.xpi.util.converter.Field;
12 import com.sap.aii.af.lib.mp.module.ModuleException;
13 import com.sap.engine.interfaces.messaging.api.Message;
14 import com.sap.engine.interfaces.messaging.api.auditlog.AuditLogStatus;
15
16 public class JSON2XMLConverter extends AbstractModuleConverter {
17 private ConversionJSONInput jsonIn;
18 private ConversionDOMOutput domOut;
19 private String documentName;
20 private String documentNamespace;
21 private int indentFactor;
22 private boolean escapeInvalidNameStartChar;
23 private boolean mangleInvalidNameChar;
24 private boolean allowArrayAtTop;
25 private String topArrayName;
26 private ArrayList<Field> inputContents;
https://github.com/engswee/equalize-xpi-modules/blob/master/com.equalize.xpi.af.modules.ejb/ejbModule/com/equalize/xpi/af/modules/json/JSON2X… 1/3
12/23/2020 equalize-xpi-modules/JSON2XMLConverter.java at master · engswee/equalize-xpi-modules · GitHub

27
28 public JSON2XMLConverter(Message msg, ParameterHelper param, AuditLogHelper audit, Dynamic
29 super(msg, param, audit, dyncfg, debug);
30 }
31
32 @Override
33 public void retrieveModuleParameters() throws ModuleException {
34 this.documentName = this.param.getMandatoryParameter("documentName");
35 this.documentNamespace = this.param.getMandatoryParameter("documentNamespace");
36 this.indentFactor = this.param.getIntParameter("indentFactor");
37 this.escapeInvalidNameStartChar = this.param.getBoolParameter("escapeInvalidNameSt
38 this.mangleInvalidNameChar = this.param.getBoolParameter("mangleInvalidNameChar",
39 this.allowArrayAtTop = this.param.getBoolParameter("allowArrayAtTop", "N", false);
40 if(this.allowArrayAtTop) {
41 this.topArrayName = this.param.getConditionallyMandatoryParameter("topArra
42 }
43 }
44
45 @Override
46 public void parseInput() throws ModuleException {
47 // Parse input JSON contents
48 String content = this.payload.getText();
49 if(this.allowArrayAtTop) {
50 this.jsonIn = new ConversionJSONInput(content, this.topArrayName);
51 } else {
52 this.jsonIn = new ConversionJSONInput(content);
53 }
54 this.audit.addLog(AuditLogStatus.SUCCESS, "Parsing input JSON");
55 this.inputContents = this.jsonIn.extractJSONContent();
56 }
57
58 @Override
59 public byte[] generateOutput() throws ModuleException {
60 try {
61 // Create output converter and generate output DOM
62 this.domOut = new ConversionDOMOutput(this.documentName, this.documentName
63 this.audit.addLog(AuditLogStatus.SUCCESS, "Constructing output XML");
64
65 // Generate OutputStream from DOM
66 if(this.indentFactor > 0) {
67 this.domOut.setIndentFactor(this.indentFactor);
68 this.audit.addLog(AuditLogStatus.SUCCESS, "Output XML will be inde
69 }
70

71 this.domOut.setEscapeInvalidNameStartChar(this.escapeInvalidNameStartChar)
72 this.domOut.setMangleInvalidNameChar(this.mangleInvalidNameChar);
73
74 ByteArrayOutputStream baos = this.domOut.generateDOMOutput(this.inputConte
https://github.com/engswee/equalize-xpi-modules/blob/master/com.equalize.xpi.af.modules.ejb/ejbModule/com/equalize/xpi/af/modules/json/JSON2X… 2/3
12/23/2020 equalize-xpi-modules/JSON2XMLConverter.java at master · engswee/equalize-xpi-modules · GitHub

75 this.audit.addLog(AuditLogStatus.SUCCESS, "Conversion complete");


76 return baos.toByteArray();
77 } catch (Exception e) {
78 this.audit.addLog(AuditLogStatus.ERROR, e.getMessage());
79 throw new ModuleException(e.getMessage(), e);
80 }
81 }
82 }

https://github.com/engswee/equalize-xpi-modules/blob/master/com.equalize.xpi.af.modules.ejb/ejbModule/com/equalize/xpi/af/modules/json/JSON2X… 3/3

You might also like