Annotation of FM2SQL/src/Convert.java, revision 1.13

1.1       rogo        1: /*
                      2:  * Convert.java -- Converter class - Filemaker to SQL Converter Copyright (C)
                      3:  * 2003 Robert Gordesch (rogo@mpiwg-berlin.mpg.de) This program is free
                      4:  * software; you can redistribute it and/or modify it under the terms of the GNU
                      5:  * General Public License as published by the Free Software Foundation; either
                      6:  * version 2 of the License, or (at your option) any later version. Please read
                      7:  * license.txt for the full details. A copy of the GPL may be found at
                      8:  * http://www.gnu.org/copyleft/lgpl.html You should have received a copy of the
                      9:  * GNU General Public License along with this program; if not, write to the Free
                     10:  * Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
                     11:  * USA Created on 15.09.2003 by rogo
                     12:  */
                     13: 
                     14: import java.awt.Cursor;
                     15: import java.io.BufferedReader;
                     16: import java.io.BufferedWriter;
                     17: import java.io.File;
                     18: import java.io.FileInputStream;
                     19: import java.io.FileNotFoundException;
                     20: import java.io.FileOutputStream;
                     21: import java.io.IOException;
                     22: import java.io.InputStream;
                     23: import java.io.InputStreamReader;
                     24: import java.io.OutputStreamWriter;
                     25: import java.io.PrintStream;
                     26: import java.net.URL;
                     27: import java.sql.PreparedStatement;
                     28: import java.sql.ResultSet;
                     29: import java.sql.SQLException;
                     30: import java.sql.Statement;
                     31: import java.sql.Types;
1.11      rogo       32: import java.text.DateFormat;
1.1       rogo       33: import java.text.ParseException;
                     34: import java.util.ArrayList;
1.11      rogo       35: import java.util.Date;
1.1       rogo       36: import java.util.Hashtable;
                     37: import java.util.Iterator;
                     38: import java.util.List;
                     39: import java.util.StringTokenizer;
                     40: import java.util.TreeSet;
                     41: import java.util.Vector;
                     42: 
                     43: import javax.swing.JDialog;
                     44: import javax.swing.JLabel;
                     45: import javax.swing.JPanel;
                     46: 
                     47: import com.exploringxml.xml.Node;
                     48: import com.exploringxml.xml.Xparse;
                     49: 
                     50: class Convert
                     51: {
1.11      rogo       52:   private static final String _TEMP = "_temp";
                     53: 
1.4       rogo       54:   /**
                     55:    * Helper class for index creation
                     56:    * 
                     57:    * @author rogo
                     58:    * 
                     59:    */
                     60:   public static class IndexList extends Vector
                     61:   {
                     62:     public String toString()
                     63:     {
                     64:       StringBuffer buff = new StringBuffer(1000);
                     65:       int count = 0;
                     66:       for (Iterator iter = this.iterator(); iter.hasNext();)
                     67:       {
                     68:         String element = (String) iter.next();
                     69:         if (count < elementCount - 1)
                     70:         {
                     71:           buff.append(element).append(", ");
                     72:           count++;
                     73:         } else
                     74:           buff.append(element);
                     75: 
                     76:       }
                     77: 
                     78:       return buff.toString();
                     79:     }
                     80:   }
                     81: 
                     82:   /**
                     83:    * Helper class for pre/or post execution of SQLCommands
                     84:    * @author rogo
                     85:    *
                     86:    */
                     87:   public static class SQLCommand
                     88:   {
                     89:     private DBBean bean;
                     90:     private String command;
                     91: 
                     92:     public SQLCommand(DBBean bean, String command)
                     93:     {
                     94:       this.bean = bean;
                     95:       this.command = command;
                     96:     }
                     97: 
                     98:     public void executeCommand() throws SQLException, Exception
                     99:     {
1.6       rogo      100:       System.out.println("Executing command: \n");
                    101:       System.out.println(command);
                    102: 
1.4       rogo      103:       java.sql.Connection con = bean.getConnection();
                    104:       Statement stm = con.createStatement();
                    105:       stm.execute(command);
1.6       rogo      106:       stm.close();
1.4       rogo      107:     }
                    108:   }
                    109: 
                    110:   static DBBean bean = new DBBean();
                    111: 
                    112:   static DBBean beanDest = new DBBean();
                    113: 
                    114:   static String user = "", passwd = "e1nste1n";
                    115: 
                    116:   static String userDest = "postgres", passwdDest = "rogo";
                    117: 
                    118:   static boolean batchRun = false;
                    119: 
                    120:   static Vector databases = new Vector();
                    121: 
                    122:   final static int numHits = 5000;
                    123: 
                    124:   final static int numIntervalls = 4;
                    125: 
1.12      rogo      126:   static boolean debug = false;
1.4       rogo      127: 
                    128:   static boolean isGUI = true;
                    129: 
                    130:   /**
                    131:    * Vector for all SQLCommands to executed before any conversion action is performed
                    132:    */
                    133:   static Vector preSQLCommands = new Vector();
                    134:   /**
                    135:    * Vector for all SQLCommands to executed after any conversion action has been performed
                    136:    */
                    137: 
                    138:   static Vector postSQLCommands = new Vector();
                    139: 
1.13    ! rogo      140:   static final String versionID = new String("FM2SQL Version 0.9.6b\n");
1.10      rogo      141: 
                    142:   private static boolean noError = false;
1.7       rogo      143: 
1.4       rogo      144:   public static void main(String args[]) throws IOException
                    145:   {
1.12      rogo      146:     //    DateFormat d = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT,
                    147:     //        Locale.GERMANY);
                    148:     //    System.out.println(convertText("rogoistSuper" + "_" + d.format(new Date()).replace(':', '_')));
                    149: 
1.4       rogo      150:     /*
                    151:      * try { //byte[] b = "�".getBytes("UTF-8"); //
                    152:      * System.out.println("QueryString " +b[0]+" "+b[1]+(new
                    153:      * String(b).getBytes()[0])+" "+new String(b).getBytes()[1]);
                    154:      * //System.out.println(new String(b,"UTF-8")); } catch
                    155:      * (UnsupportedEncodingException e) { e.printStackTrace(); }
                    156:      */
1.8       rogo      157:     File tmpPath = new File(System.getProperty("java.io.tmpdir"));
1.4       rogo      158:     isGUI = false;
                    159:     FileOutputStream file = null;
                    160:     if (args.length != 1)
                    161:     {
1.7       rogo      162:       System.out.println(versionID);
1.4       rogo      163:       System.out.println("Usage: java Convert <xml config file>");
                    164:       System.exit(-1);
                    165:     }
1.8       rogo      166:     File temp = null;
1.4       rogo      167:     try
                    168:     {
1.10      rogo      169:       temp = new File(tmpPath, "fm2sql.txt");
1.8       rogo      170:       int count = 1;
                    171:       while (temp.exists())
                    172:       {
                    173:         temp = new File(tmpPath, "fm2sql" + generateSuffix(count++) + ".txt");
                    174:       }
1.4       rogo      175:       file = new FileOutputStream(temp);
                    176:     } catch (FileNotFoundException e1)
                    177:     {
                    178:       e1.printStackTrace();
                    179:     }
                    180:     PrintStream stream = new PrintStream(file, true);
1.8       rogo      181:     // write info for user to stdout
                    182:     System.out.println(versionID);
1.10      rogo      183:     System.out.println("Loading " + args[0] + "....");
                    184:     System.out.println("Log  will be written to " + temp.getCanonicalPath());
1.8       rogo      185: 
1.4       rogo      186:     if (!debug)
                    187:     {
                    188:       System.setOut(stream);
                    189:       System.setErr(stream);
                    190:     }
1.7       rogo      191:     System.out.println(versionID);
1.10      rogo      192:     System.out.println("Using config file : " + args[0] + "....");
                    193: 
1.4       rogo      194:     StringBuffer sb = readXMLFile(args[0]);
                    195:     parseXMLConfig(sb);
                    196:     if (!(new File(args[0]).exists()))
1.7       rogo      197:     {
                    198: 
1.4       rogo      199:       System.exit(0);
1.7       rogo      200:     }
1.4       rogo      201:     System.out.println("Finished!");
                    202:     // convert("jdbc:fmpro:http://141.14.237.74:8050","jdbc:postgresql://erebos/test",null,null);
                    203:   }
                    204: 
                    205:   public static void convertBatch(DBBean source, DBBean destination, Vector names, Vector layouts,
                    206:       Vector selects, Vector creates, Vector ids, int mode, String delimiter) throws Exception
                    207:   {
                    208:     bean = source;
                    209:     beanDest = destination;
                    210:     convert(null, null, names, layouts, selects, creates, ids, mode, delimiter);
                    211:   }
                    212: 
                    213:   public static String formatFileMakerArray(List list, String delimiter)
                    214:   {
                    215:     StringBuffer formattedString = new StringBuffer();
                    216:     for (int i = 0; i < list.size(); ++i)
                    217:     {
                    218:       formattedString.append(list.get(i).toString());
                    219:       if (i < list.size() - 1)
                    220:         formattedString.append(delimiter);
                    221:     }
                    222:     return formattedString.toString();
                    223:   }
                    224: 
                    225:   /**
                    226:    * Method for SQL UPDATE
                    227:    * 
                    228:    * @param source
                    229:    * @param destination
                    230:    * @param names
                    231:    * @param layouts
                    232:    * @param selects
                    233:    * @param creates
                    234:    * @param ids
                    235:    * @param mode
                    236:    * @throws Exception
                    237:    */
                    238:   public static void update(String source, String destination, Vector names, Vector layouts,
                    239:       Vector selects, Vector creates, Vector ids, int mode) throws Exception
                    240:   {
                    241: 
                    242:     FM2SQL.ProgressDialog dialog = null;
                    243:     if (isGUI)
                    244:     {
                    245:       dialog = initDialog();
                    246:     }
                    247:     // setting user and passwd
                    248:     bean.setUserAndPasswd(user, passwd);
                    249:     // setting user and passwd
                    250:     beanDest.setUserAndPasswd(userDest, passwdDest);
                    251: 
                    252:     StringBuffer command = null;
                    253:     String query = null;
                    254:     try
                    255:     {
                    256: 
                    257:       bean.setConnection(source);
                    258: 
                    259:       if (names == null)
                    260:         names = bean.getTableNames();
                    261:       // Collections.sort(names);
                    262:       int tbIndex = 1;
                    263: 
                    264:       System.out.println("Start at table " + names.firstElement());
                    265:       for (tbIndex = 0; tbIndex < names.size(); ++tbIndex)
                    266:       {
                    267:         Vector[] result = null;
                    268:         String destTableName = "";
                    269:         try
                    270:         {
                    271:           query = "select * from " + bean.getQC() + names.get(tbIndex).toString() + bean.getQC();
                    272:           String layout = (layouts.isEmpty()) ? "" : layouts.get(tbIndex).toString();
                    273:           query = (selects != null) ? selects.get(tbIndex).toString() : query;
                    274:           // if vectors[1].get(i) != null)
1.10      rogo      275:           if (!layout.equals(""))
1.4       rogo      276:           {
1.11      rogo      277: 
1.4       rogo      278:             query = addLayoutToQuery(names, query, tbIndex, layout);
                    279: 
                    280:           }
                    281:           if (dialog != null)
                    282:           {
                    283:             prepareDialogforUse(names, dialog, tbIndex);
                    284:           }
                    285:           bean.getConnection();
                    286:           bean.makeQuery(query, 0);
                    287: 
                    288:         } catch (Exception e)
                    289:         {
                    290:           System.out.println("Warning exception occured \n " + e);
                    291: 
                    292:           continue;
                    293:         }
                    294:         // determine destTableName from createStatement or from source
                    295:         // table name
                    296:         if (!creates.get(tbIndex).equals(""))
                    297:         {
                    298:           String create = creates.get(tbIndex).toString().toLowerCase();
                    299:           int fromIndex = create.indexOf("table") + 5;
                    300:           int toIndex = create.indexOf("(");
                    301:           destTableName = create.substring(fromIndex, toIndex).replaceAll(beanDest.getQC(), "")
                    302:               .trim();
                    303:           System.out.println("destTable " + destTableName);
                    304: 
                    305:         } else
                    306:           destTableName = convertText(names.get(tbIndex).toString());
                    307: 
                    308:         beanDest.setConnection(destination);
                    309: 
                    310:         Statement stm = beanDest.getConnection().createStatement();
                    311: 
                    312:         Vector tables = beanDest.getTableNames();
                    313: 
                    314:         System.out.println(names.get(tbIndex) + " "
                    315:             + tables.indexOf(convertText((String) names.get(tbIndex)))); // "//beanDest.getTypeNames());
                    316:         tables = beanDest.getTableNames();
                    317:         stm = beanDest.getConnection().createStatement();
                    318: 
                    319:         if (dialog != null)
                    320:           dialog.title.setText("Updating table data ...");
                    321:         else
                    322:           System.out.println("Updating table data ...");
                    323:         int j = -1;
                    324: 
                    325:         Vector row = null;
                    326:         command = new StringBuffer();
                    327: 
                    328:         command.append("UPDATE ");
                    329:         command.append(beanDest.getQC());
                    330:         command.append(destTableName);
                    331:         // command.append(convertText((String) names.get(tbIndex)));
                    332:         command.append(beanDest.getQC());
                    333:         command.append(" SET  ");
                    334: 
                    335:         int size = bean.getColumnNames().size();
                    336:         for (int i = 0; i < size - 1; ++i)
                    337:           command.append(beanDest.getQC() + convertText((String) bean.getColumnNames().get(i))
                    338:               + beanDest.getQC() + " = ? ,");
                    339:         command.append(convertText((String) bean.getColumnNames().get(size - 1)) + " = ? ");
                    340:         command.append("WHERE " + convertText(ids.get(tbIndex).toString()) + " =  ?");
                    341:         PreparedStatement pstm = beanDest.getConnection().prepareStatement(command.toString());
                    342:         System.out.println(command + " " + tbIndex);
                    343:         int rowCount = bean.getRowCount(query);
                    344:         int idIndex = bean.getColumnNames().indexOf(ids.get(tbIndex));
                    345:         while ((row = bean.getNextRow()) != null)
                    346:         {
                    347:           j++;
                    348:           // print rows
                    349:           Object obj = null;
                    350:           for (int k = 0; k < row.size(); ++k)
                    351:           {
                    352:             obj = row.get(k);
                    353:             if (obj instanceof ArrayList)
                    354:               obj = ((List) obj).get(0);
                    355:             String str = (obj == null) ? "NULL" : obj.toString();
                    356:             if (!str.equals("NULL"))
                    357:               pstm.setString(k + 1, str);
                    358:             else
                    359:               pstm.setNull(k + 1, Types.NULL);
                    360:           }
                    361:           pstm.setString(row.size() + 1, row.get(idIndex).toString());
                    362:           pstm.execute();
                    363:           if (dialog != null)
                    364:             dialog.progress.setValue((int) (((double) (j + 1) / (double) rowCount) * 100.0));
                    365:           command = null;
                    366:         } // to for loop
                    367: 
                    368:       }
                    369:     } catch (Exception e)
                    370:     {
                    371:       System.out.println("Error while connecting to database " + e);
                    372:       if (isGUI)
                    373:       {
                    374:         showExceptionDialog(dialog, command, e);
                    375:       } else
                    376:       {
                    377:         e.printStackTrace();
                    378: 
                    379:       }
                    380:     } finally
                    381:     {
                    382:       if (isGUI)
                    383:       {
                    384:         resetGUI(dialog);
                    385:       }
                    386:     }
                    387:   }
                    388: 
                    389:   /**
                    390:    * @param dialog
                    391:    */
                    392:   private static void resetGUI(FM2SQL.ProgressDialog dialog)
                    393:   {
                    394:     dialog.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
                    395:     FM2SQL.fmInstance.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
                    396:     dialog.setVisible(false);
                    397:   }
                    398: 
                    399:   /**
                    400:    * @param dialog
                    401:    * @param command
                    402:    * @param e
                    403:    */
                    404:   private static void showExceptionDialog(FM2SQL.ProgressDialog dialog, StringBuffer command,
                    405:       Exception e)
                    406:   {
                    407:     dialog.setVisible(false);
                    408:     dialog.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
                    409:     FM2SQL.fmInstance.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
                    410:     java.io.ByteArrayOutputStream b = new java.io.ByteArrayOutputStream();
                    411:     java.io.PrintStream stream = new java.io.PrintStream(b);
                    412:     stream.print(command + "\n\n");
                    413:     e.printStackTrace(stream);
                    414:     FM2SQL.showErrorDialog(b.toString(), "Error occured !");
                    415:   }
                    416: 
                    417:   /**
                    418:    * @return
                    419:    */
                    420:   private static FM2SQL.ProgressDialog initDialog()
                    421:   {
                    422:     FM2SQL.ProgressDialog dialog;
                    423:     dialog = new FM2SQL.ProgressDialog(FM2SQL.fmInstance, bean);
                    424:     dialog.setTitle("Conversion running ...");
                    425:     dialog.title.setText("Getting table data ...");
                    426:     dialog.setLocation(FM2SQL.fmInstance.getLocationOnScreen().x
                    427:         + (FM2SQL.fmInstance.getWidth() - 400) / 2, FM2SQL.fmInstance.getLocationOnScreen().y
                    428:         + (FM2SQL.fmInstance.getHeight() - 250) / 2);
                    429:     dialog.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
                    430:     FM2SQL.fmInstance.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
                    431:     dialog.thread = Thread.currentThread();
                    432:     dialog.setSize(420, 250);
                    433:     return dialog;
                    434:   }
                    435: 
                    436:   /**
                    437:    * transfers the specified array of tables to the destination database and
                    438:    * creates the table if it does not exist if it exists and mode is not append
                    439:    * the table is dropped
                    440:    * 
                    441:    * @param source
                    442:    * @param destination
                    443:    * @param names
                    444:    * @param layouts
                    445:    * @param selects
                    446:    * @param creates
                    447:    * @param ids
                    448:    * @param mode
                    449:    * @throws Exception
                    450:    */
                    451: 
                    452:   public static void convert(String source, String destination, Vector names, Vector layouts,
                    453:       Vector selects, Vector creates, Vector ids, int mode, String delimiter) throws Exception
                    454:   {
1.7       rogo      455:     // TODO implement convert_temp mode!!! 
1.4       rogo      456:     FM2SQL.ProgressDialog dialog = null;
                    457: 
                    458:     if (isGUI)
                    459:     {
                    460:       dialog = initDialog();
                    461:     }
                    462: 
                    463:     System.out.println("connection established " + source + " " + bean.url);
                    464: 
                    465:     java.util.TreeSet myIds = new TreeSet();
                    466:     int deltaID = 1;
                    467:     String idField = "";
                    468:     String destTableName = "";
                    469:     String[] fieldNames = null;
                    470: 
                    471:     if (source != null && destination != null)
                    472:     {
                    473:       // setting user and passwd
                    474:       bean.setUserAndPasswd(user, passwd);
                    475:       // setting user and passwd
                    476:       beanDest.setUserAndPasswd(userDest, passwdDest);
                    477:     }
                    478: 
                    479:     StringBuffer command = null;
                    480:     String query = null;
                    481:     try
                    482:     {
                    483: 
                    484:       if (source != null)
                    485:         bean.setConnection(source);
                    486:       else
                    487:         bean.setConnection(bean.url);
                    488:       if (names == null)
                    489:         names = bean.getTableNames();
                    490:       int tbIndex = 1;
                    491: 
                    492:       for (tbIndex = 0; tbIndex < names.size(); ++tbIndex)
                    493:       {
                    494:         Vector[] result = null;
                    495:         try
                    496:         {
                    497:           String layout = (layouts.isEmpty()) ? "" : layouts.get(tbIndex).toString();
                    498:           query = (selects != null) ? selects.get(tbIndex).toString() : "select * from "
                    499:               + bean.getQC() + names.get(tbIndex).toString() + bean.getQC();
1.10      rogo      500:           if (layout.intern() != "")
1.4       rogo      501:           {
                    502:             query = addLayoutToQuery(names, query, tbIndex, layout);
                    503: 
                    504:           }
                    505:           if (dialog != null)
                    506:           {
                    507:             prepareDialogforUse(names, dialog, tbIndex);
                    508:           }
                    509: 
                    510:           bean.getConnection();
                    511:           bean.makeQuery(query, 50);
                    512:           idField = ids.get(tbIndex).toString();
                    513: 
                    514:         } catch (Exception e)
                    515:         {
                    516:           System.out.println("Warning exception occured \n " + e);
                    517: 
                    518:           continue;
                    519:         }
                    520:         if (destination != null)
                    521:           beanDest.setConnection(destination);
                    522:         else
                    523:           beanDest.setConnection(beanDest.url);
                    524:         Statement stm = beanDest.getConnection().createStatement();
                    525: 
                    526:         Vector tables = beanDest.getTableNames();
                    527:         // Collections.sort(tables);
                    528:         System.out.println(names.get(tbIndex) + " "
                    529:             + tables.indexOf(convertText((String) names.get(tbIndex)))); // "//beanDest.getTypeNames());
                    530:         tables = beanDest.getTableNames();
                    531:         // System.out.println(beanDest.getTableNames(beanDest.getCatalogs().get(2).toString()));
                    532:         stm = beanDest.getConnection().createStatement();
                    533:         // System.exit(0);
                    534: 
                    535:         // determine destTableName from createStatement or from source
                    536:         // table name
                    537:         ConversionProperties prop = getFieldNamesAndDestTableName(creates.get(tbIndex).toString(),
                    538:             query, names.get(tbIndex).toString());
                    539:         destTableName = prop.destTableName;
1.7       rogo      540:         if (mode == Convert.DataBase.CONVERT_TEMP_MODE)
                    541:         {
1.11      rogo      542:           destTableName += _TEMP;
1.7       rogo      543:         }
1.4       rogo      544:         fieldNames = prop.fieldNames;
1.7       rogo      545:         if (mode == Convert.DataBase.CONVERT_MODE || mode == Convert.DataBase.CONVERT_TEMP_MODE)
1.4       rogo      546:         {
                    547: 
                    548:           if (tables.indexOf(destTableName) >= 0)
                    549:           {
                    550:             stm.executeUpdate("drop table " + beanDest.getQC() + destTableName + beanDest.getQC());
                    551:             tables.remove(destTableName);
                    552:             System.out.println("dropped table" + destTableName);
                    553:           }
                    554:           if ((tables.indexOf(destTableName) < 0))
                    555:           {
                    556: 
                    557:             if (creates.get(tbIndex).equals("")
                    558:                 || creates.get(tbIndex).toString().toLowerCase().indexOf("create") < 0)
                    559:             {
                    560:               System.out
                    561:                   .println("Warning empty or invalid create statement - creating one for you\n");
                    562: 
                    563:               command = new StringBuffer(50);
                    564:               command.append("CREATE TABLE ");
                    565:               command.append(beanDest.getQC());
1.7       rogo      566:               command.append(destTableName);//convertText((String) names.get(tbIndex)));
1.4       rogo      567:               command.append(beanDest.getQC());
                    568:               command.append("(");
                    569:               String type = null;
                    570:               Vector columnNames = bean.getColumnNames();
                    571:               for (int i = 0; i < columnNames.size() - 1; ++i)
                    572:               {
                    573:                 type = bean.metaData.getColumnTypeName(i + 1);
                    574:                 // System.out.println(i+" "+result[1].get(i)+"
                    575:                 // "+type);
                    576:                 type = (type.equals("NUMBER")) ? "INT4" : type;
                    577:                 type = (type.equals("CONTAINER")) ? "TEXT" : type;
                    578: 
                    579:                 command.append(beanDest.getQC() + convertText((String) columnNames.get(i))
                    580:                     + beanDest.getQC() + " " + type + ", ");
                    581:               }
                    582:               type = bean.metaData.getColumnTypeName(columnNames.size());
                    583:               type = (type.equals("NUMBER")) ? "INT4" : type;
                    584:               type = (type.equals("CONTAINER")) ? "TEXT" : type;
                    585:               command.append(beanDest.getQC()
                    586:                   + convertText((String) columnNames.get(columnNames.size() - 1))
                    587:                   + beanDest.getQC() + " " + type);
                    588:               command.append(" )");
                    589: 
                    590:             } else
                    591:               command = new StringBuffer().append(creates.get(tbIndex).toString().toLowerCase());
                    592:             stm.executeUpdate(command.toString());
                    593: 
                    594:           }
                    595:         }
                    596:         if (dialog != null)
                    597:           dialog.title.setText("Writing table data ...");
                    598: 
                    599:         // prepare the insert statement
                    600:         int j = -1;
                    601:         Vector row = null;
                    602:         command = new StringBuffer();
                    603: 
                    604:         command.append("INSERT  INTO ");
                    605:         command.append(beanDest.getQC());
                    606:         command.append(destTableName);
                    607:         command.append(beanDest.getQC());
                    608:         command.append(" (");
                    609:         for (int i = 0; i < fieldNames.length; i++)
                    610:         {
                    611:           command.append(fieldNames[i]);
                    612:           if (i < fieldNames.length - 1)
                    613:             command.append(",");
                    614:         }
                    615:         command.append(") ");
                    616: 
                    617:         command.append(" values ( ");
                    618:         // add a question marks for every field
                    619:         for (int i = 0; i < bean.getColumnNames().size() - 1; ++i)
                    620:           command.append("?,");
                    621:         command.append("?)");
                    622:         PreparedStatement pstm = beanDest.getConnection().prepareStatement(command.toString());
                    623:         System.out.println(command);
                    624:         int rowCount = (idField != "") ? myIds.size() : bean.getRowCount(query);
                    625:         Vector vec = new Vector(myIds);
                    626:         int endIndex = -1;
                    627:         String tempQuery = query;
                    628:         String tempID = bean.getQC() + idField + bean.getQC();
                    629:         // if id_field not do incremental conversion else do it all at
                    630:         // once
                    631:         if (!idField.equals(""))
                    632:         {
                    633:           long startTime = System.currentTimeMillis();
                    634:           int counter = -1;
                    635:           while (true)
                    636:           {
                    637:             ++counter;
                    638:             if (counter == 0 && dialog != null)
                    639:               dialog.title.setText("Check if data  is available");
                    640:             else if (dialog != null)
                    641:               dialog.title.setText("Check if more  data  is available");
                    642:             myIds = bean.getIDVector(ids.get(tbIndex).toString(), (String) names.get(tbIndex),
                    643:                 tempQuery, numHits);
                    644:             if (myIds.isEmpty())
                    645:               break;
                    646:             vec = new Vector(myIds);
                    647:             rowCount = vec.size();
                    648:             System.out.println("ID LIST SIZE "
                    649:                 + Math.round((double) myIds.size() / (double) numIntervalls) + " " + myIds.size());
                    650:             deltaID = (int) Math.round((double) myIds.size() / (double) numIntervalls);
                    651:             if (vec.size() <= numIntervalls)
                    652:             {
                    653:               endIndex = 0;
                    654:               deltaID = vec.size();
                    655:             }
                    656:             for (int k = 0; k < vec.size() - deltaID; k = k + deltaID)
                    657:             {
                    658:               System.out.println(vec.get(k) + " " + vec.get(k + deltaID) + " " + vec.lastElement());
                    659:               if (query.indexOf("where") > 0)
                    660:                 tempQuery = query + " and " + tempID + ">='" + vec.get(k) + "' and " + tempID
                    661:                     + "<='" + vec.get(k + deltaID) + "'";
                    662:               else
                    663:                 tempQuery = query + " where " + tempID + ">='" + vec.get(k) + "' and " + tempID
                    664:                     + "<='" + vec.get(k + deltaID) + "'";
                    665:               System.out.println(tempQuery);
                    666:               if (dialog != null)
                    667:                 dialog.title.setText("Reading table data ...");
                    668: 
                    669:               bean.makeQuery(tempQuery, deltaID);
                    670:               if (dialog != null)
                    671:                 dialog.title.setText("Writing table data ...");
                    672: 
                    673:               command = writeDatainDestTable(dialog, command, k, pstm, rowCount, delimiter);
                    674:               endIndex = k + deltaID;
                    675:             }
                    676:             System.out.println(endIndex);
                    677:             // all data written ? if not write last chunk of data
                    678:             if (endIndex == vec.size() - 1)
                    679:               System.out.println("fits");
                    680:             else
                    681:             {
                    682:               System.out.println(" last intervall from " + vec.get(endIndex) + " "
                    683:                   + vec.lastElement());
                    684: 
                    685:               if (query.indexOf("where") > 0)
                    686:                 tempQuery = query + " and " + tempID + ">='" + vec.get(endIndex) + "' and "
                    687:                     + tempID + "<='" + vec.lastElement() + "'";
                    688:               else
                    689:                 tempQuery = query + " where " + tempID + ">='" + vec.get(endIndex) + "' and "
                    690:                     + tempID + "<='" + vec.lastElement() + "'";
                    691:               System.out.println(tempQuery);
                    692:               if (dialog != null)
                    693:                 dialog.title.setText("Reading table data ...");
                    694:               bean.makeQuery(tempQuery, 0);
                    695:               if (dialog != null)
                    696:                 dialog.title.setText("Writing table data ...");
                    697:               command = writeDatainDestTable(dialog, command, endIndex, pstm, rowCount, delimiter);
                    698:             }
                    699:             // prepare new query for next chunk
                    700:             if (query.indexOf("where") > 0)
                    701:               tempQuery = query + " and " + tempID + ">'" + vec.lastElement() + "'";
                    702:             else
                    703:               tempQuery = query + " where " + tempID + ">'" + vec.lastElement() + "'";
                    704: 
                    705:           }
                    706:           long endTime = System.currentTimeMillis();
                    707:           System.out.println("Time for incremental convert elapsed " + (endTime - startTime));
                    708:         } else
                    709:         {
                    710:           // read and write all in one big chunk
                    711:           long startTime = System.currentTimeMillis();
                    712: 
                    713:           bean.makeQuery(query, 0);
1.10      rogo      714:           System.err.println("query for whole table done");
1.4       rogo      715:           command = writeDatainDestTable(dialog, command, j, pstm, rowCount, delimiter);
                    716:           long endTime = System.currentTimeMillis();
                    717:           System.out.println("Time for old convert elapsed " + (endTime - startTime));
                    718: 
                    719:         }
                    720:         if (isGUI)
                    721:           resetGUI(dialog);
1.10      rogo      722:         noError = true;
1.11      rogo      723:         if (mode == Convert.DataBase.CONVERT_TEMP_MODE)
                    724:         {
                    725:           String originalName = destTableName.split(_TEMP)[0];
                    726:           // TODO 
                    727:           if (beanDest.getTableNames().contains(originalName))
                    728:           {
1.13    ! rogo      729:             DateFormat d = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM);
1.11      rogo      730:             d.setTimeZone(java.util.TimeZone.getTimeZone("CET"));
1.13    ! rogo      731:           
1.11      rogo      732:             String date = d.format(new Date());
                    733:             date = date.replace(':', '_');
1.13    ! rogo      734:             String newName = addQuotes(beanDest, convertText(originalName + "_" + date));
        !           735:             // rename table to newName
        !           736:             renameTable(beanDest, addQuotes(beanDest, originalName), newName);
1.11      rogo      737:           }
1.13    ! rogo      738:           // rename Table_temp to originalName
1.11      rogo      739:           renameTable(beanDest, addQuotes(beanDest, destTableName), addQuotes(beanDest,
                    740:               originalName));
                    741:         }
1.4       rogo      742:       }
                    743:     } catch (Exception e)
                    744:     {
1.10      rogo      745:       System.out.println("Error while connecting to database " + e.getMessage());
                    746:       noError = false;
1.4       rogo      747:       if (isGUI)
                    748:       {
                    749:         showExceptionDialog(dialog, command, e);
                    750:         resetGUI(dialog);
                    751:       } else
                    752:       {
                    753:         e.printStackTrace();
                    754: 
                    755:       }
1.10      rogo      756:     } catch (Error e)
                    757:     {
1.11      rogo      758:       noError = false;
                    759: 
1.10      rogo      760:       System.out.println(e);
                    761:       e.printStackTrace();
1.4       rogo      762:     }
                    763: 
                    764:   }
                    765: 
                    766:   /**
1.11      rogo      767:    *
                    768:    * @param beanDest2
                    769:    * @param originalName
                    770:    * @return
                    771:    */
                    772:   private static String addQuotes(DBBean bean, String originalName)
                    773:   {
                    774:     return bean.getQC() + originalName + bean.getQC();
                    775:   }
                    776: 
                    777:   /**
1.4       rogo      778:    * @param names
                    779:    * @param dialog
                    780:    * @param tbIndex
                    781:    */
                    782:   private static void prepareDialogforUse(Vector names, FM2SQL.ProgressDialog dialog, int tbIndex)
                    783:   {
                    784:     dialog.title.setText("Reading table data ...");
                    785:     dialog.table.setText(names.get(tbIndex).toString());
                    786:     dialog.status.setText("Table " + (tbIndex + 1) + " of " + names.size());
                    787:     dialog.setVisible(true);
                    788:   }
                    789: 
                    790:   /**
                    791:    * @param names
                    792:    * @param query
                    793:    * @param tbIndex
                    794:    * @param layout
                    795:    * @return
                    796:    */
                    797:   private static String addLayoutToQuery(Vector names, String query, int tbIndex, String layout)
                    798:   {
                    799:     layout = " layout " + bean.getQC() + layout + bean.getQC();
                    800:     String name = names.get(tbIndex).toString();
                    801:     StringBuffer queryLayout = new StringBuffer(query);
                    802:     queryLayout.insert(queryLayout.indexOf(name) + name.length() + 1, " " + layout);
                    803:     query = queryLayout.toString();
                    804:     System.out.println("added layout  " + query);
                    805:     return query;
                    806:   }
                    807: 
                    808:   /**
                    809:    * Writes data to the destination table
                    810:    * 
                    811:    * @param dialog
                    812:    *          progress dialog
                    813:    * @param command
                    814:    * @param j
                    815:    *          data index for progress bar
                    816:    * @param pstm
                    817:    *          prepared statement
                    818:    * @param rowCount
                    819:    *          number of datasets
                    820:    * @return command
                    821:    * @throws Exception
                    822:    * @throws SQLException
                    823:    */
                    824:   private static StringBuffer writeDatainDestTable(FM2SQL.ProgressDialog dialog,
                    825:       StringBuffer command, int j, PreparedStatement pstm, int rowCount, String delimiter)
                    826:       throws Exception, SQLException
                    827:   {
                    828:     Vector row;
                    829:     while ((row = bean.getNextRow()) != null)
                    830:     {
                    831:       j++;
                    832:       Object obj = null;
                    833:       for (int k = 0; k < row.size(); ++k)
                    834:       {
                    835:         obj = row.get(k);
                    836: 
                    837:         if (obj instanceof ArrayList)
                    838:           obj = formatFileMakerArray((List) obj, delimiter);
                    839: 
                    840:         String str = (obj == null) ? "NULL" : obj.toString();
                    841:         if (obj instanceof Double)
                    842:         {
                    843:           pstm.setDouble(k + 1, ((Double) obj).doubleValue());
                    844:         } else if (!str.equals("NULL"))
                    845:           pstm.setString(k + 1, str);
                    846:         else
                    847:           pstm.setNull(k + 1, Types.NULL);
                    848:       }
                    849:       pstm.execute();
                    850:       if (isGUI)
                    851:         dialog.progress.setValue((int) (((double) (j + 1) / (double) rowCount) * 100.0));
                    852:       command = null;
                    853:     } // to while loop
                    854:     return command;
                    855:   }
                    856: 
                    857:   /**
                    858:    * removes special characters from the input string as well as .fp5
                    859:    * 
                    860:    * @param newName
                    861:    *          String to change
                    862:    * @return
                    863:    */
                    864:   public static String convertText(String newName)
                    865:   {
                    866:     StringBuffer alterMe = new StringBuffer(newName.trim().toLowerCase());
                    867:     int length = alterMe.length();
                    868:     int j = 0;
                    869:     int index = alterMe.indexOf(".fp5");
                    870:     if (index >= 0)
                    871:     {
                    872:       alterMe.delete(index, index + 4);
                    873:       length = length - 4;
                    874:     }
                    875: 
                    876:     while (j < length)
                    877:     {
                    878:       if (alterMe.charAt(j) == ' ')
                    879:       {
                    880:         alterMe.setCharAt(j, '_');
                    881:         // if(j<length-1) j=j+1;
                    882:       } else if (alterMe.charAt(j) == '_')
                    883:       {
                    884: 
                    885:         if (alterMe.charAt(j + 1) == '_')
                    886:           alterMe.deleteCharAt(j);
                    887:         length = length - 1;
                    888:         // if(j<length-1) j=j+1;
                    889:       } else if (alterMe.charAt(j) == 'ä')
                    890:       {
                    891:         alterMe.setCharAt(j, 'a');
                    892:         alterMe.insert(j + 1, "e");
                    893:         length = length + 1;
                    894:         if (j < length - 1)
                    895:           j = j + 1;
                    896:       } else if (alterMe.charAt(j) == 'ö')
                    897:       {
                    898:         alterMe.setCharAt(j, 'o');
                    899:         alterMe.insert(j + 1, "e");
                    900:         length = length + 1;
                    901:         if (j < length - 1)
                    902:           j = j + 1;
                    903:       } else if (alterMe.charAt(j) == 'ü')
                    904:       {
                    905:         alterMe.setCharAt(j, 'u');
                    906:         alterMe.insert(j + 1, "e");
                    907:         length = length + 1;
                    908:         if (j < length - 1)
                    909:           j = j + 1;
                    910:       } else if (alterMe.charAt(j) == 'ß')
                    911:       {
                    912:         alterMe.setCharAt(j, 's');
                    913:         alterMe.insert(j + 1, "s");
                    914:         length = length + 1;
                    915:         if (j < length - 1)
                    916:           j = j + 1;
                    917:       } else if (alterMe.charAt(j) == ':')
                    918:       {
                    919:         if (j < length - 1)
                    920:         {
                    921:           if (alterMe.charAt(j + 1) == ':')
                    922:           {
                    923:             alterMe.setCharAt(j, '_');
                    924:             alterMe.delete(j + 1, j + 2);
                    925:             length = length - 1;
                    926: 
                    927:           }
                    928: 
                    929:           if (j < length - 1)
                    930:             j = j + 1;
                    931:         }
                    932:       } else if (alterMe.charAt(j) == '-')
                    933:       {
                    934:         alterMe.setCharAt(j, '_');
                    935: 
                    936:       } else if (alterMe.charAt(j) == '?')
                    937:       {
                    938:         // changed ? to _ because of update statement
                    939:         alterMe.setCharAt(j, '_');
                    940:         // length = length + 1;
                    941:         // j=j+1;
                    942:         System.out.println(alterMe);
                    943:       } else if (alterMe.charAt(j) == '.')
                    944:       {
                    945:         if (j == length - 1)
                    946:         {
                    947:           alterMe.delete(j, j);
                    948:           length--;
                    949:         } else
                    950:           alterMe.setCharAt(j, '_');
                    951:       }
                    952: 
                    953:       ++j;
                    954:     }
                    955:     return alterMe.toString();
                    956:   }
                    957: 
                    958:   /**
                    959:    * Converts > and < in an entity (&gt; or &lt;)
                    960:    * 
                    961:    * @param newName
                    962:    * @return
                    963:    */
                    964:   public static String convertToEntities(String newName)
                    965:   {
                    966:     StringBuffer alterMe = new StringBuffer(newName.trim());
                    967:     int length = alterMe.length();
                    968:     int j = 0;
                    969: 
                    970:     while (j < length)
                    971:     {
                    972: 
                    973:       if (alterMe.charAt(j) == '>')
                    974:       {
                    975:         alterMe.setCharAt(j, '&');
                    976:         alterMe.insert(j + 1, "gt;");
                    977:         length = length + 2;
                    978:         if (j < length - 1)
                    979:           j = j + 1;
                    980: 
                    981:       } else if (alterMe.charAt(j) == '<')
                    982:       {
                    983:         alterMe.setCharAt(j, '&');
                    984:         alterMe.insert(j + 1, "lt;");
                    985:         length = length + 2;
                    986:         if (j < length - 1)
                    987:           j = j + 1;
                    988: 
                    989:       }
                    990:       ++j;
                    991:     }
                    992:     return alterMe.toString();
                    993:   }
                    994: 
                    995:   /**
                    996:    * Masks the single quote character '-->\'
                    997:    * 
                    998:    * @param newName
                    999:    * @return
                   1000:    */
                   1001:   public static String convertUml(String newName)
                   1002:   {
                   1003:     StringBuffer alterMe = new StringBuffer(newName.trim());
                   1004:     int length = alterMe.length();
                   1005:     int j = 0;
                   1006: 
                   1007:     while (j < length)
                   1008:     {
                   1009: 
                   1010:       if (alterMe.charAt(j) == '\'')
                   1011:       {
                   1012:         alterMe.setCharAt(j, '\\');
                   1013:         alterMe.insert(j + 1, "'");
                   1014:         length = length + 1;
                   1015:         if (j < length - 1)
                   1016:           j = j + 1;
                   1017:       }
                   1018:       /*
                   1019:        * else if (alterMe.charAt(j) == '"') { alterMe.setCharAt(j, '\\');
                   1020:        * alterMe.insert(j + 1, "\""); length = length + 1; if(j <length-1)
                   1021:        * j=j+1; } else if (alterMe.charAt(j) == '>') { alterMe.setCharAt(j,
                   1022:        * '\\'); alterMe.insert(j + 1, ">"); length = length + 1; if(j <length-1)
                   1023:        * j=j+1; } else if (alterMe.charAt(j) == ' <') { alterMe.setCharAt(j,
                   1024:        * '\\'); alterMe.insert(j + 1, " <"); length = length + 1; if(j
                   1025:        * <length-1) j=j+1; } else if (alterMe.charAt(j) == '?') {
                   1026:        * alterMe.setCharAt(j, '\\'); alterMe.insert(j + 1, "?"); length = length +
                   1027:        * 1; if(j <length-1) j=j+1; } else if (alterMe.charAt(j) == '&') {
                   1028:        * alterMe.setCharAt(j, '\\'); alterMe.insert(j + 1, "&"); length = length +
                   1029:        * 1; if(j <length-1) j=j+1; } else if (alterMe.charAt(j) == '=') {
                   1030:        * alterMe.setCharAt(j, '\\'); alterMe.insert(j + 1, "="); length = length +
                   1031:        * 1; if(j <length-1) j=j+1; } else if (alterMe.charAt(j) == ',') {
                   1032:        * alterMe.setCharAt(j, '\\'); alterMe.insert(j + 1, ","); length = length +
                   1033:        * 1; if(j <length-1) j=j+1; } else if (alterMe.charAt(j) == '.') {
                   1034:        * alterMe.setCharAt(j, '\\'); alterMe.insert(j + 1, "."); length = length +
                   1035:        * 1; if(j <length-1) j=j+1; } else if (alterMe.charAt(j) == '[') {
                   1036:        * alterMe.setCharAt(j, '\\'); alterMe.insert(j + 1, "."); length = length +
                   1037:        * 1; if(j <length-1) j=j+1; } else if (alterMe.charAt(j) == ']') {
                   1038:        * alterMe.setCharAt(j, '\\'); alterMe.insert(j + 1, "."); length = length +
                   1039:        * 1; if(j <length-1) j=j+1; } else if (alterMe.charAt(j) == '%') {
                   1040:        * alterMe.setCharAt(j, '\\'); alterMe.insert(j + 1, "%"); length = length +
                   1041:        * 1; if(j <length-1) j=j+1; }
                   1042:        */
                   1043:       ++j;
                   1044:     }
                   1045:     return alterMe.toString();
                   1046:   }
                   1047: 
                   1048:   /**
                   1049:    * parses the input xml file for batch conversion called from readXMLFile *
                   1050:    * 
                   1051:    * @param sb
                   1052:    */
                   1053:   public static void parseXMLConfig(StringBuffer sb)
                   1054:   {
                   1055:     // boolean finished = false;
                   1056:     Vector databases = new Vector();
                   1057:     try
                   1058:     {
                   1059:       databases = getXMLConfig(sb);
1.7       rogo     1060: 
1.6       rogo     1061:       // destination DataBase object
1.7       rogo     1062:       DataBase dbDest = ((DataBase) databases.lastElement());
1.6       rogo     1063: 
1.4       rogo     1064:       DBBean database = ((DataBase) databases.lastElement()).bean;
                   1065:       databases.remove(databases.size() - 1);
1.7       rogo     1066: 
1.6       rogo     1067:       for (Iterator iterator = dbDest.preCommands.iterator(); iterator.hasNext();)
                   1068:       {
                   1069:         SQLCommand sqlCommand = (SQLCommand) iterator.next();
                   1070:         sqlCommand.executeCommand();
                   1071:       }
                   1072: 
1.4       rogo     1073:       // databases.add(database);
                   1074:       for (Iterator iter = databases.iterator(); iter.hasNext();)
                   1075:       {
                   1076:         DataBase db = (DataBase) iter.next();
                   1077:         for (Iterator iterator = db.preCommands.iterator(); iterator.hasNext();)
                   1078:         {
                   1079:           SQLCommand sqlCommand = (SQLCommand) iterator.next();
                   1080:           sqlCommand.executeCommand();
                   1081:         }
                   1082:         int mode = db.mode;
1.10      rogo     1083:         if (mode == DataBase.CONVERT_TEMP_MODE)
                   1084:         {
                   1085:           convertBatch(db.bean, database, db.tables, db.layouts, db.selects, db.creates, db.ids,
                   1086:               mode, db.delimiter);
                   1087:           if (noError)
                   1088:           {
                   1089:             System.out.println("no Error occured ");
                   1090:             //                db.bean.setURL(database.url);
                   1091:             //                db.bean.setUserAndPasswd(database.user,database.passwd);
                   1092:             //
                   1093:             //                Convert.user = db.bean.user;
                   1094:             //                Convert.passwd = db.bean.passwd;
                   1095:             //                userDest = database.user;
                   1096:             //                passwdDest = database.passwd;
                   1097:             //                synchronize(db.bean.url, database.url, db.tables, db.layouts, db.selects, db.creates,
                   1098:             //                    db.ids, mode, db.delimiter, new Vector(db.htIndex.values()));
                   1099:           }
                   1100:         }
                   1101:         if (mode == DataBase.CONVERT_MODE || mode == DataBase.APPEND_MODE)
1.4       rogo     1102:           convertBatch(db.bean, database, db.tables, db.layouts, db.selects, db.creates, db.ids,
                   1103:               mode, db.delimiter);
                   1104:         else if (mode == DataBase.UPDATE_MODE)
                   1105:         {
                   1106: 
                   1107:           Convert.user = db.bean.user;
                   1108:           Convert.passwd = db.bean.passwd;
                   1109:           userDest = database.user;
                   1110:           passwdDest = database.passwd;
                   1111: 
                   1112:           update(db.bean.url, database.url, db.tables, db.layouts, db.selects, db.creates, db.ids,
                   1113:               mode);
                   1114:         } else if (mode == DataBase.SYNCHRONIZE_MODE)
                   1115:         {
                   1116:           Convert.user = db.bean.user;
                   1117:           Convert.passwd = db.bean.passwd;
                   1118:           userDest = database.user;
                   1119:           passwdDest = database.passwd;
                   1120: 
                   1121:           synchronize(db.bean.url, database.url, db.tables, db.layouts, db.selects, db.creates,
                   1122:               db.ids, mode, db.delimiter, new Vector(db.htIndex.values()));
                   1123:         }
                   1124:         for (Iterator iterator = db.postCommands.iterator(); iterator.hasNext();)
                   1125:         {
                   1126:           SQLCommand sqlCommand = (SQLCommand) iterator.next();
                   1127:           sqlCommand.executeCommand();
                   1128:         }
                   1129: 
1.6       rogo     1130:       }
                   1131:       for (Iterator iterator = dbDest.postCommands.iterator(); iterator.hasNext();)
                   1132:       {
                   1133:         SQLCommand sqlCommand = (SQLCommand) iterator.next();
                   1134:         sqlCommand.executeCommand();
1.4       rogo     1135:       }
                   1136: 
                   1137:     } catch (Exception e)
                   1138:     {
                   1139: 
                   1140:       e.printStackTrace();
                   1141: 
                   1142:     } finally
                   1143:     {
                   1144:       bean.closeAllConnections();
                   1145:       beanDest.closeAllConnections();
                   1146:     }
1.11      rogo     1147:   }
                   1148: 
                   1149:   /**
                   1150:    *
                   1151:    * @param database
                   1152:    * @param db 
                   1153:    * @throws Exception 
                   1154:    * @throws SQLException 
                   1155:    */
                   1156:   private static void renameTable(DBBean database, String sourceTable, String destTable)
                   1157:       throws SQLException, Exception
                   1158:   {
                   1159:     String command = "alter table " + sourceTable + " rename " + " to " + destTable;
                   1160:     SQLCommand sqlCommand = new SQLCommand(database, command);
                   1161:     sqlCommand.executeCommand();
1.4       rogo     1162:   }
                   1163: 
                   1164:   public static Vector getXMLConfig(StringBuffer sb)
                   1165:   {
                   1166: 
                   1167:     boolean finished = false;
                   1168:     // parse string and build document tree
                   1169:     Xparse parser = new Xparse();
                   1170:     parser.changeEntities = true;
                   1171:     Node root = parser.parse(sb.toString());
                   1172:     // printContents(root);
                   1173:     Vector databases = new Vector();
                   1174:     Vector tables = new Vector();
                   1175:     Vector layouts = new Vector();
                   1176:     Vector selects = new Vector();
                   1177:     Vector creates = new Vector();
                   1178:     Vector ids = new Vector();
                   1179:     Vector preSQLCommands = new Vector();
                   1180:     Vector postSQLCommands = new Vector();
                   1181: 
                   1182:     String delimiter = "|";
                   1183:     int mode = -1;
                   1184:     try
                   1185:     {
                   1186:       Node tempNode = root.find("convert/source", new int[]
                   1187:       { 1, 1 });
                   1188:       if (tempNode == null)
                   1189:         throw new Error("parse error source tag missing");
                   1190:       System.out.println(tempNode.name);
                   1191:       int length = countNodes(tempNode);
                   1192:       for (int i = 1; i <= length; i++)
                   1193:       {
                   1194: 
                   1195:         DBBean database = new DBBean();
                   1196:         tables = new Vector();
                   1197:         layouts = new Vector();
                   1198:         selects = new Vector();
                   1199:         creates = new Vector();
                   1200:         ids = new Vector();
                   1201:         preSQLCommands = new Vector();
                   1202:         postSQLCommands = new Vector();
                   1203: 
                   1204:         // parse dataBase
                   1205:         Node node = root.find("convert/source/database/url", new int[]
                   1206:         { 1, 1, i, 1 });
                   1207:         Node node1 = root.find("convert/source/database/user", new int[]
                   1208:         { 1, 1, i, 1, 1 });
                   1209:         Node node2 = root.find("convert/source/database/password", new int[]
                   1210:         { 1, 1, i, 1, 1 });
                   1211:         Node node3 = root.find("convert/source/database", new int[]
                   1212:         { 1, 1, i });
                   1213:         Node nodeMode = root.find("convert/source/database/mode", new int[]
                   1214:         { 1, 1, i, 1, 1 });
                   1215:         Node delimiterNode = root.find("convert/source/database/delimiter", new int[]
                   1216:         { 1, 1, i, 1, 1 });
                   1217: 
                   1218:         Node commandNodes = root.find("convert/source/database/sqlcommands", new int[]
                   1219:         { 1, 1, i, 1, 1 });
                   1220:         if (commandNodes != null)
                   1221:         {
                   1222:           parseCommandNode(commandNodes, database, preSQLCommands, postSQLCommands);
                   1223:         }
                   1224:         Node useNormanToUnicodeMapper = root.find(
                   1225:             "convert/source/database/usenormantounicodemapper", new int[]
                   1226:             { 1, 1, i, 1, 1 });
                   1227: 
                   1228:         if (delimiterNode != null)
                   1229:           delimiter = delimiterNode.getCharacters();
                   1230:         if (useNormanToUnicodeMapper != null)
                   1231:         {
                   1232:           database.setUseNormanToUnicodeMapper(Boolean.valueOf(
                   1233:               useNormanToUnicodeMapper.getCharacters()).booleanValue());
                   1234:           System.out.println("useMapper "
                   1235:               + Boolean.valueOf(useNormanToUnicodeMapper.getCharacters().trim()).booleanValue());
                   1236:         }
                   1237: 
                   1238:         if (node3 == null)
                   1239:           throw new Error("parse error database tag missing");
                   1240:         if (node == null)
                   1241:           throw new Error("parse error url tag missing");
                   1242:         if (node1 == null)
                   1243:           throw new Error("parse error user tag missing");
                   1244:         if (node2 == null)
                   1245:           throw new Error("parse error password tag missing");
                   1246:         String url = node.getCharacters();
                   1247:         String user = node1.getCharacters();
                   1248:         String password = node2.getCharacters();
                   1249:         database.setURL(url.trim());
                   1250:         database.setUserAndPasswd(user.trim(), password.trim());
                   1251:         System.out.println(node.name + " " + node.getCharacters());
                   1252:         System.out.println(node1.name + " " + node1.getCharacters());
                   1253:         System.out.println(node2.name + " " + node2.getCharacters());
                   1254:         String modeString = "";
                   1255:         if (nodeMode == null)
                   1256:           modeString = "convert";
                   1257:         else
                   1258:           modeString = nodeMode.getCharacters();
                   1259:         if (modeString.equals("convert"))
                   1260:           mode = DataBase.CONVERT_MODE;
                   1261:         else if (modeString.equals("append"))
                   1262:           mode = DataBase.APPEND_MODE;
                   1263:         else if (modeString.equals("update"))
                   1264:           mode = DataBase.UPDATE_MODE;
                   1265:         else if (modeString.equals("delete"))
                   1266:           mode = DataBase.DELETE_MODE;
                   1267: 
                   1268:         else if (modeString.equals("synchronize"))
                   1269:           mode = DataBase.SYNCHRONIZE_MODE;
1.7       rogo     1270:         else if (modeString.equals("convert_temp"))
                   1271:           mode = DataBase.CONVERT_TEMP_MODE;
                   1272: 
1.4       rogo     1273:         // if(node3!=null)
                   1274:         // System.out.println(node3.name);
                   1275: 
                   1276:         int length2 = countNodes(node3);
                   1277: 
                   1278:         System.out.println("number of tables " + length2);
                   1279: 
                   1280:         for (int j = 1; j <= length2; ++j)
                   1281:         {
                   1282:           Node node4 = root.find("convert/source/database/table", new int[]
                   1283:           { 1, 1, i, j });
                   1284:           Node node5 = root.find("convert/source/database/table/select", new int[]
                   1285:           { 1, 1, i, j, 1 });
                   1286:           Node node6 = root.find("convert/source/database/table/create", new int[]
                   1287:           { 1, 1, i, j, 1 });
                   1288: 
                   1289:           if (node4 != null)
                   1290:             System.out.println(node4.name + " " + node4.attributes.get("layout").equals(""));
                   1291:           if (node5 != null)
                   1292:             System.out.println(node5.name + " " + node5.getCharacters());
                   1293:           if (node6 != null)
                   1294:             System.out.println(node6.name + " " + node6.getCharacters());
                   1295:           if (node4 == null)
                   1296:             throw new Error("parse error table tag missing");
                   1297:           // if(node5==null) throw new Error("parse error select tag
                   1298:           // missing");
                   1299:           // if(node6==null) throw new Error("parse error create tag
                   1300:           // missing");
                   1301:           String name = (String) node4.attributes.get("name");
                   1302:           String layout = (String) node4.attributes.get("layout");
                   1303:           String id = (String) node4.attributes.get("id");
                   1304:           System.out.println("id was " + id);
                   1305: 
                   1306:           if (name == null)
                   1307:             throw new Error("parse error required table tag attribute name missing");
                   1308:           if (layout == null)
                   1309:             layout = "";
                   1310:           if (id == null)
                   1311:             id = "";
                   1312:           if (name.equals(""))
                   1313:             throw new Error("parse error table tag attribute must not be empty");
1.10      rogo     1314:           tables.add(name.intern());
                   1315:           layouts.add(layout.intern());
                   1316:           ids.add(id.intern());
1.4       rogo     1317:           String query = (node5 == null) ? "" : node5.getCharacters();
                   1318:           if (query.equals(""))
                   1319:             System.err.println("Warning empty select tag or  select tag missing !!");
                   1320:           query = (query.equals("")) ? "select * from " + database.getQC() + name
                   1321:               + database.getQC() : query;
                   1322:           selects.add(query);
                   1323:           if (node6 != null)
                   1324:             creates.add(node6.getCharacters().trim());
                   1325:           else
                   1326:             creates.add("");
                   1327: 
                   1328:         }
                   1329:         DataBase dataBase = new DataBase(database, tables, layouts, selects, creates, ids, mode);
                   1330:         dataBase.delimiter = delimiter;
                   1331:         dataBase.preCommands = new Vector(preSQLCommands);
                   1332:         dataBase.postCommands = new Vector(postSQLCommands);
                   1333:         databases.add(dataBase);
                   1334:       }
                   1335:       DBBean database = new DBBean();
                   1336: 
                   1337:       preSQLCommands.clear();
                   1338:       postSQLCommands.clear();
                   1339: 
                   1340:       // parse dataBase
                   1341:       Node node = root.find("convert/destination/database/url", new int[]
                   1342:       { 1, 1, 1, 1 });
                   1343:       Node node1 = root.find("convert/destination/database/user", new int[]
                   1344:       { 1, 1, 1, 1, 1 });
                   1345:       Node node2 = root.find("convert/destination/database/password", new int[]
                   1346:       { 1, 1, 1, 1, 1 });
                   1347:       Node commandNodes = root.find("convert/destination/database/sqlcommands", new int[]
                   1348:       { 1, 1, 1, 1, 1 });
                   1349:       if (commandNodes != null)
                   1350:       {
                   1351:         parseCommandNode(commandNodes, database, preSQLCommands, postSQLCommands);
                   1352:       }
                   1353: 
                   1354:       String url = node.getCharacters();
                   1355:       String user = node1.getCharacters();
                   1356:       String password = node2.getCharacters();
                   1357:       System.out.println(url);
                   1358:       database.setURL(url.trim());
                   1359:       database.setUserAndPasswd(user.trim(), password.trim());
                   1360:       DataBase db = new DataBase(database, new Vector(), null, null, null, null, 0);
                   1361:       databases.add(db);
                   1362:       db.preCommands = new Vector(preSQLCommands);
                   1363:       db.postCommands = new Vector(postSQLCommands);
                   1364: 
                   1365:     } catch (Exception e)
                   1366:     {
                   1367:       e.printStackTrace();
                   1368:     }
                   1369:     return databases;
                   1370:   }
                   1371: 
                   1372:   /**
                   1373:    *
                   1374:    * @param commandNode
                   1375:    * @param database
                   1376:    * @param preSQLCommands 
                   1377:    * @param postSQLCommand 
                   1378:    */
                   1379:   private static void parseCommandNode(Node commandNode, DBBean database,
                   1380:       java.util.Vector preSQLCommands, java.util.Vector postSQLCommands)
                   1381:   {
                   1382:     // System.out.println(commandNode.name + " " + countNodes(commandNode));
                   1383:     int numCommands = commandNode.contents.length();
                   1384:     for (int j = 0; j < numCommands; ++j)
                   1385:     {
                   1386:       Node node = (Node) commandNode.contents.v.elementAt(j);
                   1387:       if (node.type.equals("element"))
                   1388:       {
                   1389:         // System.out.println(node.name + " " + node.getCharacters() + database);
                   1390:         String execute = node.attributes.get("execute").toString();
                   1391:         if (execute.equals("before"))
                   1392:         {
                   1393:           preSQLCommands.add(new SQLCommand(database, node.getCharacters()));
                   1394:         }
                   1395:         if (execute.equals("after"))
                   1396:         {
                   1397:           postSQLCommands.add(new SQLCommand(database, node.getCharacters()));
                   1398:         }
                   1399: 
                   1400:       }
                   1401: 
                   1402:     }
                   1403:   }
                   1404: 
                   1405:   private static int countNodes(Node tempNode)
                   1406:   {
                   1407:     int length = 0;
                   1408:     for (int i = 0; i < tempNode.contents.v.size(); ++i)
                   1409:     {
                   1410:       Node node = (Node) tempNode.contents.v.elementAt(i);
                   1411:       if (node.type.equals("element"))
                   1412:       {
                   1413:         if (node.name.equals("database"))
                   1414:           length++;
                   1415:         if (node.name.equals("table"))
                   1416:           length++;
                   1417:         if (node.name.equals("sqlcommand"))
                   1418:           length++;
                   1419: 
                   1420:       }
                   1421: 
                   1422:       // System.out.println(((Node)tempNode.contents.v.elementAt(i)).attributes+"
                   1423:       // "+i);
                   1424:     }
                   1425:     return length;
                   1426:   }
                   1427: 
                   1428:   private static void printContents(Node root)
                   1429:   {
                   1430: 
                   1431:     Vector contents = (root.index == null) ? root.contents.v : root.index.v;
                   1432:     for (int i = 0; i < contents.size(); ++i)
                   1433:     {
                   1434:       Node n = (Node) contents.elementAt(i);
                   1435:       if (n.type.equals("element"))
                   1436:       {
                   1437:         System.out.println("tag " + n.name);
                   1438:         System.out.println(n.getCharacters());
                   1439:         // contents=n.contents.v i=0;
                   1440:       }
                   1441:       // System.out.println(n.type);
                   1442:     }
                   1443:   }
                   1444: 
                   1445:   /**
                   1446:    * reads the specified xml file
                   1447:    * 
                   1448:    * @param xmlFile
                   1449:    */
                   1450:   public static StringBuffer readXMLFile(String xmlFile)
                   1451:   {
                   1452:     InputStream stream = null;
                   1453:     StringBuffer sb = new StringBuffer();
                   1454: 
                   1455:     try
                   1456:     {
                   1457: 
                   1458:       if (xmlFile.indexOf("file://") >= 0 || xmlFile.indexOf("http://") >= 0)
                   1459:       {
                   1460:         URL url = new URL(xmlFile);
                   1461:         stream = url.openStream();
                   1462:       } else
                   1463:         // read XML Metadata from a file
                   1464:         stream = new FileInputStream(xmlFile);
                   1465:       InputStreamReader isr = new InputStreamReader(stream, "UTF-8");
                   1466:       BufferedReader buffr = new BufferedReader(isr);
                   1467:       int c = 0;
                   1468:       while ((c = buffr.read()) != -1)
                   1469:       {
                   1470:         char ch = (char) c;
                   1471:         sb.append(ch);
                   1472:         // System.out.print((char)c);
                   1473:       }
                   1474:     } catch (Exception e)
                   1475:     {
                   1476:       e.printStackTrace();
                   1477:     } finally
                   1478:     {
                   1479: 
                   1480:       try
                   1481:       {
                   1482:         stream.close();
                   1483:       } catch (IOException e1)
                   1484:       {
                   1485:         // TODO Auto-generated catch block
                   1486:         e1.printStackTrace();
                   1487:       }
                   1488:     }
                   1489:     return sb;
                   1490:   }
                   1491: 
                   1492:   /**
                   1493:    * Helper class for Conversion etc. Contains data needed for the conversion
                   1494:    * 
                   1495:    * @author rogo
                   1496:    * 
                   1497:    */
                   1498: 
                   1499:   public static class ConversionProperties
                   1500:   {
                   1501:     String destTableName;
                   1502: 
                   1503:     String[] fieldNames;
                   1504: 
                   1505:     public ConversionProperties()
                   1506:     {
                   1507:     }
                   1508: 
                   1509:     public ConversionProperties(String destTableName, String[] fieldNames)
                   1510:     {
                   1511:       this.destTableName = destTableName;
                   1512:       this.fieldNames = fieldNames;
                   1513: 
                   1514:     }
                   1515: 
                   1516:   }
                   1517: 
                   1518:   /**
                   1519:    * Helper class for XML-File parsing Holds the parsed data
                   1520:    * 
                   1521:    * @author rogo
                   1522:    * 
                   1523:    */
                   1524:   public static class DataBase
                   1525:   {
                   1526:     DBBean bean;
                   1527: 
                   1528:     Vector creates;
                   1529: 
                   1530:     Vector selects;
                   1531: 
                   1532:     Vector layouts;
                   1533: 
1.7       rogo     1534:     Vector tables = new Vector();
1.4       rogo     1535: 
                   1536:     Vector ids;
                   1537: 
                   1538:     String delimiter = "//";
                   1539: 
                   1540:     Vector preCommands;
                   1541:     Vector postCommands;
                   1542: 
                   1543:     /**
                   1544:      * maps table name to index fields
                   1545:      */
                   1546:     Hashtable htIndex = new Hashtable();
                   1547: 
                   1548:     boolean useNormanToUnicodeMapper = false;
                   1549: 
                   1550:     final static int CONVERT_MODE = 1;
                   1551: 
                   1552:     final static int APPEND_MODE = 2;
                   1553: 
                   1554:     final static int UPDATE_MODE = 3;
                   1555: 
                   1556:     final static int DELETE_MODE = 4;
                   1557: 
                   1558:     final static int SYNCHRONIZE_MODE = 5;
                   1559: 
1.7       rogo     1560:     final static int CONVERT_TEMP_MODE = 6;
                   1561: 
1.4       rogo     1562:     int mode = -1;
                   1563: 
                   1564:     public DataBase(DBBean bean, Vector tables, Vector layouts, Vector selects, Vector creates,
                   1565:         Vector ids, int mode)
                   1566:     {
                   1567:       this.bean = bean;
                   1568:       this.tables = tables;
                   1569:       this.layouts = layouts;
                   1570:       this.selects = selects;
                   1571:       this.creates = creates;
                   1572:       this.ids = ids;
                   1573:       this.mode = mode;
                   1574:       this.bean.setIDVector(ids);
                   1575:     }
                   1576: 
                   1577:     /**
                   1578:      * @param indexListVec
                   1579:      */
                   1580:     public void buildIndexTable(Vector indexListVec)
                   1581:     {
                   1582:       for (int i = 0; i < tables.size(); i++)
                   1583:       {
                   1584:         fillIndexList((String) tables.get(i), (String) indexListVec.get(i));
                   1585:       }
                   1586:     }
                   1587: 
                   1588:     /**
                   1589:      * writes the data contained in this object to the buffered writer *
                   1590:      * 
                   1591:      * @param buffr
                   1592:      * @throws Exception
                   1593:      */
                   1594:     public void exportToXML(BufferedWriter buffr) throws Exception
                   1595:     {
                   1596:       // ids=bean.getIDVector();
                   1597:       buffr.write("    <database>\n");
                   1598:       buffr.write("      <url>" + bean.url + "</url>\n");
                   1599:       buffr.write("      <user>" + bean.user + "</user>\n");
                   1600:       buffr.write("      <password>" + bean.passwd + "</password>\n");
                   1601:       buffr.write("      <delimiter>" + delimiter + "</delimiter>\n");
                   1602:       String modeString = "";
1.13    ! rogo     1603:       if (mode == CONVERT_TEMP_MODE)
        !          1604:         modeString = "convert_temp";
        !          1605:       else if (mode == CONVERT_MODE)
1.4       rogo     1606:         modeString = "convert";
                   1607:       else if (mode == APPEND_MODE)
                   1608:         modeString = "append";
                   1609:       else if (mode == UPDATE_MODE)
                   1610:         modeString = "update";
                   1611:       else if (mode == DELETE_MODE)
                   1612:         modeString = "delete";
                   1613:       else if (mode == SYNCHRONIZE_MODE)
                   1614:         modeString = "synchronize";
                   1615: 
                   1616:       buffr.write("      <mode>" + modeString + "</mode>\n");
                   1617:       buffr.write("      <usenormantounicodemapper>" + useNormanToUnicodeMapper
                   1618:           + "</usenormantounicodemapper>\n");
                   1619:       if (preCommands != null || postCommands != null)
                   1620:       {
                   1621:         int count = 0;
                   1622: 
                   1623:         buffr.write("      <sqlcommands> \n");
                   1624: 
                   1625:         if (preCommands != null)
                   1626:         {
                   1627:           while (count < preCommands.size())
                   1628:           {
1.7       rogo     1629:             SQLCommand sqlcommand = (SQLCommand) preCommands.get(count);
                   1630:             buffr.write("        <sqlcommand execute=\"before\">" + sqlcommand.command
                   1631:                 + "</sqlcommand>\n");
1.4       rogo     1632:             count++;
                   1633:           }
                   1634:         }
                   1635:         if (postCommands != null)
                   1636:         {
                   1637:           count = 0;
                   1638:           while (count < postCommands.size())
                   1639:           {
1.7       rogo     1640:             SQLCommand sqlcommand = (SQLCommand) postCommands.get(count);
                   1641: 
                   1642:             buffr.write("        <sqlcommand execute=\"after\">" + sqlcommand.command
                   1643:                 + "</sqlcommand>\n");
1.4       rogo     1644:             count++;
                   1645:           }
                   1646:         }
                   1647:         buffr.write("      </sqlcommands> \n");
                   1648: 
                   1649:       }
                   1650:       int index = 0;
                   1651:       while (index < tables.size())
                   1652:       {
                   1653:         String table = (String) tables.get(index);
                   1654:         String layout = (String) layouts.get(index);
                   1655:         String select = (String) selects.get(index);
                   1656:         String create = (String) creates.get(index);
                   1657:         String id = (String) ids.get(index);
                   1658:         IndexList indexList = (IndexList) htIndex.get(table);
                   1659:         if (indexList == null)
                   1660:           indexList = new IndexList();
                   1661:         buffr.write("      <table name = \"" + table + "\" layout = \"" + layout + "\" id = \""
                   1662:             + id + "\" indexList =\"" + indexList + "\">\n");
                   1663:         buffr.write("         <select>" + convertToEntities(select) + "</select>\n");
                   1664:         if (!create.equals(""))
                   1665:           buffr.write("         <create>" + create + "         </create>\n");
                   1666:         buffr.write("      </table>\n");
                   1667:         index++;
                   1668:       }
                   1669:       buffr.write("    </database>\n");
                   1670:     }
                   1671: 
                   1672:     public void fillIndexList(String table, String list)
                   1673:     {
                   1674:       IndexList indexList = new IndexList();
                   1675:       StringTokenizer tokenizer = new StringTokenizer(list, ",");
                   1676:       while (tokenizer.hasMoreTokens())
                   1677:       {
                   1678:         indexList.add(tokenizer.nextToken());
                   1679:       }
                   1680:       System.out.println(indexList);
                   1681: 
                   1682:       htIndex.put(table, indexList);
                   1683:     }
                   1684: 
                   1685:     public String toString()
                   1686:     {
                   1687:       return bean.url + " " + tables;
                   1688:     }
                   1689: 
                   1690:   }
                   1691: 
                   1692:   public static void writeConfig(String file, DataBase source, DataBase destination)
                   1693:       throws Exception
                   1694:   {
                   1695:     if (!file.toLowerCase().endsWith(".xml"))
                   1696:       file += ".xml";
                   1697:     File f = new File(file);
                   1698: 
                   1699:     FileOutputStream fout = new FileOutputStream(f);
                   1700:     OutputStreamWriter outsw = new OutputStreamWriter(fout, "UTF-8");
                   1701:     BufferedWriter buffw = new BufferedWriter(outsw);
                   1702:     buffw.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
                   1703:     buffw.newLine();
                   1704:     buffw.write("<convert>\n");
                   1705:     buffw.write("  <source>\n");
                   1706:     source.exportToXML(buffw);
                   1707:     buffw.write("  </source>\n");
                   1708:     buffw.write("\n  <destination>\n");
                   1709:     destination.exportToXML(buffw);
                   1710:     buffw.write("  </destination>\n");
                   1711:     buffw.write("</convert>\n");
                   1712:     buffw.close();
                   1713:   }
                   1714: 
                   1715:   public static void delete(String source, String destination, Vector names, Vector layouts,
                   1716:       Vector selects, Vector creates, Vector ids, int mode) throws Exception
                   1717:   {
                   1718:     FM2SQL.ProgressDialog dialog = null;
                   1719:     if (isGUI)
                   1720:     {
                   1721:       dialog = initDialog();
                   1722:     }
                   1723:     // setting user and passwd
                   1724:     bean.setUserAndPasswd(user, passwd);
                   1725:     // setting user and passwd
                   1726:     beanDest.setUserAndPasswd(userDest, passwdDest);
                   1727:     StringBuffer command = null;
                   1728:     String query = null;
                   1729:     try
                   1730:     {
                   1731:       // bean.setConnection("jdbc:fmpro:http://141.14.237.74:8050");
                   1732:       // bean.setConnection("jdbc:postgresql://erebos/test","postgres","rogo");
                   1733:       bean.setConnection(source);
                   1734:       if (names == null)
                   1735:         names = bean.getTableNames();
                   1736:       // Collections.sort(names);
                   1737:       int tbIndex = 1;
                   1738: 
                   1739:       // System.out.println("Start at
                   1740:       // "+names.indexOf("archimedes_facsimiles"));
                   1741:       for (tbIndex = 0; tbIndex < names.size(); ++tbIndex)
                   1742:       {
                   1743:         Vector[] result = null;
                   1744:         java.util.TreeSet myIds = new TreeSet();
                   1745:         java.util.TreeSet myIdsDest = new TreeSet();
                   1746:         int deltaID = 1;
                   1747:         String idField = "";
                   1748:         String destTableName = "";
                   1749: 
                   1750:         try
                   1751:         {
                   1752:           query = "select * from " + bean.getQC() + names.get(tbIndex).toString() + bean.getQC();
                   1753:           String layout = (layouts.isEmpty()) ? "" : layouts.get(tbIndex).toString();
                   1754:           query = (selects != null) ? selects.get(tbIndex).toString() : query;
                   1755:           // if vectors[1].get(i) != null)
                   1756:           if (layout != "")
                   1757:           {
                   1758:             layout = " layout " + bean.getQC() + layout + bean.getQC();
                   1759:             String name = names.get(tbIndex).toString();
                   1760:             StringBuffer queryLayout = new StringBuffer(query);
                   1761:             queryLayout.insert(queryLayout.indexOf(name) + name.length() + 1, " " + layout);
                   1762:             query = queryLayout.toString();
                   1763:             System.out.println("added layout  " + query);
                   1764: 
                   1765:           }
                   1766:           dialog.title.setText("Getting table data ...");
                   1767:           dialog.table.setText(names.get(tbIndex).toString());
                   1768:           dialog.status.setText("Table " + (tbIndex + 1) + " of " + names.size());
                   1769:           dialog.setVisible(true);
                   1770:           bean.getConnection();
                   1771:           bean.makeQuery(query, 50);
                   1772:           idField = ids.get(tbIndex).toString();
                   1773: 
                   1774:         } catch (Exception e)
                   1775:         {
                   1776:           continue;
                   1777:         }
                   1778:         // determine destTableName from createStatement or from source
                   1779:         // table name
                   1780:         if (!creates.get(tbIndex).equals(""))
                   1781:         {
                   1782:           String create = creates.get(tbIndex).toString().toLowerCase();
                   1783:           int fromIndex = create.indexOf("table") + 5;
                   1784:           int toIndex = create.indexOf("(");
                   1785:           destTableName = create.substring(fromIndex, toIndex).replaceAll(beanDest.getQC(), "")
                   1786:               .trim();
                   1787:           System.out.println("destTable " + destTableName);
                   1788: 
                   1789:         } else
                   1790:           destTableName = convertText(names.get(tbIndex).toString());
                   1791: 
                   1792:         // for id kram
                   1793:         Vector vec = null;
                   1794:         Vector vecDest = null;
                   1795:         // tempo
                   1796:         beanDest.setConnection(destination);
                   1797:         int rowCount = (idField != "") ? myIds.size() : bean.getRowCount(query);
                   1798:         String tempID = bean.getQC() + idField + bean.getQC();
                   1799:         String tempIDdest = beanDest.getQC() + convertText(idField) + beanDest.getQC();
                   1800: 
                   1801:         int endIndex = -1;
                   1802:         String tempQuery = query;
                   1803:         String destQuery = query.replaceAll(names.get(tbIndex).toString(), destTableName);
                   1804:         String tempQueryDest = destQuery;
                   1805:         // remove extra query parts
                   1806:         // destQuery.substring(0,destQuery.lastIndexOf(destTableName)+destTableName.length()+1);
                   1807:         System.out.println("new Query " + tempQueryDest);
                   1808:         if (!idField.equals(""))
                   1809:         {
                   1810:           long startTime = System.currentTimeMillis();
                   1811:           int counter = -1;
                   1812:           while (true)
                   1813:           {
                   1814:             ++counter;
                   1815:             if (counter == 0 && dialog != null)
                   1816:               dialog.title.setText("Check if data  is available");
                   1817:             else if (dialog != null)
                   1818:               dialog.title.setText("Check if more  data  is available");
                   1819:             myIds = bean.getIDVector(ids.get(tbIndex).toString(), (String) names.get(tbIndex),
                   1820:                 tempQuery, numHits);
                   1821:             myIdsDest = beanDest.getIDVector(convertText(idField), destTableName, tempQueryDest,
                   1822:                 numHits);
                   1823:             if (myIds.isEmpty())
                   1824:               break;
                   1825:             vec = new Vector(myIds);
                   1826:             vecDest = new Vector(myIdsDest);
                   1827:             rowCount = vec.size();
                   1828:             // Deletion will work this way
                   1829:             Vector deleted = new Vector(vec);
                   1830:             Vector linesToDelete = new Vector(vecDest);
                   1831:             // remove all lines that should not be deleted
                   1832:             linesToDelete.removeAll(deleted);
                   1833:             // System.out.println("ID LIST SIZE " +
                   1834:             // Math.round((double) myIds.size() / (double)
                   1835:             // numIntervalls) + " " + myIdsDest.size());
                   1836:             // / @TODO complete delete task remove query show lines
                   1837:             // to be deleted let user choose if he wants that
                   1838:             System.out.println("number of lines to  be deleted " + linesToDelete.size());
                   1839:             deltaID = (int) Math.round((double) myIds.size() / (double) numIntervalls);
                   1840:             beanDest.setConnection(destination);
                   1841: 
                   1842:             Statement stm = beanDest.getConnection().createStatement();
                   1843: 
                   1844:             Vector tables = beanDest.getTableNames();
                   1845:             // Collections.sort(tables);
                   1846:             System.out.println(names.get(tbIndex) + " "
                   1847:                 + tables.indexOf(convertText((String) names.get(tbIndex)))); // "//beanDest.getTypeNames());
                   1848:             tables = beanDest.getTableNames();
                   1849:             // System.out.println(beanDest.getTableNames(beanDest.getCatalogs().get(2).toString()));
                   1850:             stm = beanDest.getConnection().createStatement();
                   1851: 
                   1852:             if (dialog != null)
                   1853:               dialog.title.setText(" Deleting table data ...");
                   1854: 
                   1855:             int j = -1;
                   1856: 
                   1857:             Vector row = null;
                   1858:             command = new StringBuffer();
                   1859: 
                   1860:             command.append("DELETE FROM");
                   1861:             command.append(beanDest.getQC());
                   1862:             command.append(destTableName);
                   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:             while (true)
                   1869:             {
                   1870: 
                   1871:               ++j;
                   1872:               if (j == linesToDelete.size())
                   1873:                 break;
                   1874:               // print rows
                   1875:               pstm.setString(1, linesToDelete.get(j).toString());
                   1876:               System.out.println(pstm.toString());
                   1877:               pstm.execute();
                   1878:               if (isGUI)
                   1879:                 dialog.progress.setValue((int) (((double) (j + 1) / (double) rowCount) * 100.0));
                   1880:               command = null;
                   1881:             }
                   1882:             // prepare new query for next chunk
                   1883:             if (query.indexOf("where") > 0)
                   1884:               tempQuery = query + " and " + tempID + ">'" + vec.lastElement() + "'";
                   1885:             else
                   1886:               tempQuery = query + " where " + tempID + ">'" + vec.lastElement() + "'";
                   1887: 
                   1888:           } // to outer while
                   1889:         } // to idfield if
                   1890:       } // table loop
                   1891: 
                   1892:     } catch (Exception e)
                   1893:     {
                   1894:       System.out.println("Error while connecting to database " + e);
                   1895:       if (isGUI)
                   1896:       {
                   1897:         showExceptionDialog(dialog, command, e);
                   1898:         resetGUI(dialog);
                   1899:       } else
                   1900:       {
                   1901:         e.printStackTrace();
                   1902:       }
                   1903:     }
                   1904:   } // to method
                   1905: 
                   1906:   /**
                   1907:    * synchronize method based on delete method code
                   1908:    * 
                   1909:    * @param source
                   1910:    * @param destination
                   1911:    * @param names
                   1912:    * @param layouts
                   1913:    * @param selects
                   1914:    * @param creates
                   1915:    * @param ids
                   1916:    * @param mode
                   1917:    * @throws Exception
                   1918:    */
                   1919:   // TODO implement append,update and delete in one method
                   1920:   // TODO using id based algorithm
                   1921:   public static void synchronize(String source, String destination, Vector names, Vector layouts,
                   1922:       Vector selects, Vector creates, Vector ids, int mode, String delimiter, Vector indexList)
                   1923:       throws Exception
                   1924:   {
                   1925:     System.out.println(" bin in synchronize!!!");
                   1926:     FM2SQL.ProgressDialog dialog = null;
                   1927:     if (isGUI)
                   1928:     {
                   1929:       dialog = initDialog();
                   1930:       dialog.setTitle("Synchronize running ...");
                   1931: 
                   1932:     }
                   1933:     // setting user and passwd
                   1934:     bean.setUserAndPasswd(user, passwd);
                   1935:     // setting user and passwd
                   1936:     beanDest.setUserAndPasswd(userDest, passwdDest);
                   1937:     StringBuffer command = null;
                   1938:     String query = null;
                   1939:     try
                   1940:     {
                   1941:       bean.setConnection(source);
                   1942:       if (names == null)
                   1943:         names = bean.getTableNames();
                   1944:       int tbIndex = 1;
                   1945: 
                   1946:       for (tbIndex = 0; tbIndex < names.size(); ++tbIndex)
                   1947:       {
                   1948:         Vector[] result = null;
                   1949:         java.util.TreeSet myIds = new TreeSet();
                   1950:         java.util.TreeSet myIdsDest = new TreeSet();
                   1951:         int deltaID = 1;
                   1952:         String idField = "";
                   1953:         String destTableName = "";
                   1954: 
                   1955:         try
                   1956:         {
                   1957:           query = "select * from " + bean.getQC() + names.get(tbIndex).toString() + bean.getQC();
                   1958:           String layout = (layouts.isEmpty()) ? "" : layouts.get(tbIndex).toString();
                   1959:           query = (selects != null) ? selects.get(tbIndex).toString() : query;
                   1960:           // if vectors[1].get(i) != null)
                   1961:           if (!layout.equals(""))
                   1962:           {
                   1963:             query = addLayoutToQuery(names, query, tbIndex, layout);
                   1964: 
                   1965:           }
                   1966:           if (dialog != null)
                   1967:           {
                   1968:             prepareDialogforUse(names, dialog, tbIndex);
                   1969:           }
                   1970:           bean.getConnection();
                   1971:           bean.makeQuery(query, 50);
                   1972:           idField = ids.get(tbIndex).toString();
                   1973: 
                   1974:         } catch (Exception e)
                   1975:         {
                   1976:           System.out.println("Warning exception occured \n " + e);
                   1977: 
                   1978:           continue;
                   1979:         }
                   1980:         // determine destTableName from createStatement or from source
                   1981:         // table name
                   1982:         if (!creates.get(tbIndex).equals(""))
                   1983:         {
                   1984:           String create = creates.get(tbIndex).toString().toLowerCase();
                   1985:           int fromIndex = create.indexOf("table") + 5;
                   1986:           int toIndex = create.indexOf("(");
                   1987:           destTableName = create.substring(fromIndex, toIndex).replaceAll(beanDest.getQC(), "")
                   1988:               .trim();
                   1989:           System.out.println("destTable " + destTableName);
                   1990: 
                   1991:         } else
                   1992:           destTableName = convertText(names.get(tbIndex).toString());
                   1993: 
                   1994:         // for id kram
                   1995:         Vector vec = null;
                   1996:         Vector vecDest = null;
                   1997:         // tempo
                   1998:         beanDest.setConnection(destination);
                   1999:         int rowCount = (idField != "") ? myIds.size() : bean.getRowCount(query);
                   2000:         String tempID = bean.getQC() + idField + bean.getQC();
                   2001:         String tempIDdest = beanDest.getQC() + convertText(idField) + beanDest.getQC();
                   2002: 
                   2003:         int endIndex = -1;
                   2004:         String tempQuery = query;
                   2005:         String destQuery = query.replaceAll(names.get(tbIndex).toString(), destTableName);
                   2006:         destQuery = destQuery.replaceAll(bean.getQC(), beanDest.getQC());
                   2007:         destQuery = removeLayoutPartFromQuery(destQuery, layouts.get(tbIndex).toString());
                   2008:         // TODO remove layout part for destQuery
                   2009:         String tempQueryDest = destQuery;
                   2010:         // remove extra query parts
                   2011:         // destQuery.substring(0,destQuery.lastIndexOf(destTableName)+destTableName.length()+1);
                   2012:         System.out.println("new Query " + tempQueryDest);
                   2013:         System.out.println("idfield " + idField + " " + ids.get(tbIndex).toString());
                   2014:         if (!idField.equals(""))
                   2015:         {
                   2016:           long startTime = System.currentTimeMillis();
                   2017:           int counter = -1;
                   2018:           TreeSet linesToDelete = null;
                   2019:           PreparedStatement delPSt = null;
                   2020:           while (true)
                   2021:           {
                   2022:             ++counter;
                   2023:             if (counter == 0 && dialog != null)
                   2024:               dialog.title.setText("Check if data  is available");
                   2025:             else if (dialog != null)
                   2026:               dialog.title.setText("Check if more  data  is available");
                   2027: 
                   2028:             myIds = bean.getIDVector(ids.get(tbIndex).toString(), (String) names.get(tbIndex),
                   2029:                 tempQuery, 0);
                   2030:             myIdsDest = beanDest.getIDVector(convertText(idField), destTableName, tempQueryDest, 0);
                   2031:             // System.out.println("status of remove
                   2032:             // "+myIds.remove("b015892"));
                   2033:             System.out.println("ids found for " + idField + " " + !myIds.isEmpty());
                   2034:             if (myIds.isEmpty())
                   2035:               break;
                   2036:             vec = new Vector(myIds);
                   2037:             vecDest = new Vector(myIdsDest);
                   2038:             rowCount = vec.size();
                   2039:             // Deletion will work this way
                   2040:             Vector deleted = new Vector(vec);
                   2041: 
                   2042:             TreeSet linesToAppend = new TreeSet(vec);
                   2043:             linesToAppend.addAll(vec);
                   2044:             linesToDelete = new TreeSet(vecDest);
                   2045:             // remove all lines that are already in dest database
                   2046:             linesToAppend.removeAll(vecDest);
                   2047:             // remove all lines that should not be deleted
                   2048:             linesToDelete.removeAll(deleted);
                   2049:             System.out.println("linesToAppend " + linesToAppend.size() + " " + destTableName);
                   2050:             System.out.println("linesToDelete " + linesToDelete.size() + " " + destTableName);
                   2051:             System.out.println("ID LIST SIZE "
                   2052:                 + Math.round((double) myIds.size() / (double) numIntervalls) + " " + myIds.size());
                   2053:             deltaID = (int) Math.round((double) myIds.size() / (double) numIntervalls);
                   2054:             ConversionProperties prop = getFieldNamesAndDestTableName(creates.get(tbIndex)
                   2055:                 .toString(), query, names.get(tbIndex).toString());
                   2056:             StringBuffer insCommand = createInsertCommand(prop.destTableName, prop.fieldNames);
                   2057:             StringBuffer updCommand = createUpdateCommand(prop.destTableName, prop.fieldNames,
                   2058:                 tempIDdest);
                   2059:             StringBuffer delCommand = createDeleteCommand(destTableName, tempIDdest);
                   2060:             PreparedStatement insPst = beanDest.getConnection().prepareStatement(
                   2061:                 insCommand.toString());
                   2062:             PreparedStatement updPst = beanDest.getConnection().prepareStatement(
                   2063:                 updCommand.toString());
                   2064:             delPSt = beanDest.getConnection().prepareStatement(delCommand.toString());
                   2065:             // delPSt.setString(1,"b015892");
                   2066:             // delPSt.execute();
                   2067:             // if (true)
                   2068:             // return;
                   2069:             if (vec.size() <= numIntervalls)
                   2070:             {
                   2071:               endIndex = 0;
                   2072:               deltaID = vec.size();
                   2073:             }
                   2074:             for (int k = 0; k < vec.size() - deltaID; k = k + deltaID)
                   2075:             {
                   2076:               System.out.println(vec.get(k) + " " + vec.get(k + deltaID) + " " + vec.lastElement());
                   2077:               if (query.indexOf("where") > 0)
                   2078:                 tempQuery = query + " and " + tempID + ">='" + vec.get(k) + "' and " + tempID
                   2079:                     + "<='" + vec.get(k + deltaID) + "'";
                   2080:               else
                   2081:                 tempQuery = query + " where " + tempID + ">='" + vec.get(k) + "' and " + tempID
                   2082:                     + "<='" + vec.get(k + deltaID) + "'";
                   2083:               System.out.println(tempQuery);
                   2084:               if (dialog != null)
                   2085:                 dialog.title.setText("Reading table data ...");
                   2086: 
                   2087:               // bean.makeQuery(tempQuery, deltaID);
                   2088:               if (dialog != null)
                   2089:                 dialog.title.setText("Writing table data ...");
                   2090: 
                   2091:               performSynchronize(idField, vec, tempQuery, linesToDelete, linesToAppend, insPst,
                   2092:                   updPst, delPSt, deltaID, delimiter, dialog);
                   2093:               // System.out.println("ID LIST SIZE " +
                   2094:               // Math.round((double) myIds.size() / (double)
                   2095:               // numIntervalls) + " " + myIdsDest.size());
                   2096:               endIndex = k + deltaID;
                   2097:             }
                   2098:             System.out.println(endIndex);
                   2099:             // all data written ? if not write last chunk of data
                   2100:             if (endIndex == vec.size() - 1)
                   2101:               System.out.println("fits");
                   2102:             else
                   2103:             {
                   2104:               System.out.println(" last intervall from " + vec.get(endIndex) + " "
                   2105:                   + vec.lastElement());
                   2106: 
                   2107:               if (query.indexOf("where") > 0)
                   2108:                 tempQuery = query + " and " + tempID + ">='" + vec.get(endIndex) + "' and "
                   2109:                     + tempID + "<='" + vec.lastElement() + "'";
                   2110:               else
                   2111:                 tempQuery = query + " where " + tempID + ">='" + vec.get(endIndex) + "' and "
                   2112:                     + tempID + "<='" + vec.lastElement() + "'";
                   2113:               System.out.println(tempQuery);
                   2114:               if (dialog != null)
                   2115:                 dialog.title.setText("Reading table data ...");
                   2116:               // bean.makeQuery(tempQuery, 0);
                   2117:               if (dialog != null)
                   2118:                 dialog.title.setText("Writing table data ...");
                   2119:               performSynchronize(idField, vec, tempQuery, linesToDelete, linesToAppend, insPst,
                   2120:                   updPst, delPSt, deltaID, delimiter, dialog);
                   2121:               // System.out.println("ID LIST SIZE " +
                   2122:               // Math.round((double) myIds.size() / (double)
                   2123:               // numIntervalls) + " " + myIdsDest.size());
                   2124:             }
                   2125:             // prepare new query for next chunk
                   2126:             if (query.indexOf("where") > 0)
                   2127:               tempQuery = query + " and " + tempID + ">'" + vec.lastElement() + "'";
                   2128:             else
                   2129:               tempQuery = query + " where " + tempID + ">'" + vec.lastElement() + "'";
                   2130: 
                   2131:           }
                   2132:           String tableName = names.get(tbIndex).toString();
                   2133:           if (!indexList.isEmpty())
                   2134:           {
                   2135:             IndexList idList = (IndexList) indexList.get(0);
                   2136:             System.out.println("found list " + idList);
                   2137:             Statement stm = beanDest.getConnection().createStatement();
                   2138:             Vector destTables = beanDest.getTableNames();
                   2139:             System.out.println("tempQueryDest" + tempQueryDest);
                   2140:             beanDest.makeQuery(tempQueryDest, 0);
                   2141:             for (Iterator iter = idList.iterator(); iter.hasNext();)
                   2142:             {
                   2143:               String indexField = (String) iter.next();
                   2144:               indexField = convertText(indexField);
                   2145:               String indexName = destTableName + "_" + indexField;
                   2146:               if (destTables.contains(indexName))
                   2147:               {
                   2148:                 stm.execute("DROP  INDEX " + destTableName + "_" + indexField);
                   2149:                 // continue;
                   2150:               }
                   2151:               // stm.execute("DROP INDEX
                   2152:               // "+destTableName+"_"+indexField);
                   2153: 
                   2154:               String type = beanDest.getColumnType(indexField).toLowerCase();
                   2155:               // System.out.println(indexField+" "+type+"
                   2156:               // "+(type.indexOf("text") >= 0 ||
                   2157:               // type.indexOf("varchar") >= 0 || type.indexOf("char")
                   2158:               // >= 0));
                   2159:               if (type.indexOf("text") >= 0 || type.indexOf("varchar") >= 0
                   2160:                   || type.indexOf("char") >= 0)
                   2161:               {
                   2162:                 if (beanDest.url.indexOf("mysql") >= 0)
                   2163:                 {
                   2164:                   // System.out.println("CREATE INDEX " +
                   2165:                   // indexName + " ON " + destTableName + " (" +
                   2166:                   // indexField + "(10))");
                   2167:                   // TODO problem if index exist !!!
                   2168:                   stm.execute("CREATE  INDEX " + indexName + " ON " + destTableName + " ("
                   2169:                       + indexField + "(10))");
                   2170:                 } else
                   2171:                 {
                   2172:                   stm.execute("CREATE  INDEX " + indexName + " ON " + destTableName + " (lower( "
                   2173:                       + indexField + "))");
                   2174: 
                   2175:                 }
                   2176: 
                   2177:               } else
                   2178:               {
                   2179:                 stm.execute("CREATE  INDEX " + destTableName + "_" + indexField + " ON "
                   2180:                     + destTableName + "(" + indexField + ")");
                   2181: 
                   2182:               }
                   2183: 
                   2184:               // stm.execute("DROP INDEX
                   2185:               // "+destTableName+"_"+indexField);
                   2186: 
                   2187:             }
                   2188:           }
                   2189:           // CREATE UNIQUE INDEX title_idx ON films (title);
                   2190:           for (Iterator iter = linesToDelete.iterator(); iter.hasNext();)
                   2191:           {
                   2192:             String id = (String) iter.next();
                   2193:             delPSt.setString(1, id);
                   2194:             delPSt.execute();
                   2195: 
                   2196:           }
                   2197: 
                   2198:           long endTime = System.currentTimeMillis();
                   2199:           System.out.println("Time for incremental synchronize  elapsed " + (endTime - startTime));
                   2200:         } // to idfield if
                   2201:       } // table loop
                   2202: 
                   2203:     } catch (Exception e)
                   2204:     {
                   2205:       System.out.println("Error while connecting to database " + e);
                   2206:       e.printStackTrace();
                   2207:       if (isGUI)
                   2208:         showExceptionDialog(dialog, command, e);
                   2209:     }
                   2210:     if (isGUI)
                   2211:     {
                   2212:       resetGUI(dialog);
                   2213:     }
                   2214:   }
                   2215: 
                   2216:   /**
                   2217:    * @param destQuery
                   2218:    * @param string
                   2219:    * @return
                   2220:    */
                   2221:   private static String removeLayoutPartFromQuery(String destQuery, String layoutName)
                   2222:   {
                   2223:     String removeString = "layout " + beanDest.getQC() + layoutName + beanDest.getQC();
                   2224:     destQuery = destQuery.replaceFirst(removeString, "");
                   2225:     System.out.println("destQuery change to " + destQuery);
                   2226:     return destQuery;
                   2227:   }
                   2228: 
                   2229:   private static void performSynchronize(String idField, Vector vec, String tempQuery,
                   2230:       TreeSet linesToDelete, TreeSet linesToAppend, PreparedStatement insPst,
                   2231:       PreparedStatement updPst, PreparedStatement delPSt, int deltaID, String delimiter,
                   2232:       FM2SQL.ProgressDialog dialog) throws SQLException, ParseException, Exception
                   2233:   {
                   2234:     if (dialog != null)
                   2235:     {
                   2236:       dialog.progress.setValue(0);
                   2237:       dialog.title.setText("Retrieving new data");
                   2238:     }
                   2239: 
                   2240:     Vector[] vectors = bean.getQueryData(tempQuery, deltaID);
                   2241:     int count = 0, size = vectors[0].size();
                   2242:     int idIndex = vectors[1].indexOf(idField);
                   2243:     // System.out.println(idIndex + " " + vectors[1] + " " + idField);
                   2244:     // todo arraylist code has to be added
                   2245:     if (dialog != null)
                   2246:       dialog.title.setText("Synchronize with new data");
                   2247: 
                   2248:     for (Iterator iter = vectors[0].iterator(); iter.hasNext();)
                   2249:     {
                   2250:       Vector line = (Vector) iter.next();
                   2251:       Object lineIDIndex = line.get(idIndex);
                   2252:       if (linesToAppend.contains(lineIDIndex))
                   2253:         System.out.println("line " + linesToAppend.contains(line.get(idIndex)) + " " + lineIDIndex);
                   2254:       if (linesToAppend.contains(lineIDIndex))
                   2255:       {
                   2256:         for (int l = 0; l < line.size(); ++l)
                   2257:         {
                   2258:           Object obj = line.get(l);
                   2259:           if (obj instanceof ArrayList)
                   2260:             obj = formatFileMakerArray((List) obj, delimiter);
                   2261:           if (obj != null)
                   2262:             insPst.setString(l + 1, obj.toString());
                   2263:           else
                   2264:             insPst.setNull(l + 1, Types.NULL);
                   2265:         }
                   2266:         insPst.execute();
                   2267: 
                   2268:       } else
                   2269:       // update
                   2270:       {
                   2271:         for (int l = 0; l < line.size(); ++l)
                   2272:         {
                   2273:           Object obj = line.get(l);
                   2274:           if (obj instanceof ArrayList)
                   2275:             obj = formatFileMakerArray((List) obj, delimiter);
                   2276:           if (obj != null)
                   2277:             updPst.setString(l + 1, obj.toString());
                   2278:           else
                   2279:             updPst.setNull(l + 1, Types.NULL);
                   2280:         }
                   2281:         updPst.setString(line.size() + 1, line.get(idIndex).toString());
                   2282:         // updPst.addBatch();
                   2283:         // updPst.execute();
                   2284:       }
                   2285:       if (dialog != null)
                   2286:       {
                   2287:         int value = (int) Math.round(((double) count / (double) size) * 100.0);
                   2288:         dialog.progress.setValue(value);
                   2289:         count++;
                   2290:       }
                   2291:     }
                   2292:     // updPst.executeBatch();
                   2293:   } // to method
                   2294: 
                   2295:   /**
                   2296:    * Converts input String in norman encoding to unicode
                   2297:    * 
                   2298:    * @param inp
                   2299:    * @return converted String
                   2300:    */
                   2301:   static public String normanToUnicode(String inp)
                   2302:   {
                   2303:     StringBuffer buf = new StringBuffer();
                   2304:     for (int i = 0; i < inp.length(); i++)
                   2305:     {
                   2306:       char c = inp.charAt(i);
                   2307:       // System.out.println("char "+c+" "+(int)c);
                   2308:       switch (c)
                   2309:       {
                   2310:         case 1:
                   2311:           buf.append("\u00d0");
                   2312:           break; // Eth
                   2313:         case 2:
                   2314:           buf.append("\u00f0");
                   2315:           break; // eth
                   2316:         case 3:
                   2317:           buf.append("\u0141");
                   2318:           break; // Lslash
                   2319:         case 4:
                   2320:           buf.append("\u0142");
                   2321:           break; // lslash
                   2322:         case 5:
                   2323:           buf.append("\u0160");
                   2324:           break; // S caron
                   2325:         case 6:
                   2326:           buf.append("\u0161");
                   2327:           break; // s caron
                   2328:         case 7:
                   2329:           buf.append("\u00dd");
                   2330:           break; // Y acute
                   2331:         case 8:
                   2332:           buf.append("\u00fd");
                   2333:           break; // y acute
                   2334:         case 11:
                   2335:           buf.append("\u00de");
                   2336:           break; // Thorn
                   2337:         case 12:
                   2338:           buf.append("\u00fe");
                   2339:           break; // thorn
                   2340:         case 14:
                   2341:           buf.append("\u017d");
                   2342:           break; // Z caron
                   2343:         case 15:
                   2344:           buf.append("\u017e");
                   2345:           break; // z caron
                   2346:         case 17:
                   2347:           buf.append("\u0073");
                   2348:           break; // asciitilde
                   2349:         case 18:
                   2350:           buf.append("j\u0305");
                   2351:           break; // j macron [does a single char exist?]
                   2352:         case 19:
                   2353:           buf.append("^");
                   2354:           break; // circumflex
                   2355:         case 20:
                   2356:           buf.append("\u0303");
                   2357:           break; // tilde
                   2358:         case 21:
                   2359:           buf.append("\u00bd");
                   2360:           break; // onehalf
                   2361:         case 22:
                   2362:           buf.append("\u00bc");
                   2363:           break; // onequarter
                   2364:         case 23:
                   2365:           buf.append("\u00b9");
                   2366:           break; // onesuperior
                   2367:         case 24:
                   2368:           buf.append("\u00be");
                   2369:           break; // threequarters
                   2370:         case 25:
                   2371:           buf.append("\u00b3");
                   2372:           break; // threesuperior
                   2373:         case 26:
                   2374:           buf.append("\u00b2");
                   2375:           break; // twosuperior
                   2376:         case 27:
                   2377:           buf.append("\u00a6");
                   2378:           break; // brokenbar
                   2379:         case 28:
                   2380:           buf.append("-");
                   2381:           break; // minus
                   2382:         case 29:
                   2383:           buf.append("\u00d7");
                   2384:           break; // multiply
                   2385:         case 39:
                   2386:           buf.append("'");
                   2387:           break; // quotesingle
                   2388:         case 94:
                   2389:           buf.append("\u0302");
                   2390:           break; // circumflex
                   2391:         case 96:
                   2392:           buf.append("\u0300");
                   2393:           break; // grave
                   2394:         case 196:
                   2395:           buf.append("\u00c4");
                   2396:           break; // A dieresis
                   2397:         case 197:
                   2398:           buf.append("\u00c5");
                   2399:           break; // A ring
                   2400:         case 201:
                   2401:           buf.append("\u00c9");
                   2402:           break; // E acute
                   2403:         case 209:
                   2404:           buf.append("\u00d1");
                   2405:           break; // N tilde
                   2406:         case 214:
                   2407:           buf.append("\u00d6");
                   2408:           break; // O dieresis
                   2409:         case 220:
                   2410:           buf.append("\u00dc");
                   2411:           break; // U dieresis
                   2412:         case 225:
                   2413:           buf.append("\u00e1");
                   2414:           break; // a acute
                   2415:         case 224:
                   2416:           buf.append("\u00e0");
                   2417:           break; // a grave
                   2418:         case 226:
                   2419:           buf.append("\u00e2");
                   2420:           break; // a circumflex
                   2421:         case 228:
                   2422:           buf.append("\u00e4");
                   2423:           break; // a dieresis
                   2424:         case 227:
                   2425:           buf.append("\u00e3");
                   2426:           break; // a tilde
                   2427:         case 229:
                   2428:           buf.append("\u0101");
                   2429:           break; // a macron
                   2430:         case 231:
                   2431:           buf.append("\u00e7");
                   2432:           break; // c cedilla
                   2433:         case 233:
                   2434:           buf.append("\u00e9");
                   2435:           break; // e acute
                   2436:         case 232:
                   2437:           buf.append("\u00e8");
                   2438:           break; // e grave
                   2439:         case 234:
                   2440:           buf.append("\u00ea");
                   2441:           break; // e circumflex
                   2442:         case 235:
                   2443:           buf.append("\u00eb");
                   2444:           break; // e dieresis
                   2445:         case 237:
                   2446:           buf.append("\u00ed");
                   2447:           break; // i acute
                   2448:         case 236:
                   2449:           buf.append("\u00ec");
                   2450:           break; // i grave
                   2451:         case 238:
                   2452:           buf.append("\u00ee");
                   2453:           break; // i circumflex
                   2454:         case 239:
                   2455:           buf.append("\u00ef");
                   2456:           break; // i dieresis
                   2457:         case 241:
                   2458:           buf.append("\u00f1");
                   2459:           break; // n tilde
                   2460:         case 243:
                   2461:           buf.append("\u00f3");
                   2462:           break; // o acute
                   2463:         case 242:
                   2464:           buf.append("\u00f2");
                   2465:           break; // o grave
                   2466:         case 244:
                   2467:           buf.append("\u00f4");
                   2468:           break; // o circumflex
                   2469:         case 246:
                   2470:           buf.append("\u00f6");
                   2471:           break; // o dieresis
                   2472:         case 245:
                   2473:           buf.append("\u00f5");
                   2474:           break; // o tilde
                   2475:         case 250:
                   2476:           buf.append("\u00fa");
                   2477:           break; // u acute
                   2478:         case 249:
                   2479:           buf.append("\u00f9");
                   2480:           break; // u grave
                   2481:         case 251:
                   2482:           buf.append("\u00fb");
                   2483:           break; // u circumflex
                   2484:         case 252:
                   2485:           buf.append("\u00fc");
                   2486:           break; // u dieresis
                   2487:         case 8224:
                   2488:           buf.append("\u1e6d");
                   2489:           break; // t underdot
                   2490:         case 176:
                   2491:           buf.append("\u00b0");
                   2492:           break; // degree
                   2493:         case 162:
                   2494:           buf.append("\u1ebd");
                   2495:           break; // e tilde
                   2496:         case 163:
                   2497:           buf.append("\u00a3");
                   2498:           break; // sterling
                   2499:         case 167:
                   2500:           buf.append("\u00a7");
                   2501:           break; // section
                   2502:         case 182:
                   2503:           buf.append("\u00b6");
                   2504:           break; // paragraph
                   2505:         case 223:
                   2506:           buf.append("\u015b");
                   2507:           break; // s acute
                   2508:         case 174:
                   2509:           buf.append("\u1e5b");
                   2510:           break; // r underdot
                   2511:         case 169:
                   2512:           buf.append("\u1e45");
                   2513:           break; // n overdot
                   2514:         case 353:
                   2515:           buf.append("\u1e45");
                   2516:           break; // n overdot
                   2517:         case 180:
                   2518:           buf.append("\u0301");
                   2519:           break; // acute
                   2520:         case 168:
                   2521:           buf.append("\u0308");
                   2522:           break; // dieresis
                   2523:         case 8800:
                   2524:           buf.append("\u1e6d");
                   2525:           break; // t underdot
                   2526:         case 198:
                   2527:           buf.append("\u00c6");
                   2528:           break; // AE
                   2529:         case 216:
                   2530:           buf.append("\u014d");
                   2531:           break; // o macron
                   2532:         case 8734:
                   2533:           buf.append("\u0129");
                   2534:           break; // i tilde
                   2535:         case 177:
                   2536:           buf.append("\u00b1");
                   2537:           break; // plusminus
                   2538:         case 165:
                   2539:           buf.append("\u012b");
                   2540:           break; // i macron
                   2541:         case 181:
                   2542:           buf.append("\u1e43");
                   2543:           break; // m underdot
                   2544:         case 8706:
                   2545:           buf.append("\u1e0d");
                   2546:           break; // d underdot
                   2547:         case 240:
                   2548:           buf.append("\u1e0d");
                   2549:           break; // d underdot
                   2550: 
                   2551:         case 8721:
                   2552:           buf.append("\u1e63");
                   2553:           break; // s underdot
                   2554:         case 960:
                   2555:           buf.append("\u017a");
                   2556:           break; // z acute
                   2557:         case 8747:
                   2558:           buf.append("\u1e45");
                   2559:           break; // n overdot
                   2560:         case 937:
                   2561:           buf.append("\u0169");
                   2562:           break; // u tilde
                   2563:         case 230:
                   2564:           buf.append("\u00e6");
                   2565:           break; // ae
                   2566:         case 248:
                   2567:           buf.append("\u00f8");
                   2568:           break; // oslash
                   2569:         case 191:
                   2570:           buf.append("\u0304\u0306");
                   2571:           break; // macron breve
                   2572:         case 172:
                   2573:           buf.append("\u1e37");
                   2574:           break; // 
                   2575:         case 8730:
                   2576:           buf.append("j\u0305");
                   2577:           break; // j macron [does a single char exist?]
                   2578:         case 402:
                   2579:           buf.append("\u0103");
                   2580:           break; // a breve
                   2581:         case 8776:
                   2582:           buf.append("\u016d");
                   2583:           break; // u breve
                   2584:         case 187:
                   2585:           buf.append("\u1e42");
                   2586:           break; // M underdot
                   2587:         case 8230:
                   2588:           buf.append("\u2026");
                   2589:           break; // ellipsis
                   2590:         case 192:
                   2591:           buf.append("\u00c0");
                   2592:           break; // A grave
                   2593:         case 195:
                   2594:           buf.append("\u00c3");
                   2595:           break; // A tilde
                   2596:         case 213:
                   2597:           buf.append("\u00d5");
                   2598:           break; // O tilde
                   2599:         case 338:
                   2600:           buf.append("m\u0306");
                   2601:           break; // m breve
                   2602:         case 339:
                   2603:           buf.append("\u0153");
                   2604:           break; // oe
                   2605:         case 8211:
                   2606:           buf.append("\u2013");
                   2607:           break; // endash
                   2608:         case 8212:
                   2609:           buf.append("\u2014");
                   2610:           break; // emdash
                   2611:         case 8220:
                   2612:           buf.append("\u201c");
                   2613:           break; // quotedblleft
                   2614:         case 8221:
                   2615:           buf.append("\u201d");
                   2616:           break; // quotedblright
                   2617:         case 8216:
                   2618:           buf.append("\u2018");
                   2619:           break; // quoteleft
                   2620:         case 8217:
                   2621:           buf.append("\u2019");
                   2622:           break; // quoteright
                   2623:         case 247:
                   2624:           buf.append("\u1e37");
                   2625:           break; // l underring [actually underdot]
                   2626:         case 9674:
                   2627:           buf.append("\u1e41");
                   2628:           break; // m overdot
                   2629:         case 255:
                   2630:           buf.append("n\u0306");
                   2631:           break; // n breve
                   2632:         case 376:
                   2633:           buf.append("\u00d7");
                   2634:           break; // multiply
                   2635:         case 8364:
                   2636:           buf.append("\u1e5b");
                   2637:           break; // r underring [actually underdot]
                   2638:         case 8249:
                   2639:           buf.append("\u1e44");
                   2640:           break; // N overdot
                   2641:         case 8250:
                   2642:           buf.append("\u1e62");
                   2643:           break; // S underdot
                   2644:         case 64257:
                   2645:           buf.append("\u1e24");
                   2646:           break; // H underdot
                   2647:         case 64258:
                   2648:           buf.append("\u1e0c");
                   2649:           break; // D underdot
                   2650:         case 8225:
                   2651:           buf.append("\u2021");
                   2652:           break; // daggerdbl
                   2653:         case 8218:
                   2654:           buf.append("\u1e36");
                   2655:           break; // L underdot
                   2656:         case 8222:
                   2657:           buf.append("\u0113");
                   2658:           break; // e macron
                   2659:         case 194:
                   2660:           buf.append("\u1e5f");
                   2661:           break; // r underbar
                   2662:         case 202:
                   2663:           buf.append("r\u0324");
                   2664:           break; // r underdieresis
                   2665:         case 193:
                   2666:           buf.append("\u012a");
                   2667:           break; // I macron
                   2668:         case 8486:
                   2669:         case 203:
                   2670:           buf.append("\u016b");
                   2671:           break; // u macron
                   2672:         case 200:
                   2673:           buf.append("\u1e6c");
                   2674:           break; // T underdot
                   2675:         case 205:
                   2676:           buf.append("\u1e64");
                   2677:           break; // S acute
                   2678:         case 206:
                   2679:           buf.append("\u2020");
                   2680:           break; // dagger
                   2681:         case 207:
                   2682:           buf.append("\u0115");
                   2683:           break; // e breve
                   2684:         case 204:
                   2685:           buf.append("\u014f");
                   2686:           break; // o breve
                   2687:         case 211:
                   2688:           buf.append("\u0100");
                   2689:           break; // A macron
                   2690:         case 212:
                   2691:           buf.append("\u1e46");
                   2692:           break; // N underdot
                   2693:         case 210:
                   2694:           buf.append("\u1e3b");
                   2695:           break; // l underbar
                   2696:         case 218:
                   2697:           buf.append("\u016a");
                   2698:           break; // U macron
                   2699:         case 219:
                   2700:           buf.append("\u0179");
                   2701:           break; // Z acute
                   2702:         case 217:
                   2703:           buf.append("\u1e5a");
                   2704:           break; // R underdot
                   2705:         case 305:
                   2706:           buf.append("\u0131");
                   2707:           break; // dotlessi
                   2708:         case 710:
                   2709:           buf.append("\u1e47");
                   2710:           break; // n underdot
                   2711:         case 732:
                   2712:           buf.append("\u1e49");
                   2713:           break; // n underbar
                   2714:         case 175:
                   2715:           buf.append("\u0304");
                   2716:           break; // macron
                   2717:         case 728:
                   2718:           buf.append("\u0306");
                   2719:           break; // breve
                   2720:         case 729:
                   2721:         case 215:
                   2722:           buf.append("\u1e25");
                   2723:           break; // h underdot
                   2724:         case 730:
                   2725:           buf.append("\u012d");
                   2726:           break; // i breve
                   2727:         case 184:
                   2728:           buf.append("\u0327");
                   2729:           break; // cedilla
                   2730:         case 733:
                   2731:           buf.append("\u030b");
                   2732:           break; // hungarumlaut
                   2733:         case 731:
                   2734:           buf.append("\u0328");
                   2735:           break; // ogonek
                   2736:         case 711:
                   2737:           buf.append("\u030c");
                   2738:           break; // caron
                   2739:         case 199:
                   2740:           buf.append("\u012b\u0303");
                   2741:           break; // imacron tilde
                   2742:         case 8226:
                   2743:           buf.append("\u1e5d");
                   2744:           break; // runderdot macron
                   2745:         case 8482:
                   2746:           buf.append("\u016b\0306");
                   2747:           break; // umacron breve
                   2748:         case 8804:
                   2749:           buf.append("\u0101\u0301");
                   2750:           break; // amacron acute
                   2751:         case 8805:
                   2752:           buf.append("\u016b\u0301");
                   2753:           break; // umacron acute
                   2754:         case 8719:
                   2755:           buf.append("\u0113\u0301");
                   2756:           break; // emacron acute
                   2757:         case 170:
                   2758:           buf.append("\u0113\u0300");
                   2759:           break; // emacron breve
                   2760:         case 186:
                   2761:           buf.append("\u014d\u0300");
                   2762:           break; // omacron breve
                   2763:         case 161:
                   2764:           buf.append("\u0101\u0306");
                   2765:           break; // amacron breve
                   2766:         case 8710:
                   2767:           buf.append("\u0101\u0303");
                   2768:           break; // amacron tilde
                   2769:         case 171:
                   2770:           buf.append("\u012b\u0301");
                   2771:           break; // imacron acute
                   2772:         case 8260:
                   2773:           buf.append("\u1e00");
                   2774:           break; // runderdotmacron acute
                   2775:         case 183:
                   2776:           buf.append("\u1e5b\u0301");
                   2777:           break; // runderdot acute
                   2778:         case 8240:
                   2779:           buf.append("\u012b\u0306");
                   2780:           break; // imacron breve
                   2781:         case 63743:
                   2782:           buf.append("\u016b\u0303");
                   2783:           break; // umacron tilde
                   2784:         default:
                   2785:           buf.append(c);
                   2786:           if ((int) c > 127)
                   2787:             System.out.println("char " + c + " " + (int) c);
                   2788:           break;
                   2789:       }
                   2790:     }
                   2791:     return buf.toString();
                   2792:   }
                   2793: 
                   2794:   static public String normanToUnicodeOld(String inp)
                   2795:   {
                   2796:     StringBuffer buf = new StringBuffer();
                   2797:     for (int i = 0; i < inp.length(); i++)
                   2798:     {
                   2799:       char c = inp.charAt(i);
                   2800:       switch (c)
                   2801:       {
                   2802:         case 1:
                   2803:           buf.append("\u00d0");
                   2804:           break; // Eth
                   2805:         case 2:
                   2806:           buf.append("\u00f0");
                   2807:           break; // eth
                   2808:         case 3:
                   2809:           buf.append("\u0141");
                   2810:           break; // Lslash
                   2811:         case 4:
                   2812:           buf.append("\u0142");
                   2813:           break; // lslash
                   2814:         case 5:
                   2815:           buf.append("\u0160");
                   2816:           break; // S caron
                   2817:         case 6:
                   2818:           buf.append("\u0161");
                   2819:           break; // s caron
                   2820:         case 7:
                   2821:           buf.append("\u00dd");
                   2822:           break; // Y acute
                   2823:         case 8:
                   2824:           buf.append("\u00fd");
                   2825:           break; // y acute
                   2826:         case 11:
                   2827:           buf.append("\u00de");
                   2828:           break; // Thorn
                   2829:         case 12:
                   2830:           buf.append("\u00fe");
                   2831:           break; // thorn
                   2832:         case 14:
                   2833:           buf.append("\u017d");
                   2834:           break; // Z caron
                   2835:         case 15:
                   2836:           buf.append("\u017e");
                   2837:           break; // z caron
                   2838:         case 17:
                   2839:           buf.append("\u0073");
                   2840:           break; // asciitilde
                   2841:         case 18:
                   2842:           buf.append("j\u0305");
                   2843:           break; // j macron [does a single char exist?]
                   2844:         case 19:
                   2845:           buf.append("^");
                   2846:           break; // circumflex
                   2847:         case 20:
                   2848:           buf.append("\u0303");
                   2849:           break; // tilde
                   2850:         case 21:
                   2851:           buf.append("\u00bd");
                   2852:           break; // onehalf
                   2853:         case 22:
                   2854:           buf.append("\u00bc");
                   2855:           break; // onequarter
                   2856:         case 23:
                   2857:           buf.append("\u00b9");
                   2858:           break; // onesuperior
                   2859:         case 24:
                   2860:           buf.append("\u00be");
                   2861:           break; // threequarters
                   2862:         case 25:
                   2863:           buf.append("\u00b3");
                   2864:           break; // threesuperior
                   2865:         case 26:
                   2866:           buf.append("\u00b2");
                   2867:           break; // twosuperior
                   2868:         case 27:
                   2869:           buf.append("\u00a6");
                   2870:           break; // brokenbar
                   2871:         case 28:
                   2872:           buf.append("-");
                   2873:           break; // minus
                   2874:         case 29:
                   2875:           buf.append("\u00d7");
                   2876:           break; // multiply
                   2877:         case 39:
                   2878:           buf.append("'");
                   2879:           break; // quotesingle
                   2880:         case 94:
                   2881:           buf.append("\u0302");
                   2882:           break; // circumflex
                   2883:         case 96:
                   2884:           buf.append("\u0300");
                   2885:           break; // grave
                   2886:         case 128:
                   2887:           buf.append("\u00c4");
                   2888:           break; // A dieresis
                   2889:         case 129:
                   2890:           buf.append("\u00c5");
                   2891:           break; // A ring
                   2892:         case 131:
                   2893:           buf.append("\u00c9");
                   2894:           break; // E acute
                   2895:         case 132:
                   2896:           buf.append("\u00d1");
                   2897:           break; // N tilde
                   2898:         case 133:
                   2899:           buf.append("\u00d6");
                   2900:           break; // O dieresis
                   2901:         case 134:
                   2902:           buf.append("\u00dc");
                   2903:           break; // U dieresis
                   2904:         case 135:
                   2905:           buf.append("\u00e1");
                   2906:           break; // a acute
                   2907:         case 136:
                   2908:           buf.append("\u00e0");
                   2909:           break; // a grave
                   2910:         case 137:
                   2911:           buf.append("\u00e2");
                   2912:           break; // a circumflex
                   2913:         case 138:
                   2914:           buf.append("\u00e4");
                   2915:           break; // a dieresis
                   2916:         case 139:
                   2917:           buf.append("\u00e3");
                   2918:           break; // a tilde
                   2919:         case 140:
                   2920:           buf.append("\u0101");
                   2921:           break; // a macron
                   2922:         case 141:
                   2923:           buf.append("\u00e7");
                   2924:           break; // c cedilla
                   2925:         case 142:
                   2926:           buf.append("\u00e9");
                   2927:           break; // e acute
                   2928:         case 143:
                   2929:           buf.append("\u00e8");
                   2930:           break; // e grave
                   2931:         case 144:
                   2932:           buf.append("\u00ea");
                   2933:           break; // e circumflex
                   2934:         case 145:
                   2935:           buf.append("\u00eb");
                   2936:           break; // e dieresis
                   2937:         case 146:
                   2938:           buf.append("\u00ed");
                   2939:           break; // i acute
                   2940:         case 147:
                   2941:           buf.append("\u00ec");
                   2942:           break; // i grave
                   2943:         case 148:
                   2944:           buf.append("\u00ee");
                   2945:           break; // i circumflex
                   2946:         case 149:
                   2947:           buf.append("\u00ef");
                   2948:           break; // i dieresis
                   2949:         case 150:
                   2950:           buf.append("\u00f1");
                   2951:           break; // n tilde
                   2952:         case 151:
                   2953:           buf.append("\u00f3");
                   2954:           break; // o acute
                   2955:         case 152:
                   2956:           buf.append("\u00f2");
                   2957:           break; // o grave
                   2958:         case 153:
                   2959:           buf.append("\u00f4");
                   2960:           break; // o circumflex
                   2961:         case 154:
                   2962:           buf.append("\u00f6");
                   2963:           break; // o dieresis
                   2964:         case 155:
                   2965:           buf.append("\u00f5");
                   2966:           break; // o tilde
                   2967:         case 156:
                   2968:           buf.append("\u00fa");
                   2969:           break; // u acute
                   2970:         case 157:
                   2971:           buf.append("\u00f9");
                   2972:           break; // u grave
                   2973:         case 158:
                   2974:           buf.append("\u00fb");
                   2975:           break; // u circumflex
                   2976:         case 159:
                   2977:           buf.append("\u00fc");
                   2978:           break; // u dieresis
                   2979:         case 160:
                   2980:           buf.append("\u1e6d");
                   2981:           break; // t underdot
                   2982:         case 161:
                   2983:           buf.append("\u00b0");
                   2984:           break; // degree
                   2985:         case 162:
                   2986:           buf.append("\u1ebd");
                   2987:           break; // e tilde
                   2988:         case 163:
                   2989:           buf.append("\u00a3");
                   2990:           break; // sterling
                   2991:         case 164:
                   2992:           buf.append("\u00a7");
                   2993:           break; // section
                   2994:         case 166:
                   2995:           buf.append("\u00b6");
                   2996:           break; // paragraph
                   2997:         case 167:
                   2998:           buf.append("\u015b");
                   2999:           break; // s acute
                   3000:         case 168:
                   3001:           buf.append("\u1e5b");
                   3002:           break; // r underdot
                   3003:         case 169:
                   3004:           buf.append("\u1e67");
                   3005:           break; // s caron
                   3006:         case 171:
                   3007:           buf.append("\u0301");
                   3008:           break; // acute
                   3009:         case 172:
                   3010:           buf.append("\u0308");
                   3011:           break; // dieresis
                   3012:         case 173:
                   3013:           buf.append("\u1e6d");
                   3014:           break; // t underdot
                   3015:         case 174:
                   3016:           buf.append("\u00c6");
                   3017:           break; // AE
                   3018:         case 175:
                   3019:           buf.append("\u014d");
                   3020:           break; // o macron
                   3021:         case 176:
                   3022:           buf.append("\u0129");
                   3023:           break; // i tilde
                   3024:         case 177:
                   3025:           buf.append("\u00b1");
                   3026:           break; // plusminus
                   3027:         case 180:
                   3028:           buf.append("\u012b");
                   3029:           break; // i macron
                   3030:         case 181:
                   3031:           buf.append("\u1e43");
                   3032:           break; // m underdot
                   3033:         case 182:
                   3034:           buf.append("\u1e0d");
                   3035:           break; // d underdot
                   3036:         case 183:
                   3037:           buf.append("\u1e63");
                   3038:           break; // s underdot
                   3039:         case 185:
                   3040:           buf.append("\u017a");
                   3041:           break; // z acute
                   3042:         case 186:
                   3043:           buf.append("\u1e45");
                   3044:           break; // n overdot
                   3045:         case 189:
                   3046:           buf.append("\u0169");
                   3047:           break; // u tilde
                   3048:         case 190:
                   3049:           buf.append("\u00e6");
                   3050:           break; // ae
                   3051:         case 191:
                   3052:           buf.append("\u00f8");
                   3053:           break; // oslash
                   3054:         case 192:
                   3055:           buf.append("\u0304\u0306");
                   3056:           break; // macron breve
                   3057:         case 194:
                   3058:           buf.append("\u1e37");
                   3059:           break; // 
                   3060:         case 195:
                   3061:           buf.append("j\u0305");
                   3062:           break; // j macron [does a single char exist?]
                   3063:         case 196:
                   3064:           buf.append("\u0103");
                   3065:           break; // a breve
                   3066:         case 197:
                   3067:           buf.append("\u016d");
                   3068:           break; // u breve
                   3069:         case 200:
                   3070:           buf.append("\u1e42");
                   3071:           break; // M underdot
                   3072:         case 201:
                   3073:           buf.append("\u2026");
                   3074:           break; // ellipsis
                   3075:         case 203:
                   3076:           buf.append("\u00c0");
                   3077:           break; // A grave
                   3078:         case 204:
                   3079:           buf.append("\u00c3");
                   3080:           break; // A tilde
                   3081:         case 205:
                   3082:           buf.append("\u00d5");
                   3083:           break; // O tilde
                   3084:         case 206:
                   3085:           buf.append("m\u0306");
                   3086:           break; // m breve
                   3087:         case 207:
                   3088:           buf.append("\u0153");
                   3089:           break; // oe
                   3090:         case 208:
                   3091:           buf.append("\u2013");
                   3092:           break; // endash
                   3093:         case 209:
                   3094:           buf.append("\u2014");
                   3095:           break; // emdash
                   3096:         case 210:
                   3097:           buf.append("\u201c");
                   3098:           break; // quotedblleft
                   3099:         case 211:
                   3100:           buf.append("\u201d");
                   3101:           break; // quotedblright
                   3102:         case 212:
                   3103:           buf.append("\u2018");
                   3104:           break; // quoteleft
                   3105:         case 213:
                   3106:           buf.append("\u2019");
                   3107:           break; // quoteright
                   3108:         case 214:
                   3109:           buf.append("\u1e37");
                   3110:           break; // l underring [actually underdot]
                   3111:         case 215:
                   3112:           buf.append("\u1e41");
                   3113:           break; // m overdot
                   3114:         case 216:
                   3115:           buf.append("n\u0306");
                   3116:           break; // n breve
                   3117:         case 217:
                   3118:           buf.append("\u00d7");
                   3119:           break; // multiply
                   3120:         case 219:
                   3121:           buf.append("\u1e5b");
                   3122:           break; // r underring [actually underdot]
                   3123:         case 220:
                   3124:           buf.append("\u1e44");
                   3125:           break; // N overdot
                   3126:         case 221:
                   3127:           buf.append("\u1e62");
                   3128:           break; // S underdot
                   3129:         case 222:
                   3130:           buf.append("\u1e24");
                   3131:           break; // H underdot
                   3132:         case 223:
                   3133:           buf.append("\u1e0c");
                   3134:           break; // D underdot
                   3135:         case 224:
                   3136:           buf.append("\u2021");
                   3137:           break; // daggerdbl
                   3138:         case 226:
                   3139:           buf.append("\u1e36");
                   3140:           break; // L underdot
                   3141:         case 227:
                   3142:           buf.append("\u0113");
                   3143:           break; // e macron
                   3144:         case 229:
                   3145:           buf.append("\u1e5f");
                   3146:           break; // r underbar
                   3147:         case 230:
                   3148:           buf.append("r\u0324");
                   3149:           break; // r underdieresis
                   3150:         case 231:
                   3151:           buf.append("\u012a");
                   3152:           break; // I macron
                   3153:         case 232:
                   3154:           buf.append("\u016b");
                   3155:           break; // u macron
                   3156:         case 233:
                   3157:           buf.append("\u01e6c");
                   3158:           break; // T underdot
                   3159:         case 234:
                   3160:           buf.append("\u1e64");
                   3161:           break; // S acute
                   3162:         case 235:
                   3163:           buf.append("\u2020");
                   3164:           break; // dagger
                   3165:         case 236:
                   3166:           buf.append("\u0115");
                   3167:           break; // e breve
                   3168:         case 237:
                   3169:           buf.append("\u014f");
                   3170:           break; // o breve
                   3171:         case 238:
                   3172:           buf.append("\u0100");
                   3173:           break; // A macron
                   3174:         case 239:
                   3175:           buf.append("\u1e46");
                   3176:           break; // N underdot
                   3177:         case 241:
                   3178:           buf.append("\u1e3b");
                   3179:           break; // l underbar
                   3180:         case 242:
                   3181:           buf.append("\u016a");
                   3182:           break; // U macron
                   3183:         case 243:
                   3184:           buf.append("\u0179");
                   3185:           break; // Z acute
                   3186:         case 244:
                   3187:           buf.append("\u1e5a");
                   3188:           break; // R underdot
                   3189:         case 245:
                   3190:           buf.append("\u0131");
                   3191:           break; // dotlessi
                   3192:         case 246:
                   3193:           buf.append("\u1e47");
                   3194:           break; // n underdot
                   3195:         case 247:
                   3196:           buf.append("\u1e49");
                   3197:           break; // n underbar
                   3198:         case 248:
                   3199:           buf.append("\u0304");
                   3200:           break; // macron
                   3201:         case 249:
                   3202:           buf.append("\u0306");
                   3203:           break; // breve
                   3204:         case 250:
                   3205:           buf.append("\u1e25");
                   3206:           break; // h underdot
                   3207:         case 251:
                   3208:           buf.append("\u012d");
                   3209:           break; // i breve
                   3210:         case 252:
                   3211:           buf.append("\u0327");
                   3212:           break; // cedilla
                   3213:         case 253:
                   3214:           buf.append("\u030b");
                   3215:           break; // hungarumlaut
                   3216:         case 254:
                   3217:           buf.append("\u0328");
                   3218:           break; // ogonek
                   3219:         case 255:
                   3220:           buf.append("\u030c");
                   3221:           break; // caron
                   3222:         case 130:
                   3223:           buf.append("\u012b\u0303");
                   3224:           break; // imacron tilde
                   3225:         case 165:
                   3226:           buf.append("\u1e5d");
                   3227:           break; // runderdot macron
                   3228:         case 170:
                   3229:           buf.append("\u016b\0306");
                   3230:           break; // umacron breve
                   3231:         case 178:
                   3232:           buf.append("\u0101\u0301");
                   3233:           break; // amacron acute
                   3234:         case 179:
                   3235:           buf.append("\u016b\u0301");
                   3236:           break; // umacron acute
                   3237:         case 184:
                   3238:           buf.append("\u0113\u0301");
                   3239:           break; // emacron acute
                   3240:         case 187:
                   3241:           buf.append("\u0113\u0300");
                   3242:           break; // emacron breve
                   3243:         case 188:
                   3244:           buf.append("\u014d\u0300");
                   3245:           break; // omacron breve
                   3246:         case 193:
                   3247:           buf.append("\u0101\u0306");
                   3248:           break; // amacron breve
                   3249:         case 198:
                   3250:           buf.append("\u0101\u0303");
                   3251:           break; // amacron tilde
                   3252:         case 199:
                   3253:           buf.append("\u012b\u0301");
                   3254:           break; // imacron acute
                   3255:         case 218:
                   3256:           buf.append("\u1e00");
                   3257:           break; // runderdotmacron acute
                   3258:         case 225:
                   3259:           buf.append("\u1e5b\u0301");
                   3260:           break; // runderdot acute
                   3261:         case 228:
                   3262:           buf.append("\u012b\u0306");
                   3263:           break; // imacron breve
                   3264:         case 240:
                   3265:           buf.append("\u016b\u0303");
                   3266:           break; // umacron tilde
                   3267:         default:
                   3268:           buf.append(c);
                   3269:           break;
                   3270:       }
                   3271:     }
                   3272:     return buf.toString();
                   3273:   }
                   3274: 
                   3275:   static public String normanToUnicodeNew(String inp)
                   3276:   {
                   3277:     StringBuffer buf = new StringBuffer();
                   3278:     for (int i = 0; i < inp.length(); i++)
                   3279:     {
                   3280:       char c = inp.charAt(i);
                   3281:       switch (c)
                   3282:       {
                   3283:         case 1:
                   3284:           buf.append("\u00d0");
                   3285:           break; // Eth
                   3286:         case 2:
                   3287:           buf.append("\u00f0");
                   3288:           break; // eth
                   3289:         case 3:
                   3290:           buf.append("\u0141");
                   3291:           break; // Lslash
                   3292:         case 4:
                   3293:           buf.append("\u0142");
                   3294:           break; // lslash
                   3295:         case 5:
                   3296:           buf.append("\u0160");
                   3297:           break; // S caron
                   3298:         case 6:
                   3299:           buf.append("\u0161");
                   3300:           break; // s caron
                   3301:         case 7:
                   3302:           buf.append("\u00dd");
                   3303:           break; // Y acute
                   3304:         case 8:
                   3305:           buf.append("\u00fd");
                   3306:           break; // y acute
                   3307:         case 11:
                   3308:           buf.append("\u00de");
                   3309:           break; // Thorn
                   3310:         case 12:
                   3311:           buf.append("\u00fe");
                   3312:           break; // thorn
                   3313:         case 14:
                   3314:           buf.append("\u017d");
                   3315:           break; // Z caron
                   3316:         case 15:
                   3317:           buf.append("\u017e");
                   3318:           break; // z caron
                   3319:         case 17:
                   3320:           buf.append("\u0073");
                   3321:           break; // asciitilde
                   3322:         case 18:
                   3323:           buf.append("j\u0305");
                   3324:           break; // j macron [does a single char exist?]
                   3325:         case 19:
                   3326:           buf.append("^");
                   3327:           break; // circumflex
                   3328:         case 20:
                   3329:           buf.append("\u0303");
                   3330:           break; // tilde
                   3331:         case 21:
                   3332:           buf.append("\u00bd");
                   3333:           break; // onehalf
                   3334:         case 22:
                   3335:           buf.append("\u00bc");
                   3336:           break; // onequarter
                   3337:         case 23:
                   3338:           buf.append("\u00b9");
                   3339:           break; // onesuperior
                   3340:         case 24:
                   3341:           buf.append("\u00be");
                   3342:           break; // threequarters
                   3343:         case 25:
                   3344:           buf.append("\u00b3");
                   3345:           break; // threesuperior
                   3346:         case 26:
                   3347:           buf.append("\u00b2");
                   3348:           break; // twosuperior
                   3349:         case 27:
                   3350:           buf.append("\u00a6");
                   3351:           break; // brokenbar
                   3352:         case 28:
                   3353:           buf.append("-");
                   3354:           break; // minus
                   3355:         case 29:
                   3356:           buf.append("\u00d7");
                   3357:           break; // multiply
                   3358:         case 39:
                   3359:           buf.append("'");
                   3360:           break; // quotesingle
                   3361:         case 94:
                   3362:           buf.append("\u0302");
                   3363:           break; // circumflex
                   3364:         case 96:
                   3365:           buf.append("\u0300");
                   3366:           break; // grave
                   3367:         case 196:
                   3368:           buf.append("\u00c4");
                   3369:           break; // A dieresis
                   3370:         case 197:
                   3371:           buf.append("\u00c5");
                   3372:           break; // A ring
                   3373:         case 201:
                   3374:           buf.append("\u00c9");
                   3375:           break; // E acute
                   3376:         case 209:
                   3377:           buf.append("\u00d1");
                   3378:           break; // N tilde
                   3379:         case 214:
                   3380:           buf.append("\u00d6");
                   3381:           break; // O dieresis
                   3382:         case 220:
                   3383:           buf.append("\u00dc");
                   3384:           break; // U dieresis
                   3385:         case 225:
                   3386:           buf.append("\u00e1");
                   3387:           break; // a acute
                   3388:         case 224:
                   3389:           buf.append("\u00e0");
                   3390:           break; // a grave
                   3391:         case 226:
                   3392:           buf.append("\u00e2");
                   3393:           break; // a circumflex
                   3394:         case 228:
                   3395:           buf.append("\u00e4");
                   3396:           break; // a dieresis
                   3397:         case 227:
                   3398:           buf.append("\u00e3");
                   3399:           break; // a tilde
                   3400:         case 229:
                   3401:           buf.append("\u0101");
                   3402:           break; // a macron
                   3403:         case 231:
                   3404:           buf.append("\u00e7");
                   3405:           break; // c cedilla
                   3406:         case 233:
                   3407:           buf.append("\u00e9");
                   3408:           break; // e acute
                   3409:         case 232:
                   3410:           buf.append("\u00e8");
                   3411:           break; // e grave
                   3412:         case 234:
                   3413:           buf.append("\u00ea");
                   3414:           break; // e circumflex
                   3415:         case 235:
                   3416:           buf.append("\u00eb");
                   3417:           break; // e dieresis
                   3418:         case 237:
                   3419:           buf.append("\u00ed");
                   3420:           break; // i acute
                   3421:         case 236:
                   3422:           buf.append("\u00ec");
                   3423:           break; // i grave
                   3424:         case 238:
                   3425:           buf.append("\u00ee");
                   3426:           break; // i circumflex
                   3427:         case 239:
                   3428:           buf.append("\u00ef");
                   3429:           break; // i dieresis
                   3430:         case 241:
                   3431:           buf.append("\u00f1");
                   3432:           break; // n tilde
                   3433:         case 243:
                   3434:           buf.append("\u00f3");
                   3435:           break; // o acute
                   3436:         case 242:
                   3437:           buf.append("\u00f2");
                   3438:           break; // o grave
                   3439:         case 244:
                   3440:           buf.append("\u00f4");
                   3441:           break; // o circumflex
                   3442:         case 246:
                   3443:           buf.append("\u00f6");
                   3444:           break; // o dieresis
                   3445:         case 245:
                   3446:           buf.append("\u00f5");
                   3447:           break; // o tilde
                   3448:         case 250:
                   3449:           buf.append("\u00fa");
                   3450:           break; // u acute
                   3451:         case 249:
                   3452:           buf.append("\u00f9");
                   3453:           break; // u grave
                   3454:         case 251:
                   3455:           buf.append("\u00fb");
                   3456:           break; // u circumflex
                   3457:         case 252:
                   3458:           buf.append("\u00fc");
                   3459:           break; // u dieresis
                   3460:         case 8224:
                   3461:           buf.append("\u1e6d");
                   3462:           break; // t underdot
                   3463:         case 176:
                   3464:           buf.append("\u00b0");
                   3465:           break; // degree
                   3466:         case 162:
                   3467:           buf.append("\u1ebd");
                   3468:           break; // e tilde
                   3469:         case 163:
                   3470:           buf.append("\u00a3");
                   3471:           break; // sterling
                   3472:         case 167:
                   3473:           buf.append("\u00a7");
                   3474:           break; // section
                   3475:         case 182:
                   3476:           buf.append("\u00b6");
                   3477:           break; // paragraph
                   3478:         case 223:
                   3479:           buf.append("\u015b");
                   3480:           break; // s acute
                   3481:         case 174:
                   3482:           buf.append("\u1e5b");
                   3483:           break; // r underdot
                   3484:         case 169:
                   3485:           buf.append("\u1e45");
                   3486:           break; // n overdot
                   3487:         case 180:
                   3488:           buf.append("\u0301");
                   3489:           break; // acute
                   3490:         case 168:
                   3491:           buf.append("\u0308");
                   3492:           break; // dieresis
                   3493:         case 8800:
                   3494:           buf.append("\u1e6d");
                   3495:           break; // t underdot
                   3496:         case 198:
                   3497:           buf.append("\u00c6");
                   3498:           break; // AE
                   3499:         case 216:
                   3500:           buf.append("\u014d");
                   3501:           break; // o macron
                   3502:         case 8734:
                   3503:           buf.append("\u0129");
                   3504:           break; // i tilde
                   3505:         case 177:
                   3506:           buf.append("\u00b1");
                   3507:           break; // plusminus
                   3508:         case 165:
                   3509:           buf.append("\u012b");
                   3510:           break; // i macron
                   3511:         case 181:
                   3512:           buf.append("\u1e43");
                   3513:           break; // m underdot
                   3514:         case 8706:
                   3515:           buf.append("\u1e0d");
                   3516:           break; // d underdot
                   3517:         case 8721:
                   3518:           buf.append("\u1e63");
                   3519:           break; // s underdot
                   3520:         case 960:
                   3521:           buf.append("\u017a");
                   3522:           break; // z acute
                   3523:         case 8747:
                   3524:           buf.append("\u1e45");
                   3525:           break; // n overdot
                   3526:         case 937:
                   3527:           buf.append("\u0169");
                   3528:           break; // u tilde
                   3529:         case 230:
                   3530:           buf.append("\u00e6");
                   3531:           break; // ae
                   3532:         case 248:
                   3533:           buf.append("\u00f8");
                   3534:           break; // oslash
                   3535:         case 191:
                   3536:           buf.append("\u0304\u0306");
                   3537:           break; // macron breve
                   3538:         case 172:
                   3539:           buf.append("\u1e37");
                   3540:           break; // 
                   3541:         case 8730:
                   3542:           buf.append("j\u0305");
                   3543:           break; // j macron [does a single char exist?]
                   3544:         case 402:
                   3545:           buf.append("\u0103");
                   3546:           break; // a breve
                   3547:         case 8776:
                   3548:           buf.append("\u016d");
                   3549:           break; // u breve
                   3550:         case 187:
                   3551:           buf.append("\u1e42");
                   3552:           break; // M underdot
                   3553:         case 8230:
                   3554:           buf.append("\u2026");
                   3555:           break; // ellipsis
                   3556:         case 192:
                   3557:           buf.append("\u00c0");
                   3558:           break; // A grave
                   3559:         case 195:
                   3560:           buf.append("\u00c3");
                   3561:           break; // A tilde
                   3562:         case 213:
                   3563:           buf.append("\u00d5");
                   3564:           break; // O tilde
                   3565:         case 338:
                   3566:           buf.append("m\u0306");
                   3567:           break; // m breve
                   3568:         case 339:
                   3569:           buf.append("\u0153");
                   3570:           break; // oe
                   3571:         case 8211:
                   3572:           buf.append("\u2013");
                   3573:           break; // endash
                   3574:         case 8212:
                   3575:           buf.append("\u2014");
                   3576:           break; // emdash
                   3577:         case 8220:
                   3578:           buf.append("\u201c");
                   3579:           break; // quotedblleft
                   3580:         case 8221:
                   3581:           buf.append("\u201d");
                   3582:           break; // quotedblright
                   3583:         case 8216:
                   3584:           buf.append("\u2018");
                   3585:           break; // quoteleft
                   3586:         case 8217:
                   3587:           buf.append("\u2019");
                   3588:           break; // quoteright
                   3589:         case 247:
                   3590:           buf.append("\u1e37");
                   3591:           break; // l underring [actually underdot]
                   3592:         case 9674:
                   3593:           buf.append("\u1e41");
                   3594:           break; // m overdot
                   3595:         case 255:
                   3596:           buf.append("n\u0306");
                   3597:           break; // n breve
                   3598:         case 376:
                   3599:           buf.append("\u00d7");
                   3600:           break; // multiply
                   3601:         case 8364:
                   3602:           buf.append("\u1e5b");
                   3603:           break; // r underring [actually underdot]
                   3604:         case 8249:
                   3605:           buf.append("\u1e44");
                   3606:           break; // N overdot
                   3607:         case 8250:
                   3608:           buf.append("\u1e62");
                   3609:           break; // S underdot
                   3610:         case 64257:
                   3611:           buf.append("\u1e24");
                   3612:           break; // H underdot
                   3613:         case 64258:
                   3614:           buf.append("\u1e0c");
                   3615:           break; // D underdot
                   3616:         case 8225:
                   3617:           buf.append("\u2021");
                   3618:           break; // daggerdbl
                   3619:         case 8218:
                   3620:           buf.append("\u1e36");
                   3621:           break; // L underdot
                   3622:         case 8222:
                   3623:           buf.append("\u0113");
                   3624:           break; // e macron
                   3625:         case 194:
                   3626:           buf.append("\u1e5f");
                   3627:           break; // r underbar
                   3628:         case 202:
                   3629:           buf.append("r\u0324");
                   3630:           break; // r underdieresis
                   3631:         case 193:
                   3632:           buf.append("\u012a");
                   3633:           break; // I macron
                   3634:         case 203:
                   3635:           buf.append("\u016b");
                   3636:           break; // u macron
                   3637:         case 200:
                   3638:           buf.append("\u1e6c");
                   3639:           break; // T underdot
                   3640:         case 205:
                   3641:           buf.append("\u1e64");
                   3642:           break; // S acute
                   3643:         case 206:
                   3644:           buf.append("\u2020");
                   3645:           break; // dagger
                   3646:         case 207:
                   3647:           buf.append("\u0115");
                   3648:           break; // e breve
                   3649:         case 204:
                   3650:           buf.append("\u014f");
                   3651:           break; // o breve
                   3652:         case 211:
                   3653:           buf.append("\u0100");
                   3654:           break; // A macron
                   3655:         case 212:
                   3656:           buf.append("\u1e46");
                   3657:           break; // N underdot
                   3658:         case 210:
                   3659:           buf.append("\u1e3b");
                   3660:           break; // l underbar
                   3661:         case 218:
                   3662:           buf.append("\u016a");
                   3663:           break; // U macron
                   3664:         case 219:
                   3665:           buf.append("\u0179");
                   3666:           break; // Z acute
                   3667:         case 217:
                   3668:           buf.append("\u1e5a");
                   3669:           break; // R underdot
                   3670:         case 305:
                   3671:           buf.append("\u0131");
                   3672:           break; // dotlessi
                   3673:         case 710:
                   3674:           buf.append("\u1e47");
                   3675:           break; // n underdot
                   3676:         case 732:
                   3677:           buf.append("\u1e49");
                   3678:           break; // n underbar
                   3679:         case 175:
                   3680:           buf.append("\u0304");
                   3681:           break; // macron
                   3682:         case 728:
                   3683:           buf.append("\u0306");
                   3684:           break; // breve
                   3685:         case 729:
                   3686:           buf.append("\u1e25");
                   3687:           break; // h underdot
                   3688:         case 730:
                   3689:           buf.append("\u012d");
                   3690:           break; // i breve
                   3691:         case 184:
                   3692:           buf.append("\u0327");
                   3693:           break; // cedilla
                   3694:         case 733:
                   3695:           buf.append("\u030b");
                   3696:           break; // hungarumlaut
                   3697:         case 731:
                   3698:           buf.append("\u0328");
                   3699:           break; // ogonek
                   3700:         case 711:
                   3701:           buf.append("\u030c");
                   3702:           break; // caron
                   3703:         case 199:
                   3704:           buf.append("\u012b\u0303");
                   3705:           break; // imacron tilde
                   3706:         case 8226:
                   3707:           buf.append("\u1e5d");
                   3708:           break; // runderdot macron
                   3709:         case 8482:
                   3710:           buf.append("\u016b\0306");
                   3711:           break; // umacron breve
                   3712:         case 8804:
                   3713:           buf.append("\u0101\u0301");
                   3714:           break; // amacron acute
                   3715:         case 8805:
                   3716:           buf.append("\u016b\u0301");
                   3717:           break; // umacron acute
                   3718:         case 8719:
                   3719:           buf.append("\u0113\u0301");
                   3720:           break; // emacron acute
                   3721:         case 170:
                   3722:           buf.append("\u0113\u0300");
                   3723:           break; // emacron breve
                   3724:         case 186:
                   3725:           buf.append("\u014d\u0300");
                   3726:           break; // omacron breve
                   3727:         case 161:
                   3728:           buf.append("\u0101\u0306");
                   3729:           break; // amacron breve
                   3730:         case 8710:
                   3731:           buf.append("\u0101\u0303");
                   3732:           break; // amacron tilde
                   3733:         case 171:
                   3734:           buf.append("\u012b\u0301");
                   3735:           break; // imacron acute
                   3736:         case 8260:
                   3737:           buf.append("\u1e00");
                   3738:           break; // runderdotmacron acute
                   3739:         case 183:
                   3740:           buf.append("\u1e5b\u0301");
                   3741:           break; // runderdot acute
                   3742:         case 8240:
                   3743:           buf.append("\u012b\u0306");
                   3744:           break; // imacron breve
                   3745:         case 63743:
                   3746:           buf.append("\u016b\u0303");
                   3747:           break; // umacron tilde
                   3748:         default:
                   3749:           buf.append(c);
                   3750:           break;
                   3751:       }
                   3752:     }
                   3753:     return buf.toString();
                   3754:   }
                   3755: 
                   3756:   public static ConversionProperties getFieldNamesAndDestTableName(String create, String query,
                   3757:       String tableName)
                   3758:   {
                   3759:     String[] fieldNames = null;
                   3760:     String destTableName = null;
                   3761:     // determine destTableName from createStatement or from source table
                   3762:     // name
                   3763:     if (!create.equals(""))
                   3764:     {
                   3765:       int fromIndex = create.toLowerCase().indexOf("table") + 5;
                   3766:       int toIndex = create.indexOf("(");
                   3767:       int endIndex = create.indexOf(")", toIndex);
                   3768: 
                   3769:       destTableName = create.substring(fromIndex, toIndex).replaceAll(beanDest.getQC(), "").trim();
                   3770:       System.out.println("destTable " + destTableName);
                   3771:       // retrieve field_names from select statement
                   3772:       // TODO problem with different fieldNames in create statement will
                   3773:       // overwrite them
1.7       rogo     3774:       if (query.indexOf("*") < 0 && create.equals(""))// quick hack for hartmut
1.4       rogo     3775:       {
                   3776:         int selectEndIndex = query.indexOf("from");
                   3777:         StringTokenizer tokenizer = new StringTokenizer(query.substring(6, selectEndIndex), ",");
                   3778:         int numFields = tokenizer.countTokens();
                   3779:         fieldNames = new String[numFields];
                   3780:         int fieldIndex = 0;
                   3781:         while (tokenizer.hasMoreTokens())
                   3782:         {
                   3783:           String fieldName = tokenizer.nextToken().trim();
                   3784:           fieldNames[fieldIndex] = convertText(fieldName);
                   3785:           System.out.println(fieldNames[fieldIndex]);
                   3786:           fieldIndex++;
                   3787:         }
                   3788: 
                   3789:       } else
                   3790:       {
                   3791:         // use create statement for field names
                   3792:         StringTokenizer tokenizer = new StringTokenizer(create.substring(toIndex + 1, endIndex),
                   3793:             ",");
                   3794:         int numFields = tokenizer.countTokens();
                   3795:         fieldNames = new String[numFields];
                   3796:         int fieldIndex = 0;
                   3797:         while (tokenizer.hasMoreTokens())
                   3798:         {
                   3799:           String fieldName = tokenizer.nextToken().trim();
                   3800:           int index = fieldName.lastIndexOf(" ");
                   3801:           fieldNames[fieldIndex] = fieldName.substring(0, index);
                   3802:           System.out.println(fieldNames[fieldIndex]);
                   3803:           fieldIndex++;
                   3804:         }
                   3805:       }
                   3806:     } else
                   3807:     {
                   3808:       destTableName = convertText(tableName);
                   3809: 
                   3810:       // retrieve field_names from select statement
                   3811:       if (query.indexOf("*") < 0)
                   3812:       {
1.10      rogo     3813:         int selectEndIndex = query.lastIndexOf("from");
1.4       rogo     3814:         StringTokenizer tokenizer = new StringTokenizer(query.substring(6, selectEndIndex), ",");
                   3815:         int numFields = tokenizer.countTokens();
                   3816:         fieldNames = new String[numFields];
                   3817:         int fieldIndex = 0;
                   3818:         while (tokenizer.hasMoreTokens())
                   3819:         {
                   3820:           String fieldName = tokenizer.nextToken().trim();
1.10      rogo     3821:           String text = convertText(fieldName);
                   3822:           if (text.indexOf("\"") >= 0)
                   3823:             fieldNames[fieldIndex] = convertText(fieldName);
                   3824:           else
                   3825:             fieldNames[fieldIndex] = beanDest.getQC() + convertText(fieldName) + beanDest.getQC();
1.4       rogo     3826:           // System.out.println("field "+ fieldNames[fieldIndex]);
                   3827:           fieldIndex++;
                   3828:         }
                   3829: 
                   3830:       } else
                   3831:       {
                   3832:         Vector fieldNamesVec = bean.getColumnNames();
                   3833:         fieldNames = new String[fieldNamesVec.size()];
                   3834:         int fieldIndex = -1;
                   3835:         for (Iterator iter = fieldNamesVec.iterator(); iter.hasNext();)
                   3836:         {
                   3837:           String element = (String) iter.next();
                   3838:           fieldNames[++fieldIndex] = beanDest.getQC() + convertText(element) + beanDest.getQC();
                   3839:           // System.out.println("field " + fieldNames[fieldIndex]);
                   3840:         }
                   3841:       }
                   3842:     }
                   3843:     return new ConversionProperties(destTableName, fieldNames);
                   3844:   }
                   3845: 
                   3846:   /**
                   3847:    * creates an insert into statement for the specified table and given field
                   3848:    * names
                   3849:    * 
                   3850:    * @param destTableName
                   3851:    * @param fieldNames
                   3852:    * @return
                   3853:    */
                   3854:   public static StringBuffer createInsertCommand(String destTableName, String[] fieldNames)
                   3855:   {
                   3856:     StringBuffer command = new StringBuffer();
                   3857:     command.append("INSERT  INTO ");
                   3858:     command.append(beanDest.getQC());
                   3859:     command.append(destTableName); // convertText((String)
                   3860:     // names.get(tbIndex)));
                   3861:     command.append(beanDest.getQC());
                   3862:     command.append(" (");
                   3863:     for (int i = 0; i < fieldNames.length; i++)
                   3864:     {
                   3865:       command.append(fieldNames[i]);
                   3866:       if (i < fieldNames.length - 1)
                   3867:         command.append(",");
                   3868:     }
                   3869:     command.append(") ");
                   3870: 
                   3871:     command.append(" values ( ");
                   3872:     // add a question marks for every field
                   3873:     for (int i = 0; i < fieldNames.length - 1; ++i)
                   3874:       command.append("?,");
                   3875:     command.append("?)");
                   3876:     return command;
                   3877:   }
                   3878: 
                   3879:   public static StringBuffer createUpdateCommand(String destTableName, String[] fieldNames,
                   3880:       String id)
                   3881:   {
                   3882:     StringBuffer command = new StringBuffer();
                   3883: 
                   3884:     command.append("UPDATE ");
                   3885:     command.append(beanDest.getQC());
                   3886:     command.append(destTableName);
                   3887:     command.append(beanDest.getQC());
                   3888:     command.append(" SET  ");
                   3889: 
                   3890:     int size = bean.getColumnNames().size();
                   3891:     for (int i = 0; i < size - 1; ++i)
                   3892:       command.append(fieldNames[i] + " = ? ,");
                   3893:     command.append(fieldNames[size - 1] + " = ? ");
                   3894:     command.append("WHERE " + id + " =  ?");
                   3895:     return command;
                   3896:   }
                   3897: 
                   3898:   public static StringBuffer createDeleteCommand(String destTableName, String idField)
                   3899:   {
                   3900:     StringBuffer command = new StringBuffer();
                   3901: 
                   3902:     command.append("DELETE FROM");
                   3903:     command.append(beanDest.getQC());
                   3904:     command.append(destTableName);
                   3905:     // command.append(convertText((String) names.get(tbIndex)));
                   3906:     command.append(beanDest.getQC());
                   3907:     command.append("WHERE " + idField + " =  ?");
                   3908:     return command;
                   3909:   }
                   3910: 
                   3911:   public void makeTest(String table, String idField, String tempQuery) throws Exception
                   3912:   {
                   3913:     int counter = 0;
                   3914: 
                   3915:     // ****** test code *****
                   3916: 
                   3917:     bean.getConnection();
                   3918:     ResultSet resultSet = null;
                   3919:     String lastResult = "P227634.11";// "P227625.79554";//"P227625.77391";//"P116034.970998";
                   3920:     String myQuery = "select " + bean.getQC() + idField + bean.getQC() + ",serial " + " from "
                   3921:         + bean.getQC() + table + bean.getQC();
                   3922:     System.out.println("Query is now " + myQuery);
                   3923:     JDialog statusDialog = new JDialog();
                   3924:     statusDialog.setTitle("Status Information");
                   3925:     JLabel status = new JLabel("actual DataSet : ");
                   3926:     JLabel status2 = new JLabel(Integer.toString(++counter));
                   3927:     JLabel status3 = new JLabel(lastResult);
                   3928: 
                   3929:     JPanel statusPanel = new JPanel();
                   3930:     JPanel statusPanel2 = new JPanel();
                   3931:     statusPanel.add(status);
                   3932:     statusPanel.add(status2);
                   3933:     statusPanel2.add(status3);
                   3934:     statusDialog.getContentPane().add(statusPanel, "North");
                   3935:     statusDialog.getContentPane().add(statusPanel2, "Center");
                   3936:     statusDialog.setLocation(400, 500);
                   3937:     statusDialog.setSize(300, 150);
                   3938:     statusDialog.setVisible(true);
                   3939:     while (true)
                   3940:     {
                   3941:       if (!statusDialog.isVisible())
                   3942:         statusDialog.setVisible(true);
                   3943:       tempQuery = myQuery + " where " + bean.getQC() + idField + bean.getQC() + ">'" + lastResult
                   3944:           + "'";
                   3945:       resultSet = bean.makeQuery(tempQuery, 1);
                   3946:       if (resultSet == null)
                   3947:       {
                   3948:         System.out.println("lastResult was " + lastResult + " counter was " + counter);
                   3949:         break;
                   3950:       } else
                   3951:       {
                   3952:         resultSet.next();
                   3953:         lastResult = resultSet.getString(1);
                   3954:         counter++;
                   3955:         status2.setText(Integer.toString(counter));
                   3956:         status3.setText(lastResult + " " + resultSet.getString(2));
                   3957:         if (counter % 100 == 0)
                   3958:         {
                   3959:           System.out.println("actual Result was " + lastResult + " counter was " + counter);
                   3960:           // break;
                   3961:         }
                   3962:       }
                   3963:       resultSet = null;
                   3964:     }
                   3965:     System.exit(0);
1.1       rogo     3966: 
1.4       rogo     3967:     // ****** end Test ******
1.1       rogo     3968: 
1.4       rogo     3969:   }
1.8       rogo     3970: 
                   3971:   public final static String generateSuffix(final int step)
                   3972:   {
                   3973:     String fileString = null;
                   3974:     if (step < 10)
                   3975:       fileString = "00" + step;
                   3976:     else if (step < 100)
                   3977:       fileString = "0" + step;
                   3978:     else
                   3979:       fileString = step + "";
                   3980:     return fileString;
                   3981:   }
                   3982: 
1.1       rogo     3983: }

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