/*
* Hypertext_Link.bsh - a BeanShell macro script for the
* jEdit text editor - creates an HTML anchor (... tag)
* for the URL selected in a buffer. Also gets the page title and puts
* it into the tag body. Requires jTidy plugin.
*
* Copyright (C) 2004 Vojtech Broz
*
* vojtech.broz@email.cz
*
*/
import org.w3c.tidy.*;
import org.w3c.dom.*;
void hypertextLink()
{
text = textArea.getSelectedText();
Tidy t = new Tidy();
t.setXmlTags(false);
t.setQuiet(true);
String title = null;
try {
URL url = new URL(text);
InputStream is = url.openStream();
Document root = t.parseDOM(is, null);
NodeList nl = root.getElementsByTagName("title");
title = nl.item(0).getFirstChild().getNodeValue();
} catch (Exception e) {
System.out.println(e.getMessage());
title = "???";
}
StringBuffer sb = new StringBuffer();
sb.append("");
sb.append(title);
sb.append("");
textArea.setSelectedText(sb.toString());
}
hypertextLink();
/*
Macro index data (in DocBook format)
Hypertext_Link.bsh
Creates a hypertext link while getting the HTML page title.
*/