Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
swiftMtMx
Overview
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
isc-v3.1-tmp
swiftMtMx
Commits
36fb2644
Commit
36fb2644
authored
Oct 17, 2022
by
chengzhuoshen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
使用正则表达式的方式去掉命名空间前缀
parent
0058d1ce
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
15 additions
and
41 deletions
+15
-41
Mx2ElementCreatorManager.java
...brilliance/swift/mx2element/Mx2ElementCreatorManager.java
+2
-7
Field59Generate.java
...om/brilliance/swift/mx2mt/mt103/impl/Field59Generate.java
+1
-1
XmlUtil.java
...Core/src/main/java/com/brilliance/swift/util/XmlUtil.java
+12
-33
No files found.
swiftCore/src/main/java/com/brilliance/swift/mx2element/Mx2ElementCreatorManager.java
View file @
36fb2644
...
...
@@ -42,11 +42,6 @@ public class Mx2ElementCreatorManager {
public
Map
<
String
,
Object
>
mx2ElementMaps
(
String
xmlStr
)
throws
SwiftException
{
xmlStr
=
handlingXml
(
xmlStr
);
AbstractMX
abstractMX
=
AbstractMX
.
parse
(
xmlStr
);
//如果存在命名空間則去掉命名空間 重新parse
if
(
StringUtil
.
isEmpty
(
abstractMX
.
getAppHdr
().
from
()))
{
xmlStr
=
XmlUtil
.
clearXmlNamespace
(
xmlStr
);
abstractMX
=
AbstractMX
.
parse
(
xmlStr
);
}
String
messageType
=
(
abstractMX
.
getMxId
().
getBusinessProcess
().
name
()
+
"."
+
abstractMX
.
getMxId
().
getFunctionality
()
...
...
@@ -92,9 +87,9 @@ public class Mx2ElementCreatorManager {
flag
=
false
;
}
if
(
flag
)
{
//如果是有效xml报文,直接返回
return
xmlStr
;
return
XmlUtil
.
clearXmlNamespacePrefix
(
xmlStr
)
;
}
else
{
return
SwiftTransfer
.
fetchXmlFromMixMessage
(
xmlStr
);
return
XmlUtil
.
clearXmlNamespacePrefix
(
SwiftTransfer
.
fetchXmlFromMixMessage
(
xmlStr
)
);
}
}
}
swiftCore/src/main/java/com/brilliance/swift/mx2mt/mt103/impl/Field59Generate.java
View file @
36fb2644
...
...
@@ -40,7 +40,7 @@ public class Field59Generate extends AbstractMx2MtTagsGenerate {
int
addressLineCount
=
getXmlNodeCounts
(
bodyHdrParentElementName
,
document
,
"CdtTrfTxInf.Cdtr.PstlAdr.AdrLine"
);
String
addressLine1
=
""
;
if
(
addressLineCount
>
0
)
{
addressLine1
=
getXmlNodeValue
(
bodyHdrParentElementName
,
document
,
"CdtTrfTxInf.
Db
tr.PstlAdr.AdrLine(0)"
);
addressLine1
=
getXmlNodeValue
(
bodyHdrParentElementName
,
document
,
"CdtTrfTxInf.
Cd
tr.PstlAdr.AdrLine(0)"
);
}
String
partyName
=
getXmlNodeValue
(
bodyHdrParentElementName
,
document
,
"CdtTrfTxInf.Cdtr.Nm"
);
String
value
=
""
;
...
...
swiftCore/src/main/java/com/brilliance/swift/util/XmlUtil.java
View file @
36fb2644
...
...
@@ -11,6 +11,8 @@ import java.net.URL;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
public
class
XmlUtil
{
...
...
@@ -188,39 +190,16 @@ public class XmlUtil {
}
public
static
String
clearXmlNamespace
(
String
xmlStr
)
{
try
{
SAXReader
reader
=
new
SAXReader
();
Document
document
=
reader
.
read
(
new
ByteArrayInputStream
(
xmlStr
.
getBytes
()));
document
.
accept
(
new
NameSpaceCleaner
());
String
xml
=
document
.
asXML
();
return
xml
.
replaceAll
(
"xmlns:([\\w]*)"
,
"xmlns"
);
}
catch
(
DocumentException
e
)
{
throw
new
SwiftException
(
e
.
getMessage
());
}
}
private
static
class
NameSpaceCleaner
extends
VisitorSupport
{
public
void
visit
(
Document
document
)
{
((
DefaultElement
)
document
.
getRootElement
())
.
setNamespace
(
Namespace
.
NO_NAMESPACE
);
document
.
getRootElement
().
additionalNamespaces
().
clear
();
}
public
void
visit
(
Namespace
namespace
)
{
namespace
.
detach
();
}
public
void
visit
(
Attribute
node
)
{
if
(
node
.
toString
().
contains
(
"xmlns"
)
||
node
.
toString
().
contains
(
"xsi:"
))
{
node
.
detach
();
}
}
public
void
visit
(
Element
node
)
{
if
(
node
instanceof
DefaultElement
)
{
((
DefaultElement
)
node
).
setNamespace
(
Namespace
.
NO_NAMESPACE
);
}
public
static
String
clearXmlNamespacePrefix
(
String
xmlStr
)
{
String
regex
=
"[AppHdr|Document][\\s]*xmlns:([\\w]*)="
;
Pattern
p
=
Pattern
.
compile
(
regex
);
Matcher
m
=
p
.
matcher
(
xmlStr
);
String
prefix
=
""
;
while
(
m
.
find
())
{
prefix
=
m
.
group
(
1
);
xmlStr
=
xmlStr
.
replace
(
"<"
+
prefix
+
":"
,
"<"
).
replace
(
"</"
+
prefix
+
":"
,
"</"
);
}
xmlStr
=
xmlStr
.
replaceAll
(
"xmlns:([\\w]*)"
,
"xmlns"
);
return
xmlStr
;
}
}
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