Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
swifteditor_java
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
fukai
swifteditor_java
Commits
0986f44f
Commit
0986f44f
authored
Nov 07, 2019
by
WeiCong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1.修复嵌套可选项的解析;2.完成通用获取域的API
parent
c6c688a7
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
209 additions
and
89 deletions
+209
-89
TagFormat.java
src/main/java/com/brilliace/swifteditor/tag/TagFormat.java
+5
-5
TagLine.java
src/main/java/com/brilliace/swifteditor/tag/TagLine.java
+14
-6
MessageFormat.java
.../com/brilliace/swifteditor/tag/message/MessageFormat.java
+6
-11
SWFMessage.java
...ava/com/brilliace/swifteditor/tag/message/SWFMessage.java
+109
-67
Assert.java
src/main/java/com/brilliace/swifteditor/util/Assert.java
+23
-0
ParseSwiftTest.java
src/test/java/com/brilliace/swifteditor/ParseSwiftTest.java
+52
-0
No files found.
src/main/java/com/brilliace/swifteditor/tag/TagFormat.java
View file @
0986f44f
...
...
@@ -2,11 +2,8 @@ package com.brilliace.swifteditor.tag;
import
java.io.IOException
;
import
java.io.StringReader
;
import
java.util.Arrays
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.*
;
import
java.util.Map.Entry
;
import
java.util.Properties
;
public
class
TagFormat
{
public
static
Properties
TagProps
=
new
Properties
();
...
...
@@ -60,6 +57,7 @@ public class TagFormat {
int
minLen
=
1
;
boolean
isConst
=
false
;
TagCell
cell
=
null
;
Stack
<
Integer
>
bracket
=
new
Stack
<
Integer
>();
while
(
true
)
{
ic
=
reader
.
read
();
...
...
@@ -163,11 +161,13 @@ public class TagFormat {
else
if
(
c
==
'['
)
{
line
.
addOptions
(
new
int
[]{
line
.
cellList
.
size
(),-
1
});
bracket
.
push
(
line
.
options
.
size
()-
1
);
}
else
if
(
c
==
']'
)
{
//if("51A".equals(tag))
line
.
fillLastOption
(
line
.
cellList
.
size
());
//line.fillLastOption(line.cellList.size());
line
.
fillOption
(
bracket
.
pop
(),
line
.
cellList
.
size
());
}
}
line
.
setMaxCnt
(
cnt
-
1
);
...
...
src/main/java/com/brilliace/swifteditor/tag/TagLine.java
View file @
0986f44f
package
com
.
brilliace
.
swifteditor
.
tag
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
com.brilliace.swifteditor.tag.message.MessageArea
;
import
java.util.*
;
public
class
TagLine
implements
MessageArea
{
public
List
<
TagCell
>
cellList
=
new
ArrayList
<
TagCell
>();
public
List
<
int
[]>
options
=
new
ArrayList
<
int
[]>();
...
...
@@ -15,6 +11,8 @@ public class TagLine implements MessageArea {
private
String
value
;
private
String
tagName
;
private
String
status
;
public
MessageArea
parent
;
public
String
getStatus
()
{
return
status
;
}
...
...
@@ -33,6 +31,15 @@ public class TagLine implements MessageArea {
{
options
.
add
(
points
);
}
public
void
fillOption
(
int
index
,
int
point
)
{
if
(
options
.
size
()
==
0
)
{
System
.
err
.
println
(
"error pattern:"
+
this
.
getName
()+
"----"
+
this
.
getPattern
());
return
;
}
options
.
get
(
index
)[
1
]
=
point
;
}
public
void
fillLastOption
(
int
point
)
{
if
(
options
.
size
()
==
0
)
...
...
@@ -260,4 +267,5 @@ public class TagLine implements MessageArea {
}
return
indexMap
;
}
}
src/main/java/com/brilliace/swifteditor/tag/message/MessageFormat.java
View file @
0986f44f
package
com
.
brilliace
.
swifteditor
.
tag
.
message
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Stack
;
import
com.brilliace.swifteditor.tag.TagFormat
;
import
com.brilliace.swifteditor.tag.TagLine
;
import
com.google.gson.Gson
;
import
org.apache.poi.ss.usermodel.Cell
;
import
org.apache.poi.ss.usermodel.Row
;
import
org.apache.poi.ss.usermodel.Sheet
;
import
org.apache.poi.xssf.usermodel.XSSFWorkbook
;
import
com.brilliace.swifteditor.tag.TagFormat
;
import
com.brilliace.swifteditor.tag.TagLine
;
import
com.google.gson.Gson
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.util.*
;
public
class
MessageFormat
{
...
...
src/main/java/com/brilliace/swifteditor/tag/message/SWFMessage.java
View file @
0986f44f
package
com
.
brilliace
.
swifteditor
.
tag
.
message
;
import
java.util.HashMap
;
import
java.util.Map
;
import
com.brilliace.swifteditor.tag.TagLine
;
import
com.brilliace.swifteditor.util.Assert
;
import
com.google.gson.Gson
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.regex.Pattern
;
public
class
SWFMessage
extends
AbstractMessageArea
{
private
String
mtType
;
private
Map
<
Integer
,
String
>
headers
;
private
Map
<
Integer
,
TagLine
>
flatModel
=
new
HashMap
<>();
private
Map
<
String
,
String
>
bscInfo
;
protected
SWFMessage
()
{
}
public
static
SWFMessage
loadMTTemp
(
String
mt
)
{
return
null
;
}
private
static
void
toSubJson
(
AbstractMessageArea
ma
,
StringBuilder
sb
)
{
sb
.
append
(
"[\r\n"
);
for
(
MessageArea
sma
:
ma
.
getFields
())
{
if
(
sma
.
getType
()
==
TAG
)
{
TagLine
tag
=
(
TagLine
)
sma
;
if
(
tag
.
getName
().
startsWith
(
"50"
))
{
System
.
out
.
println
(
111
);
}
sb
.
append
(
String
.
format
(
"\t{\"tag\":\"%s\",\"status\":\"%s\",\"tno\":%d,\"letter\":%s,\"label\":\"%s\",\"tagValue\":%s},\r\n"
,
tag
.
getSuffix
().
size
()
>
0
&&
tag
.
getName
().
endsWith
(
"a"
)
?
tag
.
getSuffix
().
get
(
0
)
:
tag
.
getName
(),
tag
.
getStatus
(),
tag
.
getTno
(),
new
Gson
().
toJson
(
tag
.
getSuffix
()),
tag
.
getDesp
(),
new
Gson
().
toJson
(
new
Object
[]{
tag
.
getIndexMap
(),
tag
.
getSourceValue
()})));
}
else
if
(
sma
.
getType
()
==
CYCLIST
)
{
StringBuilder
buff
=
new
StringBuilder
();
// int first = 9999;
for
(
MessageArea
ssma
:
((
AbstractMessageArea
)
sma
).
getFields
())
{
AbstractMessageArea
temp
=
(
AbstractMessageArea
)
ssma
;
toSubJson
(
temp
,
buff
);
buff
.
append
(
','
);
}
sb
.
append
(
String
.
format
(
"\t{\"cyclist\":\"%s\",\"cycs\":["
,
sma
.
getName
()));
// String temp = buff.toString().trim();
sb
.
append
(
buff
.
subSequence
(
0
,
buff
.
length
()
-
1
));
sb
.
append
(
"],\r\n\t\"pattern\":"
);
buff
=
new
StringBuilder
();
toSubJson
((
AbstractMessageArea
)
((
AbstractMessageArea
)
sma
).
getPattern
(),
buff
);
sb
.
append
(
buff
);
sb
.
append
(
"\t},\r\n"
);
}
else
if
(
sma
.
getType
()
==
SEQLIST
)
{
StringBuilder
buff
=
new
StringBuilder
();
// int first = 9999;
for
(
MessageArea
ssma
:
((
AbstractMessageArea
)
sma
).
getFields
())
{
AbstractMessageArea
temp
=
(
AbstractMessageArea
)
ssma
;
toSubJson
(
temp
,
buff
);
buff
.
append
(
','
);
}
SEQList
seqlst
=
(
SEQList
)
sma
;
sb
.
append
(
String
.
format
(
"\t{\"seqlist\":\"%s\",\"cyccnt\":%d,\"status\":\"%s\",\"seqs\":["
,
sma
.
getName
(),
seqlst
.
getCyc
(),
seqlst
.
getOm
()));
// String temp = buff.toString().trim();
sb
.
append
(
buff
.
subSequence
(
0
,
buff
.
length
()
-
1
));
sb
.
append
(
"],\r\n\t\"pattern\":"
);
buff
=
new
StringBuilder
();
toSubJson
((
AbstractMessageArea
)
((
AbstractMessageArea
)
sma
).
getPattern
(),
buff
);
sb
.
append
(
buff
);
sb
.
append
(
String
.
format
(
",\r\n\t\"desp\":\"%s\""
,
seqlst
.
getDesp
()));
sb
.
append
(
"\t},\r\n"
);
}
}
if
(
sb
.
length
()
>
3
&&
sb
.
charAt
(
sb
.
length
()
-
3
)
==
','
)
sb
.
setCharAt
(
sb
.
length
()
-
3
,
' '
);
sb
.
append
(
"]"
);
}
public
Map
<
Integer
,
String
>
getHeaders
()
{
return
headers
;
}
...
...
@@ -21,6 +90,10 @@ public class SWFMessage extends AbstractMessageArea {
this
.
headers
=
clone
;
}
public
Map
<
Integer
,
TagLine
>
getFlatModel
()
{
return
this
.
flatModel
;
}
public
Map
<
String
,
String
>
getBscInfo
()
{
return
bscInfo
;
}
...
...
@@ -29,8 +102,6 @@ public class SWFMessage extends AbstractMessageArea {
this
.
bscInfo
=
bscInfo
;
}
private
Map
<
String
,
String
>
bscInfo
;
public
String
getMtType
()
{
return
mtType
;
}
...
...
@@ -39,13 +110,6 @@ public class SWFMessage extends AbstractMessageArea {
this
.
mtType
=
mtType
;
}
protected
SWFMessage
()
{
}
public
static
SWFMessage
loadMTTemp
(
String
mt
)
{
return
null
;
}
/***
*
* @param sb
...
...
@@ -72,6 +136,7 @@ public class SWFMessage extends AbstractMessageArea {
}
msg
.
setName
(
this
.
getName
());
msg
.
setAnlyReg
(
this
.
getAnlyReg
());
generateFlatModel
(
msg
,
msg
.
flatModel
,
null
);
return
msg
;
}
...
...
@@ -81,9 +146,9 @@ public class SWFMessage extends AbstractMessageArea {
rs
.
put
(
"mty"
,
this
.
mtType
);
rs
.
put
(
"snd_bic"
,
bscInfo
.
get
(
"sndbic"
));
rs
.
put
(
"rcv_bic"
,
bscInfo
.
get
(
"rcvbic"
));
if
(
bscInfo
.
containsKey
(
"t111"
))
if
(
bscInfo
.
containsKey
(
"t111"
))
rs
.
put
(
"t111"
,
bscInfo
.
get
(
"t111"
));
if
(
bscInfo
.
containsKey
(
"t121"
))
if
(
bscInfo
.
containsKey
(
"t121"
))
rs
.
put
(
"t121"
,
bscInfo
.
get
(
"t121"
));
rs
.
put
(
"tdheaders"
,
bscInfo
.
get
(
"tdmsgHead"
));
rs
.
put
(
"headers"
,
headers
);
...
...
@@ -113,65 +178,42 @@ public class SWFMessage extends AbstractMessageArea {
return
sb
.
toString
();
}
private
static
void
toSubJson
(
AbstractMessageArea
ma
,
StringBuilder
sb
)
{
sb
.
append
(
"[\r\n"
);
for
(
MessageArea
sma
:
ma
.
getFields
())
{
if
(
sma
.
getType
()
==
TAG
)
{
TagLine
tag
=
(
TagLine
)
sma
;
if
(
tag
.
getName
().
startsWith
(
"50"
))
{
System
.
out
.
println
(
111
);
@Override
public
int
getType
()
{
return
MESSAGE
;
}
sb
.
append
(
String
.
format
(
"\t{\"tag\":\"%s\",\"status\":\"%s\",\"tno\":%d,\"letter\":%s,\"label\":\"%s\",\"tagValue\":%s},\r\n"
,
tag
.
getSuffix
().
size
()
>
0
&&
tag
.
getName
().
endsWith
(
"a"
)
?
tag
.
getSuffix
().
get
(
0
)
:
tag
.
getName
(),
tag
.
getStatus
(),
tag
.
getTno
(),
new
Gson
().
toJson
(
tag
.
getSuffix
()),
tag
.
getDesp
(),
new
Gson
().
toJson
(
new
Object
[]
{
tag
.
getIndexMap
(),
tag
.
getSourceValue
()
})));
}
else
if
(
sma
.
getType
()
==
CYCLIST
)
{
StringBuilder
buff
=
new
StringBuilder
();
// int first = 9999;
for
(
MessageArea
ssma
:
((
AbstractMessageArea
)
sma
).
getFields
())
{
AbstractMessageArea
temp
=
(
AbstractMessageArea
)
ssma
;
toSubJson
(
temp
,
buff
);
buff
.
append
(
','
);
}
sb
.
append
(
String
.
format
(
"\t{\"cyclist\":\"%s\",\"cycs\":["
,
sma
.
getName
()));
// String temp = buff.toString().trim();
sb
.
append
(
buff
.
subSequence
(
0
,
buff
.
length
()
-
1
));
sb
.
append
(
"],\r\n\t\"pattern\":"
);
buff
=
new
StringBuilder
();
toSubJson
((
AbstractMessageArea
)
((
AbstractMessageArea
)
sma
).
getPattern
(),
buff
);
sb
.
append
(
buff
);
sb
.
append
(
"\t},\r\n"
);
}
else
if
(
sma
.
getType
()
==
SEQLIST
)
{
StringBuilder
buff
=
new
StringBuilder
();
// int first = 9999;
for
(
MessageArea
ssma
:
((
AbstractMessageArea
)
sma
).
getFields
())
{
AbstractMessageArea
temp
=
(
AbstractMessageArea
)
ssma
;
toSubJson
(
temp
,
buff
);
buff
.
append
(
','
);
final
Pattern
CHECKPATH
=
Pattern
.
compile
(
"^\\d+(\\.\\d)?$"
);
public
String
getGeneric
(
String
path
){
Assert
.
state
(
path
!=
null
&&
path
!=
""
&&
CHECKPATH
.
matcher
(
path
).
find
(),
"索引["
+
path
+
"]不符合规范"
);
int
index
=
path
.
indexOf
(
"."
);
TagLine
tagLine
;
if
(
index
==-
1
){
tagLine
=
this
.
flatModel
.
get
(
Integer
.
valueOf
(
path
));
return
tagLine
.
getValue
();
}
else
{
tagLine
=
this
.
flatModel
.
get
(
Integer
.
valueOf
(
path
.
substring
(
0
,
index
)));
int
part
=
Integer
.
parseInt
(
path
.
substring
(
index
+
1
));
Assert
.
state
(
part
>=
0
&&
part
<
tagLine
.
cellList
.
size
(),
"索引["
+
path
+
"]指定的域块不存在"
);
return
tagLine
.
cellList
.
get
(
part
).
value
;
}
SEQList
seqlst
=
(
SEQList
)
sma
;
sb
.
append
(
String
.
format
(
"\t{\"seqlist\":\"%s\",\"cyccnt\":%d,\"status\":\"%s\",\"seqs\":["
,
sma
.
getName
(),
seqlst
.
getCyc
(),
seqlst
.
getOm
()));
// String temp = buff.toString().trim();
sb
.
append
(
buff
.
subSequence
(
0
,
buff
.
length
()
-
1
));
sb
.
append
(
"],\r\n\t\"pattern\":"
);
buff
=
new
StringBuilder
();
toSubJson
((
AbstractMessageArea
)
((
AbstractMessageArea
)
sma
).
getPattern
(),
buff
);
sb
.
append
(
buff
);
sb
.
append
(
String
.
format
(
",\r\n\t\"desp\":\"%s\""
,
seqlst
.
getDesp
()));
sb
.
append
(
"\t},\r\n"
);
}
}
if
(
sb
.
length
()
>
3
&&
sb
.
charAt
(
sb
.
length
()
-
3
)
==
','
)
sb
.
setCharAt
(
sb
.
length
()
-
3
,
' '
);
sb
.
append
(
"]"
);
private
void
generateFlatModel
(
MessageArea
area
,
Map
<
Integer
,
TagLine
>
flatModel
,
MessageArea
parent
)
{
List
<
MessageArea
>
fieldList
=
((
AbstractMessageArea
)
area
).
getFields
();
for
(
int
i
=
0
;
i
<
fieldList
.
size
();
i
++)
{
MessageArea
item
=
fieldList
.
get
(
i
);
if
(
item
.
getType
()
==
MessageArea
.
TAG
)
{
TagLine
tagLine
=
(
TagLine
)
item
;
tagLine
.
parent
=
parent
;
flatModel
.
put
(
tagLine
.
getTno
(),
tagLine
);
}
else
if
(
item
.
getType
()
==
MessageArea
.
CYCLIST
||
item
.
getType
()
==
MessageArea
.
SEQLIST
)
{
generateFlatModel
(((
AbstractMessageArea
)
item
).
getFields
().
get
(
0
),
flatModel
,
item
);
}
else
{
System
.
out
.
println
(
item
.
getType
()+
" no match"
);
continue
;
}
@Override
public
int
getType
()
{
return
MESSAGE
;
}
}
}
src/main/java/com/brilliace/swifteditor/util/Assert.java
0 → 100644
View file @
0986f44f
package
com
.
brilliace
.
swifteditor
.
util
;
public
abstract
class
Assert
{
protected
Assert
()
{
}
public
static
void
notNull
(
Object
obj
,
String
message
)
{
if
(
obj
==
null
)
{
throw
new
IllegalArgumentException
(
message
);
}
}
public
static
void
notNullByArray
(
Object
[]
obj
,
String
message
)
{
if
(
obj
==
null
||
obj
.
length
==
0
)
{
throw
new
IllegalArgumentException
(
message
);
}
}
public
static
void
state
(
boolean
expression
,
String
message
)
{
if
(!
expression
)
{
throw
new
IllegalStateException
(
message
);
}
}
}
src/test/java/com/brilliace/swifteditor/ParseSwiftTest.java
0 → 100644
View file @
0986f44f
package
com
.
brilliace
.
swifteditor
;
import
com.brilliace.swifteditor.tag.message.MessageAnalyzer
;
import
com.brilliace.swifteditor.tag.message.MessageFormat
;
import
com.brilliace.swifteditor.tag.message.SWFMessage
;
import
junit.framework.TestCase
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
public
class
ParseSwiftTest
extends
TestCase
{
public
void
testLoadSwiftMessage
()
{
String
path
=
"F:\\brilliance\\jkpt-pj\\task\\南洋商业银行\\接口配置\\swift标准报文\\950.sf2"
;
String
msg
=
MessageAnalyzer
.
readFull
(
path
);
SWFMessage
swf
=
MessageAnalyzer
.
loadSwiftMessage
(
msg
);
System
.
out
.
println
(
swf
.
toJSON
());
}
public
void
testGetSWFMessage
()
{
SWFMessage
obj
=
MessageFormat
.
getSWFMessage
(
"101"
);
System
.
out
.
println
(
obj
.
getFlatModel
());
}
public
void
testRegWithName
()
{
String
reg
=
"((?<S1>\\d{6})((?<S2>\\d{4}))?)?((?<S3>[A-Z]{7}))?"
;
String
tagsCombo
=
"123456"
;
Matcher
m
=
Pattern
.
compile
(
reg
).
matcher
(
tagsCombo
);
if
(
m
.
find
())
{
System
.
out
.
println
(
m
.
group
(
"S1"
));
}
else
{
System
.
out
.
println
(
"no found"
);
}
reg
=
"^\\d+(\\.\\d)?$"
;
m
=
Pattern
.
compile
(
reg
).
matcher
(
"122."
);
if
(
m
.
find
()){
System
.
out
.
println
(
"yes"
);
}
else
{
System
.
out
.
println
(
"no"
);
}
}
public
void
testGetTagLineValue
(){
String
path
=
"F:\\brilliance\\jkpt-pj\\task\\南洋商业银行\\接口配置\\swift标准报文\\950.sf2"
;
String
msg
=
MessageAnalyzer
.
readFull
(
path
);
SWFMessage
swf
=
MessageAnalyzer
.
loadSwiftMessage
(
msg
);
//获取3域
System
.
out
.
println
(
swf
.
getGeneric
(
"3"
));
//获取3域第一部分
System
.
out
.
println
(
swf
.
getGeneric
(
"3.0"
));
}
}
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