📄 catalogparse.java
字号:
/**
* <p>Title: IDOC Interface</p>
* <p>Description: IDOC 转换器</p>
* <p>Copyright: Copyright (c) 2004</p>
* <p>Company: SiChuan XinHua</p>
* @author zjc
* @version 1.0
*/
/**
*<p>商品类目解析类</p>
*/
package com.idoc.logic;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileOutputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Vector;
import javax.swing.JOptionPane;
import com.idoc.face.InterfaceParse;
import com.idoc.util.Operate;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
public class CatalogParse
implements InterfaceParse {
Vector Tv = new Vector(); //容纳解析后拼装的欲插入中间数据库的sql语句
public CatalogParse() {
}
/**
*<p>调TempTableDispose类的dealData()方法</p>
*<p>处理解析出的数据并传入处理后须删除的文件</p>
*/
public boolean disposeData(File file) {
boolean flag1 = false;
parseData(file);
TempTableDispose TTDCATA = new TempTableDispose();
flag1 = TTDCATA.disposeData(Tv, file, "catalog");
return flag1;
}
/**
*<p>parseData()方法解析idoc文件</p>
*/
public boolean parseData(File file) {
boolean flag = false;
Operate Operate1 = new Operate();
int Count = 0; //记录idoc文件的行号
String stype = ""; //容纳每一行idoc数据的字符串
String WARENGR = ""; //类目编码
String BEZEICH = ""; //类目名称
String VERKNUEPFG = ""; //上层类目编码
String HIERARCHIE = ""; //当前层号
String Tsql = ""; //
BufferedReader br = null;
InputStream bin = null;
InputStreamReader ir = null;
FileInputStream fis = null;
try {
fis = new FileInputStream(file);
byte[] buff = new byte[ (int) file.length()];
int len = 0, pos = 0;
while ( (len = fis.read(buff, pos, buff.length - pos)) > -1 &&
pos < buff.length) {
pos += len;
}
bin = new java.io.ByteArrayInputStream(buff);
ir = new InputStreamReader(bin);
br = new BufferedReader(ir);
stype = new String();
while ( (stype = br.readLine()) != null) {
Count++;
stype = Operate1.gb2CP850(stype);
if (Count == 1) {
stype = stype.substring(39, 69).trim();
if (!stype.equalsIgnoreCase("WPDWGR01")) {
if (br != null)
br.close();
if (ir != null)
ir.close();
if (bin != null)
bin.close();
if (fis != null)
fis.close();
flag = false;
break;
}
}
else {
if (Operate1.getsubString(stype, 0, 30).equalsIgnoreCase("E2WPW01")) {
WARENGR = Operate1.getsubString(stype, 103, 118);
}
if (Operate1.getsubString(stype, 0, 30).equalsIgnoreCase("E2WPW02")) {
BEZEICH = Operate1.cp8502GB(Operate1.getsubString(stype, 64, 99));
BEZEICH = BEZEICH.trim();
HIERARCHIE = Operate1.getsubString(stype, 99, 114);
HIERARCHIE = HIERARCHIE.trim();
VERKNUEPFG = Operate1.getsubString(stype, 114, 129);
VERKNUEPFG = VERKNUEPFG.trim();
if (WARENGR.equalsIgnoreCase("")) {
continue;
}
Tsql = "insert into T_SAPIN_SY_MASTER_Merch_CATE(CATE_CODE,CATE_NAME,UP_CATE_CODE,CURRENT_LEVEL)"
+ "VALUEs('" + WARENGR + "','" + BEZEICH + "','" + VERKNUEPFG +
"','" + HIERARCHIE + "')";
Tv.addElement(Tsql);
}
}
}
flag = true;
}
catch (FileNotFoundException e) {
e.printStackTrace();
System.out.println("CatalogParse---parseData---error"+e.toString());
}
catch (IOException e) {
e.printStackTrace();
System.out.println("CatalogParse---parseData---error"+e.toString());
}
catch (Exception e) {
e.printStackTrace();
System.out.println("CatalogParse---parseData---error"+e.toString());
}
finally {
try {
if (br != null)
br.close();
if (ir != null)
ir.close();
if (bin != null)
bin.close();
if (fis != null)
fis.close();
return flag;
}
catch (Exception ex) {
ex.printStackTrace();
System.out.println("CatalogParse---parseData---error"+ex.toString());
return false;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -