1 package com.knowgate.hipergate.datamodel; 2 3 import java.io.IOException ; 4 import java.io.FileNotFoundException ; 5 import java.io.FileReader ; 6 import java.io.FileWriter ; 7 import java.io.LineNumberReader ; 8 9 import com.knowgate.dfs.FileSystem; 10 11 12 18 public class UNLoCode { 19 public UNLoCode() { 20 } 21 22 public static void generateSQLScript(String sInFile, String sOutFile, String sCountries) 23 throws IOException { 24 StringBuffer oCty = new StringBuffer (65000); 25 String sLine, sCountryCode, sPlaceCode, sPlaceName, sPort, sRail, sRoad, sAirport, sPostal, sStatus, sIata, sLat, sLong; 26 FileWriter oLC = new FileWriter (sOutFile); 27 FileWriter oCC = new FileWriter (sCountries); 28 FileReader oFR = new FileReader (sInFile); 29 LineNumberReader oLR = new LineNumberReader (oFR); 30 while ( null!= (sLine = oLR.readLine()) ) { 31 sCountryCode = sLine.substring(3,5).toLowerCase(); 32 sPlaceCode = sLine.substring(6,9).toLowerCase(); 33 sPlaceName = sLine.substring(10,46).trim().replace((char)39,'´'); 34 if (sPlaceName.charAt(0)!='.') { 35 sPort = (sLine.charAt(86)=='1' ? "1" : "0"); 36 sRail = (sLine.charAt(87)=='2' ? "1" : "0"); 37 sRoad = (sLine.charAt(88)=='3' ? "1" : "0"); 38 sAirport = (sLine.charAt(89)=='4' ? "1" : "0"); 39 sPostal = (sLine.charAt(90)=='5' ? "1" : "0"); 40 sStatus = sLine.substring(95,97).trim(); 41 sIata = sLine.substring(103,106).trim(); 42 if (sIata.length()>0) 43 sIata = "'"+sIata+"'"; 44 else 45 sIata = "null"; 46 sLat = sLine.substring(108,113).trim(); 47 if (sLat.length()>0) 48 sLat = "'"+sLat+"'"; 49 else 50 sLat = "null"; 51 sLong = sLine.substring(114,120).trim(); 52 if (sLong.length()>0) 53 sLong = "'"+sLong+"'"; 54 else 55 sLong = "null"; 56 oLC.write("INSERT INTO k_lu_unlocode (id_country,id_place,nm_place,bo_active,bo_port,bo_rail,bo_road,bo_airport,bo_postal,id_status,id_iata,coord_lat,coord_long) VALUES('"+sCountryCode+"','"+sPlaceCode+"','"+sPlaceName+"',1,"+sPort+","+sRail+","+sRoad+","+sAirport+","+sPostal+",'"+sStatus+"',"+sIata+","+sLat+","+sLong+");\n"); 57 } else { 58 oCC.write(sCountryCode+" "+sPlaceName.substring(1)+"\n"); 59 } 60 } oLR.close(); 62 oFR.close(); 63 oCC.close(); 64 oLC.close(); 65 } 66 } 67 | Popular Tags |