Annotation of FM2SQL/Convert.java, revision 1.84

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

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