public JsSearchTextRenderer(JsSearchText viewer) {
this.viewer = viewer;
}
public void viewDocument(HTMLNode header, HTMLNode body, String url) {
Browser browser = viewer.getBrowser();
if(body.isNode(Name.CONTENT)
|| body.isNode(Name.COMMENT)
|| body.isNode(Name.UNKNOWN)) {
browser.setText(body.getTextValue());
return;
}
try {
StringBuilder builder = new StringBuilder();
builder.append("<html>").append("<head>");
if(header != null && header.getChildren() != null) {
for(HTMLNode ele : header.getChildren()){
builder.append(ele.getTextValue()).append('\n');
}
}
// String baseHref = UtilFile.getFolder("client/htmlexplorer/").toURI().toString();
//.getAbsolutePath();//HTMLExplorer.class.getResource("").toString();
// builder.append("<base href=\""+baseHref+"\">").append("</head>");
builder.append ("<script language=\"JavaScript\">\n");
builder.append ("function gotoSelectedText() {\n");
builder.append (" var value;\n");
builder.append (" try {\n");
builder.append (" window.stop();\n");
builder.append (" } catch(e) {\n");
// builder.append (" alert('1111: ' + e.message);\n");
builder.append (" try {\n");
builder.append (" document.execCommand(\"Stop\");\n");
builder.append (" } catch(e) {\n");
builder.append (" alert('222: ' + e.message);\n");
builder.append (" }\n");
builder.append (" }\n");
builder.append (" try {\n");
builder.append (" value = window.getSelection();\n");
builder.append (" } catch(e) {\n");
builder.append (" value = document.selection.createRange().text;\n");
builder.append (" }\n");
builder.append (" try {\n");
// builder.append (" alert(value);\n");
builder.append (" result = theJavaFunction(value);\n");
builder.append (" } catch (e) {\n");
// String os_name = System.getProperty("os.name").toLowerCase();
// if(os_name.indexOf("windows") > -1
// || os_name.indexOf("win") > -1) {
// builder.append (" alert('select node error occurred: ' + e.message + '! Select again.');\n");
// }
builder.append (" return;\n");
builder.append (" }\n");
builder.append ("}\n");
builder.append ("</script>\n");
builder.append("</head>");
builder.append("<body onmouseup=\"gotoSelectedText();\">\n");
builder.append(buildBodyText(body)).append("</body></html>");
// System.out.println(builder.toString());
browser.setText(builder.toString());
if(searcher != null) searcher.dispose();
searcher = new JsSearchTextFunction(viewer);
} catch (Exception e) {
if(url != null) viewer.getBrowser().setUrl(url);