From cded7c7d278d9f15c8606feafc9e039172133a1c Mon Sep 17 00:00:00 2001 From: lukas-heiligenbrunner Date: Fri, 27 Mar 2020 10:06:24 +0100 Subject: [PATCH] new class representing a storage --- .../com/wasteinformationserver/Dateget.java | 105 ------------------ src/java/com/wasteinformationserver/Main.kt | 2 + .../basicutils/Storage.kt | 46 ++++++++ 3 files changed, 48 insertions(+), 105 deletions(-) delete mode 100644 src/java/com/wasteinformationserver/Dateget.java create mode 100644 src/java/com/wasteinformationserver/basicutils/Storage.kt diff --git a/src/java/com/wasteinformationserver/Dateget.java b/src/java/com/wasteinformationserver/Dateget.java deleted file mode 100644 index c10c8da..0000000 --- a/src/java/com/wasteinformationserver/Dateget.java +++ /dev/null @@ -1,105 +0,0 @@ -/** - * dead code... - */ -package com.wasteinformationserver; - -import com.wasteinformationserver.basicutils.Log; - -import java.io.IOException; -import java.io.InputStreamReader; -import java.net.MalformedURLException; -import java.net.URL; -import java.text.DateFormat; -import java.util.ArrayList; -import java.util.GregorianCalendar; -import java.util.Scanner; - -public class Dateget { - private int index = 0; - ArrayList list = new ArrayList<>(); - ArrayList listnew = new ArrayList<>(); - public String nextDate; - - - public void getdata() { - - GregorianCalendar now = new GregorianCalendar(); - DateFormat df = DateFormat.getDateInstance(DateFormat.MEDIUM); - String datum = df.format(now.getTime()); - - URL url = null; - try { - url = new URL("https://www.steyr.at/system/web/kalender.aspx?vdatum=" + datum + "&bdatum=19.10.2019&typ=&typid=0&typids=225781950&detailonr=0&menuonr=225781812"); - Scanner scanner = new Scanner(new InputStreamReader(url.openStream())); - - int n = 0; - while (scanner.hasNext()) { - String temp = scanner.next(); - addList(temp); - } - - } catch (MalformedURLException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } - Filter(); - } - - private void addList(String temp) { - list.add(index, temp); - } - - public void printList() { - for (int n = 0; n < list.size(); n++) { - Log.Log.debug(list.get(n)); - } - } - - public void printListnew() { - for (int n = 0; n < listnew.size(); n++) { - Log.Log.debug(listnew.get(n)); - } - } - - private void Filter() { - String temp = "href=\"/system/web/kalender.aspx?detailonr=225781954-6&menuonr=225781812\">Hausabfall"; - int counter = 0; - - for (int n = 0; n < list.size(); n++) { - if (list.get(n).equals(temp)) { - counter++; - - if (counter == 4) { - - int zaehler = 0; - - for (int v = n; v < list.size(); v++) { - listnew.add(zaehler, list.get(v)); - zaehler++; - } - - /* String string = "004-034556"; - String[] parts = string.split("-"); - String part1 = parts[0]; // 004 - String part2 = parts[1]; // 034556*/ - - splitter(); - - } - } - } - } - - private void splitter() { - String temp = "

"; - - for (int n = 0; n < listnew.size(); n++) { - - if (listnew.get(n).equals(temp)) { - - } - } - } - -} diff --git a/src/java/com/wasteinformationserver/Main.kt b/src/java/com/wasteinformationserver/Main.kt index cd82eb1..67bd65a 100644 --- a/src/java/com/wasteinformationserver/Main.kt +++ b/src/java/com/wasteinformationserver/Main.kt @@ -3,6 +3,7 @@ package com.wasteinformationserver import com.wasteinformationserver.basicutils.Info import com.wasteinformationserver.basicutils.Log +import com.wasteinformationserver.basicutils.Storage import com.wasteinformationserver.db.JDBC import com.wasteinformationserver.mqtt.MqttService import com.wasteinformationserver.website.Webserver @@ -16,6 +17,7 @@ import java.io.IOException fun main() { Log.setLevel(Log.DEBUG) Info.init() + Storage.getInstance().init() Log.info("startup of WasteInformationServer") diff --git a/src/java/com/wasteinformationserver/basicutils/Storage.kt b/src/java/com/wasteinformationserver/basicutils/Storage.kt new file mode 100644 index 0000000..41e43d2 --- /dev/null +++ b/src/java/com/wasteinformationserver/basicutils/Storage.kt @@ -0,0 +1,46 @@ +package com.wasteinformationserver.basicutils + +import java.io.FileInputStream +import java.io.FileNotFoundException +import java.io.FileOutputStream +import java.io.IOException +import java.util.* + +/** + * Storeage of user information + * * database infos + * * mqtt infos + * + * @author Lukas Heiligenbrunner + */ +class Storage { + companion object { + val obj = Storage() + fun getInstance(): Storage { + return obj; + } + } + + var mqttServer: String = ""; + + + /** + * init config file + */ + fun init() { + val prop = Properties() + try { + // try to load existing config file + val inp = FileInputStream("settings.prop") + prop.load(inp) + + + } catch (ee: FileNotFoundException) { + // file not generated yet + prop.store(FileOutputStream("settings.prop"), "") + Log.info("new Settings config file generated") + } catch (e: IOException) { + e.printStackTrace() + } + } +} \ No newline at end of file