Example usage for com.liferay.portal.kernel.util EscapableLocalizableFunction getOriginalValue

List of usage examples for com.liferay.portal.kernel.util EscapableLocalizableFunction getOriginalValue

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.util EscapableLocalizableFunction getOriginalValue.

Prototype

public String getOriginalValue(Locale locale) 

Source Link

Usage

From source file:com.liferay.petra.mail.template.internal.DefaultMailTemplate.java

License:Open Source License

@Override
public void render(Writer writer, Locale locale, MailTemplateContext mailTemplateContext) throws IOException {

    Map<String, EscapableLocalizableFunction> replacements = mailTemplateContext.getReplacements();

    String content = _template;/*from w  w  w .  jav a 2 s  .  c  o  m*/

    for (Map.Entry<String, EscapableLocalizableFunction> replacement : replacements.entrySet()) {

        EscapableLocalizableFunction value = replacement.getValue();

        final String valueString;

        if (_escapeHtml) {
            valueString = value.getEscapedValue(locale);
        } else {
            valueString = value.getOriginalValue(locale);
        }

        content = StringUtil.replace(content, replacement.getKey(), valueString);
    }

    EscapableLocalizableFunction escapableLocalizableFunction = replacements.get("[$PORTAL_URL$]");

    if (escapableLocalizableFunction != null) {
        String portalURL = escapableLocalizableFunction.getOriginalValue(locale);

        if (Validator.isNotNull(portalURL)) {
            content = StringUtil.replace(content, new String[] { "href=\"/", "src=\"/" },
                    new String[] { "href=\"" + portalURL + "/", "src=\"" + portalURL + "/" });
        }
    }

    writer.append(content);
}