private VSEStructureElement.StudyType handleProgramData(Document doc) throws Exception { VSEStructureElement.StudyType studyType = new VSEStructureElement.StudyType(); Elements tables = doc.body().select("table"); studyType.name = tables.get(0).select("tbody tr").get(3).select("td").get(1).text(); Elements programmeRows = tables.get(1).select("tbody tr"); for (Element row : programmeRows) { Elements cells = row.getElementsByTag("td"); if (cells.get(0).hasAttr("width")) break; String link = cells.get(5).getElementsByTag("a").get(0).attr("href"); Map<String, String> args = HttpRequestBuilder.getGetArguments(link, '=', ';'); String programmeString = cells.get(1).text(); final VSEStructureElement.Programme programme = new VSEStructureElement.Programme(); int spaceIdx = programmeString.indexOf(" "); String[] codes = programmeString.substring(0, spaceIdx).split("-"); programme.name = programmeString.substring(spaceIdx + 1); programme.addCode(codes[codes.length - 1]); studyType.addCode(codes[0]); runTask( args, new OnDocumentLoaded() { @Override public void loaded(Document document) throws Exception { programme.fields = handleFieldsData(document); } }); studyType.programmes.add(programme); } Elements specializationRows = tables.get(2).select("tbody tr"); for (Element row : specializationRows) { Elements cells = row.getElementsByTag("td"); if (cells.get(0).hasAttr("width")) break; String specializationString = cells.get(1).text(); String[] specializationParts = specializationString.split(" ", 2); VSEStructureElement specialization = new VSEStructureElement(); specialization.addCode(specializationParts[0]); specialization.name = specializationParts[1]; studyType.specializations.add(specialization); } return studyType; }
private VSEStructureElement.List<VSEStructureElement> handleFieldsData(Document doc) throws Exception { Elements tables = doc.body().select("table"); Elements fieldRows = tables.get(1).select("tbody tr"); VSEStructureElement.List<VSEStructureElement> fields = new VSEStructureElement.List<VSEStructureElement>(); for (Element row : fieldRows) { Elements cells = row.getElementsByTag("td"); VSEStructureElement field = new VSEStructureElement(); field.name = cells.get(1).text(); String[] codes = cells.get(0).text().split("-"); field.addCode(codes[codes.length - 1]); fields.add(field); } return fields; }