Commit 4a71a6a4 by fukai

合并文件

parent 83f6687b
......@@ -12,6 +12,7 @@ import com.brilliace.swifteditor.tag.TagLine;
import com.brilliace.swifteditor.tag.message.MessageFormat;
import com.brilliace.swifteditor.tag.message.SWFMessage;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
/**
* Hello world!
......@@ -19,6 +20,7 @@ import com.google.gson.Gson;
*/
public class App
{
static Gson gson = new GsonBuilder().disableHtmlEscaping().create();
public static void main( String[] args ) throws IOException
{
// generMTFormat();
......@@ -29,6 +31,7 @@ public class App
// TagLine t59 = TagFormat.TagMap.get("79");
// t59.setValue("14314321\n423424234\nasdgfasdgfasf\nafdagfadsf\r\nasdfasdfsaf");
// System.out.println(t59);
// System.out.println(new Gson().toJson(TagFormat.TagMap.get("34B").toSegRegMap()));
// System.out.println(new Gson().toJson(TagFormat.WalkTagCell("51A", "['/'<DC>]['/'34x]['CRLF']<SWIFTBIC>")));
// for(Map.Entry<String, TagLine> entry: TagFormat.TagMap.entrySet())
......@@ -37,7 +40,6 @@ public class App
// }
// MessageFormat.loadSWFMessage();
// SWFMessage swf = MessageFormat.getSWFMessage("202");
// //toJSON();
// System.out.println(swf.toFormatJSON());
// generMTFormat();
// System.out.println("111");
......
package com.brilliace.swifteditor.tag.message;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
......@@ -14,7 +12,8 @@ import java.util.regex.Pattern;
import com.brilliace.swifteditor.tag.TagFormat;
import com.brilliace.swifteditor.tag.TagLine;
import com.google.gson.Gson;
import com.google.gson.internal.LinkedTreeMap;
public class MessageAnalyzer {
/*
......@@ -759,9 +758,8 @@ public class MessageAnalyzer {
try {
StringBuilder sb = new StringBuilder();
int len = -1;
while((len = reader.read(buf))!=-1)
{
sb.append(buf,0,len);
while ((len = reader.read(buf)) != -1) {
sb.append(buf, 0, len);
}
reader.close();
return sb.toString();
......@@ -774,6 +772,7 @@ public class MessageAnalyzer {
e.printStackTrace();
}
return null;
<<<<<<< HEAD
}
public static void main(String[] args)
{
......@@ -790,4 +789,24 @@ public class MessageAnalyzer {
//System.out.println(value.matches(TagFormat.TagMap.get("79").toAnalyzeReg()));
}
=======
}
public static void main(String[] args) {
// SWFMessage swf = MessageFormat.getSWFMessage("202COV");
// System.out.println(swf.toFormatJSON());
// MessageFormat.loadSWFMessage();
String path = "d:/black/103.sf2";
String msg = readFull(path);
SWFMessage swf = loadSwiftMessage(msg);
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"));
}
}
>>>>>>> 9f1e374811c69ecece4e29dc2a1ddb7bdc7c6538
}
package com.brilliace.swifteditor.tag.message;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;
......@@ -9,68 +8,75 @@ import com.google.gson.Gson;
public class SWFMessage extends AbstractMessageArea {
private String mtType;
private Map<Integer,String> headers;
private Map<Integer, String> headers;
public Map<Integer, String> getHeaders() {
return headers;
}
public void setHeaders(Map<Integer, String> headers) {
Map<Integer,String> clone = new HashMap<Integer,String>();
Map<Integer, String> clone = new HashMap<Integer, String>();
clone.putAll(headers);
clone.remove(4);
this.headers = clone;
}
public Map<String, String> getBscInfo() {
return bscInfo;
}
public void setBscInfo(Map<String, String> bscInfo) {
this.bscInfo = bscInfo;
}
private Map<String,String> bscInfo;
private Map<String, String> bscInfo;
public String getMtType() {
return mtType;
}
public void setMtType(String mtType) {
this.mtType = mtType;
}
protected SWFMessage()
{
protected SWFMessage() {
}
public static SWFMessage loadMTTemp(String mt)
{
public static SWFMessage loadMTTemp(String mt) {
return null;
}
/***
*
* @param sb 缓存4文首域名
* @param sb
* 缓存4文首域名
*/
public void toSwfMessage(StringBuilder sb)
{
public void toSwfMessage(StringBuilder sb) {
sb.append("{4:\r\n");
for(MessageArea sub : this.getFields())
for (MessageArea sub : this.getFields())
sub.toSwfMessage(sb);
sb.append("\r\n}");
}
public String toSwfMessage()
{
public String toSwfMessage() {
StringBuilder sb = new StringBuilder();
toSwfMessage(sb);
return sb.toString();
}
public SWFMessage clone()
{
public SWFMessage clone() {
SWFMessage msg = new SWFMessage();
msg.mtType = this.mtType;
for(MessageArea field : this.getFields())
{
for (MessageArea field : this.getFields()) {
msg.addSubArea(field.clone());
}
msg.setName(this.getName());
msg.setAnlyReg(this.getAnlyReg());
return msg;
}
public String toJSON()
{
Map<String,Object> rs = new HashMap<String,Object>();
public String toJSON() {
Map<String, Object> rs = new HashMap<String, Object>();
rs.put("title", this.getName());
rs.put("mty", this.mtType);
rs.put("snd_bic", bscInfo.get("sndbic"));
......@@ -83,96 +89,89 @@ public class SWFMessage extends AbstractMessageArea {
rs.put("headers", headers);
rs.put("swift_message", toFormatJSON());
return new Gson().toJson(rs);
// return String.format("{\r\ntitle:\"%s\",\r\nmty:'%s',\r\nrcv_bic:'%s',\r\ntdheader:'%s',\r\nheaders:%s,\r\nswift_message:%s\r\n}",
// this.getName(),
// this.mtType,
// this.bscInfo.get("rcvbic"),
// this.bscInfo.get("tdmsgHead")==null?null:URLEncoder.encode(this.bscInfo.get("tdmsgHead")),
// new Gson().toJson( headers),
// this.toFormatJSON()
// );
// return
// String.format("{\r\ntitle:\"%s\",\r\nmty:'%s',\r\nrcv_bic:'%s',\r\ntdheader:'%s',\r\nheaders:%s,\r\nswift_message:%s\r\n}",
// this.getName(),
// this.mtType,
// this.bscInfo.get("rcvbic"),
// this.bscInfo.get("tdmsgHead")==null?null:URLEncoder.encode(this.bscInfo.get("tdmsgHead")),
// new Gson().toJson( headers),
// this.toFormatJSON()
// );
}
public String toFormatJSON()
{
public String toFormatJSON() {
StringBuilder sb = new StringBuilder();
// sb.append("const M='M' \r\n");
// sb.append("const O='O' \r\n");
// sb.append("const Tags=");
toSubJson(this,sb);
// sb.append("\r\nconst Title=\""+this.getName()+"\"");
// sb.append("\r\n\r\nexport default { Tags,Title}");
// sb.append("const M='M' \r\n");
// sb.append("const O='O' \r\n");
// sb.append("const Tags=");
toSubJson(this, sb);
// sb.append("\r\nconst Title=\""+this.getName()+"\"");
// sb.append("\r\n\r\nexport default { Tags,Title}");
return sb.toString();
}
private static void toSubJson(AbstractMessageArea ma,StringBuilder sb)
{
private static void toSubJson(AbstractMessageArea ma, StringBuilder sb) {
sb.append("[\r\n");
for(MessageArea sma :ma.getFields())
{
if(sma.getType() == TAG)
{
for (MessageArea sma : ma.getFields()) {
if (sma.getType() == TAG) {
TagLine tag = (TagLine) sma;
sb.append(String.format("\t{\"tag\":\"%s\",\"status\":\"%s\",\"tno\":%d,\"letter\":%s,\"label\":\"%s\",\"tagValue\":%s},\r\n",
tag.getSuffix().size() > 0 ?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)
{
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);
// 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(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);
toSubJson((AbstractMessageArea) ((AbstractMessageArea) sma).getPattern(), buff);
sb.append(buff);
sb.append("\t},\r\n");
}
else if(sma.getType() == SEQLIST)
{
} 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);
// 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));
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);
toSubJson((AbstractMessageArea) ((AbstractMessageArea) sma).getPattern(), buff);
sb.append(buff);
sb.append(String.format(",\r\n\t\"desp\":\"%s\"",seqlst.getDesp() ));
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, ' ');
if (sb.length() > 3 && sb.charAt(sb.length() - 3) == ',')
sb.setCharAt(sb.length() - 3, ' ');
sb.append("]");
}
@Override
public int getType() {
return MESSAGE;
}
}
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