Commit 0986f44f by WeiCong

1.修复嵌套可选项的解析;2.完成通用获取域的API

parent c6c688a7
...@@ -2,11 +2,8 @@ package com.brilliace.swifteditor.tag; ...@@ -2,11 +2,8 @@ package com.brilliace.swifteditor.tag;
import java.io.IOException; import java.io.IOException;
import java.io.StringReader; import java.io.StringReader;
import java.util.Arrays; import java.util.*;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Properties;
public class TagFormat { public class TagFormat {
public static Properties TagProps = new Properties(); public static Properties TagProps = new Properties();
...@@ -60,6 +57,7 @@ public class TagFormat { ...@@ -60,6 +57,7 @@ public class TagFormat {
int minLen = 1; int minLen = 1;
boolean isConst = false; boolean isConst = false;
TagCell cell = null; TagCell cell = null;
Stack<Integer> bracket = new Stack<Integer>();
while(true) while(true)
{ {
ic=reader.read(); ic=reader.read();
...@@ -163,11 +161,13 @@ public class TagFormat { ...@@ -163,11 +161,13 @@ public class TagFormat {
else if(c == '[') else if(c == '[')
{ {
line.addOptions(new int[]{line.cellList.size(),-1}); line.addOptions(new int[]{line.cellList.size(),-1});
bracket.push(line.options.size()-1);
} }
else if(c == ']') else if(c == ']')
{ {
//if("51A".equals(tag)) //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); line.setMaxCnt(cnt-1);
......
package com.brilliace.swifteditor.tag; 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 com.brilliace.swifteditor.tag.message.MessageArea;
import java.util.*;
public class TagLine implements MessageArea { public class TagLine implements MessageArea {
public List<TagCell> cellList = new ArrayList<TagCell>(); public List<TagCell> cellList = new ArrayList<TagCell>();
public List<int[]> options = new ArrayList<int[]>(); public List<int[]> options = new ArrayList<int[]>();
...@@ -15,6 +11,8 @@ public class TagLine implements MessageArea { ...@@ -15,6 +11,8 @@ public class TagLine implements MessageArea {
private String value; private String value;
private String tagName; private String tagName;
private String status; private String status;
public MessageArea parent;
public String getStatus() { public String getStatus() {
return status; return status;
} }
...@@ -33,6 +31,15 @@ public class TagLine implements MessageArea { ...@@ -33,6 +31,15 @@ public class TagLine implements MessageArea {
{ {
options.add(points); 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) public void fillLastOption(int point)
{ {
if(options.size() ==0) if(options.size() ==0)
...@@ -260,4 +267,5 @@ public class TagLine implements MessageArea { ...@@ -260,4 +267,5 @@ public class TagLine implements MessageArea {
} }
return indexMap; return indexMap;
} }
} }
package com.brilliace.swifteditor.tag.message; package com.brilliace.swifteditor.tag.message;
import java.io.IOException; import com.brilliace.swifteditor.tag.TagFormat;
import java.io.InputStream; import com.brilliace.swifteditor.tag.TagLine;
import java.util.ArrayList; import com.google.gson.Gson;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Stack;
import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import com.brilliace.swifteditor.tag.TagFormat; import java.io.IOException;
import com.brilliace.swifteditor.tag.TagLine; import java.io.InputStream;
import com.google.gson.Gson; import java.util.*;
public class MessageFormat { public class MessageFormat {
......
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);
}
}
}
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"));
}
}
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