Annotation of FM2SQL/Convert.java, revision 1.4
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:
310: public static void convert(String source,String destination,Vector names,Vector layouts,Vector selects,Vector creates) 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(true)
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();
789:
790: try
791: {
792: Node tempNode = root.find("convert/source", new int[] { 1, 1 });
793: if(tempNode==null) throw new Error("parse error source tag missing");
794: System.out.println(tempNode.name);
795: int length =countNodes(tempNode);
796: for (int i = 1; i <= length; i++)
797: {
798:
799: DBBean database = new DBBean();
800: tables = new Vector();
801: layouts = new Vector();
802: selects = new Vector();
803: creates = new Vector();
804:
805: // parse dataBase
806: Node node = root.find("convert/source/database/url", new int[] { 1, 1, i, 1 });
807: Node node1 = root.find("convert/source/database/user", new int[] { 1, 1, i, 1, 1 });
808: Node node2 = root.find("convert/source/database/password", new int[] { 1, 1, i, 1, 1 });
809: Node node3 = root.find("convert/source/database", new int[] { 1, 1, i});
810: if(node3== null) throw new Error("parse error database tag missing");
811: if(node==null) throw new Error("parse error url tag missing");
812: if(node1==null) throw new Error("parse error user tag missing");
813: if(node2==null) throw new Error("parse error password tag missing");
814: String url=node.getCharacters();
815: String user=node1.getCharacters();
816: String password=node2.getCharacters();
817: database.setURL(url.trim());
818: database.setUserAndPasswd(user.trim(),password.trim());
819: System.out.println(node.name + " " + node.getCharacters());
820: System.out.println(node1.name + " " + node1.getCharacters());
821: System.out.println(node2.name + " " + node2.getCharacters());
822:
823: // if(node3!=null)
824: // System.out.println(node3.name);
825:
826: int length2= countNodes(node3);
827:
828: System.out.println("number of tables " +length2);
829:
830: for(int j=1;j<=length2;++j)
831: {
832: Node node4 = root.find("convert/source/database/table", new int[] { 1, 1, i, j });
833: Node node5 = root.find("convert/source/database/table/select", new int[] { 1, 1, i, j, 1 });
834: Node node6 = root.find("convert/source/database/table/create", new int[] { 1, 1, i, j, 1 });
835: if(node4!=null)
836: System.out.println(node4.name + " " + node4.attributes.get("layout").equals(""));
837: if(node5!=null)
838: System.out.println(node5.name + " " + node5.getCharacters());
839: if(node6!=null)
840: System.out.println(node6.name + " " + node6.getCharacters());
841: if(node4==null) throw new Error("parse error table tag missing");
842: // if(node5==null) throw new Error("parse error select tag missing");
843: // if(node6==null) throw new Error("parse error create tag missing");
844: String name = (String)node4.attributes.get("name");
845: String layout = (String)node4.attributes.get("layout");
846: if(name==null) throw new Error("parse error required table tag attribute name missing");
847: if(layout==null) layout ="";
848: if(name.equals("")) throw new Error("parse error table tag attribute must not be empty");
849: tables.add(name);
850: layouts.add(layout);
851: String query = (node5==null) ? "":node5.getCharacters();
852: if(query.equals("")) System.err.println("Warning empty select tag or select tag missing !!");
853: query = (query.equals("")) ? "select * from "+database.getQC()+name+database.getQC():query;
854: selects.add(query);
855: if(node6!=null) creates.add(node6.getCharacters().trim());
856: else
857: creates.add("");
858:
859: }
860: databases.add(new DataBase(database, tables, layouts, selects,creates));
861: }
862: DBBean database = new DBBean();
863: // parse dataBase
864: Node node = root.find("convert/destination/database/url", new int[] { 1, 1, 1, 1 });
865: Node node1 = root.find("convert/destination/database/user", new int[] { 1, 1, 1, 1, 1 });
866: Node node2 = root.find("convert/destination/database/password", new int[] { 1, 1, 1, 1, 1 });
867: String url = node.getCharacters();
868: String user = node1.getCharacters();
869: String password = node2.getCharacters();
870: System.out.println(url);
871: database.setURL(url.trim());
872: database.setUserAndPasswd(user.trim(), password.trim());
873: //databases.add(database);
874: for (Iterator iter = databases.iterator(); iter.hasNext();)
875: {
876: DataBase db = (DataBase) iter.next();
877: convertBatch(db.bean,database,db.tables,db.layouts,db.selects,db.creates);
878:
879: }
880: // printContents(node3);
881: // FM2SQL.fmInstance=new FM2SQL();
882: } catch (Exception e)
883: {
884: // TODO Auto-generated catch block
885: e.printStackTrace();
886: }
887: /*
888: Node tempNode=root.find(rootNode,new int[] {1});
889: if(tempNode==null) return rtTag;
890: int count=1;
891: /*
892: for(int i=0;i<tempNode.contents.v.size();++i)
893: {
894: // System.out.println(((Node)tempNode.contents.v.elementAt(i)).attributes+" "+i);
895: }*/
896: /*
897: if(tempNode.contents.v.size()==0) return rtTag;
898: Node notNull=null;
899: Node rtNode=root.find(rootNode+"/rt",new int[] {1,1});
900: rtTag=(rtNode==null) ? "finished":rtNode.getCharacters();
901: System.out.println("rt tag is "+ rtTag);
902: int length=0;//(tempNode.contents.length()-1)/2;
903: for(int i=0;i<tempNode.contents.v.size();++i) {
904: Node node=(Node)tempNode.contents.v.elementAt(i);
905: if(node.type.equals("element"))
906: if(node.name.equals("doc"))length++;
907: // System.out.println(((Node)tempNode.contents.v.elementAt(i)).attributes+" "+i);
908: }
909: if(length==0) rtTag="finished";
910: while(count<=length)
911: {
912: //System.out.println(count+" "+length);
913: tempNode=root.find(rootNode+"/doc",new int[] {1,count});
914: if(tempNode==null)
915: {
916: rtTag="finished";
917: break;
918: }
919: Bundle.Document doc = new Bundle.Document();
920: Hashtable attributes=tempNode.attributes;
921: int docID=0;
922: int ver=0;
923: if(attributes != null)
924: {
925: docID=Integer.parseInt((String)attributes.get("id"));
926: ver=Integer.parseInt((String)attributes.get("ver"));
927: doc.addData("docID",(String)attributes.get("id"));
928: doc.addData("ver",(String)attributes.get("ver"));
929: }
930: bundle.docs.put(new Integer(docID),doc);
931: bundle.documents.addElement(doc);
932: // System.out.println("id " +docID+" ver "+ver);
933: Node fileNode=root.find(rootNode+"/doc/file",new int[] {1,count,1});
934: attributes=(fileNode==null)? null:fileNode.attributes;
935: int fileID=0;
936: int fileVer=0;
937: if(attributes != null)
938: {
939: fileID=Integer.parseInt((String)attributes.get("id"));
940: fileVer=Integer.parseInt((String)attributes.get("ver"));
941: doc.addData("fileID",(String)attributes.get("id"));
942: doc.addData("fileVer",(String)attributes.get("ver"));
943: // System.out.println("fileid " +fileID+" ver "+fileVer);
944: }
945: // add all Document tags to actual Document
946: for(int i=0;i<tempNode.contents.v.size();++i)
947: {
948: Node node=(Node)tempNode.contents.v.elementAt(i);
949: if(node.type.equals("element"))
950: {
951: //System.out.println(node.name+" "+node.getCharacters()+" "+node.contents.v.size());
952: if(node.contents.v.size()>1)
953: {
954: for(int j=0;j<node.contents.v.size();++j)
955: {
956: Node node2=(Node)node.contents.v.elementAt(j);
957: if(node2.type.equals("element"))
958: {
959: doc.addData(node2.name,node2.getCharacters());
960: //System.out.println(node2.name+" "+node2.getCharacters()+" "+node2.contents.v.size());
961: }
962: }
963: } else doc.addData(node.name,node.getCharacters());
964: }
965: }
966: bundle.docsLocator.put(doc.locator,doc);
967:
968: bundle.documents.addElement(doc);
969: count++;
970: } */
971:
972: // System.out.println(bundle.docs.size());
973: // return rtTag;
974: }
975: public static Vector getXMLConfig(String xmlFile)
976: {
977: StringBuffer sb=null;
978: try
979: {
980: // read XML Metadata from a file
981: FileInputStream fi= new FileInputStream(xmlFile);
982: InputStreamReader isr= new InputStreamReader(fi,"UTF-8");
983: BufferedReader buffr = new BufferedReader(isr);
984: sb=new StringBuffer();
985: int c=0;
986: while ((c = buffr.read()) != -1)
987: {
988: char ch=(char)c;
989: sb.append(ch);
990: // System.out.print((char)c);
991: }
992:
993: } catch(Exception e) { e.printStackTrace();}
994:
995: boolean finished = false;
996: // parse string and build document tree
1.4 ! rogo 997: Xparse parser =new Xparse();
! 998: parser.changeEntities = true;
! 999: Node root = parser.parse(sb.toString());
! 1000: // printContents(root);
1.1 rogo 1001: Vector databases= new Vector();
1002: Vector tables = new Vector();
1003: Vector layouts = new Vector();
1004: Vector selects = new Vector();
1005: Vector creates = new Vector();
1006:
1007: try
1008: {
1009: Node tempNode = root.find("convert/source", new int[] { 1, 1 });
1010: if(tempNode==null) throw new Error("parse error source tag missing");
1011: System.out.println(tempNode.name);
1012: int length =countNodes(tempNode);
1013: for (int i = 1; i <= length; i++)
1014: {
1015:
1016: DBBean database = new DBBean();
1017: tables = new Vector();
1018: layouts = new Vector();
1019: selects = new Vector();
1020: creates = new Vector();
1021:
1022: // parse dataBase
1023: Node node = root.find("convert/source/database/url", new int[] { 1, 1, i, 1 });
1024: Node node1 = root.find("convert/source/database/user", new int[] { 1, 1, i, 1, 1 });
1025: Node node2 = root.find("convert/source/database/password", new int[] { 1, 1, i, 1, 1 });
1026: Node node3 = root.find("convert/source/database", new int[] { 1, 1, i});
1027: if(node3== null) throw new Error("parse error database tag missing");
1028: if(node==null) throw new Error("parse error url tag missing");
1029: if(node1==null) throw new Error("parse error user tag missing");
1030: if(node2==null) throw new Error("parse error password tag missing");
1031: String url=node.getCharacters();
1032: String user=node1.getCharacters();
1033: String password=node2.getCharacters();
1034: database.setURL(url.trim());
1035: database.setUserAndPasswd(user.trim(),password.trim());
1036: System.out.println(node.name + " " + node.getCharacters());
1037: System.out.println(node1.name + " " + node1.getCharacters());
1038: System.out.println(node2.name + " " + node2.getCharacters());
1039:
1040: // if(node3!=null)
1041: // System.out.println(node3.name);
1042:
1043: int length2= countNodes(node3);
1044:
1045: System.out.println("number of tables " +length2);
1046:
1047: for(int j=1;j<=length2;++j)
1048: {
1049: Node node4 = root.find("convert/source/database/table", new int[] { 1, 1, i, j });
1050: Node node5 = root.find("convert/source/database/table/select", new int[] { 1, 1, i, j, 1 });
1051: Node node6 = root.find("convert/source/database/table/create", new int[] { 1, 1, i, j, 1 });
1052: if(node4!=null)
1053: System.out.println(node4.name + " " + node4.attributes.get("layout").equals(""));
1054: if(node5!=null)
1055: System.out.println(node5.name + " " + node5.getCharacters());
1056: if(node6!=null)
1057: System.out.println(node6.name + " " + node6.getCharacters());
1058: if(node4==null) throw new Error("parse error table tag missing");
1059: // if(node5==null) throw new Error("parse error select tag missing");
1060: // if(node6==null) throw new Error("parse error create tag missing");
1061: String name = (String)node4.attributes.get("name");
1062: String layout = (String)node4.attributes.get("layout");
1063: if(name==null) throw new Error("parse error required table tag attribute name missing");
1064: if(layout==null) layout ="";
1065: if(name.equals("")) throw new Error("parse error table tag attribute must not be empty");
1066: tables.add(name);
1067: layouts.add(layout);
1068: String query = (node5==null) ? "":node5.getCharacters();
1069: if(query.equals("")) System.err.println("Warning empty select tag or select tag missing !!");
1070: query = (query.equals("")) ? "select * from "+database.getQC()+name+database.getQC():query;
1071: selects.add(query);
1072: if(node6!=null) creates.add(node6.getCharacters().trim());
1073: else
1074: creates.add("");
1075:
1076: }
1077: databases.add(new DataBase(database, tables, layouts, selects,creates));
1078: }
1079: DBBean database = new DBBean();
1080: // parse dataBase
1081: Node node = root.find("convert/destination/database/url", new int[] { 1, 1, 1, 1 });
1082: Node node1 = root.find("convert/destination/database/user", new int[] { 1, 1, 1, 1, 1 });
1083: Node node2 = root.find("convert/destination/database/password", new int[] { 1, 1, 1, 1, 1 });
1084: String url = node.getCharacters();
1085: String user = node1.getCharacters();
1086: String password = node2.getCharacters();
1087: System.out.println(url);
1088: database.setURL(url.trim());
1089: database.setUserAndPasswd(user.trim(), password.trim());
1090: databases.add(new DataBase(database,null,null,null,null));
1091: //databases.add(database);
1092: /* for (Iterator iter = databases.iterator(); iter.hasNext();)
1093: {
1094: DataBase db = (DataBase) iter.next();
1095: convertBatch(db.bean,database,db.tables,db.layouts,db.selects,db.creates);
1096:
1097: }*/
1098: // printContents(node3);
1099: // FM2SQL.fmInstance=new FM2SQL();
1100: } catch (Exception e)
1101: {
1102: // TODO Auto-generated catch block
1103: e.printStackTrace();
1104: }
1105: return databases;
1106: }
1107:
1108:
1109: private static int countNodes(Node tempNode)
1110: {
1111: int length = 0;
1112: for(int i=0;i<tempNode.contents.v.size();++i) {
1113: Node node=(Node)tempNode.contents.v.elementAt(i);
1114: if(node.type.equals("element"))
1115: {
1116: if(node.name.equals("database"))length++;
1117: if(node.name.equals("table"))length++;
1118: }
1119:
1120: // System.out.println(((Node)tempNode.contents.v.elementAt(i)).attributes+" "+i);
1121: }
1122: return length;
1123: }
1124: private static void printContents(Node root)
1125: {
1126:
1127:
1128: Vector contents=(root.index==null)? root.contents.v:root.index.v;
1129: for (int i=0;i<contents.size();++i)
1130: {
1131: Node n=(Node)contents.elementAt(i);
1132: if(n.type.equals("element"))
1133: {
1134: System.out.println("tag "+n.name);
1135: System.out.println(n.getCharacters());
1136: //contents=n.contents.v i=0;
1137: }
1138: // System.out.println(n.type);
1139:
1140:
1141:
1142: }
1143: }
1144: public static void readXMLFile(String xmlFile)
1145: {
1146: try
1147: {
1148: // read XML Metadata from a file
1149: FileInputStream fi= new FileInputStream(xmlFile);
1150: InputStreamReader isr= new InputStreamReader(fi,"UTF-8");
1151: BufferedReader buffr = new BufferedReader(isr);
1152: StringBuffer sb=new StringBuffer();
1153: int c=0;
1154: while ((c = buffr.read()) != -1)
1155: {
1156: char ch=(char)c;
1157: sb.append(ch);
1158: // System.out.print((char)c);
1159: }
1160: parseXMLConfig(sb);
1161: } catch(Exception e) { e.printStackTrace();}
1162: }
1163: public static class DataBase
1164: {
1165: DBBean bean;
1166: Vector creates;
1167: Vector selects;
1168: Vector layouts;
1169: Vector tables;
1170: public DataBase(DBBean bean,Vector tables,Vector layouts,Vector selects,Vector creates)
1171: {
1172: this.bean = bean;
1173: this.tables = tables;
1174: this.layouts = layouts;
1175: this.selects = selects;
1176: this.creates = creates;
1177: }
1178: public void exportToXML(BufferedWriter buffr) throws Exception
1179: {
1180: buffr.write(" <database>\n");
1181: buffr.write(" <url>"+bean.url+"</url>\n");
1182: buffr.write(" <user>"+bean.user+"</user>\n");
1183: buffr.write(" <password>"+bean.passwd+"</password>\n");
1184:
1185: int index = 0;
1186: while(index<tables.size())
1187: {
1188: String table=(String)tables.get(index);
1189: String layout=(String)layouts.get(index);
1190: String select=(String)selects.get(index);
1191: String create=(String)creates.get(index);
1192:
1193: buffr.write(" <table name = \""+table+"\" layout = \""+layout+"\">\n");
1.4 ! rogo 1194: buffr.write(" <select>"+ convertToEntities(select)+"</select>\n");
1.1 rogo 1195: if(!create.equals(""))
1196: buffr.write(" <create>"+create+" </create>\n");
1197: buffr.write(" </table>\n");
1198: index++;
1199: }
1200: buffr.write(" </database>\n");
1201: }
1202: public String toString() {return bean.url+" "+tables;}
1203:
1204: }
1205: public static String convertToUTF8(Object command)
1206: {
1207: String str = null;
1208: try
1209: {
1210: str = new String(command.toString().getBytes("UTF-8"));
1211: } catch (UnsupportedEncodingException e)
1212: {
1213: // TODO Auto-generated catch block
1214: e.printStackTrace();
1215: }
1216: return str;
1217: }
1218: public static void writeConfig(String file, DataBase source, DataBase destination) throws Exception
1219: {
1220: if(!file.toLowerCase().endsWith(".xml")) file+=".xml";
1221: File f = new File(file);
1222:
1223: FileOutputStream fout= new FileOutputStream(f);
1224: OutputStreamWriter outsw = new OutputStreamWriter(fout,"UTF-8");
1225: BufferedWriter buffw = new BufferedWriter(outsw);
1226: buffw.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
1227: buffw.newLine();
1228: buffw.write("<convert>\n");
1229: buffw.write(" <source>\n");
1230: source.exportToXML(buffw);
1231: buffw.write(" </source>\n");
1232: buffw.write("\n <destination>\n");
1233: destination.exportToXML(buffw);
1234: buffw.write(" </destination>\n");
1235: buffw.write("</convert>\n");
1236: buffw.close();
1237: }
1238: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>