use of org.olat.core.gui.render.StringOutput in project openolat by klemens.
the class IQComponentRenderer method displayItem.
private void displayItem(StringOutput sb, Renderer renderer, URLBuilder ubu, ItemContext itc, AssessmentInstance ai) {
StringBuilder buffer = new StringBuilder(1000);
Resolver resolver = ai.getResolver();
RenderInstructions ri = new RenderInstructions();
ri.put(RenderInstructions.KEY_STATICS_PATH, resolver.getStaticsBaseURI() + "/");
ri.put(RenderInstructions.KEY_LOCALE, renderer.getTranslator().getLocale());
StringOutput soCommandURI = new StringOutput(50);
ubu.buildURI(soCommandURI, new String[] { VelocityContainer.COMMAND_ID }, new String[] { "sflash" });
ri.put(RenderInstructions.KEY_APPLET_SUBMIT_URI, soCommandURI.toString());
if (itc.getItemInput() != null)
ri.put(RenderInstructions.KEY_ITEM_INPUT, itc.getItemInput());
ri.put(RenderInstructions.KEY_RENDER_TITLE, Boolean.valueOf(ai.isDisplayTitles()));
if (ai.isAutoEnum()) {
String k = renderer.getTranslator().translate("choices.autoenum.keys");
if (k != null) {
ri.put(RenderInstructions.KEY_RENDER_AUTOENUM_LIST, k);
}
}
itc.getQtiItem().render(buffer, ri);
sb.append(buffer);
}
use of org.olat.core.gui.render.StringOutput in project openolat by klemens.
the class RichTextConfiguration method appendConfigToTinyJSArray_4.
protected void appendConfigToTinyJSArray_4(StringOutput out, Translator translator) {
// Now add the quoted values
Map<String, String> copyValues = new HashMap<String, String>(quotedConfigValues);
// Now add the non-quoted values (e.g. true, false or functions)
Map<String, String> copyNonValues = new HashMap<String, String>(nonQuotedConfigValues);
String converter = copyNonValues.get(URLCONVERTER_CALLBACK);
if (converter != null) {
copyNonValues.put(CONVERT_URLS, "true");
}
String contentCss = copyValues.remove(CONTENT_CSS);
if (contentCss != null) {
// add styles from content css and add them to format menu
copyNonValues.put(IMPORTCSS_APPEND, "true");
copyValues.put("content_css", contentCss);
// filter emoticons classes from content css
copyNonValues.put(IMPORT_SELECTOR_CONVERTER, IMPORT_SELECTOR_CONVERTER_VALUE_REMOVE_EMOTICONS);
// group imported css classes to paragraph, div, table and style menu
copyNonValues.put(IMPORTCSS_GROUPS, IMPORTCSS_GROUPS_VALUE_MENU);
// add css class filters if available to minimise classes the user sees
String selectorFilter = Settings.getHtmlEditorContentCssClassPrefixes();
if (selectorFilter != null) {
if (selectorFilter.startsWith("/") && selectorFilter.endsWith("/")) {
// a (multi) prefix filter witten as JS regexp pattern
copyNonValues.put(IMPORTCSS_SELECTOR_FILTER, selectorFilter);
} else {
// a simple prefix filter without JS regexp syntax
copyValues.put(IMPORTCSS_SELECTOR_FILTER, selectorFilter);
}
}
}
// new with menu
StringOutput tinyMenuSb = new StringOutput();
tinyMenuSb.append("plugins: '").append(tinyConfig.getPlugins()).append("',\n").append("image_advtab:true,\n").append("image_caption:").append(figCaption).append(",\n").append("image_title:true,\n").append("relative_urls:").append(isRelativeUrls()).append(",\n").append("remove_script_host:").append(isRemoveScriptHost()).append(",\n").append("statusbar:").append(true).append(",\n").append("resize:").append(true).append(",\n").append("menubar:").append(tinyConfig.hasMenu()).append(",\n");
if (isReadOnly()) {
tinyMenuSb.append("readonly: 1,\n");
}
String leftAndClear = "Left and clear";
String rightAndClear = "Right and clear";
String leftAndClearNomargin = "Left with caption";
if (translator != null) {
translator = Util.createPackageTranslator(RichTextConfiguration.class, translator.getLocale(), translator);
leftAndClear = translator.translate("left.clear");
rightAndClear = translator.translate("right.clear");
leftAndClearNomargin = translator.translate("left.clear.nomargin");
}
tinyMenuSb.append("image_class_list: [\n").append(" {title: 'Left', value: 'b_float_left'},\n").append(" {title: '").append(leftAndClear).append("', value: 'b_float_left_clear'},\n").append(" {title: '").append(leftAndClearNomargin).append("', value: 'b_float_left_clear_nomargin'},\n").append(" {title: 'Center', value: 'b_centered'},\n").append(" {title: 'Right', value: 'b_float_right'},\n").append(" {title: '").append(rightAndClear).append("', value: 'b_float_right_clear'},\n").append(" {title: 'Circle', value: 'b_circle'},\n").append(" {title: 'Border', value: 'b_with_border'}\n").append("],\n");
tinyMenuSb.append("link_class_list: [\n").append(" {title: '', value: ''},\n").append(" {title: 'Extern', value: 'b_link_extern'},\n").append(" {title: 'Mail', value: 'b_link_mailto'},\n").append(" {title: 'Forward', value: 'b_link_forward'}\n").append("],\n");
tinyMenuSb.append("table_class_list: [\n").append(" {title: 'Borderless', value: 'b_borderless'},\n").append(" {title: 'Grid', value: 'b_grid'},\n").append(" {title: 'Border', value: 'b_border'},\n").append(" {title: 'Full', value: 'b_full'},\n").append(" {title: 'Middle', value: 'b_middle'},\n").append(" {title: 'Gray', value: 'b_gray'},\n").append(" {title: 'Red', value: 'b_red'},\n").append(" {title: 'Green', value: 'b_green'},\n").append(" {title: 'Blue', value: 'b_blue'},\n").append(" {title: 'Yellow', value: 'b_yellow'}\n").append("],\n");
if (tinyConfig.getTool1() != null) {
tinyMenuSb.append("toolbar1: '").append(tinyConfig.getTool1()).append("',\n");
} else {
tinyMenuSb.append("toolbar:false,\n");
}
if (tinyConfig.hasMenu()) {
tinyMenuSb.append("menu:{\n");
boolean first = true;
for (String menuItem : tinyConfig.getMenu()) {
if (!first)
tinyMenuSb.append("\n,");
if (first)
first = false;
tinyMenuSb.append(menuItem);
}
tinyMenuSb.append("\n},\n");
} else {
tinyMenuSb.append("menu:{},\n");
}
for (Map.Entry<String, String> entry : copyValues.entrySet()) {
tinyMenuSb.append(entry.getKey()).append(": \"").append(entry.getValue()).append("\",\n");
}
for (Map.Entry<String, String> entry : copyNonValues.entrySet()) {
tinyMenuSb.append(entry.getKey()).append(": ").append(entry.getValue()).append(",\n");
}
out.append(tinyMenuSb);
}
use of org.olat.core.gui.render.StringOutput in project openolat by klemens.
the class RichTextElementRenderer method renderTinyMCE_4.
private void renderTinyMCE_4(StringOutput sb, String domID, RichTextElementComponent teC, URLBuilder ubu, Translator translator) {
RichTextElementImpl te = teC.getRichTextElementImpl();
te.setRenderingMode(TextMode.formatted);
RichTextConfiguration config = te.getEditorConfiguration();
List<String> onInit = config.getOnInit();
StringOutput configurations = new StringOutput();
config.appendConfigToTinyJSArray_4(configurations, translator);
if (config.getAdditionalConfiguration() != null) {
config.getAdditionalConfiguration().appendConfigToTinyJSArray_4(configurations, translator);
}
StringOutput baseUrl = new StringOutput();
StaticMediaDispatcher.renderStaticURI(baseUrl, "js/tinymce4/tinymce/tinymce.min.js", true);
// Read write view
renderTinyMCETextarea(sb, domID, teC);
Form form = te.getRootForm();
configurations.append("ffxhrevent: { formNam:\"").append(form.getFormName()).append("\", dispIdField:\"").append(form.getDispatchFieldId()).append("\",").append(" dispId:\"").append(teC.getFormDispatchId()).append("\", eventIdField:\"").append(form.getEventFieldId()).append("\"},\n");
if (te.getMaxLength() > 0) {
configurations.append("maxSize:").append(te.getMaxLength()).append("\n");
}
sb.append("<script type='text/javascript'>/* <![CDATA[ */\n");
// file browser url
sb.append(" BTinyHelper.editorMediaUris.put('").append(domID).append("','");
ubu.buildURI(sb, null, null);
sb.append("');\n");
sb.append(" jQuery('#").append(domID).append("').tinymce({\n").append(" selector: '#").append(domID).append("',\n").append(" script_url: '").append(baseUrl.toString()).append("',\n").append(" setup: function(ed){\n").append(" ed.on('init', function(e) {\n").append(" ").append(onInit.get(0).replace(".curry(", "(")).append(";\n").append(" });\n").append(" ed.on('change', function(e) {\n").append(" BTinyHelper.triggerOnChange('").append(domID).append("');\n").append(" });\n");
if (config.isSendOnBlur()) {
sb.append(" ed.on('blur', function(e) {\n").append(" o_ffXHREvent('").append(form.getFormName()).append("','").append(form.getDispatchFieldId()).append("','").append(teC.getFormDispatchId()).append("','").append(form.getEventFieldId()).append("', 2, false, false, false, 'cmd','saveinlinedtiny','").append(domID).append("',ed.getContent());\n").append(" });\n");
}
sb.append(" },\n").append(configurations).append(" });\n").append("/* ]]> */</script>\n");
}
use of org.olat.core.gui.render.StringOutput in project openolat by klemens.
the class AutoCompleterRenderer method render.
@Override
public void render(Renderer renderer, StringOutput sb, Component source, URLBuilder ubu, Translator translator, RenderResult renderResult, String[] args) {
AutoCompleterComponent cmp = (AutoCompleterComponent) source;
AutoCompleter autoCompleter = cmp.getAutoCompleter();
final int inputSize = 72;
String id = autoCompleter.getFormDispatchId();
if (autoCompleter.isEnabled()) {
boolean showDisplayKey = false;
String mapperUri = autoCompleter.getMapperUri();
int minLength = autoCompleter.getMinLength();
StringOutput command = new StringOutput(64);
ubu.createCopyFor(cmp).openXHREvent(command, null, false, false, new NameValuePair(VelocityContainer.COMMAND_ID, "select"));
sb.append("<input type='text' class='form-control' size='").append(inputSize).append("' id='").append(id).append("' name='").append(id).append("' value=\"");
if (StringHelper.containsNonWhitespace(autoCompleter.getValue())) {
sb.append(StringHelper.escapeHtml(autoCompleter.getValue()));
}
sb.append("\" />");
sb.append("<script type='text/javascript'>\n").append("/* <![CDATA[ */\n").append("jQuery(function(){\n").append(" var fullNameTypeahead = new Bloodhound({\n").append(" datumTokenizer: function (d) {\n").append(" return Bloodhound.tokenizers.whitespace(d.value);\n").append(" },\n").append(" queryTokenizer: Bloodhound.tokenizers.whitespace,\n").append(" remote: {\n").append(" url: '").append(mapperUri).append(// place holder is useless but for tomcat, sometimes it said that the term parameter is corrupted and will not be part of the request send to OpenOLAT
"/?place=holder&term=%QUERY',\n").append(" wildcard: '%QUERY',\n").append(" filter: function ( response ) {\n").append(" return jQuery.map(response, function (object) {\n").append(" return {\n").append(" value: '' + object.key,\n");
if (showDisplayKey) {
sb.append(" fullName: object.displayKey + ': ' + object.value\n");
} else {
sb.append(" fullName: object.value\n");
}
sb.append(" };\n").append(" });\n").append(" }\n").append(" }\n").append(" });\n").append(" fullNameTypeahead.initialize();\n").append(" jQuery('#").append(id).append("').typeahead({\n").append(" hint: false,\n").append(" highlight: false,\n").append(" minLength: ").append(minLength).append("\n").append(" },{\n").append(" minLength: ").append(minLength).append(",\n").append(" displayKey: 'fullName',\n").append(" source: fullNameTypeahead.ttAdapter()\n").append(" }).on('typeahead:selected', function (e, object) {\n").append(" ").append(command).append(",'key',object.value,'value',object.fullName);\n").append(" });\n").append("});\n").append("/* ]]> */\n").append("</script>");
} else {
String value = "";
if (StringHelper.containsNonWhitespace(autoCompleter.getValue())) {
value = autoCompleter.getValue();
}
sb.append("<input id=\"").append(id).append("\" type=\"test\" disabled=\"disabled\" class=\"form-control o_disabled\" size=\"").append(inputSize).append("\" value=\"").append(value).append("\" />").append("</span>");
}
}
use of org.olat.core.gui.render.StringOutput in project openolat by klemens.
the class GuiDebugDispatcherController method createInterceptComponentRenderer.
/*
* (non-Javadoc)
*
* @see org.olat.core.gui.render.debug.DebugHandler#createDebugComponentRenderer(org.olat.core.gui.components.ComponentRenderer)
*/
@Override
public ComponentRenderer createInterceptComponentRenderer(final ComponentRenderer originalRenderer) {
return new ComponentRenderer() {
@Override
public void render(Renderer renderer, StringOutput sb, Component source, URLBuilder ubu, Translator translator, RenderResult renderResult, String[] args) {
if (debugURLBuilder != null && !DebugHelper.isProtected(source)) {
// remember source for later debug info access
String did = source.getDispatchID();
String didS = String.valueOf(did);
idToComponent.put(didS, source);
int lev = renderResult.getNestedLevel();
String cname = source.getClass().getName();
String cnameShort = cname.substring(cname.lastIndexOf('.') + 1);
// header before component
sb.append("<div class='o_dev_w'>");
sb.append("<div class='o_dev_h'><span id='o_guidebugst").append(did).append("' onmouseover=\"o_debu_show(this.parentNode.parentNode, jQuery('#o_guidebugtt").append(did).append("'))\">");
sb.append(source.getComponentName()).append(" (").append(cnameShort).append(")");
sb.append("</span></div>");
sb.append("<div class='o_dev_c'><div id='o_guidebugtt").append(did).append("' class='o_dev_i'>");
sb.append("Info: <b>").append(source.getComponentName()).append("</b> (" + cnameShort + ") id:");
sb.append(String.valueOf(source.getDispatchID())).append(" level:").append(lev);
Controller listC = Util.getListeningControllerFor(source);
if (listC != null) {
sb.append("<br /><b>controller:</b> <a target=\"_blank\" href=\"");
String controllerClassName = listC.getClass().getName();
debugURLBuilder.buildURI(sb, new String[] { "cid", "com", "class" }, new String[] { String.valueOf(did), "ojava", controllerClassName });
sb.append("\">");
sb.append(controllerClassName);
sb.append("</a>");
}
sb.append("<br /><i>listeners</i>: ");
if (!source.isEnabled()) {
sb.append(" NOT ENABLED");
}
String listeners = source.getListenerInfo();
sb.append(listeners);
if (!source.isVisible()) {
sb.append("<br />INVISIBLE");
}
sb.append("<br />");
// we must let the original renderer do its work so that the collecting translator is callbacked.
// we save the result in a new var since it is too early to append it to the 'stream' right now.
StringOutput sbOrig = new StringOutput();
try {
originalRenderer.render(renderer, sbOrig, source, ubu, translator, renderResult, args);
} catch (Exception e) {
String emsg = "exception while rendering component '" + source.getComponentName() + "' (" + source.getClass().getName() + ") " + source.getListenerInfo() + "<br />Message of exception: " + e.getMessage();
sbOrig.append("<span style=\"color:red\">Exception</span><br /><pre>" + emsg + "</pre>");
}
sb.append("</div>");
// add original component
sb.append(sbOrig);
sb.append("</div></div>");
} else {
// e.g. when the render process take place before the delegating
// component of this controller here was rendered.
// the delegating component should be placed near the <html> tag in
// order to be rendered first.
// the contentpane of the window and the first implementing container
// will not be provided with debug info, which is on purpose,
// since those are contents from the chiefcontroller which control the
// window.
// render original component
originalRenderer.render(renderer, sb, source, ubu, translator, renderResult, args);
}
}
@Override
public void renderHeaderIncludes(Renderer renderer, StringOutput sb, Component source, URLBuilder ubu, Translator translator, RenderingState rstate) {
originalRenderer.renderHeaderIncludes(renderer, sb, source, ubu, translator, rstate);
}
@Override
public void renderBodyOnLoadJSFunctionCall(Renderer renderer, StringOutput sb, Component source, RenderingState rstate) {
originalRenderer.renderBodyOnLoadJSFunctionCall(renderer, sb, source, rstate);
}
};
}
Aggregations