use of org.olat.core.gui.render.StringOutput in project OpenOLAT by OpenOLAT.
the class VelocityRenderDecorator method contextHelpJSCommand.
/**
* Create a js command to open a specific page in the manual.
*
* @param page Help page name
* @return
*/
public StringOutput contextHelpJSCommand(String page) {
StringOutput sb = new StringOutput(100);
if (helpModule.isHelpEnabled()) {
Locale locale = renderer.getTranslator().getLocale();
String url = helpModule.getHelpProvider().getURL(locale, page);
sb.append("contextHelpWindow('").append(url).append("')");
}
return sb;
}
use of org.olat.core.gui.render.StringOutput in project OpenOLAT by OpenOLAT.
the class VelocityRenderDecorator method renderHeaderIncludes.
/**
* 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;
}
use of org.olat.core.gui.render.StringOutput in project OpenOLAT by OpenOLAT.
the class VelocityRenderDecorator method relLink.
/**
* 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;
}
use of org.olat.core.gui.render.StringOutput in project OpenOLAT by OpenOLAT.
the class VelocityRenderDecorator method getId.
/**
* @param prefix e.g. abc for "abc647547326" and so on
* @return an prefixed id (e.g. f23748932) which is unique in the current render tree.
*/
public StringOutput getId(String prefix) {
StringOutput sb = new StringOutput(16);
sb.append("o_s").append(prefix).append(vc.getDispatchID());
return sb;
}
use of org.olat.core.gui.render.StringOutput in project OpenOLAT by OpenOLAT.
the class InlineTranslationInterceptHandlerController method replaceLocalizationMarkupWithHTML.
/**
* Helper method to replace the translations that are wrapped with some
* identifyer markup by the translator with HTML markup to allow inline
* editing.
* <p>
* This method is public and static to be testable with jUnit.
*
* @param stringWithMarkup The text that contains translated elements that are
* wrapped with some identifyers
* @param inlineTranslationURLBuilder URI builder used to create the inline
* translation links
* @param inlineTrans
* @return
*/
public static String replaceLocalizationMarkupWithHTML(String stringWithMarkup, URLBuilder inlineTranslationURLBuilder, Translator inlineTrans) {
while (stringWithMarkup.indexOf(I18nManager.IDENT_PREFIX) != -1) {
// calculate positions of next localization identifyer
int startSPos = stringWithMarkup.indexOf(I18nManager.IDENT_PREFIX);
int startPostfixPos = stringWithMarkup.indexOf(I18nManager.IDENT_START_POSTFIX);
String combinedKey = stringWithMarkup.substring(startSPos + I18nManager.IDENT_PREFIX.length(), startPostfixPos);
int startEPos = startPostfixPos + I18nManager.IDENT_START_POSTFIX.length();
String endIdent = I18nManager.IDENT_PREFIX + combinedKey + I18nManager.IDENT_END_POSTFIX;
int endSPos = stringWithMarkup.indexOf(endIdent);
int endEPos = endSPos + endIdent.length();
// Build link for this identifyer
StringOutput link = new StringOutput();
// Check if we can parse the combined key
String[] args = combinedKey.split(":");
if (args.length == 3) {
buildInlineTranslationLink(args, link, inlineTrans, inlineTranslationURLBuilder);
} else {
// ups, can not parse combined key? could be for example because
// ContactList.setName() replaced : with fancy ¦ which got HTML escaped
// In any case, we can not produce a translation link for this, do nothing
stringWithMarkup = replaceItemWithoutHTMLMarkup(stringWithMarkup, startSPos, startEPos, endSPos, endEPos);
continue;
}
// Case 1: translated within a 'a' tag. The tag can contain an optional
// span tag
// before and after translated link some other content could be
// No support for i18n text that does contain HTML markup
Matcher m = patternLink.matcher(stringWithMarkup);
boolean foundPos = m.find();
int wrapperOpen = 0;
int wrapperClose = 0;
if (foundPos) {
wrapperOpen = m.start(0);
wrapperClose = m.end(0);
// check if found position does belong to start position
if (wrapperOpen > startSPos) {
foundPos = false;
} else {
// check if link is visible, skip other links
int skipPos = stringWithMarkup.indexOf("o_skip", wrapperOpen);
if (skipPos > -1 && skipPos < wrapperClose) {
stringWithMarkup = replaceItemWithoutHTMLMarkup(stringWithMarkup, startSPos, startEPos, endSPos, endEPos);
continue;
}
// found a valid link pattern, replace it
stringWithMarkup = replaceItemWithHTMLMarkupSurrounded(stringWithMarkup, link, startSPos, startEPos, endSPos, endEPos, wrapperOpen, wrapperClose);
continue;
}
}
// Case 2: translated within an 'input' tag
if (!foundPos) {
m = patternInput.matcher(stringWithMarkup);
foundPos = m.find();
if (foundPos) {
wrapperOpen = m.start(0);
wrapperClose = m.end(0);
// check if found position does belong to start position
if (wrapperOpen > startSPos)
foundPos = false;
else {
// ignore within a checkbox
int checkboxPos = stringWithMarkup.indexOf("checkbox", wrapperOpen);
if (checkboxPos != -1 && checkboxPos < startSPos) {
stringWithMarkup = replaceItemWithoutHTMLMarkup(stringWithMarkup, startSPos, startEPos, endSPos, endEPos);
continue;
}
// ignore within a radio button
int radioPos = stringWithMarkup.indexOf("radio", wrapperOpen);
if (radioPos != -1 && radioPos < startSPos) {
stringWithMarkup = replaceItemWithoutHTMLMarkup(stringWithMarkup, startSPos, startEPos, endSPos, endEPos);
continue;
}
// found a valid input pattern, replace it
stringWithMarkup = replaceItemWithHTMLMarkupSurrounded(stringWithMarkup, link, startSPos, startEPos, endSPos, endEPos, wrapperOpen, wrapperClose);
continue;
}
}
}
// Case 3: translated within a tag attribute of an element - don't offer
// inline translation
m = patAttribute.matcher(stringWithMarkup);
foundPos = m.find();
if (foundPos) {
wrapperOpen = m.start(0);
wrapperClose = m.end(0);
// check if found position does belong to start position
if (wrapperOpen > startSPos)
foundPos = false;
else {
// found a patter in within an attribute, skip this one
stringWithMarkup = replaceItemWithoutHTMLMarkup(stringWithMarkup, startSPos, startEPos, endSPos, endEPos);
continue;
}
}
// Case 4: i18n element in html head - don't offer inline translation
if (startSPos < stringWithMarkup.indexOf(BODY_TAG)) {
// found a pattern in the HTML head, skip this one
stringWithMarkup = replaceItemWithoutHTMLMarkup(stringWithMarkup, startSPos, startEPos, endSPos, endEPos);
continue;
}
// Case 4: default case: normal translation, surround with inline
// translation link
StringBuffer tmp = new StringBuffer();
tmp.append(stringWithMarkup.substring(0, startSPos));
tmp.append(SPAN_TRANSLATION_I18NITEM_OPEN);
tmp.append(link);
tmp.append(stringWithMarkup.substring(startEPos, endSPos));
tmp.append(SPAN_CLOSE);
tmp.append(stringWithMarkup.substring(endEPos));
stringWithMarkup = tmp.toString();
}
return stringWithMarkup;
}
Aggregations