Repository navigation
Expand file tree
/
Copy pathSectionType.java
More file actions
95 lines (84 loc) · 3.39 KB
/
Copy pathSectionType.java
File metadata and controls
95 lines (84 loc) · 3.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package ru.javaops.webapp.model;
import ru.javaops.webapp.util.DateUtil;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.List;
public enum SectionType {
OBJECTIVE("Позиция"),
PERSONAL("Личные качества"),
ACHIEVEMENT("Достижения") {
@Override
protected <T> String toHtml0(T section) {
return fromListSection(section);
}
},
QUALIFICATIONS("Квалификация") {
@Override
protected <T> String toHtml0(T section) {
return fromListSection(section);
}
},
EXPERIENCE("Опыт работы") {
@Override
protected <T> String toHtml0(T section) {
return fromOrganisationSection(section);
}
},
EDUCATION("Образование") {
@Override
protected <T> String toHtml0(T section) {
return fromOrganisationSection(section);
}
};
private final String title;
SectionType(String value) {
this.title = value;
}
public static String toLink(String href, String title) {
String headStart = "<h3 style=\"text-align: left; padding-left: 80px;\">";
if (href == null || href.trim().isEmpty()) {
return headStart + title + "</h3>";
}
return headStart + "<a href='" + href + "'>" + title + "</a></h3>";
}
public String getTitle() {
return title;
}
public <T extends AbstractSection> String toHtml(T section) {
return (section == null) ? "" : toHtml0(section);
}
protected <T> String toHtml0(T section) {
String value = ((TextSection) section).getContent();
return "<h2>" + getTitle() + "</h2>\n" + value;
}
protected <T> String fromListSection(T section) {
List<String> value = ((ListSection) section).getStrings();
StringBuilder strings = new StringBuilder();
for (String s : value) {
strings.append(s).append("<br/>");
}
return "<h2>" + getTitle() + "</h2>\n" + strings;
}
protected <T> String fromOrganisationSection(T section) {
StringBuilder strings = new StringBuilder();
strings.append("<h2>").append(getTitle()).append("</h2>\n");
List<Organization> organizations = ((OrganizationSection) section).getOrganisations();
for (Organization org : organizations) {
Link homePage = org.getHomePage();
strings.append(toLink(homePage.getUrl(), homePage.getName()));
List<Organization.Period> periods = org.getPeriods();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/yyyy");
for (Organization.Period period : periods) {
strings.append("<p style=\"padding-left: 80px;\">");
String dates = period.getStart().format(formatter) + " - " +
((period.getEnd().isEqual(LocalDate.now()) || period.getEnd().isAfter(LocalDate.now())) ? "сейчас" :
period.getEnd().format(formatter));
strings.append(dates).append("<br/>").append(period.getTitle()).append("</p>");
if (period.getDescription() != null) {
strings.append("<p style=\"padding-left: 80px;\">").append(period.getDescription()).append("</p>");
}
}
}
return strings.toString();
}
}