autoSelect();
}
private void autoSelect() {
if(type == HTMLExplorer.NONE) return;
NodePath bodyPath = null;
NodePathParser pathParser = new NodePathParser();
try {
bodyPath = pathParser.toPath("BODY");
}catch (Exception e) {
ClientLog.getInstance().setException(tree.getShell(), e);
}
if(bodyPath == null || document == null) return;
HTMLNode body = new HTMLExtractor().lookNode(document.getRoot(), bodyPath);
List<HTMLNode> list = new ArrayList<HTMLNode>();
List<HTMLNode> commons = new ArrayList<HTMLNode>();
if(HTMLExplorer.SECTION == type) {
searchSectionCSS(commons, list, body);
short selectType = PathConfirmDialog.YES;
for(HTMLNode ele : commons) {
try {
NodePath path = pathParser.toPath(ele);
if(path == null) continue;
selectType = handler.traverseTree(tree, path, TreeHandler.MARK, selectType);
} catch(Exception exp){
ClientLog.getInstance().setMessage(tree.getShell(), exp);
}
}
return;
}
searchContentCSS(commons, list, body);
int maxCountContent = 0;
HTMLNode maxNodeContent = null;
List<HTMLNode> contents = new ArrayList<HTMLNode>();
CharacterUtil characterUtil = new CharacterUtil();
HTMLText htmlText = new HTMLText();
short selectType = PathConfirmDialog.YES;
boolean traverse = false;
for(HTMLNode ele : commons) {
contents.clear();
htmlText.searchText(contents, ele);
int count = countText(characterUtil, contents);
if(count > maxCountContent) {
maxCountContent = count;
maxNodeContent = ele;
}
if(count < 100) continue;
NodePath path = pathParser.toPath(ele);
if(path == null) continue;
handler.traverseTree(tree, path, TreeHandler.MARK, selectType);
if(!traverse) traverse = true;
}
if(traverse || maxNodeContent == null) return;
try {
NodePath path = pathParser.toPath(maxNodeContent);
if(path == null) return;
handler.traverseTree(tree, path, TreeHandler.MARK, selectType);
}catch(Exception exp){
ClientLog.getInstance().setMessage(tree.getShell(), exp);
}