コード例 #1
0
 /** org.olat.presentation.framework.components.Component) */
 @Override
 public void renderBodyOnLoadJSFunctionCall(
     Renderer renderer, StringOutput sb, Component source, RenderingState rstate) {
   HtmlHeaderComponent hc = (HtmlHeaderComponent) source;
   String js = hc.getJsBodyOnLoad();
   if (js != null) sb.append(js);
 }
コード例 #2
0
 /**
  * org.olat.presentation.framework.components.Component,
  * org.olat.presentation.framework.render.URLBuilder,
  * org.olat.presentation.framework.translator.Translator)
  */
 @Override
 public void renderHeaderIncludes(
     Renderer renderer,
     StringOutput sb,
     Component source,
     URLBuilder ubu,
     Translator translator,
     RenderingState rstate) {
   HtmlHeaderComponent hc = (HtmlHeaderComponent) source;
   String header = hc.getHeaderInclude();
   if (header != null) sb.append(header);
 }
コード例 #3
0
ファイル: I18nITCase.java プロジェクト: YaqubGhazi/olat
  /**
   * Test methods i18nManager inline translation tool and
   * InlineTranslationInterceptHandlerController
   */
  @Test
  public void testInlineTranslationReplaceLocalizationMarkupWithHTML() {
    // enable inline translation markup
    i18nMgr.setMarkLocalizedStringsEnabled(null, true);
    Translator inlineTrans =
        PackageUtil.createPackageTranslator(
            InlineTranslationInterceptHandlerController.class, i18nMgr.getLocaleOrNull("de"));
    URLBuilder inlineTranslationURLBuilder = new jUnitURLBuilder();
    String testKey = "no.need.to.translate.this";
    String rawtext1 = "Lorem impsum<b>nice stuff</b>";
    String rawtext2 = "Holderadio <ul>lsdfsdf<y  asdf blblb";
    String combinedKey = bundleName + ":" + testKey;
    // test method that adds identifyers around the translation items
    String plainVanillaWrapped =
        i18nMgr.getLocalizedString(
            bundleName, testKey, null, i18nMgr.getLocaleOrNull("de"), false, false);
    String plainVanillaPlain = "just a test";
    Pattern plainVanillaWrappedPattern =
        Pattern.compile(
            I18nManager.IDENT_PREFIX
                + combinedKey
                + ":([0-9]*?)"
                + I18nManager.IDENT_START_POSTFIX
                + plainVanillaPlain
                + I18nManager.IDENT_PREFIX
                + combinedKey
                + ":\\1"
                + I18nManager.IDENT_END_POSTFIX);
    Matcher m = plainVanillaWrappedPattern.matcher(plainVanillaWrapped);
    assertTrue(m.find());

    // test find-replace translator identifyers with HTML markup
    StringOutput inlineTransLink = new StringOutput();
    String[] args = (combinedKey + ":1000000001").split(":");
    InlineTranslationLinkBuilder.buildInlineTranslationLink(
        args, inlineTransLink, inlineTrans, inlineTranslationURLBuilder);
    // Plain vanilla text
    String convertedToHTMLMarkup =
        LocalizationMarkupHtmlReplacer.replaceLocalizationMarkupWithHTML(
            plainVanillaWrapped, inlineTranslationURLBuilder, inlineTrans);
    assertEquals(
        "<span class=\"b_translation_i18nitem\">"
            + inlineTransLink.toString()
            + plainVanillaPlain
            + "</span>",
        convertedToHTMLMarkup);
    // Simple link
    String linkOPEN =
        "<a href=\"http://www.olat.org/bla/blu:bli#bla\" title='funny title' class=\"b_css b_anothercss\">";
    String linkCLOSE = "</a>";
    String inlineSpanOPEN = "<span class=\"b_translation_i18nitem\">";
    String inlineSpanCLOSE = "</span>";
    String translatedWithinLink = linkOPEN + plainVanillaWrapped + linkCLOSE + rawtext1;
    convertedToHTMLMarkup =
        LocalizationMarkupHtmlReplacer.replaceLocalizationMarkupWithHTML(
            translatedWithinLink, inlineTranslationURLBuilder, inlineTrans);
    String convertedWithinLinkExpected =
        inlineSpanOPEN
            + inlineTransLink.toString()
            + linkOPEN
            + plainVanillaPlain
            + linkCLOSE
            + inlineSpanCLOSE
            + rawtext1;
    assertEquals(convertedWithinLinkExpected, convertedToHTMLMarkup);
    // Simple link with span
    String linkSpanOPEN = "<span class=\"bluber\">";
    String linkSpanCLOSE = "</span>";
    String translatedWithinLinkAndSpan =
        rawtext2 + linkOPEN + linkSpanOPEN + plainVanillaWrapped + linkSpanCLOSE + linkCLOSE;
    convertedToHTMLMarkup =
        LocalizationMarkupHtmlReplacer.replaceLocalizationMarkupWithHTML(
            translatedWithinLinkAndSpan, inlineTranslationURLBuilder, inlineTrans);
    String convertedWithinLinkAndSpanExpected =
        rawtext2
            + inlineSpanOPEN
            + inlineTransLink.toString()
            + linkOPEN
            + linkSpanOPEN
            + plainVanillaPlain
            + linkSpanCLOSE
            + linkCLOSE
            + inlineSpanCLOSE;
    assertEquals(convertedWithinLinkAndSpanExpected, convertedToHTMLMarkup);
    // Muliple links
    String translatedWithinMultipleLinks =
        translatedWithinLink + translatedWithinLinkAndSpan + translatedWithinLinkAndSpan;
    convertedToHTMLMarkup =
        LocalizationMarkupHtmlReplacer.replaceLocalizationMarkupWithHTML(
            translatedWithinMultipleLinks, inlineTranslationURLBuilder, inlineTrans);
    String convertedWithinMultipleLinksExpected =
        convertedWithinLinkExpected
            + convertedWithinLinkAndSpanExpected
            + convertedWithinLinkAndSpanExpected;
    assertEquals(convertedWithinMultipleLinksExpected, convertedToHTMLMarkup);
    // Input elements
    String inputOPEN = "<input type='submit' class=\"bluber\" value=\"";
    String inputCLOSE = "\" />";
    String translatedWithinInput = inputOPEN + plainVanillaWrapped + inputCLOSE + rawtext1;
    convertedToHTMLMarkup =
        LocalizationMarkupHtmlReplacer.replaceLocalizationMarkupWithHTML(
            translatedWithinInput, inlineTranslationURLBuilder, inlineTrans);
    String convertedWithinInputExpected =
        inlineSpanOPEN
            + inlineTransLink.toString()
            + inputOPEN
            + plainVanillaPlain
            + inputCLOSE
            + inlineSpanCLOSE
            + rawtext1;
    assertEquals(convertedWithinInputExpected, convertedToHTMLMarkup);
    // checkbox elements
    String checkboxOPEN = "<input type='submit' class=\"bluber\" type=\"checkbox\" value=\"";
    String checkboxCLOSE = "\" />";
    String translatedWithinCheckbox = checkboxOPEN + plainVanillaWrapped + checkboxCLOSE + rawtext1;
    convertedToHTMLMarkup =
        LocalizationMarkupHtmlReplacer.replaceLocalizationMarkupWithHTML(
            translatedWithinCheckbox, inlineTranslationURLBuilder, inlineTrans);
    String convertedWithinCheckboxExpected =
        checkboxOPEN + plainVanillaPlain + checkboxCLOSE + rawtext1;
    assertEquals(convertedWithinCheckboxExpected, convertedToHTMLMarkup);
    // Input and links mixed
    String translatedWithinMultipleLinksAndInput =
        translatedWithinLink
            + rawtext1
            + translatedWithinInput
            + translatedWithinLinkAndSpan
            + rawtext2
            + translatedWithinInput
            + translatedWithinLinkAndSpan;
    convertedToHTMLMarkup =
        LocalizationMarkupHtmlReplacer.replaceLocalizationMarkupWithHTML(
            translatedWithinMultipleLinksAndInput, inlineTranslationURLBuilder, inlineTrans);
    String convertedWithinMultipleLinksAndInputExpected =
        convertedWithinLinkExpected
            + rawtext1
            + convertedWithinInputExpected
            + convertedWithinLinkAndSpanExpected
            + rawtext2
            + convertedWithinInputExpected
            + convertedWithinLinkAndSpanExpected;
    assertEquals(convertedWithinMultipleLinksAndInputExpected, convertedToHTMLMarkup);
    // Within element attribute
    String attributeOPEN = "<a href='sdfsdf' title=\"";
    String attributeCLOSE = "\" class=\"b_bluber\">hello world</a>";
    String translatedWithinAttribute =
        attributeOPEN + plainVanillaWrapped + attributeCLOSE + rawtext1;
    convertedToHTMLMarkup =
        LocalizationMarkupHtmlReplacer.replaceLocalizationMarkupWithHTML(
            translatedWithinAttribute, inlineTranslationURLBuilder, inlineTrans);
    String convertedWithinAttributeExpected =
        attributeOPEN + plainVanillaPlain + attributeCLOSE + rawtext1;
    assertEquals(convertedWithinAttributeExpected, convertedToHTMLMarkup);
    // Ultimate test
    String translatedUltimate =
        translatedWithinMultipleLinksAndInput
            + rawtext1
            + translatedWithinAttribute
            + translatedWithinMultipleLinksAndInput
            + rawtext2
            + translatedWithinInput
            + translatedWithinLinkAndSpan;
    convertedToHTMLMarkup =
        LocalizationMarkupHtmlReplacer.replaceLocalizationMarkupWithHTML(
            translatedUltimate, inlineTranslationURLBuilder, inlineTrans);
    String convertedUltimateExpected =
        convertedWithinMultipleLinksAndInputExpected
            + rawtext1
            + convertedWithinAttributeExpected
            + convertedWithinMultipleLinksAndInputExpected
            + rawtext2
            + convertedWithinInputExpected
            + convertedWithinLinkAndSpanExpected;
    assertEquals(convertedUltimateExpected, convertedToHTMLMarkup);

    // don't do inline translation markup
    i18nMgr.setMarkLocalizedStringsEnabled(null, false);
  }
コード例 #4
0
ファイル: I18nITCase.java プロジェクト: YaqubGhazi/olat
 public void buildURI(StringOutput buf, String[] keys, String[] values) {
   buf.append("http://do.test.com");
 }