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)
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);
229: while((row=bean.getNextRow())!=null)
230: {
231: /* //Vector row = (Vector) result[0].get(j);
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 ( ");
239: */
240: //print rows
241: Object obj = null;
242: /*
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;
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:
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:
310: public static void convert(String source,String destination,Vector names,Vector layouts,Vector selects,Vector creates,int mode) throws Exception
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);
380: if(mode==Convert.DataBase.CONVERT_MODE)
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;
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);
467: int rowCount= bean.getRowCount(query);
468: while((row=bean.getNextRow())!=null)
469: {
470: j++;
471: // row = (Vector) result[0].get(j);
472: /* command = new StringBuffer();
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 ( ");
479: */
480: //print rows
481: Object obj = null;
482: /* for(int k=0;k<row.size()-1;++k)
483: {
484: obj = row.get(k);
485: //System.out.println("row "+obj+" "+k);
486: if(obj!=null&&!(obj instanceof ArrayList))
487: command.append("'"+convertUml(obj.toString())+"',");
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))
494: command.append("'"+convertUml(obj.toString())+"')");
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)");
499: */
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);
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());
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;
548: int index=alterMe.indexOf(".fp5");
549: if ( index >= 0 )
550: {
551: alterMe.delete(index, index + 4);
552: length = length - 4;
553: }
554:
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:
622: }
623: else if (alterMe.charAt(j) == '.')
624: {
625: if(j==length-1)
626: {
627: alterMe.delete(j, j);
628: length--;
629: }
630: else
631: alterMe.setCharAt(j,'_');
632: }
633:
634: ++j;
635: }
636: return alterMe.toString();
637: }
638: public static String convertToEntities(String newName)
639: {
640: StringBuffer alterMe = new StringBuffer(newName.trim());
641: int length = alterMe.length();
642: int j = 0;
643:
644: while (j < length)
645: {
646:
647: if (alterMe.charAt(j) == '>')
648: {
649: alterMe.setCharAt(j, '&');
650: alterMe.insert(j + 1, "gt;");
651: length = length + 2;
652: if (j < length - 1)
653: j = j + 1;
654:
655: } else if (alterMe.charAt(j) == '<')
656: {
657: alterMe.setCharAt(j, '&');
658: alterMe.insert(j + 1, "lt;");
659: length = length + 2;
660: if (j < length - 1)
661: j = j + 1;
662:
663: }
664: ++j;
665: }
666: return alterMe.toString();
667: }
668: public static String convertUml(String newName)
669: {
670: StringBuffer alterMe = new StringBuffer(newName.trim());
671: int length = alterMe.length();
672: int j = 0;
673:
674:
675: while (j < length)
676: {
677:
678: if (alterMe.charAt(j) == '\'')
679: {
680: alterMe.setCharAt(j, '\\');
681: alterMe.insert(j + 1, "'");
682: length = length + 1;
683: if(j<length-1) j=j+1;
684: }
685: /* else
686: if (alterMe.charAt(j) == '"')
687: {
688: alterMe.setCharAt(j, '\\');
689: alterMe.insert(j + 1, "\"");
690: length = length + 1;
691: if(j<length-1) j=j+1;
692: }
693: else
694: if (alterMe.charAt(j) == '>')
695: {
696: alterMe.setCharAt(j, '\\');
697: alterMe.insert(j + 1, ">");
698: length = length + 1;
699: if(j<length-1) j=j+1;
700: }
701: else
702: if (alterMe.charAt(j) == '<')
703: {
704: alterMe.setCharAt(j, '\\');
705: alterMe.insert(j + 1, "<");
706: length = length + 1;
707: if(j<length-1) j=j+1;
708: }
709: else
710: if (alterMe.charAt(j) == '?')
711: {
712: alterMe.setCharAt(j, '\\');
713: alterMe.insert(j + 1, "?");
714: length = length + 1;
715: if(j<length-1) j=j+1;
716: }
717: else
718: if (alterMe.charAt(j) == '&')
719: {
720: alterMe.setCharAt(j, '\\');
721: alterMe.insert(j + 1, "&");
722: length = length + 1;
723: if(j<length-1) j=j+1;
724: }
725: else
726: if (alterMe.charAt(j) == '=')
727: {
728: alterMe.setCharAt(j, '\\');
729: alterMe.insert(j + 1, "=");
730: length = length + 1;
731: if(j<length-1) j=j+1;
732: }
733: else
734: if (alterMe.charAt(j) == ',')
735: {
736: alterMe.setCharAt(j, '\\');
737: alterMe.insert(j + 1, ",");
738: length = length + 1;
739: if(j<length-1) j=j+1;
740: }
741: else
742: if (alterMe.charAt(j) == '.')
743: {
744: alterMe.setCharAt(j, '\\');
745: alterMe.insert(j + 1, ".");
746: length = length + 1;
747: if(j<length-1) j=j+1;
748: }
749: else
750: if (alterMe.charAt(j) == '[')
751: {
752: alterMe.setCharAt(j, '\\');
753: alterMe.insert(j + 1, ".");
754: length = length + 1;
755: if(j<length-1) j=j+1;
756: }
757: else
758: if (alterMe.charAt(j) == ']')
759: {
760: alterMe.setCharAt(j, '\\');
761: alterMe.insert(j + 1, ".");
762: length = length + 1;
763: if(j<length-1) j=j+1;
764: }
765: else
766: if (alterMe.charAt(j) == '%')
767: {
768: alterMe.setCharAt(j, '\\');
769: alterMe.insert(j + 1, "%");
770: length = length + 1;
771: if(j<length-1) j=j+1;
772: }*/
773: ++j;
774: }
775: return alterMe.toString();
776: }
777:
778: public static void parseXMLConfig(StringBuffer sb)
779: {
780: boolean finished = false;
781: // parse string and build document tree
782: Xparse parser =new Xparse();
783: parser.changeEntities = true;
784: Node root = parser.parse(sb.toString());
785: // printContents(root);
786: Vector databases= new Vector();
787: Vector tables = new Vector();
788: Vector layouts = new Vector();
789: Vector selects = new Vector();
790: Vector creates = new Vector();
791: int mode = -1;
792:
793: try
794: {
795: Node tempNode = root.find("convert/source", new int[] { 1, 1 });
796: if(tempNode==null) throw new Error("parse error source tag missing");
797: System.out.println(tempNode.name);
798: int length =countNodes(tempNode);
799: for (int i = 1; i <= length; i++)
800: {
801:
802: DBBean database = new DBBean();
803: tables = new Vector();
804: layouts = new Vector();
805: selects = new Vector();
806: creates = new Vector();
807:
808: // parse dataBase
809: Node node = root.find("convert/source/database/url", new int[] { 1, 1, i, 1 });
810: Node node1 = root.find("convert/source/database/user", new int[] { 1, 1, i, 1, 1 });
811: Node node2 = root.find("convert/source/database/password", new int[] { 1, 1, i, 1, 1 });
812: Node node3 = root.find("convert/source/database", new int[] { 1, 1, i});
813: Node nodeMode = root.find("convert/source/database/mode/", new int[] {1, 1, i, 1,1});
814:
815: if(node3== null) throw new Error("parse error database tag missing");
816: if(node==null) throw new Error("parse error url tag missing");
817: if(node1==null) throw new Error("parse error user tag missing");
818: if(node2==null) throw new Error("parse error password tag missing");
819: String url=node.getCharacters();
820: String user=node1.getCharacters();
821: String password=node2.getCharacters();
822: database.setURL(url.trim());
823: database.setUserAndPasswd(user.trim(),password.trim());
824: System.out.println(node.name + " " + node.getCharacters());
825: System.out.println(node1.name + " " + node1.getCharacters());
826: System.out.println(node2.name + " " + node2.getCharacters());
827: String modeString = "";
828: if (nodeMode == null)
829: modeString = "convert";
830: else
831: modeString = nodeMode.getCharacters();
832: if (modeString.equals("convert"))
833: mode = DataBase.CONVERT_MODE;
834: else
835: if (modeString.equals("append"))
836: mode = DataBase.APPEND_MODE;
837: else
838: if (modeString.equals("update"))
839: mode = DataBase.UPDATE_MODE;
840: // if(node3!=null)
841: // System.out.println(node3.name);
842:
843: int length2= countNodes(node3);
844:
845: System.out.println("number of tables " +length2);
846:
847: for(int j=1;j<=length2;++j)
848: {
849: Node node4 = root.find("convert/source/database/table", new int[] { 1, 1, i, j });
850: Node node5 = root.find("convert/source/database/table/select", new int[] { 1, 1, i, j, 1 });
851: Node node6 = root.find("convert/source/database/table/create", new int[] { 1, 1, i, j, 1 });
852: if(node4!=null)
853: System.out.println(node4.name + " " + node4.attributes.get("layout").equals(""));
854: if(node5!=null)
855: System.out.println(node5.name + " " + node5.getCharacters());
856: if(node6!=null)
857: System.out.println(node6.name + " " + node6.getCharacters());
858: if(node4==null) throw new Error("parse error table tag missing");
859: // if(node5==null) throw new Error("parse error select tag missing");
860: // if(node6==null) throw new Error("parse error create tag missing");
861: String name = (String)node4.attributes.get("name");
862: String layout = (String)node4.attributes.get("layout");
863: if(name==null) throw new Error("parse error required table tag attribute name missing");
864: if(layout==null) layout ="";
865: if(name.equals("")) throw new Error("parse error table tag attribute must not be empty");
866: tables.add(name);
867: layouts.add(layout);
868: String query = (node5==null) ? "":node5.getCharacters();
869: if(query.equals("")) System.err.println("Warning empty select tag or select tag missing !!");
870: query = (query.equals("")) ? "select * from "+database.getQC()+name+database.getQC():query;
871: selects.add(query);
872: if(node6!=null) creates.add(node6.getCharacters().trim());
873: else
874: creates.add("");
875:
876: }
877: databases.add(new DataBase(database, tables, layouts, selects,creates,mode));
878: }
879: DBBean database = new DBBean();
880: // parse dataBase
881: Node node = root.find("convert/destination/database/url", new int[] { 1, 1, 1, 1 });
882: Node node1 = root.find("convert/destination/database/user", new int[] { 1, 1, 1, 1, 1 });
883: Node node2 = root.find("convert/destination/database/password", new int[] { 1, 1, 1, 1, 1 });
884: String url = node.getCharacters();
885: String user = node1.getCharacters();
886: String password = node2.getCharacters();
887: System.out.println(url);
888: database.setURL(url.trim());
889: database.setUserAndPasswd(user.trim(), password.trim());
890: //databases.add(database);
891: for (Iterator iter = databases.iterator(); iter.hasNext();)
892: {
893: DataBase db = (DataBase) iter.next();
894: convertBatch(db.bean,database,db.tables,db.layouts,db.selects,db.creates);
895:
896: }
897: // printContents(node3);
898: // FM2SQL.fmInstance=new FM2SQL();
899: } catch (Exception e)
900: {
901: // TODO Auto-generated catch block
902: e.printStackTrace();
903: }
904: /*
905: Node tempNode=root.find(rootNode,new int[] {1});
906: if(tempNode==null) return rtTag;
907: int count=1;
908: /*
909: for(int i=0;i<tempNode.contents.v.size();++i)
910: {
911: // System.out.println(((Node)tempNode.contents.v.elementAt(i)).attributes+" "+i);
912: }*/
913: /*
914: if(tempNode.contents.v.size()==0) return rtTag;
915: Node notNull=null;
916: Node rtNode=root.find(rootNode+"/rt",new int[] {1,1});
917: rtTag=(rtNode==null) ? "finished":rtNode.getCharacters();
918: System.out.println("rt tag is "+ rtTag);
919: int length=0;//(tempNode.contents.length()-1)/2;
920: for(int i=0;i<tempNode.contents.v.size();++i) {
921: Node node=(Node)tempNode.contents.v.elementAt(i);
922: if(node.type.equals("element"))
923: if(node.name.equals("doc"))length++;
924: // System.out.println(((Node)tempNode.contents.v.elementAt(i)).attributes+" "+i);
925: }
926: if(length==0) rtTag="finished";
927: while(count<=length)
928: {
929: //System.out.println(count+" "+length);
930: tempNode=root.find(rootNode+"/doc",new int[] {1,count});
931: if(tempNode==null)
932: {
933: rtTag="finished";
934: break;
935: }
936: Bundle.Document doc = new Bundle.Document();
937: Hashtable attributes=tempNode.attributes;
938: int docID=0;
939: int ver=0;
940: if(attributes != null)
941: {
942: docID=Integer.parseInt((String)attributes.get("id"));
943: ver=Integer.parseInt((String)attributes.get("ver"));
944: doc.addData("docID",(String)attributes.get("id"));
945: doc.addData("ver",(String)attributes.get("ver"));
946: }
947: bundle.docs.put(new Integer(docID),doc);
948: bundle.documents.addElement(doc);
949: // System.out.println("id " +docID+" ver "+ver);
950: Node fileNode=root.find(rootNode+"/doc/file",new int[] {1,count,1});
951: attributes=(fileNode==null)? null:fileNode.attributes;
952: int fileID=0;
953: int fileVer=0;
954: if(attributes != null)
955: {
956: fileID=Integer.parseInt((String)attributes.get("id"));
957: fileVer=Integer.parseInt((String)attributes.get("ver"));
958: doc.addData("fileID",(String)attributes.get("id"));
959: doc.addData("fileVer",(String)attributes.get("ver"));
960: // System.out.println("fileid " +fileID+" ver "+fileVer);
961: }
962: // add all Document tags to actual Document
963: for(int i=0;i<tempNode.contents.v.size();++i)
964: {
965: Node node=(Node)tempNode.contents.v.elementAt(i);
966: if(node.type.equals("element"))
967: {
968: //System.out.println(node.name+" "+node.getCharacters()+" "+node.contents.v.size());
969: if(node.contents.v.size()>1)
970: {
971: for(int j=0;j<node.contents.v.size();++j)
972: {
973: Node node2=(Node)node.contents.v.elementAt(j);
974: if(node2.type.equals("element"))
975: {
976: doc.addData(node2.name,node2.getCharacters());
977: //System.out.println(node2.name+" "+node2.getCharacters()+" "+node2.contents.v.size());
978: }
979: }
980: } else doc.addData(node.name,node.getCharacters());
981: }
982: }
983: bundle.docsLocator.put(doc.locator,doc);
984:
985: bundle.documents.addElement(doc);
986: count++;
987: } */
988:
989: // System.out.println(bundle.docs.size());
990: // return rtTag;
991: }
992: public static Vector getXMLConfig(String xmlFile)
993: {
994: StringBuffer sb=null;
995: try
996: {
997: // read XML Metadata from a file
998: FileInputStream fi= new FileInputStream(xmlFile);
999: InputStreamReader isr= new InputStreamReader(fi,"UTF-8");
1000: BufferedReader buffr = new BufferedReader(isr);
1001: sb=new StringBuffer();
1002: int c=0;
1003: while ((c = buffr.read()) != -1)
1004: {
1005: char ch=(char)c;
1006: sb.append(ch);
1007: // System.out.print((char)c);
1008: }
1009:
1010: } catch(Exception e) { e.printStackTrace();}
1011:
1012: boolean finished = false;
1013: // parse string and build document tree
1014: Xparse parser =new Xparse();
1015: parser.changeEntities = true;
1016: Node root = parser.parse(sb.toString());
1017: // printContents(root);
1018: Vector databases= new Vector();
1019: Vector tables = new Vector();
1020: Vector layouts = new Vector();
1021: Vector selects = new Vector();
1022: Vector creates = new Vector();
1023: int mode = -1;
1024: try
1025: {
1026: Node tempNode = root.find("convert/source", new int[] { 1, 1 });
1027: if(tempNode==null) throw new Error("parse error source tag missing");
1028: System.out.println(tempNode.name);
1029: int length =countNodes(tempNode);
1030: for (int i = 1; i <= length; i++)
1031: {
1032:
1033: DBBean database = new DBBean();
1034: tables = new Vector();
1035: layouts = new Vector();
1036: selects = new Vector();
1037: creates = new Vector();
1038:
1039: // parse dataBase
1040: Node node = root.find("convert/source/database/url", new int[] { 1, 1, i, 1 });
1041: Node node1 = root.find("convert/source/database/user", new int[] { 1, 1, i, 1, 1 });
1042: Node node2 = root.find("convert/source/database/password", new int[] { 1, 1, i, 1, 1 });
1043: Node node3 = root.find("convert/source/database", new int[] { 1, 1, i});
1044: Node nodeMode = root.find("convert/source/database/mode", new int[] { 1, 1, i, 1, 1 });
1045:
1046: if(node3== null) throw new Error("parse error database tag missing");
1047: if(node==null) throw new Error("parse error url tag missing");
1048: if(node1==null) throw new Error("parse error user tag missing");
1049: if(node2==null) throw new Error("parse error password tag missing");
1050: String url=node.getCharacters();
1051: String user=node1.getCharacters();
1052: String password=node2.getCharacters();
1053: database.setURL(url.trim());
1054: database.setUserAndPasswd(user.trim(),password.trim());
1055: System.out.println(node.name + " " + node.getCharacters());
1056: System.out.println(node1.name + " " + node1.getCharacters());
1057: System.out.println(node2.name + " " + node2.getCharacters());
1058: String modeString = "";
1059: if (nodeMode == null)
1060: modeString = "convert";
1061: else
1062: modeString = nodeMode.getCharacters();
1063: if (modeString.equals("convert"))
1064: mode = DataBase.CONVERT_MODE;
1065: else
1066: if (modeString.equals("append"))
1067: mode = DataBase.APPEND_MODE;
1068: else
1069: if (modeString.equals("update"))
1070: mode = DataBase.UPDATE_MODE;
1071:
1072:
1073: // if(node3!=null)
1074: // System.out.println(node3.name);
1075:
1076: int length2= countNodes(node3);
1077:
1078: System.out.println("number of tables " +length2);
1079:
1080: for(int j=1;j<=length2;++j)
1081: {
1082: Node node4 = root.find("convert/source/database/table", new int[] { 1, 1, i, j });
1083: Node node5 = root.find("convert/source/database/table/select", new int[] { 1, 1, i, j, 1 });
1084: Node node6 = root.find("convert/source/database/table/create", new int[] { 1, 1, i, j, 1 });
1085: if(node4!=null)
1086: System.out.println(node4.name + " " + node4.attributes.get("layout").equals(""));
1087: if(node5!=null)
1088: System.out.println(node5.name + " " + node5.getCharacters());
1089: if(node6!=null)
1090: System.out.println(node6.name + " " + node6.getCharacters());
1091: if(node4==null) throw new Error("parse error table tag missing");
1092: // if(node5==null) throw new Error("parse error select tag missing");
1093: // if(node6==null) throw new Error("parse error create tag missing");
1094: String name = (String)node4.attributes.get("name");
1095: String layout = (String)node4.attributes.get("layout");
1096: if(name==null) throw new Error("parse error required table tag attribute name missing");
1097: if(layout==null) layout ="";
1098: if(name.equals("")) throw new Error("parse error table tag attribute must not be empty");
1099: tables.add(name);
1100: layouts.add(layout);
1101: String query = (node5==null) ? "":node5.getCharacters();
1102: if(query.equals("")) System.err.println("Warning empty select tag or select tag missing !!");
1103: query = (query.equals("")) ? "select * from "+database.getQC()+name+database.getQC():query;
1104: selects.add(query);
1105: if(node6!=null) creates.add(node6.getCharacters().trim());
1106: else
1107: creates.add("");
1108:
1109: }
1110: databases.add(new DataBase(database, tables, layouts, selects,creates,mode));
1111: }
1112: DBBean database = new DBBean();
1113: // parse dataBase
1114: Node node = root.find("convert/destination/database/url", new int[] { 1, 1, 1, 1 });
1115: Node node1 = root.find("convert/destination/database/user", new int[] { 1, 1, 1, 1, 1 });
1116: Node node2 = root.find("convert/destination/database/password", new int[] { 1, 1, 1, 1, 1 });
1117: String url = node.getCharacters();
1118: String user = node1.getCharacters();
1119: String password = node2.getCharacters();
1120: System.out.println(url);
1121: database.setURL(url.trim());
1122: database.setUserAndPasswd(user.trim(), password.trim());
1123: databases.add(new DataBase(database,null,null,null,null,0));
1124: //databases.add(database);
1125: /* for (Iterator iter = databases.iterator(); iter.hasNext();)
1126: {
1127: DataBase db = (DataBase) iter.next();
1128: convertBatch(db.bean,database,db.tables,db.layouts,db.selects,db.creates);
1129:
1130: }*/
1131: // printContents(node3);
1132: // FM2SQL.fmInstance=new FM2SQL();
1133: } catch (Exception e)
1134: {
1135: // TODO Auto-generated catch block
1136: e.printStackTrace();
1137: }
1138: return databases;
1139: }
1140:
1141:
1142: private static int countNodes(Node tempNode)
1143: {
1144: int length = 0;
1145: for(int i=0;i<tempNode.contents.v.size();++i) {
1146: Node node=(Node)tempNode.contents.v.elementAt(i);
1147: if(node.type.equals("element"))
1148: {
1149: if(node.name.equals("database"))length++;
1150: if(node.name.equals("table"))length++;
1151: }
1152:
1153: // System.out.println(((Node)tempNode.contents.v.elementAt(i)).attributes+" "+i);
1154: }
1155: return length;
1156: }
1157: private static void printContents(Node root)
1158: {
1159:
1160:
1161: Vector contents=(root.index==null)? root.contents.v:root.index.v;
1162: for (int i=0;i<contents.size();++i)
1163: {
1164: Node n=(Node)contents.elementAt(i);
1165: if(n.type.equals("element"))
1166: {
1167: System.out.println("tag "+n.name);
1168: System.out.println(n.getCharacters());
1169: //contents=n.contents.v i=0;
1170: }
1171: // System.out.println(n.type);
1172:
1173:
1174:
1175: }
1176: }
1177: public static void readXMLFile(String xmlFile)
1178: {
1179: try
1180: {
1181: // read XML Metadata from a file
1182: FileInputStream fi= new FileInputStream(xmlFile);
1183: InputStreamReader isr= new InputStreamReader(fi,"UTF-8");
1184: BufferedReader buffr = new BufferedReader(isr);
1185: StringBuffer sb=new StringBuffer();
1186: int c=0;
1187: while ((c = buffr.read()) != -1)
1188: {
1189: char ch=(char)c;
1190: sb.append(ch);
1191: // System.out.print((char)c);
1192: }
1193: parseXMLConfig(sb);
1194: } catch(Exception e) { e.printStackTrace();}
1195: }
1196: public static class DataBase
1197: {
1198: DBBean bean;
1199: Vector creates;
1200: Vector selects;
1201: Vector layouts;
1202: Vector tables;
1203: final static int CONVERT_MODE = 1;
1204: final static int APPEND_MODE = 2;
1205: final static int UPDATE_MODE = 3;
1206: int mode = -1;
1207:
1208: public DataBase(DBBean bean,Vector tables,Vector layouts,Vector selects,Vector creates,int mode)
1209: {
1210: this.bean = bean;
1211: this.tables = tables;
1212: this.layouts = layouts;
1213: this.selects = selects;
1214: this.creates = creates;
1215: this.mode = mode;
1216: }
1217: public void exportToXML(BufferedWriter buffr) throws Exception
1218: {
1219: buffr.write(" <database>\n");
1220: buffr.write(" <url>"+bean.url+"</url>\n");
1221: buffr.write(" <user>"+bean.user+"</user>\n");
1222: buffr.write(" <password>"+bean.passwd+"</password>\n");
1223: String modeString ="";
1224: if (mode == CONVERT_MODE)
1225: modeString = "convert";
1226: else
1227: if (mode == APPEND_MODE)
1228: modeString = "append";
1229: else
1230: if (mode == UPDATE_MODE)
1231: modeString = "update";
1232:
1233: buffr.write(" <mode>"+ modeString+"</mode>\n");
1234: int index = 0;
1235: while(index<tables.size())
1236: {
1237: String table=(String)tables.get(index);
1238: String layout=(String)layouts.get(index);
1239: String select=(String)selects.get(index);
1240: String create=(String)creates.get(index);
1241:
1242: buffr.write(" <table name = \""+table+"\" layout = \""+layout+"\">\n");
1243: buffr.write(" <select>"+ convertToEntities(select)+"</select>\n");
1244: if(!create.equals(""))
1245: buffr.write(" <create>"+create+" </create>\n");
1246: buffr.write(" </table>\n");
1247: index++;
1248: }
1249: buffr.write(" </database>\n");
1250: }
1251: public String toString() {return bean.url+" "+tables;}
1252:
1253: }
1254: public static String convertToUTF8(Object command)
1255: {
1256: String str = null;
1257: try
1258: {
1259: str = new String(command.toString().getBytes("UTF-8"));
1260: } catch (UnsupportedEncodingException e)
1261: {
1262: // TODO Auto-generated catch block
1263: e.printStackTrace();
1264: }
1265: return str;
1266: }
1267: public static void writeConfig(String file, DataBase source, DataBase destination) throws Exception
1268: {
1269: if(!file.toLowerCase().endsWith(".xml")) file+=".xml";
1270: File f = new File(file);
1271:
1272: FileOutputStream fout= new FileOutputStream(f);
1273: OutputStreamWriter outsw = new OutputStreamWriter(fout,"UTF-8");
1274: BufferedWriter buffw = new BufferedWriter(outsw);
1275: buffw.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
1276: buffw.newLine();
1277: buffw.write("<convert>\n");
1278: buffw.write(" <source>\n");
1279: source.exportToXML(buffw);
1280: buffw.write(" </source>\n");
1281: buffw.write("\n <destination>\n");
1282: destination.exportToXML(buffw);
1283: buffw.write(" </destination>\n");
1284: buffw.write("</convert>\n");
1285: buffw.close();
1286: }
1287: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>