Browse Source

Replaced cutLine method to class OldParser

master
Defend 8 years ago
parent
commit
cb429eb65d
  1. 22
      app/src/main/java/ru/defend/defdevteam/tstu/OldParser.java
  2. 122
      app/src/main/java/ru/defend/defdevteam/tstu/WebActivity.java

22
app/src/main/java/ru/defend/defdevteam/tstu/OldParser.java

@ -25,4 +25,26 @@ public class OldParser {
public ArrayList<WebActivity.groupList> 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;
}
}

122
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("<span id=\\\"P1_STUD\\\" class=\\\"display_only\\\" style=\\\"font-size: 120%; font-family:Verdana, Arial, Helvetica, sans-serif; color: #0000FF; font-weight:bold\\\">",
String studNameGroup = parser.cutLine("<span id=\\\"P1_STUD\\\" class=\\\"display_only\\\" style=\\\"font-size: 120%; font-family:Verdana, Arial, Helvetica, sans-serif; color: #0000FF; font-weight:bold\\\">",
"</span>",
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("<td headers=\\\"BRS\\\"><a href=\\\"","\" title=\\\"Просмотр журналов\\\">",AdditionalHTML);
parser.cutLine("<td headers=\\\"BRS\\\"><a href=\\\"","\" title=\\\"Просмотр журналов\\\">",AdditionalHTML);
RateValueURL = "http://web-iais.admin.tstu.ru:7777/zion/" +
cutLine("<td headers=\\\"RTG\\\"><a href=\\\"","\\\" title=\\\"Просмотр успеваемости\\\">",AdditionalHTML);
parser.cutLine("<td headers=\\\"RTG\\\"><a href=\\\"","\\\" title=\\\"Просмотр успеваемости\\\">",AdditionalHTML);
browser.loadUrl(JournalURL);
break;
case 4:
@ -384,10 +366,10 @@ public class WebActivity extends AppCompatActivity
break;
case 5:
RateValueHTML = siteBuf;
String rate = cutLine("<td align=\\\"center\\\" headers=\\\"STUDRATE\\\">","</td>",RateValueHTML);
String rate = parser.cutLine("<td align=\\\"center\\\" headers=\\\"STUDRATE\\\">","</td>",RateValueHTML);
studentRate.setText("Балл: " + rate);
GroupRateURL = "http://web-iais.admin.tstu.ru:7777/zion/" + cutLine("><td headers=\\\"GROUP_NAME\\\"><a href=\\\"","\\\">",RateValueHTML);
FacultyRateURL = "http://web-iais.admin.tstu.ru:7777/zion/" + cutLine("<td headers=\\\"INST\\\"><a href=\\\"","\\\">", RateValueHTML);
GroupRateURL = "http://web-iais.admin.tstu.ru:7777/zion/" + parser.cutLine("><td headers=\\\"GROUP_NAME\\\"><a href=\\\"","\\\">",RateValueHTML);
FacultyRateURL = "http://web-iais.admin.tstu.ru:7777/zion/" + parser.cutLine("<td headers=\\\"INST\\\"><a href=\\\"","\\\">", 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<groupList>();
String n,r;
String gr = siteBuf;
gr = cutLine("<h1>Рейтинг в группе</h1>", "", gr);
gr = parser.cutLine("<h1>Рейтинг в группе</h1>", "", gr);
int i = 0;
while ( !(cutLine("<tr><td align=\\\"center\\\" headers=\\\"ROWNUM\\\">","</tr>",gr,true) == "")){
Integer s = Integer.valueOf(cutLine("<td align=\\\"center\\\" headers=\\\"ROWNUM\\\">","</td>",gr));
while ( !(parser.cutLine("<tr><td align=\\\"center\\\" headers=\\\"ROWNUM\\\">","</tr>",gr,true) == "")){
Integer s = Integer.valueOf(parser.cutLine("<td align=\\\"center\\\" headers=\\\"ROWNUM\\\">","</td>",gr));
if(s == (i+1)) {
n = cutLine("<td headers=\\\"STUDNAME\\\">", "</td>", gr);
if (!(cutLine("<font color=\\\"red\\\"><b>", "</b></font>", n) == ""))
n = cutLine("<font color=\\\"red\\\"><b>", "</b></font>",n);
r = cutLine("<td align=\\\"center\\\" headers=\\\"STUDRATE\\\">", "</td>", gr);
r += " | Группа: " + cutLine("<td headers=\\\"GROUP_NAME\\\">","</td>", gr, true);
n = parser.cutLine("<td headers=\\\"STUDNAME\\\">", "</td>", gr);
if (!(parser.cutLine("<font color=\\\"red\\\"><b>", "</b></font>", n) == ""))
n = parser.cutLine("<font color=\\\"red\\\"><b>", "</b></font>",n);
r = parser.cutLine("<td align=\\\"center\\\" headers=\\\"STUDRATE\\\">", "</td>", gr);
r += " | Группа: " + parser.cutLine("<td headers=\\\"GROUP_NAME\\\">","</td>", gr, true);
group.add(new groupList(n,"Общий балл: " + r));
i++;
}
gr = cutLine("</td></tr>\\n", "", gr);
gr = parser.cutLine("</td></tr>\\n", "", gr);
}
ArrayAdapter<groupList> 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<groupList>();
String n,r;
String fr = siteBuf;
fr = cutLine("<h1>Рейтинг в институте/факультете</h1>", "", fr);
fr = parser.cutLine("<h1>Рейтинг в институте/факультете</h1>", "", fr);
int i = 0;
while ( !(cutLine("<tr><td align=\\\"center\\\" headers=\\\"ROWNUM\\\">","</tr>",fr,true) == "")){
Integer s = Integer.valueOf(cutLine("<td align=\\\"center\\\" headers=\\\"ROWNUM\\\">","</td>",fr));
while ( !(parser.cutLine("<tr><td align=\\\"center\\\" headers=\\\"ROWNUM\\\">","</tr>",fr,true) == "")){
Integer s = Integer.valueOf(parser.cutLine("<td align=\\\"center\\\" headers=\\\"ROWNUM\\\">","</td>",fr));
if(s == (i+1)) {
n = cutLine("<td headers=\\\"STUDNAME\\\">", "</td>", fr);
if (!(cutLine("<font color=\\\"red\\\"><b>", "</b></font>", n) == ""))
n = cutLine("<font color=\\\"red\\\"><b>", "</b></font>",n);
r = cutLine("<td align=\\\"center\\\" headers=\\\"STUDRATE\\\">", "</td>", fr);
r += " | Группа: " + cutLine("<td headers=\\\"GROUP_NAME\\\">","</td>", fr, true);
n = parser.cutLine("<td headers=\\\"STUDNAME\\\">", "</td>", fr);
if (!(parser.cutLine("<font color=\\\"red\\\"><b>", "</b></font>", n) == ""))
n = parser.cutLine("<font color=\\\"red\\\"><b>", "</b></font>",n);
r = parser.cutLine("<td align=\\\"center\\\" headers=\\\"STUDRATE\\\">", "</td>", fr);
r += " | Группа: " + parser.cutLine("<td headers=\\\"GROUP_NAME\\\">","</td>", fr, true);
faculty.add(new groupList(n,"Общий балл: " + r));
i++;
}
fr = cutLine("</td></tr>\\n", "", fr);
fr = parser.cutLine("</td></tr>\\n", "", fr);
}
ArrayAdapter<groupList> 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("<tr>","</tr>",GroupRateHTML);
s = cutLine("<font","</font>",s);
s = parser.cutLine("<tr>","</tr>",GroupRateHTML);
s = parser.cutLine("<font","</font>",s);
while (s.equals("")) {
s2 = cutLine("</tr>","",s2);
s = cutLine("<tr>","</tr>",s2);
s = cutLine("<font","</font>",s);
s2 = parser.cutLine("</tr>","",s2);
s = parser.cutLine("<tr>","</tr>",s2);
s = parser.cutLine("<font","</font>",s);
}
s2 = cutLine("<td align=\\\"center\\\" headers=\\\"ROWNUM\\\">","</td>",s2);
s2 = parser.cutLine("<td align=\\\"center\\\" headers=\\\"ROWNUM\\\">","</td>",s2);
Log.i("GroupPos",s2);
positionGroup.setText("Место в группе: " + s2);
s = "";
s2 = FacultyRateHTML;
s = cutLine("<tr>","</tr>",FacultyRateHTML);
s = cutLine("<font","</font>",s);
s = parser.cutLine("<tr>","</tr>",FacultyRateHTML);
s = parser.cutLine("<font","</font>",s);
while (s.equals("")) {
s2 = cutLine("</tr>","",s2);
s = cutLine("<tr>","</tr>",s2);
s = cutLine("<font","</font>",s);
s2 = parser.cutLine("</tr>","",s2);
s = parser.cutLine("<tr>","</tr>",s2);
s = parser.cutLine("<font","</font>",s);
}
s2 = cutLine("<td align=\\\"center\\\" headers=\\\"ROWNUM\\\">","</td>",s2);
s2 = parser.cutLine("<td align=\\\"center\\\" headers=\\\"ROWNUM\\\">","</td>",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("<title>","</title>",siteBuf));
Log.d("Response html","Загружена страница "+parser.cutLine("<title>","</title>",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());
}
}
}

Loading…
Cancel
Save