version 1.1, 2005/01/21 11:27:03
|
version 1.3, 2005/02/16 13:00:48
|
Line 127 class Convert
|
Line 127 class Convert
|
System.setOut(stream); |
System.setOut(stream); |
System.setErr(stream); |
System.setErr(stream); |
} |
} |
readXMLFile(args[0]); |
StringBuffer sb = readXMLFile(args[0]); |
|
parseXMLConfig(sb); |
if (!(new File(args[0]).exists())) |
if (!(new File(args[0]).exists())) |
System.exit(0); |
System.exit(0); |
|
|
Line 660 class Convert
|
Line 661 class Convert
|
dialog.title.setText("Reading table data ..."); |
dialog.title.setText("Reading table data ..."); |
dialog.table.setText(names.get(tbIndex).toString()); |
dialog.table.setText(names.get(tbIndex).toString()); |
dialog.status.setText("Table " + (tbIndex + 1) + " of " + names.size()); |
dialog.status.setText("Table " + (tbIndex + 1) + " of " + names.size()); |
dialog.show(); |
dialog.setVisible(true); |
} |
} |
|
|
/** |
/** |
Line 938 class Convert
|
Line 939 class Convert
|
*/ |
*/ |
public static void parseXMLConfig(StringBuffer sb) |
public static void parseXMLConfig(StringBuffer sb) |
{ |
{ |
boolean finished = false; |
// boolean finished = false; |
// parse string and build document tree |
|
Xparse parser = new Xparse(); |
|
parser.changeEntities = true; |
|
Node root = parser.parse(sb.toString()); |
|
// printContents(root); |
|
Vector databases = new Vector(); |
Vector databases = new Vector(); |
Vector tables = new Vector(); |
|
Vector layouts = new Vector(); |
|
Vector selects = new Vector(); |
|
Vector creates = new Vector(); |
|
Vector ids = new Vector(); |
|
Vector indexListVec = new Vector(); |
|
String delimiter = "|"; |
|
int mode = -1; |
|
|
|
try |
try |
{ |
{ |
Node tempNode = root.find("convert/source", new int[] |
databases = getXMLConfig(sb); |
{1, 1}); |
DBBean database = ((DataBase) databases.lastElement()).bean; |
if (tempNode == null) |
databases.remove(databases.size() - 1); |
throw new Error("parse error source tag missing"); |
|
System.out.println(tempNode.name); |
|
int length = countNodes(tempNode); |
|
for (int i = 1; i <= length; i++) |
|
{ |
|
|
|
DBBean database = new DBBean(); |
|
tables = new Vector(); |
|
layouts = new Vector(); |
|
selects = new Vector(); |
|
creates = new Vector(); |
|
ids = new Vector(); |
|
indexListVec = new Vector(); |
|
// parse dataBase |
|
Node node = root.find("convert/source/database/url", new int[] |
|
{1, 1, i, 1}); |
|
Node node1 = root.find("convert/source/database/user", new int[] |
|
{1, 1, i, 1, 1}); |
|
Node node2 = root.find("convert/source/database/password", new int[] |
|
{1, 1, i, 1, 1}); |
|
Node node3 = root.find("convert/source/database", new int[] |
|
{1, 1, i}); |
|
Node nodeMode = root.find("convert/source/database/mode", new int[] |
|
{1, 1, i, 1, 1}); |
|
Node delimiterNode = root.find("convert/source/database/delimiter", new int[] |
|
{1, 1, i, 1, 1}); |
|
Node useNormanToUnicodeMapper = root.find("convert/source/database/usenormantounicodemapper", new int[] |
|
{1, 1, i, 1, 1}); |
|
|
|
if (node3 == null) |
|
throw new Error("parse error database tag missing"); |
|
if (node == null) |
|
throw new Error("parse error url tag missing"); |
|
if (node1 == null) |
|
throw new Error("parse error user tag missing"); |
|
if (node2 == null) |
|
throw new Error("parse error password tag missing"); |
|
if (delimiterNode != null) |
|
delimiter = delimiterNode.getCharacters(); |
|
if (useNormanToUnicodeMapper != null) |
|
{ |
|
database.setUseNormanToUnicodeMapper(Boolean.valueOf(useNormanToUnicodeMapper.getCharacters()).booleanValue()); |
|
System.out.println("useMapper " + Boolean.valueOf(useNormanToUnicodeMapper.getCharacters().trim()).booleanValue()); |
|
} |
|
|
|
String url = node.getCharacters(); |
|
String user = node1.getCharacters(); |
|
String password = node2.getCharacters(); |
|
database.setURL(url.trim()); |
|
database.setUserAndPasswd(user.trim(), password.trim()); |
|
System.out.println(node.name + " " + node.getCharacters()); |
|
System.out.println(node1.name + " " + node1.getCharacters()); |
|
System.out.println(node2.name + " " + node2.getCharacters()); |
|
String modeString = ""; |
|
if (nodeMode == null) |
|
modeString = "convert"; |
|
else |
|
modeString = nodeMode.getCharacters(); |
|
if (modeString.equals("convert")) |
|
mode = DataBase.CONVERT_MODE; |
|
else if (modeString.equals("append")) |
|
mode = DataBase.APPEND_MODE; |
|
else if (modeString.equals("update")) |
|
mode = DataBase.UPDATE_MODE; |
|
else if (modeString.equals("delete")) |
|
mode = DataBase.DELETE_MODE; |
|
else if (modeString.equals("synchronize")) |
|
mode = DataBase.SYNCHRONIZE_MODE; |
|
|
|
// if(node3!=null) |
|
// System.out.println(node3.name); |
|
|
|
int length2 = countNodes(node3); |
|
|
|
System.out.println("number of tables " + length2); |
|
|
|
for (int j = 1; j <= length2; ++j) |
|
{ |
|
Node node4 = root.find("convert/source/database/table", new int[] |
|
{1, 1, i, j}); |
|
Node node5 = root.find("convert/source/database/table/select", new int[] |
|
{1, 1, i, j, 1}); |
|
Node node6 = root.find("convert/source/database/table/create", new int[] |
|
{1, 1, i, j, 1}); |
|
if (node4 != null) |
|
System.out.println(node4.name + " " + node4.attributes.get("layout").equals("")); |
|
if (node5 != null) |
|
System.out.println(node5.name + " " + node5.getCharacters()); |
|
if (node6 != null) |
|
System.out.println(node6.name + " " + node6.getCharacters()); |
|
if (node4 == null) |
|
throw new Error("parse error table tag missing"); |
|
// if(node5==null) throw new Error("parse error select tag |
|
// missing"); |
|
// if(node6==null) throw new Error("parse error create tag |
|
// missing"); |
|
String name = (String) node4.attributes.get("name"); |
|
String layout = (String) node4.attributes.get("layout"); |
|
String id = (String) node4.attributes.get("id"); |
|
String indexList = (String) node4.attributes.get("indexList"); |
|
|
|
System.out.println("id was " + id); |
|
if (name == null) |
|
throw new Error("parse error required table tag attribute name missing"); |
|
if (layout == null) |
|
layout = ""; |
|
if (id == null) |
|
id = ""; |
|
if (indexList == null) |
|
indexList = ""; |
|
if (name.equals("")) |
|
throw new Error("parse error table tag attribute must not be empty"); |
|
tables.add(name); |
|
layouts.add(layout); |
|
|
|
ids.add(id); |
|
indexListVec.add(indexList); |
|
String query = (node5 == null) ? "" : node5.getCharacters(); |
|
if (query.equals("")) |
|
System.err.println("Warning empty select tag or select tag missing !!"); |
|
query = (query.equals("")) ? "select * from " + database.getQC() + name + database.getQC() : query; |
|
selects.add(query); |
|
if (node6 != null) |
|
creates.add(node6.getCharacters().trim()); |
|
else |
|
creates.add(""); |
|
|
|
} |
|
DataBase dataBase = new DataBase(database, tables, layouts, selects, creates, ids, mode); |
|
dataBase.delimiter = delimiter; |
|
dataBase.buildIndexTable(indexListVec); |
|
databases.add(dataBase); |
|
} |
|
DBBean database = new DBBean(); |
|
// parse dataBase |
|
Node node = root.find("convert/destination/database/url", new int[] |
|
{1, 1, 1, 1}); |
|
Node node1 = root.find("convert/destination/database/user", new int[] |
|
{1, 1, 1, 1, 1}); |
|
Node node2 = root.find("convert/destination/database/password", new int[] |
|
{1, 1, 1, 1, 1}); |
|
String url = node.getCharacters(); |
|
String user = node1.getCharacters(); |
|
String password = node2.getCharacters(); |
|
System.out.println(" The url is " + url); |
|
database.setURL(url.trim()); |
|
database.setUserAndPasswd(user.trim(), password.trim()); |
|
//databases.add(database); |
//databases.add(database); |
for (Iterator iter = databases.iterator(); iter.hasNext();) |
for (Iterator iter = databases.iterator(); iter.hasNext();) |
{ |
{ |
DataBase db = (DataBase) iter.next(); |
DataBase db = (DataBase) iter.next(); |
|
int mode = db.mode; |
if (mode == DataBase.CONVERT_MODE || mode == DataBase.APPEND_MODE) |
if (mode == DataBase.CONVERT_MODE || mode == DataBase.APPEND_MODE) |
convertBatch(db.bean, database, db.tables, db.layouts, db.selects, db.creates, db.ids, mode, db.delimiter); |
convertBatch(db.bean, database, db.tables, db.layouts, db.selects, db.creates, db.ids, mode, db.delimiter); |
else if (mode == DataBase.UPDATE_MODE) |
else if (mode == DataBase.UPDATE_MODE) |
Line 1146 class Convert
|
Line 987 class Convert
|
} |
} |
} |
} |
|
|
public static Vector getXMLConfig(String xmlFile) |
public static Vector getXMLConfig(StringBuffer sb) |
{ |
|
StringBuffer sb = null; |
|
try |
|
{ |
|
// read XML Metadata from a file |
|
FileInputStream fi = new FileInputStream(xmlFile); |
|
InputStreamReader isr = new InputStreamReader(fi, "UTF-8"); |
|
BufferedReader buffr = new BufferedReader(isr); |
|
sb = new StringBuffer(); |
|
int c = 0; |
|
while ((c = buffr.read()) != -1) |
|
{ |
|
char ch = (char) c; |
|
sb.append(ch); |
|
// System.out.print((char)c); |
|
} |
|
|
|
} |
|
catch (Exception e) |
|
{ |
{ |
e.printStackTrace(); |
|
} |
|
|
|
boolean finished = false; |
boolean finished = false; |
// parse string and build document tree |
// parse string and build document tree |
Line 1381 class Convert
|
Line 1201 class Convert
|
* |
* |
* @param xmlFile |
* @param xmlFile |
*/ |
*/ |
public static void readXMLFile(String xmlFile) |
public static StringBuffer readXMLFile(String xmlFile) |
{ |
{ |
|
InputStream stream = null; |
|
StringBuffer sb = new StringBuffer(); |
|
|
try |
try |
{ |
{ |
InputStream stream = null; |
|
|
|
if (xmlFile.indexOf("file://") >= 0 || xmlFile.indexOf("http://") >= 0) |
if (xmlFile.indexOf("file://") >= 0 || xmlFile.indexOf("http://") >= 0) |
{ |
{ |
Line 1397 class Convert
|
Line 1219 class Convert
|
stream = new FileInputStream(xmlFile); |
stream = new FileInputStream(xmlFile); |
InputStreamReader isr = new InputStreamReader(stream, "UTF-8"); |
InputStreamReader isr = new InputStreamReader(stream, "UTF-8"); |
BufferedReader buffr = new BufferedReader(isr); |
BufferedReader buffr = new BufferedReader(isr); |
StringBuffer sb = new StringBuffer(); |
|
int c = 0; |
int c = 0; |
while ((c = buffr.read()) != -1) |
while ((c = buffr.read()) != -1) |
{ |
{ |
Line 1405 class Convert
|
Line 1226 class Convert
|
sb.append(ch); |
sb.append(ch); |
// System.out.print((char)c); |
// System.out.print((char)c); |
} |
} |
parseXMLConfig(sb); |
|
} |
} |
catch (Exception e) |
catch (Exception e) |
{ |
{ |
e.printStackTrace(); |
e.printStackTrace(); |
|
} finally |
|
{ |
|
|
|
try |
|
{ |
|
stream.close(); |
|
} |
|
catch (IOException e1) |
|
{ |
|
// TODO Auto-generated catch block |
|
e1.printStackTrace(); |
|
} |
} |
} |
|
return sb; |
} |
} |
|
|
/** |
/** |
* Helper class for Conversion etc Holds the some data |
* Helper class for Conversion etc. Contains data needed for the conversion |
* |
* |
* @author rogo |
* @author rogo |
* |
* |
Line 1663 class Convert
|
Line 1496 class Convert
|
dialog.title.setText("Getting table data ..."); |
dialog.title.setText("Getting table data ..."); |
dialog.table.setText(names.get(tbIndex).toString()); |
dialog.table.setText(names.get(tbIndex).toString()); |
dialog.status.setText("Table " + (tbIndex + 1) + " of " + names.size()); |
dialog.status.setText("Table " + (tbIndex + 1) + " of " + names.size()); |
dialog.show(); |
dialog.setVisible(true); |
bean.getConnection(); |
bean.getConnection(); |
bean.makeQuery(query, 50); |
bean.makeQuery(query, 50); |
idField = ids.get(tbIndex).toString(); |
idField = ids.get(tbIndex).toString(); |