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
92006a51
Commit
92006a51
authored
Nov 19, 2023
by
Owen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fieldno ordering acc to schema, removed extra spacing on xml.
parent
6827826d
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
92 additions
and
3 deletions
+92
-3
XML_Saver.js
...e/WebContent/WebGde-Widgets/Submit/XMLWriter/XML_Saver.js
+26
-3
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
+35
-0
XMLContents.java
...n/java/com/svi/webgde/restservice/object/XMLContents.java
+9
-0
XMLUtil.java
...c/main/java/com/svi/webgde/restservice/utils/XMLUtil.java
+14
-0
No files found.
WebGde/WebContent/WebGde-Widgets/Submit/XMLWriter/XML_Saver.js
View file @
92006a51
...
...
@@ -74,7 +74,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
;
}
await
createOutputXml
(
fields
,
myArray
,
doctype
,
section
);
let
fieldOrder
=
extractAkaValues
(
schema
,
doctype
,
section
);
console
.
log
(
fieldOrder
);
await
createOutputXml
(
fields
,
myArray
,
doctype
,
section
,
fieldOrder
);
}
}
catch
(
Err
)
{
...
...
@@ -83,7 +87,25 @@ 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
elementId
=
sessionStorage
.
getItem
(
"element_id"
);
let
filePaths
=
JSON
.
parse
(
sessionStorage
.
getItem
(
"dir_files"
));
...
...
@@ -111,7 +133,8 @@ async function createOutputXml(fields, metrics, doctype, section) {
"fields"
:
fields
,
"outputDir"
:
sessionStorage
.
getItem
(
"element_file_loc"
)
+
"/"
+
(
ENCODING_PASS
==
"PASS1"
?
elementId
+
".DTA"
:
elementId
+
".DTB"
),
"doctype"
:
doctype
,
"section"
:
section
"section"
:
section
,
"fieldOrder"
:
fieldOrder
}
...
...
WebGde/src/main/java/com/svi/webgde/restservice/object/Field.java
View file @
92006a51
...
...
@@ -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 @
92006a51
...
...
@@ -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 @
92006a51
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,37 @@ 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
(
Comparator
.
comparingInt
(
f
->
getOrder
(
f
.
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 @
92006a51
...
...
@@ -25,6 +25,15 @@ public class XMLContents {
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
;
...
...
WebGde/src/main/java/com/svi/webgde/restservice/utils/XMLUtil.java
View file @
92006a51
...
...
@@ -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
;
...
...
@@ -74,6 +77,8 @@ public class XMLUtil {
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();
...
...
@@ -85,6 +90,15 @@ public class XMLUtil {
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
();
...
...
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