/** * Create a link that can be used within a context help page to link to another context help page * from another package. The link text can be specified as a thirt attribute. * * @param bundleName e.g. "org.olat.core" * @param pageName e.g. "my-page.html" * @return */ public StringOutput contextHelpRelativeLink(String bundleName, String pageName, String linkText) { StringOutput sb = new StringOutput(100); if (ContextHelpModule.isContextHelpEnabled()) { sb.append("<a href=\""); if (bundleName == null) { renderer .getUrlBuilder() .buildURI( sb, new String[] {VelocityContainer.COMMAND_ID}, new String[] {pageName}, isIframePostEnabled ? AJAXFlags.MODE_TOBGIFRAME : AJAXFlags.MODE_NORMAL); } else { renderer .getUrlBuilder() .buildURI( sb, new String[] {VelocityContainer.COMMAND_ID, PARAM_CHELP_BUNDLE}, new String[] {pageName, bundleName}, isIframePostEnabled ? AJAXFlags.MODE_TOBGIFRAME : AJAXFlags.MODE_NORMAL); } sb.append("\" "); if (isIframePostEnabled) { renderer.getUrlBuilder().appendTarget(sb); } sb.append(">"); sb.append(linkText); sb.append("</a>"); } return sb; }
/** * Create a js command to open a specific context help page * * @param packageName * @param pageName * @return */ public StringOutput contextHelpJSCommand(String packageName, String pageName) { StringOutput sb = new StringOutput(100); if (ContextHelpModule.isContextHelpEnabled()) { String langCode = renderer.getTranslator().getLocale().toString(); sb.append("contextHelpWindow('"); Renderer.renderNormalURI(sb, "help/"); sb.append(langCode).append("/").append(packageName).append("/").append(pageName); sb.append("')"); } return sb; }
/** * renders the component. if the component cannot be found, there is no error, but an empty String * is returned. Not recommended to use normally, but rather use @see render(String componentName) * * @param componentName * @return */ public StringOutput renderForce(String componentName) { Component source = renderer.findComponent(componentName); StringOutput sb; if (source == null) { sb = new StringOutput(1); } else if (target == null) { sb = new StringOutput(10000); renderer.render(source, sb, null); } else { renderer.render(source, target, null); } return new StringOutput(1); }
/** * Use it to create the forced non-ajax action for a handmade form in a velocity template, e.g. * '<form method="post" action="$r.formURIgb("viewswitch")">' * * @param command * @return */ public StringOutput formURI(String command) { StringOutput sb = new StringOutput(100); renderer .getUrlBuilder() .buildURI(sb, new String[] {VelocityContainer.COMMAND_ID}, new String[] {command}); return sb; }
/** * renderer a target="oaa" if ajax-mode is on, otherwise returns an empty string * * @return */ public StringOutput bgTarget() { StringOutput sb = new StringOutput(16); if (isIframePostEnabled) { renderer.getUrlBuilder().appendTarget(sb); } return sb; }
/** * @param packageName * @param pageName * @param hoverTextKey * @return */ public StringOutput contextHelp(String packageName, String pageName, String hoverTextKey) { StringOutput sb = new StringOutput(100); if (ContextHelpModule.isContextHelpEnabled()) { String hooverText = renderer.getTranslator().translate(hoverTextKey); if (hooverText != null) { hooverText = StringEscapeUtils.escapeHtml(hooverText); } sb.append("<a href=\"javascript:"); sb.append(contextHelpJSCommand(packageName, pageName)); sb.append("\" title=\"") .append(hooverText) .append("\" class=\"o_chelp\"><i class='o_icon o_icon_help'></i> "); sb.append(renderer.getTranslator().translate("help")); sb.append("</a>"); } return sb; }
public StringOutput contextHelpWithWrapper(String page) { StringOutput sb = new StringOutput(192); if (ContextHelpModule.isContextHelpEnabled()) { HelpModule helpModule = CoreSpringFactory.getImpl(HelpModule.class); Locale locale = renderer.getTranslator().getLocale(); String url = helpModule.getHelpProvider().getURL(locale, page); if (url != null) { sb.append("<span class=\"o_chelp_wrapper\">") .append("<a href=\"") .append(url) .append("\" class=\"o_chelp\" target=\"_blank\"><i class='o_icon o_icon_help'></i> ") .append(renderer.getTranslator().translate("help")) .append("</a></span>"); } } return sb; }
private StringOutput doRender(String componentName, String[] args) { Component source = renderer.findComponent(componentName); StringOutput sb; if (source == null) { sb = new StringOutput(128); sb.append( ">>>>>>>>>>>>>>>>>>>>>>>>>> component " + componentName + " could not be found to be rendered!"); } else if (target == null) { sb = new StringOutput(10000); renderer.render(source, sb, args); } else { sb = new StringOutput(1); renderer.render(source, target, args); } return sb; }
/** * @param command * @return */ public StringOutput commandURI(String command, String paramKey, String paramValue) { StringOutput sb = new StringOutput(100); renderer .getUrlBuilder() .buildURI( sb, new String[] {VelocityContainer.COMMAND_ID, paramKey}, new String[] {command, paramValue}); return sb; }
/** * Creates a java script fragment to execute a background request. In ajax mode the request uses * the ajax asynchronous methods, in legacy mode it uses a standard document.location.request * * @param command * @return */ public StringOutput javaScriptBgCommand(String command) { StringOutput sb = new StringOutput(100); renderer .getUrlBuilder() .buildJavaScriptBgCommand( sb, new String[] {VelocityContainer.COMMAND_ID}, new String[] {command}, isIframePostEnabled ? AJAXFlags.MODE_TOBGIFRAME : AJAXFlags.MODE_NORMAL); return sb; }
/** * Method to translate a key that comes from another package. This should be used rarely. When a * key is used withing multiple packages is is usually better to use a fallback translator or to * move the key to the default packages. * * <p>Used in context help system * * @param bundleName the package name, e.g. 'org.olat.core' * @param key the key, e.g. 'my.key' * @param args optional arguments, null if not used * @return */ public String translateWithPackage(String bundleName, String key, String[] args) { Translator pageTrans = renderer.getTranslator(); if (pageTrans == null) return "{Translator is null: key_to_translate=" + key + "}"; Locale locale = pageTrans.getLocale(); Translator tempTrans = new PackageTranslator(bundleName, locale); String result = tempTrans.translate(key, args); if (result == null) { return "{Invalid bundle name: " + bundleName + " and key: " + key + "}"; } return result; }
/** * @param command * @return */ public StringOutput commandURIbg(String command, String paramKey, String paramValue) { StringOutput sb = new StringOutput(100); renderer .getUrlBuilder() .buildURI( sb, new String[] {VelocityContainer.COMMAND_ID, paramKey}, new String[] {command, paramValue}, isIframePostEnabled ? AJAXFlags.MODE_TOBGIFRAME : AJAXFlags.MODE_NORMAL); return sb; }
/** * @param key * @return */ public String translate(String key) { Translator trans = renderer.getTranslator(); if (trans == null) return "{Translator is null: key_to_translate=" + key + "}"; String res = trans.translate(key); if (res == null) return "?? key not found to translate: key_to_translate=" + key + " / trans info:" + trans + "}"; return res; }
/** * Create a link that can be used within a context help page to link to another context help page * from another package. As link text the page title is used. * * @param bundleName e.g. "org.olat.core" * @param pageName e.g. "my-page.html" * @return */ public StringOutput contextHelpRelativeLink(String bundleName, String pageName) { String linkText; int lastDotPos = pageName.lastIndexOf("."); if (lastDotPos != -1) { Translator pageTrans = renderer.getTranslator(); if (bundleName != null) { Locale locale = pageTrans.getLocale(); pageTrans = new PackageTranslator(bundleName, locale); } linkText = pageTrans.translate("chelp." + pageName.subSequence(0, lastDotPos) + ".title"); } else { linkText = pageName; // fallback } return contextHelpRelativeLink(bundleName, pageName, linkText); }
/** * @param componentName * @return true if the component with name componentName is a child of the current container and * if this component is visible */ public boolean visible(String componentName) { Component source = renderer.findComponent(componentName); return (source != null && source.isVisible()); }
/** * @param componentName * @return true if the component with name componentName is a child of the current container. Used * to "if" the render instruction "$r.render(componentName)" if it is not known beforehand * whether the component is there or not. */ public boolean available(String componentName) { Component source = renderer.findComponent(componentName); return (source != null); }
/** * should be called within the main .html template after the <head>tag. gets some js/css/onLoad * code from the component to render/work correctly. * * @return */ public StringOutput renderHeaderIncludes() { StringOutput sb = new StringOutput(100); renderer.renderHeaderIncludes(sb, vc); return sb; }
protected void renderHeaderButtons( Renderer renderer, StringOutput sb, FlexiTableElementImpl ftE, URLBuilder ubu, Translator translator, RenderResult renderResult, String[] args) { Component searchCmp = ftE.getExtendedSearchComponent(); if (searchCmp == null && !ftE.isExtendedSearchExpanded() && !ftE.isNumOfRowsEnabled() && !ftE.isFilterEnabled() && !ftE.isSortEnabled() && !ftE.isExportEnabled() && !ftE.isCustomizeColumns() && ftE.getAvailableRendererTypes().length <= 1) { return; } if (searchCmp != null && ftE.isExtendedSearchExpanded()) { renderer.render(searchCmp, sb, args); } sb.append("<div class='row clearfix o_table_toolbar'>") .append("<div class='col-sm-6 col-xs-12'>"); if (searchCmp == null || !ftE.isExtendedSearchExpanded()) { renderHeaderSearch(renderer, sb, ftE, ubu, translator, renderResult, args); } sb.append("</div>"); sb.append("<div class='col-sm-3 col-xs-4 o_table_row_count'>"); if (ftE.isNumOfRowsEnabled()) { int rowCount = ftE.getTableDataModel().getRowCount(); if (rowCount == 1) { sb.append(rowCount).append(" ").append(ftE.getTranslator().translate("table.entry")); } else if (rowCount > 1) { sb.append(rowCount).append(" ").append(ftE.getTranslator().translate("table.entries")); } } sb.append( "</div><div class='col-sm-3 col-xs-8'><div class='pull-right'><div class='o_table_tools'>"); boolean empty = ftE.getTableDataModel().getRowCount() == 0; String filterIndication = null; // filter if (ftE.isFilterEnabled()) { List<FlexiTableFilter> filters = ftE.getFilters(); if (filters != null && filters.size() > 0) { filterIndication = renderFilterDropdown(sb, ftE, filters); } } // sort if (ftE.isSortEnabled()) { List<FlexiTableSort> sorts = ftE.getSorts(); if (sorts != null && sorts.size() > 0) { renderSortDropdown(sb, ftE, sorts); } } if (ftE.getExportButton() != null && ftE.isExportEnabled()) { sb.append("<div class='btn-group'>"); ftE.getExportButton().setEnabled(!empty); renderFormItem(renderer, sb, ftE.getExportButton(), ubu, translator, renderResult, args); sb.append("</div> "); } if (ftE.getCustomButton() != null && ftE.isCustomizeColumns()) { sb.append("<div class='btn-group'>"); renderFormItem(renderer, sb, ftE.getCustomButton(), ubu, translator, renderResult, args); sb.append("</div> "); } // switch type of tables FlexiTableRendererType[] types = ftE.getAvailableRendererTypes(); if (types.length > 1) { sb.append("<div class='btn-group'>"); for (FlexiTableRendererType type : types) { renderHeaderSwitchType(type, renderer, sb, ftE, ubu, translator, renderResult, args); } sb.append("</div> "); } sb.append("</div>"); if (StringHelper.containsNonWhitespace(filterIndication)) { sb.append( "<div class='o_table_tools_indications'><i class='o_icon o_icon_filter o_icon-lg'> </i> ") .append(filterIndication) .append("</div>"); } sb.append("</div>"); sb.append("</div></div>"); }
/** * @param renderer * @param vc */ public VelocityRenderDecorator(Renderer renderer, VelocityContainer vc, StringOutput target) { this.renderer = renderer; this.vc = vc; this.target = target; this.isIframePostEnabled = renderer.getGlobalSettings().getAjaxFlags().isIframePostEnabled(); }
/** * e.g. "/olat/" * * @return */ public String relWinLink() { return renderer.getUriPrefix(); }
/** * e.g. "images/somethingicannotdowithcss.jpg" -> * /olat/raw/61x/images/somethingicannotdowithcss.jpg" with /olat/raw/61x/ mounted to * webapp/static directory of your webapp * * @param URI * @return */ public StringOutput staticLink(String URI) { StringOutput sb = new StringOutput(100); Renderer.renderStaticURI(sb, URI); return sb; }
/** * Note: use only rarely - e.g. for static redirects to login screen or to a special dispatcher. * Renders a uri which is mounted to the webapp/ directory of your webapplication. * * <p>For static references (e.g. images which cannot be delivered using css): use renderStaticURI * instead! */ public StringOutput relLink(String URI) { StringOutput sb = new StringOutput(100); Renderer.renderNormalURI(sb, URI); return sb; }
/** * Return the component * * @param componentName * @return */ public Component getComponent(String componentName) { Component source = renderer.findComponent(componentName); return source; }
public String formatDateAndTime(Date date) { Formatter f = Formatter.getInstance(renderer.getTranslator().getLocale()); return f.formatDateAndTime(date); }
/** * should be called within the main .html template after the <head>tag. gets some js/css/onLoad * code from the component to render/work correctly. * * @return */ public StringOutput renderBodyOnLoadJSFunctionCall() { StringOutput sb = new StringOutput(100); renderer.renderBodyOnLoadJSFunctionCall(sb, vc); return sb; }
/** * @see org.olat.core.gui.render.ui.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 target, Component source, URLBuilder ubu, Translator translator, RenderResult renderResult, String[] args) { // Get the model object Choice choice = (Choice) source; ChoiceModel model = choice.getModel(); boolean iframePostEnabled = renderer.getGlobalSettings().getAjaxFlags().isIframePostEnabled(); // form header String id = choice.getComponentName() + "_" + choice.hashCode(); target .append("<form method=\"post\" name=\"") .append(id) .append("\" id=\"") .append(id) .append("\" action=\""); ubu.buildURI( target, null, null, iframePostEnabled ? AJAXFlags.MODE_TOBGIFRAME : AJAXFlags.MODE_NORMAL); target.append("\""); if (iframePostEnabled) { ubu.appendTarget(target); } if (choice.getElementCssClass() != null) { target.append(" class=\"").append(choice.getElementCssClass()).append("\""); } target.append(">"); target.append("<table class=\"o_choice\">"); int rows = model.getRowCount(); for (int i = 0; i < rows; i++) { Boolean val = model.isEnabled(i); boolean selected = val == null ? false : val.booleanValue(); boolean disabled = model.isDisabled(i); String keyN = "c" + i; target .append("<tr><td class='o_choice_checkrow'><input type='checkbox' class='o_checkbox'") .append(" checked='checked'", selected) .append(" disabled='disabled'", disabled) .append(" name='") .append(keyN) .append("' onchange=\"return setFormDirty('") .append(id) .append("')\" />") .append("</td>"); String label = model.getLabel(i); target.append("<td class='o_choice_textrow'>"); if (choice.isEscapeHtml()) { target.append(StringEscapeUtils.escapeHtml(label)); } else { target.append(label); } target.append("</td></tr>"); } // Toggle all on/off target .append("<tr><td colspan='2' class=\"o_togglecheck\">") .append("<div class=\"o_togglecheck o_block_top\">") .append("<a href=\"#\" onclick=\"javascript:o_choice_toggleCheck('" + id + "', true)\">") .append("<i class='o_icon o_icon_fw o_icon_checkbox_checked'></i> ") .append(translator.translate("checkall")) .append( "</a> <a href=\"#\" onclick=\"javascript:o_choice_toggleCheck('" + id + "', false)\">") .append("<i class='o_icon o_icon_fw o_icon_checkbox'></i> ") .append(translator.translate("uncheckall")) .append("</a></div></td></tr>"); // buttons target.append("<tr><td colspan='2'><div class='btn-group btn-group-xs o_block_top'>"); // Submit button target .append("<input type='submit' name='olat_fosm' value=\"") .append(StringEscapeUtils.escapeHtml(translator.translate(choice.getSubmitKey()))) .append("\" class='btn btn-primary' />"); // Reset button String resetKey = choice.getResetKey(); if (resetKey != null) { target .append("<input type='submit' name='") .append(Choice.RESET_IDENTIFICATION) .append("' value=\"") .append(StringEscapeUtils.escapeHtml(translator.translate(resetKey))) .append("\" class='btn btn-default' />"); } // Cancel button String cancelKey = choice.getCancelKey(); if (cancelKey != null) { target .append("<input type='submit' name='") .append(Choice.CANCEL_IDENTIFICATION) .append("' value=\"") .append(StringEscapeUtils.escapeHtml(translator.translate(cancelKey))) .append("\" class='btn btn-default' />"); } target.append("</div></td></tr></table></form>"); }
/** * @see * org.olat.search.service.indexer.AbstractHierarchicalIndexer#doIndex(org.olat.search.service.SearchResourceContext, * java.lang.Object, org.olat.search.service.indexer.OlatFullIndexer) */ @Override public void doIndex( SearchResourceContext parentResourceContext, Object parentObject, OlatFullIndexer indexWriter) throws IOException, InterruptedException { if (!ContextHelpModule.isContextHelpEnabled()) { // don't index context help when disabled return; } long startTime = System.currentTimeMillis(); Set<String> helpPageIdentifyers = ContextHelpModule.getAllContextHelpPages(); Set<String> languages = I18nModule.getEnabledLanguageKeys(); if (log.isDebug()) log.debug( "ContextHelpIndexer helpPageIdentifyers.size::" + helpPageIdentifyers.size() + " and languages.size::" + languages.size()); // loop over all help pages for (String helpPageIdentifyer : helpPageIdentifyers) { String[] identifyerSplit = helpPageIdentifyer.split(":"); String bundleName = identifyerSplit[0]; String page = identifyerSplit[1]; // fxdiff: FXOLAT-221: don't use velocity on images if (page == null || !page.endsWith(".html")) { continue; } // Translator with default locale. Locale is set to each language in the // language iteration below Translator pageTranslator = new PackageTranslator(bundleName, I18nModule.getDefaultLocale()); // Open velocity page for this help page String pagePath = bundleName.replace('.', '/') + ContextHelpModule.CHELP_DIR + page; VelocityContainer container = new VelocityContainer("contextHelpPageVC", pagePath, pageTranslator, null); Context ctx = container.getContext(); GlobalSettings globalSettings = new GlobalSettings() { public int getFontSize() { return 100; } public AJAXFlags getAjaxFlags() { return new EmptyAJAXFlags(); } public ComponentRenderer getComponentRendererFor(Component source) { return null; } public boolean isIdDivsForced() { return false; } }; Renderer renderer = Renderer.getInstance( container, pageTranslator, new EmptyURLBuilder(), null, globalSettings); // Add render decorator with helper methods VelocityRenderDecorator vrdec = new VelocityRenderDecorator(renderer, container, null); ctx.put("r", vrdec); // Add empty static dir url - only used to not generate error messages ctx.put("chelpStaticDirUrl", ""); // Create document for each language using the velocity context for (String langCode : languages) { Locale locale = I18nManager.getInstance().getLocaleOrNull(langCode); String relPagePath = langCode + "/" + bundleName + "/" + page; if (log.isDebug()) log.debug("Indexing help page with path::" + relPagePath); SearchResourceContext searchResourceContext = new SearchResourceContext(parentResourceContext); searchResourceContext.setBusinessControlFor( OresHelper.createOLATResourceableType( ContextHelpModule.class.getSimpleName())); // to match the list of indexer // Create context help document and index now, set translator to current locale pageTranslator.setLocale(locale); Document document = ContextHelpDocument.createDocument( searchResourceContext, bundleName, page, pageTranslator, ctx, pagePath); indexWriter.addDocument(document); } IOUtils.closeQuietly(vrdec); } long indexTime = System.currentTimeMillis() - startTime; if (log.isDebug()) log.debug("ContextHelpIndexer finished in " + indexTime + " ms"); }