Jerry ist eine Open-Source-Lib, die eine von jQuery bekannte Funktionalität in Java abbildet. Beispiele von der Webseite: http://jodd.org/doc/jerry/index.html.
import static jodd.lagarto.dom.jerry.Jerry.jerry;
...
Jerry doc = jerry(html);
doc.$("div#jodd p.neat").css("color", "red").addClass("ohmy");
und:
doc.$("select option:selected").each(new JerryFunction() {
public boolean onNode(Jerry $this, int index) {
str.append($this.text()).append(' ');
return true;
}
});
Statt aus einem String kann die Eingabe auch direkt aus der Datei kommen:
File file = new File(SystemUtil.getTempDir(), "allmusic.html");
NetUtil.downloadFile("http://allmusic.com", file);
// create Jerry, i.e. document context
Jerry doc = Jerry.jerry(FileUtil.readString(file));
// parse
doc.$("div#new_releases div.list_item").each(new JerryFunction() {
public boolean onNode(Jerry $this, int index) {
System.out.println("-----");
System.out.println($this.$("div.album_title").text());
System.out.println($this.$("div.album_artist").text().trim());
return true;
}
});
			
Jerry sieht nicht schlecht aus. Die Library macht ähnliche Dinge, wie http://jsoup.org/ oder http://code.google.com/p/gwtquery/. Alle drei libraries sind sehr stark HTML-fokussiert und haben ein eigenes DOM-Modell.
Für jquery-ähnliche Abfragen auf Java’s w3c DOM packages gibt’s da noch http://code.google.com/p/joox/. jOOX integriert mehr mit Java standards, so wie z.B. DOM, XPath, JAXB, XSLT, Xalan extensions etc. Feedback würd mich interessieren!
Gruss,
Lukas