Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
web-ui
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
WEBGDE-Components
web-ui
Commits
94bd47ba
Commit
94bd47ba
authored
Nov 22, 2023
by
Owen Ryan Ang
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'feature-doctype-update' into 'development-mobile'
Feature doctype update See merge request
!76
parents
52c263e4
f7d141dc
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
243 additions
and
69 deletions
+243
-69
getElement.js
WebGde/WebContent/WebGde-Widgets/BPO/getElement.js
+1
-1
config.js
WebGde/WebContent/WebGde-Widgets/DataInputWidget/config.js
+2
-2
generateFields.js
...bContent/WebGde-Widgets/DataInputWidget/generateFields.js
+62
-20
validateInput.js
...ebContent/WebGde-Widgets/DataInputWidget/validateInput.js
+17
-2
XML_Saver.js
...e/WebContent/WebGde-Widgets/Submit/XMLWriter/XML_Saver.js
+40
-11
config.js
WebGde/WebContent/WebGde-Widgets/config.js
+2
-2
Navotas 2.json
...de/WebContent/WebGde-Widgets/sample_schema/Navotas 2.json
+0
-0
Field.java
...rc/main/java/com/svi/webgde/restservice/object/Field.java
+4
-0
Record.java
...c/main/java/com/svi/webgde/restservice/object/Record.java
+4
-0
SubRecord.java
...ain/java/com/svi/webgde/restservice/object/SubRecord.java
+44
-0
XMLContents.java
...n/java/com/svi/webgde/restservice/object/XMLContents.java
+12
-1
XMLUtil.java
...c/main/java/com/svi/webgde/restservice/utils/XMLUtil.java
+55
-30
No files found.
WebGde/WebContent/WebGde-Widgets/BPO/getElement.js
View file @
94bd47ba
...
...
@@ -167,7 +167,7 @@ export class BPO {
async
getMobileFieldData
()
{
let
elementId
=
sessionStorage
.
getItem
(
"element_id"
);
let
xmlData
=
{
"outputDir"
:
sessionStorage
.
getItem
(
"element_file_loc"
)
+
"/"
+
(
ENCODING_PASS
==
"PASS1"
?
elementId
+
".DTA"
:
elementId
+
".DTB"
)
"outputDir"
:
sessionStorage
.
getItem
(
"element_file_loc"
)
+
"/"
+
elementId
+
".DFC"
}
let
response
=
await
fetch
(
urlGetMobileFields
,
{
...
...
WebGde/WebContent/WebGde-Widgets/DataInputWidget/config.js
View file @
94bd47ba
//Data Input Field Config
export
var
SCHEMA_FILE_PATH
=
"./WebGde-Widgets/sample_schema/schema_sqa.json"
;
// export var SCHEMA_FILE_PATH = "./WebGde-Widgets/sample_schema/HR Speed Test schema.json";
export
var
SCHEMA_FILE_PATH
=
"./WebGde-Widgets/sample_schema/Navotas 2.json"
;
//DBLookup Webservice URL
export
var
DB_URL
=
"http://localhost:8080/WebGde/svc/gfs-rest/db-lookup"
\ No newline at end of file
WebGde/WebContent/WebGde-Widgets/DataInputWidget/generateFields.js
View file @
94bd47ba
...
...
@@ -15,6 +15,7 @@ let newOption;
export
let
schema
;
export
async
function
generateFields
(
inputSchema
,
containerId
)
{
window
.
populateFields
=
populateFields
;
schema
=
inputSchema
;
let
divContainer
=
document
.
getElementById
(
containerId
);
...
...
@@ -197,10 +198,8 @@ export async function generateFields(inputSchema, containerId) {
$
(
document
).
ready
(
function
()
{
$
(
'form:first *:input[type!=hidden]:first'
).
focus
();
// Run code
});
}
}
...
...
@@ -242,6 +241,32 @@ const noValidation = (key) => {
* @returns
* created input field element
*/
const
inputHidden
=
(
key
,
validation
)
=>
{
try
{
const
input
=
document
.
createElement
(
'textarea'
);
input
.
setAttribute
(
'rows'
,
5
);
input
.
setAttribute
(
'id'
,
key
);
input
.
setAttribute
(
'name'
,
key
);
input
.
setAttribute
(
'cols'
,
30
);
input
.
setAttribute
(
'autocomplete'
,
'off'
);
input
.
setAttribute
(
'inputMode'
,
validation
.
collection
===
'email'
?
'email'
:
'text'
);
input
.
addEventListener
(
'focusout'
,
handleInput
);
return
input
;
}
catch
(
err
)
{
throw
err
;
}
}
/**
*
* @param {*} key
* will serve as id of input field
* @param {*} validation
* validation of field from schema
* @returns
* created input field element
*/
const
inputString
=
(
key
,
validation
)
=>
{
try
{
const
{
...
...
@@ -1829,21 +1854,37 @@ const deconstruct = async (section, container, classAttribute) => {
fieldLabel, hidden
} = section[key]
// Create hidden input for fields with hidden="y"
// if (hidden && hidden.toLowerCase() === "y") {
// const hiddenInput = document.createElement('
input
');
// hiddenInput.setAttribute('
type
', '
hidden
');
// hiddenInput.setAttribute('
name
', key);
// hiddenInput.setAttribute('
value
', ''); // Set the value as needed
const validation = getValidation(key, schema)
// // Append the hidden input to the container
// container.appendChild(hiddenInput);
if (hidden) {
const hiddenField = document.createElement('
div
') // will contain input field and label
hiddenField.setAttribute('
class
', '
fieldContainer
' + classAttribute)
container.appendChild(hiddenField)
// // Skip creating other visible input elements for hidden fields
// continue;
// }
const labelContainer = document.createElement('
div
') // name beside input field
labelContainer.setAttribute('
class
', '
labelContainer
' + classAttribute)
hiddenField.appendChild(labelContainer)
const validation = getValidation(key, schema)
const label = document.createElement('
label
')
label.textContent = fieldLabel ? fieldLabel : `Missing label`
label.style.color = fieldLabel ? '
#
000000
' : '
#
ff3333
'
labelContainer.appendChild(label)
const inputContainer = document.createElement('
div
') // input field
inputContainer.setAttribute('
class
', '
inputContainer
' + classAttribute)
hiddenField.appendChild(inputContainer)
// default hiddeninputs to String
const hiddenInput = inputHidden(key, schema);
hiddenInput.setAttribute('
class
', classAttribute)
inputContainer.appendChild(hiddenInput);
hiddenField.style.display = '
none
'; // Hide the input
hiddenField.classList.add('
hidden
'); // Add '
hidden
' class
continue;
}
const newField = document.createElement('
div
') // will contain input field and label
newField.setAttribute('
class
', '
fieldContainer
' + classAttribute)
...
...
@@ -1924,10 +1965,6 @@ const deconstruct = async (section, container, classAttribute) => {
}
input.setAttribute('
class
', classAttribute)
inputContainer.appendChild(input)
if (hidden && hidden.toLowerCase() === '
y
') {
newField.style.display = '
none
'; // Hide the input
newField.classList.add('
hidden
'); // Add '
hidden
' class
}
}
//keys na drop down
...
...
@@ -2226,10 +2263,15 @@ export async function populateFields() {
for (let key of Object.keys(schema[doctype][section])) {
if (schema[doctype][section][key].aka == "field" + k) {
//console.log("key = " + key
);
console.log("key = " + key + +", value ="+v
);
//console.log("validation: " + schema[doctype][section][key].validation.collection);
fields["field" + k] = v;
if (schema[doctype][section][key].hidden){
document.getElementById(key).value = v;
continue;
}
if(schema[doctype][section][key].validation.collection === '
radiolist
'){
//retrieve the radio button value from the XML
...
...
WebGde/WebContent/WebGde-Widgets/DataInputWidget/validateInput.js
View file @
94bd47ba
...
...
@@ -22,6 +22,10 @@ export const validateInput = (fieldID, value) => {
if
(
!
validation
)
return
{
valid
:
false
,
error
:
[
`FieldName: '
${
fieldID
}
' not in schema`
]
}
// Skip validation for hidden fields
if
(
isFieldHidden
(
fieldID
)){
return
{
valid
:
true
};
}
switch
(
validation
.
collection
)
{
case
'email'
:
return
validateEmail
(
validation
,
value
)
...
...
@@ -429,4 +433,15 @@ export const checkValidValues = (fieldID, value) => {
}
catch
(
err
)
{
return
{
isValidValue
:
false
,
errMsg
:
[
err
]}
}
}
\ No newline at end of file
}
function
isFieldHidden
(
key
)
{
for
(
const
docType
in
schema
)
{
for
(
const
section
in
schema
[
docType
])
{
if
(
schema
[
docType
][
section
][
key
]
&&
schema
[
docType
][
section
][
key
].
hidden
)
{
return
true
;
}
}
}
return
false
;
}
\ No newline at end of file
WebGde/WebContent/WebGde-Widgets/Submit/XMLWriter/XML_Saver.js
View file @
94bd47ba
...
...
@@ -15,10 +15,15 @@ export async function WriteForm(e,metrics,doctype,section) {
// localStorage.setItem("submit", "1");
let
fields
=
{};
for
(
var
i
=
0
;
i
<
Nodes
.
length
;
i
++
)
{
for
(
var
i
=
0
;
i
<
Nodes
.
length
;
i
++
)
{
if
(
Nodes
[
i
].
style
.
display
===
'none'
&&
!
Nodes
[
i
].
classList
.
contains
(
'hidden'
))
continue
let
fid
=
Nodes
[
i
].
id
;
if
(
fid
==
'DocType'
||
fid
==
'Section'
||
fid
==
''
||
fid
==
"submitButton"
)
continue
// Add doctype as field1
if
(
fid
===
'DocType'
)
{
fields
[
'1'
]
=
Nodes
[
i
].
value
;
continue
;
}
if
(
fid
==
'Section'
||
fid
==
''
||
fid
==
"submitButton"
)
continue
// Skip the textbox in checklist and radiolist
if
(
Nodes
[
i
].
classList
.
contains
(
'radioOther'
)
||
Nodes
[
i
].
classList
.
contains
(
'checkboxOther'
))
continue
;
// Skip elements of type "button", "submit", and files
...
...
@@ -73,8 +78,11 @@ export async function WriteForm(e,metrics,doctype,section) {
}
fields
[
Object
.
keys
(
lookup
[
fid
]).
includes
(
'aka'
)
?
lookup
[
fid
].
aka
.
replace
(
"field"
,
""
)
:
fid
]
=
Nodes
[
i
].
value
;
}
let
fieldOrder
=
extractAkaValues
(
schema
,
doctype
,
section
);
console
.
log
(
fieldOrder
);
let
response
=
await
createOutputXml
(
fields
,
myArray
,
doctype
,
section
);
let
response
=
await
createOutputXml
(
fields
,
myArray
,
doctype
,
section
,
fieldOrder
);
return
response
;
}
catch
(
Err
)
{
...
...
@@ -83,17 +91,36 @@ export async function WriteForm(e,metrics,doctype,section) {
return
false
;
}
async
function
createOutputXml
(
fields
,
metrics
,
doctype
,
section
)
{
function
extractAkaValues
(
json
,
doctype
,
section
)
{
const
akaValues
=
[];
function
recursiveExtract
(
obj
)
{
for
(
const
key
in
obj
)
{
if
(
typeof
obj
[
key
]
===
'object'
)
{
recursiveExtract
(
obj
[
key
]);
}
else
if
(
key
===
'aka'
)
{
akaValues
.
push
(
obj
[
key
].
replace
(
'field'
,
''
));
}
}
}
recursiveExtract
(
json
[
doctype
][
section
]);
return
akaValues
.
join
(
'|'
);
}
async
function
createOutputXml
(
fields
,
metrics
,
doctype
,
section
,
fieldOrder
)
{
let
response
=
null
;
if
(
IS_RETRIEVE_FROM_BPO
==
"Y"
)
{
response
=
await
createBPOXML
(
fields
,
metrics
,
doctype
,
section
);
response
=
await
createBPOXML
(
fields
,
metrics
,
doctype
,
section
,
fieldOrder
);
}
else
{
response
=
await
createNonBPOXML
(
fields
,
metrics
,
doctype
,
section
);
response
=
await
createNonBPOXML
(
fields
,
metrics
,
doctype
,
section
,
fieldOrder
);
}
return
response
;
}
async
function
createNonBPOXML
(
fields
,
metrics
,
doctype
,
section
){
async
function
createNonBPOXML
(
fields
,
metrics
,
doctype
,
section
,
fieldOrder
){
console
.
log
(
fields
);
let
fileExt
=
""
;
switch
(
ENCODING_PASS
){
case
"PASS1"
:
...
...
@@ -137,7 +164,8 @@ async function createNonBPOXML(fields, metrics, doctype, section){
"fields"
:
fields
,
"outputDir"
:
TEMPORARY_FOLDER
+
"/"
+
fileNameOnly
+
"/"
+
fileName
,
"doctype"
:
doctype
,
"section"
:
section
"section"
:
section
,
"fieldOrder"
:
fieldOrder
}
let
response
=
await
fetch
(
urlWriteXml
,
{
...
...
@@ -151,7 +179,7 @@ async function createNonBPOXML(fields, metrics, doctype, section){
return
response
;
}
async
function
createBPOXML
(
fields
,
metrics
,
doctype
,
section
){
async
function
createBPOXML
(
fields
,
metrics
,
doctype
,
section
,
fieldOrder
){
let
elementId
=
sessionStorage
.
getItem
(
"element_id"
);
let
filePaths
=
JSON
.
parse
(
sessionStorage
.
getItem
(
"dir_files"
));
...
...
@@ -174,9 +202,10 @@ async function createBPOXML(fields, metrics, doctype, section){
"subRecordNo"
:
"1"
,
"eor"
:
"N"
,
"fields"
:
fields
,
"outputDir"
:
sessionStorage
.
getItem
(
"element_file_loc"
)
+
"/"
+
(
ENCODING_PASS
==
"PASS1"
?
elementId
+
".DTA"
:
elementId
+
".DTB"
)
,
"outputDir"
:
sessionStorage
.
getItem
(
"element_file_loc"
)
+
"/"
+
elementId
+
".DVR"
,
"doctype"
:
doctype
,
"section"
:
section
"section"
:
section
,
"fieldOrder"
:
fieldOrder
}
let
response
=
await
fetch
(
urlWriteXml
,
{
...
...
WebGde/WebContent/WebGde-Widgets/config.js
View file @
94bd47ba
...
...
@@ -21,7 +21,7 @@ export const IS_RETRIEVE_FROM_GFS = "N"
export
const
INVALID_KEYS
=
"F1,F2,F3,F4,F5,F6,F7,F8,F9,F10,F11,F12,PrintScreen,ScrollLock,Pause,PageUp,PageDown,Insert,Delete,Control"
//BPO CONFIG
export
const
IS_RETRIEVE_FROM_BPO
=
"
Y
"
export
const
IS_RETRIEVE_FROM_BPO
=
"
N
"
// export const BPO_URL = "http://35.171.20.94:8080/bpo-sqa/"
// export const CURRENT_NODE = "Web GDE"
export
let
BPO_URL
=
DOMAIN
+
"bpo/"
;
...
...
@@ -30,7 +30,7 @@ export let CURRENT_NODE = ""
export
const
ENCODING_PASS
=
"PASS1"
export
const
NEXT_NODE
=
"Complete"
export
const
EXCEPTION_NODE
=
"Exception"
export
const
SHOW_ELEMENT_LIST_VIEWER
=
"
Y
"
export
const
SHOW_ELEMENT_LIST_VIEWER
=
"
N
"
export
const
ADD_NEW_OPTION
=
"N"
export
const
DISPLAYED_DETAILS
=
"Address"
//pipe-delimited
...
...
WebGde/WebContent/WebGde-Widgets/sample_schema/Navotas 2.json
0 → 100644
View file @
94bd47ba
This diff is collapsed.
Click to expand it.
WebGde/src/main/java/com/svi/webgde/restservice/object/Field.java
View file @
94bd47ba
...
...
@@ -24,4 +24,8 @@ public class Field {
this
.
no
=
no
;
this
.
value
=
value
;
}
public
String
getNo
()
{
return
this
.
no
;
}
}
WebGde/src/main/java/com/svi/webgde/restservice/object/Record.java
View file @
94bd47ba
...
...
@@ -36,4 +36,8 @@ public class Record {
this
.
section
=
xml
.
getSection
();
this
.
subRecord
=
new
SubRecord
(
xml
);
}
public
SubRecord
getSubRecord
()
{
return
this
.
subRecord
;
}
}
WebGde/src/main/java/com/svi/webgde/restservice/object/SubRecord.java
View file @
94bd47ba
package
com
.
svi
.
webgde
.
restservice
.
object
;
import
java.util.Comparator
;
import
java.util.List
;
import
java.util.stream.Collectors
;
import
com.svi.webgde.restservice.utils.XMLUtil
;
import
com.thoughtworks.xstream.annotations.XStreamAlias
;
...
...
@@ -31,4 +33,46 @@ public class SubRecord {
this
.
eor
=
xml
.
getEor
();
this
.
fields
=
XMLUtil
.
generateFields
(
xml
);
}
/**
* Arrange the contents of the fields list based on the order specified in the pipe-delimited string.
*
* @param orderPipeDelimited Pipe-delimited string specifying the order.
*/
public
void
arrangeFields
(
String
orderPipeDelimited
)
{
List
<
Field
>
sortedFields
=
fields
.
stream
()
.
sorted
((
f1
,
f2
)
->
{
if
(
"1"
.
equals
(
f1
.
getNo
()))
{
return
-
1
;
// f1 comes before f2
}
else
if
(
"1"
.
equals
(
f2
.
getNo
()))
{
return
1
;
// f2 comes before f1
}
else
{
return
Integer
.
compare
(
getOrder
(
f1
.
getNo
(),
orderPipeDelimited
),
getOrder
(
f2
.
getNo
(),
orderPipeDelimited
));
}
})
.
collect
(
Collectors
.
toList
());
// Update the fields list with the sorted order
fields
.
clear
();
fields
.
addAll
(
sortedFields
);
}
/**
* Helper method to get the order of a field based on the pipe-delimited string.
*
* @param fieldNo The field number to get the order for.
* @param orderPipeDelimited The pipe-delimited string specifying the order.
* @return The order of the field.
*/
private
int
getOrder
(
String
fieldNo
,
String
orderPipeDelimited
)
{
String
[]
orderArray
=
orderPipeDelimited
.
split
(
"\\|"
);
for
(
int
i
=
0
;
i
<
orderArray
.
length
;
i
++)
{
if
(
orderArray
[
i
].
equals
(
fieldNo
))
{
return
i
;
}
}
// Default to a high value if not found (end of the list)
return
orderArray
.
length
;
}
}
WebGde/src/main/java/com/svi/webgde/restservice/object/XMLContents.java
View file @
94bd47ba
package
com
.
svi
.
webgde
.
restservice
.
object
;
import
java.util.LinkedHashMap
;
import
java.util.Map
;
public
class
XMLContents
{
...
...
@@ -21,10 +22,19 @@ public class XMLContents {
private
String
imageName
;
private
int
subRecordNo
;
private
String
eor
;
private
Map
<
String
,
String
>
fields
;
private
Map
<
String
,
String
>
fields
=
new
LinkedHashMap
<>();
;
private
String
outputDir
;
private
String
doctype
;
private
String
section
;
private
String
fieldOrder
;
public
String
getFieldOrder
()
{
return
fieldOrder
;
}
public
void
setFieldOrder
(
String
fieldOrder
)
{
this
.
fieldOrder
=
fieldOrder
;
}
public
String
getProjCode
()
{
return
projCode
;
...
...
@@ -193,4 +203,5 @@ public class XMLContents {
public
void
setSection
(
String
section
)
{
this
.
section
=
section
;
}
}
WebGde/src/main/java/com/svi/webgde/restservice/utils/XMLUtil.java
View file @
94bd47ba
...
...
@@ -20,7 +20,10 @@ import javax.xml.transform.TransformerException;
import
javax.xml.transform.TransformerFactory
;
import
javax.xml.transform.dom.DOMSource
;
import
javax.xml.transform.stream.StreamResult
;
import
javax.xml.xpath.XPath
;
import
javax.xml.xpath.XPathConstants
;
import
javax.xml.xpath.XPathExpressionException
;
import
javax.xml.xpath.XPathFactory
;
import
org.w3c.dom.Document
;
import
org.w3c.dom.Element
;
...
...
@@ -67,29 +70,41 @@ public class XMLUtil {
*/
public
static
String
generateXML
(
XMLContents
xml
)
throws
TransformerException
,
ParserConfigurationException
,
SAXException
,
IOException
,
XPathExpressionException
{
XStream
xs
=
new
XStream
(
new
DomDriver
(
"
ISO-8859-1
"
,
new
XmlFriendlyNameCoder
(
"_-"
,
"_"
)));
XStream
xs
=
new
XStream
(
new
DomDriver
(
"
UTF-8
"
,
new
XmlFriendlyNameCoder
(
"_-"
,
"_"
)));
xs
.
alias
(
xml
.
getProjCode
(),
OutputXML
.
class
);
xs
.
processAnnotations
(
Record
.
class
);
Header
header
=
new
Header
(
xml
);
Record
record
=
new
Record
(
xml
);
record
.
getSubRecord
().
arrangeFields
(
xml
.
getFieldOrder
());
OutputXML
output
=
new
OutputXML
(
header
,
record
);
// SAXParserFactory spf = SAXParserFactory.newInstance();
// SAXParser sp = spf.newSAXParser();
// Source source = new SAXSource(sp.getXMLReader(),
// new InputSource(new StringReader(xs.toXML(output).replaceAll("(?<![^\\W_])[ ](?![^\\W_])", " "))));
// SAXParserFactory spf = SAXParserFactory.newInstance();
// SAXParser sp = spf.newSAXParser();
// Source source = new SAXSource(sp.getXMLReader(),
// new InputSource(new StringReader(xs.toXML(output).replaceAll("(?<![^\\W_])[
// ](?![^\\W_])", " "))));
DocumentBuilderFactory
factory
=
DocumentBuilderFactory
.
newInstance
();
DocumentBuilder
builder
=
factory
.
newDocumentBuilder
();
Document
document
=
builder
.
parse
(
new
InputSource
(
new
StringReader
(
xs
.
toXML
(
output
).
replaceAll
(
"(?<![^\\W_])[ ](?![^\\W_])"
,
" "
))));
// Generate list of all empty Nodes, them remove them
XPath
xp
=
XPathFactory
.
newInstance
().
newXPath
();
NodeList
nl
=
(
NodeList
)
xp
.
evaluate
(
"//text()[normalize-space(.)='']"
,
document
,
XPathConstants
.
NODESET
);
for
(
int
i
=
0
;
i
<
nl
.
getLength
();
++
i
)
{
// note the position of the '++'
Node
node
=
nl
.
item
(
i
);
node
.
getParentNode
().
removeChild
(
node
);
}
DOMSource
source
=
new
DOMSource
(
document
);
TransformerFactory
transformerFactory
=
TransformerFactory
.
newInstance
();
Transformer
transformer
=
transformerFactory
.
newTransformer
();
transformer
.
setOutputProperty
(
OutputKeys
.
ENCODING
,
"
ISO-8859-1
"
);
transformer
.
setOutputProperty
(
OutputKeys
.
ENCODING
,
"
UTF-8
"
);
transformer
.
setOutputProperty
(
OutputKeys
.
INDENT
,
"yes"
);
transformer
.
setOutputProperty
(
OutputKeys
.
STANDALONE
,
"no"
);
transformer
.
setOutputProperty
(
"{http://xml.apache.org/xslt}indent-amount"
,
"4"
);
...
...
@@ -334,31 +349,41 @@ public class XMLUtil {
DocumentBuilder
builder
=
factory
.
newDocumentBuilder
();
Document
document
=
builder
.
parse
(
xml
.
getOutputDir
());
Node
imagename
=
document
.
getElementsByTagName
(
"imagename"
).
item
(
0
);
Node
xmlSubRecord
=
imagename
.
getParentNode
().
getLastChild
().
getPreviousSibling
();
Map
<
String
,
String
>
fields
=
new
HashMap
<>();
records
.
put
(
"DocType"
,
imagename
.
getParentNode
().
getFirstChild
().
getNextSibling
().
getNextSibling
()
.
getNextSibling
().
getTextContent
());
records
.
put
(
"Section"
,
imagename
.
getParentNode
().
getFirstChild
().
getNextSibling
().
getNextSibling
()
.
getNextSibling
().
getNextSibling
().
getNextSibling
().
getTextContent
());
records
.
put
(
"fields"
,
fields
);
for
(
int
i
=
0
;
i
<
xmlSubRecord
.
getChildNodes
().
getLength
();
i
++)
{
if
(
xmlSubRecord
.
getChildNodes
().
item
(
i
).
getNodeType
()
==
Node
.
ELEMENT_NODE
)
{
for
(
int
j
=
0
;
j
<
xmlSubRecord
.
getChildNodes
().
item
(
i
).
getChildNodes
().
getLength
();
j
++)
{
if
(
xmlSubRecord
.
getChildNodes
().
item
(
i
).
getChildNodes
().
item
(
j
)
.
getNodeType
()
==
Node
.
ELEMENT_NODE
)
{
fields
.
put
(
xmlSubRecord
.
getChildNodes
().
item
(
i
).
getAttributes
().
getNamedItem
(
"no"
).
getNodeValue
(),
xmlSubRecord
.
getChildNodes
().
item
(
i
).
getChildNodes
().
item
(
j
).
getTextContent
());
records
.
put
(
"fields"
,
fields
);
}
}
}
}
Element
record
=
(
Element
)
document
.
getElementsByTagName
(
"record"
).
item
(
0
);
if
(
record
!=
null
)
{
records
.
put
(
"DocType"
,
getElementTextByTagName
(
record
,
"doctype"
));
records
.
put
(
"Section"
,
getElementTextByTagName
(
record
,
"section"
));
Map
<
String
,
String
>
fields
=
new
HashMap
<>();
records
.
put
(
"fields"
,
fields
);
Element
subRecord
=
(
Element
)
record
.
getElementsByTagName
(
"sub-record"
).
item
(
0
);
if
(
subRecord
!=
null
)
{
NodeList
fieldList
=
subRecord
.
getElementsByTagName
(
"field"
);
for
(
int
j
=
0
;
j
<
fieldList
.
getLength
();
j
++)
{
Element
field
=
(
Element
)
fieldList
.
item
(
j
);
String
noAttributeValue
=
field
.
getAttribute
(
"no"
);
String
textContentValue
=
field
.
getElementsByTagName
(
"value"
).
item
(
0
).
getTextContent
();
if
(
"1"
.
equals
(
noAttributeValue
))
{
// Replace the value of "DocType" with the text content
records
.
put
(
"DocType"
,
textContentValue
);
}
fields
.
put
(
noAttributeValue
,
textContentValue
);
}
}
}
return
records
;
}
return
records
;
private
static
String
getElementTextByTagName
(
Element
parentElement
,
String
tagName
)
{
NodeList
elements
=
parentElement
.
getElementsByTagName
(
tagName
);
if
(
elements
.
getLength
()
>
0
)
{
return
elements
.
item
(
0
).
getTextContent
();
}
return
null
;
// or an appropriate default value
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment