Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
Component Sharing
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
CI / CD Analytics
Repository Analytics
Value Stream Analytics
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Gagandeep Singh Bhatia
Component Sharing
Commits
3638d1fb
Commit
3638d1fb
authored
Mar 06, 2024
by
Sonawane Amol Madhjuar
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload New File
parent
fab652bf
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
107 additions
and
0 deletions
+107
-0
Amol/API/Application API/AcknowledgementReader.java
Amol/API/Application API/AcknowledgementReader.java
+107
-0
No files found.
Amol/API/Application API/AcknowledgementReader.java
0 → 100644
View file @
3638d1fb
package
ibase
.
webitm
.
ejb
.
sys
;
import
java.io.File
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
org.w3c.dom.Document
;
import
org.w3c.dom.Element
;
import
org.w3c.dom.Node
;
import
org.w3c.dom.NodeList
;
import
javax.xml.parsers.DocumentBuilder
;
import
javax.xml.parsers.DocumentBuilderFactory
;
public
class
AcknowledgementReader
{
public
static
Map
<
String
,
Object
[]>
parseXMLFiles
(
String
directoryPath
)
{
Map
<
String
,
Object
[]>
resultMap
=
new
HashMap
<>();
try
{
File
directory
=
new
File
(
directoryPath
);
if
(
directory
.
isDirectory
())
{
File
[]
files
=
directory
.
listFiles
((
dir
,
name
)
->
name
.
toLowerCase
().
endsWith
(
".xml"
));
if
(
files
!=
null
)
{
for
(
File
file
:
files
)
{
DocumentBuilderFactory
dbFactory
=
DocumentBuilderFactory
.
newInstance
();
DocumentBuilder
dBuilder
=
dbFactory
.
newDocumentBuilder
();
Document
doc
=
dBuilder
.
parse
(
file
);
doc
.
getDocumentElement
().
normalize
();
NodeList
topLevelNodes
=
doc
.
getDocumentElement
().
getChildNodes
();
processNodes
(
topLevelNodes
,
resultMap
);
}
}
}
else
{
System
.
out
.
println
(
"Specified path is not a directory."
);
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
resultMap
;
}
private
static
void
processNodes
(
NodeList
nodes
,
Map
<
String
,
Object
[]>
resultMap
)
{
for
(
int
i
=
0
;
i
<
nodes
.
getLength
();
i
++)
{
Node
node
=
nodes
.
item
(
i
);
if
(
node
.
getNodeType
()
==
Node
.
ELEMENT_NODE
)
{
Element
element
=
(
Element
)
node
;
String
orgnlEndToEndId
=
getElementValue
(
element
,
"OrgnlEndToEndId"
);
String
txSts
=
getElementValue
(
element
,
"TxSts"
);
String
rsn
=
getElementValue
(
element
,
"Rsn"
);
List
<
String
>
addtlInfList
=
new
ArrayList
<>();
NodeList
addtlInfNodes
=
element
.
getElementsByTagName
(
"AddtlInf"
);
for
(
int
j
=
0
;
j
<
addtlInfNodes
.
getLength
();
j
++)
{
addtlInfList
.
add
(
addtlInfNodes
.
item
(
j
).
getTextContent
());
}
Object
[]
values
=
{
txSts
,
new
Object
[]{
rsn
,
addtlInfList
.
toArray
(
new
String
[
0
])}};
resultMap
.
put
(
orgnlEndToEndId
,
values
);
// Recursively process child nodes
processNodes
(
node
.
getChildNodes
(),
resultMap
);
}
}
}
private
static
String
getElementValue
(
Element
element
,
String
tagName
)
{
NodeList
nodeList
=
element
.
getElementsByTagName
(
tagName
);
return
nodeList
.
getLength
()
>
0
?
nodeList
.
item
(
0
).
getTextContent
()
:
""
;
}
public
static
void
main
(
String
[]
args
)
{
String
directoryPath
=
"/home/amol.sonawane/Documents/Acknowledgement"
;
Map
<
String
,
Object
[]>
result
=
parseXMLFiles
(
directoryPath
);
System
.
out
.
println
(
"Tag Values are :"
);
for
(
Map
.
Entry
<
String
,
Object
[]>
entry
:
result
.
entrySet
())
{
System
.
out
.
println
(
"Key: "
+
entry
.
getKey
());
Object
[]
values
=
entry
.
getValue
();
System
.
out
.
println
(
"TxSts: "
+
(
String
)
values
[
0
]);
Object
[]
innerArray
=
(
Object
[])
values
[
1
];
System
.
out
.
println
(
"Rsn: "
+
(
String
)
innerArray
[
0
]);
String
[]
addtlInfArray
=
(
String
[])
innerArray
[
1
];
System
.
out
.
print
(
"AddtlInf: "
);
for
(
String
addtlInf
:
addtlInfArray
)
{
System
.
out
.
print
(
addtlInf
+
" "
);
}
System
.
out
.
println
(
"\n"
);
}
}
}
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