Commit 5695a96a by gechengyang

完善代码

parent 7b2d8e63
...@@ -6,7 +6,11 @@ ...@@ -6,7 +6,11 @@
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="src" path="src/main/resources"/> <classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java"> <classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes> <attributes>
<attribute name="optional" value="true"/> <attribute name="optional" value="true"/>
...@@ -18,6 +22,6 @@ ...@@ -18,6 +22,6 @@
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jdk1.7"/>
<classpathentry kind="output" path="target/classes"/> <classpathentry kind="output" path="target/classes"/>
</classpath> </classpath>
/target/
#Tue Feb 12 10:54:25 CST 2019
eclipse.preferences.version=1
useAssemblyMapping=true
#Tue Feb 12 11:31:34 CST 2019
eclipse.preferences.version=1 eclipse.preferences.version=1
encoding//src/main/java=UTF-8 encoding//src/main/java=UTF-8
encoding//src/main/resources=UTF-8
encoding//src/main/resources/tags.properties=UTF-8 encoding//src/main/resources/tags.properties=UTF-8
encoding//src/test/java=UTF-8 encoding//src/test/java=UTF-8
encoding/<project>=UTF-8 encoding/<project>=UTF-8
#Tue Feb 12 11:31:34 CST 2019
eclipse.preferences.version=1 eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.compliance=1.8 org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.8 org.eclipse.jdt.core.compiler.source=1.7
...@@ -39,6 +39,12 @@ ...@@ -39,6 +39,12 @@
<version>2.8.5</version> <version>2.8.5</version>
</dependency> </dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.5</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml --> <!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml -->
<dependency> <dependency>
......
...@@ -12,6 +12,7 @@ import com.brilliace.swifteditor.tag.TagLine; ...@@ -12,6 +12,7 @@ import com.brilliace.swifteditor.tag.TagLine;
import com.brilliace.swifteditor.tag.message.MessageFormat; import com.brilliace.swifteditor.tag.message.MessageFormat;
import com.brilliace.swifteditor.tag.message.SWFMessage; import com.brilliace.swifteditor.tag.message.SWFMessage;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
/** /**
* Hello world! * Hello world!
...@@ -19,13 +20,14 @@ import com.google.gson.Gson; ...@@ -19,13 +20,14 @@ import com.google.gson.Gson;
*/ */
public class App public class App
{ {
static Gson gson = new GsonBuilder().disableHtmlEscaping().create();
public static void main( String[] args ) throws IOException public static void main( String[] args ) throws IOException
{ {
TagFormat.WalkTagCell("61", "6!n[4!n]2a[1!a]15d1!a3!c16x['//'16x]['CRLF'34x]"); // TagFormat.WalkTagCell("61", "6!n[4!n]2a[1!a]15d1!a3!c16x['//'16x]['CRLF'34x]");
// System.out.println( TagFormat.TagMap.get("71F").toAnalyzeReg() ); // System.out.println( TagFormat.TagMap.get("71F").toAnalyzeReg() );
// TagLine t59 = TagFormat.TagMap.get("79"); // TagLine t59 = TagFormat.TagMap.get("59");
// t59.setValue("14314321\n423424234\nasdgfasdgfasf\nafdagfadsf\r\nasdfasdfsaf"); // t59.setValue("/14314321\n423424234\nasdgfasdgfasf\nafdagfadsf\r\nasdfasdfsaf");
// System.out.println(t59); // System.out.println(gson.toJson(t59));
// System.out.println(new Gson().toJson(TagFormat.TagMap.get("34B").toSegRegMap())); // System.out.println(new Gson().toJson(TagFormat.TagMap.get("34B").toSegRegMap()));
// System.out.println(new Gson().toJson(TagFormat.WalkTagCell("51A", "['/'<DC>]['/'34x]['CRLF']<SWIFTBIC>"))); // System.out.println(new Gson().toJson(TagFormat.WalkTagCell("51A", "['/'<DC>]['/'34x]['CRLF']<SWIFTBIC>")));
// for(Map.Entry<String, TagLine> entry: TagFormat.TagMap.entrySet()) // for(Map.Entry<String, TagLine> entry: TagFormat.TagMap.entrySet())
...@@ -34,7 +36,6 @@ public class App ...@@ -34,7 +36,6 @@ public class App
// } // }
// MessageFormat.loadSWFMessage(); // MessageFormat.loadSWFMessage();
// SWFMessage swf = MessageFormat.getSWFMessage("202"); // SWFMessage swf = MessageFormat.getSWFMessage("202");
// //toJSON();
// System.out.println(swf.toFormatJSON()); // System.out.println(swf.toFormatJSON());
// generMTFormat(); // generMTFormat();
// System.out.println("111"); // System.out.println("111");
......
package com.brilliace.swifteditor.tag.message; package com.brilliace.swifteditor.tag.message;
import java.io.BufferedReader;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.FileReader; import java.io.FileReader;
import java.io.IOException; import java.io.IOException;
import java.io.StringReader;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
...@@ -14,31 +12,27 @@ import java.util.regex.Pattern; ...@@ -14,31 +12,27 @@ import java.util.regex.Pattern;
import com.brilliace.swifteditor.tag.TagFormat; import com.brilliace.swifteditor.tag.TagFormat;
import com.brilliace.swifteditor.tag.TagLine; import com.brilliace.swifteditor.tag.TagLine;
import com.google.gson.Gson;
import com.google.gson.internal.LinkedTreeMap;
public class MessageAnalyzer { public class MessageAnalyzer {
/* /*
* @param msg:报文字符串; 传递报文字符串,将其中的文首都解析出来。 对于ACK/NCK报文,后面会附带原报,会出现文首重复的情况,将附带的原报文首的KEY添加负号做为KEY,避免覆盖。 * @param msg:报文字符串; 传递报文字符串,将其中的文首都解析出来。
* 对于ACK/NCK报文,后面会附带原报,会出现文首重复的情况,将附带的原报文首的KEY添加负号做为KEY,避免覆盖。
* 如果后面附带了S等带字母的“文首”,则直接使用其Acsii码,作为KEY。 * 如果后面附带了S等带字母的“文首”,则直接使用其Acsii码,作为KEY。
*/ */
public static Map<Integer, String> anlyMsgHead(String msg) public static Map<Integer, String> anlyMsgHead(String msg) {
{
Map<Integer, String> headSet = new HashMap<Integer, String>(); Map<Integer, String> headSet = new HashMap<Integer, String>();
String reg = "\\{[\\d|S]:"; String reg = "\\{[\\d|S]:";
Matcher m = Pattern.compile(reg).matcher(msg); Matcher m = Pattern.compile(reg).matcher(msg);
int lstEnd = -1; int lstEnd = -1;
int lstHead = -1; int lstHead = -1;
while (m.find()) while (m.find()) {
{ if (lstEnd > 0 && lstHead > 0) {
if (lstEnd > 0 && lstHead > 0)
{
String val = msg.substring(lstEnd, m.start() - 1); String val = msg.substring(lstEnd, m.start() - 1);
if (!headSet.containsKey(lstHead)) if (!headSet.containsKey(lstHead)) {
{
headSet.put(lstHead, val); headSet.put(lstHead, val);
} } else {
else
{
headSet.put(-lstHead, val); headSet.put(-lstHead, val);
} }
} }
...@@ -65,19 +59,15 @@ public class MessageAnalyzer { ...@@ -65,19 +59,15 @@ public class MessageAnalyzer {
/* /*
* @param mt:对正文block 4中包含的栏位名称和栏位值切割,以换行符加“:”来切割 * @param mt:对正文block 4中包含的栏位名称和栏位值切割,以换行符加“:”来切割
*/ */
public static List<String[]> msgTxtAnly(String mt) public static List<String[]> msgTxtAnly(String mt) {
{ if (mt.startsWith(":"))
if(mt.startsWith(":")) mt = "\r\n" + mt;
mt = "\r\n"+mt;
String[] tags = mt.split("[\\r\\n]{1,2}:"); String[] tags = mt.split("[\\r\\n]{1,2}:");
List<String[]> list = new ArrayList<String[]>(); List<String[]> list = new ArrayList<String[]>();
for (String tv : tags) for (String tv : tags) {
{ if (tv.trim().length() > 0) {
if (tv.trim().length() > 0)
{
int i = tv.indexOf(':'); int i = tv.indexOf(':');
if (i > 0) if (i > 0) {
{
String[] arr = new String[2]; String[] arr = new String[2];
arr[0] = tv.substring(0, i); arr[0] = tv.substring(0, i);
arr[1] = tv.substring(i + 1); arr[1] = tv.substring(i + 1);
...@@ -85,20 +75,16 @@ public class MessageAnalyzer { ...@@ -85,20 +75,16 @@ public class MessageAnalyzer {
} }
} }
} }
if (list.size() > 0) if (list.size() > 0) {
{
String[] lstOne = list.get(list.size() - 1); String[] lstOne = list.get(list.size() - 1);
int i = lstOne[1].lastIndexOf("\r\n"); int i = lstOne[1].lastIndexOf("\r\n");
if (i < 0) if (i < 0) {
{
i = lstOne[1].lastIndexOf("\r"); i = lstOne[1].lastIndexOf("\r");
} }
if (i < 0) if (i < 0) {
{
i = lstOne[1].lastIndexOf("\n"); i = lstOne[1].lastIndexOf("\n");
} }
if (i > -1) if (i > -1) {
{
lstOne[1] = lstOne[1].substring(0, i); lstOne[1] = lstOne[1].substring(0, i);
list.set(list.size() - 1, lstOne); list.set(list.size() - 1, lstOne);
} }
...@@ -107,8 +93,7 @@ public class MessageAnalyzer { ...@@ -107,8 +93,7 @@ public class MessageAnalyzer {
} }
/* 屏蔽不同的系统的换行符差异,获取换行符位置 */ /* 屏蔽不同的系统的换行符差异,获取换行符位置 */
private static int getLinePos(String str) private static int getLinePos(String str) {
{
if (str == null) if (str == null)
return -1; return -1;
int idxr = str.indexOf("\r"); int idxr = str.indexOf("\r");
...@@ -116,23 +101,18 @@ public class MessageAnalyzer { ...@@ -116,23 +101,18 @@ public class MessageAnalyzer {
if (idxr > -1 && idxn > -1)// \r\n连接在一起 if (idxr > -1 && idxn > -1)// \r\n连接在一起
{ {
return idxr < idxn ? idxr : idxn; return idxr < idxn ? idxr : idxn;
} } else {
else
{
return idxr <= idxn ? idxn : idxr;// 单个\r或者\n的情况,返回较大的 return idxr <= idxn ? idxn : idxr;// 单个\r或者\n的情况,返回较大的
} }
} }
public static Map<String, String> getSwfMsgInfoViaMsg(Map<Integer, String> heads) public static Map<String, String> getSwfMsgInfoViaMsg(Map<Integer, String> heads) {
{
Map<String, String> infMap = new HashMap<String, String>(); Map<String, String> infMap = new HashMap<String, String>();
String hd4 = heads.get(4); String hd4 = heads.get(4);
boolean isNACK = false; // 是否为ACK/NCK报文 boolean isNACK = false; // 是否为ACK/NCK报文
if (hd4 != null) if (hd4 != null) {
{ if (hd4.contains("{451:0}") || hd4.contains("{451:1}")) {
if (hd4.contains("{451:0}") || hd4.contains("{451:1}"))
{
isNACK = true; isNACK = true;
if (hd4.contains("{451:0}")) if (hd4.contains("{451:0}"))
infMap.put("mty", "ACK"); infMap.put("mty", "ACK");
...@@ -140,14 +120,12 @@ public class MessageAnalyzer { ...@@ -140,14 +120,12 @@ public class MessageAnalyzer {
infMap.put("mty", "NCK"); infMap.put("mty", "NCK");
// infMap.put("ehf",heads.get(-4) ); // infMap.put("ehf",heads.get(-4) );
int errIdx = hd4.indexOf("{405:"); int errIdx = hd4.indexOf("{405:");
if (errIdx > -1) if (errIdx > -1) {
{
int idx2 = hd4.indexOf("}", errIdx);// 获取下一个括号 int idx2 = hd4.indexOf("}", errIdx);// 获取下一个括号
if (idx2 > -1) if (idx2 > -1)
infMap.put("errcod", hd4.substring(errIdx + 5, idx2));// 将错误码放进去 infMap.put("errcod", hd4.substring(errIdx + 5, idx2));// 将错误码放进去
} }
} } else
else
// 非ACK 或NCK报文 // 非ACK 或NCK报文
{ {
...@@ -166,15 +144,13 @@ public class MessageAnalyzer { ...@@ -166,15 +144,13 @@ public class MessageAnalyzer {
if (hd2 != null) // 拆解2文首 if (hd2 != null) // 拆解2文首
{ {
// 如果2文首不为空,开始获取收发方向和报文类型 // 如果2文首不为空,开始获取收发方向和报文类型
if (hd2.length() >= 4) if (hd2.length() >= 4) {
{
direct = hd2.substring(0, 1); direct = hd2.substring(0, 1);
infMap.put("direct", direct);// 存储报文方向 infMap.put("direct", direct);// 存储报文方向
msgTyp = hd2.substring(1, 4); msgTyp = hd2.substring(1, 4);
if ("I".equals(direct)) // 发出报文 if ("I".equals(direct)) // 发出报文
{ {
if (hd2.length() >= 16) if (hd2.length() >= 16) {
{
String rcvbic = hd2.substring(4, 16); // 获取收报行 String rcvbic = hd2.substring(4, 16); // 获取收报行
infMap.put("rcvbic", rcvbic); infMap.put("rcvbic", rcvbic);
} }
...@@ -184,15 +160,11 @@ public class MessageAnalyzer { ...@@ -184,15 +160,11 @@ public class MessageAnalyzer {
infMap.put("tns", hd2.substring(17, 18)); infMap.put("tns", hd2.substring(17, 18));
if (hd2.length() >= 21) if (hd2.length() >= 21)
infMap.put("dyt", hd2.substring(18, 21)); infMap.put("dyt", hd2.substring(18, 21));
} } else if ("O".equals(direct)) {
else if ("O".equals(direct)) if (hd2.length() >= 26) {
{
if (hd2.length() >= 26)
{
String sndbic = hd2.substring(14, 26); String sndbic = hd2.substring(14, 26);
infMap.put("sndbic", sndbic); // 获取发报行 infMap.put("sndbic", sndbic); // 获取发报行
if (hd2.length() >= 36) if (hd2.length() >= 36) {
{
infMap.put("mir", hd2.substring(8, 14) + " " + hd2.substring(14, 36));// 获取MIR infMap.put("mir", hd2.substring(8, 14) + " " + hd2.substring(14, 36));// 获取MIR
if (hd2.length() == 47) if (hd2.length() == 47)
infMap.put("prt", hd2.substring(46));// 电报优先级 infMap.put("prt", hd2.substring(46));// 电报优先级
...@@ -203,46 +175,34 @@ public class MessageAnalyzer { ...@@ -203,46 +175,34 @@ public class MessageAnalyzer {
} }
if (hd1 != null) // 拆解1文首 if (hd1 != null) // 拆解1文首
{ {
if (hd1.length() >= 15) if (hd1.length() >= 15) {
{
String bnk1 = hd1.substring(3, 15); String bnk1 = hd1.substring(3, 15);
if ("O".equals(direct)) if ("O".equals(direct)) {
{
infMap.put("rcvbic", bnk1); infMap.put("rcvbic", bnk1);
} } else if ("I".equals(direct)) {
else if ("I".equals(direct))
{
infMap.put("sndbic", bnk1); infMap.put("sndbic", bnk1);
} }
if (hd2 != null && hd2.length() >= 14) if (hd2 != null && hd2.length() >= 14) {
{
infMap.put("mor", hd2.substring(8, 14) + " " + hd1.substring(3));// 获取MOR infMap.put("mor", hd2.substring(8, 14) + " " + hd1.substring(3));// 获取MOR
} }
} }
} }
if (hd3 != null) if (hd3 != null) {
{ if (hd3.contains("{119:COV}")) {
if (hd3.contains("{119:COV}"))
{
msgTyp = msgTyp + "COV"; msgTyp = msgTyp + "COV";
} }
if (hd3.contains("{FMT:")) if (hd3.contains("{FMT:")) {
{
String fmt = hd3.substring(1, hd3.length() - 1); String fmt = hd3.substring(1, hd3.length() - 1);
String args[] = fmt.split(":"); String args[] = fmt.split(":");
infMap.put("fmttype", args[0]); infMap.put("fmttype", args[0]);
infMap.put("fmtstd", args[1]); infMap.put("fmtstd", args[1]);
String strarry[] = hd3.split("\\}"); String strarry[] = hd3.split("\\}");
for (String substr : strarry) for (String substr : strarry) {
{
substr = substr.substring(1); substr = substr.substring(1);
String sp[] = substr.split(":"); String sp[] = substr.split(":");
if (sp.length == 2) if (sp.length == 2) {
{
infMap.put(sp[0], sp[1]); infMap.put(sp[0], sp[1]);
} } else {
else
{
infMap.put(sp[0], null); infMap.put(sp[0], null);
} }
} }
...@@ -250,8 +210,7 @@ public class MessageAnalyzer { ...@@ -250,8 +210,7 @@ public class MessageAnalyzer {
// else if(hd3.contains("{119:STP}")) // else if(hd3.contains("{119:STP}"))
// msgTyp = msgTyp + "+"; // msgTyp = msgTyp + "+";
Matcher m = Pattern.compile("\\{108:\\w+\\}").matcher(hd3); Matcher m = Pattern.compile("\\{108:\\w+\\}").matcher(hd3);
if (m.find()) if (m.find()) {
{
String gp = m.group(); String gp = m.group();
int idx = gp.indexOf(":"); int idx = gp.indexOf(":");
infMap.put("sndnum", gp.substring(idx + 1, gp.length() - 1)); /* 取发报流水号 */ infMap.put("sndnum", gp.substring(idx + 1, gp.length() - 1)); /* 取发报流水号 */
...@@ -265,8 +224,7 @@ public class MessageAnalyzer { ...@@ -265,8 +224,7 @@ public class MessageAnalyzer {
if (hd4 != null) // 处理4域,即正文 if (hd4 != null) // 处理4域,即正文
{ {
List<String[]> kv = msgTxtAnly(hd4); List<String[]> kv = msgTxtAnly(hd4);
for (String[] strArr : kv) for (String[] strArr : kv) {
{
if (strArr[0].endsWith("20"))// 业务编号 if (strArr[0].endsWith("20"))// 业务编号
{ {
if (!infMap.containsKey("ref")) // 如果没有填入20栏,则将20栏填入,已填入则不进行覆盖。为nXX系列报文附带原报的情况 if (!infMap.containsKey("ref")) // 如果没有填入20栏,则将20栏填入,已填入则不进行覆盖。为nXX系列报文附带原报的情况
...@@ -293,8 +251,7 @@ public class MessageAnalyzer { ...@@ -293,8 +251,7 @@ public class MessageAnalyzer {
} }
if (strArr[0].endsWith("32A"))// 金额币种起息日 if (strArr[0].endsWith("32A"))// 金额币种起息日
{ {
if (strArr[1].matches("\\d{6}[A-Z]{3}\\d{1,15},\\d*")) if (strArr[1].matches("\\d{6}[A-Z]{3}\\d{1,15},\\d*")) {
{
String valDat = strArr[1].substring(0, 6); String valDat = strArr[1].substring(0, 6);
String cur = strArr[1].substring(6, 9); String cur = strArr[1].substring(6, 9);
String amt = strArr[1].substring(9); String amt = strArr[1].substring(9);
...@@ -304,19 +261,16 @@ public class MessageAnalyzer { ...@@ -304,19 +261,16 @@ public class MessageAnalyzer {
} }
} }
if (strArr[0].matches("62[FM]")) if (strArr[0].matches("62[FM]")) {
{
// 950/940对账单的币种金额起息日 // 950/940对账单的币种金额起息日
if (strArr[1] != null && strArr[1].matches("[DC]\\d{6}[A-Z]{3}\\d{1,15},\\d*")) if (strArr[1] != null && strArr[1].matches("[DC]\\d{6}[A-Z]{3}\\d{1,15},\\d*")) {
{
String valDat = strArr[1].substring(1, 7); String valDat = strArr[1].substring(1, 7);
String cur = strArr[1].substring(7, 10); String cur = strArr[1].substring(7, 10);
String amt = strArr[1].substring(10).replace(",", "."); String amt = strArr[1].substring(10).replace(",", ".");
infMap.put("vludat", valDat); infMap.put("vludat", valDat);
infMap.put("amt", amt.replace(",", ".")); infMap.put("amt", amt.replace(",", "."));
infMap.put("cur", cur); infMap.put("cur", cur);
} } else
else
return infMap; return infMap;
} }
if (strArr[0].matches("25")) // 获取940/950里面的账号 if (strArr[0].matches("25")) // 获取940/950里面的账号
...@@ -324,63 +278,50 @@ public class MessageAnalyzer { ...@@ -324,63 +278,50 @@ public class MessageAnalyzer {
String act = strArr[1]; String act = strArr[1];
infMap.put("act", act); infMap.put("act", act);
} }
if ("O".equals(infMap.get("direct")) && strArr[0].matches("54A") && strArr[1] != null) if ("O".equals(infMap.get("direct")) && strArr[0].matches("54A") && strArr[1] != null) {
{
String actbic = strArr[1]; String actbic = strArr[1];
int secondLine = getLinePos(actbic); int secondLine = getLinePos(actbic);
if (secondLine > -1) if (secondLine > -1) {
{
actbic = actbic.substring(secondLine); actbic = actbic.substring(secondLine);
actbic = actbic.replaceAll("\\r|\\n", "");// 去除遗留的\r\n actbic = actbic.replaceAll("\\r|\\n", "");// 去除遗留的\r\n
} }
infMap.put("actbic", actbic); infMap.put("actbic", actbic);
} }
if ("O".equals(infMap.get("direct")) && strArr[0].matches("53A") && strArr[1] != null) if ("O".equals(infMap.get("direct")) && strArr[0].matches("53A") && strArr[1] != null) {
{
String actbic = strArr[1]; String actbic = strArr[1];
int secondLine = getLinePos(actbic); int secondLine = getLinePos(actbic);
if (secondLine > -1) if (secondLine > -1) {
{
actbic = actbic.substring(secondLine); actbic = actbic.substring(secondLine);
actbic = actbic.replaceAll("\\r|\\n", "");// 去除遗留的\r\n actbic = actbic.replaceAll("\\r|\\n", "");// 去除遗留的\r\n
} }
infMap.put("t53bic", actbic); infMap.put("t53bic", actbic);
} }
if ("I".equals(direct) && strArr[0].matches("53A") && strArr[1] != null) if ("I".equals(direct) && strArr[0].matches("53A") && strArr[1] != null) {
{
String actbic = strArr[1]; String actbic = strArr[1];
int secondLine = getLinePos(actbic); int secondLine = getLinePos(actbic);
if (secondLine > -1) if (secondLine > -1) {
{
actbic = actbic.substring(secondLine); actbic = actbic.substring(secondLine);
actbic = actbic.replaceAll("\\r|\\n", "");// 去除遗留的\r\n actbic = actbic.replaceAll("\\r|\\n", "");// 去除遗留的\r\n
} }
infMap.put("actbic", actbic); infMap.put("actbic", actbic);
} }
if (strArr[0].matches("50[AK]") && strArr[1] != null) if (strArr[0].matches("50[AK]") && strArr[1] != null) {
{
int index = getLinePos(strArr[1]); int index = getLinePos(strArr[1]);
if (index > -1 && strArr[1].startsWith("/")) if (index > -1 && strArr[1].startsWith("/"))
infMap.put("act", strArr[1].substring(1, index)); infMap.put("act", strArr[1].substring(1, index));
if (strArr[0].endsWith("K")) if (strArr[0].endsWith("K")) {
{ if (index > -1) {
if (index > -1)
{
String nam = strArr[1].substring(index).replaceAll("^[\\r\\n]{1,2}", ""); String nam = strArr[1].substring(index).replaceAll("^[\\r\\n]{1,2}", "");
infMap.put("ordnamadr", nam); infMap.put("ordnamadr", nam);
} } else {
else
{
infMap.put("ordnamadr", strArr[1]); infMap.put("ordnamadr", strArr[1]);
} }
} }
} }
if (strArr[0].matches("59") && strArr[1] != null) if (strArr[0].matches("59") && strArr[1] != null) {
{
int index = getLinePos(strArr[1]); int index = getLinePos(strArr[1]);
String nam = strArr[1]; String nam = strArr[1];
if (index > -1 && strArr[1].startsWith("/")) if (index > -1 && strArr[1].startsWith("/")) {
{
String act = strArr[1].substring(1, index);// 取出前面的账号 String act = strArr[1].substring(1, index);// 取出前面的账号
infMap.put("act", act);// 填入59域的账号,收益人账号 infMap.put("act", act);// 填入59域的账号,收益人账号
infMap.put("benact", act);// 查询查复使用,需区分50域的账号 infMap.put("benact", act);// 查询查复使用,需区分50域的账号
...@@ -389,8 +330,7 @@ public class MessageAnalyzer { ...@@ -389,8 +330,7 @@ public class MessageAnalyzer {
infMap.put("bennamadr", nam); infMap.put("bennamadr", nam);
} }
// 下面主要对MT300起作用 // 下面主要对MT300起作用
if (strArr[0].endsWith("22C")) if (strArr[0].endsWith("22C")) {
{
if (!infMap.containsKey("comref")) // 如果没有填入22C栏 if (!infMap.containsKey("comref")) // 如果没有填入22C栏
{ {
if (strArr[1].length() > 16) if (strArr[1].length() > 16)
...@@ -399,8 +339,7 @@ public class MessageAnalyzer { ...@@ -399,8 +339,7 @@ public class MessageAnalyzer {
infMap.put("comref", strArr[1]); infMap.put("comref", strArr[1]);
} }
} }
if (strArr[0].endsWith("33B")) if (strArr[0].endsWith("33B")) {
{
String cur = strArr[1].substring(0, 3); String cur = strArr[1].substring(0, 3);
String amt = strArr[1].substring(3); String amt = strArr[1].substring(3);
infMap.put("sellamt", amt.replace(",", ".")); infMap.put("sellamt", amt.replace(",", "."));
...@@ -409,13 +348,11 @@ public class MessageAnalyzer { ...@@ -409,13 +348,11 @@ public class MessageAnalyzer {
} }
// 这里主要是对MT320起作用 // 这里主要是对MT320起作用
if (strArr[0].endsWith("17R")) if (strArr[0].endsWith("17R")) {
{
if (!infMap.containsKey("BorL")) if (!infMap.containsKey("BorL"))
infMap.put("BorL", strArr[1]); infMap.put("BorL", strArr[1]);
} }
if (strArr[0].endsWith("34E")) if (strArr[0].endsWith("34E")) {
{
String tagN = strArr[1].substring(0, 1); String tagN = strArr[1].substring(0, 1);
String interest = ""; String interest = "";
if ("N".equals(tagN)) if ("N".equals(tagN))
...@@ -425,14 +362,12 @@ public class MessageAnalyzer { ...@@ -425,14 +362,12 @@ public class MessageAnalyzer {
infMap.put("interest", interest.replace(",", ".")); infMap.put("interest", interest.replace(",", "."));
} }
// 公共区域 // 公共区域
if (strArr[0].endsWith("30V")) if (strArr[0].endsWith("30V")) {
{
if (!infMap.containsKey("m3xValDate")) if (!infMap.containsKey("m3xValDate"))
infMap.put("m3xValDate", strArr[1]); infMap.put("m3xValDate", strArr[1]);
} }
if (strArr[0].endsWith("32B")) if (strArr[0].endsWith("32B")) {
{
String cur = strArr[1].substring(0, 3); String cur = strArr[1].substring(0, 3);
String amt = strArr[1].substring(3); String amt = strArr[1].substring(3);
infMap.put("buyamt", amt.replace(",", ".")); infMap.put("buyamt", amt.replace(",", "."));
...@@ -443,116 +378,108 @@ public class MessageAnalyzer { ...@@ -443,116 +378,108 @@ public class MessageAnalyzer {
} }
return infMap; return infMap;
} }
/* /*
* @param msg:报文字符串 对报文信息的基本获取,如果是NCK/ACK报文则mty为NCK/ACK,如有附带报文,则附带的报文类型由emty记录 * @param msg:报文字符串
* 对报文信息的基本获取,如果是NCK/ACK报文则mty为NCK/ACK,如有附带报文,则附带的报文类型由emty记录
*/ */
public static Map<String, String> getSwfMsgInfoViaMsg(String msg) public static Map<String, String> getSwfMsgInfoViaMsg(String msg) {
{
if (msg == null || msg.trim().length() == 0) if (msg == null || msg.trim().length() == 0)
return new HashMap<String,String>(); return new HashMap<String, String>();
Map<Integer,String> headers = anlyMsgHead(msg); Map<Integer, String> headers = anlyMsgHead(msg);
return getSwfMsgInfoViaMsg(headers); return getSwfMsgInfoViaMsg(headers);
} }
/*** /***
* 解析TD的格式报文 * 解析TD的格式报文
*
* @param msg * @param msg
* @return * @return
*/ */
public static Map<String,String> getSwfMsgInfoViaTDMsg(String msg) public static Map<String, String> getSwfMsgInfoViaTDMsg(String msg) {
{ Map<String, String> bscInfo = new HashMap<String, String>();
Map<String,String> bscInfo = new HashMap<String,String>();
String reg = ":MT:(\\d{3})[\\r\\n]{1,2}:IO:(\\w{2,11})[\\r\\n]{1,2}:II:(\\w{2,11})[\\r\\n]{1,2}:MP:(\\w)"; String reg = ":MT:(\\d{3})[\\r\\n]{1,2}:IO:(\\w{2,11})[\\r\\n]{1,2}:II:(\\w{2,11})[\\r\\n]{1,2}:MP:(\\w)";
Matcher m = Pattern.compile(reg).matcher(msg); Matcher m = Pattern.compile(reg).matcher(msg);
if(!m.find()) if (!m.find())
return bscInfo ;// 错误的格式 return bscInfo;// 错误的格式
//bscInfo.put("mty", m.group(1)); // bscInfo.put("mty", m.group(1));
bscInfo.put("sndbic", m.group(3)); bscInfo.put("sndbic", m.group(3));
bscInfo.put("rcvbic", m.group(2)); bscInfo.put("rcvbic", m.group(2));
bscInfo.put("prt", m.group(4)); bscInfo.put("prt", m.group(4));
int idx = msg.indexOf(":EOH:", m.end()); int idx = msg.indexOf(":EOH:", m.end());
String tdmsgHead= msg.substring(0,idx); String tdmsgHead = msg.substring(0, idx);
bscInfo.put("tdmsgHead", tdmsgHead);//存头,方便前端组报 bscInfo.put("tdmsgHead", tdmsgHead);// 存头,方便前端组报
if(tdmsgHead.indexOf(":119:COV")> -1) if (tdmsgHead.indexOf(":119:COV") > -1) {
{ bscInfo.put("mty", m.group(1) + "COV");
bscInfo.put("mty", m.group(1)+"COV"); } else
}
else
bscInfo.put("mty", m.group(1)); bscInfo.put("mty", m.group(1));
msg = msg.substring(idx + ":EOH:".length());
msg = msg.substring(idx+":EOH:".length()); if (msg.endsWith("-"))
if(msg.endsWith("-")) msg = msg.substring(0, msg.length() - 1);
msg = msg.substring(0, msg.length()-1); Map<Integer, String> headers = new HashMap<Integer, String>();
Map<Integer,String> headers = new HashMap<Integer,String>();
headers.put(4, msg); headers.put(4, msg);
Map<String,String> infoMap = getSwfMsgInfoViaMsg(headers); Map<String, String> infoMap = getSwfMsgInfoViaMsg(headers);
infoMap.put("mty", bscInfo.get("mty")); infoMap.put("mty", bscInfo.get("mty"));
bscInfo.putAll(infoMap); bscInfo.putAll(infoMap);
return bscInfo; return bscInfo;
} }
public static SWFMessage loadSwiftFile(String path)
{ public static SWFMessage loadSwiftFile(String path) {
return loadSwiftMessage(readFull(path)); return loadSwiftMessage(readFull(path));
} }
public static SWFMessage loadSwiftMessage(String message) public static SWFMessage loadSwiftMessage(String message) {
{ Map<Integer, String> headers = null;
Map<Integer,String> headers = null;
Map<String,String> bscInfo = null; Map<String, String> bscInfo = null;
if(message.startsWith(":MT:")) // TD内部报文 if (message.startsWith(":MT:")) // TD内部报文
{ {
bscInfo = getSwfMsgInfoViaTDMsg(message); bscInfo = getSwfMsgInfoViaTDMsg(message);
int index = message.indexOf(":EOH:")+":EOH:".length(); int index = message.indexOf(":EOH:") + ":EOH:".length();
int lastIndex = message.lastIndexOf("-"); int lastIndex = message.lastIndexOf("-");
if(lastIndex > 0) if (lastIndex > 0)
message = message.substring(index, lastIndex).trim(); message = message.substring(index, lastIndex).trim();
else else
message = message.substring(index); message = message.substring(index);
headers = new HashMap<Integer,String>(); headers = new HashMap<Integer, String>();
headers.put(4, message); headers.put(4, message);
} } else {
else
{
headers = anlyMsgHead(message); headers = anlyMsgHead(message);
bscInfo = getSwfMsgInfoViaMsg(headers); bscInfo = getSwfMsgInfoViaMsg(headers);
} }
//取出报文类型 // 取出报文类型
String mty = bscInfo.get("mty"); String mty = bscInfo.get("mty");
System.out.print("---------"+mty); System.out.print("---------" + mty);
SWFMessage swf = MessageFormat.getSWFMessage(mty); SWFMessage swf = MessageFormat.getSWFMessage(mty);
swf.setHeaders(headers); swf.setHeaders(headers);
swf.setBscInfo(bscInfo); swf.setBscInfo(bscInfo);
List<String[]> tags = msgTxtAnly(headers.get(4)); List<String[]> tags = msgTxtAnly(headers.get(4));
String tagsCombo = getTagsStr(tags); String tagsCombo = getTagsStr(tags);
loadSwiftMessage(swf,tagsCombo,tags); loadSwiftMessage(swf, tagsCombo, tags);
return swf; return swf;
} }
private static int loadSwiftMessage(MessageArea area,String tagsCombo,List<String[]> tags) private static int loadSwiftMessage(MessageArea area, String tagsCombo, List<String[]> tags) {
{
StringBuilder buf = new StringBuilder(); StringBuilder buf = new StringBuilder();
generReg(area,buf); generReg(area, buf);
String reg = buf.toString(); String reg = buf.toString();
Matcher m = Pattern.compile(reg).matcher(tagsCombo); Matcher m = Pattern.compile(reg).matcher(tagsCombo);
if(!m.find() || m.start() == m.end()) if (!m.find() || m.start() == m.end())
return -1; //栏位格式不符 return -1; // 栏位格式不符
List<MessageArea> fieldList = ((AbstractMessageArea) area).getFields(); List<MessageArea> fieldList = ((AbstractMessageArea) area).getFields();
for(int i=0; i< fieldList.size();i++) for (int i = 0; i < fieldList.size(); i++) {
{
MessageArea item = fieldList.get(i); MessageArea item = fieldList.get(i);
if(item.getType() == MessageArea.TAG) if (item.getType() == MessageArea.TAG) {
{ // 直接捕获对应分组
//直接捕获对应分组 TagLine tag = (TagLine) item;
TagLine tag = (TagLine)item; String grpName = "T" + String.valueOf(tag.getTno());
String grpName = "T"+String.valueOf(tag.getTno());
String value = m.group(grpName); String value = m.group(grpName);
if(value == null) if (value == null)
continue; continue;
String[] valArr = value.split(","); String[] valArr = value.split(",");
//tag.setName(valArr[0]); // tag.setName(valArr[0]);
if(tag.getName().endsWith("a")) if (tag.getName().endsWith("a")) {
{
TagLine tag2 = TagFormat.getTagLine(valArr[0]); TagLine tag2 = TagFormat.getTagLine(valArr[0]);
tag2.setDesp(tag.getDesp()); tag2.setDesp(tag.getDesp());
tag2.setTno(tag.getTno()); tag2.setTno(tag.getTno());
...@@ -560,181 +487,155 @@ public class MessageAnalyzer { ...@@ -560,181 +487,155 @@ public class MessageAnalyzer {
tag2.setStatus(tag.getStatus()); tag2.setStatus(tag.getStatus());
tag2.getSuffix().addAll(tag.getSuffix()); tag2.getSuffix().addAll(tag.getSuffix());
tag = tag2; tag = tag2;
fieldList.set(i, tag); //置换新的栏位 fieldList.set(i, tag); // 置换新的栏位
} }
int idx = Integer.parseInt(valArr[1].substring(0, valArr[1].length()-1)); int idx = Integer.parseInt(valArr[1].substring(0, valArr[1].length() - 1));
tag.setValue(tags.get(idx)[1]);//还要考虑值分解 tag.setValue(tags.get(idx)[1]);// 还要考虑值分解
}else if(item.getType() == MessageArea.CYCLIST ) } else if (item.getType() == MessageArea.CYCLIST) {
{ String grpName = String.valueOf("C" + item.getName());
String grpName = String.valueOf("C"+item.getName()); String value = m.group(grpName); // 新的块级
String value = m.group(grpName); //新的块级 if (value == null || value.length() == 0)
if(value == null || value.length() == 0)
continue; continue;
MessageArea cp = ((AbstractMessageArea) item).getFields().get(0);//默认有一个组项 MessageArea cp = ((AbstractMessageArea) item).getFields().get(0);// 默认有一个组项
int offset = 0; int offset = 0;
do{ do {
offset = loadSwiftMessage(cp,value,tags); offset = loadSwiftMessage(cp, value, tags);
if(offset <= 0) if (offset <= 0)
break; break;
if(offset >= value.length()) if (offset >= value.length())
break; //提前终止,避免不必要的空循环 break; // 提前终止,避免不必要的空循环
cp = ((AbstractMessageArea) item).getPattern().clone(); cp = ((AbstractMessageArea) item).getPattern().clone();
item.addSubArea(cp); item.addSubArea(cp);
value = value.substring(offset); value = value.substring(offset);
} } while (true);
while(true); } else if (item.getType() == MessageArea.SEQLIST) {
}else if(item.getType() == MessageArea.SEQLIST ) String grpName = String.valueOf("S" + item.getName());
{ String value = m.group(grpName); // 新的块级
String grpName = String.valueOf("S"+item.getName()); if (value == null || value.length() == 0)
String value = m.group(grpName); //新的块级
if(value == null || value.length() == 0)
continue; continue;
MessageArea cp = ((AbstractMessageArea) item).getFields().get(0);//默认有一个组项 MessageArea cp = ((AbstractMessageArea) item).getFields().get(0);// 默认有一个组项
int offset = 0; int offset = 0;
do{ do {
offset = loadSwiftMessage(cp,value,tags); offset = loadSwiftMessage(cp, value, tags);
if(offset <= 0) if (offset <= 0)
break; break;
if(offset >= value.length()) if (offset >= value.length())
break; //提前终止,避免不必要的空循环 break; // 提前终止,避免不必要的空循环
cp = ((AbstractMessageArea) item).getPattern().clone(); cp = ((AbstractMessageArea) item).getPattern().clone();
item.addSubArea(cp); item.addSubArea(cp);
value = value.substring(offset); value = value.substring(offset);
} } while (true);
while(true);
} }
} }
return m.end(); return m.end();
} }
private static String getTagsStr(List<String[]> tags) private static String getTagsStr(List<String[]> tags) {
{
StringBuilder buf = new StringBuilder(); StringBuilder buf = new StringBuilder();
int cnt = 0; int cnt = 0;
for(String[] item:tags) for (String[] item : tags) {
{ // System.out.println(item[0]+"-----"+item[1]);
//System.out.println(item[0]+"-----"+item[1]); buf.append(item[0] + "," + cnt);
buf.append(item[0]+","+cnt);
cnt++; cnt++;
buf.append(";"); buf.append(";");
} }
return buf.toString(); return buf.toString();
} }
public static void generReg(MessageArea area,StringBuilder sb) public static void generReg(MessageArea area, StringBuilder sb) {
{
if(area.getType() == MessageArea.TAG) if (area.getType() == MessageArea.TAG) {
{ TagLine tag = (TagLine) area;
TagLine tag = (TagLine)area; sb.append("(?<T" + tag.getTno() + ">");
sb.append("(?<T"+tag.getTno()+">"); if (tag.getSuffix().size() != 0) {
if(tag.getSuffix().size() != 0 )
{
sb.append(tag.getName().substring(0, 2)); sb.append(tag.getName().substring(0, 2));
sb.append('['); sb.append('[');
boolean hasOpt = false; boolean hasOpt = false;
for(String item : tag.getSuffix()) for (String item : tag.getSuffix()) {
{ if (item.length() == 2)
if(item.length()==2)
hasOpt = true; hasOpt = true;
else else
sb.append(item.charAt(2)); sb.append(item.charAt(2));
} }
sb.append(']'); sb.append(']');
if(hasOpt) if (hasOpt)
sb.append('?'); sb.append('?');
} } else
else
sb.append(tag.getName()); sb.append(tag.getName());
sb.append(",\\d{1,3};)"); sb.append(",\\d{1,3};)");
if("O".equals(tag.getStatus())) if ("O".equals(tag.getStatus()))
sb.append('?'); sb.append('?');
return ; return;
} }
String defaultReg = ((AbstractMessageArea) area).getAnlyReg(); String defaultReg = ((AbstractMessageArea) area).getAnlyReg();
if(defaultReg!=null) if (defaultReg != null) {
{
sb.append(defaultReg); sb.append(defaultReg);
return; return;
} }
if(area instanceof SWFMessage) if (area instanceof SWFMessage) {
{ for (MessageArea item : ((AbstractMessageArea) area).getFields()) {
for(MessageArea item : ((AbstractMessageArea) area).getFields()) generReg(item, sb);
{
generReg(item,sb);
}
} }
else if(area.getType() == MessageArea.CYCLIST ) } else if (area.getType() == MessageArea.CYCLIST) {
{
StringBuilder buf = new StringBuilder(); StringBuilder buf = new StringBuilder();
buf.append('('); buf.append('(');
buf.append("?<C"+area.getName()+">"); buf.append("?<C" + area.getName() + ">");
buf.append('('); buf.append('(');
for(MessageArea item : ((AbstractMessageArea) area).getFields()) for (MessageArea item : ((AbstractMessageArea) area).getFields()) {
{ generReg(item, buf);
generReg(item,buf);
} }
buf.append(")*"); //块级区域的可选 buf.append(")*"); // 块级区域的可选
buf.append(')'); buf.append(')');
((AbstractMessageArea) area).setAnlyReg(buf.toString()); ((AbstractMessageArea) area).setAnlyReg(buf.toString());
sb.append(buf); sb.append(buf);
} } else if (area.getType() == MessageArea.SEQLIST) {
else if(area.getType() == MessageArea.SEQLIST)
{
StringBuilder buf = new StringBuilder(); StringBuilder buf = new StringBuilder();
buf.append('('); buf.append('(');
buf.append("?<S"+area.getName()+">"); buf.append("?<S" + area.getName() + ">");
buf.append('('); buf.append('(');
for(MessageArea item : ((AbstractMessageArea) area).getFields()) for (MessageArea item : ((AbstractMessageArea) area).getFields()) {
{ generReg(item, buf);
generReg(item,buf);
} }
SEQList seqlst = (SEQList)area; SEQList seqlst = (SEQList) area;
buf.append(')'); buf.append(')');
if(seqlst.getCyc()>0) if (seqlst.getCyc() > 0)
buf.append(")+"); //块级区域的可选 buf.append(")+"); // 块级区域的可选
buf.append(')'); buf.append(')');
if("O".equals(seqlst.getOm())) if ("O".equals(seqlst.getOm()))
buf.append('?'); buf.append('?');
((AbstractMessageArea) area).setAnlyReg(buf.toString()); ((AbstractMessageArea) area).setAnlyReg(buf.toString());
sb.append(buf); sb.append(buf);
} } else if (area.getType() == MessageArea.CYC || area.getType() == MessageArea.SEQ) {
else if(area.getType() == MessageArea.CYC || area.getType() == MessageArea.SEQ)
{
StringBuilder buf = new StringBuilder(); StringBuilder buf = new StringBuilder();
for(MessageArea item : ((AbstractMessageArea) area).getFields()) for (MessageArea item : ((AbstractMessageArea) area).getFields()) {
{ generReg(item, buf);
generReg(item,buf);
} }
((AbstractMessageArea) area).setAnlyReg(buf.toString()); ((AbstractMessageArea) area).setAnlyReg(buf.toString());
sb.append(buf); sb.append(buf);
} }
} }
public static String generReg(SWFMessage swf)
{ public static String generReg(SWFMessage swf) {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
generReg(swf,sb); generReg(swf, sb);
return sb.toString(); return sb.toString();
} }
public static String readFull(String path) {
public static String readFull(String path)
{
try { try {
FileReader reader = new FileReader(path); FileReader reader = new FileReader(path);
char[] buf = new char[1024]; char[] buf = new char[1024];
try { try {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
int len = -1; int len = -1;
while((len = reader.read(buf))!=-1) while ((len = reader.read(buf)) != -1) {
{ sb.append(buf, 0, len);
sb.append(buf,0,len);
} }
reader.close(); reader.close();
return sb.toString(); return sb.toString();
...@@ -748,16 +649,21 @@ public class MessageAnalyzer { ...@@ -748,16 +649,21 @@ public class MessageAnalyzer {
} }
return null; return null;
} }
public static void main(String[] args)
{ public static void main(String[] args) {
// SWFMessage swf = MessageFormat.getSWFMessage("202COV"); // SWFMessage swf = MessageFormat.getSWFMessage("202COV");
// System.out.println(swf.toFormatJSON()); // System.out.println(swf.toFormatJSON());
// MessageFormat.loadSWFMessage(); // MessageFormat.loadSWFMessage();
String path = "/Volumes/FUKAI/00026202.TXT"; String path = "d:/black/103.sf2";
String msg = readFull(path); String msg = readFull(path);
SWFMessage swf =loadSwiftMessage(msg); SWFMessage swf = loadSwiftMessage(msg);
System.out.print(swf.toJSON()); System.out.println("swiftType=" + swf.getMtType());
List<LinkedTreeMap> list = new Gson().fromJson(swf.toFormatJSON(), List.class);
// System.out.println(list);
// System.out.print(swf.toJSON());
for (LinkedTreeMap map : list) {
System.out.println(map.get("tag") + "...." + map.get("tagValue"));
}
} }
} }
package com.brilliance.black.util;
import java.io.File;
import java.io.FileInputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.io.IOUtils;
import com.brilliace.swifteditor.tag.message.MessageAnalyzer;
import com.brilliace.swifteditor.tag.message.SWFMessage;
import com.google.gson.Gson;
import com.google.gson.internal.LinkedTreeMap;
public class BlackListUtil {
private static List<SwiftTagInfo> swiftTagBlacks = new ArrayList<SwiftTagInfo>();
private static List<SwiftTagInfo> getSwiftTagBlacks(String blackTagPath) {
try {
if (swiftTagBlacks.size() == 0) {
List<String> fileList = IOUtils.readLines(new FileInputStream(new File(blackTagPath)), "utf-8");
for (String str : fileList) {
if (str == null || str.trim().equals(""))
continue;
String arr[] = str.split("\t");
SwiftTagInfo swiftTagBlack = new SwiftTagInfo();
swiftTagBlack.setMty(arr[0]);
swiftTagBlack.setTag(arr[1]);
swiftTagBlack.setDataPosition(arr[2]);
swiftTagBlack.setShootType(arr[3]);
swiftTagBlacks.add(swiftTagBlack);
}
}
} catch (Exception e) {
e.printStackTrace();
}
return swiftTagBlacks;
}
private static List<SwiftTagInfo> getSwiftTagBlacksByMty(String blackTagPath, String mty) {
getSwiftTagBlacks(blackTagPath);
List<SwiftTagInfo> lswiftTagBlacks = new ArrayList<SwiftTagInfo>();
for (SwiftTagInfo swiftTagBlack : swiftTagBlacks) {
if (swiftTagBlack.getMty().equals(mty)) {
lswiftTagBlacks.add(swiftTagBlack);
}
}
return lswiftTagBlacks;
}
@SuppressWarnings("rawtypes")
public static List<Map<String, Object>> detailsOfTags(String msg, String blackTagPath) {
List<Map<String, Object>> ret = new ArrayList<Map<String, Object>>();
SWFMessage swf = MessageAnalyzer.loadSwiftMessage(msg);
System.out.println("swiftType=" + swf.getMtType());
List<SwiftTagInfo> swiftTagBlacks = getSwiftTagBlacksByMty(blackTagPath, swf.getMtType());
@SuppressWarnings("rawtypes")
List<LinkedTreeMap> list = new Gson().fromJson(swf.toFormatJSON(), List.class);
System.out.println(swf.toJSON());
for (SwiftTagInfo swiftTagBlack : swiftTagBlacks) {
String tag = swiftTagBlack.getTag();
for (LinkedTreeMap map : list) {
if (map.get("tag") != null && map.get("tag").equals(tag)) {
Map<String, Object> retMap = new HashMap<String, Object>();
retMap.put("tag", tag);
retMap.put("label", map.get("label"));
if (map.get("tagValue") != null) {
List tagValueList = (List) map.get("tagValue");
for (Object obj : tagValueList) {
if (obj instanceof Map) {
retMap.put("tagValue", ((Map) obj).get(swiftTagBlack.getDataPosition()));
retMap.put("shootType", swiftTagBlack.getShootType());
}
}
}
ret.add(retMap);
}
}
}
return ret;
}
public static void main(String[] args) throws Exception {
String swiftMsg = IOUtils.toString(new FileInputStream(new File("d:/black/103.sf2")), "utf-8");
List<Map<String, Object>> list = detailsOfTags(swiftMsg, "C:/Users/ge/Desktop/blackList.txt");
System.out.println("list=" + list);
}
}
package com.brilliance.black.util;
public class SwiftTagInfo {
private String mty;// 报文类型
private String tag;
private String dataPosition;// 数据域位置 S1 S2 S3 S4 ...
private String shootType;// 1:BIC检查 2:名称地址检查
public String getMty() {
return mty;
}
public String getTag() {
return tag;
}
public String getShootType() {
return shootType;
}
public void setMty(String mty) {
this.mty = mty;
}
public void setTag(String tag) {
this.tag = tag;
}
public void setShootType(String shootType) {
this.shootType = shootType;
}
public String getDataPosition() {
return dataPosition;
}
public void setDataPosition(String dataPosition) {
this.dataPosition = dataPosition;
}
}
Manifest-Version: 1.0
Built-By: fukai
Build-Jdk: 1.8.0_121
Created-By: Maven Integration for Eclipse
#Generated by Maven Integration for Eclipse
#Tue Nov 06 10:48:36 CST 2018
version=0.0.1-SNAPSHOT
groupId=com.brilliace
m2e.projectName=swifteditor
m2e.projectLocation=/Users/fukai/Documents/workspace/swifteditor
artifactId=swifteditor
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.brilliace</groupId>
<artifactId>swifteditor</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>swifteditor</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.10.1</version>
</dependency>
<!-- <dependency>
<groupId>com.thoughtworks.xstream</groupId>
<artifactId>xstream</artifactId>
<version>1.4.10</version>
</dependency>
<dependency>
<groupId>org.codehaus.jettison</groupId>
<artifactId>jettison</artifactId>
<version>1.3.5</version>
</dependency> -->
<!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.5</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.10.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.freemarker/freemarker -->
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
<version>2.3.28</version>
<!-- <scope>test</scope> -->
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>swifteditor</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
#Generated by Maven #Generated by Maven
#Tue Nov 06 10:48:50 CST 2018 #Tue Aug 20 11:08:02 CST 2019
version=0.0.1-SNAPSHOT version=0.0.1-SNAPSHOT
groupId=com.brilliace groupId=com.brilliace
artifactId=swifteditor artifactId=swifteditor
com/brilliace/swifteditor/tag/message/CYCList.class com\brilliace\swifteditor\tag\message\CYC.class
com/brilliace/swifteditor/tag/message/CYC.class com\brilliace\swifteditor\tag\TagCell.class
com/brilliace/swifteditor/tag/TagFormat.class com\brilliace\swifteditor\tag\message\SWFMessage.class
com/brilliace/swifteditor/tag/message/MessageArea.class com\brilliace\swifteditor\tag\message\SEQList.class
com/brilliace/swifteditor/tag/message/SWFMessage.class com\brilliace\swifteditor\tag\message\CYCList.class
com/brilliace/swifteditor/tag/message/MessageAnalyzer.class com\brilliace\swifteditor\tag\message\AbstractMessageArea.class
com/brilliace/swifteditor/tag/message/SEQ.class com\brilliace\swifteditor\tag\message\SEQ.class
com/brilliace/swifteditor/tag/message/AbstractMessageArea.class com\brilliace\swifteditor\tag\TagFormat.class
com/brilliace/swifteditor/tag/message/JSOutputTools.class com\brilliace\swifteditor\tag\message\MessageArea.class
com/brilliace/swifteditor/tag/TagLine.class com\brilliace\swifteditor\App.class
com/brilliace/swifteditor/tag/message/MessageFormat.class com\brilliace\swifteditor\tag\message\JSOutputTools.class
com/brilliace/swifteditor/tag/TagAnalyzer.class com\brilliace\swifteditor\tag\TagLine.class
com/brilliace/swifteditor/App.class com\brilliace\swifteditor\tag\message\MessageFormat.class
com/brilliace/swifteditor/tag/TagCell.class com\brilliace\swifteditor\tag\TagAnalyzer.class
com/brilliace/swifteditor/tag/message/SEQList.class com\brilliace\swifteditor\tag\message\MessageAnalyzer.class
com/brilliace/swifteditor/AppTest.class com\brilliace\swifteditor\AppTest.class
<?xml version="1.0" encoding="UTF-8" ?> <?xml version="1.0" encoding="UTF-8" ?>
<testsuite tests="1" failures="0" name="com.brilliace.swifteditor.AppTest" time="0.004" errors="0" skipped="0"> <testsuite failures="0" time="0.006" errors="0" skipped="0" tests="1" name="com.brilliace.swifteditor.AppTest">
<properties> <properties>
<property name="java.runtime.name" value="Java(TM) SE Runtime Environment"/> <property name="java.runtime.name" value="Java(TM) SE Runtime Environment"/>
<property name="sun.boot.library.path" value="/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib"/> <property name="sun.boot.library.path" value="G:\eclipse64\jdk1.7\jre\bin"/>
<property name="java.vm.version" value="25.121-b13"/> <property name="java.vm.version" value="24.75-b04"/>
<property name="gopherProxySet" value="false"/>
<property name="java.vm.vendor" value="Oracle Corporation"/> <property name="java.vm.vendor" value="Oracle Corporation"/>
<property name="maven.multiModuleProjectDirectory" value="/Users/fukai/Documents/workspace/swifteditor"/>
<property name="java.vendor.url" value="http://java.oracle.com/"/> <property name="java.vendor.url" value="http://java.oracle.com/"/>
<property name="path.separator" value=":"/> <property name="path.separator" value=";"/>
<property name="guice.disable.misplaced.annotation.check" value="true"/> <property name="guice.disable.misplaced.annotation.check" value="true"/>
<property name="java.vm.name" value="Java HotSpot(TM) 64-Bit Server VM"/> <property name="java.vm.name" value="Java HotSpot(TM) 64-Bit Server VM"/>
<property name="file.encoding.pkg" value="sun.io"/> <property name="file.encoding.pkg" value="sun.io"/>
<property name="user.script" value=""/>
<property name="user.country" value="CN"/> <property name="user.country" value="CN"/>
<property name="sun.java.launcher" value="SUN_STANDARD"/> <property name="sun.java.launcher" value="SUN_STANDARD"/>
<property name="sun.os.patch.level" value="unknown"/> <property name="sun.os.patch.level" value=""/>
<property name="java.vm.specification.name" value="Java Virtual Machine Specification"/> <property name="java.vm.specification.name" value="Java Virtual Machine Specification"/>
<property name="user.dir" value="/Users/fukai/Documents/workspace/swifteditor"/> <property name="user.dir" value="G:\work\swifteditor_java"/>
<property name="java.runtime.version" value="1.8.0_121-b13"/> <property name="java.runtime.version" value="1.7.0_75-b13"/>
<property name="java.awt.graphicsenv" value="sun.awt.CGraphicsEnvironment"/> <property name="java.awt.graphicsenv" value="sun.awt.Win32GraphicsEnvironment"/>
<property name="java.endorsed.dirs" value="/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/endorsed"/> <property name="java.endorsed.dirs" value="G:\eclipse64\jdk1.7\jre\lib\endorsed"/>
<property name="os.arch" value="x86_64"/> <property name="os.arch" value="amd64"/>
<property name="java.io.tmpdir" value="/var/folders/pd/hbf3q9xx6fq6p9j1nn7kx0xw0000gn/T/"/> <property name="java.io.tmpdir" value="C:\Users\ge\AppData\Local\Temp\"/>
<property name="line.separator" value=" <property name="line.separator" value="
"/> "/>
<property name="java.vm.specification.vendor" value="Oracle Corporation"/> <property name="java.vm.specification.vendor" value="Oracle Corporation"/>
<property name="os.name" value="Mac OS X"/> <property name="user.variant" value=""/>
<property name="classworlds.conf" value="/Users/fukai/Documents/workspace/.metadata/.plugins/org.eclipse.m2e.launching/launches/m2conf6118131129949174889.tmp"/> <property name="os.name" value="Windows 8.1"/>
<property name="sun.jnu.encoding" value="UTF-8"/> <property name="classworlds.conf" value="G:\work\cbpp\.metadata\.plugins\org.eclipse.m2e.launching\launches\m2conf5593905727808716630.tmp"/>
<property name="java.library.path" value="/Users/fukai/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:."/> <property name="sun.jnu.encoding" value="GBK"/>
<property name="java.library.path" value="G:\eclipse64\jdk1.7\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;d:\Program Files\Git\cmd;D:\Program Files\TortoiseSVN\bin;D:\Program Files\nodejs\;d:\Program Files (x86)\Tesseract-OCR;C:\Users\ge\AppData\Local\Microsoft\WindowsApps;G:\eclipse64\jdk1.8\bin;D:\Program\apache-maven-3.2.3\bin;&quot;E:\reactNative\android\sdk\tools;E:\reactNative\android\sdk\platform-tools&quot;;C:\Users\ge\AppData\Roaming\npm;E:\reactNative\android\sdk\platforms;E:\reactNative\android\sdk\platform-tools;E:\SoftWare\mysql-5.6.24-winx64\bin;D:\Program Files\nodejs;;."/>
<property name="java.specification.name" value="Java Platform API Specification"/> <property name="java.specification.name" value="Java Platform API Specification"/>
<property name="java.class.version" value="52.0"/> <property name="java.class.version" value="51.0"/>
<property name="sun.management.compiler" value="HotSpot 64-Bit Tiered Compilers"/> <property name="sun.management.compiler" value="HotSpot 64-Bit Tiered Compilers"/>
<property name="os.version" value="10.14.1"/> <property name="os.version" value="6.3"/>
<property name="user.home" value="/Users/fukai"/> <property name="user.home" value="C:\Users\ge"/>
<property name="user.timezone" value="Asia/Shanghai"/> <property name="user.timezone" value="Asia/Shanghai"/>
<property name="java.awt.printerjob" value="sun.lwawt.macosx.CPrinterJob"/> <property name="java.awt.printerjob" value="sun.awt.windows.WPrinterJob"/>
<property name="java.specification.version" value="1.8"/> <property name="java.specification.version" value="1.7"/>
<property name="file.encoding" value="UTF-8"/> <property name="file.encoding" value="GBK"/>
<property name="user.name" value="fukai"/> <property name="user.name" value="ge"/>
<property name="java.class.path" value="/Users/fukai/eclipse/jee-neon/Eclipse.app/Contents/Eclipse/../../../../../.p2/pool/plugins/org.eclipse.m2e.maven.runtime_1.7.0.20160603-1931/jars/plexus-classworlds-2.5.2.jar"/> <property name="java.class.path" value="/G:/eclipse64/plugins/org.eclipse.m2e.maven.runtime_1.5.0.20140605-2032/jars/plexus-classworlds-2.5.1.jar"/>
<property name="java.vm.specification.version" value="1.8"/> <property name="org.slf4j.simpleLogger.defaultLogLevel" value="info"/>
<property name="java.vm.specification.version" value="1.7"/>
<property name="sun.arch.data.model" value="64"/> <property name="sun.arch.data.model" value="64"/>
<property name="java.home" value="/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre"/> <property name="java.home" value="G:\eclipse64\jdk1.7\jre"/>
<property name="sun.java.command" value="org.codehaus.plexus.classworlds.launcher.Launcher -B -gs /Users/fukai/apache-maven-3.3.9/conf/settings.xml -s /Users/fukai/apache-maven-3.3.9/conf/settings.xml install"/> <property name="sun.java.command" value="org.codehaus.plexus.classworlds.launcher.Launcher -B -s D:\MavenRepository\settings.xml install"/>
<property name="java.specification.vendor" value="Oracle Corporation"/> <property name="java.specification.vendor" value="Oracle Corporation"/>
<property name="user.language" value="zh"/> <property name="user.language" value="zh"/>
<property name="awt.toolkit" value="sun.lwawt.macosx.LWCToolkit"/> <property name="awt.toolkit" value="sun.awt.windows.WToolkit"/>
<property name="java.vm.info" value="mixed mode"/> <property name="java.vm.info" value="mixed mode"/>
<property name="java.version" value="1.8.0_121"/> <property name="java.version" value="1.7.0_75"/>
<property name="java.ext.dirs" value="/Users/fukai/Library/Java/Extensions:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/ext:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java"/> <property name="java.ext.dirs" value="G:\eclipse64\jdk1.7\jre\lib\ext;C:\WINDOWS\Sun\Java\lib\ext"/>
<property name="sun.boot.class.path" value="/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/resources.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/rt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/sunrsasign.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/jsse.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/jce.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/charsets.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/jfr.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/classes"/> <property name="sun.boot.class.path" value="G:\eclipse64\jdk1.7\jre\lib\resources.jar;G:\eclipse64\jdk1.7\jre\lib\rt.jar;G:\eclipse64\jdk1.7\jre\lib\sunrsasign.jar;G:\eclipse64\jdk1.7\jre\lib\jsse.jar;G:\eclipse64\jdk1.7\jre\lib\jce.jar;G:\eclipse64\jdk1.7\jre\lib\charsets.jar;G:\eclipse64\jdk1.7\jre\lib\jfr.jar;G:\eclipse64\jdk1.7\jre\classes"/>
<property name="java.vendor" value="Oracle Corporation"/> <property name="java.vendor" value="Oracle Corporation"/>
<property name="maven.home" value="/Users/fukai/Documents/workspace/swifteditor/EMBEDDED"/> <property name="maven.home" value="G:\work\swifteditor_java\EMBEDDED"/>
<property name="file.separator" value="/"/> <property name="file.separator" value="\"/>
<property name="java.vendor.url.bug" value="http://bugreport.sun.com/bugreport/"/> <property name="java.vendor.url.bug" value="http://bugreport.sun.com/bugreport/"/>
<property name="sun.cpu.endian" value="little"/> <property name="sun.cpu.endian" value="little"/>
<property name="sun.io.unicode.encoding" value="UnicodeBig"/> <property name="sun.io.unicode.encoding" value="UnicodeLittle"/>
<property name="sun.cpu.isalist" value=""/> <property name="sun.desktop" value="windows"/>
<property name="sun.cpu.isalist" value="amd64"/>
</properties> </properties>
<testcase classname="com.brilliace.swifteditor.AppTest" name="testApp" time="0.004"/> <testcase time="0.006" classname="com.brilliace.swifteditor.AppTest" name="testApp"/>
</testsuite> </testsuite>
\ No newline at end of file
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Test set: com.brilliace.swifteditor.AppTest Test set: com.brilliace.swifteditor.AppTest
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.024 sec Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.008 sec
No preview for this file type
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