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

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

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