当路由返回一条数据(类似调数据库),网银集合接收。多条可以让核心封成文件,网银要java解析和jsp分页。
parseFile:
项目指定路径包内配xml解析,在trans control中注入文件下载路径和文件操作工具类。
public Map parseFile(Context context, Map dataMap) throws PeException { Integer totalCount = new Integer((String) dataMap.get("TotalCount")); if (totalCount.intValue() > 0) { String fileName = (String) dataMap.get("FILENAME"); if (fileName != null && fileName.trim().length() > 0) { try { byte[] fileContent = (byte[]) fileDownloadTransport.submit(new StringBuffer(fileDownloadPath).append(fileName).toString()); Transformer transformer = transformerFactory.getTransformer("AcctInfo"); Map fileContentMap = (Map) transformer.parse(new ByteArrayInputStream(fileContent), dataMap); List list = (List) fileContentMap.get("List"); for (int i = 0; i < list.size(); i++) { Map curMap = (Map) list.get(i); // 时间改为yyyy-MM-dd /* curMap.put("TrxDateshow", formatDateStr((String) curMap.get("TrxDate")));// 交易日期 */ } dataMap.putAll(fileContentMap); } catch (CommunicationException e) { throw new ValidationException("validation.pinterbus.hots.bdzhacctinf.err"); } } }else{ dataMap.put("List", new ArrayList()); } /* context.setDataMap(dataMap);*/ return dataMap;
context为了最后的put接收,可以去掉因dataMap等对象都是传地址,TotalCount是核心遍历的统计返文件必有。
AcctInfo是xml解析格式,类似报文样式。核心代码是spring注入的两个文件操作类。所以等价于
byte[] fileContent = (byte[]) fileDownloadTransport.submit(new StringBuffer(fileDownloadPath).append(fileName).toString()); Transformer transformer = transformerFactory.getTransformer("AcctInfo"); Map fileContentMap = (Map) transformer.parse(new ByteArrayInputStream(fileContent), dataMap);
第一行fileDownloadTransport是普通文件解析,submit核心代码是 :
br = new BufferedReader(new InputStreamReader(new FileInputStream((String)arg0);//agr0是文件全路径 readoneline = br.readLine();//readoneline=6223692312020300|0200037061415669|0104010013| fileData.append(readoneline).append("\n"); //然后关闭流、getBytes转换成路由内部utf-8
第二行transformerFactory是定义格式(类似日期yyyy-mm-dd格式化),getTransformer核心代码是:
Transformer element = (Transformer)this.elementFactory.getElement(id); //(Element)this.cache.get(id);得到父节点
第三行parse,解析和格式化文件内容。parse核心代码是:
in = new ByteArrayInputStream((byte[])in1);//文件变io流 Object[] children = this.getChildren();//遍历子节点 Object object = ((TransformerElement)element).parse(in, (Map)(context == null ? resultData : context));//递归遍历匹配 //object[0]={BingAcNo,6223692312020300}
jsp自定义分页标签: