public void setHighLightingEnabled(boolean enabled) {
myContent.contextPut("highlight", Boolean.valueOf(enabled));
}
public MediaResource extractMediaResource(boolean wrapHTML) {
JSONObject json = getAndClearJSON();
String res;
String jsonText = json.toString();
//System.out.println("jsontext:"+jsonText);
if (wrapHTML) {
// most ajax responses are a lot smaller than 16k
StringBuffer sb = new StringBuffer(16384);
sb.append("<html><head><script type=\"text/javascript\">\n/* <![CDATA[ */\nfunction invoke(){var r=")
.append(jsonText).append("; ")
.append("if (parent!=self&&parent.window.o_info){")
.append("parent.window.o_ainvoke(r);")
// normal case: ajax result can be delivered into the hidden iframe.
// else: no parent frame or parent frame is not olat -> reasons:
// a) mouse-right-click to open in new tab/window
// b) fast double-click when target causes a 302 and browser's window's document has been updated, but old link was still clickable
// c) ...
// -> in all cases, do not show the json command, but reload the window which contained the link clicked (= window id of url)
.append("} else {")
// inform user that ajax-request cannot be opened in a new window,
// todo felix: maybe send back request to bookmark-launch current url? -> new window?
// we could then come near to what the user probably wanted when he/she opened a link in a new window
.append("this.document.location=\"")
.append(StaticMediaDispatcher.createStaticURIFor("msg/json/en/info.html"))
.append("\";")
//.append("window.open(self.location+\"?o_win_jsontop=1\"); this.close();")
//.append("this.document.location=self.location+\"?o_win_jsontop=1\";")
.append("}}")
.append("\n/* ]]> */\n</script></head><body onLoad=\"invoke()\">");
if (showJSON) {
try {
sb.append("<pre style=\"font-size:12px;\">len:").append(jsonText.length()).append(":\n").append(StringEscapeUtils.escapeHtml(json.toString(2))).append("</pre>");
} catch (JSONException e) {
sb.append("error while prettyprinting json for debug mode: ").append(e.getMessage());
}
}
sb.append("</body></html>");