移植 anaComm
1 parent 507a44e commit f20787d3cb85cc02cfe362dcb5c96ad784a2bfdf
@hayashi hayashi authored on 30 Sep 2017
Showing 2 changed files
View
318
src/osm/jp/coverage/busstop/Busstop.java
}
 
 
 
/**
*
* @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 (?,?,?)");
try {
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 = true;
ps1.setString(1, idrefStr);
ResultSet rset = ps1.executeQuery();
if (rset.next()) {
insert = false;
}
rset.close();
 
if (insert) {
ps2.setString(1, idrefStr);
ps2.setString(2, nameStr);
ps2.setString(3, iFileName);
System.out.println("INSERT INTO bus_stop (idref,name,ifile) VALUES ('"+ idrefStr +"','"+ nameStr +"','"+ iFileName +"')");
ps2.executeUpdate();
}
}
finally {
ps1.close();
ps2.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 ps2 = con.prepareStatement("UPDATE bus_stop SET name=?,ifile=? WHERE idref=?");
 
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 をデータベースに格納する
ps2.setString(1, nameStr);
ps2.setString(2, iFileName);
ps2.setString(3, idrefStr);
ps2.executeUpdate();
ps2.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>
View
27
src/osm/jp/coverage/busstop/DbBusstop.java
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
import static osm.jp.coverage.busstop.Busstop.anaComm;
import static osm.jp.coverage.busstop.Busstop.anaCommJGD;
 
public class DbBusstop {
public static final String TABLE_NAME = "bus_stop";
ps2.executeUpdate();
}
}
 
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);
switch (node2.getNodeName()) {
case "ksj:BSC":
rtn[0] = node2.getTextContent();
break;
case "ksj:BLN":
rtn[1] = node2.getTextContent();
break;
case "ksj:BOC":
rtn[2] = node2.getTextContent();
break;
default:
break;
}
}
return rtn;
}
 
/**
* 'table.BUS_STOP'を新規に作る
* 既にテーブルが存在する時には何もしない
* @param conHsql