Annotation of FM2SQL/Convert.java, revision 1.7
1.1 rogo 1:
2:
3: import java.util.*;
4: import java.sql.*;
5: import java.awt.Cursor;
6: import java.io.BufferedReader;
7: import java.io.BufferedWriter;
8: import java.io.File;
9: import java.io.FileInputStream;
10: import java.io.FileNotFoundException;
11: import java.io.FileOutputStream;
12: import java.io.InputStreamReader;
13: import java.io.OutputStreamWriter;
14: import java.io.PrintStream;
15: import java.io.UnsupportedEncodingException;
16:
17: import com.exploringxml.xml.Node;
18: import com.exploringxml.xml.Xparse;
19:
20: class Convert
21: {
22: static DBBean bean = new DBBean();
23: static DBBean beanDest = new DBBean();
24:
25: static String user ="",passwd="e1nste1n";
26: static String userDest="postgres",passwdDest="rogo";
27: static boolean batchRun=false;
28: static Vector databases = new Vector();
29:
30: public static void main(String args[])
31: {
32: /* try
33: {
34: //byte[] b = "ö".getBytes("UTF-8");
35: // System.out.println("QueryString " +b[0]+" "+b[1]+(new String(b).getBytes()[0])+" "+new String(b).getBytes()[1]);
36: //System.out.println(new String(b,"UTF-8"));
37: } catch (UnsupportedEncodingException e)
38: {
39: // TODO Auto-generated catch block
40: e.printStackTrace();
41: }*/
42: FileOutputStream file = null;
43: if(args.length!=1)
44: {
45: System.out.println("Usage: java Convert <xml config file>");
46: System.exit(-1);
47: }
48: if(!(new File(args[0]).exists())) System.exit(0);
49: try
50: {
51: file = new FileOutputStream("./log.txt");
52: } catch (FileNotFoundException e1)
53: {
54: // TODO Auto-generated catch block
55: e1.printStackTrace();
56: }
57: PrintStream stream= new PrintStream(file);
58: System.setOut(stream);
59: System.setErr(stream);
60: readXMLFile(args[0]);
61: System.out.println("Finished!");
62: //convert("jdbc:fmpro:http://141.14.237.74:8050","jdbc:postgresql://erebos/test",null,null);
63: }
64: public static void convertBatch(DBBean source,DBBean destination,Vector names,Vector layouts,Vector selects,Vector creates) throws Exception
65: {
66: /*FM2SQL.ProgressDialog dialog = new FM2SQL.ProgressDialog(FM2SQL.fmInstance);
67: dialog.setTitle("Conversion running ...");
68: dialog.title.setText("Getting table data ...");
69: dialog.setLocation(500,500);
70: dialog.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
71: */
72: // FM2SQL.fmInstance.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
73: //dialog.thread=Thread.currentThread();
74: bean=source;
75: beanDest = destination;
76: /* // setting user and passwd
77: bean.setUserAndPasswd(user,passwd);
78: // setting user and passwd
79: beanDest.setUserAndPasswd(userDest,passwdDest);
80: */
81: //dialog.setSize(400,250);
82: StringBuffer command= null;
83: try
84: {
85: //bean.setConnection("jdbc:fmpro:http://141.14.237.74:8050");
86: //bean.setConnection("jdbc:postgresql://erebos/test","postgres","rogo");
87: bean.setConnection(source.url);
88: if(names==null)
89: names=bean.getTableNames();
90: //Collections.sort(names);
91: int tbIndex = 1;
92:
93: // System.out.println("Start at "+names.indexOf("archimedes_facsimiles"));
94: for(tbIndex=0;tbIndex<names.size();++tbIndex)
95: {
96: Vector[] result = null;
97: try {
98: String query = "select * from " + bean.getQC() +names.get(tbIndex).toString() + bean.getQC();
99: String layout=(layouts.isEmpty()) ? "":layouts.get(tbIndex).toString();
100: query = (selects!=null) ? selects.get(tbIndex).toString():query;
101: //if vectors[1].get(i) != null)
102: if (!layout.equals(""))
103: {
104: System.out.println("before "+query+" table"+names.get(tbIndex));
105: layout = " layout " + bean.getQC() + layout + bean.getQC();
106: String name = names.get(tbIndex).toString();
107: StringBuffer queryLayout = new StringBuffer(query);
108: queryLayout.insert(queryLayout.indexOf(name) + name.length() + 1, " " + layout);
109: query = queryLayout.toString();
110: System.out.println("added layout " + query);
111:
112: }
113: // if ( layout!= "")
114: // query += " layout " + bean.getQC() + layout + bean.getQC();
115: /* dialog.title.setText("Getting table data ...");
116: dialog.table.setText(names.get(tbIndex).toString());
117: dialog.status.setText("Table " + (tbIndex + 1) + " of " + names.size());
118: dialog.show();
119: */
120: System.out.println(" performing query "+query);
121: //result = bean.getQueryData(query, null, 0);
122: bean.getConnection();
123: bean.makeQuery(query,0);
124: } catch (Exception e)
125: {
126: System.out.println(e.getMessage());
127: e.printStackTrace();
128: continue;
129: }
130: //beanDest.setConnection("jdbc:postgresql://erebos/test3");
131: beanDest.setConnection(destination.url);
132:
133: Statement stm = beanDest.getConnection().createStatement();
134:
135: Vector tables = beanDest.getTableNames();
136: // Collections.sort(tables);
137: System.out.println("converting table "+names.get(tbIndex) + " " + tables.indexOf(convertText((String) names.get(tbIndex)))); // "//beanDest.getTypeNames());
138: tables = beanDest.getTableNames();
139: // System.out.println(beanDest.getTableNames(beanDest.getCatalogs().get(2).toString()));
140: stm = beanDest.getConnection().createStatement();
141: // System.exit(0);
142: if(true)
143: {
144: if(tables.indexOf(names.get(tbIndex))>=0)
145: {
146: stm.executeUpdate("drop table "+beanDest.getQC()+names.get(tbIndex)+beanDest.getQC());
147: tables.remove((String)names.get(tbIndex));
148: System.out.println("dropped table "+ names.get(tbIndex));
149: }
150: else
151: if(tables.indexOf(convertText(names.get(tbIndex).toString()))>=0)
152: {
153: stm.executeUpdate("drop table "+beanDest.getQC()+convertText((String)names.get(tbIndex))+beanDest.getQC());
154: tables.remove(convertText((String)names.get(tbIndex)));
155: System.out.println("dropped table "+ names.get(tbIndex));
156: }
157:
158: if(tables.indexOf(names.get(tbIndex))<0&&tables.indexOf(convertText(names.get(tbIndex).toString()))<0)
159: {
160: if(creates.get(tbIndex).equals("")||creates.get(tbIndex).toString().toLowerCase().indexOf("create")<0)
161: {
162: System.out.println("Warning empty or invalid create statement - creating one for you\n");
163:
164: command = new StringBuffer(50);
165: command.append("CREATE TABLE ");
166: command.append(beanDest.getQC());
167: command.append(convertText((String)names.get(tbIndex)));
168: command.append(beanDest.getQC());
169: command.append("(");
170: String type = null;
171: Vector columnNames=bean.getColumnNames();
172: for(int i=0;i<columnNames.size()-1;++i)
173: {
174: type = bean.metaData.getColumnTypeName(i+1);
175: // System.out.println(i+" "+result[1].get(i)+" "+type);
176: type = (type.equals("NUMBER")) ?"INT4":type;
177: type = (type.equals("CONTAINER")) ?"TEXT":type;
178:
179: command.append(beanDest.getQC() + convertText((String) columnNames.get(i)) + beanDest.getQC() + " " + type + ", ");
180: }
181: type = bean.metaData.getColumnTypeName(columnNames.size());
182: type = (type.equals("NUMBER")) ? "INT4" : type;
183: type = (type.equals("CONTAINER")) ? "TEXT" : type;
184: command.append(beanDest.getQC() + convertText((String) columnNames.get(columnNames.size() - 1)) + beanDest.getQC() + " " + type);
185: command.append(" )");
186: }
187: else
188: command=new StringBuffer().append(creates.get(tbIndex).toString());
189:
190: System.out.println(command);
191: // System.exit(0);
192: //command.append(DBBean.getQC());
193: stm.executeUpdate(command.toString());
194:
195: }
196: }
197: // System.out.println(names);
198: /*
199: if (idVal == "")
200: stm.executeUpdate("INSERT INTO " + DBBean.getQC() + box.getSelectedItem() + DBBean.getQC() + " (" + DBBean.getQC() + columnName + DBBean.getQC() + ") VALUES ('" + value + "') ");
201: else
202: stm.executeUpdate("UPDATE " + DBBean.getQC() + box.getSelectedItem() + DBBean.getQC() + " SET " + DBBean.getQC() + columnName + DBBean.getQC() + "='" + value + "' WHERE ID='" + idVal + "' ");
203: */
204:
205: // Vector[] result2=beanDest.getQueryData(names.get(tbIndex).toString());
206: // print results to screen
207: /* for (int i = 0; i < result[1].size(); ++i)
208: {
209: //print Header
210: // System.out.println(" "+result[1].get(i)+" "+result2[1].get(i)+" "+i);
211: }*/
212: // System.out.println();
213: //dialog.title.setText("Writing table data ...");
214: Vector row = null;
215: //for (int j = 0; j < result[0].size(); ++j)
1.3 rogo 216: command = new StringBuffer();
217:
218: command.append("INSERT INTO ");
219: command.append(beanDest.getQC());
220: command.append(convertText((String) names.get(tbIndex)));
221: command.append(beanDest.getQC());
222: command.append(" values ( ");
223:
224: for (int i = 0; i < bean.getColumnNames().size() - 1; ++i)
225: command.append("?,");
226: command.append("?)");
227: PreparedStatement pstm = beanDest.getConnection().prepareStatement(command.toString());
228: System.out.println(command);
1.1 rogo 229: while((row=bean.getNextRow())!=null)
230: {
1.3 rogo 231: /* //Vector row = (Vector) result[0].get(j);
1.1 rogo 232: command = new StringBuffer();
233:
234: command.append("INSERT INTO ");
235: command.append(beanDest.getQC());
236: command.append(convertText((String) names.get(tbIndex)));
237: command.append(beanDest.getQC());
238: command.append(" values ( ");
1.3 rogo 239: */
240: //print rows
1.1 rogo 241: Object obj = null;
1.3 rogo 242: /*
1.1 rogo 243: for(int k=0;k<row.size()-1;++k)
244: {
245: obj = row.get(k);
246: //System.out.println("row "+obj+" "+k);
247: if(obj!=null&&!(obj instanceof ArrayList))
248: command.append("'"+convertUml(new String(obj.toString().getBytes("UTF-8"),"UTF-8"))+"',");
249: else if(obj!=null&& obj instanceof ArrayList)
250: command.append("'"+convertUml(((ArrayList)obj).get(0).toString())+"',");
251: else command.append("NULL,");
252: }
253: obj = row.get(row.size() - 1);
254: if (obj != null && !(obj instanceof ArrayList))
255: command.append("'"+convertUml(new String(obj.toString().getBytes("UTF-8"),"UTF-8"))+"')");
256: else
257: if(obj!=null&& obj instanceof ArrayList)
258: command.append("'"+convertUml(((ArrayList)obj).get(0).toString())+"')"); //command.append(obj.toString()+")");
259: else command.append("NULL)");
260: //command.append("'"+row.get(row.size()-1)+"')");
261: //command.append(" )");
262: // for(int k=0;k<row.size();++k)
263:
264: // System.out.println();
265: // System.out.println(command+" "+j+" "+row.size()+" "+ ((Vector)result2[0].get(j)).size());
266: // System.out.println(command);
267: stm.executeUpdate(command.toString());
268: // dialog.progress.setValue((int)(((double)(j+1)/(double)result[0].size())*100.0));
269: // System.out.println( (int)(((double)(j+1)/(double)result[0].size())*100.0)+" "+result[0].size()+" "+j);
270: command = null;
1.3 rogo 271: */
272: for (int k = 0; k < row.size(); ++k)
273: {
274: obj = row.get(k);
275: if (obj instanceof ArrayList)
276: obj = ((List) obj).get(0);
277: String str = (obj == null) ? "NULL" : obj.toString();
278: if (!str.equals("NULL"))
279: pstm.setString(k + 1, str);
280: else
281: pstm.setNull(k + 1, Types.NULL);
282: }
283: pstm.execute();
284:
1.1 rogo 285: }// to for loop
286:
287: }
288: } catch(Exception e)
289: {
290: System.out.println("Error while connecting to database "+ e);
291: //dialog.setVisible(false);
292: //dialog.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
293: //FM2SQL.fmInstance.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
294: java.io.ByteArrayOutputStream b = new java.io.ByteArrayOutputStream();
295: java.io.PrintStream stream = new java.io.PrintStream(b);
296: stream.print(command+"\n\n");
297: e.printStackTrace(stream);
298: System.err.println(b);
299: //FM2SQL.showErrorDialog(b.toString(), "Error occured !");
300:
301: }
302: // dialog.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
303: //FM2SQL.fmInstance.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
304:
305: // dialog.setVisible(false);
306: }
307:
308:
309:
1.6 rogo 310: public static void convert(String source,String destination,Vector names,Vector layouts,Vector selects,Vector creates,int mode) throws Exception
1.1 rogo 311: {
312: FM2SQL.ProgressDialog dialog = new FM2SQL.ProgressDialog(FM2SQL.fmInstance);
313: dialog.setTitle("Conversion running ...");
314: dialog.title.setText("Getting table data ...");
315: dialog.setLocation(FM2SQL.fmInstance.getLocationOnScreen().x+(FM2SQL.fmInstance.getWidth()-400)/2,FM2SQL.fmInstance.getLocationOnScreen().y+(FM2SQL.fmInstance.getHeight()-250)/2);
316: dialog.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
317: FM2SQL.fmInstance.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
318: dialog.thread=Thread.currentThread();
319: // setting user and passwd
320: bean.setUserAndPasswd(user,passwd);
321: // setting user and passwd
322: beanDest.setUserAndPasswd(userDest,passwdDest);
323: dialog.setSize(400,250);
324: StringBuffer command= null;
325: String query = null;
326: try
327: {
328: //bean.setConnection("jdbc:fmpro:http://141.14.237.74:8050");
329: //bean.setConnection("jdbc:postgresql://erebos/test","postgres","rogo");
330: bean.setConnection(source);
331: if(names==null)
332: names=bean.getTableNames();
333: // Collections.sort(names);
334: int tbIndex = 1;
335:
336: // System.out.println("Start at "+names.indexOf("archimedes_facsimiles"));
337: for(tbIndex=0;tbIndex<names.size();++tbIndex)
338: {
339: Vector[] result = null;
340: try {
341: query = "select * from " + bean.getQC() +names.get(tbIndex).toString() + bean.getQC();
342: String layout=(layouts.isEmpty()) ? "":layouts.get(tbIndex).toString();
343: query = (selects!=null) ? selects.get(tbIndex).toString():query;
344: //if vectors[1].get(i) != null)
345: if (layout != "")
346: {
347: layout = " layout " + bean.getQC() + layout + bean.getQC();
348: String name = names.get(tbIndex).toString();
349: StringBuffer queryLayout = new StringBuffer(query);
350: queryLayout.insert(queryLayout.indexOf(name) + name.length() + 1, " " + layout);
351: query = queryLayout.toString();
352: System.out.println("added layout "+ query);
353:
354: }
355: // if ( layout!= "")
356: // query += " layout " + bean.getQC() + layout + bean.getQC();
357: dialog.title.setText("Getting table data ...");
358: dialog.table.setText(names.get(tbIndex).toString());
359: dialog.status.setText("Table " + (tbIndex + 1) + " of " + names.size());
360: dialog.show();
361: //result = bean.getQueryData(query, dialog, 0);
362: bean.getConnection();
363: bean.makeQuery(query,0);
364: } catch (Exception e)
365: {
366: continue;
367: }
368: //beanDest.setConnection("jdbc:postgresql://erebos/test3");
369: beanDest.setConnection(destination);
370:
371: Statement stm = beanDest.getConnection().createStatement();
372:
373: Vector tables = beanDest.getTableNames();
374: // Collections.sort(tables);
375: System.out.println(names.get(tbIndex) + " " + tables.indexOf(convertText((String) names.get(tbIndex)))); // "//beanDest.getTypeNames());
376: tables = beanDest.getTableNames();
377: // System.out.println(beanDest.getTableNames(beanDest.getCatalogs().get(2).toString()));
378: stm = beanDest.getConnection().createStatement();
379: // System.exit(0);
1.7 ! rogo 380: if(mode==Convert.DataBase.CONVERT_MODE)
1.1 rogo 381: {
382: if(tables.indexOf(names.get(tbIndex))>=0)
383: {
384: stm.executeUpdate("drop table "+beanDest.getQC()+names.get(tbIndex)+beanDest.getQC());
385: tables.remove((String)names.get(tbIndex));
386: System.out.println("dropped table"+ names.get(tbIndex));
387: }
388: else
389: if(tables.indexOf(convertText(names.get(tbIndex).toString()))>=0)
390: {
391: stm.executeUpdate("drop table "+beanDest.getQC()+convertText((String)names.get(tbIndex))+beanDest.getQC());
392: tables.remove(convertText((String)names.get(tbIndex)));
393: System.out.println("dropped table"+ names.get(tbIndex));
394: }
395:
396: if(tables.indexOf(names.get(tbIndex))<0&&tables.indexOf(convertText(names.get(tbIndex).toString()))<0)
397: {
398: if(creates.get(tbIndex).equals("")||creates.get(tbIndex).toString().toLowerCase().indexOf("create")<0)
399: {
400: System.out.println("Warning empty or invalid create statement - creating one for you\n");
401:
402: command = new StringBuffer(50);
403: command.append("CREATE TABLE ");
404: command.append(beanDest.getQC());
405: command.append(convertText((String)names.get(tbIndex)));
406: command.append(beanDest.getQC());
407: command.append("(");
408: String type = null;
409: Vector columnNames = bean.getColumnNames();
410: for(int i=0;i<columnNames.size()-1;++i)
411: {
412: type = bean.metaData.getColumnTypeName(i+1);
413: // System.out.println(i+" "+result[1].get(i)+" "+type);
414: type = (type.equals("NUMBER")) ?"INT4":type;
415: type = (type.equals("CONTAINER")) ?"TEXT":type;
416:
417: command.append(beanDest.getQC() + convertText((String) columnNames.get(i)) + beanDest.getQC() + " " + type + ", ");
418: }
419: type = bean.metaData.getColumnTypeName(columnNames.size());
420: type = (type.equals("NUMBER")) ? "INT4" : type;
421: type = (type.equals("CONTAINER")) ? "TEXT" : type;
422: command.append(beanDest.getQC() + convertText((String) columnNames.get(columnNames.size() - 1)) + beanDest.getQC() + " " + type);
423: command.append(" )");
424:
425: // System.out.println(command);
426: // System.exit(0);
427: //command.append(DBBean.getQC());
428: } else
429: command=new StringBuffer().append(creates.get(tbIndex).toString());
430: stm.executeUpdate(command.toString());
431:
432: }
433: }
434: // System.out.println(names);
435: /*
436: if (idVal == "")
437: stm.executeUpdate("INSERT INTO " + DBBean.getQC() + box.getSelectedItem() + DBBean.getQC() + " (" + DBBean.getQC() + columnName + DBBean.getQC() + ") VALUES ('" + value + "') ");
438: else
439: stm.executeUpdate("UPDATE " + DBBean.getQC() + box.getSelectedItem() + DBBean.getQC() + " SET " + DBBean.getQC() + columnName + DBBean.getQC() + "='" + value + "' WHERE ID='" + idVal + "' ");
440: */
441:
442: // Vector[] result2=beanDest.getQueryData(names.get(tbIndex).toString());
443: // print results to screen
444: /* for (int i = 0; i < result[1].size(); ++i)
445: {
446: //print Header
447: // System.out.println(" "+result[1].get(i)+" "+result2[1].get(i)+" "+i);
448: }*/
449: // System.out.println();
450: dialog.title.setText("Writing table data ...");
451:
452: //for (int j = 0; j < result[0].size(); ++j)
453: int j=-1;
454: Vector row = null;
1.3 rogo 455: command = new StringBuffer();
456:
457: command.append("INSERT INTO ");
458: command.append(beanDest.getQC());
459: command.append(convertText((String) names.get(tbIndex)));
460: command.append(beanDest.getQC());
461: command.append(" values ( ");
462:
463: for(int i=0;i<bean.getColumnNames().size()-1;++i) command.append("?,");
464: command.append("?)");
465: PreparedStatement pstm = beanDest.getConnection().prepareStatement(command.toString());
466: System.out.println(command);
1.1 rogo 467: int rowCount= bean.getRowCount(query);
468: while((row=bean.getNextRow())!=null)
469: {
470: j++;
471: // row = (Vector) result[0].get(j);
1.3 rogo 472: /* command = new StringBuffer();
1.1 rogo 473:
474: command.append("INSERT INTO ");
475: command.append(beanDest.getQC());
476: command.append(convertText((String) names.get(tbIndex)));
477: command.append(beanDest.getQC());
478: command.append(" values ( ");
1.3 rogo 479: */
480: //print rows
1.1 rogo 481: Object obj = null;
1.3 rogo 482: /* for(int k=0;k<row.size()-1;++k)
1.1 rogo 483: {
484: obj = row.get(k);
485: //System.out.println("row "+obj+" "+k);
486: if(obj!=null&&!(obj instanceof ArrayList))
1.3 rogo 487: command.append("'"+convertUml(obj.toString())+"',");
1.1 rogo 488: else if(obj!=null&& obj instanceof ArrayList)
489: command.append("'"+convertUml(((ArrayList)obj).get(0).toString())+"',");
490: else command.append("NULL,");
491: }
492: obj = row.get(row.size() - 1);
493: if (obj != null && !(obj instanceof ArrayList))
1.3 rogo 494: command.append("'"+convertUml(obj.toString())+"')");
1.1 rogo 495: else
496: if(obj!=null&& obj instanceof ArrayList)
497: command.append("'"+convertUml(((ArrayList)obj).get(0).toString())+"')"); //command.append(obj.toString()+")");
498: else command.append("NULL)");
1.3 rogo 499: */
1.1 rogo 500: //command.append("'"+row.get(row.size()-1)+"')");
501: //command.append(" )");
502: // for(int k=0;k<row.size();++k)
503:
504: // System.out.println();
505: // System.out.println(command+" "+j+" "+row.size()+" "+ ((Vector)result2[0].get(j)).size());
506: // System.out.println(command);
1.3 rogo 507: for(int k=0;k<row.size();++k)
508: {
509: obj = row.get(k);
510: if(obj instanceof ArrayList) obj=((List)obj).get(0);
511: String str =(obj==null) ? "NULL":obj.toString();
512: if(!str.equals("NULL"))
513: pstm.setString(k+1,str);
514: else pstm.setNull(k+1,Types.NULL);
515: }
516: pstm.execute();
517: //stm.executeUpdate(command.toString());
1.1 rogo 518: dialog.progress.setValue((int) (((double) (j + 1) / (double) rowCount) * 100.0));
519: // System.out.println( (int)(((double)(j+1)/(double)result[0].size())*100.0)+" "+result[0].size()+" "+j);
520: command = null;
521: }// to for loop
522:
523: }
524: } catch(Exception e)
525: {
526: System.out.println("Error while connecting to database "+ e);
527: dialog.setVisible(false);
528: dialog.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
529: FM2SQL.fmInstance.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
530: java.io.ByteArrayOutputStream b = new java.io.ByteArrayOutputStream();
531: java.io.PrintStream stream = new java.io.PrintStream(b);
532: stream.print(command+"\n\n");
533: e.printStackTrace(stream);
534: FM2SQL.showErrorDialog(b.toString(), "Error occured !");
535:
536: }
537: dialog.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
538: FM2SQL.fmInstance.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
539:
540: dialog.setVisible(false);
541: }
542:
543: public static String convertText(String newName)
544: {
545: StringBuffer alterMe = new StringBuffer(newName.trim().toLowerCase());
546: int length = alterMe.length();
547: int j = 0;
1.3 rogo 548: int index=alterMe.indexOf(".fp5");
549: if ( index >= 0 )
550: {
551: alterMe.delete(index, index + 4);
552: length = length - 4;
553: }
554:
1.1 rogo 555: while (j < length)
556: {
557: if (alterMe.charAt(j) == ' ')
558: {
559: alterMe.setCharAt(j, '_');
560: // if(j<length-1) j=j+1;
561: }
562: else
563: if (alterMe.charAt(j) == '_')
564: {
565:
566: if(alterMe.charAt(j+1)=='_')
567: alterMe.deleteCharAt(j);
568: length = length-1;
569: // if(j<length-1) j=j+1;
570: }
571: else
572: if (alterMe.charAt(j) == 'ä')
573: {
574: alterMe.setCharAt(j, 'a');
575: alterMe.insert(j+1,"e");
576: length=length+1;
577: if(j<length-1) j=j+1;
578: }
579: else
580: if (alterMe.charAt(j) == 'ö')
581: {
582: alterMe.setCharAt(j, 'o');
583: alterMe.insert(j+1,"e");
584: length=length+1;
585: if(j<length-1) j=j+1;
586: }
587: else
588: if (alterMe.charAt(j) == 'ü')
589: {
590: alterMe.setCharAt(j, 'u');
591: alterMe.insert(j+1,"e");
592: length=length+1;
593: if(j<length-1) j=j+1;
594: }
595: else
596: if (alterMe.charAt(j) == 'ß')
597: {
598: alterMe.setCharAt(j, 's');
599: alterMe.insert(j + 1, "s");
600: length = length + 1;
601: if (j < length - 1)
602: j = j + 1;
603: } else if (alterMe.charAt(j) == ':')
604: {
605: if(j<length-1)
606: {
607: if (alterMe.charAt(j + 1) == ':')
608: {
609: alterMe.setCharAt(j,'_');
610: alterMe.delete(j+1,j+2);
611: length = length - 1;
612:
613: }
614:
615: if (j < length - 1)
616: j = j + 1;
617: }
618: } else if (alterMe.charAt(j) == '-')
619: {
620: alterMe.setCharAt(j, '_');
621:
1.3 rogo 622: }
623: else if (alterMe.charAt(j) == '.')
624: {
625: if(j==length-1)
626: {
627: alterMe.delete(j, j);
628: length--;
629: }
1.1 rogo 630: }
631:
632: ++j;
633: }
634: return alterMe.toString();
635: }
1.4 rogo 636: public static String convertToEntities(String newName)
637: {
638: StringBuffer alterMe = new StringBuffer(newName.trim());
639: int length = alterMe.length();
640: int j = 0;
641:
642: while (j < length)
643: {
644:
645: if (alterMe.charAt(j) == '>')
646: {
647: alterMe.setCharAt(j, '&');
648: alterMe.insert(j + 1, "gt;");
649: length = length + 2;
650: if (j < length - 1)
651: j = j + 1;
652:
653: } else if (alterMe.charAt(j) == '<')
654: {
655: alterMe.setCharAt(j, '&');
656: alterMe.insert(j + 1, "lt;");
657: length = length + 2;
658: if (j < length - 1)
659: j = j + 1;
660:
661: }
662: ++j;
663: }
664: return alterMe.toString();
665: }
1.1 rogo 666: public static String convertUml(String newName)
667: {
668: StringBuffer alterMe = new StringBuffer(newName.trim());
669: int length = alterMe.length();
670: int j = 0;
671:
672:
673: while (j < length)
674: {
675:
676: if (alterMe.charAt(j) == '\'')
677: {
678: alterMe.setCharAt(j, '\\');
679: alterMe.insert(j + 1, "'");
680: length = length + 1;
681: if(j<length-1) j=j+1;
682: }
683: /* else
684: if (alterMe.charAt(j) == '"')
685: {
686: alterMe.setCharAt(j, '\\');
687: alterMe.insert(j + 1, "\"");
688: length = length + 1;
689: if(j<length-1) j=j+1;
690: }
691: else
692: if (alterMe.charAt(j) == '>')
693: {
694: alterMe.setCharAt(j, '\\');
695: alterMe.insert(j + 1, ">");
696: length = length + 1;
697: if(j<length-1) j=j+1;
698: }
699: else
700: if (alterMe.charAt(j) == '<')
701: {
702: alterMe.setCharAt(j, '\\');
703: alterMe.insert(j + 1, "<");
704: length = length + 1;
705: if(j<length-1) j=j+1;
706: }
707: else
708: if (alterMe.charAt(j) == '?')
709: {
710: alterMe.setCharAt(j, '\\');
711: alterMe.insert(j + 1, "?");
712: length = length + 1;
713: if(j<length-1) j=j+1;
714: }
715: else
716: if (alterMe.charAt(j) == '&')
717: {
718: alterMe.setCharAt(j, '\\');
719: alterMe.insert(j + 1, "&");
720: length = length + 1;
721: if(j<length-1) j=j+1;
722: }
723: else
724: if (alterMe.charAt(j) == '=')
725: {
726: alterMe.setCharAt(j, '\\');
727: alterMe.insert(j + 1, "=");
728: length = length + 1;
729: if(j<length-1) j=j+1;
730: }
731: else
732: if (alterMe.charAt(j) == ',')
733: {
734: alterMe.setCharAt(j, '\\');
735: alterMe.insert(j + 1, ",");
736: length = length + 1;
737: if(j<length-1) j=j+1;
738: }
739: else
740: if (alterMe.charAt(j) == '.')
741: {
742: alterMe.setCharAt(j, '\\');
743: alterMe.insert(j + 1, ".");
744: length = length + 1;
745: if(j<length-1) j=j+1;
746: }
747: else
748: if (alterMe.charAt(j) == '[')
749: {
750: alterMe.setCharAt(j, '\\');
751: alterMe.insert(j + 1, ".");
752: length = length + 1;
753: if(j<length-1) j=j+1;
754: }
755: else
756: if (alterMe.charAt(j) == ']')
757: {
758: alterMe.setCharAt(j, '\\');
759: alterMe.insert(j + 1, ".");
760: length = length + 1;
761: if(j<length-1) j=j+1;
762: }
763: else
764: if (alterMe.charAt(j) == '%')
765: {
766: alterMe.setCharAt(j, '\\');
767: alterMe.insert(j + 1, "%");
768: length = length + 1;
769: if(j<length-1) j=j+1;
770: }*/
771: ++j;
772: }
773: return alterMe.toString();
774: }
775:
776: public static void parseXMLConfig(StringBuffer sb)
777: {
778: boolean finished = false;
779: // parse string and build document tree
1.4 rogo 780: Xparse parser =new Xparse();
781: parser.changeEntities = true;
782: Node root = parser.parse(sb.toString());
1.1 rogo 783: // printContents(root);
784: Vector databases= new Vector();
785: Vector tables = new Vector();
786: Vector layouts = new Vector();
787: Vector selects = new Vector();
788: Vector creates = new Vector();
1.5 rogo 789: int mode = -1;
790:
1.1 rogo 791: try
792: {
793: Node tempNode = root.find("convert/source", new int[] { 1, 1 });
794: if(tempNode==null) throw new Error("parse error source tag missing");
795: System.out.println(tempNode.name);
796: int length =countNodes(tempNode);
797: for (int i = 1; i <= length; i++)
798: {
799:
800: DBBean database = new DBBean();
801: tables = new Vector();
802: layouts = new Vector();
803: selects = new Vector();
804: creates = new Vector();
805:
806: // parse dataBase
807: Node node = root.find("convert/source/database/url", new int[] { 1, 1, i, 1 });
808: Node node1 = root.find("convert/source/database/user", new int[] { 1, 1, i, 1, 1 });
809: Node node2 = root.find("convert/source/database/password", new int[] { 1, 1, i, 1, 1 });
810: Node node3 = root.find("convert/source/database", new int[] { 1, 1, i});
1.5 rogo 811: Node nodeMode = root.find("convert/source/database/mode/", new int[] {1, 1, i, 1,1});
812:
1.1 rogo 813: if(node3== null) throw new Error("parse error database tag missing");
814: if(node==null) throw new Error("parse error url tag missing");
815: if(node1==null) throw new Error("parse error user tag missing");
816: if(node2==null) throw new Error("parse error password tag missing");
817: String url=node.getCharacters();
818: String user=node1.getCharacters();
819: String password=node2.getCharacters();
820: database.setURL(url.trim());
821: database.setUserAndPasswd(user.trim(),password.trim());
822: System.out.println(node.name + " " + node.getCharacters());
823: System.out.println(node1.name + " " + node1.getCharacters());
824: System.out.println(node2.name + " " + node2.getCharacters());
1.5 rogo 825: String modeString = "";
826: if (nodeMode == null)
827: modeString = "convert";
828: else
829: modeString = nodeMode.getCharacters();
830: if (modeString.equals("convert"))
831: mode = DataBase.CONVERT_MODE;
832: else
833: if (modeString.equals("append"))
834: mode = DataBase.APPEND_MODE;
835: else
836: if (modeString.equals("update"))
837: mode = DataBase.UPDATE_MODE;
1.1 rogo 838: // if(node3!=null)
839: // System.out.println(node3.name);
840:
841: int length2= countNodes(node3);
842:
843: System.out.println("number of tables " +length2);
844:
845: for(int j=1;j<=length2;++j)
846: {
847: Node node4 = root.find("convert/source/database/table", new int[] { 1, 1, i, j });
848: Node node5 = root.find("convert/source/database/table/select", new int[] { 1, 1, i, j, 1 });
849: Node node6 = root.find("convert/source/database/table/create", new int[] { 1, 1, i, j, 1 });
850: if(node4!=null)
851: System.out.println(node4.name + " " + node4.attributes.get("layout").equals(""));
852: if(node5!=null)
853: System.out.println(node5.name + " " + node5.getCharacters());
854: if(node6!=null)
855: System.out.println(node6.name + " " + node6.getCharacters());
856: if(node4==null) throw new Error("parse error table tag missing");
857: // if(node5==null) throw new Error("parse error select tag missing");
858: // if(node6==null) throw new Error("parse error create tag missing");
859: String name = (String)node4.attributes.get("name");
860: String layout = (String)node4.attributes.get("layout");
861: if(name==null) throw new Error("parse error required table tag attribute name missing");
862: if(layout==null) layout ="";
863: if(name.equals("")) throw new Error("parse error table tag attribute must not be empty");
864: tables.add(name);
865: layouts.add(layout);
866: String query = (node5==null) ? "":node5.getCharacters();
867: if(query.equals("")) System.err.println("Warning empty select tag or select tag missing !!");
868: query = (query.equals("")) ? "select * from "+database.getQC()+name+database.getQC():query;
869: selects.add(query);
870: if(node6!=null) creates.add(node6.getCharacters().trim());
871: else
872: creates.add("");
873:
874: }
1.5 rogo 875: databases.add(new DataBase(database, tables, layouts, selects,creates,mode));
1.1 rogo 876: }
877: DBBean database = new DBBean();
878: // parse dataBase
879: Node node = root.find("convert/destination/database/url", new int[] { 1, 1, 1, 1 });
880: Node node1 = root.find("convert/destination/database/user", new int[] { 1, 1, 1, 1, 1 });
881: Node node2 = root.find("convert/destination/database/password", new int[] { 1, 1, 1, 1, 1 });
882: String url = node.getCharacters();
883: String user = node1.getCharacters();
884: String password = node2.getCharacters();
885: System.out.println(url);
886: database.setURL(url.trim());
887: database.setUserAndPasswd(user.trim(), password.trim());
888: //databases.add(database);
889: for (Iterator iter = databases.iterator(); iter.hasNext();)
890: {
891: DataBase db = (DataBase) iter.next();
892: convertBatch(db.bean,database,db.tables,db.layouts,db.selects,db.creates);
893:
894: }
895: // printContents(node3);
896: // FM2SQL.fmInstance=new FM2SQL();
897: } catch (Exception e)
898: {
899: // TODO Auto-generated catch block
900: e.printStackTrace();
901: }
902: /*
903: Node tempNode=root.find(rootNode,new int[] {1});
904: if(tempNode==null) return rtTag;
905: int count=1;
906: /*
907: for(int i=0;i<tempNode.contents.v.size();++i)
908: {
909: // System.out.println(((Node)tempNode.contents.v.elementAt(i)).attributes+" "+i);
910: }*/
911: /*
912: if(tempNode.contents.v.size()==0) return rtTag;
913: Node notNull=null;
914: Node rtNode=root.find(rootNode+"/rt",new int[] {1,1});
915: rtTag=(rtNode==null) ? "finished":rtNode.getCharacters();
916: System.out.println("rt tag is "+ rtTag);
917: int length=0;//(tempNode.contents.length()-1)/2;
918: for(int i=0;i<tempNode.contents.v.size();++i) {
919: Node node=(Node)tempNode.contents.v.elementAt(i);
920: if(node.type.equals("element"))
921: if(node.name.equals("doc"))length++;
922: // System.out.println(((Node)tempNode.contents.v.elementAt(i)).attributes+" "+i);
923: }
924: if(length==0) rtTag="finished";
925: while(count<=length)
926: {
927: //System.out.println(count+" "+length);
928: tempNode=root.find(rootNode+"/doc",new int[] {1,count});
929: if(tempNode==null)
930: {
931: rtTag="finished";
932: break;
933: }
934: Bundle.Document doc = new Bundle.Document();
935: Hashtable attributes=tempNode.attributes;
936: int docID=0;
937: int ver=0;
938: if(attributes != null)
939: {
940: docID=Integer.parseInt((String)attributes.get("id"));
941: ver=Integer.parseInt((String)attributes.get("ver"));
942: doc.addData("docID",(String)attributes.get("id"));
943: doc.addData("ver",(String)attributes.get("ver"));
944: }
945: bundle.docs.put(new Integer(docID),doc);
946: bundle.documents.addElement(doc);
947: // System.out.println("id " +docID+" ver "+ver);
948: Node fileNode=root.find(rootNode+"/doc/file",new int[] {1,count,1});
949: attributes=(fileNode==null)? null:fileNode.attributes;
950: int fileID=0;
951: int fileVer=0;
952: if(attributes != null)
953: {
954: fileID=Integer.parseInt((String)attributes.get("id"));
955: fileVer=Integer.parseInt((String)attributes.get("ver"));
956: doc.addData("fileID",(String)attributes.get("id"));
957: doc.addData("fileVer",(String)attributes.get("ver"));
958: // System.out.println("fileid " +fileID+" ver "+fileVer);
959: }
960: // add all Document tags to actual Document
961: for(int i=0;i<tempNode.contents.v.size();++i)
962: {
963: Node node=(Node)tempNode.contents.v.elementAt(i);
964: if(node.type.equals("element"))
965: {
966: //System.out.println(node.name+" "+node.getCharacters()+" "+node.contents.v.size());
967: if(node.contents.v.size()>1)
968: {
969: for(int j=0;j<node.contents.v.size();++j)
970: {
971: Node node2=(Node)node.contents.v.elementAt(j);
972: if(node2.type.equals("element"))
973: {
974: doc.addData(node2.name,node2.getCharacters());
975: //System.out.println(node2.name+" "+node2.getCharacters()+" "+node2.contents.v.size());
976: }
977: }
978: } else doc.addData(node.name,node.getCharacters());
979: }
980: }
981: bundle.docsLocator.put(doc.locator,doc);
982:
983: bundle.documents.addElement(doc);
984: count++;
985: } */
986:
987: // System.out.println(bundle.docs.size());
988: // return rtTag;
989: }
990: public static Vector getXMLConfig(String xmlFile)
991: {
992: StringBuffer sb=null;
993: try
994: {
995: // read XML Metadata from a file
996: FileInputStream fi= new FileInputStream(xmlFile);
997: InputStreamReader isr= new InputStreamReader(fi,"UTF-8");
998: BufferedReader buffr = new BufferedReader(isr);
999: sb=new StringBuffer();
1000: int c=0;
1001: while ((c = buffr.read()) != -1)
1002: {
1003: char ch=(char)c;
1004: sb.append(ch);
1005: // System.out.print((char)c);
1006: }
1007:
1008: } catch(Exception e) { e.printStackTrace();}
1009:
1010: boolean finished = false;
1011: // parse string and build document tree
1.4 rogo 1012: Xparse parser =new Xparse();
1013: parser.changeEntities = true;
1014: Node root = parser.parse(sb.toString());
1015: // printContents(root);
1.1 rogo 1016: Vector databases= new Vector();
1017: Vector tables = new Vector();
1018: Vector layouts = new Vector();
1019: Vector selects = new Vector();
1020: Vector creates = new Vector();
1.5 rogo 1021: int mode = -1;
1.1 rogo 1022: try
1023: {
1024: Node tempNode = root.find("convert/source", new int[] { 1, 1 });
1025: if(tempNode==null) throw new Error("parse error source tag missing");
1026: System.out.println(tempNode.name);
1027: int length =countNodes(tempNode);
1028: for (int i = 1; i <= length; i++)
1029: {
1030:
1031: DBBean database = new DBBean();
1032: tables = new Vector();
1033: layouts = new Vector();
1034: selects = new Vector();
1035: creates = new Vector();
1036:
1037: // parse dataBase
1038: Node node = root.find("convert/source/database/url", new int[] { 1, 1, i, 1 });
1039: Node node1 = root.find("convert/source/database/user", new int[] { 1, 1, i, 1, 1 });
1040: Node node2 = root.find("convert/source/database/password", new int[] { 1, 1, i, 1, 1 });
1041: Node node3 = root.find("convert/source/database", new int[] { 1, 1, i});
1.5 rogo 1042: Node nodeMode = root.find("convert/source/database/mode", new int[] { 1, 1, i, 1, 1 });
1043:
1.1 rogo 1044: if(node3== null) throw new Error("parse error database tag missing");
1045: if(node==null) throw new Error("parse error url tag missing");
1046: if(node1==null) throw new Error("parse error user tag missing");
1047: if(node2==null) throw new Error("parse error password tag missing");
1048: String url=node.getCharacters();
1049: String user=node1.getCharacters();
1050: String password=node2.getCharacters();
1051: database.setURL(url.trim());
1052: database.setUserAndPasswd(user.trim(),password.trim());
1053: System.out.println(node.name + " " + node.getCharacters());
1054: System.out.println(node1.name + " " + node1.getCharacters());
1055: System.out.println(node2.name + " " + node2.getCharacters());
1.5 rogo 1056: String modeString = "";
1057: if (nodeMode == null)
1058: modeString = "convert";
1059: else
1060: modeString = nodeMode.getCharacters();
1061: if (modeString.equals("convert"))
1062: mode = DataBase.CONVERT_MODE;
1063: else
1064: if (modeString.equals("append"))
1065: mode = DataBase.APPEND_MODE;
1066: else
1067: if (modeString.equals("update"))
1068: mode = DataBase.UPDATE_MODE;
1069:
1070:
1.1 rogo 1071: // if(node3!=null)
1072: // System.out.println(node3.name);
1073:
1074: int length2= countNodes(node3);
1075:
1076: System.out.println("number of tables " +length2);
1077:
1078: for(int j=1;j<=length2;++j)
1079: {
1080: Node node4 = root.find("convert/source/database/table", new int[] { 1, 1, i, j });
1081: Node node5 = root.find("convert/source/database/table/select", new int[] { 1, 1, i, j, 1 });
1082: Node node6 = root.find("convert/source/database/table/create", new int[] { 1, 1, i, j, 1 });
1083: if(node4!=null)
1084: System.out.println(node4.name + " " + node4.attributes.get("layout").equals(""));
1085: if(node5!=null)
1086: System.out.println(node5.name + " " + node5.getCharacters());
1087: if(node6!=null)
1088: System.out.println(node6.name + " " + node6.getCharacters());
1089: if(node4==null) throw new Error("parse error table tag missing");
1090: // if(node5==null) throw new Error("parse error select tag missing");
1091: // if(node6==null) throw new Error("parse error create tag missing");
1092: String name = (String)node4.attributes.get("name");
1093: String layout = (String)node4.attributes.get("layout");
1094: if(name==null) throw new Error("parse error required table tag attribute name missing");
1095: if(layout==null) layout ="";
1096: if(name.equals("")) throw new Error("parse error table tag attribute must not be empty");
1097: tables.add(name);
1098: layouts.add(layout);
1099: String query = (node5==null) ? "":node5.getCharacters();
1100: if(query.equals("")) System.err.println("Warning empty select tag or select tag missing !!");
1101: query = (query.equals("")) ? "select * from "+database.getQC()+name+database.getQC():query;
1102: selects.add(query);
1103: if(node6!=null) creates.add(node6.getCharacters().trim());
1104: else
1105: creates.add("");
1106:
1107: }
1.5 rogo 1108: databases.add(new DataBase(database, tables, layouts, selects,creates,mode));
1.1 rogo 1109: }
1110: DBBean database = new DBBean();
1111: // parse dataBase
1112: Node node = root.find("convert/destination/database/url", new int[] { 1, 1, 1, 1 });
1113: Node node1 = root.find("convert/destination/database/user", new int[] { 1, 1, 1, 1, 1 });
1114: Node node2 = root.find("convert/destination/database/password", new int[] { 1, 1, 1, 1, 1 });
1115: String url = node.getCharacters();
1116: String user = node1.getCharacters();
1117: String password = node2.getCharacters();
1118: System.out.println(url);
1119: database.setURL(url.trim());
1120: database.setUserAndPasswd(user.trim(), password.trim());
1.5 rogo 1121: databases.add(new DataBase(database,null,null,null,null,0));
1.1 rogo 1122: //databases.add(database);
1123: /* for (Iterator iter = databases.iterator(); iter.hasNext();)
1124: {
1125: DataBase db = (DataBase) iter.next();
1126: convertBatch(db.bean,database,db.tables,db.layouts,db.selects,db.creates);
1127:
1128: }*/
1129: // printContents(node3);
1130: // FM2SQL.fmInstance=new FM2SQL();
1131: } catch (Exception e)
1132: {
1133: // TODO Auto-generated catch block
1134: e.printStackTrace();
1135: }
1136: return databases;
1137: }
1138:
1139:
1140: private static int countNodes(Node tempNode)
1141: {
1142: int length = 0;
1143: for(int i=0;i<tempNode.contents.v.size();++i) {
1144: Node node=(Node)tempNode.contents.v.elementAt(i);
1145: if(node.type.equals("element"))
1146: {
1147: if(node.name.equals("database"))length++;
1148: if(node.name.equals("table"))length++;
1149: }
1150:
1151: // System.out.println(((Node)tempNode.contents.v.elementAt(i)).attributes+" "+i);
1152: }
1153: return length;
1154: }
1155: private static void printContents(Node root)
1156: {
1157:
1158:
1159: Vector contents=(root.index==null)? root.contents.v:root.index.v;
1160: for (int i=0;i<contents.size();++i)
1161: {
1162: Node n=(Node)contents.elementAt(i);
1163: if(n.type.equals("element"))
1164: {
1165: System.out.println("tag "+n.name);
1166: System.out.println(n.getCharacters());
1167: //contents=n.contents.v i=0;
1168: }
1169: // System.out.println(n.type);
1170:
1171:
1172:
1173: }
1174: }
1175: public static void readXMLFile(String xmlFile)
1176: {
1177: try
1178: {
1179: // read XML Metadata from a file
1180: FileInputStream fi= new FileInputStream(xmlFile);
1181: InputStreamReader isr= new InputStreamReader(fi,"UTF-8");
1182: BufferedReader buffr = new BufferedReader(isr);
1183: StringBuffer sb=new StringBuffer();
1184: int c=0;
1185: while ((c = buffr.read()) != -1)
1186: {
1187: char ch=(char)c;
1188: sb.append(ch);
1189: // System.out.print((char)c);
1190: }
1191: parseXMLConfig(sb);
1192: } catch(Exception e) { e.printStackTrace();}
1193: }
1194: public static class DataBase
1195: {
1196: DBBean bean;
1197: Vector creates;
1198: Vector selects;
1199: Vector layouts;
1200: Vector tables;
1.5 rogo 1201: final static int CONVERT_MODE = 1;
1202: final static int APPEND_MODE = 2;
1203: final static int UPDATE_MODE = 3;
1204: int mode = -1;
1205:
1206: public DataBase(DBBean bean,Vector tables,Vector layouts,Vector selects,Vector creates,int mode)
1.1 rogo 1207: {
1208: this.bean = bean;
1209: this.tables = tables;
1210: this.layouts = layouts;
1211: this.selects = selects;
1212: this.creates = creates;
1.5 rogo 1213: this.mode = mode;
1.1 rogo 1214: }
1215: public void exportToXML(BufferedWriter buffr) throws Exception
1216: {
1217: buffr.write(" <database>\n");
1218: buffr.write(" <url>"+bean.url+"</url>\n");
1219: buffr.write(" <user>"+bean.user+"</user>\n");
1220: buffr.write(" <password>"+bean.passwd+"</password>\n");
1.5 rogo 1221: String modeString ="";
1222: if (mode == CONVERT_MODE)
1223: modeString = "convert";
1224: else
1225: if (mode == APPEND_MODE)
1226: modeString = "append";
1227: else
1228: if (mode == UPDATE_MODE)
1229: modeString = "update";
1230:
1231: buffr.write(" <mode>"+ modeString+"</mode>\n");
1.1 rogo 1232: int index = 0;
1233: while(index<tables.size())
1234: {
1235: String table=(String)tables.get(index);
1236: String layout=(String)layouts.get(index);
1237: String select=(String)selects.get(index);
1238: String create=(String)creates.get(index);
1239:
1240: buffr.write(" <table name = \""+table+"\" layout = \""+layout+"\">\n");
1.4 rogo 1241: buffr.write(" <select>"+ convertToEntities(select)+"</select>\n");
1.1 rogo 1242: if(!create.equals(""))
1243: buffr.write(" <create>"+create+" </create>\n");
1244: buffr.write(" </table>\n");
1245: index++;
1246: }
1247: buffr.write(" </database>\n");
1248: }
1249: public String toString() {return bean.url+" "+tables;}
1250:
1251: }
1252: public static String convertToUTF8(Object command)
1253: {
1254: String str = null;
1255: try
1256: {
1257: str = new String(command.toString().getBytes("UTF-8"));
1258: } catch (UnsupportedEncodingException e)
1259: {
1260: // TODO Auto-generated catch block
1261: e.printStackTrace();
1262: }
1263: return str;
1264: }
1265: public static void writeConfig(String file, DataBase source, DataBase destination) throws Exception
1266: {
1267: if(!file.toLowerCase().endsWith(".xml")) file+=".xml";
1268: File f = new File(file);
1269:
1270: FileOutputStream fout= new FileOutputStream(f);
1271: OutputStreamWriter outsw = new OutputStreamWriter(fout,"UTF-8");
1272: BufferedWriter buffw = new BufferedWriter(outsw);
1273: buffw.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
1274: buffw.newLine();
1275: buffw.write("<convert>\n");
1276: buffw.write(" <source>\n");
1277: source.exportToXML(buffw);
1278: buffw.write(" </source>\n");
1279: buffw.write("\n <destination>\n");
1280: destination.exportToXML(buffw);
1281: buffw.write(" </destination>\n");
1282: buffw.write("</convert>\n");
1283: buffw.close();
1284: }
1285: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>