Example usage for org.apache.commons.text StringEscapeUtils unescapeEcmaScript

List of usage examples for org.apache.commons.text StringEscapeUtils unescapeEcmaScript

Introduction

In this page you can find the example usage for org.apache.commons.text StringEscapeUtils unescapeEcmaScript.

Prototype

public static final String unescapeEcmaScript(final String input) 

Source Link

Document

Unescapes any EcmaScript literals found in the String .

For example, it will turn a sequence of '\' and 'n' into a newline character, unless the '\' is preceded by another '\' .

Usage

From source file:de.micromata.genome.gwiki.controls.GWikiPageSuggestionsActionBean.java

/**
 * deprecated/* w w w  .ja v a 2  s. c  om*/
 * 
 * @return
 */
public Object onLinkAutocomplete() {
    String format = wikiContext.getRequestParameter("f");
    String q = wikiContext.getRequestParameter("q");
    String pageType = wikiContext.getRequestParameter("pageType");
    String queryexpr = SearchUtils.createLinkExpression(q, true, pageType);
    SearchQuery query = new SearchQuery(queryexpr, wikiContext.getWikiWeb());

    query.setMaxCount(1000);
    QueryResult qr = filter(query);
    StringBuilder sb = new StringBuilder();
    // int size = qr.getResults().size();
    if (StringUtils.equals(format, "json") == true) {
        wikiContext.getResponse().setContentType("application/json");
        sb.append("[");
        boolean first = true;
        for (SearchResult sr : qr.getResults()) {
            if (first == false) {
                sb.append(",");
            } else {
                first = false;
            }
            String tti = wikiContext.getTranslatedProp(sr.getElementInfo().getTitle());
            sb.append("{ pageId: '").append(sr.getPageId()).append("', title: '")
                    .append(StringEscapeUtils.unescapeEcmaScript(tti)).append("'}");
            //        sb.append("'").append(sr.getPageId()).append("'");
        }
        sb.append("]");
    } else {
        for (SearchResult sr : qr.getResults()) {
            sb.append(sr.getPageId()).append("|")
                    .append(wikiContext.getTranslatedProp(sr.getElementInfo().getTitle())).append("\n");
        }
    }
    wikiContext.append(sb.toString());
    wikiContext.flush();
    return noForward();
}