Advertisement
Guest User

Untitled

a guest
Oct 31st, 2017
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 47.11 KB | None | 0 0
  1. package sk.tuke.tssu;
  2.  
  3.  
  4. import org.jsoup.Jsoup;
  5. import org.jsoup.nodes.Document;
  6. import org.jsoup.nodes.Element;
  7. import org.jsoup.select.Elements;
  8. //import org.openqa.selenium.WebElement;
  9. import java.io.IOException;
  10. import java.sql.*;
  11. import java.text.ParseException;
  12. import java.text.SimpleDateFormat;
  13. import java.util.ArrayList;
  14. import java.util.regex.Matcher;
  15. import java.util.regex.Pattern;
  16.  
  17.  
  18. public class Orsr {
  19.     private static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
  20.     private static final String DB_URL = "jdbc:mysql://localhost/";
  21.  
  22.     //  Database credentials
  23.     private static final String USER = "tssu";
  24.     private static final String PASS = "tssuuserPW";
  25.     private static ArrayList<Long> pouziteICO = new ArrayList<Long>();
  26.     private static MySQLAccess mySQLAccess;
  27.     private static int IdStatut = 0;
  28.  
  29.  
  30.     public static void main(String[] args) throws IOException, ParseException, InterruptedException {
  31.  
  32.         ArrayList<Long> icoList = new ArrayList<Long>();
  33.         Element row = null;
  34.         String html;
  35.         int i = 0;
  36.         Connection conn = null;
  37.         Statement stmt = null;
  38.         mySQLAccess = new MySQLAccess();
  39.         //ORSR
  40.         try {
  41.             //STEP 2: Register JDBC driver
  42.             Class.forName("com.mysql.jdbc.Driver");
  43.  
  44.             //STEP 3: Open a connection
  45.             System.out.println("Connecting to a selected database...");
  46.             conn = DriverManager.getConnection("jdbc:mysql://localhost/tssu?user=tssuuser&password=tssuuserPW&autoReconnect=true&useSSL=false");
  47.             System.out.println("Connected database successfully...");
  48.  
  49.             //STEP 4: Execute a query
  50.             System.out.println("Creating statement...");
  51.             stmt = conn.createStatement();
  52.  
  53.             String sql = "SELECT  ICO FROM tssu.faktura";
  54.             ResultSet rs = stmt.executeQuery(sql);
  55.             //STEP 5: Extract data from result set
  56.             while (rs.next()) {
  57.                 //Retrieve by column na
  58.                 long ico = rs.getLong("ICO");
  59.                 icoList.add(ico);
  60.                 //System.out.println(i+ " ICO: " + ico);
  61.                 i++;
  62.             }
  63.             rs.close();
  64.         } catch (Exception e) {
  65.             //Handle errors for Class.forName
  66.             e.printStackTrace();
  67.         } finally {
  68.             //finally block used to close resources
  69.             try {
  70.                 if (stmt != null)
  71.                     conn.close();
  72.             } catch (SQLException se) {
  73.             }// do nothing
  74.             try {
  75.                 if (conn != null)
  76.                     conn.close();
  77.             } catch (SQLException se) {
  78.                 se.printStackTrace();
  79.             }//end finally try
  80.         }//end try
  81.  
  82.         // System.out.println(icoList.size());
  83.         //--------------------------DOWNLOAD----------------------------------------
  84.  
  85.  
  86.         for (int j = 306; j < icoList.size(); j++) {
  87.             int count = 0;
  88.             System.out.println("***************************************************************************************");
  89.             System.out.println("Cislo faktury v cykle: " + j);
  90.  
  91.             if (j % 100 == 0) {
  92.                 System.out.println("Ideme spinkať...");
  93.                 Thread.sleep(2500);
  94.             }
  95.  
  96.  
  97.             ////////////////////////////////////////////////
  98.             ////////////tabulka dodavatel////////////////////
  99.             boolean isOZPZO = false;
  100.             String sidlo = null;
  101.             String denVymazu = null;
  102.             String denZapisu = null;
  103.             String obchodnéMeno = null;
  104.             String čisloDomu;
  105.             String pravnaForma = null;
  106.             String PSČ;
  107.  
  108.             String mesto;
  109.             String ulica;
  110.             String ico = String.valueOf(icoList.get(j));
  111.             ///////////////////////////////////////////////////
  112.  
  113.             ////////////////////////////////////////////////
  114.             ////////////tabulka statutarny organ////////////
  115.             String statutarnyOrgan = null;
  116.  
  117.  
  118.             ////////////////////////////////////////////////
  119.             ////////////TABULKA Predstavenstvo////////////
  120.             String predseda = null;
  121.             String podpredseda = null;
  122.             boolean isPodpredseda = false;
  123.             boolean isPredseda = false;
  124.  
  125.             ////////////////////////////////////////////////
  126.             ////////////tabulka clen////////////////////
  127.             ArrayList<String> vlastnici = new ArrayList<String>();
  128.             ArrayList<String> titulPredClena = new ArrayList<String>();
  129.             ArrayList<String> titulZaClena = new ArrayList<String>();
  130.             ArrayList<String> pscClena = new ArrayList<String>();
  131.             ArrayList<String> ulicaClena = new ArrayList<String>();
  132.             ArrayList<String> cisloDomuClen = new ArrayList<String>();
  133.             ArrayList<String> mestoClena = new ArrayList<String>();
  134.             ArrayList<String> menoClena = new ArrayList<String>();
  135.             ArrayList<String> priezviskoClena = new ArrayList<String>();
  136.             ArrayList<String> rolaClena = new ArrayList<String>();
  137.             ArrayList<String> odDatumClen = new ArrayList<String>();
  138.             ArrayList<String> doDatumClen = new ArrayList<String>();
  139.             ///////////////////////////////////////////////////
  140.  
  141.             ////////////////////////////////////////////////
  142.             ////////////tabulka konatel////////////////////
  143.             ArrayList<String> titulPredKonatel = new ArrayList<String>();
  144.             ArrayList<String> titulZaKonatel = new ArrayList<String>();
  145.             ArrayList<String> pscKonatel = new ArrayList<String>();
  146.             ArrayList<String> ulicaKonatel = new ArrayList<String>();
  147.             ArrayList<String> cisloDomuKonatel = new ArrayList<String>();
  148.             ArrayList<String> mestoKonatel = new ArrayList<String>();
  149.             ArrayList<String> menoKonatel = new ArrayList<String>();
  150.             ArrayList<String> priezviskoKonatel = new ArrayList<String>();
  151.             ArrayList<String> rolaKonatel = new ArrayList<String>();
  152.             ArrayList<String> odDatumKonatel = new ArrayList<String>();
  153.             ArrayList<String> doDatumKonatel = new ArrayList<String>();
  154.             ///////////////////////////////////////////////////
  155.  
  156.             ///////////////////////////////////////////////
  157.  
  158.             ico = ico.replaceAll(" ", "");
  159.  
  160.             String url = "http://orsr.sk/hladaj_ico.asp?ICO=+" + ico;
  161.             //  System.out.println("Adresa pre URL PRE HLADANIE:" + url);
  162.  
  163.             Document document = Jsoup.connect(url).get();
  164.             Elements links = document.select("a[href]");
  165.             String[] urls = new String[links.size()];
  166.  
  167.             for (i = 0; i < links.size(); i++) {
  168.                 urls[i] = links.get(i).attr("href");
  169.             }
  170.  
  171.             url = "http://orsr.sk/" + urls[8];
  172.             Pattern p = Pattern.compile("&P=1");
  173.             Matcher m = p.matcher(url);
  174.             if (m.find()) {
  175.                 System.out.println("Adresa pre URL PRE DETAIL:" + url);
  176.                 // System.out.println("=========================");
  177.  
  178.                 document = Jsoup.connect(url).get();
  179.                 int tableSize = document.select("table").size();
  180.                 Element table = null;
  181.                 Elements rows = null;
  182.                 int helpName = 0;
  183.  
  184.                 for (int l = 0; l < tableSize - 1; l++) {
  185.                     table = document.select("table").get(l);
  186.                     rows = table.select("tr");
  187.                     p = Pattern.compile("Obchodné meno");   ///menil som :
  188.                     m = p.matcher(rows.toString());
  189.                     if (m.find()) {
  190.                         helpName = l;
  191.                         break;
  192.                     }
  193.                 }
  194.  
  195.                 table = document.select("table").get(helpName);
  196.                 rows = table.select("tr");
  197.                 p = Pattern.compile("Obchodné meno");    //menil som
  198.                 m = p.matcher(rows.toString());
  199.  
  200.                 if (m.find()) {
  201.                     row = rows.get(1);
  202.                     Elements cols = row.select("td");
  203.                     Element col = cols.get(0);
  204.                     obchodnéMeno = col.toString();
  205.                     obchodnéMeno = obchodnéMeno.replaceAll("<[^>]*>", "");
  206.                     //  System.out.println("Obchodné meno: " + obchodnéMeno);
  207.                 } else {
  208.                     isOZPZO = true;
  209.                     row = rows.get(1);
  210.                     Elements cols = row.select("td");
  211.                     Element col = cols.get(0);
  212.                     obchodnéMeno = col.toString();
  213.                     obchodnéMeno = obchodnéMeno.replaceAll("<[^>]*>", "");
  214.                     //   System.out.println("Obchodné meno: " + obchodnéMeno);
  215.                 }
  216.  
  217.                 ///////////////////////vlozenie obchodneho mena do tabulky dodavatel
  218.  
  219.                 int helpSidlo = 0;
  220.                 int helpDenZapisu = 0;
  221.                 int helpDenVymazu = 0;
  222.                 int helpPravnaForma = 0;
  223.                 int helpStatutarnyOrgan = 0;
  224.  
  225.                 for (int l = 0; l < tableSize - 1; l++) {
  226.                     table = document.select("table").get(l);//7
  227.                     rows = table.select("tr");
  228.                     for (int n = 0; n < rows.size(); n++) {
  229.                         row = rows.get(n);
  230.                         p = Pattern.compile("Sídlo:");
  231.                         m = p.matcher(row.toString());
  232.                         if (m.find()) {
  233.                             helpSidlo = n;
  234.                             tableSize = 0;
  235.                             break;
  236.                         }
  237.                         p = Pattern.compile("Miesto podnikania:");
  238.                         m = p.matcher(row.toString());
  239.                         if (m.find()) {
  240.                             helpSidlo = n;
  241.                             tableSize = 0;
  242.                             break;
  243.                         }
  244.                         p = Pattern.compile("Sídlo organizačnej zložky:");
  245.                         m = p.matcher(row.toString());
  246.                         if (m.find()) {
  247.                             helpSidlo = n;
  248.                             tableSize = 0;
  249.                             break;
  250.                         }
  251.                     }
  252.  
  253.  
  254.                 }
  255.                 m = p.matcher(row.toString());
  256.                 row = rows.get(helpSidlo);
  257.                 if (m.find())
  258.                     row = rows.get(helpSidlo + 1);
  259.  
  260.                 Elements cols = row.select("td");
  261.                 Element col = cols.get(0);
  262.                 sidlo = col.toString();
  263.                 //sidlo = sidlo.replaceAll("<[^>]*>", "");
  264.  
  265.                 ArrayList<String> rozdelenaAdresa = rozdelAdresuVlastnika(sidlo);
  266.  
  267.                 ulica = rozdelenaAdresa.get(0).trim();
  268.                 čisloDomu = rozdelenaAdresa.get(1).trim();
  269.                 mesto = rozdelenaAdresa.get(2).trim();
  270.                 PSČ = rozdelenaAdresa.get(3).trim();
  271.  
  272.                 /////////////////////////vlozenie adresy do tabulky dodavatel
  273.  
  274.                 tableSize = document.select("table").size();
  275.  
  276.                 for (int l = 7; l < tableSize - 1; l++) {
  277.                     table = document.select("table").get(l);//7
  278.                     rows = table.select("tr");
  279.                     for (int n = 0; n < rows.size(); n++) {
  280.                         row = rows.get(n);
  281.                         p = Pattern.compile("Deň zápisu:");
  282.                         m = p.matcher(row.toString());
  283.                         if (m.find()) {
  284.                             helpDenZapisu = n;
  285.                             tableSize = 0;
  286.                             break;
  287.                         }
  288.                     }
  289.                 }
  290.                 row = rows.get(helpDenZapisu);
  291.                 m = p.matcher(row.toString());
  292.                 if (m.find())
  293.                     row = rows.get(helpDenZapisu + 1);
  294.                 cols = row.select("td");
  295.                 col = cols.get(0);
  296.                 denZapisu = col.toString();
  297.                 denZapisu = denZapisu.replaceAll("<[^>]*>", "");
  298.                 //   System.out.println("Den zápisu: " + denZapisu);
  299.                 ///////////vlozenie dna zapisu dodavatel
  300.                 // System.out.println("---------------------");
  301.  
  302.                 tableSize = document.select("table").size();
  303.  
  304.                 for (int l = 9; l < tableSize - 1; l++) {
  305.                     table = document.select("table").get(l);
  306.                     rows = table.select("tr");
  307.                     for (int n = 0; n < rows.size(); n++) {
  308.                         row = rows.get(n);
  309.                         p = Pattern.compile("Právna forma:");
  310.                         m = p.matcher(row.toString());
  311.                         if (m.find()) {
  312.                             helpPravnaForma = n;
  313.                             tableSize = 0;
  314.                             break;
  315.                         }
  316.                     }
  317.                 }
  318.                 row = rows.get(helpPravnaForma);
  319.                 m = p.matcher(row.toString());
  320.                 if (m.find())
  321.                     row = rows.get(helpPravnaForma + 1);
  322.                 cols = row.select("td");
  323.                 col = cols.get(0);
  324.                 pravnaForma = col.toString();
  325.                 pravnaForma = pravnaForma.replaceAll("<[^>]*>", "");
  326.                 //  System.out.println("Právna forma: " + pravnaForma);
  327.                 ////////////////vlozenie pravnej formy
  328.                 //   System.out.println("=================================================================================================");
  329.  
  330.  
  331.                 tableSize = document.select("table").size();
  332.                 int tableNum = 0;
  333.                 for (int l = 10; l < tableSize - 1; l++) {
  334.                     table = document.select("table").get(l);
  335.                     rows = table.select("tr");
  336.                     for (int n = 0; n < rows.size(); n++) {
  337.                         row = rows.get(n);
  338.                         p = Pattern.compile("Štatutárny orgán:");
  339.                         m = p.matcher(row.toString());
  340.                         Pattern p2 = Pattern.compile("Vedúci organizačnej zložky:");
  341.                         Matcher m2 = p2.matcher(row.toString());
  342.                         if (m.find()) {
  343.                             helpStatutarnyOrgan = n;
  344.                             tableNum = l;
  345.                             tableSize = 0;
  346.                             break;
  347.                         } else if (m2.find()) {
  348.                             helpStatutarnyOrgan = n;
  349.                             tableNum = l;
  350.                             tableSize = 0;
  351.                             break;
  352.                         }
  353.                     }
  354.                 }
  355.                 row = rows.get(helpStatutarnyOrgan);
  356.                 m = p.matcher(row.toString());
  357.                 if (m.find())
  358.                     row = rows.get(helpStatutarnyOrgan + 1);
  359.                 cols = row.select("td");
  360.                 col = cols.get(0);
  361.                 statutarnyOrgan = col.toString();
  362.                 statutarnyOrgan = statutarnyOrgan.replaceAll("<[^>]*>", "");
  363.  
  364.  
  365.                 //  System.out.println("Štatutárny orgán: " + statutarnyOrgan);
  366.                 ///////////////////vlozenie statutarny organ
  367.                 //   System.out.println("=================================================================================================");
  368.  
  369.                 p = Pattern.compile("Samostatne podnikajúca fyzická osoba");
  370.                 m = p.matcher(pravnaForma);
  371.                 if (m.find() || isOZPZO == true) {
  372.                     statutarnyOrgan = null;
  373.                 }
  374.  
  375.                 //-----------ČLENOVIA------------------------
  376.                 table = document.select("table").get(tableNum);
  377.                 rows = table.select("tr");
  378.                 p = Pattern.compile("Samostatne podnikajúca fyzická osoba");
  379.                 m = p.matcher(pravnaForma);
  380.                 if (!m.find()) {
  381.  
  382.  
  383.                     for (int n = 1; n < rows.size(); n++) {
  384.                         if (isPredstavenstvo(rows)) {
  385.                             row = rows.get(n);
  386.                             p = Pattern.compile("predstavenstvo");
  387.                             m = p.matcher(row.toString());
  388.                             p = Pattern.compile("konatelia");
  389.                             Matcher matcher = p.matcher(row.toString());
  390.                             if (!m.find()) {
  391.                                 if (!matcher.find()) {
  392.                                     cols = row.select("td");
  393.                                     col = cols.get(0);
  394.                                     String vlastnik = col.toString();
  395.                                     p = Pattern.compile("-");
  396.                                     m = p.matcher(row.toString());
  397.                                     if (m.find()) {
  398.                                         Pattern p1 = Pattern.compile("predstavenstvo");
  399.                                         Matcher m1 = p1.matcher(vlastnik);
  400.                                         //Pattern p2 = Pattern.compile("konatelia");
  401.                                         //Matcher m2 = p2.matcher(vlastnik);
  402.                                         if (!m1.find()) {
  403.  
  404.                                         //    System.out.println("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
  405.  
  406.                                             ArrayList<String> rozdeleneMenoClena = rozdelMenoATituly(oddelPredstavitelov(vlastnik).get(0)); //vracia meno rozdelene na tituly a mena
  407.                                             vlastnici.add(oddelPredstavitelov(vlastnik).get(0).replaceAll("<[^>]*>", ""));
  408.                                             //spúšťa rozdelenie adresy vlastníka, ktorá vracia rozdelenú adresu
  409.                                             //ArrayList<String> rozdeleneMenoClena = rozdelMenoATituly(vlastnici.get(count));
  410.                                             titulPredClena.add(rozdeleneMenoClena.get(0).replaceAll("<[^>]*>", ""));
  411.                                             menoClena.add(rozdeleneMenoClena.get(1).replaceAll("<[^>]*>", ""));
  412.                                             priezviskoClena.add(rozdeleneMenoClena.get(2).replaceAll("<[^>]*>", ""));
  413.                                             titulZaClena.add(rozdeleneMenoClena.get(3).replaceAll("<[^>]*>", ""));
  414.  
  415.                                             ArrayList<String> rozdelenaAdresaClena = oddelPredstavitelov(vlastnik);
  416.                                             if (rozdelenaAdresaClena.size() > 5) {
  417.                                                 ulicaClena.add(rozdelenaAdresaClena.get(2).replaceAll("<[^>]*>", ""));
  418.                                                 cisloDomuClen.add(rozdelenaAdresaClena.get(3).replaceAll("<[^>]*>", ""));
  419.                                                 mestoClena.add(rozdelenaAdresaClena.get(4).replaceAll("<[^>]*>", ""));
  420.                                                 pscClena.add(rozdelenaAdresaClena.get(5).replaceAll("<[^>]*>", ""));
  421.                                             }
  422.  
  423.  
  424.                                             rozdelenaAdresaClena.clear();
  425.                                             rozdeleneMenoClena.clear();
  426.  
  427.                                             p1 = Pattern.compile("člen");
  428.                                             Pattern p2 = Pattern.compile("predseda");
  429.                                             m1 = p1.matcher(vlastnik);
  430.                                             Matcher m2 = p2.matcher(vlastnik);
  431.                                             if (!m.find() && !m2.find())
  432.                                                 rolaClena.add("člen");
  433.  
  434.                                             else {
  435.                                                 rolaClena.add(oddelPredstavitelov(vlastnik).get(1).replaceAll("<[^>]*>", "").replaceAll("-", ""));
  436.                                             }
  437.  
  438.                                             if (isPodpredseda == false) {
  439.                                                 Pattern pattern = Pattern.compile("podpredseda");
  440.                                                 Matcher matcher1 = pattern.matcher(rolaClena.get(count));
  441.                                                 if (matcher1.find()) {
  442.                                                     podpredseda = vlastnici.get(count);
  443.                                                     isPodpredseda = true;
  444.                                                 }
  445.                                             }
  446.                                             if (isPredseda == false) {
  447.                                                 Pattern pattern = Pattern.compile("predseda");
  448.                                                 Matcher matcher1 = pattern.matcher(rolaClena.get(count));
  449.                                                 if (matcher1.find()) {
  450.                                                     predseda = vlastnici.get(count);
  451.                                                     isPredseda = true;
  452.                                                 }
  453.                                             }
  454.  
  455.                                         }
  456.                                     } else {
  457.  
  458.                                         rozdelMenoATituly(oddelVlastnikov(vlastnik).get(0));
  459.                                         vlastnici.add(oddelVlastnikov(vlastnik).get(0).replaceAll("<[^>]*>", ""));
  460.  
  461.                                         rolaClena.add("člen");
  462.  
  463.                                     }
  464.  
  465.                                     col = cols.get(1);
  466.                                     String datumy = col.toString();
  467.                                     datumy = datumy.replaceAll("<[^>]*>", "");
  468.                                     datumy = datumy.replaceAll("&nbsp;", "");
  469.                                     datumy = datumy.replaceAll("od:", "");
  470.                                     p = Pattern.compile("do");
  471.                                     m = p.matcher(datumy);
  472.                                     if (m.find()) {
  473.                                         odDatumClen.add(oddeldatum(datumy).get(0));
  474.                                         doDatumClen.add(oddeldatum(datumy).get(1));
  475.                                     } else {
  476.                                         odDatumClen.add(datumy);
  477.                                         doDatumClen.add(null);
  478.  
  479.  
  480.                                     }
  481.  
  482.  
  483.                                 //    System.out.println("Pozicia vlastnika: " + rolaClena.get(count));
  484.                                 //    System.out.println("Datum od: " + editDate(odDatumClen.get(count).replaceAll("[(\\|)]", "").trim()));
  485.  
  486.  
  487.                                     if (doDatumClen.get(count) == null) {
  488.  
  489.                                   //      System.out.println("Dátum do: Este aktualne");
  490.                                     } else {
  491.                                    //     System.out.println("Dátum do: " + editDate(doDatumClen.get(count).replaceAll("[(\\|)]", "")));
  492.                                     }
  493.                            //         System.out.println("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
  494.                                     count++;
  495.                                 }
  496.                             }
  497.                         } else {
  498.                             row = rows.get(n);
  499.                             cols = row.select("td");
  500.                             col = cols.get(0);
  501.                             String vlastnik = col.toString();
  502.                             Pattern p1 = Pattern.compile("konateľ");
  503.                             Matcher m1 = p1.matcher(vlastnik);
  504.                             Pattern p2 = Pattern.compile("konatelia");
  505.                             Matcher m2 = p2.matcher(vlastnik);
  506.                             if (!m1.find() && !m2.find()) {
  507.  
  508.  
  509.                                 vlastnici.add(oddelVlastnikov(vlastnik).get(0).replaceAll("<[^>]*>", ""));
  510.  
  511.                                 // ulicaVlastnika.add(oddelVlastnikov(vlastnik).get(1));
  512.                                 //cisloDomuVlastnika.add(oddelVlastnikov(vlastnik).get(2));
  513.                                 //mestoVlastnika.add(oddelVlastnikov(vlastnik).get(3));
  514.                                 //pscVlastnika.add(oddelVlastnikov(vlastnik).get(4));
  515.  
  516.                             }
  517.                             col = cols.get(1);
  518.                             String datumy = col.toString();
  519.                             datumy = datumy.replaceAll("<[^>]*>", "");
  520.                             datumy = datumy.replaceAll("&nbsp;", "");
  521.                             datumy = datumy.replaceAll("od:", "");
  522.                             datumy = datumy.replaceAll("\\(:", "");
  523.  
  524.                             p = Pattern.compile("do");
  525.                             m = p.matcher(datumy);
  526.  
  527.                             if (m.find()) {
  528.                                 odDatumKonatel.add(oddeldatum(datumy).get(0));
  529.                                 doDatumKonatel.add(oddeldatum(datumy).get(1));
  530.                             } else {
  531.                                 odDatumKonatel.add(datumy);
  532.                                 doDatumKonatel.add(null);
  533.  
  534.  
  535.                             }
  536.  
  537.                             //    System.out.println("Datum od:" + editDate(odDatumKonatel.get(count).replaceAll("[(\\|)]", "")));
  538.  
  539.                             if (doDatumKonatel.get(count) == null) {
  540.  
  541.                                 //     System.out.println(" Este aktualne");
  542.                             } else {
  543.                                 //       System.out.println("Dátum do: " + editDate(doDatum.get(count).replaceAll("[(\\|)]", "")));
  544.                             }
  545.                             //System.out.println("Vlstníci: " + vlastnici.get(count));
  546.  
  547.                             count++;
  548.                         }
  549.                     }
  550.                 }
  551.  
  552.                 tableSize = document.select("table").size();
  553.  
  554.                 for (int l = 10; l < tableSize - 1; l++) {
  555.                     table = document.select("table").get(l);
  556.                     rows = table.select("tr");
  557.                     for (int n = 0; n < rows.size(); n++) {
  558.                         row = rows.get(n);
  559.                         p = Pattern.compile("Deň výmazu:");
  560.                         m = p.matcher(row.toString());
  561.                         if (m.find()) {
  562.                             helpDenVymazu = n;
  563.                             tableSize = 0;
  564.                             row = rows.get(helpDenVymazu);
  565.                             m = p.matcher(row.toString());
  566.                             if (m.find())
  567.                                 row = rows.get(helpDenVymazu + 1);
  568.                             cols = row.select("td");
  569.                             col = cols.get(0);
  570.                             denVymazu = col.toString();
  571.                             denVymazu = denVymazu.replaceAll("<[^>]*>", "");
  572.                             break;
  573.                         }
  574.  
  575.                     }
  576.                     if (l == tableSize)
  577.                         denVymazu = null;
  578.                 }
  579.  
  580.                 ///////////////////////////////////////////////////////////////////////////////////////////////
  581.                 ////////////////////////////////////////tu sa bude vkladat//////////////////////////////////////
  582.                 ///////////////////////////////////////////////////////////////////////////////////////////////
  583.  
  584.               /*  System.out.println("__________________________________________Tabulka Dodavatel___________________________________________");
  585.                 if (denVymazu == null) {
  586.                     System.out.println("Obchodne meno: " + obchodnéMeno + " |ICO: " + ico + " |Zapis: " + editDate(denZapisu.replaceAll("[(\\|)]", "")) + " |Vymaz:*******|");
  587.                 } else {
  588.                     System.out.println("Obchodne meno: " + obchodnéMeno + " |ICO: " + ico + " |Zapis: " + editDate(denZapisu.replaceAll("[(\\|)]", "")) + " |Vymaz:" + editDate(denVymazu.replaceAll("[(\\|)]", "")));
  589.                 }
  590.                 System.out.println("Právna forma: " + pravnaForma.trim().replaceAll("\\.", "") + " |Ulica: " + ulica + " |CD: " + čisloDomu + " |PSC: " + PSČ + " |Mesto: " + mesto);
  591.                 System.out.println("______________________________________________________________________________________________________");
  592.                 System.out.println("__________________________________________Statutarny Ogan_____________________________________________");
  593.  
  594.                 if (pravnaForma.trim().equals("Samostatne podnikajúca fyzická osoba")) {
  595.                     statutarnyOrgan = "Živnostník";
  596.                 } else if (pravnaForma.trim().equals("Organizačná zložka podniku zahraničnej osoby.")) {
  597.                     statutarnyOrgan = "Zahraničná osoba";
  598.                 }
  599.                 System.out.println("ICO: " + ico + " |Typ: " + statutarnyOrgan.trim() + " |ID: " + IdStatut);
  600.                 System.out.println("______________________________________________________________________________________________________");
  601.  
  602.  
  603.                 if (statutarnyOrgan.equals("Živnostník")) {
  604.                     System.out.println("__________________________________________Zivnostnik______________________________________________");
  605.  
  606.                     System.out.println("Meno: " + "|Priezvisko: " + "|TitulPred: " + "|TitulZa: " + "|Ulica: " + "|CD: " + "|PSC: " + "|Mesto: " + "|DatumPriradenia: " + "|DatumUkoncenia: " + "|IDStatutOrganu: " + IdStatut);
  607.  
  608.                     System.out.println("__________________________________________________________________________________________________");
  609.                 } else if (pravnaForma.trim().equals("Akciová spoločnosť")) {
  610.                     System.out.println("__________________________________________Predstavenstvo__________________________________________");
  611.                     if (predseda != null)
  612.                         predseda.trim();
  613.                     if (predseda != null)
  614.                         podpredseda.trim();
  615.                     System.out.println("Predseda: " + predseda + "|Podpredseda: " + podpredseda + " |ID: " + IdStatut);
  616.                     //kazdeho clena este
  617.                     System.out.println("__________________________________________________________________________________________________");*/
  618.  
  619.                     System.out.println("__________________________________________Tabuľka člen__________________________________________");
  620.                     for (int clen = 0; i == count; clen++) {
  621.                         System.out.println("Tituly pred: "
  622.                                 + titulPredClena.get(clen).trim() +
  623.                                 "|Meno: " + menoClena.get(clen).trim() +
  624.                                 "|Priezvisko: " + priezviskoClena.get(clen).trim()
  625.                                 + "|Tituly za: " + titulZaClena.get(clen).trim());
  626.                         System.out.println("Rola: " + rolaClena.get(clen).trim() + "|Ulica: " + ulicaClena.get(clen).trim() + "|CD: " + cisloDomuClen.get(clen).trim() +
  627.                                 "|Mesto: " + mestoClena.get(clen).trim() + "|PSČ: " + pscClena.get(clen).trim());
  628.                         System.out.println("Dátum priradenia: " + odDatumClen.get(clen) + "|Dátum ukončenia: " + doDatumClen.get(clen) + "|Id: CHÝBA PREMENNÁ");
  629.                     }
  630.  
  631.                     System.out.println("__________________________________________________________________________________________________");
  632. /*
  633.                 } else if (pravnaForma.trim().equals("Spoločnosť s ručením obmedzeným")) {
  634.                     System.out.println("__________________________________________Konatel_________________________________________________");
  635.  
  636.                     //kazdeho konatela
  637.  
  638.                     System.out.println("__________________________________________________________________________________________________");
  639.                 } else if (statutarnyOrgan.trim().equals("Zahraničná osoba")) {
  640.                     System.out.println("__________________________________________Zahranicna osoba________________________________________");
  641.  
  642.                     System.out.println("Meno: " + "|Priezvisko: " + "|TitulPred: " + "|TitulZa: " + "|Ulica: " + "|CD: " + "|PSC: " + "|Mesto: " + "|DatumPriradenia: " + "|DatumUkoncenia: " + "|IDStatutOrganu: " + IdStatut);
  643.  
  644.                     System.out.println("__________________________________________________________________________________________________");
  645.                 } else {
  646.                     System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!NOVY STATUTARNY ORGAN!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
  647.                 }*/
  648.  
  649.  
  650.             } else {
  651.                 System.out.println("Nenašlo sa IČO...");
  652.             }
  653.  
  654.             IdStatut++;
  655.  
  656.         }
  657.  
  658.     }
  659.  
  660.     private static ArrayList<String> rozdelAdresuVlastnika(String adresa) {
  661.         ArrayList<String> rozdelene = new ArrayList<>();
  662.  
  663.         //0 - ulica
  664.         //1 - cislo
  665.         //2 - mesto
  666.         //3 - psc
  667.  
  668.         char[] buff = adresa.toCharArray();
  669.         ArrayList<String> pomocnePole = new ArrayList<>();   //pole, kde si rozdelim data medzi '> <'
  670.         // System.out.println(adresa);
  671.         int pos1 = 0;
  672.         int pos2 = 0;
  673.  
  674.         // System.out.println("_______________________________________");
  675.         for (int i = 0; i < buff.length; i++) {
  676.             if (pos1 != 0 && pos2 != 0 && pos1 < pos2) {
  677.  
  678.                 if (adresa.substring(pos1 + 1, pos2).length() > 2) {   //kvoli htmltagom kde su medzeri medzi nimi len
  679.                     pomocnePole.add(adresa.substring(pos1 + 1, pos2));
  680.                     //  System.out.println(pomocnePole.size() - 1 + "    " + adresa.substring(pos1 + 1, pos2));
  681.                     pos1 = 0;
  682.                     pos2 = 0;
  683.                 }
  684.             }
  685.  
  686.             if (buff[i] == '>') {
  687.                 pos1 = i;
  688.             }
  689.  
  690.             if (buff[i] == '<') {
  691.                 pos2 = i;
  692.             }
  693.         }
  694.         //  System.out.println("_______________________________________");
  695.  
  696.  
  697.         switch (pomocnePole.size()) {
  698.             case 3: {                    //ulica, cislo ulice, mesto
  699.                 rozdelene.add(pomocnePole.get(0));
  700.                 rozdelene.add(pomocnePole.get(1));
  701.                 rozdelene.add(pomocnePole.get(2));
  702.                 rozdelene.add("XXXXX");
  703.                 break;
  704.             }
  705.             case 4: {                    //ulica, cislo ulice, mesto,psc
  706.  
  707.                 char[] pom2 = pomocnePole.get(0).trim().toCharArray();   //pre pripad ked zacina sa to cislom domu lbo dedina nema ulice, tak ulicu nastavim taku ako nazov dediny
  708.                 if (Character.isDigit(pom2[0])) {
  709.                     rozdelene.add(pomocnePole.get(1));  //ulica ako dedina
  710.                     rozdelene.add(pomocnePole.get(0));  //cd ktore bolo na zaciatku
  711.                     rozdelene.add(pomocnePole.get(1));  //mesto
  712.                     rozdelene.add(pomocnePole.get(2));  //psc
  713.                 } else {
  714.                     rozdelene.add((pomocnePole.get(0)));
  715.                     rozdelene.add(pomocnePole.get(1));
  716.                     rozdelene.add(pomocnePole.get(2));
  717.                     if (pomocnePole.get(3) != null) {
  718.                         char[] pom = pomocnePole.get(3).toCharArray();
  719.                         if (Character.isAlphabetic(pom[3])) {
  720.                             rozdelene.add("XXXXX");
  721.                         } else
  722.                             rozdelene.add((pomocnePole.get(3)));
  723.                     } else
  724.                         rozdelene.add("XXXXX");
  725.                 }
  726.                 break;
  727.             }
  728.             case 5: {                    //ulica, cislo ulice, mesto,psc
  729.                 rozdelene.add((pomocnePole.get(0)));
  730.                 rozdelene.add(pomocnePole.get(1));
  731.                 rozdelene.add(pomocnePole.get(2));
  732.  
  733.                 if (pomocnePole.get(3) != null) {
  734.                     char[] pom = pomocnePole.get(3).trim().toCharArray();
  735.                     if (Character.isAlphabetic(pom[3])) {    //daktore nemusia mat 4 pismenka
  736.                         rozdelene.add("XXXXX");
  737.                     } else
  738.                         rozdelene.add((pomocnePole.get(3)));
  739.                 } else
  740.                     rozdelene.add("XXXXX");
  741.  
  742.                 break;
  743.             }
  744.             case 6: {                    //ulica, cislo ulice, mesto,psc
  745.                 rozdelene.add((pomocnePole.get(0)));
  746.                 rozdelene.add(pomocnePole.get(1));
  747.                 rozdelene.add(pomocnePole.get(2));
  748.                 if (pomocnePole.get(3) != null) {
  749.                     char[] pom = pomocnePole.get(3).toCharArray();
  750.                     if (Character.isAlphabetic(pom[3])) {
  751.                         rozdelene.add("XXXXX");
  752.                     } else
  753.                         rozdelene.add((pomocnePole.get(3)));
  754.                 } else
  755.                     rozdelene.add("XXXXX");
  756.                 break;
  757.             }
  758.             case 7: {                    //ulica, cislo ulice, mesto,psc
  759.                 rozdelene.add((pomocnePole.get(0)));
  760.                 rozdelene.add(pomocnePole.get(1));
  761.                 rozdelene.add(pomocnePole.get(2));
  762.                 if (pomocnePole.get(3) != null) {
  763.                     char[] pom = pomocnePole.get(3).toCharArray();
  764.                     if (Character.isAlphabetic(pom[3])) {
  765.                         rozdelene.add("XXXXX");
  766.                     } else
  767.                         rozdelene.add((pomocnePole.get(3)));
  768.                 } else
  769.                     rozdelene.add("XXXXX");
  770.                 break;
  771.             }
  772.             case 8: {                    //ulica, cislo ulice, mesto,psc
  773.                 rozdelene.add((pomocnePole.get(0)));
  774.                 rozdelene.add(pomocnePole.get(1));
  775.                 rozdelene.add(pomocnePole.get(2));
  776.  
  777.                 if (pomocnePole.get(3) != null) {
  778.                     char[] pom = pomocnePole.get(3).toCharArray();
  779.                     if (Character.isAlphabetic(pom[3])) {
  780.                         rozdelene.add("XXXXX");
  781.                     } else {
  782.                         rozdelene.add((pomocnePole.get(3)));
  783.                     }
  784.                 } else {
  785.                     rozdelene.add("XXXXX");
  786.                 }
  787.                 break;
  788.             }
  789.             default: {
  790.                 //   System.out.println(pomocnePole.size());
  791.                 rozdelene.add(" ");
  792.                 rozdelene.add(" ");
  793.                 rozdelene.add(" ");
  794.                 rozdelene.add(" ");
  795.                 break;
  796.             }
  797.  
  798.         }
  799.      /*  System.out.println("_____________________________________________________");
  800.         System.out.println("Ulica: " + rozdelene.get(0));
  801.         System.out.println("Čislo: " + rozdelene.get(1));
  802.         System.out.println("Mesto: " + rozdelene.get(2));
  803.         System.out.println("PSČ: " + rozdelene.get(3));
  804.         System.out.println(pomocnePole.size());
  805.         System.out.println("_____________________________________________________");*/
  806.  
  807.         return rozdelene;
  808.     }
  809.  
  810.     private static ArrayList<String> oddelPredstavitelov(String predstavitel) {
  811.         ArrayList<String> rozdeleniePredstavitelov = new ArrayList<String>();
  812.  
  813.         if (predstavitel != null) {
  814.             char[] buff = predstavitel.toCharArray();
  815.             int medzera = 0;
  816.             String pom = "";
  817.  
  818.             for (int i = 0; i <= buff.length; i++) {
  819.  
  820.  
  821.                 if (medzera == 0 && buff[i] == '<' && buff[i + 1] == 'b' && buff[i + 2] == 'r' && buff[i + 3] == '>') {
  822.                     pom = pom.replaceAll("td width=\"67%\">", "");
  823.                     Pattern p = Pattern.compile("člen");
  824.                     Pattern p2 = Pattern.compile("predseda");
  825.                     Matcher m = p.matcher(pom);
  826.                     Matcher m2 = p2.matcher(pom);
  827.                     if (!m.find() && !m2.find())
  828.                         pom = "člen";
  829.                     rozdeleniePredstavitelov.add(pom);
  830.                     // System.out.println(pom);
  831.                     pom = "";
  832.                     medzera++;
  833.                 }
  834.  
  835.                 if (buff[i] == '-' && buff[i + 1] == ' ') {     //lebo moze v mene byt -
  836.                     pom = pom.replaceAll("td width=\"67%\">", "");
  837.                     pom = pom.replaceAll("- ", "");
  838.                     rozdeleniePredstavitelov.add(pom);
  839.                     pom = "";
  840.                 }
  841.                 if (i == buff.length - 1) {
  842.                     rozdeleniePredstavitelov.add(rozdelAdresuVlastnika(pom).get(0));
  843.                     rozdeleniePredstavitelov.add(rozdelAdresuVlastnika(pom).get(1));
  844.                     rozdeleniePredstavitelov.add(rozdelAdresuVlastnika(pom).get(2));
  845.                     rozdeleniePredstavitelov.add(rozdelAdresuVlastnika(pom).get(3));
  846.                     pom = "";
  847.                     break;
  848.                 } else {
  849.  
  850.                     pom = pom + String.valueOf(buff[i]);
  851.                     buff[i] = ' ';
  852.                 }
  853.             }
  854.  
  855.         }
  856.         return rozdeleniePredstavitelov;
  857.     }
  858.  
  859.     private static ArrayList<String> oddelVlastnikov(String vlastnik) {
  860.  
  861.         ArrayList<String> rozdelenieVlastnikov = new ArrayList<String>();
  862.         if (vlastnik != null) {
  863.             char[] buff = vlastnik.toCharArray();
  864.             String pom = "";
  865.             int medzera = 0;
  866.  
  867.             for (int i = 0; i <= buff.length; i++) {
  868.                 if ((medzera == 0) && buff[i] == '<' && buff[i + 1] == 'b' && buff[i + 2] == 'r' && buff[i + 3] == '>') {
  869.                     pom = pom.replaceAll("td width=\"67%\">", "");
  870.                     rozdelenieVlastnikov.add(pom);
  871.                     pom = "";
  872.                     medzera++;
  873.                     // ;break;
  874.                 }
  875.                 if (i == buff.length) {
  876.                     rozdelenieVlastnikov.add(rozdelAdresuVlastnika(pom).get(0));
  877.                     rozdelenieVlastnikov.add(rozdelAdresuVlastnika(pom).get(1));
  878.                     rozdelenieVlastnikov.add(rozdelAdresuVlastnika(pom).get(2));
  879.                     rozdelenieVlastnikov.add(rozdelAdresuVlastnika(pom).get(3));
  880.  
  881.                     break;
  882.                 } else {
  883.  
  884.                     pom = pom + String.valueOf(buff[i]);
  885.                     buff[i] = ' ';
  886.                 }
  887.             }
  888.         }
  889.  
  890.  
  891.         return rozdelenieVlastnikov;
  892.     }
  893.  
  894.     private static ArrayList<String> oddeldatum(String datumy) {
  895.  
  896.         ArrayList<String> rozdeleniedatumov = new ArrayList<String>();
  897.         if (datumy != null) {
  898.             char[] buff = datumy.toCharArray();
  899.             String pom = "";
  900.             int medzera = 0;
  901.  
  902.             for (int i = 0; i <= buff.length + 1; i++) {
  903.                 if (buff[i] == 'd') {
  904.                     pom = pom.replaceAll("\\(", "");
  905.                     rozdeleniedatumov.add(pom);
  906.                     pom = "";
  907.                     medzera++;
  908.                 }
  909.                 if (medzera == 1 && i == buff.length - 1) {
  910.                     pom = pom.replaceAll("do:", "");
  911.                     pom = pom.replaceAll("\\(", "");
  912.                     pom = pom.replaceAll("\\)", "");
  913.  
  914.                     rozdeleniedatumov.add(pom);
  915.                     medzera++;
  916.                     break;
  917.  
  918.                 } else {
  919.  
  920.                     pom = pom + String.valueOf(buff[i]);
  921.                     buff[i] = ' ';
  922.                 }
  923.  
  924.             }
  925.  
  926.         }
  927.         return rozdeleniedatumov;
  928.     }
  929.  
  930.     private static boolean isPredstavenstvo(Elements rows) {
  931.         Element row = rows.get(0);
  932.         Pattern p = Pattern.compile("predstavenstvo");
  933.         Matcher m = p.matcher(row.toString());
  934.         return m.find();
  935.     }
  936.  
  937.     private static Date editDate(String date) throws ParseException {
  938.         SimpleDateFormat format = new SimpleDateFormat("dd.MM.yyyy");
  939.         java.util.Date parsed = format.parse(date.trim());
  940.         return new Date(parsed.getTime());
  941.     }
  942.  
  943.     private static ArrayList<String> rozdelMenoATituly(String meno) {
  944.         ArrayList<String> rozdelene = new ArrayList<>();
  945.  
  946.         //0 - pred
  947.         //1 - meno
  948.         //2 - priezvisko
  949.         //3 - titulza
  950.  
  951.         char[] buff = meno.toCharArray();
  952.         ArrayList<String> pomocnePole = new ArrayList<>();   //pole, kde si rozdelim data medzi '> <'
  953.  
  954.         int pos1 = 0;
  955.         int pos2 = 0;
  956.  
  957.         for (int i = 0; i < buff.length; i++) {
  958.  
  959.             if (pos1 != 0 && pos2 != 0 && pos1 < pos2) {
  960.                 if (meno.substring(pos1 + 1, pos2).length() > 2) {   //kvoli htmltagom kde su medzeri medzi nimi len
  961.                     pomocnePole.add(meno.substring(pos1 + 1, pos2));
  962.                     pos1 = 0;
  963.                     pos2 = 0;
  964.                 }
  965.             }
  966.  
  967.             if (buff[i] == '>') {
  968.                 pos1 = i;
  969.             }
  970.  
  971.             if (buff[i] == '<') {
  972.                 pos2 = i;
  973.             }
  974.         }
  975.  
  976.  
  977.         switch (pomocnePole.size()) {
  978.             case 2: {                    //meno a priezvisko
  979.                 rozdelene.add(" ");
  980.                 rozdelene.add(pomocnePole.get(0));
  981.                 rozdelene.add(pomocnePole.get(1));
  982.                 rozdelene.add(" ");
  983.                 break;
  984.             }
  985.  
  986.             case 3: {                    //meno a priezvisko a 1 titul bud pred alebo za
  987.  
  988.                 if (pomocnePole.get(0).contains(".") || pomocnePole.get(0).contains(",")) {
  989.                     rozdelene.add(pomocnePole.get(0));
  990.                     rozdelene.add(pomocnePole.get(1));
  991.                     rozdelene.add(pomocnePole.get(2));
  992.                     rozdelene.add(" ");
  993.                 } else {
  994.                     rozdelene.add(" ");
  995.                     rozdelene.add(pomocnePole.get(0));
  996.                     rozdelene.add(pomocnePole.get(1));
  997.                     rozdelene.add(pomocnePole.get(2));
  998.                 }
  999.                 break;
  1000.  
  1001.             }
  1002.             case 4: {                    //meno a priezvisko a titul pred aj za
  1003.                 rozdelene.add((pomocnePole.get(0)));
  1004.                 rozdelene.add(pomocnePole.get(1));
  1005.                 rozdelene.add(pomocnePole.get(2));
  1006.                 rozdelene.add((pomocnePole.get(3)));
  1007.                 break;
  1008.             }
  1009.             default: {
  1010.                 rozdelene.add(" ");
  1011.                 rozdelene.add(" ");
  1012.                 rozdelene.add(" ");
  1013.                 rozdelene.add(" ");
  1014.  
  1015.             }
  1016.  
  1017.         }
  1018.         // System.out.println("_____________________________________________________");
  1019.      //   System.out.println("Titil pred: " + rozdelene.get(0));
  1020.      //   System.out.println("Meno: " + rozdelene.get(1));
  1021.      //   System.out.println("Priezvisko: " + rozdelene.get(2));
  1022.      //   System.out.println("Titul za:" + rozdelene.get(3));
  1023.      //   //   System.out.println("_____________________________________________________");
  1024.  
  1025.         return rozdelene;
  1026.     }
  1027.  
  1028. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement