File:  [Repository] / FM2SQL / Attic / Convert.java
Revision 1.61: download - view: text, annotated - select for diffs - revision graph
Mon Jul 12 10:15:13 2004 UTC (19 years, 11 months ago) by rogo
Branches: MAIN
CVS tags: HEAD
synchronize method

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

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