Example usage for org.apache.commons.lang3 StringEscapeUtils escapeHtml4

List of usage examples for org.apache.commons.lang3 StringEscapeUtils escapeHtml4

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringEscapeUtils escapeHtml4.

Prototype

public static final String escapeHtml4(final String input) 

Source Link

Document

Escapes the characters in a String using HTML entities.

For example:

"bread" & "butter"

becomes:

"bread" & "butter".

Usage

From source file:org.siphon.jssp.JsspWriter.java

public void printHtml(String s) throws IOException {
    this.print(StringEscapeUtils.escapeHtml4(s));
}

From source file:org.sleuthkit.autopsy.coreutils.EscapeUtil.java

/**
 * Escape html //from   w w  w  .  j ava 2s.c o  m
 * @param toEscape text (with html tags) to escape
 * @return html-escaped string
 */
public static String escapeHtml(String toEscape) {
    return StringEscapeUtils.escapeHtml4(toEscape);
}

From source file:org.spdx.html.ExceptionHtml.java

/**
 * @param exception// w w w  .  j a  v a2 s.  c o m
 */
public ExceptionHtml(SpdxLicenseRestriction exception) {
    ArrayList<String> alSourceUrls = new ArrayList<String>();
    String[] sourceUrls = exception.getSourceUrl();
    if (sourceUrls != null) {
        for (String sourceUrl : sourceUrls) {
            alSourceUrls.add(sourceUrl);
        }
    }
    mustacheMap.put("name", StringEscapeUtils.escapeHtml4(exception.getName()));
    mustacheMap.put("id", StringEscapeUtils.escapeHtml4(exception.getId()));
    mustacheMap.put("text", SpdxLicenseTemplateHelper.escapeHTML(exception.getText()));
    mustacheMap.put("getSourceUrl", alSourceUrls);
    mustacheMap.put("notes", StringEscapeUtils.escapeHtml4(exception.getNotes()));
}

From source file:org.spdx.html.ExceptionHtmlToc.java

/**
 * Add an exception to the table of contents
 * @param exception//from  w  ww.  jav a  2 s .c o m
 * @param exceptionHTMLReference
 */
public void addException(LicenseException exception, String exceptionHTMLReference) {
    exceptions.add(new ExceptionRow(StringEscapeUtils.escapeHtml4(exception.getLicenseExceptionId()),
            StringEscapeUtils.escapeHtml4(exception.getName()), exceptions.size() + 1, exceptionHTMLReference));
}

From source file:org.spdx.html.ExceptionHtmlToc.java

/**
 * Creates and writes an Exception Table of Contents file
 * @param exceptionTocFile file to write to
 * @param version Version of the License List
 * @throws IOException /*ww  w.  j  a va2 s .c o m*/
 * @throws MustacheException 
 */
public void writeToFile(File exceptionTocFile, String version) throws MustacheException, IOException {

    Map<String, Object> mustacheMap = Maps.newHashMap();
    mustacheMap.put("version", StringEscapeUtils.escapeHtml4(version));
    mustacheMap.put("listedExceptions", exceptions);
    FileOutputStream stream = null;
    OutputStreamWriter writer = null;
    if (!exceptionTocFile.exists()) {
        if (!exceptionTocFile.createNewFile()) {
            throw (new IOException("Can not create new file " + exceptionTocFile.getName()));
        }
    }
    String templateDirName = TEMPLATE_ROOT_PATH;
    File templateDirectoryRoot = new File(templateDirName);
    if (!(templateDirectoryRoot.exists() && templateDirectoryRoot.isDirectory())) {
        templateDirName = TEMPLATE_CLASS_PATH;
    }
    try {
        stream = new FileOutputStream(exceptionTocFile);
        writer = new OutputStreamWriter(stream, "UTF-8");
        DefaultMustacheFactory builder = new DefaultMustacheFactory(templateDirName);
        Mustache mustache = builder.compile(HTML_TEMPLATE);
        mustache.execute(writer, mustacheMap);
    } finally {
        if (writer != null) {
            writer.close();
        }
        if (stream != null) {
            stream.close();
        }
    }
}

From source file:org.spdx.html.LicenseHTMLFile.java

/**
 * @return//from  ww  w .j av  a 2 s. com
 * @throws  
 * @throws LicenseTemplateRuleException 
 */
private Map<String, Object> buildMustachMap() throws InvalidLicenseTemplateException {
    Map<String, Object> retval = Maps.newHashMap();
    if (license != null) {
        retval.put("licenseId", license.getLicenseId());
        String licenseTextHtml = license.getLicenseTextHtml();
        retval.put("licenseText", licenseTextHtml);
        retval.put("licenseName", license.getName());
        String notes;
        if (license.getComment() != null && !license.getComment().isEmpty()) {
            notes = license.getComment();
        } else {
            notes = null;
        }
        String templateText = license.getStandardLicenseTemplate();
        if (templateText == null) {
            templateText = StringEscapeUtils.escapeHtml4(license.getLicenseText());
        }
        retval.put("standardLicenseTemplate", templateText);
        retval.put("notes", notes);
        retval.put("osiApproved", license.isOsiApproved());
        retval.put("fsfLibre", license.isFsfLibre());
        retval.put("notFsfLibre", license.isNotFsfLibre());
        List<FormattedUrl> otherWebPages = Lists.newArrayList();
        if (license.getSeeAlso() != null && license.getSeeAlso().length > 0) {
            for (String sourceUrl : license.getSeeAlso()) {
                if (sourceUrl != null && !sourceUrl.isEmpty()) {
                    FormattedUrl formattedUrl = new FormattedUrl(sourceUrl);
                    otherWebPages.add(formattedUrl);
                }
            }
            if (otherWebPages.size() == 0) {
                otherWebPages = null; // Force the template to print None
            }
            retval.put("otherWebPages", otherWebPages);
            retval.put("title", license.getName());
            String header = license.getLicenseHeaderHtml();
            if (header != null && header.trim().isEmpty()) {
                header = null; // so the template will appropriately skip the header text
            }
            retval.put("licenseHeader", header);
        }
    }
    retval.put("deprecated", this.isDeprecated());
    retval.put("deprecatedVersion", this.deprecatedVersion);
    return retval;
}

From source file:org.spdx.html.LicenseTOCHTMLFile.java

private String escapeHTML(String s) {
    return StringEscapeUtils.escapeHtml4(s);
}

From source file:org.squashtest.tm.web.internal.helper.InternationalizableLabelFormatter.java

/**
 * /*from w w  w  .  j  a  va  2 s. c  o  m*/
 * @see org.squashtest.tm.web.internal.helper.LabelFormatter#formatLabel(java.lang.Object)
 */
@Override
public String formatLabel(Internationalizable toFormat) {
    String label = messageSource.getMessage(toFormat.getI18nKey(), null, locale);
    return escapeHtml ? StringEscapeUtils.escapeHtml4(label) : label;
}

From source file:org.squashtest.tm.web.internal.helper.LevelLabelFormatter.java

/**
 * //  w ww  .j a va2 s.c om
 * @see org.squashtest.tm.web.internal.helper.LabelFormatter#formatLabel(java.lang.Object)
 */
@Override
public String formatLabel(Level toFormat) {
    String label = toFormat.getLevel() + "-" + messageSource.getMessage(toFormat.getI18nKey(), null, locale);
    return escapeHtml ? StringEscapeUtils.escapeHtml4(label) : label;
}

From source file:org.uberfire.ext.security.server.XSSServletRequestWrapper.java

@Override
public String[] getParameterValues(final String param) {
    final String[] values = super.getParameterValues(param);

    for (int i = 0; i < values.length; i++) {
        values[i] = StringEscapeUtils.escapeHtml4(values[i]);
    }//from  ww w .  ja va2  s.  co m

    return values;
}