Commit 4a71a6a4 by fukai

合并文件

parent 83f6687b
...@@ -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,6 +20,7 @@ import com.google.gson.Gson; ...@@ -19,6 +20,7 @@ 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
{ {
// generMTFormat(); // generMTFormat();
...@@ -29,6 +31,7 @@ public class App ...@@ -29,6 +31,7 @@ public class App
// TagLine t59 = TagFormat.TagMap.get("79"); // TagLine t59 = TagFormat.TagMap.get("79");
// t59.setValue("14314321\n423424234\nasdgfasdgfasf\nafdagfadsf\r\nasdfasdfsaf"); // t59.setValue("14314321\n423424234\nasdgfasdgfasf\nafdagfadsf\r\nasdfasdfsaf");
// System.out.println(t59); // System.out.println(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())
...@@ -37,7 +40,6 @@ public class App ...@@ -37,7 +40,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,7 +12,8 @@ import java.util.regex.Pattern; ...@@ -14,7 +12,8 @@ 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 {
/* /*
...@@ -759,9 +758,8 @@ public class MessageAnalyzer { ...@@ -759,9 +758,8 @@ public class MessageAnalyzer {
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();
...@@ -774,6 +772,7 @@ public class MessageAnalyzer { ...@@ -774,6 +772,7 @@ public class MessageAnalyzer {
e.printStackTrace(); e.printStackTrace();
} }
return null; return null;
<<<<<<< HEAD
} }
public static void main(String[] args) public static void main(String[] args)
{ {
...@@ -790,4 +789,24 @@ public class MessageAnalyzer { ...@@ -790,4 +789,24 @@ public class MessageAnalyzer {
//System.out.println(value.matches(TagFormat.TagMap.get("79").toAnalyzeReg())); //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; package com.brilliace.swifteditor.tag.message;
import java.net.URLEncoder;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
...@@ -9,68 +8,75 @@ import com.google.gson.Gson; ...@@ -9,68 +8,75 @@ import com.google.gson.Gson;
public class SWFMessage extends AbstractMessageArea { public class SWFMessage extends AbstractMessageArea {
private String mtType; private String mtType;
private Map<Integer,String> headers; private Map<Integer, String> headers;
public Map<Integer, String> getHeaders() { public Map<Integer, String> getHeaders() {
return headers; return headers;
} }
public void setHeaders(Map<Integer, String> 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.putAll(headers);
clone.remove(4); clone.remove(4);
this.headers = clone; this.headers = clone;
} }
public Map<String, String> getBscInfo() { public Map<String, String> getBscInfo() {
return bscInfo; return bscInfo;
} }
public void setBscInfo(Map<String, String> bscInfo) { public void setBscInfo(Map<String, String> bscInfo) {
this.bscInfo = bscInfo; this.bscInfo = bscInfo;
} }
private Map<String,String> bscInfo;
private Map<String, String> bscInfo;
public String getMtType() { public String getMtType() {
return mtType; return mtType;
} }
public void setMtType(String mtType) { public void setMtType(String mtType) {
this.mtType = mtType; this.mtType = mtType;
} }
protected SWFMessage()
{ protected SWFMessage() {
} }
public static SWFMessage loadMTTemp(String mt)
{ public static SWFMessage loadMTTemp(String mt) {
return null; return null;
} }
/*** /***
* *
* @param sb 缓存4文首域名 * @param sb
* 缓存4文首域名
*/ */
public void toSwfMessage(StringBuilder sb) public void toSwfMessage(StringBuilder sb) {
{
sb.append("{4:\r\n"); sb.append("{4:\r\n");
for(MessageArea sub : this.getFields()) for (MessageArea sub : this.getFields())
sub.toSwfMessage(sb); sub.toSwfMessage(sb);
sb.append("\r\n}"); sb.append("\r\n}");
} }
public String toSwfMessage()
{ public String toSwfMessage() {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
toSwfMessage(sb); toSwfMessage(sb);
return sb.toString(); return sb.toString();
} }
public SWFMessage clone()
{ public SWFMessage clone() {
SWFMessage msg = new SWFMessage(); SWFMessage msg = new SWFMessage();
msg.mtType = this.mtType; msg.mtType = this.mtType;
for(MessageArea field : this.getFields()) for (MessageArea field : this.getFields()) {
{
msg.addSubArea(field.clone()); msg.addSubArea(field.clone());
} }
msg.setName(this.getName()); msg.setName(this.getName());
msg.setAnlyReg(this.getAnlyReg()); msg.setAnlyReg(this.getAnlyReg());
return msg; return msg;
} }
public String toJSON()
{ public String toJSON() {
Map<String,Object> rs = new HashMap<String,Object>(); Map<String, Object> rs = new HashMap<String, Object>();
rs.put("title", this.getName()); rs.put("title", this.getName());
rs.put("mty", this.mtType); rs.put("mty", this.mtType);
rs.put("snd_bic", bscInfo.get("sndbic")); rs.put("snd_bic", bscInfo.get("sndbic"));
...@@ -83,96 +89,89 @@ public class SWFMessage extends AbstractMessageArea { ...@@ -83,96 +89,89 @@ public class SWFMessage extends AbstractMessageArea {
rs.put("headers", headers); rs.put("headers", headers);
rs.put("swift_message", toFormatJSON()); rs.put("swift_message", toFormatJSON());
return new Gson().toJson(rs); 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}", // return
// this.getName(), // 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.mtType, // this.getName(),
// this.bscInfo.get("rcvbic"), // this.mtType,
// this.bscInfo.get("tdmsgHead")==null?null:URLEncoder.encode(this.bscInfo.get("tdmsgHead")), // this.bscInfo.get("rcvbic"),
// new Gson().toJson( headers), // this.bscInfo.get("tdmsgHead")==null?null:URLEncoder.encode(this.bscInfo.get("tdmsgHead")),
// this.toFormatJSON() // new Gson().toJson( headers),
// ); // this.toFormatJSON()
// );
} }
public String toFormatJSON()
{ public String toFormatJSON() {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
// sb.append("const M='M' \r\n"); // sb.append("const M='M' \r\n");
// sb.append("const O='O' \r\n"); // sb.append("const O='O' \r\n");
// sb.append("const Tags="); // sb.append("const Tags=");
toSubJson(this,sb); toSubJson(this, sb);
// sb.append("\r\nconst Title=\""+this.getName()+"\""); // sb.append("\r\nconst Title=\""+this.getName()+"\"");
// sb.append("\r\n\r\nexport default { Tags,Title}"); // sb.append("\r\n\r\nexport default { Tags,Title}");
return sb.toString(); return sb.toString();
} }
private static void toSubJson(AbstractMessageArea ma,StringBuilder sb)
{ private static void toSubJson(AbstractMessageArea ma, StringBuilder sb) {
sb.append("[\r\n"); sb.append("[\r\n");
for(MessageArea sma :ma.getFields()) for (MessageArea sma : ma.getFields()) {
{ if (sma.getType() == TAG) {
if(sma.getType() == TAG)
{
TagLine tag = (TagLine) sma; TagLine tag = (TagLine) sma;
sb.append(String.format("\t{\"tag\":\"%s\",\"status\":\"%s\",\"tno\":%d,\"letter\":%s,\"label\":\"%s\",\"tagValue\":%s},\r\n", if (tag.getName().startsWith("50")) {
tag.getSuffix().size() > 0 ?tag.getSuffix().get(0) :tag.getName(), System.out.println(111);
tag.getStatus(), }
tag.getTno(), sb.append(String.format("\t{\"tag\":\"%s\",\"status\":\"%s\",\"tno\":%d,\"letter\":%s,\"label\":\"%s\",\"tagValue\":%s},\r\n", tag
new Gson().toJson(tag.getSuffix()), .getSuffix().size() > 0 && tag.getName().endsWith("a") ? tag.getSuffix().get(0) : tag.getName(), tag.getStatus(),
tag.getDesp(), tag.getTno(), new Gson().toJson(tag.getSuffix()), tag.getDesp(),
new Gson().toJson(new Object[]{tag.getIndexMap(),tag.getSourceValue()}) new Gson().toJson(new Object[] { tag.getIndexMap(), tag.getSourceValue() })));
) } else if (sma.getType() == CYCLIST) {
);
}
else if(sma.getType() == CYCLIST)
{
StringBuilder buff = new StringBuilder(); StringBuilder buff = new StringBuilder();
// int first = 9999; // int first = 9999;
for(MessageArea ssma : ((AbstractMessageArea)sma).getFields() ) for (MessageArea ssma : ((AbstractMessageArea) sma).getFields()) {
{ AbstractMessageArea temp = (AbstractMessageArea) ssma;
AbstractMessageArea temp = (AbstractMessageArea)ssma ; toSubJson(temp, buff);
toSubJson(temp,buff);
buff.append(','); buff.append(',');
} }
sb.append(String.format("\t{\"cyclist\":\"%s\",\"cycs\":[",sma.getName())); sb.append(String.format("\t{\"cyclist\":\"%s\",\"cycs\":[", sma.getName()));
//String temp = buff.toString().trim(); // String temp = buff.toString().trim();
sb.append(buff.subSequence(0, buff.length()-1)); sb.append(buff.subSequence(0, buff.length() - 1));
sb.append("],\r\n\t\"pattern\":"); sb.append("],\r\n\t\"pattern\":");
buff = new StringBuilder(); buff = new StringBuilder();
toSubJson((AbstractMessageArea)((AbstractMessageArea)sma).getPattern(),buff); toSubJson((AbstractMessageArea) ((AbstractMessageArea) sma).getPattern(), buff);
sb.append(buff); sb.append(buff);
sb.append("\t},\r\n"); sb.append("\t},\r\n");
} } else if (sma.getType() == SEQLIST) {
else if(sma.getType() == SEQLIST)
{
StringBuilder buff = new StringBuilder(); StringBuilder buff = new StringBuilder();
// int first = 9999; // int first = 9999;
for(MessageArea ssma : ((AbstractMessageArea)sma).getFields() ) for (MessageArea ssma : ((AbstractMessageArea) sma).getFields()) {
{ AbstractMessageArea temp = (AbstractMessageArea) ssma;
AbstractMessageArea temp = (AbstractMessageArea)ssma ; toSubJson(temp, buff);
toSubJson(temp,buff);
buff.append(','); buff.append(',');
} }
SEQList seqlst = (SEQList)sma; SEQList seqlst = (SEQList) sma;
sb.append(String.format("\t{\"seqlist\":\"%s\",\"cyccnt\":%d,\"status\":\"%s\",\"seqs\":[",sma.getName(),seqlst.getCyc(),seqlst.getOm())); sb.append(String.format("\t{\"seqlist\":\"%s\",\"cyccnt\":%d,\"status\":\"%s\",\"seqs\":[", sma.getName(), seqlst.getCyc(),
//String temp = buff.toString().trim(); seqlst.getOm()));
sb.append(buff.subSequence(0, buff.length()-1)); // String temp = buff.toString().trim();
sb.append(buff.subSequence(0, buff.length() - 1));
sb.append("],\r\n\t\"pattern\":"); sb.append("],\r\n\t\"pattern\":");
buff = new StringBuilder(); buff = new StringBuilder();
toSubJson((AbstractMessageArea)((AbstractMessageArea)sma).getPattern(),buff); toSubJson((AbstractMessageArea) ((AbstractMessageArea) sma).getPattern(), buff);
sb.append(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"); sb.append("\t},\r\n");
} }
} }
if(sb.length() > 3 && sb.charAt(sb.length()-3)==',') if (sb.length() > 3 && sb.charAt(sb.length() - 3) == ',')
sb.setCharAt(sb.length()-3, ' '); sb.setCharAt(sb.length() - 3, ' ');
sb.append("]"); sb.append("]");
} }
@Override @Override
public int getType() { public int getType() {
return MESSAGE; 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