use of org.olat.core.gui.render.StringOutput in project openolat by klemens.
the class AssessmentObjectComponentRenderer method renderBlock.
public void renderBlock(AssessmentRenderer renderer, StringOutput sb, AssessmentObjectComponent component, ResolvedAssessmentItem resolvedAssessmentItem, ItemSessionState itemSessionState, Block block, URLBuilder ubu, Translator translator) {
switch(block.getQtiClassName()) {
case AssociateInteraction.QTI_CLASS_NAME:
case ChoiceInteraction.QTI_CLASS_NAME:
case DrawingInteraction.QTI_CLASS_NAME:
case ExtendedTextInteraction.QTI_CLASS_NAME:
case GapMatchInteraction.QTI_CLASS_NAME:
case GraphicAssociateInteraction.QTI_CLASS_NAME:
case GraphicGapMatchInteraction.QTI_CLASS_NAME:
case GraphicOrderInteraction.QTI_CLASS_NAME:
case HotspotInteraction.QTI_CLASS_NAME:
case SelectPointInteraction.QTI_CLASS_NAME:
case HottextInteraction.QTI_CLASS_NAME:
case MatchInteraction.QTI_CLASS_NAME:
case MediaInteraction.QTI_CLASS_NAME:
case OrderInteraction.QTI_CLASS_NAME:
case PositionObjectInteraction.QTI_CLASS_NAME:
case SliderInteraction.QTI_CLASS_NAME:
case UploadInteraction.QTI_CLASS_NAME:
{
renderInteraction(renderer, sb, (FlowInteraction) block, resolvedAssessmentItem, itemSessionState, component, ubu, translator);
break;
}
case CustomInteraction.QTI_CLASS_NAME:
{
renderCustomInteraction(renderer, sb, (CustomInteraction<?>) block, resolvedAssessmentItem, itemSessionState, component, ubu, translator);
break;
}
case PositionObjectStage.QTI_CLASS_NAME:
{
renderPositionObjectStage(renderer, sb, (PositionObjectStage) block, resolvedAssessmentItem, itemSessionState, component, ubu, translator);
break;
}
// never rendered
case TemplateBlock.QTI_CLASS_NAME:
break;
case InfoControl.QTI_CLASS_NAME:
{
renderInfoControl(renderer, sb, component, resolvedAssessmentItem, itemSessionState, (InfoControl) block, ubu, translator);
break;
}
case FeedbackBlock.QTI_CLASS_NAME:
{
FeedbackBlock feedbackBlock = (FeedbackBlock) block;
if (component.isFeedback(feedbackBlock, itemSessionState)) {
sb.append("<div class='o_info feedbackBlock '").append(getAtClass(feedbackBlock)).append(">");
feedbackBlock.getBlocks().forEach((child) -> renderBlock(renderer, sb, component, resolvedAssessmentItem, itemSessionState, child, ubu, translator));
sb.append("</div>");
}
break;
}
// never rendered automatically
case RubricBlock.QTI_CLASS_NAME:
break;
case Math.QTI_CLASS_NAME:
{
renderMath(renderer, sb, component, resolvedAssessmentItem, itemSessionState, (Math) block);
break;
}
case Div.QTI_CLASS_NAME:
renderStartHtmlTag(sb, component, resolvedAssessmentItem, block, null);
((Div) block).getFlows().forEach((flow) -> renderFlow(renderer, sb, component, resolvedAssessmentItem, itemSessionState, flow, ubu, translator));
renderEndTag(sb, block);
break;
case Ul.QTI_CLASS_NAME:
renderStartHtmlTag(sb, component, resolvedAssessmentItem, block, null);
((Ul) block).getLis().forEach((li) -> renderLi(renderer, sb, component, resolvedAssessmentItem, itemSessionState, li, ubu, translator));
renderEndTag(sb, block);
break;
case Ol.QTI_CLASS_NAME:
renderStartHtmlTag(sb, component, resolvedAssessmentItem, block, null);
((Ol) block).getLis().forEach((li) -> renderLi(renderer, sb, component, resolvedAssessmentItem, itemSessionState, li, ubu, translator));
renderEndTag(sb, block);
break;
case Dl.QTI_CLASS_NAME:
renderStartHtmlTag(sb, component, resolvedAssessmentItem, block, null);
((Dl) block).getDlElements().forEach((dlElement) -> renderDlElement(renderer, sb, component, resolvedAssessmentItem, itemSessionState, dlElement, ubu, translator));
renderEndTag(sb, block);
break;
case Table.QTI_CLASS_NAME:
renderTable(renderer, sb, component, resolvedAssessmentItem, itemSessionState, (Table) block, ubu, translator);
break;
case Object.QTI_CLASS_NAME:
System.out.println("1");
break;
default:
{
renderStartHtmlTag(sb, component, resolvedAssessmentItem, block, null);
if (block instanceof AtomicBlock) {
AtomicBlock atomicBlock = (AtomicBlock) block;
atomicBlock.getInlines().forEach((child) -> renderInline(renderer, sb, component, resolvedAssessmentItem, itemSessionState, child, ubu, translator));
} else if (block instanceof SimpleBlock) {
SimpleBlock simpleBlock = (SimpleBlock) block;
simpleBlock.getBlocks().forEach((child) -> renderBlock(renderer, sb, component, resolvedAssessmentItem, itemSessionState, child, ubu, translator));
}
renderEndTag(sb, block);
}
}
}
use of org.olat.core.gui.render.StringOutput in project openolat by klemens.
the class LinkRenderer method render.
@Override
public void render(Renderer renderer, StringOutput sb, Component source, URLBuilder ubu, Translator translator, RenderResult renderResult, String[] args) {
Link link = (Link) source;
String command = link.getCommand();
AJAXFlags flags = renderer.getGlobalSettings().getAjaxFlags();
// a link may force a non ajax-mode and a custom targ
boolean iframePostEnabled = flags.isIframePostEnabled() && link.isAjaxEnabled() && link.getTarget() == null;
int presentation = link.getPresentation();
/*
* START && beware! order of this if's are relevant
*/
boolean flexiformlink = (presentation - Link.FLEXIBLEFORMLNK) >= 0;
if (flexiformlink) {
presentation = presentation - Link.FLEXIBLEFORMLNK;
}
boolean nontranslated = (presentation - Link.NONTRANSLATED) >= 0;
if (nontranslated) {
presentation = presentation - Link.NONTRANSLATED;
}
/*
* END && beware! order of this if's are relevant
*/
StringBuilder cssSb = new StringBuilder("");
cssSb.append("class=\"");
if (!link.isEnabled()) {
cssSb.append(" o_disabled ");
}
if (link.isActive()) {
cssSb.append(" active ");
}
if (presentation == Link.BUTTON_XSMALL) {
cssSb.append("btn btn-xs ");
cssSb.append(link.isPrimary() ? "btn-primary" : "btn-default");
} else if (presentation == Link.BUTTON_SMALL) {
cssSb.append("btn btn-sm ");
cssSb.append(link.isPrimary() ? "btn-primary" : "btn-default");
} else if (presentation == Link.BUTTON) {
cssSb.append("btn ");
cssSb.append(link.isPrimary() ? "btn-primary" : "btn-default");
} else if (presentation == Link.BUTTON_LARGE) {
cssSb.append("btn btn-lg ");
cssSb.append(link.isPrimary() ? "btn-primary" : "btn-default");
} else if (presentation == Link.LINK_BACK) {
cssSb.append("o_link_back");
} else if (presentation == Link.TOOLENTRY_DEFAULT) {
cssSb.append("o_toolbox_link");
} else if (presentation == Link.TOOLENTRY_CLOSE) {
cssSb.append("o_toolbox_close");
} else if (presentation == Link.LINK_CUSTOM_CSS) {
String customCss = (link.isEnabled() ? link.getCustomEnabledLinkCSS() : link.getCustomDisabledLinkCSS());
cssSb.append(customCss == null ? "" : customCss);
}
if (StringHelper.containsNonWhitespace(link.getElementCssClass())) {
cssSb.append(" ").append(link.getElementCssClass());
}
cssSb.append("\"");
if (link.isEnabled()) {
// only set a target on an enabled link, target in span makes no sense
if (link.getTarget() != null) {
cssSb.append(" target=\"").append(link.getTarget()).append("\"");
}
}
String elementId = link.getElementId();
// String buffer to gather all Javascript stuff with this link
// there is a var elementId = jQuery('#elementId');
// allowing to reference the link as an Ext.Element
// Optimize initial length based on heuristic measurements of extJsSb
StringBuilder jsSb = new StringBuilder(240);
boolean inForm = isInForm(args);
String i18n = link.getI18n();
String title = link.getTitle();
String customDisplayText = link.getCustomDisplayText();
// tooltip sets its own id into the <a> tag.
if (link.isEnabled()) {
sb.append("<p class='form-control-static'>", inForm).append("<a ").append(cssSb);
// need also access to a created and id set. -> avoid "o_c"+link.getDispatchID()
if (elementId != null) {
sb.append(" id=\"").append(elementId).append("\" ");
}
String accessKey = link.getAccessKey();
if (accessKey != null) {
sb.append("accesskey=\"").append(accessKey).append("\" ");
}
if (flexiformlink) {
// no target if flexi form link! because target is set on
// post action of form
Form theForm = (Form) link.getInternalAttachedObject();
sb.append("href=\"javascript:").append(FormJSHelper.getJSFnCallFor(theForm, elementId, 1)).append(";\" ");
if (link.isForceFlexiDirtyFormWarning()) {
sb.append("onclick=\"return o2cl_dirtyCheckOnly();\" ");
}
} else if (link.isPopup()) {
StringOutput href = new StringOutput();
LinkPopupSettings popup = link.getPopup();
ubu.buildURI(href, new String[] { VelocityContainer.COMMAND_ID }, new String[] { command }, null, AJAXFlags.MODE_NORMAL);
sb.append("href=\"javascript:;\" onclick=\"o_openPopUp('").append(href).append("','").append(popup.getTarget()).append("',").append(popup.getWidth()).append(",").append(popup.getHeight()).append("); return false;\" ");
} else {
ubu.buildHrefAndOnclick(sb, null, iframePostEnabled, !link.isSuppressDirtyFormWarning(), true, new NameValuePair(VelocityContainer.COMMAND_ID, command));
}
// tooltips
if (title != null) {
if (!link.isHasTooltip()) {
sb.append(" title=\"");
if (nontranslated) {
sb.append(StringEscapeUtils.escapeHtml(title)).append("\"");
} else {
sb.append(StringEscapeUtils.escapeHtml(translator.translate(title))).append("\"");
}
}
// tooltips based on the extjs library, see webapp/static/js/ext*
if (link.isHasTooltip()) {
String text;
if (nontranslated) {
text = title;
} else {
text = translator.translate(title);
}
sb.append(" title=\"").append(StringEscapeUtils.escapeHtml(text)).append("\"");
}
}
sb.append(">");
// CSS icon
if (link.getIconLeftCSS() != null) {
sb.append("<i class='").append(link.getIconLeftCSS()).append("'");
// one space needed
sb.append("></i> ");
} else if (presentation == Link.LINK_BACK) {
// one space needed
sb.append("<i class='o_icon o_icon_back'></i> ");
}
// inner wrapper for layouting
sb.append("<span>");
if (customDisplayText != null) {
// link is nontranslated but has custom text
sb.append(customDisplayText);
} else if (nontranslated) {
if (i18n != null) {
// link name is not a i18n key
sb.append(i18n);
} else {
sb.append("");
}
} else {
// use translator
if (translator == null) {
sb.append("Ohoho");
} else {
sb.append(translator.translate(i18n));
}
}
sb.append("</span>");
// CSS icon
if (link.getIconRightCSS() != null) {
// one space needed
sb.append(" <i class='").append(link.getIconRightCSS()).append("'");
sb.append("></i> ");
}
if (link.getBadge() != null) {
renderer.render(link.getBadge(), sb, args);
}
sb.append("</a>").append("</p>", inForm);
// on click() is part of prototype.js
if (link.isRegisterForMousePositionEvent()) {
jsSb.append(elementId).append(".click(function(event) {").append(" jQuery('#").append(elementId).append("').each(function(index, el) {;").append(" var href = jQuery(el).attr('href');").append(" if(href.indexOf('x') == -1) jQuery(el).attr('href',href+'x'+event.pageX+'y'+event.pageY+'');").append(" });});");
}
/**
* TODO:gs:b may be usefull as well
* this binds the event to the function call as argument, usefull if event is needed
* Event.observe("id", "click", functionName.bindAsEventListener(this));
*/
if (link.getJavascriptHandlerFunction() != null) {
jsSb.append(elementId).append(".on('").append(link.getMouseEvent()).append("', ").append(link.getJavascriptHandlerFunction()).append(");");
}
/**
* Focus link so that it can be invoked using the enter key using a keyboard.
*/
if (link.isFocus()) {
jsSb.append(elementId).append(".focus();");
}
} else {
String text;
if (customDisplayText != null) {
// link is nontranslated but has custom text
text = customDisplayText;
} else if (nontranslated) {
// link name is not a i18n key
text = (i18n == null ? "" : i18n);
} else {
text = translator.translate(i18n);
}
sb.append("<a ");
if (elementId != null)
sb.append(" id=\"").append(elementId).append("\" ");
String description = link.getTextReasonForDisabling();
// fallback to title
if (description == null)
description = link.getTitle();
if (description != null) {
Matcher msq = singleQuote.matcher(description);
description = msq.replaceAll("'");
Matcher mdq = doubleQutoe.matcher(description);
description = mdq.replaceAll("\\\\\"");
sb.append(" title=\"").append(description).append("\" ");
}
sb.append(cssSb).append(" href='#' onclick='return false;'>");
// CSS icon
if (link.getIconLeftCSS() != null) {
sb.append("<i class='").append(link.getIconLeftCSS()).append("'");
// one space needed
sb.append("></i> ");
}
sb.append("<span>").append(text).append("</span>");
// CSS icon
if (link.getIconRightCSS() != null) {
// one space needed
sb.append(" <i class='").append(link.getIconRightCSS()).append("'");
sb.append("></i> ");
}
sb.append("</a>");
}
if (link.getTarget() != null) {
// if the link starts a download -> the o_afterserver is not called in
// non-ajax mode if a download is started.
// on click execute the "same" javascript as in o_ainvoke(r,true) for
// case 3:
jsSb.append("if (").append(elementId).append(") ").append(elementId).append(".click(function() {setTimeout(removeBusyAfterDownload,1200)});");
}
// now append all gathered javascript stuff if any
if (jsSb.length() > 0) {
// Execute code within an anonymous function (closure) to not leak
// variables to global scope (OLAT-5755)
sb.append(" <script type=\"text/javascript\">\n/* <![CDATA[ */\n").append("(function(){ var ").append(elementId).append(" = jQuery('#").append(elementId).append("');").append(jsSb).append("})();").append("\n/* ]]> */\n</script>");
}
}
use of org.olat.core.gui.render.StringOutput in project openolat by klemens.
the class ExportBinderAsPDFResource method createResultHTML.
private String createResultHTML(Component content) {
String pagePath = Util.getPackageVelocityRoot(this.getClass()) + "/export.html";
VelocityContainer mainVC = new VelocityContainer("html", pagePath, translator, null);
mainVC.put("cmp", content);
mainVC.contextPut("bodyCssClass", "o_portfolio_export");
StringOutput sb = new StringOutput(32000);
URLBuilder ubu = new URLBuilder("auth", "1", "0");
Renderer renderer = Renderer.getInstance(mainVC, translator, ubu, new RenderResult(), new EmptyGlobalSettings());
VelocityRenderDecorator vrdec = new VelocityRenderDecorator(renderer, mainVC, sb);
mainVC.contextPut("r", vrdec);
renderer.render(sb, mainVC, null);
return sb.toString();
}
use of org.olat.core.gui.render.StringOutput in project openolat by klemens.
the class StaticMediaDispatcher method createStaticURIFor.
/**
* Create a static URI for this relative URI. Helper method in case no String
* output is available.
*
* @param URI e.g. img/specialimagenotpossiblewithcss.jpg
* @param addVersionID true: the build version is added to the URL to force
* browser reload the resource when releasing a new version; false:
* don't add version (but allow browsers to cache even when resource
* has changed). Only use false when really needed
* @return
*/
public static String createStaticURIFor(String URI, boolean addVersionID) {
StringOutput so = new StringOutput();
renderStaticURI(so, URI, addVersionID);
return so.toString();
}
use of org.olat.core.gui.render.StringOutput in project openolat by klemens.
the class ChoiceTableDataModel method matchRowWithSearchString.
/**
* Check if the row-value matches with the search-query.
* @param row
* @param tableSearchString2
* @return
*/
private boolean matchRowWithSearchString(final int row, final String tableSearchString2) {
log.debug("matchRowWithFilter: row=" + row + " tableFilterString=" + tableSearchString);
if (!isTableFiltered()) {
return true;
}
// loop over all columns
TableDataModel unfilteredModel = getUnfilteredTableDataModel();
Filter htmlFilter = FilterFactory.getHtmlTagsFilter();
for (int colIndex = getColumnCountFromAllCDs(); colIndex-- > 0; ) {
ColumnDescriptor cd = getColumnDescriptorFromAllCDs(colIndex);
int dataColumn = cd.getDataColumn();
if (dataColumn >= 0 && isColumnDescriptorVisible(cd)) {
Object value = unfilteredModel.getValueAt(row, dataColumn);
// When a CustomCellRenderer exist, use this to render cell-value to String
if (cd instanceof CustomRenderColumnDescriptor) {
CustomRenderColumnDescriptor cdrd = (CustomRenderColumnDescriptor) cd;
CustomCellRenderer customCellRenderer = cdrd.getCustomCellRenderer();
if (customCellRenderer instanceof CustomCssCellRenderer) {
// For css renderers only use the hover
// text, not the CSS class name and other
// HTLM markup
CustomCssCellRenderer cssRenderer = (CustomCssCellRenderer) customCellRenderer;
value = cssRenderer.getHoverText(value);
if (!StringHelper.containsNonWhitespace((String) value)) {
continue;
}
} else {
StringOutput sb = StringOutputPool.allocStringBuilder(250);
customCellRenderer.render(sb, null, value, cdrd.getLocale(), cd.getAlignment(), null);
value = StringOutputPool.freePop(sb);
}
}
if (value instanceof String) {
String valueAsString = (String) value;
// Remove any HTML markup from the value
valueAsString = htmlFilter.filter(valueAsString);
// Finally compare with search value based on a simple lowercase match
if (valueAsString.toLowerCase().indexOf(tableSearchString2.toLowerCase()) != -1) {
return true;
}
}
}
}
return false;
}
Aggregations