Annotation of FM2SQL/Convert.java, revision 1.59
1.51 rogo 1: /*
2: * Convert.java -- Converter class - Filemaker to SQL Converter
1.52 rogo 3: * Copyright (C) 2003 Robert Gordesch (rogo@mpiwg-berlin.mpg.de)
1.51 rogo 4: * This program is free software; you can redistribute it and/or modify it
5: * under the terms of the GNU General Public License as published by the Free
6: * Software Foundation; either version 2 of the License, or (at your option)
7: * any later version. Please read license.txt for the full details. A copy of
8: * the GPL may be found at http://www.gnu.org/copyleft/lgpl.html You should
9: * have received a copy of the GNU General Public License along with this
10: * program; if not, write to the Free Software Foundation, Inc., 59 Temple
11: * Place, Suite 330, Boston, MA 02111-1307 USA Created on 15.09.2003 by
12: * rogo
13: */
14:
1.1 rogo 15: import java.awt.Cursor;
16: import java.io.BufferedReader;
17: import java.io.BufferedWriter;
18: import java.io.File;
19: import java.io.FileInputStream;
20: import java.io.FileNotFoundException;
21: import java.io.FileOutputStream;
22: import java.io.InputStreamReader;
23: import java.io.OutputStreamWriter;
24: import java.io.PrintStream;
25: import java.io.UnsupportedEncodingException;
1.57 rogo 26: import java.sql.PreparedStatement;
27: import java.sql.SQLException;
28: import java.sql.Statement;
29: import java.sql.Types;
30: import java.util.ArrayList;
31: import java.util.Iterator;
32: import java.util.List;
33: import java.util.StringTokenizer;
34: import java.util.TreeSet;
35: import java.util.Vector;
1.1 rogo 36:
37: import com.exploringxml.xml.Node;
38: import com.exploringxml.xml.Xparse;
39:
1.34 rogo 40: class Convert
1.1 rogo 41: {
1.34 rogo 42: static DBBean bean = new DBBean();
43: static DBBean beanDest = new DBBean();
1.1 rogo 44:
1.34 rogo 45: static String user = "", passwd = "e1nste1n";
46: static String userDest = "postgres", passwdDest = "rogo";
47: static boolean batchRun = false;
1.1 rogo 48: static Vector databases = new Vector();
1.30 rogo 49: final static int numHits = 5000;
50: final static int numIntervalls = 2;
1.1 rogo 51: public static void main(String args[])
52: {
1.34 rogo 53: /* try
54: {
55: //byte[] b = "ö".getBytes("UTF-8");
56: // System.out.println("QueryString " +b[0]+" "+b[1]+(new String(b).getBytes()[0])+" "+new String(b).getBytes()[1]);
57: //System.out.println(new String(b,"UTF-8"));
58: } catch (UnsupportedEncodingException e)
59: {
60: e.printStackTrace();
61: }*/
1.1 rogo 62: FileOutputStream file = null;
1.34 rogo 63: if (args.length != 1)
1.1 rogo 64: {
1.34 rogo 65: System.out.println("Usage: java Convert <xml config file>");
66: System.exit(-1);
1.1 rogo 67: }
1.34 rogo 68: if (!(new File(args[0]).exists()))
69: System.exit(0);
1.1 rogo 70: try
71: {
72: file = new FileOutputStream("./log.txt");
73: } catch (FileNotFoundException e1)
74: {
75: e1.printStackTrace();
1.34 rogo 76: }
77: PrintStream stream = new PrintStream(file);
78: System.setOut(stream);
79: System.setErr(stream);
80: readXMLFile(args[0]);
81: System.out.println("Finished!");
1.1 rogo 82: //convert("jdbc:fmpro:http://141.14.237.74:8050","jdbc:postgresql://erebos/test",null,null);
83: }
1.55 rogo 84: public static void convertBatch(DBBean source, DBBean destination, Vector names, Vector layouts, Vector selects, Vector creates, Vector ids, int mode, String delimiter) throws Exception
1.1 rogo 85: {
1.34 rogo 86: bean = source;
87: beanDest = destination;
1.55 rogo 88: convert(null, null, names, layouts, selects, creates, ids, mode, delimiter);
89: if (true)
90: return;
1.34 rogo 91: StringBuffer command = null;
1.1 rogo 92: try
93: {
94: bean.setConnection(source.url);
1.34 rogo 95: if (names == null)
96: names = bean.getTableNames();
1.1 rogo 97: //Collections.sort(names);
1.34 rogo 98: int tbIndex = 1;
99:
100: for (tbIndex = 0; tbIndex < names.size(); ++tbIndex)
1.1 rogo 101: {
102: Vector[] result = null;
1.34 rogo 103: try
1.1 rogo 104: {
1.34 rogo 105: String query = "select * from " + bean.getQC() + names.get(tbIndex).toString() + bean.getQC();
106: String layout = (layouts.isEmpty()) ? "" : layouts.get(tbIndex).toString();
107: query = (selects != null) ? selects.get(tbIndex).toString() : query;
108: //if vectors[1].get(i) != null)
109: if (!layout.equals(""))
110: {
111: System.out.println("before " + query + " table" + names.get(tbIndex));
112: layout = " layout " + bean.getQC() + layout + bean.getQC();
113: String name = names.get(tbIndex).toString();
114: StringBuffer queryLayout = new StringBuffer(query);
115: queryLayout.insert(queryLayout.indexOf(name) + name.length() + 1, " " + layout);
116: query = queryLayout.toString();
117: System.out.println("added layout " + query);
118:
119: }
120: System.out.println(" performing query " + query);
1.1 rogo 121: //result = bean.getQueryData(query, null, 0);
1.34 rogo 122: bean.getConnection();
123: bean.makeQuery(query, 0);
124: } catch (Exception e)
1.1 rogo 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();
1.34 rogo 136: // Collections.sort(tables);
137: System.out.println("converting table " + names.get(tbIndex) + " " + tables.indexOf(convertText((String) names.get(tbIndex)))); // "//beanDest.getTypeNames());
1.1 rogo 138: tables = beanDest.getTableNames();
139: // System.out.println(beanDest.getTableNames(beanDest.getCatalogs().get(2).toString()));
140: stm = beanDest.getConnection().createStatement();
141: // System.exit(0);
1.34 rogo 142: if (mode == Convert.DataBase.CONVERT_MODE)
1.1 rogo 143: {
1.34 rogo 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: } else if (tables.indexOf(convertText(names.get(tbIndex).toString())) >= 0)
1.1 rogo 150: {
1.34 rogo 151: stm.executeUpdate("drop table " + beanDest.getQC() + convertText((String) names.get(tbIndex)) + beanDest.getQC());
152: tables.remove(convertText((String) names.get(tbIndex)));
153: System.out.println("dropped table " + names.get(tbIndex));
154: }
155:
156: if (tables.indexOf(names.get(tbIndex)) < 0 && tables.indexOf(convertText(names.get(tbIndex).toString())) < 0)
1.1 rogo 157: {
1.34 rogo 158: if (creates.get(tbIndex).equals("") || creates.get(tbIndex).toString().toLowerCase().indexOf("create") < 0)
159: {
160: System.out.println("Warning empty or invalid create statement - creating one for you\n");
161:
162: command = new StringBuffer(50);
163: command.append("CREATE TABLE ");
164: command.append(beanDest.getQC());
165: command.append(convertText((String) names.get(tbIndex)));
166: command.append(beanDest.getQC());
167: command.append("(");
168: String type = null;
169: Vector columnNames = bean.getColumnNames();
170: for (int i = 0; i < columnNames.size() - 1; ++i)
171: {
172: type = bean.metaData.getColumnTypeName(i + 1);
173: // System.out.println(i+" "+result[1].get(i)+" "+type);
174: type = (type.equals("NUMBER")) ? "INT4" : type;
175: type = (type.equals("CONTAINER")) ? "TEXT" : type;
176:
177: command.append(beanDest.getQC() + convertText((String) columnNames.get(i)) + beanDest.getQC() + " " + type + ", ");
178: }
179: type = bean.metaData.getColumnTypeName(columnNames.size());
180: type = (type.equals("NUMBER")) ? "INT4" : type;
181: type = (type.equals("CONTAINER")) ? "TEXT" : type;
182: command.append(beanDest.getQC() + convertText((String) columnNames.get(columnNames.size() - 1)) + beanDest.getQC() + " " + type);
183: command.append(" )");
184: } else
185: command = new StringBuffer().append(creates.get(tbIndex).toString());
186:
187: System.out.println(command);
188: // System.exit(0);
189: //command.append(DBBean.getQC());
190: stm.executeUpdate(command.toString());
1.1 rogo 191:
1.34 rogo 192: }
1.1 rogo 193: }
1.34 rogo 194: Vector row = null;
195: command = new StringBuffer();
1.1 rogo 196:
197: command.append("INSERT INTO ");
198: command.append(beanDest.getQC());
199: command.append(convertText((String) names.get(tbIndex)));
200: command.append(beanDest.getQC());
201: command.append(" values ( ");
1.3 rogo 202:
1.34 rogo 203: for (int i = 0; i < bean.getColumnNames().size() - 1; ++i)
204: command.append("?,");
205: command.append("?)");
206: PreparedStatement pstm = beanDest.getConnection().prepareStatement(command.toString());
207: System.out.println(command);
208: while ((row = bean.getNextRow()) != null)
209: {
210: //print rows
211: Object obj = null;
212: for (int k = 0; k < row.size(); ++k)
213: {
214: obj = row.get(k);
215: if (obj instanceof ArrayList)
1.55 rogo 216: obj = formatFileMakerArray((List) obj, "\n");
1.34 rogo 217: String str = (obj == null) ? "NULL" : obj.toString();
218: if (!str.equals("NULL"))
219: pstm.setString(k + 1, str);
220: else
221: pstm.setNull(k + 1, Types.NULL);
222: }
223: pstm.execute();
224:
225: } // to for loop
226:
227: }
228: } catch (Exception e)
229: {
230: System.out.println("Error while connecting to database " + e);
231: //dialog.setVisible(false);
232: //dialog.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
233: //FM2SQL.fmInstance.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
234: java.io.ByteArrayOutputStream b = new java.io.ByteArrayOutputStream();
235: java.io.PrintStream stream = new java.io.PrintStream(b);
236: stream.print(command + "\n\n");
237: e.printStackTrace(stream);
238: System.err.println(b);
239: //FM2SQL.showErrorDialog(b.toString(), "Error occured !");
240:
1.1 rogo 241: }
1.34 rogo 242: // dialog.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
243: //FM2SQL.fmInstance.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
1.1 rogo 244:
1.34 rogo 245: // dialog.setVisible(false);
1.1 rogo 246: }
1.55 rogo 247: public static String formatFileMakerArray(List list, String delimiter)
248: {
249: StringBuffer formattedString = new StringBuffer();
250: for (int i = 0; i < list.size(); ++i)
251: {
252: formattedString.append(list.get(i).toString());
253: if (i < list.size() - 1)
254: formattedString.append(delimiter);
255: }
256: return formattedString.toString();
257: }
1.38 rogo 258: /**
259: * Method for SQL UPDATE
260: * @param source
261: * @param destination
262: * @param names
263: * @param layouts
264: * @param selects
265: * @param creates
266: * @param ids
267: * @param mode
268: * @throws Exception
269: */
1.34 rogo 270: public static void update(String source, String destination, Vector names, Vector layouts, Vector selects, Vector creates, Vector ids, int mode) throws Exception
1.12 rogo 271: {
272: FM2SQL.ProgressDialog dialog = null;
273: if (FM2SQL.fmInstance != null)
274: {
1.55 rogo 275: dialog = new FM2SQL.ProgressDialog(FM2SQL.fmInstance, bean);
1.12 rogo 276: dialog.setTitle("Conversion running ...");
277: dialog.title.setText("Getting table data ...");
278: dialog.setLocation(FM2SQL.fmInstance.getLocationOnScreen().x + (FM2SQL.fmInstance.getWidth() - 400) / 2, FM2SQL.fmInstance.getLocationOnScreen().y + (FM2SQL.fmInstance.getHeight() - 250) / 2);
279: dialog.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
280: FM2SQL.fmInstance.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
281: dialog.thread = Thread.currentThread();
282: }
283: // setting user and passwd
284: bean.setUserAndPasswd(user, passwd);
285: // setting user and passwd
286: beanDest.setUserAndPasswd(userDest, passwdDest);
287: if (dialog != null)
288: dialog.setSize(400, 250);
289: StringBuffer command = null;
290: String query = null;
291: try
292: {
293: //bean.setConnection("jdbc:fmpro:http://141.14.237.74:8050");
294: //bean.setConnection("jdbc:postgresql://erebos/test","postgres","rogo");
295: bean.setConnection(source);
296: if (names == null)
297: names = bean.getTableNames();
298: // Collections.sort(names);
299: int tbIndex = 1;
1.55 rogo 300:
1.12 rogo 301: // System.out.println("Start at "+names.indexOf("archimedes_facsimiles"));
302: for (tbIndex = 0; tbIndex < names.size(); ++tbIndex)
303: {
304: Vector[] result = null;
1.45 rogo 305: String destTableName = "";
1.12 rogo 306: try
307: {
308: query = "select * from " + bean.getQC() + names.get(tbIndex).toString() + bean.getQC();
309: String layout = (layouts.isEmpty()) ? "" : layouts.get(tbIndex).toString();
310: query = (selects != null) ? selects.get(tbIndex).toString() : query;
311: //if vectors[1].get(i) != null)
312: if (layout != "")
313: {
314: layout = " layout " + bean.getQC() + layout + bean.getQC();
315: String name = names.get(tbIndex).toString();
316: StringBuffer queryLayout = new StringBuffer(query);
317: queryLayout.insert(queryLayout.indexOf(name) + name.length() + 1, " " + layout);
318: query = queryLayout.toString();
319: System.out.println("added layout " + query);
320:
321: }
322: dialog.title.setText("Getting table data ...");
323: dialog.table.setText(names.get(tbIndex).toString());
324: dialog.status.setText("Table " + (tbIndex + 1) + " of " + names.size());
325: dialog.show();
326: bean.getConnection();
327: bean.makeQuery(query, 0);
328: } catch (Exception e)
329: {
330: continue;
331: }
1.45 rogo 332: // determine destTableName from createStatement or from source table name
1.55 rogo 333: if (!creates.get(tbIndex).equals(""))
334: {
335: String create = creates.get(tbIndex).toString().toLowerCase();
336: int fromIndex = create.indexOf("table") + 5;
337: int toIndex = create.indexOf("(");
338: destTableName = create.substring(fromIndex, toIndex).replaceAll(beanDest.getQC(), "").trim();
339: System.out.println("destTable " + destTableName);
340:
341: } else
342: destTableName = convertText(names.get(tbIndex).toString());
1.45 rogo 343:
1.12 rogo 344: //beanDest.setConnection("jdbc:postgresql://erebos/test3");
345: beanDest.setConnection(destination);
346:
347: Statement stm = beanDest.getConnection().createStatement();
348:
349: Vector tables = beanDest.getTableNames();
350: // Collections.sort(tables);
351: System.out.println(names.get(tbIndex) + " " + tables.indexOf(convertText((String) names.get(tbIndex)))); // "//beanDest.getTypeNames());
352: tables = beanDest.getTableNames();
353: // System.out.println(beanDest.getTableNames(beanDest.getCatalogs().get(2).toString()));
354: stm = beanDest.getConnection().createStatement();
355: // System.exit(0);
1.34 rogo 356:
1.12 rogo 357: if (dialog != null)
1.36 rogo 358: dialog.title.setText("Updating table data ...");
1.12 rogo 359:
360: int j = -1;
1.34 rogo 361:
1.12 rogo 362: Vector row = null;
363: command = new StringBuffer();
364:
365: command.append("UPDATE ");
366: command.append(beanDest.getQC());
1.45 rogo 367: command.append(destTableName);
368: //command.append(convertText((String) names.get(tbIndex)));
1.12 rogo 369: command.append(beanDest.getQC());
370: command.append(" SET ");
371:
372: int size = bean.getColumnNames().size();
373: for (int i = 0; i < size - 1; ++i)
1.34 rogo 374: command.append(beanDest.getQC() + convertText((String) bean.getColumnNames().get(i)) + beanDest.getQC() + " = ? ,");
375: command.append(convertText((String) bean.getColumnNames().get(size - 1)) + " = ? ");
376: command.append("WHERE " + convertText(ids.get(tbIndex).toString()) + " = ?");
1.12 rogo 377: PreparedStatement pstm = beanDest.getConnection().prepareStatement(command.toString());
1.34 rogo 378: System.out.println(command + " " + tbIndex);
379: int rowCount = bean.getRowCount(query);
380: int idIndex = bean.getColumnNames().indexOf(ids.get(tbIndex));
1.12 rogo 381: while ((row = bean.getNextRow()) != null)
382: {
383: j++;
384: //print rows
385: Object obj = null;
386: /* for(int k=0;k<row.size()-1;++k)
387: {
388: obj = row.get(k);
389: //System.out.println("row "+obj+" "+k);
390: if(obj!=null&&!(obj instanceof ArrayList))
391: command.append("'"+convertUml(obj.toString())+"',");
392: else if(obj!=null&& obj instanceof ArrayList)
393: command.append("'"+convertUml(((ArrayList)obj).get(0).toString())+"',");
394: else command.append("NULL,");
395: }
396: obj = row.get(row.size() - 1);
397: if (obj != null && !(obj instanceof ArrayList))
398: command.append("'"+convertUml(obj.toString())+"')");
399: else
400: if(obj!=null&& obj instanceof ArrayList)
401: command.append("'"+convertUml(((ArrayList)obj).get(0).toString())+"')"); //command.append(obj.toString()+")");
402: else command.append("NULL)");
403: */
404: //command.append("'"+row.get(row.size()-1)+"')");
405: //command.append(" )");
406: // for(int k=0;k<row.size();++k)
407:
408: // System.out.println();
409: // System.out.println(command+" "+j+" "+row.size()+" "+ ((Vector)result2[0].get(j)).size());
410: // System.out.println(command);
411: for (int k = 0; k < row.size(); ++k)
412: {
413: obj = row.get(k);
414: if (obj instanceof ArrayList)
415: obj = ((List) obj).get(0);
416: String str = (obj == null) ? "NULL" : obj.toString();
417: if (!str.equals("NULL"))
418: pstm.setString(k + 1, str);
419: else
420: pstm.setNull(k + 1, Types.NULL);
421: }
1.34 rogo 422: pstm.setString(row.size() + 1, row.get(idIndex).toString());
423: //System.out.println(pstm.toString());
424: // System.exit(0);
1.12 rogo 425: pstm.execute();
426: //stm.executeUpdate(command.toString());
1.34 rogo 427: if (dialog != null)
428: dialog.progress.setValue((int) (((double) (j + 1) / (double) rowCount) * 100.0));
1.12 rogo 429: // System.out.println( (int)(((double)(j+1)/(double)result[0].size())*100.0)+" "+result[0].size()+" "+j);
430: command = null;
431: } // to for loop
432:
433: }
434: } catch (Exception e)
435: {
436: System.out.println("Error while connecting to database " + e);
1.18 rogo 437: if (dialog != null)
438: {
439: dialog.setVisible(false);
440: dialog.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
441: FM2SQL.fmInstance.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
442: }
1.12 rogo 443: java.io.ByteArrayOutputStream b = new java.io.ByteArrayOutputStream();
444: java.io.PrintStream stream = new java.io.PrintStream(b);
445: stream.print(command + "\n\n");
446: e.printStackTrace(stream);
447: FM2SQL.showErrorDialog(b.toString(), "Error occured !");
448:
449: }
1.18 rogo 450: if (dialog != null)
451: {
452: dialog.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
453: FM2SQL.fmInstance.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
454:
455: dialog.setVisible(false);
456: }
1.12 rogo 457:
458: }
1.34 rogo 459: /**
1.38 rogo 460: * transfers the specified array of tables to the destination database
461: and creates the table if it does not exist if it exists and mode is not append the table is dropped
1.55 rogo 462:
1.38 rogo 463: * @param source
464: * @param destination
465: * @param names
466: * @param layouts
467: * @param selects
468: * @param creates
469: * @param ids
470: * @param mode
471: * @throws Exception
1.55 rogo 472: */
473:
474: public static void convert(String source, String destination, Vector names, Vector layouts, Vector selects, Vector creates, Vector ids, int mode, String delimiter) throws Exception
1.1 rogo 475: {
1.34 rogo 476:
477: FM2SQL.ProgressDialog dialog = null;
478:
479: if (FM2SQL.fmInstance != null)
480: {
1.55 rogo 481: dialog = new FM2SQL.ProgressDialog(FM2SQL.fmInstance, bean);
1.34 rogo 482: dialog.setTitle("Conversion running ...");
483: dialog.title.setText("Getting table data ...");
484: dialog.setLocation(FM2SQL.fmInstance.getLocationOnScreen().x + (FM2SQL.fmInstance.getWidth() - 400) / 2, FM2SQL.fmInstance.getLocationOnScreen().y + (FM2SQL.fmInstance.getHeight() - 250) / 2);
485: dialog.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
486: FM2SQL.fmInstance.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
487: dialog.thread = Thread.currentThread();
488: dialog.setSize(400, 250);
489: }
490: java.util.TreeSet myIds = new TreeSet();
491: int deltaID = 1;
492: String idField = "";
1.38 rogo 493: String destTableName = "";
1.55 rogo 494: String[] fieldNames = null;
1.34 rogo 495: if (source != null && destination != null)
496: {
497: // setting user and passwd
498: bean.setUserAndPasswd(user, passwd);
499: // setting user and passwd
500: beanDest.setUserAndPasswd(userDest, passwdDest);
501: }
502: StringBuffer command = null;
503: String query = null;
1.1 rogo 504: try
505: {
1.55 rogo 506: if (source != null)
507: bean.setConnection(source);
1.34 rogo 508: else
1.55 rogo 509: bean.setConnection(bean.url);
510:
1.34 rogo 511: if (names == null)
512: names = bean.getTableNames();
513: // Collections.sort(names);
514: int tbIndex = 1;
515:
516: // System.out.println("Start at "+names.indexOf("archimedes_facsimiles"));
517: for (tbIndex = 0; tbIndex < names.size(); ++tbIndex)
1.1 rogo 518: {
519: Vector[] result = null;
1.34 rogo 520: try
1.1 rogo 521: {
1.34 rogo 522: query = "select * from " + bean.getQC() + names.get(tbIndex).toString() + bean.getQC();
523: String layout = (layouts.isEmpty()) ? "" : layouts.get(tbIndex).toString();
524: query = (selects != null) ? selects.get(tbIndex).toString() : query;
525: //if vectors[1].get(i) != null)
526: if (layout != "")
527: {
528: layout = " layout " + bean.getQC() + layout + bean.getQC();
529: String name = names.get(tbIndex).toString();
530: StringBuffer queryLayout = new StringBuffer(query);
531: queryLayout.insert(queryLayout.indexOf(name) + name.length() + 1, " " + layout);
532: query = queryLayout.toString();
533: System.out.println("added layout " + query);
1.21 rogo 534:
1.34 rogo 535: }
536: // if ( layout!= "")
537: // query += " layout " + bean.getQC() + layout + bean.getQC();
538: if (dialog != null)
539: {
540: dialog.title.setText("Reading table data ...");
541: dialog.table.setText(names.get(tbIndex).toString());
542: dialog.status.setText("Table " + (tbIndex + 1) + " of " + names.size());
543: dialog.show();
544: }
545: //result = bean.getQueryData(query, dialog, 0);
546: bean.getConnection();
547: bean.makeQuery(query, 50);
548: idField = ids.get(tbIndex).toString();
549:
550: } catch (Exception e)
551: {
552: System.out.println(e);
553: continue;
1.1 rogo 554: }
1.55 rogo 555: if (destination != null)
556: beanDest.setConnection(destination);
1.34 rogo 557: else
1.55 rogo 558: beanDest.setConnection(beanDest.url);
1.1 rogo 559: Statement stm = beanDest.getConnection().createStatement();
560:
561: Vector tables = beanDest.getTableNames();
1.34 rogo 562: // Collections.sort(tables);
1.1 rogo 563: System.out.println(names.get(tbIndex) + " " + tables.indexOf(convertText((String) names.get(tbIndex)))); // "//beanDest.getTypeNames());
564: tables = beanDest.getTableNames();
565: // System.out.println(beanDest.getTableNames(beanDest.getCatalogs().get(2).toString()));
566: stm = beanDest.getConnection().createStatement();
567: // System.exit(0);
1.55 rogo 568:
569: // determine destTableName from createStatement or from source table name
570: if (!creates.get(tbIndex).equals(""))
1.45 rogo 571: {
1.55 rogo 572: String create = creates.get(tbIndex).toString().toLowerCase();
573: int fromIndex = create.indexOf("table") + 5;
574: int toIndex = create.indexOf("(");
575: int endIndex = create.indexOf(")", toIndex);
576:
577: destTableName = create.substring(fromIndex, toIndex).replaceAll(beanDest.getQC(), "").trim();
578: System.out.println("destTable " + destTableName);
579: // retrieve field_names from select statement
580: if (query.indexOf("*") < 0)
581: {
582: int selectEndIndex = query.indexOf("from");
583: StringTokenizer tokenizer = new StringTokenizer(query.substring(6, selectEndIndex), ",");
584: int numFields = tokenizer.countTokens();
585: fieldNames = new String[numFields];
586: int fieldIndex = 0;
587: while (tokenizer.hasMoreTokens())
588: {
589: String fieldName = tokenizer.nextToken().trim();
590: fieldNames[fieldIndex] = convertText(fieldName);
591: System.out.println(fieldNames[fieldIndex]);
592: fieldIndex++;
593: }
594:
595: } else
596: {
597: // use create statement for field names
598: StringTokenizer tokenizer = new StringTokenizer(create.substring(toIndex + 1, endIndex), ",");
599: int numFields = tokenizer.countTokens();
600: fieldNames = new String[numFields];
601: int fieldIndex = 0;
602: while (tokenizer.hasMoreTokens())
603: {
604: String fieldName = tokenizer.nextToken().trim();
605: int index = fieldName.lastIndexOf(" ");
606: fieldNames[fieldIndex] = fieldName.substring(0, index);
607: System.out.println(fieldNames[fieldIndex]);
608: fieldIndex++;
609: }
610: }
1.45 rogo 611: } else
1.55 rogo 612: {
1.45 rogo 613: destTableName = convertText(names.get(tbIndex).toString());
614:
1.55 rogo 615: // retrieve field_names from select statement
616: if (query.indexOf("*") < 0)
617: {
618: int selectEndIndex = query.indexOf("from");
619: StringTokenizer tokenizer = new StringTokenizer(query.substring(6, selectEndIndex), ",");
620: int numFields = tokenizer.countTokens();
621: fieldNames = new String[numFields];
622: int fieldIndex = 0;
623: while (tokenizer.hasMoreTokens())
624: {
625: String fieldName = tokenizer.nextToken().trim();
626: fieldNames[fieldIndex] = convertText(fieldName);
627: // System.out.println("field "+ fieldNames[fieldIndex]);
628: fieldIndex++;
629: }
630:
631: } else
632: {
633: Vector fieldNamesVec = bean.getColumnNames();
634: fieldNames = new String[fieldNamesVec.size()];
635: int fieldIndex = -1;
636: for (Iterator iter = fieldNamesVec.iterator(); iter.hasNext();)
637: {
638: String element = (String) iter.next();
639: fieldNames[++fieldIndex] = bean.getQC() + convertText(element) + bean.getQC();
640: // System.out.println("field " + fieldNames[fieldIndex]);
641: }
642: }
643: }
1.34 rogo 644: if (mode == Convert.DataBase.CONVERT_MODE)
1.1 rogo 645: {
1.38 rogo 646:
647: if (tables.indexOf(destTableName) >= 0)
648: {
649: stm.executeUpdate("drop table " + beanDest.getQC() + destTableName + beanDest.getQC());
650: tables.remove(destTableName);
651: System.out.println("dropped table" + destTableName);
652:
653: }
654: /*
655: if(destTableName.equals(""))
1.34 rogo 656: if (tables.indexOf(names.get(tbIndex)) >= 0)
657: {
658: stm.executeUpdate("drop table " + beanDest.getQC() + names.get(tbIndex) + beanDest.getQC());
659: tables.remove((String) names.get(tbIndex));
660: System.out.println("dropped table" + names.get(tbIndex));
661: } else if (tables.indexOf(convertText(names.get(tbIndex).toString())) >= 0)
1.1 rogo 662: {
1.34 rogo 663: stm.executeUpdate("drop table " + beanDest.getQC() + convertText((String) names.get(tbIndex)) + beanDest.getQC());
664: tables.remove(convertText((String) names.get(tbIndex)));
665: System.out.println("dropped table" + names.get(tbIndex));
666: }
1.55 rogo 667: */
1.38 rogo 668: if ((tables.indexOf(destTableName) < 0)) //&& tables.indexOf(names.get(tbIndex)) < 0 && tables.indexOf(convertText(names.get(tbIndex).toString())) < 0 )
1.1 rogo 669: {
1.55 rogo 670:
1.34 rogo 671: if (creates.get(tbIndex).equals("") || creates.get(tbIndex).toString().toLowerCase().indexOf("create") < 0)
672: {
673: System.out.println("Warning empty or invalid create statement - creating one for you\n");
674:
675: command = new StringBuffer(50);
676: command.append("CREATE TABLE ");
677: command.append(beanDest.getQC());
678: command.append(convertText((String) names.get(tbIndex)));
679: command.append(beanDest.getQC());
680: command.append("(");
681: String type = null;
682: Vector columnNames = bean.getColumnNames();
683: for (int i = 0; i < columnNames.size() - 1; ++i)
684: {
685: type = bean.metaData.getColumnTypeName(i + 1);
686: // System.out.println(i+" "+result[1].get(i)+" "+type);
687: type = (type.equals("NUMBER")) ? "INT4" : type;
688: type = (type.equals("CONTAINER")) ? "TEXT" : type;
689:
690: command.append(beanDest.getQC() + convertText((String) columnNames.get(i)) + beanDest.getQC() + " " + type + ", ");
691: }
692: type = bean.metaData.getColumnTypeName(columnNames.size());
693: type = (type.equals("NUMBER")) ? "INT4" : type;
694: type = (type.equals("CONTAINER")) ? "TEXT" : type;
695: command.append(beanDest.getQC() + convertText((String) columnNames.get(columnNames.size() - 1)) + beanDest.getQC() + " " + type);
696: command.append(" )");
697:
698: // System.out.println(command);
699: // System.exit(0);
700: //command.append(DBBean.getQC());
701: } else
1.38 rogo 702: command = new StringBuffer().append(creates.get(tbIndex).toString().toLowerCase());
1.34 rogo 703: stm.executeUpdate(command.toString());
1.1 rogo 704:
1.34 rogo 705: }
1.1 rogo 706: }
1.55 rogo 707: if (dialog != null)
708: dialog.title.setText("Writing table data ...");
1.34 rogo 709:
710: // prepare the insert statement
711: int j = -1;
712: Vector row = null;
713: command = new StringBuffer();
714:
715: command.append("INSERT INTO ");
716: command.append(beanDest.getQC());
1.38 rogo 717: command.append(destTableName); //convertText((String) names.get(tbIndex)));
1.34 rogo 718: command.append(beanDest.getQC());
1.55 rogo 719: command.append(" (");
720: for (int i = 0; i < fieldNames.length; i++)
721: {
722: command.append(fieldNames[i]);
723: if (i < fieldNames.length - 1)
724: command.append(",");
725: }
726: command.append(") ");
727:
1.34 rogo 728: command.append(" values ( ");
729:
1.38 rogo 730: // add a question marks for every field
1.34 rogo 731: for (int i = 0; i < bean.getColumnNames().size() - 1; ++i)
732: command.append("?,");
733: command.append("?)");
734: PreparedStatement pstm = beanDest.getConnection().prepareStatement(command.toString());
735: System.out.println(command);
736: int rowCount = (idField != "") ? myIds.size() : bean.getRowCount(query);
737: Vector vec = new Vector(myIds);
738: int endIndex = -1;
739: String tempQuery = query;
740: String tempID = bean.getQC() + idField + bean.getQC();
1.38 rogo 741: // if id_field not do incremental conversion else do it all at once
1.34 rogo 742: if (!idField.equals(""))
743: {
744: long startTime = System.currentTimeMillis();
745: int counter = -1;
746: while (true)
747: {
748: ++counter;
1.55 rogo 749: if (counter == 0 && dialog != null)
1.34 rogo 750: dialog.title.setText("Check if data is available");
1.55 rogo 751: else if (dialog != null)
1.34 rogo 752: dialog.title.setText("Check if more data is available");
753: myIds = bean.getIDVector(ids.get(tbIndex).toString(), (String) names.get(tbIndex), tempQuery, numHits);
754: if (myIds.isEmpty())
755: break;
756: vec = new Vector(myIds);
757: rowCount = vec.size();
758: System.out.println("ID LIST SIZE " + Math.round((double) myIds.size() / (double) numIntervalls) + " " + myIds.size());
759: deltaID = (int) Math.round((double) myIds.size() / (double) numIntervalls);
760: if (vec.size() <= numIntervalls)
761: {
762: endIndex = 0;
763: deltaID = vec.size();
764: }
765: for (int k = 0; k < vec.size() - deltaID; k = k + deltaID)
766: {
767: System.out.println(vec.get(k) + " " + vec.get(k + deltaID) + " " + vec.lastElement());
768: if (query.indexOf("where") > 0)
1.55 rogo 769: tempQuery = query + " and " + tempID + ">='" + vec.get(k) + "' and " + tempID + "<='" + vec.get(k + deltaID) + "'";
1.34 rogo 770: else
1.55 rogo 771: tempQuery = query + " where " + tempID + ">='" + vec.get(k) + "' and " + tempID + "<='" + vec.get(k + deltaID) + "'";
1.34 rogo 772: System.out.println(tempQuery);
1.55 rogo 773: if (dialog != null)
774: dialog.title.setText("Reading table data ...");
1.34 rogo 775:
776: bean.makeQuery(tempQuery, deltaID);
1.55 rogo 777: if (dialog != null)
778: dialog.title.setText("Writing table data ...");
1.34 rogo 779:
1.55 rogo 780: command = writeDatainDestTable(dialog, command, k, pstm, rowCount, delimiter);
1.34 rogo 781: endIndex = k + deltaID;
782: }
783: System.out.println(endIndex);
1.38 rogo 784: //all data written ? if not write last chunk of data
1.34 rogo 785: if (endIndex == vec.size() - 1)
786: System.out.println("fits");
787: else
788: {
789: System.out.println(" last intervall from " + vec.get(endIndex) + " " + vec.lastElement());
1.1 rogo 790:
1.34 rogo 791: if (query.indexOf("where") > 0)
1.55 rogo 792: tempQuery = query + " and " + tempID + ">='" + vec.get(endIndex) + "' and " + tempID + "<='" + vec.lastElement() + "'";
1.34 rogo 793: else
1.55 rogo 794: tempQuery = query + " where " + tempID + ">='" + vec.get(endIndex) + "' and " + tempID + "<='" + vec.lastElement() + "'";
1.34 rogo 795: System.out.println(tempQuery);
1.55 rogo 796: if (dialog != null)
797: dialog.title.setText("Reading table data ...");
1.34 rogo 798: bean.makeQuery(tempQuery, 0);
1.55 rogo 799: if (dialog != null)
800: dialog.title.setText("Writing table data ...");
801: command = writeDatainDestTable(dialog, command, endIndex, pstm, rowCount, delimiter);
1.34 rogo 802: }
1.38 rogo 803: // prepare new query for next chunk
1.34 rogo 804: if (query.indexOf("where") > 0)
1.55 rogo 805: tempQuery = query + " and " + tempID + ">'" + vec.lastElement() + "'";
1.34 rogo 806: else
1.55 rogo 807: tempQuery = query + " where " + tempID + ">'" + vec.lastElement() + "'";
1.34 rogo 808:
809: }
810: long endTime = System.currentTimeMillis();
811: System.out.println("Time for incremental convert elapsed " + (endTime - startTime));
812: } else
1.29 rogo 813: {
1.38 rogo 814: // read and write all in one big chunk
1.34 rogo 815: long startTime = System.currentTimeMillis();
1.55 rogo 816:
1.34 rogo 817: bean.makeQuery(query, 0);
1.55 rogo 818: command = writeDatainDestTable(dialog, command, j, pstm, rowCount, delimiter);
1.34 rogo 819: long endTime = System.currentTimeMillis();
820: System.out.println("Time for old convert elapsed " + (endTime - startTime));
1.29 rogo 821:
822: }
1.34 rogo 823: }
824: } catch (Exception e)
825: {
826: System.out.println("Error while connecting to database " + e);
827: if (dialog != null)
828: {
829: dialog.setVisible(false);
830: dialog.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
831: FM2SQL.fmInstance.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
832: java.io.ByteArrayOutputStream b = new java.io.ByteArrayOutputStream();
833: java.io.PrintStream stream = new java.io.PrintStream(b);
834: stream.print(command + "\n\n");
835: e.printStackTrace(stream);
836: FM2SQL.showErrorDialog(b.toString(), "Error occured !");
837: } else
838: {
839: e.printStackTrace();
1.33 rogo 840:
1.3 rogo 841: }
1.1 rogo 842: }
1.34 rogo 843: if (dialog != null)
844: {
845: dialog.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
846: FM2SQL.fmInstance.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
847: dialog.setVisible(false);
848: }
1.27 rogo 849: }
1.38 rogo 850: /**
851: * Writes data to the destination table
852: * @param dialog progress dialog
853: * @param command
854: * @param j data index for progress bar
855: * @param pstm prepared statement
856: * @param rowCount number of datasets
857: * @return command
858: * @throws Exception
859: * @throws SQLException
860: */
1.55 rogo 861: private static StringBuffer writeDatainDestTable(FM2SQL.ProgressDialog dialog, StringBuffer command, int j, PreparedStatement pstm, int rowCount, String delimiter) throws Exception, SQLException
1.27 rogo 862: {
863: Vector row;
1.34 rogo 864: while ((row = bean.getNextRow()) != null)
865: {
866: j++;
867: // row = (Vector) result[0].get(j);
868: /* command = new StringBuffer();
869:
870: command.append("INSERT INTO ");
871: command.append(beanDest.getQC());
872: command.append(convertText((String) names.get(tbIndex)));
873: command.append(beanDest.getQC());
874: command.append(" values ( ");
875: */
876: //print rows
877: Object obj = null;
878: /* for(int k=0;k<row.size()-1;++k)
879: {
880: obj = row.get(k);
881: //System.out.println("row "+obj+" "+k);
882: if(obj!=null&&!(obj instanceof ArrayList))
883: command.append("'"+convertUml(obj.toString())+"',");
884: else if(obj!=null&& obj instanceof ArrayList)
885: command.append("'"+convertUml(((ArrayList)obj).get(0).toString())+"',");
886: else command.append("NULL,");
887: }
888: obj = row.get(row.size() - 1);
889: if (obj != null && !(obj instanceof ArrayList))
890: command.append("'"+convertUml(obj.toString())+"')");
891: else
892: if(obj!=null&& obj instanceof ArrayList)
893: command.append("'"+convertUml(((ArrayList)obj).get(0).toString())+"')"); //command.append(obj.toString()+")");
894: else command.append("NULL)");
895: */
896: //command.append("'"+row.get(row.size()-1)+"')");
897: //command.append(" )");
898: // for(int k=0;k<row.size();++k)
899:
900: // System.out.println();
901: // System.out.println(command+" "+j+" "+row.size()+" "+ ((Vector)result2[0].get(j)).size());
902: // System.out.println(command);
903: for (int k = 0; k < row.size(); ++k)
904: {
905: obj = row.get(k);
1.55 rogo 906:
907: if (obj instanceof ArrayList)
908: obj = formatFileMakerArray((List) obj, delimiter);
909:
1.34 rogo 910: String str = (obj == null) ? "NULL" : obj.toString();
1.55 rogo 911: if (obj instanceof Double)
912: {
913: pstm.setDouble(k + 1, ((Double) obj).doubleValue());
914: } else if (!str.equals("NULL"))
1.34 rogo 915: pstm.setString(k + 1, str);
916: else
917: pstm.setNull(k + 1, Types.NULL);
918: }
919: pstm.execute();
920: //stm.executeUpdate(command.toString());
921: if (dialog != null)
922: dialog.progress.setValue((int) (((double) (j + 1) / (double) rowCount) * 100.0));
923: // System.out.println( (int)(((double)(j+1)/(double)result[0].size())*100.0)+" "+result[0].size()+" "+j);
924: command = null;
925: } // to while loop
1.27 rogo 926: return command;
1.1 rogo 927: }
928:
1.38 rogo 929: /**
930: * removes special characters from the input string as well as .fp5
931: * @param newName String to change
932: * @return
933: */
1.34 rogo 934: public static String convertText(String newName)
1.1 rogo 935: {
936: StringBuffer alterMe = new StringBuffer(newName.trim().toLowerCase());
937: int length = alterMe.length();
938: int j = 0;
1.34 rogo 939: int index = alterMe.indexOf(".fp5");
940: if (index >= 0)
941: {
942: alterMe.delete(index, index + 4);
943: length = length - 4;
944: }
945:
1.1 rogo 946: while (j < length)
1.34 rogo 947: {
1.1 rogo 948: if (alterMe.charAt(j) == ' ')
949: {
950: alterMe.setCharAt(j, '_');
1.34 rogo 951: // if(j<length-1) j=j+1;
952: } else if (alterMe.charAt(j) == '_')
953: {
954:
955: if (alterMe.charAt(j + 1) == '_')
956: alterMe.deleteCharAt(j);
957: length = length - 1;
958: // if(j<length-1) j=j+1;
959: } else if (alterMe.charAt(j) == 'ä')
960: {
961: alterMe.setCharAt(j, 'a');
962: alterMe.insert(j + 1, "e");
963: length = length + 1;
964: if (j < length - 1)
965: j = j + 1;
966: } else if (alterMe.charAt(j) == 'ö')
967: {
968: alterMe.setCharAt(j, 'o');
969: alterMe.insert(j + 1, "e");
970: length = length + 1;
971: if (j < length - 1)
972: j = j + 1;
973: } else if (alterMe.charAt(j) == 'ü')
974: {
975: alterMe.setCharAt(j, 'u');
976: alterMe.insert(j + 1, "e");
977: length = length + 1;
978: if (j < length - 1)
979: j = j + 1;
980: } else if (alterMe.charAt(j) == 'ß')
981: {
982: alterMe.setCharAt(j, 's');
983: alterMe.insert(j + 1, "s");
984: length = length + 1;
985: if (j < length - 1)
986: j = j + 1;
987: } else if (alterMe.charAt(j) == ':')
1.1 rogo 988: {
1.34 rogo 989: if (j < length - 1)
990: {
991: if (alterMe.charAt(j + 1) == ':')
992: {
993: alterMe.setCharAt(j, '_');
994: alterMe.delete(j + 1, j + 2);
995: length = length - 1;
996:
997: }
1.1 rogo 998:
1.34 rogo 999: if (j < length - 1)
1000: j = j + 1;
1001: }
1002: } else if (alterMe.charAt(j) == '-')
1003: {
1004: alterMe.setCharAt(j, '_');
1.16 rogo 1005:
1.34 rogo 1006: } else if (alterMe.charAt(j) == '?')
1.3 rogo 1007: {
1.34 rogo 1008: // changed ? to _ because of update statement
1009: alterMe.setCharAt(j, '_');
1010: // length = length + 1;
1011: // j=j+1;
1012: System.out.println(alterMe);
1013: } else if (alterMe.charAt(j) == '.')
1014: {
1015: if (j == length - 1)
1016: {
1017: alterMe.delete(j, j);
1018: length--;
1019: } else
1020: alterMe.setCharAt(j, '_');
1.3 rogo 1021: }
1.34 rogo 1022:
1023: ++j;
1.1 rogo 1024: }
1025: return alterMe.toString();
1026: }
1.38 rogo 1027: /**
1028: * Converts > and < in an entity (> or <)
1029: * @param newName
1030: * @return
1031: */
1.4 rogo 1032: public static String convertToEntities(String newName)
1033: {
1034: StringBuffer alterMe = new StringBuffer(newName.trim());
1035: int length = alterMe.length();
1036: int j = 0;
1037:
1038: while (j < length)
1039: {
1040:
1041: if (alterMe.charAt(j) == '>')
1042: {
1043: alterMe.setCharAt(j, '&');
1044: alterMe.insert(j + 1, "gt;");
1045: length = length + 2;
1046: if (j < length - 1)
1047: j = j + 1;
1048:
1049: } else if (alterMe.charAt(j) == '<')
1050: {
1051: alterMe.setCharAt(j, '&');
1052: alterMe.insert(j + 1, "lt;");
1053: length = length + 2;
1054: if (j < length - 1)
1055: j = j + 1;
1056:
1057: }
1058: ++j;
1059: }
1060: return alterMe.toString();
1061: }
1.38 rogo 1062: /**
1063: * Masks the single quote character '-->\'
1064: * @param newName
1065: * @return
1066: */
1.1 rogo 1067: public static String convertUml(String newName)
1.34 rogo 1068: {
1069: StringBuffer alterMe = new StringBuffer(newName.trim());
1070: int length = alterMe.length();
1071: int j = 0;
1072:
1073: while (j < length)
1074: {
1075:
1076: if (alterMe.charAt(j) == '\'')
1077: {
1078: alterMe.setCharAt(j, '\\');
1079: alterMe.insert(j + 1, "'");
1080: length = length + 1;
1081: if (j < length - 1)
1082: j = j + 1;
1083: }
1084: /* else
1085: if (alterMe.charAt(j) == '"')
1086: {
1087: alterMe.setCharAt(j, '\\');
1088: alterMe.insert(j + 1, "\"");
1089: length = length + 1;
1090: if(j<length-1) j=j+1;
1091: }
1092: else
1093: if (alterMe.charAt(j) == '>')
1094: {
1095: alterMe.setCharAt(j, '\\');
1096: alterMe.insert(j + 1, ">");
1097: length = length + 1;
1098: if(j<length-1) j=j+1;
1099: }
1100: else
1101: if (alterMe.charAt(j) == '<')
1102: {
1103: alterMe.setCharAt(j, '\\');
1104: alterMe.insert(j + 1, "<");
1105: length = length + 1;
1106: if(j<length-1) j=j+1;
1107: }
1108: else
1109: if (alterMe.charAt(j) == '?')
1110: {
1111: alterMe.setCharAt(j, '\\');
1112: alterMe.insert(j + 1, "?");
1113: length = length + 1;
1114: if(j<length-1) j=j+1;
1115: }
1116: else
1117: if (alterMe.charAt(j) == '&')
1118: {
1119: alterMe.setCharAt(j, '\\');
1120: alterMe.insert(j + 1, "&");
1121: length = length + 1;
1122: if(j<length-1) j=j+1;
1123: }
1124: else
1125: if (alterMe.charAt(j) == '=')
1126: {
1127: alterMe.setCharAt(j, '\\');
1128: alterMe.insert(j + 1, "=");
1129: length = length + 1;
1130: if(j<length-1) j=j+1;
1131: }
1132: else
1133: if (alterMe.charAt(j) == ',')
1134: {
1135: alterMe.setCharAt(j, '\\');
1136: alterMe.insert(j + 1, ",");
1137: length = length + 1;
1138: if(j<length-1) j=j+1;
1139: }
1140: else
1141: if (alterMe.charAt(j) == '.')
1142: {
1143: alterMe.setCharAt(j, '\\');
1144: alterMe.insert(j + 1, ".");
1145: length = length + 1;
1146: if(j<length-1) j=j+1;
1147: }
1148: else
1149: if (alterMe.charAt(j) == '[')
1150: {
1151: alterMe.setCharAt(j, '\\');
1152: alterMe.insert(j + 1, ".");
1153: length = length + 1;
1154: if(j<length-1) j=j+1;
1155: }
1156: else
1157: if (alterMe.charAt(j) == ']')
1158: {
1159: alterMe.setCharAt(j, '\\');
1160: alterMe.insert(j + 1, ".");
1161: length = length + 1;
1162: if(j<length-1) j=j+1;
1163: }
1164: else
1165: if (alterMe.charAt(j) == '%')
1166: {
1167: alterMe.setCharAt(j, '\\');
1168: alterMe.insert(j + 1, "%");
1169: length = length + 1;
1170: if(j<length-1) j=j+1;
1171: }*/
1172: ++j;
1173: }
1174: return alterMe.toString();
1175: }
1.55 rogo 1176: /**
1177: * parses the input xml file for batch conversion
1178: * called from readXMLFile
1179: * * @param sb
1180: */
1.34 rogo 1181: public static void parseXMLConfig(StringBuffer sb)
1182: {
1183: boolean finished = false;
1184: // parse string and build document tree
1185: Xparse parser = new Xparse();
1186: parser.changeEntities = true;
1187: Node root = parser.parse(sb.toString());
1188: // printContents(root);
1189: Vector databases = new Vector();
1190: Vector tables = new Vector();
1191: Vector layouts = new Vector();
1192: Vector selects = new Vector();
1193: Vector creates = new Vector();
1194: Vector ids = new Vector();
1.42 rogo 1195: String delimiter = "|";
1.34 rogo 1196: int mode = -1;
1197:
1198: try
1.1 rogo 1199: {
1.34 rogo 1200: Node tempNode = root.find("convert/source", new int[] { 1, 1 });
1201: if (tempNode == null)
1202: throw new Error("parse error source tag missing");
1203: System.out.println(tempNode.name);
1204: int length = countNodes(tempNode);
1205: for (int i = 1; i <= length; i++)
1.1 rogo 1206: {
1.34 rogo 1207:
1.1 rogo 1208: DBBean database = new DBBean();
1.34 rogo 1209: tables = new Vector();
1210: layouts = new Vector();
1211: selects = new Vector();
1212: creates = new Vector();
1213: ids = new Vector();
1.1 rogo 1214: // parse dataBase
1.34 rogo 1215: Node node = root.find("convert/source/database/url", new int[] { 1, 1, i, 1 });
1216: Node node1 = root.find("convert/source/database/user", new int[] { 1, 1, i, 1, 1 });
1217: Node node2 = root.find("convert/source/database/password", new int[] { 1, 1, i, 1, 1 });
1218: Node node3 = root.find("convert/source/database", new int[] { 1, 1, i });
1219: Node nodeMode = root.find("convert/source/database/mode", new int[] { 1, 1, i, 1, 1 });
1.55 rogo 1220: Node delimiterNode = root.find("convert/source/database/delimiter", new int[] { 1, 1, i, 1, 1 });
1.59 ! rogo 1221: Node useNormanToUnicodeMapper = root.find("convert/source/database/usenormantounicodemapper", new int[] { 1, 1, i, 1, 1 });
! 1222:
1.34 rogo 1223: if (node3 == null)
1224: throw new Error("parse error database tag missing");
1225: if (node == null)
1226: throw new Error("parse error url tag missing");
1227: if (node1 == null)
1228: throw new Error("parse error user tag missing");
1229: if (node2 == null)
1230: throw new Error("parse error password tag missing");
1.55 rogo 1231: if (delimiterNode != null)
1232: delimiter = delimiterNode.getCharacters();
1.59 ! rogo 1233: if(useNormanToUnicodeMapper!=null)
! 1234: {
! 1235: database.setUseNormanToUnicodeMapper(Boolean.valueOf(useNormanToUnicodeMapper.getCharacters()).booleanValue());
! 1236: System.out.println("useMapper "+Boolean.valueOf(useNormanToUnicodeMapper.getCharacters().trim()).booleanValue());
! 1237: }
! 1238:
1.1 rogo 1239: String url = node.getCharacters();
1240: String user = node1.getCharacters();
1241: String password = node2.getCharacters();
1242: database.setURL(url.trim());
1243: database.setUserAndPasswd(user.trim(), password.trim());
1.34 rogo 1244: System.out.println(node.name + " " + node.getCharacters());
1245: System.out.println(node1.name + " " + node1.getCharacters());
1246: System.out.println(node2.name + " " + node2.getCharacters());
1247: String modeString = "";
1248: if (nodeMode == null)
1249: modeString = "convert";
1250: else
1251: modeString = nodeMode.getCharacters();
1252: if (modeString.equals("convert"))
1253: mode = DataBase.CONVERT_MODE;
1254: else if (modeString.equals("append"))
1255: mode = DataBase.APPEND_MODE;
1256: else if (modeString.equals("update"))
1257: mode = DataBase.UPDATE_MODE;
1.48 rogo 1258: else if (modeString.equals("delete"))
1259: mode = DataBase.DELETE_MODE;
1260:
1.34 rogo 1261: // if(node3!=null)
1262: // System.out.println(node3.name);
1263:
1264: int length2 = countNodes(node3);
1265:
1266: System.out.println("number of tables " + length2);
1267:
1268: for (int j = 1; j <= length2; ++j)
1269: {
1270: Node node4 = root.find("convert/source/database/table", new int[] { 1, 1, i, j });
1271: Node node5 = root.find("convert/source/database/table/select", new int[] { 1, 1, i, j, 1 });
1272: Node node6 = root.find("convert/source/database/table/create", new int[] { 1, 1, i, j, 1 });
1273: if (node4 != null)
1274: System.out.println(node4.name + " " + node4.attributes.get("layout").equals(""));
1275: if (node5 != null)
1276: System.out.println(node5.name + " " + node5.getCharacters());
1277: if (node6 != null)
1278: System.out.println(node6.name + " " + node6.getCharacters());
1279: if (node4 == null)
1280: throw new Error("parse error table tag missing");
1281: // if(node5==null) throw new Error("parse error select tag missing");
1282: // if(node6==null) throw new Error("parse error create tag missing");
1283: String name = (String) node4.attributes.get("name");
1284: String layout = (String) node4.attributes.get("layout");
1285: String id = (String) node4.attributes.get("id");
1286: System.out.println("id was " + id);
1287: if (name == null)
1288: throw new Error("parse error required table tag attribute name missing");
1289: if (layout == null)
1290: layout = "";
1291: if (id == null)
1292: id = "";
1293: if (name.equals(""))
1294: throw new Error("parse error table tag attribute must not be empty");
1295: tables.add(name);
1296: layouts.add(layout);
1297: ids.add(id);
1298: String query = (node5 == null) ? "" : node5.getCharacters();
1299: if (query.equals(""))
1300: System.err.println("Warning empty select tag or select tag missing !!");
1301: query = (query.equals("")) ? "select * from " + database.getQC() + name + database.getQC() : query;
1302: selects.add(query);
1303: if (node6 != null)
1304: creates.add(node6.getCharacters().trim());
1305: else
1306: creates.add("");
1307:
1308: }
1.42 rogo 1309: DataBase dataBase = new DataBase(database, tables, layouts, selects, creates, ids, mode);
1310: dataBase.delimiter = delimiter;
1311: databases.add(dataBase);
1.34 rogo 1312: }
1313: DBBean database = new DBBean();
1314: // parse dataBase
1315: Node node = root.find("convert/destination/database/url", new int[] { 1, 1, 1, 1 });
1316: Node node1 = root.find("convert/destination/database/user", new int[] { 1, 1, 1, 1, 1 });
1317: Node node2 = root.find("convert/destination/database/password", new int[] { 1, 1, 1, 1, 1 });
1318: String url = node.getCharacters();
1319: String user = node1.getCharacters();
1320: String password = node2.getCharacters();
1321: System.out.println(url);
1322: database.setURL(url.trim());
1323: database.setUserAndPasswd(user.trim(), password.trim());
1324: //databases.add(database);
1325: for (Iterator iter = databases.iterator(); iter.hasNext();)
1.1 rogo 1326: {
1327: DataBase db = (DataBase) iter.next();
1.34 rogo 1328: if (mode != DataBase.UPDATE_MODE)
1.55 rogo 1329: convertBatch(db.bean, database, db.tables, db.layouts, db.selects, db.creates, db.ids, mode, db.delimiter);
1.17 rogo 1330: else
1.34 rogo 1331: update(db.bean.url, database.url, db.tables, db.layouts, db.selects, db.creates, db.ids, mode);
1.17 rogo 1332:
1.1 rogo 1333: }
1.34 rogo 1334: // printContents(node3);
1335: // FM2SQL.fmInstance=new FM2SQL();
1336: } catch (Exception e)
1337: {
1.55 rogo 1338:
1.34 rogo 1339: e.printStackTrace();
1340: }
1341: }
1342: public static Vector getXMLConfig(String xmlFile)
1343: {
1344: StringBuffer sb = null;
1345: try
1346: {
1347: // read XML Metadata from a file
1348: FileInputStream fi = new FileInputStream(xmlFile);
1349: InputStreamReader isr = new InputStreamReader(fi, "UTF-8");
1350: BufferedReader buffr = new BufferedReader(isr);
1351: sb = new StringBuffer();
1352: int c = 0;
1353: while ((c = buffr.read()) != -1)
1354: {
1355: char ch = (char) c;
1356: sb.append(ch);
1357: // System.out.print((char)c);
1.1 rogo 1358: }
1359:
1.34 rogo 1360: } catch (Exception e)
1361: {
1362: e.printStackTrace();
1363: }
1364:
1365: boolean finished = false;
1366: // parse string and build document tree
1367: Xparse parser = new Xparse();
1368: parser.changeEntities = true;
1369: Node root = parser.parse(sb.toString());
1370: // printContents(root);
1371: Vector databases = new Vector();
1372: Vector tables = new Vector();
1373: Vector layouts = new Vector();
1374: Vector selects = new Vector();
1375: Vector creates = new Vector();
1376: Vector ids = new Vector();
1.55 rogo 1377: String delimiter = "|";
1.34 rogo 1378: int mode = -1;
1379: try
1.1 rogo 1380: {
1.34 rogo 1381: Node tempNode = root.find("convert/source", new int[] { 1, 1 });
1382: if (tempNode == null)
1383: throw new Error("parse error source tag missing");
1384: System.out.println(tempNode.name);
1385: int length = countNodes(tempNode);
1386: for (int i = 1; i <= length; i++)
1.1 rogo 1387: {
1.34 rogo 1388:
1389: DBBean database = new DBBean();
1390: tables = new Vector();
1391: layouts = new Vector();
1392: selects = new Vector();
1393: creates = new Vector();
1394: ids = new Vector();
1395: // parse dataBase
1396: Node node = root.find("convert/source/database/url", new int[] { 1, 1, i, 1 });
1397: Node node1 = root.find("convert/source/database/user", new int[] { 1, 1, i, 1, 1 });
1398: Node node2 = root.find("convert/source/database/password", new int[] { 1, 1, i, 1, 1 });
1399: Node node3 = root.find("convert/source/database", new int[] { 1, 1, i });
1400: Node nodeMode = root.find("convert/source/database/mode", new int[] { 1, 1, i, 1, 1 });
1.55 rogo 1401: Node delimiterNode = root.find("convert/source/database/delimiter", new int[] { 1, 1, i, 1, 1 });
1.59 ! rogo 1402: Node useNormanToUnicodeMapper = root.find("convert/source/database/usenormantounicodemapper", new int[] { 1, 1, i, 1, 1 });
1.55 rogo 1403:
1.44 rogo 1404: if (delimiterNode != null)
1405: delimiter = delimiterNode.getCharacters();
1.59 ! rogo 1406: if(useNormanToUnicodeMapper!=null)
! 1407: {
! 1408: database.setUseNormanToUnicodeMapper(Boolean.valueOf(useNormanToUnicodeMapper.getCharacters()).booleanValue());
! 1409: System.out.println("useMapper "+Boolean.valueOf(useNormanToUnicodeMapper.getCharacters().trim()).booleanValue());
! 1410: }
! 1411:
1.34 rogo 1412: if (node3 == null)
1413: throw new Error("parse error database tag missing");
1414: if (node == null)
1415: throw new Error("parse error url tag missing");
1416: if (node1 == null)
1417: throw new Error("parse error user tag missing");
1418: if (node2 == null)
1419: throw new Error("parse error password tag missing");
1420: String url = node.getCharacters();
1421: String user = node1.getCharacters();
1422: String password = node2.getCharacters();
1423: database.setURL(url.trim());
1424: database.setUserAndPasswd(user.trim(), password.trim());
1425: System.out.println(node.name + " " + node.getCharacters());
1426: System.out.println(node1.name + " " + node1.getCharacters());
1427: System.out.println(node2.name + " " + node2.getCharacters());
1428: String modeString = "";
1429: if (nodeMode == null)
1430: modeString = "convert";
1431: else
1432: modeString = nodeMode.getCharacters();
1433: if (modeString.equals("convert"))
1434: mode = DataBase.CONVERT_MODE;
1435: else if (modeString.equals("append"))
1436: mode = DataBase.APPEND_MODE;
1437: else if (modeString.equals("update"))
1438: mode = DataBase.UPDATE_MODE;
1.48 rogo 1439: else if (modeString.equals("delete"))
1440: mode = DataBase.DELETE_MODE;
1441:
1.34 rogo 1442: // if(node3!=null)
1443: // System.out.println(node3.name);
1444:
1445: int length2 = countNodes(node3);
1446:
1447: System.out.println("number of tables " + length2);
1448:
1449: for (int j = 1; j <= length2; ++j)
1450: {
1451: Node node4 = root.find("convert/source/database/table", new int[] { 1, 1, i, j });
1452: Node node5 = root.find("convert/source/database/table/select", new int[] { 1, 1, i, j, 1 });
1453: Node node6 = root.find("convert/source/database/table/create", new int[] { 1, 1, i, j, 1 });
1454: if (node4 != null)
1455: System.out.println(node4.name + " " + node4.attributes.get("layout").equals(""));
1456: if (node5 != null)
1457: System.out.println(node5.name + " " + node5.getCharacters());
1458: if (node6 != null)
1459: System.out.println(node6.name + " " + node6.getCharacters());
1460: if (node4 == null)
1461: throw new Error("parse error table tag missing");
1462: // if(node5==null) throw new Error("parse error select tag missing");
1463: // if(node6==null) throw new Error("parse error create tag missing");
1464: String name = (String) node4.attributes.get("name");
1465: String layout = (String) node4.attributes.get("layout");
1466: String id = (String) node4.attributes.get("id");
1467: System.out.println("id was " + id);
1468:
1469: if (name == null)
1470: throw new Error("parse error required table tag attribute name missing");
1471: if (layout == null)
1472: layout = "";
1473: if (id == null)
1474: id = "";
1475: if (name.equals(""))
1476: throw new Error("parse error table tag attribute must not be empty");
1477: tables.add(name);
1478: layouts.add(layout);
1479: ids.add(id);
1480: String query = (node5 == null) ? "" : node5.getCharacters();
1481: if (query.equals(""))
1482: System.err.println("Warning empty select tag or select tag missing !!");
1483: query = (query.equals("")) ? "select * from " + database.getQC() + name + database.getQC() : query;
1484: selects.add(query);
1485: if (node6 != null)
1486: creates.add(node6.getCharacters().trim());
1487: else
1488: creates.add("");
1489:
1490: }
1.55 rogo 1491: DataBase dataBase = new DataBase(database, tables, layouts, selects, creates, ids, mode);
1492: dataBase.delimiter = delimiter;
1.43 rogo 1493: databases.add(dataBase);
1.1 rogo 1494: }
1.34 rogo 1495: DBBean database = new DBBean();
1496: // parse dataBase
1497: Node node = root.find("convert/destination/database/url", new int[] { 1, 1, 1, 1 });
1498: Node node1 = root.find("convert/destination/database/user", new int[] { 1, 1, 1, 1, 1 });
1499: Node node2 = root.find("convert/destination/database/password", new int[] { 1, 1, 1, 1, 1 });
1500: String url = node.getCharacters();
1501: String user = node1.getCharacters();
1502: String password = node2.getCharacters();
1503: System.out.println(url);
1504: database.setURL(url.trim());
1505: database.setUserAndPasswd(user.trim(), password.trim());
1506: databases.add(new DataBase(database, null, null, null, null, null, 0));
1507: //databases.add(database);
1508: /* for (Iterator iter = databases.iterator(); iter.hasNext();)
1509: {
1510: DataBase db = (DataBase) iter.next();
1511: convertBatch(db.bean,database,db.tables,db.layouts,db.selects,db.creates);
1512:
1513: }*/
1514: // printContents(node3);
1515: // FM2SQL.fmInstance=new FM2SQL();
1516: } catch (Exception e)
1517: {
1518: // TODO Auto-generated catch block
1519: e.printStackTrace();
1.1 rogo 1520: }
1.34 rogo 1521: return databases;
1522: }
1523:
1524: private static int countNodes(Node tempNode)
1525: {
1526: int length = 0;
1527: for (int i = 0; i < tempNode.contents.v.size(); ++i)
1.1 rogo 1528: {
1.34 rogo 1529: Node node = (Node) tempNode.contents.v.elementAt(i);
1530: if (node.type.equals("element"))
1.1 rogo 1531: {
1.34 rogo 1532: if (node.name.equals("database"))
1533: length++;
1534: if (node.name.equals("table"))
1535: length++;
1.1 rogo 1536: }
1.34 rogo 1537:
1538: // System.out.println(((Node)tempNode.contents.v.elementAt(i)).attributes+" "+i);
1.1 rogo 1539: }
1.34 rogo 1540: return length;
1541: }
1542: private static void printContents(Node root)
1543: {
1544:
1545: Vector contents = (root.index == null) ? root.contents.v : root.index.v;
1546: for (int i = 0; i < contents.size(); ++i)
1.1 rogo 1547: {
1.34 rogo 1548: Node n = (Node) contents.elementAt(i);
1549: if (n.type.equals("element"))
1550: {
1551: System.out.println("tag " + n.name);
1552: System.out.println(n.getCharacters());
1553: //contents=n.contents.v i=0;
1554: }
1555: // System.out.println(n.type);
1.1 rogo 1556: }
1.34 rogo 1557: }
1.38 rogo 1558: /**
1559: * reads the specified xml file
1560: * @param xmlFile
1561: */
1.34 rogo 1562: public static void readXMLFile(String xmlFile)
1.1 rogo 1563: {
1.34 rogo 1564: try
1565: {
1566: // read XML Metadata from a file
1567: FileInputStream fi = new FileInputStream(xmlFile);
1568: InputStreamReader isr = new InputStreamReader(fi, "UTF-8");
1569: BufferedReader buffr = new BufferedReader(isr);
1570: StringBuffer sb = new StringBuffer();
1571: int c = 0;
1572: while ((c = buffr.read()) != -1)
1573: {
1574: char ch = (char) c;
1575: sb.append(ch);
1576: // System.out.print((char)c);
1577: }
1578: parseXMLConfig(sb);
1579: } catch (Exception e)
1580: {
1581: e.printStackTrace();
1582: }
1.1 rogo 1583: }
1.55 rogo 1584:
1.38 rogo 1585: /**
1586: * Helper class for XML-File parsing
1587: * Holds the parsed data
1588: * @author rogo
1589: *
1590: */
1.34 rogo 1591: public static class DataBase
1592: {
1593: DBBean bean;
1594: Vector creates;
1595: Vector selects;
1596: Vector layouts;
1597: Vector tables;
1598: Vector ids;
1.43 rogo 1599: String delimiter = "//";
1.59 ! rogo 1600: boolean useNormanToUnicodeMapper = false;
! 1601:
1.34 rogo 1602: final static int CONVERT_MODE = 1;
1603: final static int APPEND_MODE = 2;
1604: final static int UPDATE_MODE = 3;
1.40 rogo 1605: final static int DELETE_MODE = 4;
1606:
1.34 rogo 1607: int mode = -1;
1608:
1609: public DataBase(DBBean bean, Vector tables, Vector layouts, Vector selects, Vector creates, Vector ids, int mode)
1610: {
1611: this.bean = bean;
1612: this.tables = tables;
1613: this.layouts = layouts;
1614: this.selects = selects;
1615: this.creates = creates;
1616: this.ids = ids;
1617: this.mode = mode;
1618: this.bean.setIDVector(ids);
1619: }
1.38 rogo 1620: /**
1.42 rogo 1621: * writes the data contained in this object to the buffered writer
1.38 rogo 1622: * * @param buffr
1623: * @throws Exception
1624: */
1.34 rogo 1625: public void exportToXML(BufferedWriter buffr) throws Exception
1626: {
1627: // ids=bean.getIDVector();
1628: buffr.write(" <database>\n");
1629: buffr.write(" <url>" + bean.url + "</url>\n");
1630: buffr.write(" <user>" + bean.user + "</user>\n");
1631: buffr.write(" <password>" + bean.passwd + "</password>\n");
1.55 rogo 1632: buffr.write(" <delimiter>" + delimiter + "</delimiter>\n");
1.34 rogo 1633: String modeString = "";
1634: if (mode == CONVERT_MODE)
1635: modeString = "convert";
1636: else if (mode == APPEND_MODE)
1.5 rogo 1637: modeString = "append";
1.34 rogo 1638: else if (mode == UPDATE_MODE)
1639: modeString = "update";
1.48 rogo 1640: else if (mode == DELETE_MODE)
1.55 rogo 1641: modeString = "delete";
1.34 rogo 1642:
1643: buffr.write(" <mode>" + modeString + "</mode>\n");
1.59 ! rogo 1644: buffr.write(" <usenormantounicodemapper>" + useNormanToUnicodeMapper + "</usenormantounicodemapper>\n");
! 1645:
1.34 rogo 1646: int index = 0;
1647: while (index < tables.size())
1648: {
1649: String table = (String) tables.get(index);
1650: String layout = (String) layouts.get(index);
1651: String select = (String) selects.get(index);
1652: String create = (String) creates.get(index);
1653: String id = (String) ids.get(index);
1654:
1655: buffr.write(" <table name = \"" + table + "\" layout = \"" + layout + "\" id = \"" + id + "\" >\n");
1656: buffr.write(" <select>" + convertToEntities(select) + "</select>\n");
1657: if (!create.equals(""))
1658: buffr.write(" <create>" + create + " </create>\n");
1659: buffr.write(" </table>\n");
1660: index++;
1661: }
1662: buffr.write(" </database>\n");
1663: }
1664: public String toString()
1665: {
1666: return bean.url + " " + tables;
1667: }
1.1 rogo 1668:
1.34 rogo 1669: }
1670: public static String convertToUTF8(Object command)
1.1 rogo 1671: {
1.34 rogo 1672: String str = null;
1673: try
1674: {
1675: str = new String(command.toString().getBytes("UTF-8"));
1676: } catch (UnsupportedEncodingException e)
1677: {
1678: // TODO Auto-generated catch block
1679: e.printStackTrace();
1680: }
1681: return str;
1.1 rogo 1682: }
1683: public static void writeConfig(String file, DataBase source, DataBase destination) throws Exception
1684: {
1.34 rogo 1685: if (!file.toLowerCase().endsWith(".xml"))
1686: file += ".xml";
1.1 rogo 1687: File f = new File(file);
1.34 rogo 1688:
1689: FileOutputStream fout = new FileOutputStream(f);
1690: OutputStreamWriter outsw = new OutputStreamWriter(fout, "UTF-8");
1.1 rogo 1691: BufferedWriter buffw = new BufferedWriter(outsw);
1692: buffw.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
1693: buffw.newLine();
1694: buffw.write("<convert>\n");
1695: buffw.write(" <source>\n");
1696: source.exportToXML(buffw);
1697: buffw.write(" </source>\n");
1698: buffw.write("\n <destination>\n");
1699: destination.exportToXML(buffw);
1700: buffw.write(" </destination>\n");
1701: buffw.write("</convert>\n");
1702: buffw.close();
1.34 rogo 1703: }
1.46 rogo 1704: public static void delete(String source, String destination, Vector names, Vector layouts, Vector selects, Vector creates, Vector ids, int mode) throws Exception
1705: {
1706: FM2SQL.ProgressDialog dialog = null;
1707: if (FM2SQL.fmInstance != null)
1708: {
1.55 rogo 1709: dialog = new FM2SQL.ProgressDialog(FM2SQL.fmInstance, bean);
1.46 rogo 1710: dialog.setTitle("Conversion running ...");
1711: dialog.title.setText("Getting table data ...");
1712: dialog.setLocation(FM2SQL.fmInstance.getLocationOnScreen().x + (FM2SQL.fmInstance.getWidth() - 400) / 2, FM2SQL.fmInstance.getLocationOnScreen().y + (FM2SQL.fmInstance.getHeight() - 250) / 2);
1713: dialog.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
1714: FM2SQL.fmInstance.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
1715: dialog.thread = Thread.currentThread();
1716: }
1717: // setting user and passwd
1718: bean.setUserAndPasswd(user, passwd);
1719: // setting user and passwd
1720: beanDest.setUserAndPasswd(userDest, passwdDest);
1721: if (dialog != null)
1722: dialog.setSize(400, 250);
1723: StringBuffer command = null;
1724: String query = null;
1725: try
1726: {
1727: //bean.setConnection("jdbc:fmpro:http://141.14.237.74:8050");
1728: //bean.setConnection("jdbc:postgresql://erebos/test","postgres","rogo");
1729: bean.setConnection(source);
1730: if (names == null)
1731: names = bean.getTableNames();
1732: // Collections.sort(names);
1733: int tbIndex = 1;
1734:
1735: // System.out.println("Start at "+names.indexOf("archimedes_facsimiles"));
1736: for (tbIndex = 0; tbIndex < names.size(); ++tbIndex)
1737: {
1738: Vector[] result = null;
1739: java.util.TreeSet myIds = new TreeSet();
1740: java.util.TreeSet myIdsDest = new TreeSet();
1741: int deltaID = 1;
1742: String idField = "";
1743: String destTableName = "";
1744:
1745: try
1746: {
1747: query = "select * from " + bean.getQC() + names.get(tbIndex).toString() + bean.getQC();
1748: String layout = (layouts.isEmpty()) ? "" : layouts.get(tbIndex).toString();
1749: query = (selects != null) ? selects.get(tbIndex).toString() : query;
1750: //if vectors[1].get(i) != null)
1751: if (layout != "")
1752: {
1753: layout = " layout " + bean.getQC() + layout + bean.getQC();
1754: String name = names.get(tbIndex).toString();
1755: StringBuffer queryLayout = new StringBuffer(query);
1756: queryLayout.insert(queryLayout.indexOf(name) + name.length() + 1, " " + layout);
1757: query = queryLayout.toString();
1758: System.out.println("added layout " + query);
1759:
1760: }
1761: dialog.title.setText("Getting table data ...");
1762: dialog.table.setText(names.get(tbIndex).toString());
1763: dialog.status.setText("Table " + (tbIndex + 1) + " of " + names.size());
1764: dialog.show();
1765: bean.getConnection();
1766: bean.makeQuery(query, 50);
1767: idField = ids.get(tbIndex).toString();
1768:
1769: } catch (Exception e)
1770: {
1771: continue;
1772: }
1773: // determine destTableName from createStatement or from source table name
1774: if (!creates.get(tbIndex).equals(""))
1775: {
1776: String create = creates.get(tbIndex).toString().toLowerCase();
1777: int fromIndex = create.indexOf("table") + 5;
1778: int toIndex = create.indexOf("(");
1779: destTableName = create.substring(fromIndex, toIndex).replaceAll(beanDest.getQC(), "").trim();
1780: System.out.println("destTable " + destTableName);
1781:
1782: } else
1783: destTableName = convertText(names.get(tbIndex).toString());
1784:
1785: // for id kram
1786: Vector vec = null;
1787: Vector vecDest = null;
1.47 rogo 1788: // tempo
1789: beanDest.setConnection(destination);
1.46 rogo 1790: int rowCount = (idField != "") ? myIds.size() : bean.getRowCount(query);
1791: String tempID = bean.getQC() + idField + bean.getQC();
1792: String tempIDdest = beanDest.getQC() + convertText(idField) + beanDest.getQC();
1.47 rogo 1793:
1.46 rogo 1794: int endIndex = -1;
1795: String tempQuery = query;
1.47 rogo 1796: String destQuery = query.replaceAll(names.get(tbIndex).toString(), destTableName);
1.49 rogo 1797: String tempQueryDest = destQuery;
1798: // remove extra query parts destQuery.substring(0,destQuery.lastIndexOf(destTableName)+destTableName.length()+1);
1.47 rogo 1799: System.out.println("new Query " + tempQueryDest);
1.46 rogo 1800: if (!idField.equals(""))
1801: {
1802: long startTime = System.currentTimeMillis();
1803: int counter = -1;
1804: while (true)
1805: {
1806: ++counter;
1807: if (counter == 0 && dialog != null)
1808: dialog.title.setText("Check if data is available");
1809: else if (dialog != null)
1810: dialog.title.setText("Check if more data is available");
1811: myIds = bean.getIDVector(ids.get(tbIndex).toString(), (String) names.get(tbIndex), tempQuery, numHits);
1812: myIdsDest = beanDest.getIDVector(convertText(idField), destTableName, tempQueryDest, numHits);
1813: if (myIds.isEmpty())
1814: break;
1815: vec = new Vector(myIds);
1816: vecDest = new Vector(myIdsDest);
1817: rowCount = vec.size();
1.47 rogo 1818: // Deletion will work this way
1819: Vector deleted = new Vector(vec);
1820: Vector linesToDelete = new Vector(vecDest);
1821: // remove all lines that should not be deleted
1822: linesToDelete.removeAll(deleted);
1823: // System.out.println("ID LIST SIZE " + Math.round((double) myIds.size() / (double) numIntervalls) + " " + myIdsDest.size());
1.46 rogo 1824: /// @TODO complete delete task remove query show lines to be deleted let user choose if he wants that
1.47 rogo 1825: System.out.println("number of lines to be deleted " + linesToDelete.size());
1.46 rogo 1826: deltaID = (int) Math.round((double) myIds.size() / (double) numIntervalls);
1.47 rogo 1827: beanDest.setConnection(destination);
1.46 rogo 1828:
1.47 rogo 1829: Statement stm = beanDest.getConnection().createStatement();
1.46 rogo 1830:
1.47 rogo 1831: Vector tables = beanDest.getTableNames();
1832: // Collections.sort(tables);
1833: System.out.println(names.get(tbIndex) + " " + tables.indexOf(convertText((String) names.get(tbIndex)))); // "//beanDest.getTypeNames());
1834: tables = beanDest.getTableNames();
1835: // System.out.println(beanDest.getTableNames(beanDest.getCatalogs().get(2).toString()));
1836: stm = beanDest.getConnection().createStatement();
1837:
1838: if (dialog != null)
1839: dialog.title.setText(" Deleting table data ...");
1840:
1841: int j = -1;
1842:
1843: Vector row = null;
1844: command = new StringBuffer();
1845:
1846: command.append("DELETE FROM");
1847: command.append(beanDest.getQC());
1848: command.append(destTableName);
1849: //command.append(convertText((String) names.get(tbIndex)));
1850: command.append(beanDest.getQC());
1851: int size = bean.getColumnNames().size();
1852: command.append("WHERE " + convertText(ids.get(tbIndex).toString()) + " = ?");
1853: PreparedStatement pstm = beanDest.getConnection().prepareStatement(command.toString());
1854: System.out.println(command + " " + tbIndex);
1855: //int rowCount = bean.getRowCount(query);
1856: // int idIndex = bean.getColumnNames().indexOf(ids.get(tbIndex));
1857: while (true)
1.46 rogo 1858: {
1859:
1.48 rogo 1860: ++j;
1.47 rogo 1861: if (j == linesToDelete.size())
1862: break;
1863: //print rows
1864: pstm.setString(1, linesToDelete.get(j).toString());
1865: System.out.println(pstm.toString());
1.55 rogo 1866: pstm.execute();
1.46 rogo 1867: if (dialog != null)
1.47 rogo 1868: dialog.progress.setValue((int) (((double) (j + 1) / (double) rowCount) * 100.0));
1869: command = null;
1.46 rogo 1870: }
1871: // prepare new query for next chunk
1872: if (query.indexOf("where") > 0)
1873: tempQuery = query + " and " + tempID + ">'" + vec.lastElement() + "'";
1874: else
1875: tempQuery = query + " where " + tempID + ">'" + vec.lastElement() + "'";
1876:
1.47 rogo 1877: } //to outer while
1878: } // to idfield if
1879: } // table loop
1880:
1881: } catch (Exception e)
1.55 rogo 1882: {
1883: System.out.println("Error while connecting to database " + e);
1.47 rogo 1884: if (dialog != null)
1885: {
1.55 rogo 1886: dialog.setVisible(false);
1.47 rogo 1887: dialog.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
1888: FM2SQL.fmInstance.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
1.55 rogo 1889: }
1890: java.io.ByteArrayOutputStream b = new java.io.ByteArrayOutputStream();
1891: java.io.PrintStream stream = new java.io.PrintStream(b);
1892: stream.print(command + "\n\n");
1893: e.printStackTrace(stream);
1894: FM2SQL.showErrorDialog(b.toString(), "Error occured !");
1895:
1896: }
1897: if (dialog != null)
1898: {
1899: dialog.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
1900: FM2SQL.fmInstance.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
1.46 rogo 1901:
1.55 rogo 1902: dialog.setVisible(false);
1903: }
1904: } // to method
1.56 rogo 1905:
1906: /**
1907: * Converts input String in norman encoding to unicode
1908: * @param inp
1909: * @return converted String
1910: */
1911: static public String normanToUnicode(String inp) {
1912: StringBuffer buf = new StringBuffer();
1913: for (int i = 0; i < inp.length(); i++) {
1914: char c = inp.charAt(i);
1.57 rogo 1915: // System.out.println("char "+c+" "+(int)c);
1916: switch (c) {
1917: case 1: buf.append("\u00d0"); break; // Eth
1918: case 2: buf.append("\u00f0"); break; // eth
1919: case 3: buf.append("\u0141"); break; // Lslash
1920: case 4: buf.append("\u0142"); break; // lslash
1921: case 5: buf.append("\u0160"); break; // S caron
1922: case 6: buf.append("\u0161"); break; // s caron
1923: case 7: buf.append("\u00dd"); break; // Y acute
1924: case 8: buf.append("\u00fd"); break; // y acute
1925: case 11: buf.append("\u00de"); break; // Thorn
1926: case 12: buf.append("\u00fe"); break; // thorn
1927: case 14: buf.append("\u017d"); break; // Z caron
1928: case 15: buf.append("\u017e"); break; // z caron
1929: case 17: buf.append("\u0073"); break; // asciitilde
1930: case 18: buf.append("j\u0305"); break; // j macron [does a single char exist?]
1931: case 19: buf.append("^"); break; // circumflex
1932: case 20: buf.append("\u0303"); break; // tilde
1933: case 21: buf.append("\u00bd"); break; // onehalf
1934: case 22: buf.append("\u00bc"); break; // onequarter
1935: case 23: buf.append("\u00b9"); break; // onesuperior
1936: case 24: buf.append("\u00be"); break; // threequarters
1937: case 25: buf.append("\u00b3"); break; // threesuperior
1938: case 26: buf.append("\u00b2"); break; // twosuperior
1939: case 27: buf.append("\u00a6"); break; // brokenbar
1940: case 28: buf.append("-"); break; // minus
1941: case 29: buf.append("\u00d7"); break; // multiply
1942: case 39: buf.append("'"); break; // quotesingle
1943: case 94: buf.append("\u0302"); break; // circumflex
1944: case 96: buf.append("\u0300"); break; // grave
1945: case 196: buf.append("\u00c4"); break; // A dieresis
1946: case 197: buf.append("\u00c5"); break; // A ring
1947: case 201: buf.append("\u00c9"); break; // E acute
1948: case 209: buf.append("\u00d1"); break; // N tilde
1949: case 214: buf.append("\u00d6"); break; // O dieresis
1950: case 220: buf.append("\u00dc"); break; // U dieresis
1951: case 225: buf.append("\u00e1"); break; // a acute
1952: case 224: buf.append("\u00e0"); break; // a grave
1953: case 226: buf.append("\u00e2"); break; // a circumflex
1954: case 228: buf.append("\u00e4"); break; // a dieresis
1955: case 227: buf.append("\u00e3"); break; // a tilde
1956: case 229: buf.append("\u0101"); break; // a macron
1957: case 231: buf.append("\u00e7"); break; // c cedilla
1958: case 233: buf.append("\u00e9"); break; // e acute
1959: case 232: buf.append("\u00e8"); break; // e grave
1960: case 234: buf.append("\u00ea"); break; // e circumflex
1961: case 235: buf.append("\u00eb"); break; // e dieresis
1962: case 237: buf.append("\u00ed"); break; // i acute
1963: case 236: buf.append("\u00ec"); break; // i grave
1964: case 238: buf.append("\u00ee"); break; // i circumflex
1965: case 239: buf.append("\u00ef"); break; // i dieresis
1966: case 241: buf.append("\u00f1"); break; // n tilde
1967: case 243: buf.append("\u00f3"); break; // o acute
1968: case 242: buf.append("\u00f2"); break; // o grave
1969: case 244: buf.append("\u00f4"); break; // o circumflex
1970: case 246: buf.append("\u00f6"); break; // o dieresis
1971: case 245: buf.append("\u00f5"); break; // o tilde
1972: case 250: buf.append("\u00fa"); break; // u acute
1973: case 249: buf.append("\u00f9"); break; // u grave
1974: case 251: buf.append("\u00fb"); break; // u circumflex
1975: case 252: buf.append("\u00fc"); break; // u dieresis
1976: case 8224: buf.append("\u1e6d"); break; // t underdot
1977: case 176: buf.append("\u00b0"); break; // degree
1978: case 162: buf.append("\u1ebd"); break; // e tilde
1979: case 163: buf.append("\u00a3"); break; // sterling
1980: case 167: buf.append("\u00a7"); break; // section
1981: case 182: buf.append("\u00b6"); break; // paragraph
1982: case 223: buf.append("\u015b"); break; // s acute
1983: case 174: buf.append("\u1e5b"); break; // r underdot
1984: case 169: buf.append("\u1e45"); break; // n overdot
1985: case 353: buf.append("\u1e45"); break; // n overdot
1986: case 180: buf.append("\u0301"); break; // acute
1987: case 168: buf.append("\u0308"); break; // dieresis
1988: case 8800: buf.append("\u1e6d"); break; // t underdot
1989: case 198: buf.append("\u00c6"); break; // AE
1990: case 216: buf.append("\u014d"); break; // o macron
1991: case 8734: buf.append("\u0129"); break; // i tilde
1992: case 177: buf.append("\u00b1"); break; // plusminus
1993: case 165: buf.append("\u012b"); break; // i macron
1994: case 181: buf.append("\u1e43"); break; // m underdot
1995: case 8706: buf.append("\u1e0d"); break; // d underdot
1996: case 240: buf.append("\u1e0d"); break; // d underdot
1997:
1998: case 8721: buf.append("\u1e63"); break; // s underdot
1999: case 960: buf.append("\u017a"); break; // z acute
2000: case 8747: buf.append("\u1e45"); break; // n overdot
2001: case 937: buf.append("\u0169"); break; // u tilde
2002: case 230: buf.append("\u00e6"); break; // ae
2003: case 248: buf.append("\u00f8"); break; // oslash
2004: case 191: buf.append("\u0304\u0306"); break; // macron breve
2005: case 172: buf.append("\u1e37"); break; //
2006: case 8730: buf.append("j\u0305"); break; // j macron [does a single char exist?]
2007: case 402: buf.append("\u0103"); break; // a breve
2008: case 8776: buf.append("\u016d"); break; // u breve
2009: case 187: buf.append("\u1e42"); break; // M underdot
2010: case 8230: buf.append("\u2026"); break; // ellipsis
2011: case 192: buf.append("\u00c0"); break; // A grave
2012: case 195: buf.append("\u00c3"); break; // A tilde
2013: case 213: buf.append("\u00d5"); break; // O tilde
2014: case 338: buf.append("m\u0306"); break; // m breve
2015: case 339: buf.append("\u0153"); break; // oe
2016: case 8211: buf.append("\u2013"); break; // endash
2017: case 8212: buf.append("\u2014"); break; // emdash
2018: case 8220: buf.append("\u201c"); break; // quotedblleft
2019: case 8221: buf.append("\u201d"); break; // quotedblright
2020: case 8216: buf.append("\u2018"); break; // quoteleft
2021: case 8217: buf.append("\u2019"); break; // quoteright
2022: case 247: buf.append("\u1e37"); break; // l underring [actually underdot]
2023: case 9674: buf.append("\u1e41"); break; // m overdot
2024: case 255: buf.append("n\u0306"); break; // n breve
2025: case 376: buf.append("\u00d7"); break; // multiply
2026: case 8364: buf.append("\u1e5b"); break; // r underring [actually underdot]
2027: case 8249: buf.append("\u1e44"); break; // N overdot
2028: case 8250: buf.append("\u1e62"); break; // S underdot
2029: case 64257: buf.append("\u1e24"); break; // H underdot
2030: case 64258: buf.append("\u1e0c"); break; // D underdot
2031: case 8225: buf.append("\u2021"); break; // daggerdbl
2032: case 8218: buf.append("\u1e36"); break; // L underdot
2033: case 8222: buf.append("\u0113"); break; // e macron
2034: case 194: buf.append("\u1e5f"); break; // r underbar
2035: case 202: buf.append("r\u0324"); break; // r underdieresis
2036: case 193: buf.append("\u012a"); break; // I macron
2037: case 8486:
2038: case 203: buf.append("\u016b"); break; // u macron
2039: case 200: buf.append("\u1e6c"); break; // T underdot
2040: case 205: buf.append("\u1e64"); break; // S acute
2041: case 206: buf.append("\u2020"); break; // dagger
2042: case 207: buf.append("\u0115"); break; // e breve
2043: case 204: buf.append("\u014f"); break; // o breve
2044: case 211: buf.append("\u0100"); break; // A macron
2045: case 212: buf.append("\u1e46"); break; // N underdot
2046: case 210: buf.append("\u1e3b"); break; // l underbar
2047: case 218: buf.append("\u016a"); break; // U macron
2048: case 219: buf.append("\u0179"); break; // Z acute
2049: case 217: buf.append("\u1e5a"); break; // R underdot
2050: case 305: buf.append("\u0131"); break; // dotlessi
2051: case 710: buf.append("\u1e47"); break; // n underdot
2052: case 732: buf.append("\u1e49"); break; // n underbar
2053: case 175: buf.append("\u0304"); break; // macron
2054: case 728: buf.append("\u0306"); break; // breve
2055: case 729:case 215: buf.append("\u1e25"); break; // h underdot
2056: case 730: buf.append("\u012d"); break; // i breve
2057: case 184: buf.append("\u0327"); break; // cedilla
2058: case 733: buf.append("\u030b"); break; // hungarumlaut
2059: case 731: buf.append("\u0328"); break; // ogonek
2060: case 711: buf.append("\u030c"); break; // caron
2061: case 199: buf.append("\u012b\u0303"); break; // imacron tilde
2062: case 8226: buf.append("\u1e5d"); break; // runderdot macron
2063: case 8482: buf.append("\u016b\0306"); break; // umacron breve
2064: case 8804: buf.append("\u0101\u0301"); break; // amacron acute
2065: case 8805: buf.append("\u016b\u0301"); break; // umacron acute
2066: case 8719: buf.append("\u0113\u0301"); break; // emacron acute
2067: case 170: buf.append("\u0113\u0300"); break; // emacron breve
2068: case 186: buf.append("\u014d\u0300"); break; // omacron breve
2069: case 161: buf.append("\u0101\u0306"); break; // amacron breve
2070: case 8710: buf.append("\u0101\u0303"); break; // amacron tilde
2071: case 171: buf.append("\u012b\u0301"); break; // imacron acute
2072: case 8260: buf.append("\u1e00"); break; // runderdotmacron acute
2073: case 183: buf.append("\u1e5b\u0301"); break; // runderdot acute
2074: case 8240: buf.append("\u012b\u0306"); break; // imacron breve
2075: case 63743: buf.append("\u016b\u0303"); break; // umacron tilde
2076: default: buf.append(c);
2077: if((int)c>127)
2078: System.out.println("char "+c+" "+(int)c);
2079: break;
2080: }
2081: }
2082: return buf.toString();
2083: }
2084:
2085: static public String normanToUnicodeOld(String inp) {
2086: StringBuffer buf = new StringBuffer();
2087: for (int i = 0; i < inp.length(); i++) {
2088: char c = inp.charAt(i);
1.56 rogo 2089: switch (c) {
2090: case 1: buf.append("\u00d0"); break; // Eth
2091: case 2: buf.append("\u00f0"); break; // eth
2092: case 3: buf.append("\u0141"); break; // Lslash
2093: case 4: buf.append("\u0142"); break; // lslash
2094: case 5: buf.append("\u0160"); break; // S caron
2095: case 6: buf.append("\u0161"); break; // s caron
2096: case 7: buf.append("\u00dd"); break; // Y acute
2097: case 8: buf.append("\u00fd"); break; // y acute
2098: case 11: buf.append("\u00de"); break; // Thorn
2099: case 12: buf.append("\u00fe"); break; // thorn
2100: case 14: buf.append("\u017d"); break; // Z caron
2101: case 15: buf.append("\u017e"); break; // z caron
2102: case 17: buf.append("\u0073"); break; // asciitilde
2103: case 18: buf.append("j\u0305"); break; // j macron [does a single char exist?]
2104: case 19: buf.append("^"); break; // circumflex
2105: case 20: buf.append("\u0303"); break; // tilde
2106: case 21: buf.append("\u00bd"); break; // onehalf
2107: case 22: buf.append("\u00bc"); break; // onequarter
2108: case 23: buf.append("\u00b9"); break; // onesuperior
2109: case 24: buf.append("\u00be"); break; // threequarters
2110: case 25: buf.append("\u00b3"); break; // threesuperior
2111: case 26: buf.append("\u00b2"); break; // twosuperior
2112: case 27: buf.append("\u00a6"); break; // brokenbar
2113: case 28: buf.append("-"); break; // minus
2114: case 29: buf.append("\u00d7"); break; // multiply
2115: case 39: buf.append("'"); break; // quotesingle
2116: case 94: buf.append("\u0302"); break; // circumflex
2117: case 96: buf.append("\u0300"); break; // grave
2118: case 128: buf.append("\u00c4"); break; // A dieresis
2119: case 129: buf.append("\u00c5"); break; // A ring
2120: case 131: buf.append("\u00c9"); break; // E acute
2121: case 132: buf.append("\u00d1"); break; // N tilde
2122: case 133: buf.append("\u00d6"); break; // O dieresis
2123: case 134: buf.append("\u00dc"); break; // U dieresis
2124: case 135: buf.append("\u00e1"); break; // a acute
2125: case 136: buf.append("\u00e0"); break; // a grave
2126: case 137: buf.append("\u00e2"); break; // a circumflex
2127: case 138: buf.append("\u00e4"); break; // a dieresis
2128: case 139: buf.append("\u00e3"); break; // a tilde
2129: case 140: buf.append("\u0101"); break; // a macron
2130: case 141: buf.append("\u00e7"); break; // c cedilla
2131: case 142: buf.append("\u00e9"); break; // e acute
2132: case 143: buf.append("\u00e8"); break; // e grave
2133: case 144: buf.append("\u00ea"); break; // e circumflex
2134: case 145: buf.append("\u00eb"); break; // e dieresis
2135: case 146: buf.append("\u00ed"); break; // i acute
2136: case 147: buf.append("\u00ec"); break; // i grave
2137: case 148: buf.append("\u00ee"); break; // i circumflex
2138: case 149: buf.append("\u00ef"); break; // i dieresis
2139: case 150: buf.append("\u00f1"); break; // n tilde
2140: case 151: buf.append("\u00f3"); break; // o acute
2141: case 152: buf.append("\u00f2"); break; // o grave
2142: case 153: buf.append("\u00f4"); break; // o circumflex
2143: case 154: buf.append("\u00f6"); break; // o dieresis
2144: case 155: buf.append("\u00f5"); break; // o tilde
2145: case 156: buf.append("\u00fa"); break; // u acute
2146: case 157: buf.append("\u00f9"); break; // u grave
2147: case 158: buf.append("\u00fb"); break; // u circumflex
2148: case 159: buf.append("\u00fc"); break; // u dieresis
2149: case 160: buf.append("\u1e6d"); break; // t underdot
2150: case 161: buf.append("\u00b0"); break; // degree
2151: case 162: buf.append("\u1ebd"); break; // e tilde
2152: case 163: buf.append("\u00a3"); break; // sterling
2153: case 164: buf.append("\u00a7"); break; // section
2154: case 166: buf.append("\u00b6"); break; // paragraph
2155: case 167: buf.append("\u015b"); break; // s acute
2156: case 168: buf.append("\u1e5b"); break; // r underdot
2157: case 169: buf.append("\u1e67"); break; // s caron
2158: case 171: buf.append("\u0301"); break; // acute
2159: case 172: buf.append("\u0308"); break; // dieresis
2160: case 173: buf.append("\u1e6d"); break; // t underdot
2161: case 174: buf.append("\u00c6"); break; // AE
2162: case 175: buf.append("\u014d"); break; // o macron
2163: case 176: buf.append("\u0129"); break; // i tilde
2164: case 177: buf.append("\u00b1"); break; // plusminus
2165: case 180: buf.append("\u012b"); break; // i macron
2166: case 181: buf.append("\u1e43"); break; // m underdot
2167: case 182: buf.append("\u1e0d"); break; // d underdot
2168: case 183: buf.append("\u1e63"); break; // s underdot
2169: case 185: buf.append("\u017a"); break; // z acute
2170: case 186: buf.append("\u1e45"); break; // n overdot
2171: case 189: buf.append("\u0169"); break; // u tilde
2172: case 190: buf.append("\u00e6"); break; // ae
2173: case 191: buf.append("\u00f8"); break; // oslash
2174: case 192: buf.append("\u0304\u0306"); break; // macron breve
2175: case 194: buf.append("\u1e37"); break; //
2176: case 195: buf.append("j\u0305"); break; // j macron [does a single char exist?]
2177: case 196: buf.append("\u0103"); break; // a breve
2178: case 197: buf.append("\u016d"); break; // u breve
2179: case 200: buf.append("\u1e42"); break; // M underdot
2180: case 201: buf.append("\u2026"); break; // ellipsis
2181: case 203: buf.append("\u00c0"); break; // A grave
2182: case 204: buf.append("\u00c3"); break; // A tilde
2183: case 205: buf.append("\u00d5"); break; // O tilde
2184: case 206: buf.append("m\u0306"); break; // m breve
2185: case 207: buf.append("\u0153"); break; // oe
2186: case 208: buf.append("\u2013"); break; // endash
2187: case 209: buf.append("\u2014"); break; // emdash
2188: case 210: buf.append("\u201c"); break; // quotedblleft
2189: case 211: buf.append("\u201d"); break; // quotedblright
2190: case 212: buf.append("\u2018"); break; // quoteleft
2191: case 213: buf.append("\u2019"); break; // quoteright
2192: case 214: buf.append("\u1e37"); break; // l underring [actually underdot]
2193: case 215: buf.append("\u1e41"); break; // m overdot
2194: case 216: buf.append("n\u0306"); break; // n breve
2195: case 217: buf.append("\u00d7"); break; // multiply
2196: case 219: buf.append("\u1e5b"); break; // r underring [actually underdot]
2197: case 220: buf.append("\u1e44"); break; // N overdot
2198: case 221: buf.append("\u1e62"); break; // S underdot
2199: case 222: buf.append("\u1e24"); break; // H underdot
2200: case 223: buf.append("\u1e0c"); break; // D underdot
2201: case 224: buf.append("\u2021"); break; // daggerdbl
2202: case 226: buf.append("\u1e36"); break; // L underdot
2203: case 227: buf.append("\u0113"); break; // e macron
2204: case 229: buf.append("\u1e5f"); break; // r underbar
2205: case 230: buf.append("r\u0324"); break; // r underdieresis
2206: case 231: buf.append("\u012a"); break; // I macron
2207: case 232: buf.append("\u016b"); break; // u macron
2208: case 233: buf.append("\u01e6c"); break; // T underdot
2209: case 234: buf.append("\u1e64"); break; // S acute
2210: case 235: buf.append("\u2020"); break; // dagger
2211: case 236: buf.append("\u0115"); break; // e breve
2212: case 237: buf.append("\u014f"); break; // o breve
2213: case 238: buf.append("\u0100"); break; // A macron
2214: case 239: buf.append("\u1e46"); break; // N underdot
2215: case 241: buf.append("\u1e3b"); break; // l underbar
2216: case 242: buf.append("\u016a"); break; // U macron
2217: case 243: buf.append("\u0179"); break; // Z acute
2218: case 244: buf.append("\u1e5a"); break; // R underdot
2219: case 245: buf.append("\u0131"); break; // dotlessi
2220: case 246: buf.append("\u1e47"); break; // n underdot
2221: case 247: buf.append("\u1e49"); break; // n underbar
2222: case 248: buf.append("\u0304"); break; // macron
2223: case 249: buf.append("\u0306"); break; // breve
2224: case 250: buf.append("\u1e25"); break; // h underdot
2225: case 251: buf.append("\u012d"); break; // i breve
2226: case 252: buf.append("\u0327"); break; // cedilla
2227: case 253: buf.append("\u030b"); break; // hungarumlaut
2228: case 254: buf.append("\u0328"); break; // ogonek
2229: case 255: buf.append("\u030c"); break; // caron
2230: case 130: buf.append("\u012b\u0303"); break; // imacron tilde
2231: case 165: buf.append("\u1e5d"); break; // runderdot macron
2232: case 170: buf.append("\u016b\0306"); break; // umacron breve
2233: case 178: buf.append("\u0101\u0301"); break; // amacron acute
2234: case 179: buf.append("\u016b\u0301"); break; // umacron acute
2235: case 184: buf.append("\u0113\u0301"); break; // emacron acute
2236: case 187: buf.append("\u0113\u0300"); break; // emacron breve
2237: case 188: buf.append("\u014d\u0300"); break; // omacron breve
2238: case 193: buf.append("\u0101\u0306"); break; // amacron breve
2239: case 198: buf.append("\u0101\u0303"); break; // amacron tilde
2240: case 199: buf.append("\u012b\u0301"); break; // imacron acute
2241: case 218: buf.append("\u1e00"); break; // runderdotmacron acute
2242: case 225: buf.append("\u1e5b\u0301"); break; // runderdot acute
2243: case 228: buf.append("\u012b\u0306"); break; // imacron breve
2244: case 240: buf.append("\u016b\u0303"); break; // umacron tilde
2245: default: buf.append(c); break;
2246: }
2247: }
2248: return buf.toString();
2249: }
1.58 rogo 2250: static public String normanToUnicodeNew(String inp) {
2251: StringBuffer buf = new StringBuffer();
2252: for (int i = 0; i < inp.length(); i++) {
2253: char c = inp.charAt(i);
2254: switch (c) {
2255: case 1: buf.append("\u00d0"); break; // Eth
2256: case 2: buf.append("\u00f0"); break; // eth
2257: case 3: buf.append("\u0141"); break; // Lslash
2258: case 4: buf.append("\u0142"); break; // lslash
2259: case 5: buf.append("\u0160"); break; // S caron
2260: case 6: buf.append("\u0161"); break; // s caron
2261: case 7: buf.append("\u00dd"); break; // Y acute
2262: case 8: buf.append("\u00fd"); break; // y acute
2263: case 11: buf.append("\u00de"); break; // Thorn
2264: case 12: buf.append("\u00fe"); break; // thorn
2265: case 14: buf.append("\u017d"); break; // Z caron
2266: case 15: buf.append("\u017e"); break; // z caron
2267: case 17: buf.append("\u0073"); break; // asciitilde
2268: case 18: buf.append("j\u0305"); break; // j macron [does a single char exist?]
2269: case 19: buf.append("^"); break; // circumflex
2270: case 20: buf.append("\u0303"); break; // tilde
2271: case 21: buf.append("\u00bd"); break; // onehalf
2272: case 22: buf.append("\u00bc"); break; // onequarter
2273: case 23: buf.append("\u00b9"); break; // onesuperior
2274: case 24: buf.append("\u00be"); break; // threequarters
2275: case 25: buf.append("\u00b3"); break; // threesuperior
2276: case 26: buf.append("\u00b2"); break; // twosuperior
2277: case 27: buf.append("\u00a6"); break; // brokenbar
2278: case 28: buf.append("-"); break; // minus
2279: case 29: buf.append("\u00d7"); break; // multiply
2280: case 39: buf.append("'"); break; // quotesingle
2281: case 94: buf.append("\u0302"); break; // circumflex
2282: case 96: buf.append("\u0300"); break; // grave
2283: case 196: buf.append("\u00c4"); break; // A dieresis
2284: case 197: buf.append("\u00c5"); break; // A ring
2285: case 201: buf.append("\u00c9"); break; // E acute
2286: case 209: buf.append("\u00d1"); break; // N tilde
2287: case 214: buf.append("\u00d6"); break; // O dieresis
2288: case 220: buf.append("\u00dc"); break; // U dieresis
2289: case 225: buf.append("\u00e1"); break; // a acute
2290: case 224: buf.append("\u00e0"); break; // a grave
2291: case 226: buf.append("\u00e2"); break; // a circumflex
2292: case 228: buf.append("\u00e4"); break; // a dieresis
2293: case 227: buf.append("\u00e3"); break; // a tilde
2294: case 229: buf.append("\u0101"); break; // a macron
2295: case 231: buf.append("\u00e7"); break; // c cedilla
2296: case 233: buf.append("\u00e9"); break; // e acute
2297: case 232: buf.append("\u00e8"); break; // e grave
2298: case 234: buf.append("\u00ea"); break; // e circumflex
2299: case 235: buf.append("\u00eb"); break; // e dieresis
2300: case 237: buf.append("\u00ed"); break; // i acute
2301: case 236: buf.append("\u00ec"); break; // i grave
2302: case 238: buf.append("\u00ee"); break; // i circumflex
2303: case 239: buf.append("\u00ef"); break; // i dieresis
2304: case 241: buf.append("\u00f1"); break; // n tilde
2305: case 243: buf.append("\u00f3"); break; // o acute
2306: case 242: buf.append("\u00f2"); break; // o grave
2307: case 244: buf.append("\u00f4"); break; // o circumflex
2308: case 246: buf.append("\u00f6"); break; // o dieresis
2309: case 245: buf.append("\u00f5"); break; // o tilde
2310: case 250: buf.append("\u00fa"); break; // u acute
2311: case 249: buf.append("\u00f9"); break; // u grave
2312: case 251: buf.append("\u00fb"); break; // u circumflex
2313: case 252: buf.append("\u00fc"); break; // u dieresis
2314: case 8224: buf.append("\u1e6d"); break; // t underdot
2315: case 176: buf.append("\u00b0"); break; // degree
2316: case 162: buf.append("\u1ebd"); break; // e tilde
2317: case 163: buf.append("\u00a3"); break; // sterling
2318: case 167: buf.append("\u00a7"); break; // section
2319: case 182: buf.append("\u00b6"); break; // paragraph
2320: case 223: buf.append("\u015b"); break; // s acute
2321: case 174: buf.append("\u1e5b"); break; // r underdot
2322: case 169: buf.append("\u1e45"); break; // n overdot
2323: case 180: buf.append("\u0301"); break; // acute
2324: case 168: buf.append("\u0308"); break; // dieresis
2325: case 8800: buf.append("\u1e6d"); break; // t underdot
2326: case 198: buf.append("\u00c6"); break; // AE
2327: case 216: buf.append("\u014d"); break; // o macron
2328: case 8734: buf.append("\u0129"); break; // i tilde
2329: case 177: buf.append("\u00b1"); break; // plusminus
2330: case 165: buf.append("\u012b"); break; // i macron
2331: case 181: buf.append("\u1e43"); break; // m underdot
2332: case 8706: buf.append("\u1e0d"); break; // d underdot
2333: case 8721: buf.append("\u1e63"); break; // s underdot
2334: case 960: buf.append("\u017a"); break; // z acute
2335: case 8747: buf.append("\u1e45"); break; // n overdot
2336: case 937: buf.append("\u0169"); break; // u tilde
2337: case 230: buf.append("\u00e6"); break; // ae
2338: case 248: buf.append("\u00f8"); break; // oslash
2339: case 191: buf.append("\u0304\u0306"); break; // macron breve
2340: case 172: buf.append("\u1e37"); break; //
2341: case 8730: buf.append("j\u0305"); break; // j macron [does a single char exist?]
2342: case 402: buf.append("\u0103"); break; // a breve
2343: case 8776: buf.append("\u016d"); break; // u breve
2344: case 187: buf.append("\u1e42"); break; // M underdot
2345: case 8230: buf.append("\u2026"); break; // ellipsis
2346: case 192: buf.append("\u00c0"); break; // A grave
2347: case 195: buf.append("\u00c3"); break; // A tilde
2348: case 213: buf.append("\u00d5"); break; // O tilde
2349: case 338: buf.append("m\u0306"); break; // m breve
2350: case 339: buf.append("\u0153"); break; // oe
2351: case 8211: buf.append("\u2013"); break; // endash
2352: case 8212: buf.append("\u2014"); break; // emdash
2353: case 8220: buf.append("\u201c"); break; // quotedblleft
2354: case 8221: buf.append("\u201d"); break; // quotedblright
2355: case 8216: buf.append("\u2018"); break; // quoteleft
2356: case 8217: buf.append("\u2019"); break; // quoteright
2357: case 247: buf.append("\u1e37"); break; // l underring [actually underdot]
2358: case 9674: buf.append("\u1e41"); break; // m overdot
2359: case 255: buf.append("n\u0306"); break; // n breve
2360: case 376: buf.append("\u00d7"); break; // multiply
2361: case 8364: buf.append("\u1e5b"); break; // r underring [actually underdot]
2362: case 8249: buf.append("\u1e44"); break; // N overdot
2363: case 8250: buf.append("\u1e62"); break; // S underdot
2364: case 64257: buf.append("\u1e24"); break; // H underdot
2365: case 64258: buf.append("\u1e0c"); break; // D underdot
2366: case 8225: buf.append("\u2021"); break; // daggerdbl
2367: case 8218: buf.append("\u1e36"); break; // L underdot
2368: case 8222: buf.append("\u0113"); break; // e macron
2369: case 194: buf.append("\u1e5f"); break; // r underbar
2370: case 202: buf.append("r\u0324"); break; // r underdieresis
2371: case 193: buf.append("\u012a"); break; // I macron
2372: case 203: buf.append("\u016b"); break; // u macron
2373: case 200: buf.append("\u1e6c"); break; // T underdot
2374: case 205: buf.append("\u1e64"); break; // S acute
2375: case 206: buf.append("\u2020"); break; // dagger
2376: case 207: buf.append("\u0115"); break; // e breve
2377: case 204: buf.append("\u014f"); break; // o breve
2378: case 211: buf.append("\u0100"); break; // A macron
2379: case 212: buf.append("\u1e46"); break; // N underdot
2380: case 210: buf.append("\u1e3b"); break; // l underbar
2381: case 218: buf.append("\u016a"); break; // U macron
2382: case 219: buf.append("\u0179"); break; // Z acute
2383: case 217: buf.append("\u1e5a"); break; // R underdot
2384: case 305: buf.append("\u0131"); break; // dotlessi
2385: case 710: buf.append("\u1e47"); break; // n underdot
2386: case 732: buf.append("\u1e49"); break; // n underbar
2387: case 175: buf.append("\u0304"); break; // macron
2388: case 728: buf.append("\u0306"); break; // breve
2389: case 729: buf.append("\u1e25"); break; // h underdot
2390: case 730: buf.append("\u012d"); break; // i breve
2391: case 184: buf.append("\u0327"); break; // cedilla
2392: case 733: buf.append("\u030b"); break; // hungarumlaut
2393: case 731: buf.append("\u0328"); break; // ogonek
2394: case 711: buf.append("\u030c"); break; // caron
2395: case 199: buf.append("\u012b\u0303"); break; // imacron tilde
2396: case 8226: buf.append("\u1e5d"); break; // runderdot macron
2397: case 8482: buf.append("\u016b\0306"); break; // umacron breve
2398: case 8804: buf.append("\u0101\u0301"); break; // amacron acute
2399: case 8805: buf.append("\u016b\u0301"); break; // umacron acute
2400: case 8719: buf.append("\u0113\u0301"); break; // emacron acute
2401: case 170: buf.append("\u0113\u0300"); break; // emacron breve
2402: case 186: buf.append("\u014d\u0300"); break; // omacron breve
2403: case 161: buf.append("\u0101\u0306"); break; // amacron breve
2404: case 8710: buf.append("\u0101\u0303"); break; // amacron tilde
2405: case 171: buf.append("\u012b\u0301"); break; // imacron acute
2406: case 8260: buf.append("\u1e00"); break; // runderdotmacron acute
2407: case 183: buf.append("\u1e5b\u0301"); break; // runderdot acute
2408: case 8240: buf.append("\u012b\u0306"); break; // imacron breve
2409: case 63743: buf.append("\u016b\u0303"); break; // umacron tilde
2410: default: buf.append(c); break;
2411: }
2412: }
2413: return buf.toString();
2414: }
2415:
2416:
1.55 rogo 2417: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>