-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHtmlParser.java
More file actions
32 lines (29 loc) · 890 Bytes
/
Copy pathHtmlParser.java
File metadata and controls
32 lines (29 loc) · 890 Bytes
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
import java.util.List;
/**
* Classe responsável por varrer o HTML e encontrar o texto mais profundo.
*/
public class HtmlParser {
/**
* Analisa as linhas do HTML para encontrar o texto mais profundo.
* @param lines Linhas pré-processadas do HTML.
* @return Texto no nível mais profundo.
*/
public String parse(List<String> lines) {
int currentDepth = 0;
int maxDepth = 0;
String deepestText = "";
for (String line : lines) {
if (HtmlUtils.isOpeningTag(line)) {
currentDepth++;
} else if (HtmlUtils.isClosingTag(line)) {
currentDepth--;
} else {
if (currentDepth > maxDepth) {
maxDepth = currentDepth;
deepestText = line;
}
}
}
return deepestText;
}
}