OSDN Git Service

2段階チェック。同一名称のバス停がある場合にはインポート対象から外す。
[convbusstop/convbusstop.git] / src / osm / jp / ConvBusstop.java
index b66c1ce..1ce3b77 100644 (file)
-package osm.jp;
-import osm.jp.api.HttpGET;
-import javax.xml.parsers.*;
-import javax.xml.transform.TransformerException;
-
-import org.w3c.dom.*;
-import org.xml.sax.*;
-
-import java.io.*;
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.Date;
-
-import jp.co.areaweb.tools.database.*;
-
-public class ConvBusstop {
-
-       String filter = "";
-       String urlStr = "";
-
-       public static final boolean DB_INIT = false;
-
-       // 近くのバス停を探す範囲(バス停を中心としたNEER×2m四方の領域
-       static final int NEER = 75;
-       static boolean nocheck = false;
-
-       /**
-        * メイン
-        *
-        * @throws IOException
-        * @throws SQLException
-        * @throws ClassNotFoundException
-        * @throws FileNotFoundException
-        * @throws TransformerException
-        * @throws SAXException
-        * @throws ParserConfigurationException */
-       public static void main(String[] args) throws FileNotFoundException, ClassNotFoundException, SQLException, IOException, ParserConfigurationException, SAXException, TransformerException
-       {
-               int index = 0;
-               boolean updateDb = true;
-               if (args.length > index) {
-                       if (args[index].equals("-exp")) {
-                               updateDb = false;
-                               index++;
-                       }
-                       if (args[index].equals("-nocheck")) {
-                               ConvBusstop.nocheck = true;
-                               index++;
-                       }
-               }
-
-               /**
-                * アプリケーション [ConvBusstop]
-                * > java -jar ConvBusstop.jar <オプション>
-                *      オプション: -exp 実行する直前にデータベースを初期化する(省略可能)
-                */
-               Connection con = DatabaseTool.openDb("database");
-               try {
-                       /**
-                        * バス停データ変換のメイン処理
-                        */
-                       int fcounter = 0;
-                       if (args.length > index) {
-                               File iFile = new File(args[index]);
-                               fcounter++;
-
-                               ConvBusstop.initDb(con);
-                               inputFile(con, iFile);
-                               String iStr = iFile.getName();
-                               outputDb(con, iStr.substring(0, iStr.length() - 4));
-                       }
-                       else {
-                               if (updateDb) {
-                                       File dbdir = new File("database");
-                                       if (dbdir.isDirectory()) {
-                                               dbdir.delete();
-                                       }
-                                       dbdir.mkdir();
-                               }
-
-                               File dir = new File(".");
-                               File[] files = dir.listFiles();
-
-                               for (File iFile : files) {
-                                       ConvBusstop.initDb(con);
-                                       if (checkFile(iFile)) {
-                                               fcounter++;
-                                               inputFile(con, iFile);
-                                       }
-                               }
-                               // ローカルデータベース内の情報を出力する
-                               for (File iFile : files) {
-                                       if (checkFile(iFile)) {
-                                               String iStr = iFile.getName();
-                                               outputDb(con, iStr.substring(0, iStr.length() - 4));
-                                       }
-                               }
-                       }
-                       System.out.println("["+ fcounter +"]つのファイルをインポートしました。");
-               }
-               finally {
-                       DatabaseTool.closeDb(con);
-               }
-       }
-
-       static String[] shiftArgs(String[] args) {
-               String[] values = new String[args.length - 1];
-               for (int i=1; i < args.length; i++) {
-                       values[i - 1] = new String(args[i]);
-               }
-               return values;
-       }
-
-       /**
-        * ソースファイルを読み取ってローカルベータベースへ記録する
-        * @param con
-        * @param iFile
-        * @throws FileNotFoundException
-        * @throws ClassNotFoundException
-        * @throws SQLException
-        * @throws IOException
-        */
-       public static void inputFile (Connection con, File iFile) throws FileNotFoundException, ClassNotFoundException, SQLException, IOException {
-               int iCounter = 0;
-               String timeStampStr = null;
-
-               String iStr = iFile.getName();
-               File dir = new File(iStr.substring(0, iStr.length() - 4));
-               dir.mkdir();
-
-               DocumentBuilderFactory factory;
-               DocumentBuilder        builder;
-               Node root;
-
-               iCounter = 0;
-               try {
-                       factory = DocumentBuilderFactory.newInstance();
-                       builder = factory.newDocumentBuilder();
-                       factory.setIgnoringElementContentWhitespace(true);
-                       factory.setIgnoringComments(true);
-                       factory.setValidating(true);
-                       root    = builder.parse(iStr);
-
-                       iCounter += showNodes(con, root, iStr.substring(0, iStr.length() - 4), timeStampStr);
-               } catch (ParserConfigurationException e0) {
-                       System.out.println(e0.getMessage());
-               } catch (SAXException e1){
-                       System.out.println(e1.getMessage());
-               } catch (IOException e2) {
-                       System.out.println(e2.getMessage());
-               } catch (SQLException e2) {
-                       System.out.println(e2.getMessage());
-               }
-               System.out.println("バス停数["+ iCounter +"]");
-       }
-
-       public static void initDb(Connection con) {
-
-               try {
-                       if (DB_INIT) {
-                               DbBusstop.drop(con);    // 'table.BUS_STOP'を削除する
-                       }
-               }
-               catch (SQLException e) {
-                       System.out.println("table [bus_stop] is not created.");
-               }
-
-               try {
-                       if (DB_INIT) {
-                               String createSt = "DROP TABLE bus_course;";
-                               PreparedStatement ps = con.prepareStatement(createSt);
-                               ps.executeUpdate();
-                               ps.close();
-                       }
-               }
-               catch (SQLException e) {
-                       System.out.println("table [bus_course] is not created.");
-               }
-
-               try {
-                       if (DB_INIT) {
-                               String createSt = "DROP TABLE bus_ref;";
-                               PreparedStatement ps = con.prepareStatement(createSt);
-                               ps.executeUpdate();
-                               ps.close();
-                       }
-               }
-               catch (SQLException e) {
-                       System.out.println("table [bus_ref] is not created.");
-               }
-
-               // 'table.BUS_STOP'を新規に作る
-               try {
-                       DbBusstop.create(con);
-               }
-               catch (SQLException e) {
-                       System.out.println("table [bus_stop] is already created.");
-               }
-
-               try {
-                       String createSt = "CREATE TABLE bus_course (code int, type int, corp VARCHAR(128) NOT NULL, course VARCHAR(512), ifile VARCHAR(128), CONSTRAINT bus_course_pk PRIMARY KEY(code));";
-                       PreparedStatement ps = con.prepareStatement(createSt);
-                       ps.executeUpdate();
-                       ps.close();
-               }
-               catch (SQLException e) {
-                       System.out.println("table [bus_course] is already created.");
-               }
-
-               try {
-                       String createSt = "CREATE TABLE bus_ref (idref VARCHAR(12), code INT);";
-                       PreparedStatement ps = con.prepareStatement(createSt);
-                       ps.executeUpdate();
-                       ps.close();
-               }
-               catch (SQLException e) {
-                       System.out.println("table [bus_ref] is already created.");
-               }
-       }
-
-
-       /**
-        * ローカルデータベース内の情報を出力する
-        * @param con
-        * @param iCode
-        * @throws IOException
-        * @throws SQLException
-        */
-       public static void outputDb(Connection con, String iCode) throws IOException, SQLException {
-               SimpleDateFormat timeStampFmt = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
-               String timeStampStr = timeStampFmt.format(new Date(Calendar.getInstance().getTimeInMillis()));
-               File dir = new File(iCode);
-               dir.mkdir();
-
-               BufferedWriter ow = null;
-               BufferedWriter gw = null;
-
-               File htmlFile = new File(iCode  +".html");
-               BufferedWriter hw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(htmlFile), "UTF-8"));
-               hw.write("<!DOCTYPE html>");
-               hw.newLine();
-               hw.write("<html><head><meta charset=\"utf-8\" /></head>");
-               hw.newLine();
-               hw.write("<body><table border='1'>");
-               hw.newLine();
-               hw.write("<tr>");
-               hw.write("<td>type</td>");
-               hw.write("<td>corp</td>");
-               hw.write("<td>course</td>");
-               hw.write("<td>GPX</td>");
-               hw.write("<td>SAMPLE</td>");
-               hw.write("<td>バス停数</td>");
-               hw.write("<td>未入力</td>");
-               hw.write("<td>既存</td>");
-               hw.write("</tr>");
-               hw.newLine();
-
-               PreparedStatement ps7 = con.prepareStatement("SELECT code,type,corp,course,ifile FROM bus_course WHERE ifile=? ORDER BY corp,course");
-               PreparedStatement ps9 = con.prepareStatement("SELECT idref FROM bus_ref WHERE code=?");
-               PreparedStatement ps8 = con.prepareStatement("SELECT name,lat,lon,fixed FROM bus_stop WHERE idref=?");
-               ps7.setString(1, iCode);
-               ResultSet rset7 = ps7.executeQuery();
-               while (rset7.next()) {
-                       int code = rset7.getInt(1);
-                       int type = rset7.getInt(2);
-                       String corp = rset7.getString(3);
-                       String course = rset7.getString(4);
-
-                       File osmFile = new File(dir, iCode + String.format("_%1$08d", code) +".osm");
-                       File gpxFile = new File(dir, iCode + String.format("_%1$08d", code) +".gpx");
-                       File osmSample = new File(dir, iCode + String.format("_s%1$08d", code) +".osm");
-
-                       System.out.println("course = "+ course);
-                       int stopCount = 0;
-                       int fixedCount = 0;
-                       int unfixedCount = 0;
-
-                       // index file header
-                       hw.write("<tr>");
-                       hw.write("<td>"+ type +"</td>");
-                       hw.write("<td>"+ corp +"</td>");
-                       hw.write("<td><a href='"+ dir.getName() +"/"+ osmFile.getName() +"'>"+ course +"</a></td>");
-                       hw.write("<td><a href='"+ dir.getName() +"/"+ gpxFile.getName() +"'>"+ gpxFile.getName() +"</a></td>");
-                       hw.write("<td><a href='"+ dir.getName() +"/"+ osmSample.getName() +"'>"+ osmSample.getName() +"</a></td>");
-                       hw.newLine();
-
-                       // OSM file header
-                       ow = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(osmFile), "UTF-8"));
-                       ow.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");
-                       ow.newLine();
-                       ow.write("<osm version=\"0.5\" generator=\"ReadKIBAN\">");
-                       ow.newLine();
-
-                       // GPX file header
-                       gw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(gpxFile), "UTF-8"));
-                       gw.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");
-                       gw.newLine();
-                       gw.write("<gpx xmlns=\"http://www.topografix.com/GPX/1/1\" version=\"1.1\" creator=\"osmtracker-android\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd \">");
-                       gw.newLine();
-
-                       double maxLat = 0.0;
-                       double minLat = 180.0;
-                       double maxLon = 0.0;
-                       double minLon = 180.0;
-
-                       ps9.setInt(1, code);
-                       ResultSet rset9 = ps9.executeQuery();
-                       while (rset9.next()) {
-                               String idref = rset9.getString(1);
-
-                               ps8.setString(1, idref);
-                               ResultSet rset8 = ps8.executeQuery();
-                               if (rset8.next()) {
-                                       stopCount++;
-                                       String name = rset8.getString(1);
-                                       Double lat = rset8.getDouble(2);
-                                       Double lon = rset8.getDouble(3);
-                                       int fixed = rset8.getInt(4);
-
-                                       if (lat > maxLat) {
-                                               maxLat = lat;
-                                       }
-                                       if (lon > maxLon) {
-                                               maxLon = lon;
-                                       }
-                                       if (lat < minLat) {
-                                               minLat = lat;
-                                       }
-                                       if (lon < minLon) {
-                                               minLon = lon;
-                                       }
-
-                                       System.out.println("\tway point = "+ idref);
-                                       fixedCount += fixed;
-                                       if (fixed == 0) {
-                                               unfixedCount++;
-
-                                               // OSM node
-                                               int nodeid = Integer.parseInt(idref.substring(1)) * -1;
-                                               String osm_node = nodeBusstop(nodeid, name, lat, lon, timeStampStr);
-                                               ow.write(osm_node);
-                                               ow.newLine();
-
-                                               // TEXT node
-                                               File txtFile = new File(dir, iCode + idref +".txt");
-                                               BufferedWriter gw2 = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(txtFile), "UTF-8"));
-                                               gw2.write(osm_node);
-                                               gw2.newLine();
-                                               gw2.close();
-
-                                               // GPX waypoint
-                                               gw.write("<wpt lat=\""+ lat +"\" lon=\""+ lon +"\">\n");
-                                               gw.write(" <time>"+ timeStampStr +"Z</time>\n");
-                                               gw.write(" <name><![CDATA["+ name +"]]></name>\n");
-                                               gw.write(" <link href=\""+ txtFile.getName() +"\"><text>"+ idref +"</text></link>\n");
-                                               gw.write("</wpt>\n");
-                                               gw.newLine();
-                                       }
-                               }
-                               rset8.close();
-                       }
-                       rset9.close();
-
-                       // INDEX file
-                       hw.write("<td>"+ stopCount +"</td>");
-                       hw.write("<td>"+ unfixedCount +"</td>");
-                       hw.write("<td>"+ fixedCount +"</td>");
-                       hw.write("</tr>");
-                       hw.newLine();
-
-                       // OSM file header
-                       BufferedWriter ow2 = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(osmSample), "UTF-8"));
-                       ow2.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");
-                       ow2.newLine();
-                       ow2.write("<osm version=\"0.5\" generator=\"ReadKIBAN\">");
-                       ow2.newLine();
-
-                       ow2.write(nodeBusstop(code, "SAMPLE", ((maxLat+minLat)/2), ((maxLon+minLon)/2), timeStampStr));
-                       ow2.newLine();
-                       ow2.write("</osm>");
-                       ow2.newLine();
-                       ow2.close();
-
-                       // OSM file footer
-                       ow.write("</osm>");
-                       ow.newLine();
-                       ow.close();
-
-                       // GPX file footer
-                       gw.write("</gpx>");
-                       gw.newLine();
-                       gw.close();
-               }
-               rset7.close();
-
-               // index file footer
-               hw.write("</table></body></html>");
-               hw.newLine();
-               hw.close();
-       }
-
-       public static String nodeBusstop(int code, String name, Double lat, Double lon, String timeStampStr) {
-               String osm_node = ("<node id=\""+ code +"\" timestamp=\""+ timeStampStr +"Z\" lat=\""+ lat +"\" lon=\""+ lon +"\">\n");
-               osm_node += "<tag k=\"name\" v=\""+ name +"\"/>\n";
-               osm_node += "<tag k=\"highway\" v=\"bus_stop\"/>\n";
-               osm_node += "<tag k=\"bus\" v=\"yes\"/>\n";
-               osm_node += "<tag k=\"fixme\" v=\"このバス停を正しい位置に移動させて\"/>\n";
-               osm_node += ("<tag k=\"source\" v=\"KSJ2\"/>\n");
-               osm_node += ("<tag k=\"source_ref\" v=\"http://nlftp.mlit.go.jp/ksj/gml/datalist/KsjTmplt-P11.html\"/>\n");
-               osm_node += ("<tag k=\"created_by\" v=\"National-Land-Numerical-Information_MLIT_Japan\"/>\n");
-               osm_node += ("<tag k=\"note\" v=\"National-Land Numerical Information (Bus stop) 2012, MLIT Japan\"/>\n");
-               osm_node += ("<tag k=\"note:ja\" v=\"国土数値情報(バス停留所)平成24年 国土交通省\"/>\n");
-               osm_node += ("<tag k=\"public_transport\" v=\"stop_position\"/>\n");
-               osm_node += ("</node>\n");
-               return osm_node;
-       }
-
-       /**
-        *
-        * @param con
-        * @param node
-        * @param iFileName             // ソースファイル名(拡張子を含まない)
-        * @param timeStampStr
-        * @return
-        * @throws IOException
-        * @throws SQLException
-        */
-       public static int showNodes(Connection con, Node node, String iFileName, String timeStampStr) throws IOException, SQLException {
-               int iCounter = 0;
-               NamedNodeMap nodeMap = node.getAttributes();
-               if ( null != nodeMap ) {
-                       for ( int j=0; j < nodeMap.getLength(); j++ ) {
-                               if (nodeMap.item(j).getNodeName().equals("timeStamp")) {
-                                       timeStampStr = nodeMap.item(j).getNodeValue();
-                               }
-                       }
-               }
-
-               NodeList nodes = node.getChildNodes();
-               for (int i=0; i<nodes.getLength(); i++) {
-                       Node node2 = nodes.item(i);
-                       if (node2.getNodeName().equals("jps:GM_Point")) {
-                               showGmPoint(con, node2);
-                       }
-                       else if (node2.getNodeName().equals("gml:Point")) {
-                               showGmlPoint(con, node2);
-                       }
-
-                       else if (node2.getNodeName().equals("ksj:ED01")) {
-                               iCounter++;
-                               showED01(con, node2, iFileName);
-                       }
-                       else if (node2.getNodeName().equals("ksj:BusStop")) {
-                               iCounter++;
-                               showBusStop(con, node2, iFileName);
-                       }
-
-                       else {
-                               iCounter += showNodes(con, node2, iFileName, timeStampStr);
-                       }
-               }
-               return iCounter;
-       }
-
-       /**
-        *
-        * @param con
-        * @param node
-        * @param iFileName             // ソースファイル名(拡張子を含まない)
-        * @throws IOException
-        * @throws SQLException
-        */
-       public static void showED01(Connection con, Node node, String iFileName) throws IOException, SQLException {
-               String idrefStr = "";
-               String nameStr = "";
-               PreparedStatement ps1 = con.prepareStatement("SELECT idref FROM bus_stop WHERE idref=?");
-               PreparedStatement ps2 = con.prepareStatement("INSERT INTO bus_stop (idref,name,ifile) VALUES (?,?,?)");
-               PreparedStatement ps3 = con.prepareStatement("SELECT code FROM bus_course WHERE course=? AND corp=? AND ifile=?");
-               PreparedStatement ps4 = con.prepareStatement("INSERT INTO bus_course (code,type,corp,course,ifile) VALUES (?,?,?,?,?)");
-               PreparedStatement ps5 = con.prepareStatement("INSERT INTO bus_ref (idref,code) VALUES (?,?)");
-               PreparedStatement ps6 = con.prepareStatement("SELECT max(code) FROM bus_course WHERE ifile=?");
-
-               ArrayList<String[]> bris = new ArrayList<String[]>();
-               NodeList nodes = node.getChildNodes();
-               for (int i=0; i < nodes.getLength(); i++) {
-                       Node node2 = nodes.item(i);
-                       if (node2.getNodeName().equals("ksj:POS")) {
-                               NamedNodeMap nodeMap = node2.getAttributes();
-                               if (null != nodeMap) {
-                                       for ( int j=0; j < nodeMap.getLength(); j++ ) {
-                                               if (nodeMap.item(j).getNodeName().equals("idref")) {
-                                                       idrefStr = nodeMap.item(j).getNodeValue();
-                                                       System.out.println("found idref='"+ idrefStr +"'");
-                                                       break;
-                                               }
-                                       }
-                               }
-                       }
-                       else if (node2.getNodeName().equals("ksj:BSN")) {
-                               nameStr = node2.getTextContent();
-                       }
-                       else if (node2.getNodeName().equals("ksj:BRI")) {
-                               String[] rtn = anaComm(node2);
-                               if (rtn != null) {
-                                       bris.add(rtn);
-                               }
-                       }
-               }
-
-               // idref と nameStr をデータベースに格納する
-               boolean insert = false;
-               ps1.setString(1, idrefStr);
-               ResultSet rset = ps1.executeQuery();
-               if (!rset.next()) {
-                       insert = true;
-               }
-               rset.close();
-
-               if (insert) {
-                       ps2.setString(1, idrefStr);
-                       ps2.setString(2, nameStr);
-                       ps2.setString(3, iFileName);
-                       ps2.executeUpdate();
-               }
-
-               for (String[] rtn : bris) {
-                       int code = 0;
-                       ps3.setString(1, rtn[1]);
-                       ps3.setString(2, rtn[2]);
-                       ps3.setString(3, iFileName);
-                       rset = ps3.executeQuery();
-                       if (rset.next()) {
-                               code = rset.getInt(1);
-                       }
-                       rset.close();
-
-                       if (code == 0) {
-                               ps6.setString(1, iFileName);
-                               ResultSet rset6 = ps6.executeQuery();
-                               if (rset6.next()) {
-                                       code = rset6.getInt(1);
-                               }
-                               rset6.close();
-                               code++;
-
-                               System.out.println("code="+code);
-                               ps4.setInt(1, code);
-                               ps4.setInt(2, Integer.parseInt(rtn[0]));
-                               ps4.setString(3, rtn[2]);
-                               ps4.setString(4, rtn[1]);
-                               ps4.setString(5, iFileName);
-                               ps4.executeUpdate();
-                       }
-
-                       ps5.setString(1, idrefStr);
-                       ps5.setInt(2, code);
-                       ps5.executeUpdate();
-               }
-
-               ps1.close();
-               ps2.close();
-               ps3.close();
-               ps4.close();
-               ps5.close();
-       }
-
-       /**
-        * <ksj:BusStop gml:id="ED01_1">
-        *      <ksj:position xlink:href="#n1"/>
-        *      <ksj:busStopName>城堀</ksj:busStopName>
-        *      <ksj:busRouteInformation>
-        *              <ksj:BusRouteInformation>
-        *                      <ksj:busType>1</ksj:busType>
-        *                      <ksj:busOperationCompany>箱根登山バス</ksj:busOperationCompany>
-        *                      <ksj:busLineName>小01</ksj:busLineName>
-        *              </ksj:BusRouteInformation>
-        *      </ksj:busRouteInformation>
-        *      <ksj:busRouteInformation>
-        *              <ksj:BusRouteInformation>
-        *                      <ksj:busType>1</ksj:busType>
-        *                      <ksj:busOperationCompany>箱根登山バス</ksj:busOperationCompany>
-        *                      <ksj:busLineName>湯07</ksj:busLineName>
-        *              </ksj:BusRouteInformation>
-        *      </ksj:busRouteInformation>
-        *      <ksj:busRouteInformation>
-        *              <ksj:BusRouteInformation>
-        *                      <ksj:busType>1</ksj:busType>
-        *                      <ksj:busOperationCompany>箱根登山バス</ksj:busOperationCompany>
-        *                      <ksj:busLineName>湯11</ksj:busLineName>
-        *              </ksj:BusRouteInformation>
-        *      </ksj:busRouteInformation>
-        * </ksj:BusStop>
-        *
-        * @param con
-        * @param node
-        * @param iFileName             // ソースファイル名(拡張子を含まない)
-        * @throws IOException
-        * @throws SQLException
-        */
-       public static void showBusStop(Connection con, Node node, String iFileName) throws IOException, SQLException {
-               String idrefStr = "";
-               String nameStr = "";
-               PreparedStatement ps1 = con.prepareStatement("SELECT idref FROM bus_stop WHERE idref=?");
-               PreparedStatement ps2 = con.prepareStatement("INSERT INTO bus_stop (idref,name,ifile) VALUES (?,?,?)");
-               PreparedStatement ps3 = con.prepareStatement("SELECT code FROM bus_course WHERE course=? AND corp=? AND ifile=?");
-               PreparedStatement ps4 = con.prepareStatement("INSERT INTO bus_course (code,type,corp,course,ifile) VALUES (?,?,?,?,?)");
-               PreparedStatement ps5 = con.prepareStatement("INSERT INTO bus_ref (idref,code) VALUES (?,?)");
-               PreparedStatement ps6 = con.prepareStatement("SELECT max(code) FROM bus_course WHERE ifile=?");
-
-               ArrayList<String[]> bris = new ArrayList<String[]>();
-               NodeList nodes = node.getChildNodes();
-               for (int i=0; i < nodes.getLength(); i++) {
-                       Node node2 = nodes.item(i);
-                       if (node2.getNodeName().equals("ksj:position")) {
-                               NamedNodeMap nodeMap = node2.getAttributes();
-                               if (null != nodeMap) {
-                                       for ( int j=0; j < nodeMap.getLength(); j++ ) {
-                                               if (nodeMap.item(j).getNodeName().equals("xlink:href")) {
-                                                       idrefStr = nodeMap.item(j).getNodeValue();
-                                                       idrefStr = idrefStr.substring(1);
-                                                       System.out.println("found idref='"+ idrefStr +"'");
-                                                       break;
-                                               }
-                                       }
-                               }
-                       }
-                       else if (node2.getNodeName().equals("ksj:busStopName")) {
-                               nameStr = node2.getTextContent();
-                       }
-                       else if (node2.getNodeName().equals("ksj:busRouteInformation")) {
-                               String[] rtn = anaCommJGD(node2);
-                               if (rtn != null) {
-                                       bris.add(rtn);
-                               }
-                       }
-               }
-
-               // idref と nameStr をデータベースに格納する
-               boolean insert = false;
-               ps1.setString(1, idrefStr);
-               ResultSet rset = ps1.executeQuery();
-               if (!rset.next()) {
-                       insert = true;
-               }
-               rset.close();
-
-               if (insert) {
-                       ps2.setString(1, idrefStr);
-                       ps2.setString(2, nameStr);
-                       ps2.setString(3, iFileName);
-                       ps2.executeUpdate();
-               }
-
-               for (String[] rtn : bris) {
-                       int code = 0;
-                       ps3.setString(1, rtn[1]);
-                       ps3.setString(2, rtn[2]);
-                       ps3.setString(3, iFileName);
-                       rset = ps3.executeQuery();
-                       if (rset.next()) {
-                               code = rset.getInt(1);
-                       }
-                       rset.close();
-
-                       if (code == 0) {
-                               ps6.setString(1, iFileName);
-                               ResultSet rset6 = ps6.executeQuery();
-                               if (rset6.next()) {
-                                       code = rset6.getInt(1);
-                               }
-                               rset6.close();
-                               code++;
-
-                               System.out.println("course="+ code +" : "+ rtn[0] +" : "+ rtn[1] +" : "+ rtn[2] );
-                               ps4.setInt(1, code);
-                               ps4.setInt(2, Integer.parseInt(rtn[0]));
-                               ps4.setString(3, rtn[2]);
-                               ps4.setString(4, rtn[1]);
-                               ps4.setString(5, iFileName);
-                               ps4.executeUpdate();
-                       }
-
-                       ps5.setString(1, idrefStr);
-                       ps5.setInt(2, code);
-                       ps5.executeUpdate();
-               }
-
-               ps1.close();
-               ps2.close();
-               ps3.close();
-               ps4.close();
-               ps5.close();
-       }
-
-       public static String[] anaComm(Node briNode) {
-               String[] rtn = new String[3];
-               rtn[0] = "";    // corp type
-               rtn[1] = "";    // course name
-               rtn[2] = "";    // corp name
-
-               NodeList nodes = briNode.getChildNodes();
-               for (int i=0; i < nodes.getLength(); i++) {
-                       Node node2 = nodes.item(i);
-                       if (node2.getNodeName().equals("ksj:BSC")) {
-                               rtn[0] = node2.getTextContent();
-                       }
-                       else if (node2.getNodeName().equals("ksj:BLN")) {
-                               rtn[1] = node2.getTextContent();
-                       }
-                       else if (node2.getNodeName().equals("ksj:BOC")) {
-                               rtn[2] = node2.getTextContent();
-                       }
-               }
-               return rtn;
-       }
-
-       /**
-        *
-        *      <ksj:busRouteInformation>
-        *              <ksj:BusRouteInformation>
-        *                      <ksj:busType>1</ksj:busType>
-        *                      <ksj:busOperationCompany>箱根登山バス</ksj:busOperationCompany>
-        *                      <ksj:busLineName>小01</ksj:busLineName>
-        *              </ksj:BusRouteInformation>
-        *      </ksj:busRouteInformation>
-        *
-        * @param briNode
-        * @return
-        */
-       public static String[] anaCommJGD(Node briNode) {
-               String[] rtn = new String[3];
-               int vcnt = 0;
-
-               NodeList nodes2 = briNode.getChildNodes();
-               for (int i=0; i < nodes2.getLength(); i++) {
-                       Node node2 = nodes2.item(i);
-                       if (node2.getNodeName().equals("ksj:BusRouteInformation")) {
-                               NodeList nodes3 = node2.getChildNodes();
-                               for (int j=0; j < nodes3.getLength(); j++) {
-                                       Node node3 = nodes3.item(j);
-                                       if (node3.getNodeName().equals("ksj:busType")) {
-                                               rtn[0] = new String(node3.getTextContent());
-                                               vcnt++;
-                                       }
-                                       else if (node3.getNodeName().equals("ksj:busLineName")) {
-                                               rtn[1] = new String(node3.getTextContent());
-                                               vcnt++;
-                                       }
-                                       else if (node3.getNodeName().equals("ksj:busOperationCompany")) {
-                                               rtn[2] = new String(node3.getTextContent());
-                                               vcnt++;
-                                       }
-                               }
-                       }
-               }
-
-               if (vcnt > 0) {
-                       return rtn;
-               }
-               return null;
-       }
-
-       public static void showGmPoint(Connection con, Node node) throws IOException, SQLException {
-               String positionStr = "";
-               String latStr = "";
-               String lonStr = "";
-               String idStr = "";
-
-               NamedNodeMap nodeMap = node.getAttributes();
-               if ( null != nodeMap ) {
-                       for ( int j=0; j<nodeMap.getLength(); j++ ) {
-                               if (nodeMap.item(j).getNodeName().equals("id")) {
-                                       idStr = nodeMap.item(j).getNodeValue();
-                               }
-                       }
-               }
-
-               NodeList nodes = node.getChildNodes();
-               for (int i=0; i < nodes.getLength(); i++) {
-                       Node node2 = nodes.item(i);
-                       if (node2.getNodeName().equals("jps:GM_Point.position")) {
-                               NodeList nodes3 = node2.getChildNodes();
-                               for (int j=0; j < nodes3.getLength(); j++) {
-                                       Node node3 = nodes3.item(j);
-                                       if (node3.getNodeName().equals("jps:DirectPosition")) {
-                                               NodeList nodes4 = node3.getChildNodes();
-                                               for (int k=0; k < nodes4.getLength(); k++) {
-                                                       Node node4 = nodes4.item(k);
-                                                       if (node4.getNodeName().equals("DirectPosition.coordinate")) {
-                                                               positionStr = node4.getTextContent();
-                                                               String[] str4Ary = positionStr.split(" ");
-                                                               latStr = str4Ary[0];
-                                                               lonStr = str4Ary[1];
-                                                               break;
-                                                       }
-                                               }
-                                               break;
-                                       }
-                               }
-
-                               PreparedStatement ps6 = con.prepareStatement("UPDATE bus_stop SET lat=?,lon=?,fixed=? WHERE idref=?");
-                               double lat = Double.parseDouble(latStr);
-                               double lon = Double.parseDouble(lonStr);
-                               ps6.setDouble(1, lat);
-                               ps6.setDouble(2, lon);
-                               ps6.setInt(3, (ConvBusstop.nocheck ? 0 : HttpGET.getMap(lat, lon, NEER)));
-                               ps6.setString(4, idStr);
-                               ps6.executeUpdate();
-                       }
-               }
-       }
-
-       /**
-        * <gml:Point gml:id="n1">
-        *      <gml:pos>35.14591397 139.10569573</gml:pos>
-        * </gml:Point>
-        *
-        * @param con
-        * @param node
-        * @throws IOException
-        * @throws SQLException
-        */
-       public static void showGmlPoint(Connection con, Node node) throws IOException, SQLException {
-               String positionStr = "";
-               String latStr = "";
-               String lonStr = "";
-               String idStr = "";
-
-               NamedNodeMap nodeMap = node.getAttributes();
-               if ( null != nodeMap ) {
-                       for ( int j=0; j<nodeMap.getLength(); j++ ) {
-                               if (nodeMap.item(j).getNodeName().equals("gml:id")) {
-                                       idStr = nodeMap.item(j).getNodeValue();
-                               }
-                       }
-               }
-
-               NodeList nodes = node.getChildNodes();
-               for (int i=0; i < nodes.getLength(); i++) {
-                       Node node2 = nodes.item(i);
-                       if (node2.getNodeName().equals("gml:pos")) {
-                               positionStr = node2.getTextContent().trim();
-                               String[] str4Ary = positionStr.split(" ");
-                               latStr = str4Ary[0];
-                               lonStr = str4Ary[1];
-
-                               PreparedStatement ps6 = con.prepareStatement("UPDATE bus_stop SET lat=?,lon=?,fixed=? WHERE idref=?");
-                               double lat = Double.parseDouble(latStr);
-                               double lon = Double.parseDouble(lonStr);
-                               ps6.setDouble(1, lat);
-                               ps6.setDouble(2, lon);
-                               ps6.setInt(3, (ConvBusstop.nocheck ? 0 : HttpGET.getMap(lat, lon, NEER)));
-                               ps6.setString(4, idStr);
-                               ps6.executeUpdate();
-                       }
-               }
-       }
-
-       static boolean checkFile(File f) {
-               String name = f.getName();
-               if (!name.startsWith("P11-")) {
-                       return false;
-               }
-               if (!name.toUpperCase().endsWith(".XML")) {
-                       return false;
-               }
-               return true;
-       }
-
-
+package osm.jp;\r
+import osm.jp.api.HttpPOST;\r
+\r
+import javax.xml.parsers.*;\r
+import javax.xml.transform.TransformerException;\r
+\r
+import org.w3c.dom.*;\r
+import org.xml.sax.*;\r
+\r
+import java.io.*;\r
+import java.sql.Connection;\r
+import java.sql.PreparedStatement;\r
+import java.sql.ResultSet;\r
+import java.sql.SQLException;\r
+import java.sql.Statement;\r
+import java.text.SimpleDateFormat;\r
+import java.util.ArrayList;\r
+import java.util.Calendar;\r
+import java.util.Date;\r
+\r
+import jp.co.areaweb.tools.database.*;\r
+\r
+public class ConvBusstop {\r
+\r
+       String filter = "";\r
+       String urlStr = "";\r
+\r
+       public static final boolean DB_INIT = false;\r
+\r
+       // 近くのバス停を探す範囲(バス停を中心としたNEER×2m四方の領域\r
+       static final int NEER = 150;\r
+       static boolean nocheck = false;\r
+\r
+       /**\r
+        * メイン\r
+        *\r
+        *      java -cp .:ConvBusstop.jar:hayashi_0225.jar:hsqldb_2.2.9.jar osm.jp.ConvBusstop <option>\r
+        *              OPTION: -nocheck        OSMデータ上に既存のバス停が存在するかどうかをチェックしない\r
+        *              OPTION: -check  OSMデータ上に既存のバス停が存在するかどうかをチェックする\r
+        *\r
+        * @throws IOException\r
+        * @throws SQLException\r
+        * @throws ClassNotFoundException\r
+        * @throws FileNotFoundException\r
+        * @throws TransformerException\r
+        * @throws SAXException\r
+        * @throws ParserConfigurationException */\r
+       public static void main(String[] args) throws FileNotFoundException, ClassNotFoundException, SQLException, IOException, ParserConfigurationException, SAXException, TransformerException\r
+       {\r
+               int index = 0;\r
+               if (args.length > index) {\r
+                       if (args[index].equals("-check")) {\r
+                               ConvBusstop.nocheck = false;\r
+                               index++;\r
+                       }\r
+                       else if (args[index].equals("-nocheck")) {\r
+                               ConvBusstop.nocheck = true;\r
+                               index++;\r
+                       }\r
+               }\r
+\r
+               /**\r
+                * アプリケーション [ConvBusstop]\r
+                * > java -jar ConvBusstop.jar <オプション>\r
+                *      オプション: -exp 実行する直前にデータベースを初期化する(省略可能)\r
+                */\r
+               File dbdir = new File("database");\r
+               if (!dbdir.isDirectory()) {\r
+                       dbdir.mkdir();\r
+               }\r
+\r
+               Connection con = DatabaseTool.openDb("database");\r
+               ConvBusstop.initDb(con);\r
+\r
+               try {\r
+                       /**\r
+                        * バス停データ変換のメイン処理\r
+                        */\r
+                       int fcounter = 0;\r
+                       if (args.length > index) {\r
+                               File iFile = new File(args[index]);\r
+                               fcounter++;\r
+                               inputFile(con, iFile);\r
+                       }\r
+                       else {\r
+                               File dir = new File(".");\r
+                               File[] files = dir.listFiles();\r
+                               for (File iFile : files) {\r
+                                       if (checkFile(iFile)) {\r
+                                               fcounter++;\r
+                                               ConvBusstop.clearDb(con);\r
+                                               inputFile(con, iFile);\r
+                                       }\r
+                               }\r
+                       }\r
+                       System.out.println("["+ fcounter +"]つのファイルをインポートしました。");\r
+                       \r
+                       /**\r
+                        * 既存のOSMバス停を読み込む\r
+                        *              --> 'existing.xml'\r
+                        */\r
+                       if (!ConvBusstop.nocheck && (fcounter > 0)) {\r
+                               /*\r
+                                * 既存のOSMデータファイルがなければ、新たにダウンロードする。\r
+                                * OSMデータファイルがあるときは、ダウンロードしないでそれを使う。\r
+                                */\r
+                               File existingFile = new File("existing.xml");\r
+                               if (!existingFile.isFile()) {\r
+                                       /**\r
+                                        * インポートしたデータの緯度経度範囲を読み取る\r
+                                        */\r
+                                       double maxLat = -90.0D;\r
+                                       double minLat = 90.0D;\r
+                                       double maxLon = -180.0D;\r
+                                       double minLon = 180.0D;\r
+                                       PreparedStatement ps8 = con.prepareStatement("SELECT lat,lon FROM bus_stop");\r
+                                       ResultSet rset8 = ps8.executeQuery();\r
+                                       while (rset8.next()) {\r
+                                               Double lat = rset8.getDouble("lat");\r
+                                               Double lon = rset8.getDouble("lon");\r
+\r
+                                               if (lat > maxLat) {\r
+                                                       maxLat = lat;\r
+                                               }\r
+                                               if (lon > maxLon) {\r
+                                                       maxLon = lon;\r
+                                               }\r
+                                               if (lat < minLat) {\r
+                                                       minLat = lat;\r
+                                               }\r
+                                               if (lon < minLon) {\r
+                                                       minLon = lon;\r
+                                               }\r
+                                       }\r
+                                       rset8.close();\r
+                                       \r
+                                       /**\r
+                                        * OSM OverPassAPI を使って、既存のOSMバス停のデータを取得して、「existing.xml」に出力する\r
+                                        */\r
+                                       HttpPOST.getCapabilities(minLat, maxLat, minLon, maxLon);\r
+                               }\r
+                               readExistingFile(con, existingFile);\r
+                               \r
+                               PreparedStatement ps1 = con.prepareStatement("SELECT idref,name,lat,lon FROM bus_stop");\r
+                               PreparedStatement ps2 = con.prepareStatement("SELECT count(idref) FROM existing_data where (lat > ?) and (lat < ?) and (lon > ?) and (lon < ?)");\r
+                               PreparedStatement ps3 = con.prepareStatement("UPDATE bus_stop SET fixed=? WHERE idref=?");\r
+                               PreparedStatement ps4 = con.prepareStatement("SELECT count(idref) FROM existing_data where (lat > ?) and (lat < ?) and (lon > ?) and (lon < ?) and (name = ?)");\r
+                               ResultSet rset1 = ps1.executeQuery();\r
+                               while (rset1.next()) {\r
+                                       String idref = rset1.getString("idref");\r
+                                       String name = rset1.getString("name");\r
+                                       Double lat = rset1.getDouble("lat");\r
+                                       Double lon = rset1.getDouble("lon");\r
+                                       \r
+                                       // 指定の緯度経度を中心とする半径150x2m四方の矩形領域\r
+                                       System.out.print(idref + "("+ name + ") ....");\r
+                                       RectArea rect = new RectArea(lat, lon, NEER);           // 300m 四方\r
+                                       ps2.setDouble(1, rect.minlat);\r
+                                       ps2.setDouble(2, rect.maxlat);\r
+                                       ps2.setDouble(3, rect.minlon);\r
+                                       ps2.setDouble(4, rect.maxlon);\r
+                                       ResultSet rset2 = ps2.executeQuery();\r
+                                       if (rset2.next()) {\r
+                                               int count = rset2.getInt(1);\r
+                                               if (count > 0) {\r
+                                                       System.out.println("."+ count);\r
+                                                       ps3.setInt(1, count);\r
+                                                       ps3.setString(2, idref);\r
+                                                       ps3.executeUpdate();\r
+                                               }\r
+                                               else {\r
+                                                       // 指定の緯度経度を中心とする半径150x4m四方の矩形領域\r
+                                                       System.out.print("***");\r
+                                                       rect = new RectArea(lat, lon, NEER*2);          // 600m 四方\r
+                                                       ps4.setDouble(1, rect.minlat);\r
+                                                       ps4.setDouble(2, rect.maxlat);\r
+                                                       ps4.setDouble(3, rect.minlon);\r
+                                                       ps4.setDouble(4, rect.maxlon);\r
+                                                       ps4.setString(5, name);\r
+                                                       ResultSet rset4 = ps4.executeQuery();\r
+                                                       if (rset4.next()) {\r
+                                                               count = rset4.getInt(1);\r
+                                                               System.out.println(".."+ count);\r
+                                                               ps3.setInt(1, count);\r
+                                                               ps3.setString(2, idref);\r
+                                                               ps3.executeUpdate();\r
+                                                       }\r
+                                                       rset4.close();\r
+                                               }\r
+                                       }\r
+                                       rset2.close();\r
+                               }\r
+                               rset1.close();\r
+                               ps3.close();\r
+                               ps2.close();\r
+                               ps1.close();\r
+                       }\r
+                       \r
+                       // ローカルデータベース内の情報を出力する\r
+                       if (args.length > index) {\r
+                               File iFile = new File(args[index]);\r
+                               String iStr = iFile.getName();\r
+                               outputDb(con, iStr.substring(0, iStr.length() - 4));\r
+                       }\r
+                       else {\r
+                               File dir = new File(".");\r
+                               File[] files = dir.listFiles();\r
+                               for (File iFile : files) {\r
+                                       if (checkFile(iFile)) {\r
+                                               String iStr = iFile.getName();\r
+                                               outputDb(con, iStr.substring(0, iStr.length() - 4));\r
+                                       }\r
+                               }\r
+                       }\r
+                       \r
+                       // ローカルデータベース内の情報を「busstop.xml」に出力する\r
+                       int counter = outputDb(con);\r
+\r
+                       System.out.println("["+ counter +"] 変換完了しました。");\r
+               }\r
+               finally {\r
+                       DatabaseTool.closeDb(con);\r
+               }\r
+       }\r
+\r
+       static String[] shiftArgs(String[] args) {\r
+               String[] values = new String[args.length - 1];\r
+               for (int i=1; i < args.length; i++) {\r
+                       values[i - 1] = new String(args[i]);\r
+               }\r
+               return values;\r
+       }\r
+\r
+       public static void readExistingFile (Connection con, File existingFile) throws FileNotFoundException, ClassNotFoundException, SQLException, IOException, ParserConfigurationException, SAXException {\r
+               int iCounter = 0;\r
+\r
+               DocumentBuilderFactory factory;\r
+               DocumentBuilder        builder;\r
+               Node root;\r
+\r
+               iCounter = 0;\r
+               factory = DocumentBuilderFactory.newInstance();\r
+               builder = factory.newDocumentBuilder();\r
+               factory.setIgnoringElementContentWhitespace(true);\r
+               factory.setIgnoringComments(true);\r
+               factory.setValidating(true);\r
+               root    = builder.parse(existingFile);\r
+\r
+               iCounter += readExistingNodes(con, root);\r
+               System.out.println("既存バス停数["+ iCounter +"]");\r
+       }\r
+       \r
+       static int readExistingNodes(Connection con, Node node) throws IOException, SQLException {\r
+               int iCounter = 0;\r
+               \r
+               NodeList nodes = node.getChildNodes();\r
+               for (int i = 0; i < nodes.getLength(); i++) {\r
+                       Node node2 = nodes.item(i);\r
+                       if (node2.getNodeName().equals("node")) {\r
+                               iCounter++;\r
+                               importExistingNode(con, node2);\r
+                       }\r
+                       else {\r
+                               iCounter += readExistingNodes(con, node2);\r
+                       }\r
+               }\r
+               return iCounter;\r
+       }\r
+\r
+       static void importExistingNode(Connection con, Node node) throws IOException, SQLException {\r
+               String idrefStr = "";\r
+               String latStr = "";\r
+               String lonStr = "";\r
+               String nameStr = "";\r
+               PreparedStatement ps5 = con.prepareStatement("INSERT INTO existing_data (idref,lat,lon, name) VALUES (?,?,?,?)");\r
+\r
+               NamedNodeMap nodeMap = node.getAttributes();\r
+               if (null != nodeMap) {\r
+                       for (int j=0; j < nodeMap.getLength(); j++) {\r
+                               if (nodeMap.item(j).getNodeName().equals("id")) {\r
+                                       idrefStr = nodeMap.item(j).getNodeValue();\r
+                               }\r
+                               else if (nodeMap.item(j).getNodeName().equals("lat")) {\r
+                                       latStr = nodeMap.item(j).getNodeValue();\r
+                               }\r
+                               else if (nodeMap.item(j).getNodeName().equals("lon")) {\r
+                                       lonStr = nodeMap.item(j).getNodeValue();\r
+                               }\r
+                       }\r
+                       \r
+                       NodeList nodes = node.getChildNodes();\r
+                       for (int i = 0; i < nodes.getLength(); i++) {\r
+                               Node node2 = nodes.item(i);\r
+                               if (node2.getNodeName().equals("tag")) {\r
+                                       NamedNodeMap nodeMap2 = node2.getAttributes();\r
+                                       if (null != nodeMap2) {\r
+                                               String key = null;\r
+                                               String value = null;\r
+                                               for (int j=0; j < nodeMap2.getLength(); j++) {\r
+                                                       if (nodeMap2.item(j).getNodeName().equals("k")) {\r
+                                                               key = nodeMap2.item(j).getNodeValue();\r
+                                                       }\r
+                                                       else if (nodeMap2.item(j).getNodeName().equals("v")) {\r
+                                                               value = nodeMap2.item(j).getNodeValue();\r
+                                                       }\r
+                                               }\r
+                                               \r
+                                               if ((key != null) && key.toLowerCase().equals("name") && (value != null)) {\r
+                                                       nameStr = value;\r
+                                                       break;\r
+                                               }\r
+                                       }\r
+                               }\r
+                       }\r
+\r
+                       // idref と nameStr をデータベースに格納する\r
+                       System.out.println("import existing_data : "+ idrefStr +" ("+ latStr +","+ lonStr+")"+ nameStr);\r
+                       ps5.setString(1, idrefStr);\r
+                       ps5.setDouble(2, Double.parseDouble(latStr));\r
+                       ps5.setDouble(3, Double.parseDouble(lonStr));\r
+                       ps5.setString(4, nameStr);\r
+                       ps5.executeUpdate();\r
+                       ps5.close();\r
+               }\r
+       }\r
+       \r
+       /**\r
+        * ソースファイルを読み取ってローカルベータベースへ記録する\r
+        * @param con\r
+        * @param iFile\r
+        * @throws FileNotFoundException\r
+        * @throws ClassNotFoundException\r
+        * @throws SQLException\r
+        * @throws IOException\r
+        * @throws ParserConfigurationException \r
+        * @throws SAXException \r
+        */\r
+       public static void inputFile (Connection con, File iFile) throws FileNotFoundException, ClassNotFoundException, SQLException, IOException, ParserConfigurationException, SAXException {\r
+               int iCounter = 0;\r
+               String timeStampStr = null;\r
+\r
+               String iStr = iFile.getName();\r
+               File dir = new File(iStr.substring(0, iStr.length() - 4));\r
+               dir.mkdir();\r
+\r
+               DocumentBuilderFactory factory;\r
+               DocumentBuilder        builder;\r
+               Node root;\r
+\r
+               iCounter = 0;\r
+               factory = DocumentBuilderFactory.newInstance();\r
+               builder = factory.newDocumentBuilder();\r
+               factory.setIgnoringElementContentWhitespace(true);\r
+               factory.setIgnoringComments(true);\r
+               factory.setValidating(true);\r
+               root    = builder.parse(iStr);\r
+\r
+               iCounter += showNodes(con, root, iStr.substring(0, iStr.length() - 4), timeStampStr);\r
+               System.out.println("バス停数["+ iCounter +"]");\r
+       }\r
+\r
+       public static void clearDb(Connection con) throws SQLException {\r
+               Statement stmt = con.createStatement();\r
+               long count = stmt.executeUpdate("delete from bus_stop");\r
+               System.out.println("'Database.bus_stop'から "+ count +" 件のデータを削除しました。");\r
+           \r
+           count = stmt.executeUpdate("delete from existing_data");\r
+           System.out.println("'Database.existing_data'から "+ count +" 件のデータを削除しました。");\r
+\r
+           count = stmt.executeUpdate("delete from bus_course");\r
+           System.out.println("'Database.bus_course'から "+ count +" 件のデータを削除しました。");\r
+\r
+           count = stmt.executeUpdate("delete from bus_ref");\r
+           System.out.println("'Database.bus_ref'から "+ count +" 件のデータを削除しました。");\r
+           stmt.close();\r
+       }\r
+\r
+       public static void initDb(Connection con) throws SQLException {\r
+               String createSt;\r
+\r
+               // 'table.BUS_STOP'を新規に作る\r
+               DbBusstop.create(con);\r
+\r
+               createSt = "CREATE TABLE existing_data (idref VARCHAR(12) NOT NULL, name VARCHAR(128), lat DOUBLE, lon DOUBLE, CONSTRAINT existing_pk PRIMARY KEY(idref, lat, lon));";\r
+               DbBusstop.create(con, createSt);\r
+               \r
+               createSt = "CREATE TABLE bus_course (code int, type int, corp VARCHAR(128) NOT NULL, course VARCHAR(512), ifile VARCHAR(128), CONSTRAINT bus_course_pk PRIMARY KEY(code));";\r
+               DbBusstop.create(con, createSt);\r
+\r
+               createSt = "CREATE TABLE bus_ref (idref VARCHAR(12), code INT);";\r
+               DbBusstop.create(con, createSt);\r
+       }\r
+\r
+\r
+       /**\r
+        * ローカルデータベース内の情報を出力する\r
+        * @param con\r
+        * @param iCode\r
+        * @throws IOException\r
+        * @throws SQLException\r
+        */\r
+       public static void outputDb(Connection con, String iCode) throws IOException, SQLException {\r
+               SimpleDateFormat timeStampFmt = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");\r
+               String timeStampStr = timeStampFmt.format(new Date(Calendar.getInstance().getTimeInMillis()));\r
+               File dir = new File(iCode);\r
+               dir.mkdir();\r
+\r
+               BufferedWriter ow = null;\r
+               BufferedWriter gw = null;\r
+               BufferedWriter hw = null;\r
+               BufferedWriter ww = null;\r
+\r
+               // HTML header\r
+               File htmlFile = new File(iCode  +".html");\r
+               hw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(htmlFile), "UTF-8"));\r
+               hw.write("<!DOCTYPE html>");\r
+               hw.newLine();\r
+               hw.write("<html><head><meta charset=\"utf-8\" /></head>");\r
+               hw.newLine();\r
+               hw.write("<body><table border='1'>");\r
+               hw.newLine();\r
+               hw.write("<tr>");\r
+               hw.write("<td>type</td>");\r
+               hw.write("<td>corp</td>");\r
+               hw.write("<td>course</td>");\r
+               hw.write("<td>GPX</td>");\r
+               hw.write("<td>SAMPLE</td>");\r
+               hw.write("<td>バス停数</td>");\r
+               hw.write("<td>未入力</td>");\r
+               hw.write("<td>既存</td>");\r
+               hw.write("</tr>");\r
+               hw.newLine();\r
+\r
+               // Wiki header\r
+               File wikiFile = new File(iCode  +".wiki.txt");\r
+               ww = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(wikiFile), "UTF-8"));\r
+               ww.write("= バス路線毎のマッピング状況 =");\r
+               ww.newLine();\r
+               ww.newLine();\r
+               \r
+               String maeCorp = "";\r
+               boolean firstCorp = true;\r
+               \r
+               PreparedStatement ps7 = con.prepareStatement("SELECT code,type,corp,course,ifile FROM bus_course WHERE ifile=? ORDER BY type,corp,course");\r
+               PreparedStatement ps9 = con.prepareStatement("SELECT idref FROM bus_ref WHERE code=?");\r
+               PreparedStatement ps8 = con.prepareStatement("SELECT name,lat,lon,fixed FROM bus_stop WHERE idref=?");\r
+               ps7.setString(1, iCode);\r
+               ResultSet rset7 = ps7.executeQuery();\r
+               while (rset7.next()) {\r
+                       int code = rset7.getInt(1);\r
+                       int type = rset7.getInt(2);\r
+                       String corp = rset7.getString(3);\r
+                       String course = rset7.getString(4);\r
+                       \r
+\r
+                       File osmFile = new File(dir, iCode + String.format("_%1$08d", code) +".osm");\r
+                       File gpxFile = new File(dir, iCode + String.format("_%1$08d", code) +".gpx");\r
+                       File osmSample = new File(dir, iCode + String.format("_s%1$08d", code) +".osm");\r
+\r
+                       System.out.println("course = "+ course);\r
+                       int stopCount = 0;\r
+                       int fixedCount = 0;\r
+                       int unfixedCount = 0;\r
+\r
+                       // index file header\r
+                       hw.write("<tr>");\r
+                       hw.write("<td>"+ type +"</td>");\r
+                       hw.write("<td>"+ corp +"</td>");\r
+                       hw.write("<td><a href='"+ dir.getName() +"/"+ osmFile.getName() +"'>"+ course +"</a></td>");\r
+                       hw.write("<td><a href='"+ dir.getName() +"/"+ gpxFile.getName() +"'>"+ gpxFile.getName() +"</a></td>");\r
+                       hw.write("<td><a href='"+ dir.getName() +"/"+ osmSample.getName() +"'>"+ osmSample.getName() +"</a></td>");\r
+                       hw.newLine();\r
+\r
+                       //--------------------------------------------\r
+                       //      Wiki見出し2: 運行会社\r
+                       //------------\r
+                       if (!maeCorp.equals(corp)) {\r
+                               if (firstCorp == false) {\r
+                                       ww.write("|}");\r
+                                       ww.newLine();\r
+                                       ww.newLine();\r
+                               }\r
+                               firstCorp = false;\r
+                               \r
+                               ww.write("=== "+ corp +" ===");\r
+                               ww.newLine();\r
+                               ww.newLine();\r
+\r
+                               ww.write(":{{JA:Tag|network||"+ corp +"}}");\r
+                               ww.newLine();\r
+                               ww.write(":{{JA:Tag|operator||"+ corp +"}}");\r
+                               ww.newLine();\r
+                               ww.newLine();\r
+\r
+                               ww.write("{| class=\"wikitable sortable\" style=\"table-layout: fixed; width: 100%\"");\r
+                               ww.newLine();\r
+                               ww.write("!style=\"width: 100px\"| ref");\r
+                               ww.newLine();\r
+                               ww.write("!class=\"unsortable\" style=\"width: 152px\"| 編集状況(マスタ)");\r
+                               ww.newLine();\r
+                               ww.write("!class=\"unsortable\" style=\"width: 152px\"| 編集状況(往路)");\r
+                               ww.newLine();\r
+                               ww.write("!class=\"unsortable\" style=\"width: 152px\"| 編集状況(復路)");\r
+                               ww.newLine();\r
+                               ww.write("!class=\"unsortable\"| 備考");\r
+                               ww.newLine();\r
+\r
+                               maeCorp = new String(corp);\r
+                       }\r
+                       \r
+                       // Wiki\r
+                       ww.write("|-");\r
+                       ww.newLine();\r
+                       ww.write("| "+ course +" ");            // ref\r
+                       ww.write("|| {{State Route|r=0}} {{relation|0|tools=no}} ");                    // 編集状況 (マスタ)\r
+                       ww.write("|| {{State Route|r=0|h=0}} {{relation|0|tools=no}} ");                // 編集状況 (往路)\r
+                       ww.write("|| {{State Route|r=0|h=0}} {{relation|0|tools=no}} ");                // 編集状況 (復路)\r
+                       ww.write("|| ");                // 備考\r
+                       ww.newLine();\r
+\r
+\r
+                       // OSM file header\r
+                       ow = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(osmFile), "UTF-8"));\r
+                       ow.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");\r
+                       ow.newLine();\r
+                       ow.write("<osm version=\"0.6\" generator=\"ConvBusstop\">");\r
+                       ow.newLine();\r
+\r
+                       // GPX file header\r
+                       gw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(gpxFile), "UTF-8"));\r
+                       gw.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");\r
+                       gw.newLine();\r
+                       gw.write("<gpx xmlns=\"http://www.topografix.com/GPX/1/1\" version=\"1.1\" creator=\"osmtracker-android\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd \">");\r
+                       gw.newLine();\r
+\r
+                       double maxLat = -180.0;\r
+                       double minLat = 180.0;\r
+                       double maxLon = -180.0;\r
+                       double minLon = 180.0;\r
+\r
+                       ps9.setInt(1, code);\r
+                       ResultSet rset9 = ps9.executeQuery();\r
+                       while (rset9.next()) {\r
+                               String idref = rset9.getString(1);\r
+\r
+                               ps8.setString(1, idref);\r
+                               ResultSet rset8 = ps8.executeQuery();\r
+                               if (rset8.next()) {\r
+                                       stopCount++;\r
+                                       String name = rset8.getString(1);\r
+                                       Double lat = rset8.getDouble(2);\r
+                                       Double lon = rset8.getDouble(3);\r
+                                       int fixed = rset8.getInt(4);\r
+\r
+                                       if (lat > maxLat) {\r
+                                               maxLat = lat;\r
+                                       }\r
+                                       if (lon > maxLon) {\r
+                                               maxLon = lon;\r
+                                       }\r
+                                       if (lat < minLat) {\r
+                                               minLat = lat;\r
+                                       }\r
+                                       if (lon < minLon) {\r
+                                               minLon = lon;\r
+                                       }\r
+                                       \r
+                                       System.out.println("\tway point = "+ idref +", lat="+ lat +", lon="+ lon +", name="+ name);\r
+                                       fixedCount += fixed;\r
+                                       if (fixed == 0) {\r
+                                               unfixedCount++;\r
+\r
+                                               // OSM node\r
+                                               int nodeid = Integer.parseInt(idref.substring(1)) * -1;\r
+                                               String osm_node = nodeBusstop(nodeid, name, lat, lon, timeStampStr);\r
+                                               ow.write(osm_node);\r
+                                               ow.newLine();\r
+\r
+                                               // TEXT node\r
+                                               //File txtFile = new File(dir, iCode + idref +".txt");\r
+                                               //BufferedWriter gw2 = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(txtFile), "UTF-8"));\r
+                                               //gw2.write(osm_node);\r
+                                               //gw2.newLine();\r
+                                               //gw2.close();\r
+\r
+                                               // GPX waypoint\r
+                                               gw.write("<wpt lat=\""+ lat +"\" lon=\""+ lon +"\">\n");\r
+                                               gw.write(" <time>"+ timeStampStr +"Z</time>\n");\r
+                                               gw.write(" <name><![CDATA["+ name +"]]></name>\n");\r
+                                               //gw.write(" <link href=\""+ txtFile.getName() +"\"><text>"+ idref +"</text></link>\n");\r
+                                               gw.write("</wpt>\n");\r
+                                               gw.newLine();\r
+                                       }\r
+                               }\r
+                               rset8.close();\r
+                       }\r
+                       rset9.close();\r
+\r
+                       // INDEX file\r
+                       hw.write("<td>"+ stopCount +"</td>");\r
+                       hw.write("<td>"+ unfixedCount +"</td>");\r
+                       hw.write("<td>"+ fixedCount +"</td>");\r
+                       hw.write("</tr>");\r
+                       hw.newLine();\r
+\r
+                       // OSM file header\r
+                       BufferedWriter ow2 = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(osmSample), "UTF-8"));\r
+                       ow2.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");\r
+                       ow2.newLine();\r
+                       ow2.write("<osm version=\"0.5\" generator=\"ConvBusstop\">");\r
+                       ow2.newLine();\r
+\r
+                       ow2.write(nodeBusstop(code, "SAMPLE", ((maxLat+minLat)/2), ((maxLon+minLon)/2), timeStampStr));\r
+                       ow2.newLine();\r
+                       ow2.write("</osm>");\r
+                       ow2.newLine();\r
+                       ow2.close();\r
+\r
+                       // OSM file footer\r
+                       ow.write("</osm>");\r
+                       ow.newLine();\r
+                       ow.close();\r
+\r
+                       // GPX file footer\r
+                       gw.write("</gpx>");\r
+                       gw.newLine();\r
+                       gw.close();\r
+               }\r
+               rset7.close();\r
+\r
+               // Wiki footer\r
+               ww.close();\r
+\r
+               // index file footer\r
+               hw.write("</table></body></html>");\r
+               hw.newLine();\r
+               hw.close();\r
+       }\r
+\r
+       public static int outputDb(Connection con) throws IOException, SQLException {\r
+               File osmFile = new File("busstop.osm");\r
+               int counter = 0;\r
+\r
+               SimpleDateFormat timeStampFmt = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");\r
+               String timeStampStr = timeStampFmt.format(new Date(Calendar.getInstance().getTimeInMillis()));\r
+               BufferedWriter ow = null;\r
+               \r
+               // OSM file header\r
+               ow = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(osmFile), "UTF-8"));\r
+               ow.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");\r
+               ow.newLine();\r
+               ow.write("<osm version=\"0.6\" generator=\"ConvBusstop\">");\r
+               ow.newLine();\r
+               \r
+               PreparedStatement ps8 = con.prepareStatement("SELECT idref,name,lat,lon,fixed FROM bus_stop");\r
+               ResultSet rset8 = ps8.executeQuery();\r
+               while (rset8.next()) {\r
+                       String idref = rset8.getString("idref");\r
+                       String name = rset8.getString("name");\r
+                       Double lat = rset8.getDouble("lat");\r
+                       Double lon = rset8.getDouble("lon");\r
+                       int fixed = rset8.getInt("fixed");\r
+                       \r
+                       if (ConvBusstop.nocheck || (fixed < 1)) {\r
+                               // OSM node\r
+                               counter++;\r
+                               int nodeid = Integer.parseInt(idref.substring(1)) * -1;\r
+                               String osm_node = nodeBusstop(nodeid, name, lat, lon, timeStampStr);\r
+                               System.out.println(osm_node);\r
+                               ow.write(osm_node);\r
+                               ow.newLine();\r
+                       }\r
+               }\r
+               rset8.close();\r
+\r
+               // OSM file footer\r
+               ow.write("</osm>");\r
+               ow.newLine();\r
+               ow.close();\r
+               return counter;\r
+       }\r
+       \r
+       public static String nodeBusstop(int code, String name, Double lat, Double lon, String timeStampStr) {\r
+               String osm_node = ("<node id=\""+ code +"\" timestamp=\""+ timeStampStr +"Z\" lat=\""+ lat +"\" lon=\""+ lon +"\">\n");\r
+               osm_node += "<tag k=\"name\" v=\""+ name +"\"/>\n";\r
+               osm_node += "<tag k=\"fixme\" v=\"platform/stop_positionを選択して、正しい位置に移動させてください\"/>\n";\r
+               osm_node += "<tag k=\"source\" v=\"KSJ2\"/>\n";\r
+               osm_node += "<tag k=\"source_ref\" v=\"http://nlftp.mlit.go.jp/ksj/gml/datalist/KsjTmplt-P11.html\"/>\n";\r
+               osm_node += "<tag k=\"created_by\" v=\"National-Land-Numerical-Information_MLIT_Japan\"/>\n";\r
+               osm_node += "<tag k=\"note\" v=\"National-Land Numerical Information (Bus stop) 2012, MLIT Japan\"/>\n";\r
+               osm_node += "<tag k=\"note:ja\" v=\"国土数値情報(バス停留所)平成24年 国土交通省\"/>\n";\r
+               osm_node += "<tag k=\"public_transport\" v=\"platform\"/>\n";\r
+               osm_node += "<tag k=\"public_transport\" v=\"stop_position\"/>\n";\r
+               osm_node += "<tag k=\"highway\" v=\"bus_stop\"/>\n";\r
+               osm_node += "<tag k=\"bus\" v=\"yes\"/>\n";\r
+               osm_node += "</node>\n";\r
+               return osm_node;\r
+       }\r
+\r
+       /**\r
+        *\r
+        * @param con\r
+        * @param node\r
+        * @param iFileName             // ソースファイル名(拡張子を含まない)\r
+        * @param timeStampStr\r
+        * @return\r
+        * @throws IOException\r
+        * @throws SQLException\r
+        */\r
+       public static int showNodes(Connection con, Node node, String iFileName, String timeStampStr) throws IOException, SQLException {\r
+               int iCounter = 0;\r
+               NamedNodeMap nodeMap = node.getAttributes();\r
+               if ( null != nodeMap ) {\r
+                       for ( int j=0; j < nodeMap.getLength(); j++ ) {\r
+                               if (nodeMap.item(j).getNodeName().equals("timeStamp")) {\r
+                                       timeStampStr = nodeMap.item(j).getNodeValue();\r
+                               }\r
+                       }\r
+               }\r
+\r
+               NodeList nodes = node.getChildNodes();\r
+               for (int i=0; i<nodes.getLength(); i++) {\r
+                       Node node2 = nodes.item(i);\r
+                       if (node2.getNodeName().equals("jps:GM_Point")) {\r
+                               showGmPoint(con, node2);\r
+                       }\r
+                       else if (node2.getNodeName().equals("gml:Point")) {\r
+                               showGmlPoint(con, node2);\r
+                       }\r
+\r
+                       else if (node2.getNodeName().equals("ksj:ED01")) {\r
+                               iCounter++;\r
+                               showED01(con, node2, iFileName);\r
+                       }\r
+                       else if (node2.getNodeName().equals("ksj:BusStop")) {\r
+                               iCounter++;\r
+                               showBusStop(con, node2, iFileName);\r
+                       }\r
+\r
+                       else {\r
+                               iCounter += showNodes(con, node2, iFileName, timeStampStr);\r
+                       }\r
+               }\r
+               return iCounter;\r
+       }\r
+\r
+       /**\r
+        *\r
+        * @param con\r
+        * @param node\r
+        * @param iFileName             // ソースファイル名(拡張子を含まない)\r
+        * @throws IOException\r
+        * @throws SQLException\r
+        */\r
+       public static void showED01(Connection con, Node node, String iFileName) throws IOException, SQLException {\r
+               String idrefStr = "";\r
+               String nameStr = "";\r
+               PreparedStatement ps1 = con.prepareStatement("SELECT idref FROM bus_stop WHERE idref=?");\r
+               PreparedStatement ps2 = con.prepareStatement("INSERT INTO bus_stop (idref,name,ifile) VALUES (?,?,?)");\r
+               PreparedStatement ps3 = con.prepareStatement("SELECT code FROM bus_course WHERE course=? AND corp=? AND ifile=?");\r
+               PreparedStatement ps4 = con.prepareStatement("INSERT INTO bus_course (code,type,corp,course,ifile) VALUES (?,?,?,?,?)");\r
+               PreparedStatement ps5 = con.prepareStatement("INSERT INTO bus_ref (idref,code) VALUES (?,?)");\r
+               PreparedStatement ps6 = con.prepareStatement("SELECT max(code) FROM bus_course WHERE ifile=?");\r
+\r
+               ArrayList<String[]> bris = new ArrayList<String[]>();\r
+               NodeList nodes = node.getChildNodes();\r
+               for (int i=0; i < nodes.getLength(); i++) {\r
+                       Node node2 = nodes.item(i);\r
+                       if (node2.getNodeName().equals("ksj:POS")) {\r
+                               NamedNodeMap nodeMap = node2.getAttributes();\r
+                               if (null != nodeMap) {\r
+                                       for ( int j=0; j < nodeMap.getLength(); j++ ) {\r
+                                               if (nodeMap.item(j).getNodeName().equals("idref")) {\r
+                                                       idrefStr = nodeMap.item(j).getNodeValue();\r
+                                                       System.out.println("found idref='"+ idrefStr +"'");\r
+                                                       break;\r
+                                               }\r
+                                       }\r
+                               }\r
+                       }\r
+                       else if (node2.getNodeName().equals("ksj:BSN")) {\r
+                               nameStr = node2.getTextContent();\r
+                       }\r
+                       else if (node2.getNodeName().equals("ksj:BRI")) {\r
+                               String[] rtn = anaComm(node2);\r
+                               if (rtn != null) {\r
+                                       bris.add(rtn);\r
+                               }\r
+                       }\r
+               }\r
+\r
+               // idref と nameStr をデータベースに格納する\r
+               boolean insert = true;\r
+               ps1.setString(1, idrefStr);\r
+               ResultSet rset = ps1.executeQuery();\r
+               if (rset.next()) {\r
+                       insert = false;\r
+               }\r
+               rset.close();\r
+\r
+               if (insert) {\r
+                       ps2.setString(1, idrefStr);\r
+                       ps2.setString(2, nameStr);\r
+                       ps2.setString(3, iFileName);\r
+                       System.out.println("INSERT INTO bus_stop (idref,name,ifile) VALUES ('"+ idrefStr +"','"+ nameStr +"','"+ iFileName +"')");\r
+                       ps2.executeUpdate();\r
+               }\r
+\r
+               for (String[] rtn : bris) {\r
+                       int code = 0;\r
+                       ps3.setString(1, rtn[1]);\r
+                       ps3.setString(2, rtn[2]);\r
+                       ps3.setString(3, iFileName);\r
+                       rset = ps3.executeQuery();\r
+                       if (rset.next()) {\r
+                               code = rset.getInt(1);\r
+                       }\r
+                       rset.close();\r
+\r
+                       if (code == 0) {\r
+                               ps6.setString(1, iFileName);\r
+                               ResultSet rset6 = ps6.executeQuery();\r
+                               if (rset6.next()) {\r
+                                       code = rset6.getInt(1);\r
+                               }\r
+                               rset6.close();\r
+                               code++;\r
+\r
+                               System.out.println("code="+code);\r
+                               ps4.setInt(1, code);\r
+                               ps4.setInt(2, Integer.parseInt(rtn[0]));\r
+                               ps4.setString(3, rtn[2]);\r
+                               ps4.setString(4, rtn[1]);\r
+                               ps4.setString(5, iFileName);\r
+                               ps4.executeUpdate();\r
+                       }\r
+\r
+                       ps5.setString(1, idrefStr);\r
+                       ps5.setInt(2, code);\r
+                       ps5.executeUpdate();\r
+               }\r
+\r
+               ps1.close();\r
+               ps2.close();\r
+               ps3.close();\r
+               ps4.close();\r
+               ps5.close();\r
+       }\r
+\r
+       /**\r
+        * <ksj:BusStop gml:id="ED01_1">\r
+        *      <ksj:position xlink:href="#n1"/>\r
+        *      <ksj:busStopName>城堀</ksj:busStopName>\r
+        *      <ksj:busRouteInformation>\r
+        *              <ksj:BusRouteInformation>\r
+        *                      <ksj:busType>1</ksj:busType>\r
+        *                      <ksj:busOperationCompany>箱根登山バス</ksj:busOperationCompany>\r
+        *                      <ksj:busLineName>小01</ksj:busLineName>\r
+        *              </ksj:BusRouteInformation>\r
+        *      </ksj:busRouteInformation>\r
+        *      <ksj:busRouteInformation>\r
+        *              <ksj:BusRouteInformation>\r
+        *                      <ksj:busType>1</ksj:busType>\r
+        *                      <ksj:busOperationCompany>箱根登山バス</ksj:busOperationCompany>\r
+        *                      <ksj:busLineName>湯07</ksj:busLineName>\r
+        *              </ksj:BusRouteInformation>\r
+        *      </ksj:busRouteInformation>\r
+        *      <ksj:busRouteInformation>\r
+        *              <ksj:BusRouteInformation>\r
+        *                      <ksj:busType>1</ksj:busType>\r
+        *                      <ksj:busOperationCompany>箱根登山バス</ksj:busOperationCompany>\r
+        *                      <ksj:busLineName>湯11</ksj:busLineName>\r
+        *              </ksj:BusRouteInformation>\r
+        *      </ksj:busRouteInformation>\r
+        * </ksj:BusStop>\r
+        *\r
+        * @param con\r
+        * @param node\r
+        * @param iFileName             // ソースファイル名(拡張子を含まない)\r
+        * @throws IOException\r
+        * @throws SQLException\r
+        */\r
+       public static void showBusStop(Connection con, Node node, String iFileName) throws IOException, SQLException {\r
+               String idrefStr = "";\r
+               String nameStr = "";\r
+               PreparedStatement ps2 = con.prepareStatement("UPDATE bus_stop SET name=?,ifile=? WHERE idref=?");\r
+               PreparedStatement ps3 = con.prepareStatement("SELECT code FROM bus_course WHERE course=? AND corp=? AND ifile=?");\r
+               PreparedStatement ps4 = con.prepareStatement("INSERT INTO bus_course (code,type,corp,course,ifile) VALUES (?,?,?,?,?)");\r
+               PreparedStatement ps5 = con.prepareStatement("INSERT INTO bus_ref (idref,code) VALUES (?,?)");\r
+               PreparedStatement ps6 = con.prepareStatement("SELECT max(code) FROM bus_course WHERE ifile=?");\r
+\r
+               ArrayList<String[]> bris = new ArrayList<String[]>();\r
+               NodeList nodes = node.getChildNodes();\r
+               for (int i=0; i < nodes.getLength(); i++) {\r
+                       Node node2 = nodes.item(i);\r
+                       if (node2.getNodeName().equals("ksj:position")) {\r
+                               NamedNodeMap nodeMap = node2.getAttributes();\r
+                               if (null != nodeMap) {\r
+                                       for ( int j=0; j < nodeMap.getLength(); j++ ) {\r
+                                               if (nodeMap.item(j).getNodeName().equals("xlink:href")) {\r
+                                                       idrefStr = nodeMap.item(j).getNodeValue();\r
+                                                       idrefStr = idrefStr.substring(1);\r
+                                                       System.out.println("found idref='"+ idrefStr +"'");\r
+                                                       break;\r
+                                               }\r
+                                       }\r
+                               }\r
+                       }\r
+                       else if (node2.getNodeName().equals("ksj:busStopName")) {\r
+                               nameStr = node2.getTextContent();\r
+                       }\r
+                       else if (node2.getNodeName().equals("ksj:busRouteInformation")) {\r
+                               String[] rtn = anaCommJGD(node2);\r
+                               if (rtn != null) {\r
+                                       bris.add(rtn);\r
+                               }\r
+                       }\r
+               }\r
+\r
+               // idref と nameStr をデータベースに格納する\r
+               ps2.setString(1, nameStr);\r
+               ps2.setString(2, iFileName);\r
+               ps2.setString(3, idrefStr);\r
+               ps2.executeUpdate();\r
+\r
+               for (String[] rtn : bris) {\r
+                       int code = 0;\r
+                       ps3.setString(1, rtn[1]);\r
+                       ps3.setString(2, rtn[2]);\r
+                       ps3.setString(3, iFileName);\r
+                       ResultSet rset = ps3.executeQuery();\r
+                       if (rset.next()) {\r
+                               code = rset.getInt(1);\r
+                       }\r
+                       rset.close();\r
+\r
+                       if (code == 0) {\r
+                               ps6.setString(1, iFileName);\r
+                               ResultSet rset6 = ps6.executeQuery();\r
+                               if (rset6.next()) {\r
+                                       code = rset6.getInt(1);\r
+                               }\r
+                               rset6.close();\r
+                               code++;\r
+\r
+                               System.out.println("course="+ code +" : "+ rtn[0] +" : "+ rtn[1] +" : "+ rtn[2] );\r
+                               ps4.setInt(1, code);\r
+                               ps4.setInt(2, Integer.parseInt(rtn[0]));\r
+                               ps4.setString(3, rtn[2]);\r
+                               ps4.setString(4, rtn[1]);\r
+                               ps4.setString(5, iFileName);\r
+                               ps4.executeUpdate();\r
+                       }\r
+\r
+                       ps5.setString(1, idrefStr);\r
+                       ps5.setInt(2, code);\r
+                       ps5.executeUpdate();\r
+               }\r
+\r
+               ps2.close();\r
+               ps3.close();\r
+               ps4.close();\r
+               ps5.close();\r
+       }\r
+\r
+       public static String[] anaComm(Node briNode) {\r
+               String[] rtn = new String[3];\r
+               rtn[0] = "";    // corp type\r
+               rtn[1] = "";    // course name\r
+               rtn[2] = "";    // corp name\r
+\r
+               NodeList nodes = briNode.getChildNodes();\r
+               for (int i=0; i < nodes.getLength(); i++) {\r
+                       Node node2 = nodes.item(i);\r
+                       if (node2.getNodeName().equals("ksj:BSC")) {\r
+                               rtn[0] = node2.getTextContent();\r
+                       }\r
+                       else if (node2.getNodeName().equals("ksj:BLN")) {\r
+                               rtn[1] = node2.getTextContent();\r
+                       }\r
+                       else if (node2.getNodeName().equals("ksj:BOC")) {\r
+                               rtn[2] = node2.getTextContent();\r
+                       }\r
+               }\r
+               return rtn;\r
+       }\r
+\r
+       /**\r
+        *\r
+        *      <ksj:busRouteInformation>\r
+        *              <ksj:BusRouteInformation>\r
+        *                      <ksj:busType>1</ksj:busType>\r
+        *                      <ksj:busOperationCompany>箱根登山バス</ksj:busOperationCompany>\r
+        *                      <ksj:busLineName>小01</ksj:busLineName>\r
+        *              </ksj:BusRouteInformation>\r
+        *      </ksj:busRouteInformation>\r
+        *\r
+        * @param briNode\r
+        * @return\r
+        */\r
+       public static String[] anaCommJGD(Node briNode) {\r
+               String[] rtn = new String[3];\r
+               int vcnt = 0;\r
+\r
+               NodeList nodes2 = briNode.getChildNodes();\r
+               for (int i=0; i < nodes2.getLength(); i++) {\r
+                       Node node2 = nodes2.item(i);\r
+                       if (node2.getNodeName().equals("ksj:BusRouteInformation")) {\r
+                               NodeList nodes3 = node2.getChildNodes();\r
+                               for (int j=0; j < nodes3.getLength(); j++) {\r
+                                       Node node3 = nodes3.item(j);\r
+                                       if (node3.getNodeName().equals("ksj:busType")) {\r
+                                               rtn[0] = new String(node3.getTextContent());\r
+                                               vcnt++;\r
+                                       }\r
+                                       else if (node3.getNodeName().equals("ksj:busLineName")) {\r
+                                               rtn[1] = new String(node3.getTextContent());\r
+                                               vcnt++;\r
+                                       }\r
+                                       else if (node3.getNodeName().equals("ksj:busOperationCompany")) {\r
+                                               rtn[2] = new String(node3.getTextContent());\r
+                                               vcnt++;\r
+                                       }\r
+                               }\r
+                       }\r
+               }\r
+\r
+               if (vcnt > 0) {\r
+                       return rtn;\r
+               }\r
+               return null;\r
+       }\r
+\r
+       public static void showGmPoint(Connection con, Node node) throws IOException, SQLException {\r
+               String positionStr = "";\r
+               String latStr = "";\r
+               String lonStr = "";\r
+               String idStr = "";\r
+\r
+               NamedNodeMap nodeMap = node.getAttributes();\r
+               if ( null != nodeMap ) {\r
+                       for ( int j=0; j<nodeMap.getLength(); j++ ) {\r
+                               if (nodeMap.item(j).getNodeName().equals("id")) {\r
+                                       idStr = nodeMap.item(j).getNodeValue();\r
+                               }\r
+                       }\r
+               }\r
+\r
+               NodeList nodes = node.getChildNodes();\r
+               for (int i=0; i < nodes.getLength(); i++) {\r
+                       Node node2 = nodes.item(i);\r
+                       if (node2.getNodeName().equals("jps:GM_Point.position")) {\r
+                               NodeList nodes3 = node2.getChildNodes();\r
+                               for (int j=0; j < nodes3.getLength(); j++) {\r
+                                       Node node3 = nodes3.item(j);\r
+                                       if (node3.getNodeName().equals("jps:DirectPosition")) {\r
+                                               NodeList nodes4 = node3.getChildNodes();\r
+                                               for (int k=0; k < nodes4.getLength(); k++) {\r
+                                                       Node node4 = nodes4.item(k);\r
+                                                       if (node4.getNodeName().equals("DirectPosition.coordinate")) {\r
+                                                               positionStr = node4.getTextContent();\r
+                                                               String[] str4Ary = positionStr.split(" ");\r
+                                                               latStr = str4Ary[0];\r
+                                                               lonStr = str4Ary[1];\r
+                                                               break;\r
+                                                       }\r
+                                               }\r
+                                               break;\r
+                                       }\r
+                               }\r
+\r
+                               PreparedStatement ps6 = con.prepareStatement("UPDATE bus_stop SET lat=?,lon=?,fixed=? WHERE idref=?");\r
+                               double lat = Double.parseDouble(latStr);\r
+                               double lon = Double.parseDouble(lonStr);\r
+                               ps6.setDouble(1, lat);\r
+                               ps6.setDouble(2, lon);\r
+                               // ps6.setInt(3, (ConvBusstop.nocheck ? 0 : HttpGET.getMap(lat, lon, NEER)));\r
+                               ps6.setInt(3, 0);\r
+                               ps6.setString(4, idStr);\r
+                               System.out.println("UPDATE bus_stop("+ idStr +") lat="+ lat +", lon="+ lon +", fixed=0");\r
+                               ps6.executeUpdate();\r
+                               ps6.close();\r
+                       }\r
+               }\r
+       }\r
+\r
+       /**\r
+        * <gml:Point gml:id="n1">\r
+        *      <gml:pos>35.14591397 139.10569573</gml:pos>\r
+        * </gml:Point>\r
+        *\r
+        * @param con\r
+        * @param node\r
+        * @throws IOException\r
+        * @throws SQLException\r
+        */\r
+       public static void showGmlPoint(Connection con, Node node) throws IOException, SQLException {\r
+               String positionStr = "";\r
+               String latStr = "";\r
+               String lonStr = "";\r
+               String idStr = "";\r
+\r
+               NamedNodeMap nodeMap = node.getAttributes();\r
+               if ( null != nodeMap ) {\r
+                       for ( int j=0; j<nodeMap.getLength(); j++ ) {\r
+                               if (nodeMap.item(j).getNodeName().equals("gml:id")) {\r
+                                       idStr = nodeMap.item(j).getNodeValue();\r
+                               }\r
+                       }\r
+               }\r
+\r
+               NodeList nodes = node.getChildNodes();\r
+               for (int i=0; i < nodes.getLength(); i++) {\r
+                       Node node2 = nodes.item(i);\r
+                       if (node2.getNodeName().equals("gml:pos")) {\r
+                               positionStr = node2.getTextContent().trim();\r
+                               String[] str4Ary = positionStr.split(" ");\r
+                               latStr = str4Ary[0];\r
+                               lonStr = str4Ary[1];\r
+                               \r
+                               PreparedStatement ps6 = con.prepareStatement("INSERT INTO bus_stop (lat,lon,fixed,idref) VALUES (?,?,?,?)");\r
+                               double lat = Double.parseDouble(latStr);\r
+                               double lon = Double.parseDouble(lonStr);\r
+                               System.out.println("INSERT INTO bus_stop (lat,lon,fixed,idref) VALUES ('"+ latStr +"','"+ lonStr +"','0','"+ idStr +"')");\r
+\r
+                               ps6.setDouble(1, lat);\r
+                               ps6.setDouble(2, lon);\r
+                               //ps6.setInt(3, (ConvBusstop.nocheck ? 0 : HttpGET.getMap(lat, lon, NEER)));\r
+                               ps6.setInt(3, 0);\r
+                               ps6.setString(4, idStr);\r
+                               ps6.executeUpdate();\r
+                               ps6.close();\r
+                       }\r
+               }\r
+       }\r
+\r
+       static boolean checkFile(File f) {\r
+               String name = f.getName();\r
+               if (!name.startsWith("P11-")) {\r
+                       return false;\r
+               }\r
+               if (!name.toUpperCase().endsWith(".XML")) {\r
+                       return false;\r
+               }\r
+               return true;\r
+       }\r
 }
\ No newline at end of file