use of org.olat.core.gui.render.StringOutput in project openolat by klemens.
the class UploadAssessmentItemBuilder method extractExtendedTextInteraction.
private void extractExtendedTextInteraction() {
try (StringOutput sb = new StringOutput()) {
List<Block> blocks = assessmentItem.getItemBody().getBlocks();
for (Block block : blocks) {
if (block instanceof UploadInteraction) {
uploadInteraction = (UploadInteraction) block;
responseIdentifier = uploadInteraction.getResponseIdentifier();
break;
} else {
serializeJqtiObject(block, sb);
}
}
question = sb.toString();
} catch (IOException e) {
log.error("", e);
}
}
use of org.olat.core.gui.render.StringOutput in project openolat by klemens.
the class QTI21ResultsExportMediaResource method createResultHTML.
private String createResultHTML(Component results) {
String pagePath = Util.getPackageVelocityRoot(this.getClass()) + "/qti21results.html";
URLBuilder ubu = new URLBuilder("auth", "1", "0");
// generate VelocityContainer and put Component
VelocityContainer mainVC = new VelocityContainer("html", pagePath, translator, null);
mainVC.contextPut("rootTitle", translator.translate("table.grading"));
mainVC.put("results", results);
// render VelocityContainer to StringOutPut
Renderer renderer = Renderer.getInstance(mainVC, translator, ubu, new RenderResult(), new EmptyGlobalSettings());
try (StringOutput sb = new StringOutput(32000);
VelocityRenderDecorator vrdec = new VelocityRenderDecorator(renderer, mainVC, sb)) {
mainVC.contextPut("r", vrdec);
renderer.render(sb, mainVC, null);
vrdec.close();
return sb.toString();
} catch (Exception e) {
log.error("", e);
return "";
}
}
use of org.olat.core.gui.render.StringOutput in project openolat by klemens.
the class EssayAssessmentItemBuilder method extractExtendedTextInteraction.
private void extractExtendedTextInteraction() {
try (StringOutput sb = new StringOutput()) {
List<Block> blocks = assessmentItem.getItemBody().getBlocks();
for (Block block : blocks) {
if (block instanceof ExtendedTextInteraction) {
extendedTextInteraction = (ExtendedTextInteraction) block;
responseIdentifier = extendedTextInteraction.getResponseIdentifier();
break;
} else {
serializeJqtiObject(block, sb);
}
}
question = sb.toString();
} catch (IOException e) {
log.error("", e);
}
}
use of org.olat.core.gui.render.StringOutput in project openolat by klemens.
the class WikiMarkupRenderer method render.
/**
* @see org.olat.core.gui.components.ComponentRenderer#render(org.olat.core.gui.render.Renderer,
* org.olat.core.gui.render.StringOutput,
* org.olat.core.gui.components.Component,
* org.olat.core.gui.render.URLBuilder,
* org.olat.core.gui.translator.Translator,
* org.olat.core.gui.render.RenderResult, java.lang.String[])
*/
@Override
public void render(Renderer renderer, StringOutput sb, Component source, URLBuilder ubu, Translator translator, RenderResult renderResult, String[] args) {
WikiMarkupComponent wikiComp = (WikiMarkupComponent) source;
AJAXFlags flags = renderer.getGlobalSettings().getAjaxFlags();
boolean iframePostEnabled = flags.isIframePostEnabled();
ParserInput input = new ParserInput();
input.setWikiUser(null);
input.setAllowSectionEdit(false);
input.setDepth(10);
input.setContext("");
// input.setTableOfContents(null);
input.setLocale(new Locale("en"));
// input.setVirtualWiki(Long.toString(wikiComp.getOres().getResourceableId()));
input.setTopicName("dummy");
input.setUserIpAddress("0.0.0.0");
OlatWikiDataHandler dataHandler = new OlatWikiDataHandler(wikiComp.getOres(), wikiComp.getImageBaseUri());
input.setDataHandler(dataHandler);
StringOutput out = new StringOutput(100);
ubu.buildURI(out, null, null, iframePostEnabled ? AJAXFlags.MODE_TOBGIFRAME : AJAXFlags.MODE_NORMAL);
String uri = out.toString();
ParserDocument parsedDoc = null;
String uniqueId = "o_wiki".concat(wikiComp.getDispatchID());
try {
uri = URLDecoder.decode(uri, "utf-8");
input.setVirtualWiki(uri.substring(1, uri.length() - 1));
if (iframePostEnabled) {
String targetUrl = " onclick=\"o_XHREvent(jQuery(this).attr('href'),false,true); return false;\"";
input.setURLTarget(targetUrl);
}
sb.append("<div style=\"min-height:" + wikiComp.getMinHeight() + "px\" id=\"");
sb.append(uniqueId);
sb.append("\">");
JFlexParser parser = new JFlexParser(input);
parsedDoc = parser.parseHTML(wikiComp.getWikiContent());
} catch (UnsupportedEncodingException e) {
// encoding utf-8 should be ok
} catch (Exception e) {
throw new OLATRuntimeException(this.getClass(), "error while rendering wiki page with content:" + wikiComp.getWikiContent(), e);
}
// Use global js math formatter for latex formulas
sb.append(Formatter.formatLatexFormulas(parsedDoc.getContent()));
sb.append("</div>");
// set targets of media, image and external links to target "_blank"
sb.append("<script type=\"text/javascript\">/* <![CDATA[ */ ");
String instanceUrl = Settings.getServerContextPathURI();
sb.append("changeAnchorTargets('").append(uniqueId).append("','").append(instanceUrl).append("');");
sb.append("/* ]]> */</script>");
}
use of org.olat.core.gui.render.StringOutput in project openolat by klemens.
the class RepositoryTableModel method addColumnDescriptors.
/**
* @param tableCtr
* @param selectButtonLabel Label of action row or null if no action row should be used
* @param enableDirectLaunch
* @return the position of the display name column
*/
public ColumnDescriptor addColumnDescriptors(TableController tableCtr, boolean selectTitle, boolean selectIcon, boolean remove, boolean infos) {
Locale loc = translator.getLocale();
CustomCellRenderer acRenderer = new RepositoryEntryACColumnDescriptor();
tableCtr.addColumnDescriptor(new CustomRenderColumnDescriptor("table.header.ac", RepoCols.ac.ordinal(), null, loc, ColumnDescriptor.ALIGNMENT_LEFT, acRenderer) {
@Override
public int compareTo(int rowa, int rowb) {
Object o1 = table.getTableDataModel().getObject(rowa);
Object o2 = table.getTableDataModel().getObject(rowb);
if (o1 == null || !(o1 instanceof RepositoryEntry))
return -1;
if (o2 == null || !(o2 instanceof RepositoryEntry))
return 1;
RepositoryEntry re1 = (RepositoryEntry) o1;
RepositoryEntry re2 = (RepositoryEntry) o2;
if (re1.isMembersOnly()) {
if (!re2.isMembersOnly()) {
return 1;
}
} else if (re2.isMembersOnly()) {
return -1;
}
OLATResourceAccess ac1 = repoEntriesWithOffer.get(re1.getOlatResource().getKey());
OLATResourceAccess ac2 = repoEntriesWithOffer.get(re2.getOlatResource().getKey());
if (ac1 == null && ac2 != null)
return -1;
if (ac1 != null && ac2 == null)
return 1;
if (ac1 != null && ac2 != null)
return compareAccess(re1, ac1, re2, ac2);
return super.compareString(re1.getDisplayname(), re2.getDisplayname());
}
private int compareAccess(RepositoryEntry re1, OLATResourceAccess ac1, RepositoryEntry re2, OLATResourceAccess ac2) {
int s1 = ac1.getMethods().size();
int s2 = ac2.getMethods().size();
int compare = s1 - s2;
if (compare != 0)
return compare;
if (s1 > 0 && s2 > 0) {
String t1 = ac1.getMethods().get(0).getMethod().getType();
String t2 = ac2.getMethods().get(0).getMethod().getType();
int compareType = super.compareString(t1, t2);
if (compareType != 0)
return compareType;
}
return super.compareString(re1.getDisplayname(), re2.getDisplayname());
}
});
tableCtr.addColumnDescriptor(new RepositoryEntryTypeColumnDescriptor("table.header.typeimg", RepoCols.repoEntry.ordinal(), null, loc, ColumnDescriptor.ALIGNMENT_LEFT));
String selectAction = selectTitle ? TABLE_ACTION_SELECT_LINK : null;
if (repositoryModule.isManagedRepositoryEntries()) {
tableCtr.addColumnDescriptor(false, new DefaultColumnDescriptor("table.header.externalid", RepoCols.externalId.ordinal(), selectAction, loc));
tableCtr.addColumnDescriptor(new DefaultColumnDescriptor("table.header.externalref", RepoCols.externalRef.ordinal(), selectAction, loc));
}
boolean lfVisible = lifecycleDao.countPublicLifecycle() > 0;
tableCtr.addColumnDescriptor(lfVisible, new DefaultColumnDescriptor("table.header.lifecycle.label", RepoCols.lifecycleLabel.ordinal(), null, loc));
tableCtr.addColumnDescriptor(false, new DefaultColumnDescriptor("table.header.lifecycle.softkey", RepoCols.lifecycleSoftKey.ordinal(), null, loc));
ColumnDescriptor nameColDesc = new DefaultColumnDescriptor("table.header.displayname", RepoCols.displayname.ordinal(), selectAction, loc) {
@Override
public int compareTo(int rowa, int rowb) {
Object o1 = table.getTableDataModel().getValueAt(rowa, 1);
Object o2 = table.getTableDataModel().getValueAt(rowb, 1);
if (o1 == null || !(o1 instanceof RepositoryEntry))
return -1;
if (o2 == null || !(o2 instanceof RepositoryEntry))
return 1;
RepositoryEntry re1 = (RepositoryEntry) o1;
RepositoryEntry re2 = (RepositoryEntry) o2;
boolean c1 = RepositoryManager.getInstance().createRepositoryEntryStatus(re1.getStatusCode()).isClosed();
boolean c2 = RepositoryManager.getInstance().createRepositoryEntryStatus(re2.getStatusCode()).isClosed();
// same as Boolean compare
int result = (c2 == c1 ? 0 : (c1 ? 1 : -1));
if (result == 0) {
Object a = table.getTableDataModel().getValueAt(rowa, dataColumn);
Object b = table.getTableDataModel().getValueAt(rowb, dataColumn);
if (a == null || !(a instanceof String))
return -1;
if (b == null || !(b instanceof String))
return 1;
String s1 = (String) a;
String s2 = (String) b;
result = compareString(s1, s2);
}
return result;
}
};
tableCtr.addColumnDescriptor(nameColDesc);
CustomCellRenderer dateRenderer = new DateCellRenderer(loc);
tableCtr.addColumnDescriptor(false, new CustomRenderColumnDescriptor("table.header.lifecycle.start", RepoCols.lifecycleStart.ordinal(), null, loc, ColumnDescriptor.ALIGNMENT_LEFT, dateRenderer));
tableCtr.addColumnDescriptor(false, new CustomRenderColumnDescriptor("table.header.lifecycle.end", RepoCols.lifecycleEnd.ordinal(), null, loc, ColumnDescriptor.ALIGNMENT_LEFT, dateRenderer));
tableCtr.addColumnDescriptor(new DefaultColumnDescriptor("table.header.author", RepoCols.author.ordinal(), null, loc));
CustomCellRenderer accessRenderer = new RepositoryEntryAccessColumnDescriptor(translator);
ColumnDescriptor accessColDesc = new CustomRenderColumnDescriptor("table.header.access", RepoCols.repoEntry.ordinal(), null, loc, ColumnDescriptor.ALIGNMENT_LEFT, accessRenderer) {
@Override
public int compareTo(int rowa, int rowb) {
Object o1 = table.getTableDataModel().getValueAt(rowa, 1);
Object o2 = table.getTableDataModel().getValueAt(rowb, 1);
if (o1 == null || !(o1 instanceof RepositoryEntry))
return -1;
if (o2 == null || !(o2 instanceof RepositoryEntry))
return 1;
RepositoryEntry re1 = (RepositoryEntry) o1;
RepositoryEntry re2 = (RepositoryEntry) o2;
int ar1 = re1.getAccess();
if (re1.isMembersOnly()) {
ar1 = 99;
}
int ar2 = re2.getAccess();
if (re2.isMembersOnly()) {
ar2 = 99;
}
if (ar1 < ar2)
return -1;
if (ar1 > ar2)
return 1;
return super.compareString(re1.getDisplayname(), re2.getDisplayname());
}
};
tableCtr.addColumnDescriptor(accessColDesc);
tableCtr.addColumnDescriptor(false, new DefaultColumnDescriptor("table.header.date", RepoCols.creationDate.ordinal(), null, loc));
tableCtr.addColumnDescriptor(false, new DefaultColumnDescriptor("table.header.lastusage", RepoCols.lastUsage.ordinal(), null, loc));
if (infos) {
tableCtr.addColumnDescriptor(new StaticColumnDescriptor(TABLE_ACTION_INFOS, "info.header", translator.translate("info.header")) {
@Override
public void renderValue(StringOutput so, int row, Renderer renderer) {
so.append("<i id='o_core").append(row).append("ref' class='o_icon o_icon-lg o_icon_info_resource'> </i>");
}
});
}
if (selectIcon) {
tableCtr.addColumnDescriptor(new StaticColumnDescriptor(TABLE_ACTION_SELECT_LINK, "select", translator.translate("table.select")));
}
if (remove) {
tableCtr.addColumnDescriptor(new StaticColumnDescriptor(TABLE_ACTION_REMOVE_LINK, "remove", translator.translate("remove")));
}
return nameColDesc;
}
Aggregations