From cb429eb65d686f61f829c0063afaeda3a4b03dd3 Mon Sep 17 00:00:00 2001 From: Defend Date: Fri, 10 Feb 2017 22:15:25 +0300 Subject: [PATCH] Replaced cutLine method to class OldParser --- .../ru/defend/defdevteam/tstu/OldParser.java | 22 ++++ .../defend/defdevteam/tstu/WebActivity.java | 122 ++++++++---------- 2 files changed, 75 insertions(+), 69 deletions(-) diff --git a/app/src/main/java/ru/defend/defdevteam/tstu/OldParser.java b/app/src/main/java/ru/defend/defdevteam/tstu/OldParser.java index 190a795..c513c2a 100644 --- a/app/src/main/java/ru/defend/defdevteam/tstu/OldParser.java +++ b/app/src/main/java/ru/defend/defdevteam/tstu/OldParser.java @@ -25,4 +25,26 @@ public class OldParser { public ArrayList parseGroup(){ return null; } + + public String cutLine(String a, String b, String Line){ + if(Line.contains(a)) Line = Line.substring(Line.indexOf(a)+ a.length()); + if(Line.contains(b)) { + if(b == ""){ + return Line; + } + Line = Line.substring(0, Line.indexOf(b)); + return Line; + } else { + return ""; + } + } + + public String cutLine(String a, String b, String Line, boolean hard){ + if ((!Line.contains(a)) || (a.equals("")) ) return ""; + if ((!Line.contains(b)) || (b.equals("")) ) return ""; + Line = Line.substring(Line.indexOf(a)+ a.length()); + Line = Line.substring(0, Line.indexOf(b)); + return Line; + } + } diff --git a/app/src/main/java/ru/defend/defdevteam/tstu/WebActivity.java b/app/src/main/java/ru/defend/defdevteam/tstu/WebActivity.java index 4d8ba7c..d27ebc0 100644 --- a/app/src/main/java/ru/defend/defdevteam/tstu/WebActivity.java +++ b/app/src/main/java/ru/defend/defdevteam/tstu/WebActivity.java @@ -178,7 +178,7 @@ public class WebActivity extends AppCompatActivity feedController = new FeedController(this, 1); AuthURL = "http://web-iais.admin.tstu.ru:7777/zion/f?p=stud_main"; - loadSite(); + loadSite(AuthURL); } @@ -263,30 +263,10 @@ public class WebActivity extends AppCompatActivity - public void loadSite () { - browser.loadUrl(AuthURL); + public void loadSite (String url) { + browser.loadUrl(url); } - public String cutLine(String a, String b, String Line){ - if(Line.contains(a)) Line = Line.substring(Line.indexOf(a)+ a.length()); - if(Line.contains(b)) { - if(b == ""){ - return Line; - } - Line = Line.substring(0, Line.indexOf(b)); - return Line; - } else { - return ""; - } - } - - public String cutLine(String a, String b, String Line, boolean hard){ - if ((!Line.contains(a)) || (a.equals("")) ) return ""; - if ((!Line.contains(b)) || (b.equals("")) ) return ""; - Line = Line.substring(Line.indexOf(a)+ a.length()); - Line = Line.substring(0, Line.indexOf(b)); - return Line; - } // НЕИЗВЕСТНОЕ ИСКЛЮЧЕНИЕ @@ -309,10 +289,11 @@ public class WebActivity extends AppCompatActivity } public byte sessionState () { + OldParser parser = new OldParser(); if(taskFinished) return 127; Intent intent = new Intent(); Log.i("sessionActive","Checking session"); - String a = cutLine("http://web-iais.admin.tstu.ru:7777/zion/f?p=503:",":",browser.getUrl()); + String a = parser.cutLine("http://web-iais.admin.tstu.ru:7777/zion/f?p=503:",":",browser.getUrl()); switch (a){ case "LOGIN_DESKTOP": Log.i("sessionActive","Окно авторизации"); @@ -340,12 +321,12 @@ public class WebActivity extends AppCompatActivity return 4; case "43": Log.i("sessionActive","Страница - Рейтинг|Главная"); - String s = cutLine("","503:",MainURL) + "503:43:" + cutLine(":1:","",MainURL)+":"; - if(cutLine(s,":NO:",browser.getUrl()).equals("RATE_GROUP")) { + String s = parser.cutLine("","503:",MainURL) + "503:43:" + parser.cutLine(":1:","",MainURL)+":"; + if(parser.cutLine(s,":NO:",browser.getUrl()).equals("RATE_GROUP")) { taskGenerator(6); return 6; } - if(cutLine(s,":NO:",browser.getUrl()).equals("RATE_INST")) { + if(parser.cutLine(s,":NO:",browser.getUrl()).equals("RATE_INST")) { taskGenerator(7); return 7; } @@ -359,23 +340,24 @@ public class WebActivity extends AppCompatActivity // Контент генератор public void taskGenerator(int state){ + OldParser parser = new OldParser(); if (!isFinishing()) switch (state){ case 2: MainHTML = siteBuf; - String studNameGroup = cutLine("", + String studNameGroup = parser.cutLine("", "", MainHTML); - studentName.setText(cutLine(""," /",studNameGroup)); - studentGroup.setText("Группа: " + cutLine("/ ","",studNameGroup)); + studentName.setText(parser.cutLine(""," /",studNameGroup)); + studentGroup.setText("Группа: " + parser.cutLine("/ ","",studNameGroup)); browser.loadUrl("javascript:apex.submit('T_ЗАНЯТИЯ/ОЦЕНКИ');"); break; case 3: AdditionalHTML = siteBuf; JournalURL = "http://web-iais.admin.tstu.ru:7777/zion/" + - cutLine("",AdditionalHTML); + parser.cutLine("",AdditionalHTML); RateValueURL = "http://web-iais.admin.tstu.ru:7777/zion/" + - cutLine("",AdditionalHTML); + parser.cutLine("",AdditionalHTML); browser.loadUrl(JournalURL); break; case 4: @@ -384,10 +366,10 @@ public class WebActivity extends AppCompatActivity break; case 5: RateValueHTML = siteBuf; - String rate = cutLine("","",RateValueHTML); + String rate = parser.cutLine("","",RateValueHTML); studentRate.setText("Балл: " + rate); - GroupRateURL = "http://web-iais.admin.tstu.ru:7777/zion/" + cutLine(">",RateValueHTML); - FacultyRateURL = "http://web-iais.admin.tstu.ru:7777/zion/" + cutLine("", RateValueHTML); + GroupRateURL = "http://web-iais.admin.tstu.ru:7777/zion/" + parser.cutLine(">",RateValueHTML); + FacultyRateURL = "http://web-iais.admin.tstu.ru:7777/zion/" + parser.cutLine("", RateValueHTML); browser.loadUrl(GroupRateURL); break; case 6: @@ -407,23 +389,24 @@ public class WebActivity extends AppCompatActivity } public void fillGroup(){ + OldParser parser = new OldParser(); group = new ArrayList(); String n,r; String gr = siteBuf; - gr = cutLine("

Рейтинг в группе

", "", gr); + gr = parser.cutLine("

Рейтинг в группе

", "", gr); int i = 0; - while ( !(cutLine("","",gr,true) == "")){ - Integer s = Integer.valueOf(cutLine("","",gr)); + while ( !(parser.cutLine("","",gr,true) == "")){ + Integer s = Integer.valueOf(parser.cutLine("","",gr)); if(s == (i+1)) { - n = cutLine("", "", gr); - if (!(cutLine("", "", n) == "")) - n = cutLine("", "",n); - r = cutLine("", "", gr); - r += " | Группа: " + cutLine("","", gr, true); + n = parser.cutLine("", "", gr); + if (!(parser.cutLine("", "", n) == "")) + n = parser.cutLine("", "",n); + r = parser.cutLine("", "", gr); + r += " | Группа: " + parser.cutLine("","", gr, true); group.add(new groupList(n,"Общий балл: " + r)); i++; } - gr = cutLine("\\n", "", gr); + gr = parser.cutLine("\\n", "", gr); } ArrayAdapter groupL = new groupAdapter(this); ListView groupList = (ListView) findViewById(R.id.groupList); @@ -435,53 +418,54 @@ public class WebActivity extends AppCompatActivity } public void fillFaculty(){ + OldParser parser = new OldParser(); faculty = new ArrayList(); String n,r; String fr = siteBuf; - fr = cutLine("

Рейтинг в институте/факультете

", "", fr); + fr = parser.cutLine("

Рейтинг в институте/факультете

", "", fr); int i = 0; - while ( !(cutLine("","",fr,true) == "")){ - Integer s = Integer.valueOf(cutLine("","",fr)); + while ( !(parser.cutLine("","",fr,true) == "")){ + Integer s = Integer.valueOf(parser.cutLine("","",fr)); if(s == (i+1)) { - n = cutLine("", "", fr); - if (!(cutLine("", "", n) == "")) - n = cutLine("", "",n); - r = cutLine("", "", fr); - r += " | Группа: " + cutLine("","", fr, true); + n = parser.cutLine("", "", fr); + if (!(parser.cutLine("", "", n) == "")) + n = parser.cutLine("", "",n); + r = parser.cutLine("", "", fr); + r += " | Группа: " + parser.cutLine("","", fr, true); faculty.add(new groupList(n,"Общий балл: " + r)); i++; } - fr = cutLine("\\n", "", fr); + fr = parser.cutLine("\\n", "", fr); } ArrayAdapter facultyL = new facultyAdapter(this); ListView facultyList = (ListView) findViewById(R.id.facultyList); facultyList.setAdapter(facultyL); } - public void fillAll(){ + OldParser parser = new OldParser(); String s; String s2 = GroupRateHTML; - s = cutLine("","",GroupRateHTML); - s = cutLine("",s); + s = parser.cutLine("","",GroupRateHTML); + s = parser.cutLine("",s); while (s.equals("")) { - s2 = cutLine("","",s2); - s = cutLine("","",s2); - s = cutLine("",s); + s2 = parser.cutLine("","",s2); + s = parser.cutLine("","",s2); + s = parser.cutLine("",s); } - s2 = cutLine("","",s2); + s2 = parser.cutLine("","",s2); Log.i("GroupPos",s2); positionGroup.setText("Место в группе: " + s2); s = ""; s2 = FacultyRateHTML; - s = cutLine("","",FacultyRateHTML); - s = cutLine("",s); + s = parser.cutLine("","",FacultyRateHTML); + s = parser.cutLine("",s); while (s.equals("")) { - s2 = cutLine("","",s2); - s = cutLine("","",s2); - s = cutLine("",s); + s2 = parser.cutLine("","",s2); + s = parser.cutLine("","",s2); + s = parser.cutLine("",s); } - s2 = cutLine("","",s2); + s2 = parser.cutLine("","",s2); Log.i("FacultyPos",s2); positionFaculty.setText("Место в институте: " + s2); } @@ -502,19 +486,19 @@ public class WebActivity extends AppCompatActivity public void encodeHTML(){ if(siteBuf != null){ + OldParser parser = new OldParser(); siteBuf = OldParser.removeUTFCharacters(siteBuf).toString(); - Log.d("Response html","Загружена страница "+cutLine("","",siteBuf)); + Log.d("Response html","Загружена страница "+parser.cutLine("","",siteBuf)); Log.i("encodeHTML",siteBuf); } } - private class MyWebViewClient extends WebViewClient { @Override public void onPageFinished(WebView view, String url) { getHTML(); - Log.i("onPageFinished",browser.getUrl()); + Log.i("onPageFinished", browser.getUrl()); } } }