Example usage for org.jdom2 Element getChildText

List of usage examples for org.jdom2 Element getChildText

Introduction

In this page you can find the example usage for org.jdom2 Element getChildText.

Prototype

public String getChildText(final String cname) 

Source Link

Document

Returns the textual content of the named child element, or null if there's no such child.

Usage

From source file:fr.crnan.videso3d.databases.aip.AIP.java

License:Open Source License

private String getUsualName(Element zone) {
    String usualName = null;// www. j  a  va  2s  .  c  om
    String partieID = zone.getChild("Partie").getAttributeValue("pk");
    Element partie = this.findElement(document.getRootElement().getChild("Situation").getChild("PartieS"),
            partieID);
    usualName = partie.getChildText("NomUsuel");
    return usualName;
}

From source file:fr.crnan.videso3d.databases.aip.AIP.java

License:Open Source License

public String getZoneAttributeValue(String zoneID, String attribute) {
    Element zone = findElement(document.getRootElement().getChild("Situation").getChild("VolumeS"), zoneID);
    return zone != null ? zone.getChildText(attribute) : null;
}

From source file:fr.crnan.videso3d.databases.aip.AIP.java

License:Open Source License

public String getTerritoireName(String territoireID) {
    Element territoire = findElement(document.getRootElement().getChild("Situation").getChild("TerritoireS"),
            territoireID);//from   w w w  . j  ava2  s  .co m
    return territoire.getChildText("Nom");
}

From source file:fr.crnan.videso3d.databases.aip.AIPContext.java

License:Open Source License

public List<JXTaskPane> showRouteInfos(String name) {
    LinkedList<JXTaskPane> taskPanesList = new LinkedList<JXTaskPane>();

    Route segment = getController().getRoutes2DLayer().getRoute(name);
    AIP aip = getController().getAIP();//w  w w .j av a2 s.  com
    String routeName = "";
    fr.crnan.videso3d.graphics.Route.Space type = null;
    String sequence = "";

    if (segment == null) {
        //pas de segment, on recherche la route AIP correspondante
        try {
            Statement st = DatabaseManager.getCurrentAIP();
            ResultSet rs = st.executeQuery("select nom, type from routes");
            String routeAIPName = null;
            while (rs.next() && routeAIPName == null) {
                if (name.equalsIgnoreCase(rs.getString(1).replaceAll(" ", ""))) {
                    routeAIPName = rs.getString(1);
                    if (rs.getString(2).equals("AWY")) {
                        type = Space.FIR;
                    } else {
                        type = Space.UIR;
                    }
                }
            }
            if (routeAIPName != null) {
                routeName = routeAIPName;
            } else {
                //aucune route AIP trouve
                return null;
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }

    } else {
        String[] splittedSegmentName = segment.getName().split("-");

        if (splittedSegmentName.length > 2) {
            routeName = (splittedSegmentName[0] + "-" + splittedSegmentName[1]).trim();
        } else {
            routeName = splittedSegmentName[0].trim();
        }
        sequence = splittedSegmentName[splittedSegmentName.length - 1].trim();
        type = segment.getSpace();
    }

    String pkRoute = null;
    String typeRoute = aip.RouteType2AIPType(routeName, type);

    try {
        pkRoute = getController().getRouteIDFromSegmentName(routeName, typeRoute);
    } catch (SQLException e) {
        e.printStackTrace();
    }
    Element maRoute = aip.findElement(aip.getDocumentRoot().getChild("RouteS"), pkRoute);
    taskPanesList.add(routeInfos(maRoute, typeRoute, pkRoute));

    if (segment != null) {
        //lments du segment AIP
        List<Element> segmentsXML = aip.findElementsByChildId(aip.getDocumentRoot().getChild("SegmentS"),
                "Route", pkRoute);
        Element monSegmentXML = null;
        for (Element segmentXML : segmentsXML) {
            if (segmentXML.getChildText("Sequence").equals(sequence)) {
                monSegmentXML = segmentXML;
            }
        }

        taskPanesList.add(segmentRouteInfos(segment, monSegmentXML, routeName, sequence, typeRoute));
    }

    return taskPanesList;
}

From source file:fr.crnan.videso3d.databases.aip.AIPContext.java

License:Open Source License

private JXTaskPane routeInfos(Element maRoute, String typeRoute, String pkRoute) {
    StringBuilder ACCTraverses = new StringBuilder();
    try {/*ww  w  . j a  v a2 s  .  c  o m*/
        PreparedStatement st = DatabaseManager.prepareStatement(DatasManager.Type.AIP,
                "select nomACC from ACCTraverses where routes_pk = ?");
        st.setString(1, pkRoute);
        ResultSet rs = st.executeQuery();
        while (rs.next()) {
            ACCTraverses.append(rs.getString(1) + " ");
        }
    } catch (SQLException e) {
        e.printStackTrace();
    }

    JXTaskPane infosRoute = new JXTaskPane();
    infosRoute.setTitle("Elments AIP sur la route");
    String CRType = maRoute.getChildText("TypeCompteRendu");
    String rmqRoute = maRoute.getChildText("Remarque");
    infosRoute.add(new JLabel("<html><b>Type de la route</b> : " + typeRoute + "</html>"));
    if (CRType != null) {
        infosRoute.add(new JLabel("<html><b>Compte-rendu</b> : " + CRType + "</html>"));
    }
    infosRoute.add(new JLabel("<html><b>ACC traverss</b> : " + ACCTraverses + "</html>"));
    if (rmqRoute != null) {
        infosRoute.add(new JLabel("<html><b>Remarque</b> : " + rmqRoute + "</html>"));
    }
    final String pkRouteFinal = pkRoute;
    infosRoute.add(new AbstractAction("Afficher les balises") {
        boolean afficher = true;

        @Override
        public void actionPerformed(ActionEvent e) {
            if (afficher) {
                getController().displayRouteNavFixs(pkRouteFinal, true, false);
                putValue(Action.NAME, "Cacher les balises");
                afficher = false;
            } else {
                getController().displayRouteNavFixs(pkRouteFinal, false, false);
                putValue(Action.NAME, "Afficher les balises");
                afficher = true;
            }

        }
    });
    return infosRoute;
}

From source file:fr.crnan.videso3d.databases.aip.AIPContext.java

License:Open Source License

private List<JXTaskPane> showNavFixInfos(int type, String name) {
    LinkedList<JXTaskPane> taskPanesList = new LinkedList<JXTaskPane>();
    final JXTaskPane infosNavFix = new JXTaskPane("Elments AIP");
    AIP aip = getController().getAIP();//from w w w .ja v  a 2 s . c  om

    float latitude = 0, longitude = 0;
    try {
        PreparedStatement ps = DatabaseManager.prepareStatement(DatasManager.Type.AIP,
                "select lat, lon from NavFix where nom=? and type = ?");
        ps.setString(1, name);
        ps.setString(2, AIP.type2String(type));
        ResultSet rs = ps.executeQuery();
        if (rs.next()) {
            latitude = rs.getFloat(1);
            longitude = rs.getFloat(2);
        }
    } catch (SQLException e) {
        e.printStackTrace();
    }
    String nordSud = "";
    String estOuest = "";
    if (latitude >= 0) {
        nordSud = "N";
    } else {
        nordSud = "S";
    }
    if (longitude >= 0) {
        estOuest = "E";
    } else {
        estOuest = "W";
    }
    if (latitude != 0 || longitude != 0) {
        infosNavFix.add(new JLabel(
                "<html><b>Position</b> :" + latitude + "" + nordSud + ", " + longitude + "" + estOuest));

        Element navFixXML = aip.findNavFixInfosByName(name);
        if (navFixXML != null) {
            String nomPhraseo = navFixXML.getChildText("NomPhraseo");
            String freq = navFixXML.getChildText("Frequence");
            String station = navFixXML.getChildText("Station");
            String LatDme = navFixXML.getChildText("LatDme");
            String LonDme = navFixXML.getChildText("LongDme");
            String alti = navFixXML.getChildText("AltitudeFt");
            String situation = navFixXML.getChildText("Situation");
            String pkAd = navFixXML.getChild("Ad").getAttributeValue("pk");
            Element adXML = aip.findElement(aip.getDocumentRoot().getChild("AdS"), pkAd);
            String finCode = adXML.getChildText("AdCode");
            String territoire = adXML.getChild("Territoire").getAttributeValue("lk").substring(1, 3);
            final String adCode = territoire + finCode;
            String adName = adXML.getChildText("AdNomComplet");
            String horCode = navFixXML.getChildText("HorCode");
            String usage = navFixXML.getChildText("Usage");
            String portee = navFixXML.getChildText("Portee");
            String flPortee = navFixXML.getChildText("FlPorteeVert");
            String couverture = navFixXML.getChildText("Couverture");
            if (nomPhraseo != null) {
                infosNavFix.add(new JLabel("<html><b>Nom phraseo</b> : " + nomPhraseo + "</html>"));
                infosNavFix.setTitle(nomPhraseo);
            }
            if (freq != null) {
                infosNavFix.add(new JLabel("<html><b>Frquence</b> : " + freq + "</html>"));
            }
            if (station != null) {
                infosNavFix.add(new JLabel("<html><b>Station</b> : " + station + "</html>"));
            }
            if (LatDme != null) {
                infosNavFix.add(new JLabel("<html><b>Lat. Dme</b> : " + LatDme + "</html>"));
            }
            if (LonDme != null) {
                infosNavFix.add(new JLabel("<html><b>Lon. Dme</b> : " + LonDme + "</html>"));
            }
            if (alti != null) {
                infosNavFix.add(new JLabel("<html><b>Altitude</b> : " + alti + " ft</html>"));
            }
            if (situation != null) {
                infosNavFix.add(new JLabel("<html><b>Situation</b> : " + situation + "</html>"));
            }
            if (adCode != null && adName != null) {
                AbstractAction adLink = new AbstractAction("<html><b>Arodrome</b> :<font color=\"blue\">"
                        + adCode + " -- " + adName + "</font></html>") {
                    @Override
                    public void actionPerformed(ActionEvent arg0) {
                        getController().highlight(AIP.AERODROME, adCode);
                        ((ContextPanel) infosNavFix.getParent().getParent().getParent().getParent())
                                .showInfo(DatasManager.Type.AIP, AIP.AERODROME, adCode);
                    }
                };
                infosNavFix.add(adLink);
            }
            if (horCode != null) {
                infosNavFix.add(new JLabel("<html><b>Code horaire</b> : " + horCode + "</html>"));
            }
            if (usage != null) {
                infosNavFix.add(new JLabel("<html><b>Usage</b> : " + usage + "</html>"));
            }
            if (portee != null) {
                infosNavFix.add(new JLabel("<html><b>Porte</b> : " + portee + "</html>"));
            }
            if (flPortee != null) {
                infosNavFix.add(new JLabel("<html><b>Porte verticale</b> : FL" + flPortee + "</html>"));
            }
            if (couverture != null) {
                infosNavFix.add(new JLabel("<html><b>Couverture</b> : " + couverture + "</html>"));
            }
        }
    } else {
        infosNavFix.add(new JLabel("<html><i>Pas d'lments AIP</i></html>"));
    }
    taskPanesList.add(infosNavFix);
    return taskPanesList;
}

From source file:fr.crnan.videso3d.databases.aip.AIPContext.java

License:Open Source License

private List<JXTaskPane> showAirportInfos(int type, String name) {
    LinkedList<JXTaskPane> taskPanesList = new LinkedList<JXTaskPane>();
    final JXTaskPane infosGen = new JXTaskPane("Infos gnrales");
    JXTaskPane infosHor = new JXTaskPane("Horaires");
    JXTaskPane infosSvc = new JXTaskPane("Services");
    JXTaskPane infosMet = new JXTaskPane("Mto");
    JXTaskPane divers = new JXTaskPane("Divers");
    AIP aip = getController().getAIP();//  ww  w.jav  a 2  s  .  co  m

    int pkAd = -1;
    List<Integer> pkPistes = new LinkedList<Integer>();
    try {
        PreparedStatement ps = null;
        if (type == AIP.AERODROME) {
            ps = DatabaseManager.prepareStatement(DatasManager.Type.AIP,
                    "select pk from aerodromes where upper(code)=?");
            ps.setString(1, name.split("--")[0].trim());
            ResultSet rs = ps.executeQuery();
            pkAd = rs.getInt(1);
        } else {
            ps = DatabaseManager.prepareStatement(DatasManager.Type.AIP,
                    "select pk from aerodromes where nom = ?");
            ps.setString(1, name);
            ResultSet rs = ps.executeQuery();
            pkAd = rs.getInt(1);
        }
        ps = DatabaseManager.prepareStatement(DatasManager.Type.AIP, "select pk from runways where pk_ad = ?");
        ps.setInt(1, pkAd);
        ResultSet rs = ps.executeQuery();
        while (rs.next()) {
            pkPistes.add(rs.getInt(1));
        }
    } catch (SQLException e) {
        e.printStackTrace();
    }
    Element airportXML = aip.findElement(aip.getDocumentRoot().getChild("AdS"), "" + pkAd);
    if (airportXML != null) {
        for (Element e : (List<Element>) airportXML.getChildren()) {
            String nom = espacer(e.getName());
            String texte = e.getText().replaceAll("#", "<br/>");
            if (nom.startsWith("Ad")
                    && !(nom.equals("Ad Code") || nom.equals("Ad Ad2") || nom.equals("Ad Geo Und"))) {
                infosGen.add(new JLabel("<html><b>" + nom.substring(3) + "</b> : " + texte + "</html>"));
            } else if (nom.startsWith("Arp")) {
                infosGen.add(new JLabel("<html><b>" + nom.substring(4) + "</b> : " + texte + "</html>"));
            } else if (nom.startsWith("Tfc")) {
                infosGen.add(new JLabel("<html><b>" + nom + "</b> : " + texte + "</html>"));
            } else if (nom.equals("Ctr")) {
                String pkCTR = e.getAttributeValue("pk");
                Element espaceCTR = aip.findElement(aip.getDocumentRoot().getChild("EspaceS"), pkCTR);
                final String nomCTR = espaceCTR.getChildText("Nom");

                AbstractAction ctrAction = new AbstractAction(
                        "<html><b>CTR</b> :<font color=\"blue\">" + nomCTR + "</font></html>") {
                    @Override
                    public void actionPerformed(ActionEvent arg0) {
                        try {
                            Statement st = DatabaseManager.getCurrentAIP();
                            ResultSet rs = st
                                    .executeQuery("select nom from volumes where type ='CTR' and (nom LIKE '"
                                            + nomCTR + " %' OR nom ='" + nomCTR + "')");
                            String lastCTR = null;
                            while (rs.next()) {
                                lastCTR = rs.getString(1);
                                getController().showObject(AIP.CTR, lastCTR);
                            }
                            getController().highlight(AIP.CTR, lastCTR);
                        } catch (SQLException e1) {
                            e1.printStackTrace();
                        }
                    }
                };
                infosGen.add(ctrAction);
            } else if (nom.startsWith("Hor")) {
                infosHor.add(new JLabel(
                        "<html><b>" + nom.substring(4).replaceAll("Txt", "") + "</b> : " + texte + "</html>"));
            } else if (nom.startsWith("Svc")) {
                infosSvc.add(new JLabel("<html><b>" + nom.substring(4) + "</b> : " + texte + "</html>"));
            } else if (nom.startsWith("Sslia") || nom.startsWith("Neige")) {
                infosSvc.add(new JLabel("<html><b>" + nom + "</b> : " + texte + "</html>"));
            } else if (nom.startsWith("Met")) {
                infosMet.add(new JLabel("<html><b>" + nom.substring(4) + "</b> : " + texte + "</html>"));
            } else if (!(nom.startsWith("Ad") || nom.equals("Wgs84") || nom.equals("Geometrie")
                    || nom.equals("Territoire"))) {
                divers.add(new JLabel("<html><b>" + nom + "</b> : " + texte + "</html>"));
            }
        }
    }
    taskPanesList.add(infosGen);
    taskPanesList.add(infosHor);
    taskPanesList.add(infosSvc);
    taskPanesList.add(infosMet);
    taskPanesList.add(divers);

    for (JXTaskPane infos : taskPanesList) {
        if (infos.getContentPane().getComponentCount() == 0) {
            JLabel noInfo = new JLabel("<html><i>Aucune info.</i></html>");
            infos.add(noInfo);
        }
        infos.setCollapsed(true);
    }
    infosGen.setCollapsed(false);
    if (pkPistes.size() > 0) {
        for (int pkPiste : pkPistes) {
            Element pisteXML = aip.findElement(aip.getDocumentRoot().getChild("RwyS"), "" + pkPiste);
            String orientation = pisteXML.getChildText("Rwy");
            JXTaskPane piste = new JXTaskPane("Piste " + orientation);
            piste.add(new JLabel("<html><b><i>Gnralits</i></b><html>"));
            piste.add(new JLabel("\n"));
            piste.add(new JLabel("<html><b>Orientation :</b> " + orientation));

            List<JLabel> gen = new LinkedList<JLabel>();
            List<JLabel> dist = new LinkedList<JLabel>();
            List<JLabel> thr = new LinkedList<JLabel>();

            for (Element e : (List<Element>) pisteXML.getChildren()) {
                String nom = espacer(e.getName());
                String texte = e.getText().replaceAll("#", "<br/>");
                if (nom.contains("Thr")) {
                    thr.add(new JLabel("<html><b>" + nom + "</b> : " + texte));
                } else if (nom.contains("Cwy") || nom.contains("Swy") || nom.contains("Lda")
                        || nom.contains("Dist")) {
                    dist.add(new JLabel("<html><b>" + nom + "</b> : " + texte));
                } else if (!(nom.equals("Ad") || nom.equals("Rwy") || nom.equals("Geometrie")
                        || nom.equals("Extension"))) {
                    gen.add(new JLabel("<html><b>" + nom + "</b> : " + texte));
                }
            }
            for (JLabel jl : gen) {
                piste.add(jl);
            }
            piste.add(new JLabel("\n"));
            piste.add(new JLabel("<html><b><i>Distances</i></b><html>"));
            piste.add(new JLabel("\n"));
            for (JLabel jl : dist) {
                piste.add(jl);
            }
            piste.add(new JLabel("\n"));
            piste.add(new JLabel("<html><b><i>Coordonnes</i></b><html>"));
            piste.add(new JLabel("\n"));
            for (JLabel jl : thr) {
                piste.add(jl);
            }
            piste.setCollapsed(true);
            taskPanesList.add(piste);
        }
    }
    return taskPanesList;
}

From source file:fr.crnan.videso3d.databases.aip.AIPController.java

License:Open Source License

/**
 * Ajoute une route identifie par son nom et son type  la vue 3D. Si les points d'une route ne sont pas dfinis dans le fichier SIA,
 * on reprsente la route seulement par un point situ  48N, 0E .
 * @param routeName Le nom de la route  afficher.
 * @param type //from   w w w.ja  va 2  s .  c  o  m
 */
public void addRouteToLayer(String routeName, int type, boolean display) {
    String routeID = AIP.getID(type, routeName);
    Route.Space routeType;
    if (type == AIP.PDR) {
        routeType = Route.Space.UIR;
    } else {
        routeType = Route.Space.FIR;
    }
    try {
        String previousNavFix = null;
        PreparedStatement st = DatabaseManager.prepareStatement(DatasManager.Type.AIP,
                "select NavFix.nom from NavFix, routes where routes.pk = ? AND routes.navFixExtremite = NavFix.pk");
        st.setString(1, routeID);
        ResultSet rs = st.executeQuery();
        if (rs.next()) {
            previousNavFix = rs.getString(1);
        }
        st = DatabaseManager.prepareStatement(DatasManager.Type.AIP,
                "select segments.pk, NavFix.nom from segments, NavFix where pkRoute = ? AND NavFix.pk = segments.navFixExtremite ORDER BY sequence");
        st.setString(1, routeID);
        ResultSet segments = st.executeQuery();
        while (segments.next()) {
            Element segment = aip.findElement(aip.getDocumentRoot().getChild("SegmentS"),
                    segments.getString(1));
            String navFixExtremite = segments.getString(2);
            String segmentName = buildSegmentName(routeName, segment.getChildText("Sequence"));
            if (routes2D.getRoute(segmentName) == null) {
                if (!segment.getChildText("Circulation").equals("(XxX)")) {
                    routesSegments.addSegment(segmentName, previousNavFix, navFixExtremite, routeName, type,
                            Integer.parseInt(routeID), display);
                    previousNavFix = navFixExtremite;
                    Couple<Altitude, Altitude> altis = aip.getLevels(segment);
                    ArrayList<LatLon> loc = new ArrayList<LatLon>();
                    Geometrie geometrieSegment = new Geometrie(segment);
                    loc.addAll(geometrieSegment.getLocations());
                    if (loc.get(0) == null) {
                        loc.clear();
                        loc.add(LatLon.fromDegrees(48, 0));
                    }

                    DatabaseRoute2D segment2D = new DatabaseRoute2D(segmentName, routeType,
                            DatasManager.Type.AIP, type);
                    List<Integer> directions = new ArrayList<Integer>();
                    Parity sens = null;
                    String sensString = segment.getChildText("Circulation");
                    if (sensString.equals("(2=1)") || sensString.equals("(1=2)")
                            || sensString.equals("(0=0)")) {
                        sens = Parity.RED;
                        for (int i = 0; i < loc.size() - 1; i++) {
                            directions.add(Route2D.LEG_AUTHORIZED);
                        }
                    } else if (sensString.equals("(X-1)") || sensString.equals("(1-X)")) {
                        sens = Parity.GREEN;
                        for (int i = 0; i < loc.size() - 1; i++) {
                            if (i == loc.size() / 2)
                                directions.add(Route2D.LEG_DIRECT);
                            else
                                directions.add(Route2D.LEG_AUTHORIZED);
                        }
                    } else if (sensString.equals("(X-2)") || sensString.equals("(2-X)")
                            || sensString.equals("(X-0)")) {
                        sens = Parity.BLUE;
                        for (int i = 0; i < loc.size() - 1; i++) {
                            if (i == loc.size() / 2)
                                directions.add(Route2D.LEG_DIRECT);
                            else
                                directions.add(Route2D.LEG_AUTHORIZED);
                        }
                    }
                    segment2D.setParity(sens);
                    segment2D.setLocations(loc, directions);
                    segment2D.setAnnotation("<html>Route " + segmentName + "<br/><b>Plancher :</b>"
                            + altis.getFirst().getFullText() + "<br/><b>Plafond :</b>"
                            + altis.getSecond().getFullText() + "</html>");
                    routes2D.addRoute(segment2D, segmentName);

                    //TODO prendre en compte le sens de circulation pour les routes 3D... 
                    DatabaseRoute3D segment3D = new DatabaseRoute3D(segmentName, routeType,
                            DatasManager.Type.AIP, type);
                    segment3D.setLocations(loc);
                    boolean lowerTerrainConformant = false, upperTerrainConformant = false;
                    if (altis.getFirst().isTerrainConforming()) {
                        lowerTerrainConformant = true;
                    }
                    if (altis.getSecond().isTerrainConforming()) {
                        upperTerrainConformant = true;
                    }
                    segment3D.setParity(sens);
                    segment3D.setTerrainConforming(lowerTerrainConformant, upperTerrainConformant);
                    segment3D.setAltitudes(altis.getFirst().getMeters(), altis.getSecond().getMeters());
                    segment3D.setAnnotation("<html>Route " + segmentName + "<br/><b>Plancher :</b>"
                            + altis.getFirst().getFullText() + "<br/><b>Plafond :</b>"
                            + altis.getSecond().getFullText() + "</html>");
                    routes3D.addRoute(segment3D, segmentName);

                    if (display) {
                        routes3D.displayRoute(segmentName);
                        routes2D.displayRoute(segmentName);
                    }
                }
            }
        }
    } catch (SQLException e) {
        e.printStackTrace();
    }
}

From source file:fr.crnan.videso3d.databases.terrainsoaci.TerrainsOaci.java

License:Open Source License

@Override
protected void getFromFiles() throws IOException, SQLException {
    this.setFile("TerrainsOACI");
    this.setProgress(0);
    //      Ci dessous, le code qui permettait d'utiliser l'ancien format de fichier terrain OACI
    //      BufferedReader in = null;
    //      try{/*from  w w w. j  a  v  a  2s  . co m*/
    //         in = new BufferedReader(new InputStreamReader(new FileInputStream(this.path)));
    //         while (in.ready()){
    //            String line = in.readLine();
    //            if(line.matches("[A-Z]{4}  ([0-9]{2} ){3}[NS] [0-9]{3} ([0-9]{2} ){2}[EW].*")){
    //               insertTerrainOaci(line);
    //            }
    //         }
    //      } catch(IOException e){
    //         throw e;
    //      } finally{
    //         if(in != null)
    //            in.close();
    //      }
    try {
        List<Element> terrs = getDocumentRoot().getChildren();
        for (Element terr : terrs) {
            if (terr.getChildText("codeIcao") != null) { //certains terrains ne sont pas recenss par l'OACI
                insertTerrainOaci(terr);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    this.setProgress(1);
}

From source file:fr.crnan.videso3d.databases.terrainsoaci.TerrainsOaci.java

License:Open Source License

private void insertTerrainOaci(Element terr) throws SQLException {
    PreparedStatement insert = this.conn.prepareStatement(
            "insert into terrainsoaci (idoaci, idiata, name, type, country, city, latitude, longitude) "
                    + "values (?, ?, ?, ?, ?, ?, ?, ?)");
    insert.setString(1, terr.getChildText("codeIcao"));
    insert.setString(2, terr.getChildText("codeIata"));
    insert.setString(3, terr.getChildText("txtName"));
    insert.setString(4, terr.getChildText("codeType"));
    insert.setString(5, filterCountry(terr.getChild("Org").getChildText("txtName").replace("'", " "))); //suppression des apostrophes pour les requtes SQL
    insert.setString(6, terr.getChildText("txtNameCitySer"));
    String lati = terr.getChildText("geoLat").trim();
    String longi = terr.getChildText("geoLong").trim();
    Latitude lat = new Latitude(Integer.parseInt(lati.substring(0, 2)), Integer.parseInt(lati.substring(2, 4)),
            Integer.parseInt(lati.substring(4, 6)), lati.substring(6, 7));
    Longitude lon = new Longitude(Integer.parseInt(longi.substring(0, 3)),
            Integer.parseInt(longi.substring(3, 5)), Integer.parseInt(longi.substring(5, 7)),
            (longi.substring(7, 8).equalsIgnoreCase("W") ? "O" : "E"));
    insert.setDouble(7, lat.toDecimal());
    insert.setDouble(8, lon.toDecimal());
    insert.executeUpdate();//from w ww .j a  v a  2  s  .  co m
    insert.close();
}