Commit 30dcc426 by WeiCong

1.修复多层sequence嵌套的报文解析

parent f0cf660a
...@@ -225,6 +225,9 @@ public class TagLine implements MessageArea { ...@@ -225,6 +225,9 @@ public class TagLine implements MessageArea {
} }
String analyzeReg = null; String analyzeReg = null;
public void setAnalyzeReg(String analyzeReg){
this.analyzeReg=analyzeReg;
}
public String getAnalyzeReg() public String getAnalyzeReg()
{ {
if(analyzeReg==null) if(analyzeReg==null)
......
...@@ -46,6 +46,7 @@ public class SEQList extends AbstractMessageArea { ...@@ -46,6 +46,7 @@ public class SEQList extends AbstractMessageArea {
cp.setAnlyReg(this.getAnlyReg()); cp.setAnlyReg(this.getAnlyReg());
cp.setDesp(this.getDesp()); cp.setDesp(this.getDesp());
cp.setOm(this.getOm()); cp.setOm(this.getOm());
cp.setCyc(this.getCyc());
return cp; return cp;
} }
......
...@@ -5,8 +5,8 @@ import com.brilliace.swifteditor.tag.message.MessageFormat; ...@@ -5,8 +5,8 @@ import com.brilliace.swifteditor.tag.message.MessageFormat;
import com.brilliace.swifteditor.tag.message.SWFMessage; import com.brilliace.swifteditor.tag.message.SWFMessage;
import junit.framework.TestCase; import junit.framework.TestCase;
import java.util.regex.Matcher; import java.util.LinkedList;
import java.util.regex.Pattern; import java.util.List;
public class ParseSwiftTest extends TestCase { public class ParseSwiftTest extends TestCase {
public void testLoadSwiftMessage() { public void testLoadSwiftMessage() {
...@@ -16,37 +16,98 @@ public class ParseSwiftTest extends TestCase { ...@@ -16,37 +16,98 @@ public class ParseSwiftTest extends TestCase {
System.out.println(swf.toJSON()); System.out.println(swf.toJSON());
} }
public void testGetSWFMessage() { public void testGetFlatModel() {
SWFMessage obj = MessageFormat.getSWFMessage("101"); SWFMessage obj = MessageFormat.getSWFMessage("101");
System.out.println(obj.getFlatModel()); System.out.println(obj.getFlatModel());
} }
public void testRegWithName() { public void testGetGeneric() {
String reg = "((?<S1>\\d{6})((?<S2>\\d{4}))?)?((?<S3>[A-Z]{7}))?"; String path = ParseSwiftTest.class.getClassLoader().getResource("950.sf2").getPath();
String tagsCombo = "123456"; String msg = MessageAnalyzer.readFull(path);
Matcher m = Pattern.compile(reg).matcher(tagsCombo); SWFMessage swf = MessageAnalyzer.loadSwiftMessage(msg);
if (m.find()) { System.out.println("获取4域(60F)=" + swf.getGeneric("4"));
System.out.println(m.group("S1")); System.out.println("获取4域第二部分(60F的<DATE2>部分)=" + swf.getGeneric("4.1"));
} else { System.out.println("获取循环域5(61)=" + swf.getGeneric("5"));
System.out.println("no found"); System.out.println("获取循环域5第一域块(61的6!n)=" + swf.getGeneric("5.0"));
}
reg="^\\d+(\\.\\d)?$"; path = path = ParseSwiftTest.class.getClassLoader().getResource("101.sf2").getPath();
m = Pattern.compile(reg).matcher("122."); msg = MessageAnalyzer.readFull(path);
if(m.find()){ swf = MessageAnalyzer.loadSwiftMessage(msg);
System.out.println("yes"); System.out.println("获取1域(不可循环的Sequence A的20域)=" + swf.getGeneric("1"));
}else{ System.out.println("获取10域(循环的Sequence B的21域)=" + swf.getGeneric("10"));
System.out.println("no"); System.out.println("获取12域(循环的Sequence B下的循环部分的23E域)=" + swf.getGeneric("12"));
}
} }
public void testGetTagLineValue(){ public void testGetGenericByIndexes() {
String path = "F:\\brilliance\\jkpt-pj\\task\\南洋商业银行\\接口配置\\swift标准报文\\950.sf2"; String path = ParseSwiftTest.class.getClassLoader().getResource("950.sf2").getPath();
String msg = MessageAnalyzer.readFull(path); String msg = MessageAnalyzer.readFull(path);
SWFMessage swf = MessageAnalyzer.loadSwiftMessage(msg); SWFMessage swf = MessageAnalyzer.loadSwiftMessage(msg);
//获取3域 System.out.println("获取循环域5(61)的第二个成员=" + swf.getGenericByIndexes("5", 1));
System.out.println(swf.getGeneric("3")); System.out.println("获取循环域5第一域块(61的6!n)的第二个成员=" + swf.getGenericByIndexes("5.0", 1));
//获取3域第一部分 path = path = ParseSwiftTest.class.getClassLoader().getResource("101.sf2").getPath();
System.out.println(swf.getGeneric("3.0")); msg = MessageAnalyzer.readFull(path);
swf = MessageAnalyzer.loadSwiftMessage(msg);
System.out.println("获取12域(循环的Sequence B下的循环部分的23E域)的第二个sequence的第三个成员="
+ swf.getGenericByIndexes("12", 1, 2));
}
public void testSetGeneric() {
SWFMessage swf = MessageFormat.getSWFMessage("950");
//填充950的20域
swf.setGeneric("1", "STMMDL129058636E");
assertEquals(swf.getGeneric("1"), "STMMDL129058636E");
//填充950的60a域
swf.setGeneric("4", "C120330GBP94854,84", "60F");
assertEquals(swf.getGeneric("4"), "C120330GBP94854,84");
//填充950的60a域的第二部分
swf.setGeneric("4.1", "120330", "60F");
assertEquals(swf.getGeneric("4.1"), "120330");
//填充950的61循环域
List<String> sixtyone = new LinkedList<String>();
sixtyone.add("1204120402DP10000,25S103CP23712040100007//GBS020420N8IM0HT\n" +
"FENG XING");
sixtyone.add("1304220402DP30000,55S103CP23712040100003//GBS02042H98IM0HS\n" +
"FENG ZZWE");
sixtyone.add("1404320402DP20115,S103CP23712040200001//GBS020428Z8IVWJK\n" +
"FENG EFFE");
swf.setGeneric("5", sixtyone);
assertEquals(swf.getGeneric("5"), sixtyone);
//填充950的61域第5部分,Amount
swf = MessageFormat.getSWFMessage("950");
List<String> sixtyone_amount = new LinkedList<String>();
sixtyone_amount.add("10000,25");
sixtyone_amount.add("30000,55");
sixtyone_amount.add("20115,");
swf.setGeneric("5.4", sixtyone_amount);
assertEquals(swf.getGeneric("5.4"), sixtyone_amount);
//填充101的不可循环的Sequence A的20域
swf = MessageFormat.getSWFMessage("101");
List<String> one = new LinkedList<>();
one.add("STMMDL129058636E");
swf.setGeneric("1", one);
assertEquals(swf.getGeneric("1"), one);
//填充101的循环的Sequence B的21域
List<Object> comList = new LinkedList<>();
one = new LinkedList<>();
one.add("101651ATT000005W");
comList.add(one);
one = new LinkedList<>();
one.add("321651ATT000005Z");
comList.add(one);
swf.setGeneric("10", comList);
assertEquals(swf.getGeneric("10"), comList);
//填充101的循环的Sequence B的23E循环域
comList = new LinkedList<>();
one = new LinkedList<>();
one.add("CHQB/HELLO");
one.add("CHQB/WORLD");
comList.add(one);
one = new LinkedList<>();
one.add("CHQB/MY");
one.add("CHQB/NAME");
one.add("CHQB/IS");
comList.add(one);
swf.setGeneric("12", comList);
assertEquals(swf.getGeneric("12"), comList);
} }
} }
{1:F01PSBCCNBJAXXX0216122148}{2:O1010000120403MIDLGB22AXXX00000000001204030000N}{4:
:20:STMMDL129058636E
:28D:00066/00001
:30:123456
:21:101651ATT000005W
:23E:CHQB/HELLO
:23E:CHQB/WORLD
:32B:USD80000,
:59:/22222222222
STRIX LIMITED
FORREST HOUSE RONALDSWAY BALLASALLA
ISLE OF MAN UK
:71A:BEN
:21:321651ATT000005Z
:23E:CHQB/MY
:23E:CHQB/NAME
:23E:CHQB/IS
:32B:USD12322,11
:59:/11111111111
HOLLW LSHIUHIWA
WZDESSS HOUSE WAWAZDR
DEDFFF OF EE ZK
:71A:OUR
-}
\ No newline at end of file
{1:F01PSBCCNBJAXXX0216122148}{2:O9500000120403MIDLGB22AXXX00000000001204030000N}{4:
:20:STMMDL129058636E
:25:68446375
:28C:00066/00001
:60F:C120330GBP94854,84
:61:1204120402DP10000,25S103CP23712040100007//GBS020420N8IM0HT
FENG XING
:61:1304220402DP30000,55S103CP23712040100003//GBS02042H98IM0HS
FENG ZZWE
:61:1404320402DP20115,S103CP23712040200001//GBS020428Z8IVWJK
FENG EFFE
:62F:C120402GBP14739,84
:64:C120402GBP14739,84
-}{5:{CHK:EEE63030C50C}}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment