Advertisement
Guest User

Untitled

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