Annotation of FM2SQL/Convert.java, revision 1.60

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

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>