Java Code Examples for org.apache.commons.text.StringEscapeUtils#escapeHtml4()

The following examples show how to use org.apache.commons.text.StringEscapeUtils#escapeHtml4() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SlimFixtureException.java    From hsac-fitnesse-fixtures with Apache License 2.0 6 votes vote down vote up
private static String createMessage(boolean stackTraceInWiki, String message) {
    String result = message;
    if (!stackTraceInWiki) {
        // Until https://github.com/unclebob/fitnesse/issues/731 is fixed
        if (message.contains("\n")) {
            if (!message.startsWith("<") || !message.endsWith(">")) {
                // it is not yet HTML, make it HTML so we can use <br/>
                message = StringEscapeUtils.escapeHtml4(message);
                message = String.format("<div>%s</div>", message);
            }
            message = message.replaceAll("(\\r)?\\n", "<br/>");
        }
        result = String.format("message:<<%s>>", message);
    }
    return result;
}
 
Example 2
Source File: BaseTrackableLinkImpl.java    From openemm with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public String getFullUrlWithExtensions() {
   	try {
		String directLink = createDirectLinkWithOptionalExtensionsWithoutUserData();
		return StringEscapeUtils.escapeHtml4(directLink);
	} catch (UnsupportedEncodingException e) {
		logger.warn("Error creation directory link with optional extension without user data, cause: " + e.getMessage());
		return "";
	}
}
 
Example 3
Source File: EventHandler.java    From openemm with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public Object methodException(@SuppressWarnings("rawtypes") Class aClass, String method, Exception e) throws Exception {
	String exceptionMessage = e.getMessage() != null ? e.getMessage() : "<no exception message>";
	
    String error = "an " + e.getClass().getName() + " was thrown by the " + method
    + " method of the " + aClass.getName() + " class [" + StringEscapeUtils.escapeHtml4(exceptionMessage.split("\n")[0]) + "]";
    errors.add(error, new ActionMessage("Method exception: " + error));
    return error;
}
 
Example 4
Source File: FormattedTextImpl.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
public String escapeHtml(String value, boolean escapeNewlines) {
    /*
     * Velocity tools depend on this returning empty string (and never null),
     * they also depend on this handling a null input and converting it to null
     */
    String val = "";
    if (StringUtils.isNotEmpty(value)){
        val = StringEscapeUtils.escapeHtml4(value);
        if (escapeNewlines && val != null) {
            val = val.replace("\n", "<br/>\n");
        }
    }
    return val;
}
 
Example 5
Source File: FormattedTextImpl.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
public String escapeHtml(String value, boolean escapeNewlines) {
    /*
     * Velocity tools depend on this returning empty string (and never null),
     * they also depend on this handling a null input and converting it to null
     */
    String val = "";
    if (StringUtils.isNotEmpty(value)){
        val = StringEscapeUtils.escapeHtml4(value);
        if (escapeNewlines && val != null) {
            val = val.replace("\n", "<br/>\n");
        }
    }
    return val;
}
 
Example 6
Source File: PagedFileViewer.java    From sailfish-core with Apache License 2.0 5 votes vote down vote up
public String find(String searchString, boolean reverse) throws IOException {

        long tempPageIndex = currentPosition;
        searchString = StringEscapeUtils.escapeHtml4(searchString);

        if (findInCurrentPage) {
            nextPagePosition = currentPosition;
            findInCurrentPage = false;
        }

        while (reverse ? !isPrevPageNotAvailable() : !isNextPageNotAvailable()) {

            String page = reverse ? readPrevPage() : readNextPage();

            if (page.contains(searchString)) {
                notFound = false;
                StringBuilder inserter = new StringBuilder(page);
                int index = 0;
                while (index < inserter.length()) {
                    int phraseIndex = inserter.indexOf(searchString, index);
                    if (phraseIndex != -1) {
                        inserter.insert(phraseIndex, "<span class='highlight'>");
                        int endTagIndex = inserter.indexOf(searchString, index) + searchString.length();
                        inserter.insert(endTagIndex, "</span>");
                        index = endTagIndex;
                    } else {
                        index = inserter.length();
                    }
                }
                return inserter.toString();
            }
        }

        notFound = true;
        findInCurrentPage = true;
        nextPagePosition = tempPageIndex;

        return readNextPage();
    }
 
Example 7
Source File: mdictBuilder.java    From mdict-java with GNU General Public License v3.0 5 votes vote down vote up
public mdictBuilder(String Dictionary_Name, String about,String charset) {
	data_tree= new ArrayListTree<>();
	privateZone = new IntervalTree();
	_Dictionary_Name=Dictionary_Name;
	_about=StringEscapeUtils.escapeHtml4(about);
	if(charset.toUpperCase().startsWith("UTF-16")){
		charset="UTF-16LE";
	}
	_encoding=charset;
	_charset=Charset.forName(_encoding);
	mContentDelimiter="\r\n\0".getBytes(_charset);
}
 
Example 8
Source File: StacktraceHtmlPrinter.java    From beakerx with Apache License 2.0 4 votes vote down vote up
public static String printRedBold(String input) {
  String escaped = StringEscapeUtils.escapeHtml4(input);
  return INSTANCE.startRedBold() + escaped + INSTANCE.endRedBold();
}
 
Example 9
Source File: HTMLEscapeTransformer.java    From LoggerPlusPlus with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public String transform(String string) {
    return StringEscapeUtils.escapeHtml4(string);
}
 
Example 10
Source File: DefaultMarkdownManager.java    From onedev with MIT License 4 votes vote down vote up
@Override
public String escape(String markdown) {
	markdown = StringEscapeUtils.escapeHtml4(markdown);
	markdown = StringUtils.replace(markdown, "\n", "<br>");
	return markdown;
}
 
Example 11
Source File: ViewHelper.java    From fess with Apache License 2.0 4 votes vote down vote up
public String createCacheContent(final Map<String, Object> doc, final String[] queries) {
    final FessConfig fessConfig = ComponentUtil.getFessConfig();
    final FileTemplateLoader loader = new FileTemplateLoader(ResourceUtil.getViewTemplatePath().toFile());
    final Handlebars handlebars = new Handlebars(loader);

    Locale locale = ComponentUtil.getRequestManager().getUserLocale();
    if (locale == null) {
        locale = Locale.ENGLISH;
    }
    String url = DocumentUtil.getValue(doc, fessConfig.getIndexFieldUrl(), String.class);
    if (url == null) {
        url = ComponentUtil.getMessageManager().getMessage(locale, "labels.search_unknown");
    }
    doc.put(fessConfig.getResponseFieldUrlLink(), getUrlLink(doc));
    String createdStr;
    final Date created = DocumentUtil.getValue(doc, fessConfig.getIndexFieldCreated(), Date.class);
    if (created != null) {
        final SimpleDateFormat sdf = new SimpleDateFormat(CoreLibConstants.DATE_FORMAT_ISO_8601_EXTEND);
        createdStr = sdf.format(created);
    } else {
        createdStr = ComponentUtil.getMessageManager().getMessage(locale, "labels.search_unknown");
    }
    doc.put(CACHE_MSG, ComponentUtil.getMessageManager().getMessage(locale, "labels.search_cache_msg", url, createdStr));

    doc.put(QUERIES, queries);

    String cache = DocumentUtil.getValue(doc, fessConfig.getIndexFieldCache(), String.class);
    if (cache != null) {
        final String mimetype = DocumentUtil.getValue(doc, fessConfig.getIndexFieldMimetype(), String.class);
        if (!ComponentUtil.getFessConfig().isHtmlMimetypeForCache(mimetype)) {
            cache = StringEscapeUtils.escapeHtml4(cache);
        }
        cache = ComponentUtil.getPathMappingHelper().replaceUrls(cache);
        if (queries != null && queries.length > 0) {
            doc.put(HL_CACHE, replaceHighlightQueries(cache, queries));
        } else {
            doc.put(HL_CACHE, cache);
        }
    } else {
        doc.put(fessConfig.getIndexFieldCache(), StringUtil.EMPTY);
        doc.put(HL_CACHE, StringUtil.EMPTY);
    }

    try {
        final Template template = handlebars.compile(cacheTemplateName);
        final Context hbsContext = Context.newContext(doc);
        return template.apply(hbsContext);
    } catch (final Exception e) {
        logger.warn("Failed to create a cache response.", e);
    }

    return null;
}
 
Example 12
Source File: XssJacksonDeserializer.java    From hdw-dubbo with Apache License 2.0 4 votes vote down vote up
@Override
public String deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
    return StringEscapeUtils.escapeHtml4(jsonParser.getText());
}
 
Example 13
Source File: XssHttpServletRequestWrapper.java    From hdw-dubbo with Apache License 2.0 4 votes vote down vote up
@Override
public String getParameter(String name) {
    return StringEscapeUtils.escapeHtml4(super.getParameter(name));
}
 
Example 14
Source File: EncryptUtils.java    From platform with Apache License 2.0 4 votes vote down vote up
/**
 * Html转码
 */
public static String escapeHtml(String html) {
    return StringEscapeUtils.escapeHtml4(html);
}
 
Example 15
Source File: DefaultHtmlWriter.java    From doov with Apache License 2.0 4 votes vote down vote up
@Override
public String escapeHtml4(String readable) {
    return StringEscapeUtils.escapeHtml4(readable);
}
 
Example 16
Source File: BufferedContentRenderResult.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
@Override
public String getTitle() throws ToolRenderException {
	return StringEscapeUtils.escapeHtml4(this.config.getTitle());
}
 
Example 17
Source File: PopulateNewsViewHolder.java    From Slide with GNU General Public License v3.0 4 votes vote down vote up
public static void openGif(Activity contextActivity, Submission submission,
        int adapterPosition) {
    if (SettingValues.gif) {
        DataShare.sharedSubmission = submission;

        Intent myIntent = new Intent(contextActivity, MediaView.class);
        myIntent.putExtra(MediaView.SUBREDDIT, submission.getSubredditName());

        GifUtils.AsyncLoadGif.VideoType t =
                GifUtils.AsyncLoadGif.getVideoType(submission.getUrl());

        if (t == GifUtils.AsyncLoadGif.VideoType.DIRECT && submission.getDataNode()
                .has("preview") && submission.getDataNode()
                .get("preview")
                .get("images")
                .get(0)
                .has("variants") && submission.getDataNode()
                .get("preview")
                .get("images")
                .get(0)
                .get("variants")
                .has("mp4")) {
            myIntent.putExtra(MediaView.EXTRA_URL, StringEscapeUtils.unescapeJson(
                    submission.getDataNode()
                            .get("preview")
                            .get("images")
                            .get(0)
                            .get("variants")
                            .get("mp4")
                            .get("source")
                            .get("url")
                            .asText()).replace("&amp;", "&"));
        } else if (t == GifUtils.AsyncLoadGif.VideoType.DIRECT
                && submission.getDataNode()
                .has("media")
                && submission.getDataNode().get("media").has("reddit_video")
                && submission.getDataNode()
                .get("media")
                .get("reddit_video")
                .has("fallback_url")) {
            myIntent.putExtra(MediaView.EXTRA_URL, StringEscapeUtils.unescapeJson(
                    submission.getDataNode()
                            .get("media")
                            .get("reddit_video")
                            .get("fallback_url")
                            .asText()).replace("&amp;", "&"));

        } else {
            myIntent.putExtra(MediaView.EXTRA_URL, submission.getUrl());
        }
        if (submission.getDataNode().has("preview") && submission.getDataNode()
                .get("preview")
                .get("images")
                .get(0)
                .get("source")
                .has("height")) { //Load the preview image which has probably already been cached in memory instead of the direct link
            String previewUrl = StringEscapeUtils.escapeHtml4(submission.getDataNode()
                    .get("preview")
                    .get("images")
                    .get(0)
                    .get("source")
                    .get("url")
                    .asText());
            myIntent.putExtra(MediaView.EXTRA_DISPLAY_URL, previewUrl);
        }
        addAdaptorPosition(myIntent, submission, adapterPosition);
        contextActivity.startActivity(myIntent);
    } else {
        LinkUtil.openExternally(submission.getUrl());
    }

}
 
Example 18
Source File: SkinnableLogin.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
public LoginRenderContext startPageContext(String skin, HttpServletRequest request, HttpServletResponse response)
{
	LoginRenderEngine rengine = loginService.getRenderEngine(loginContext, request);
	LoginRenderContext rcontext = rengine.newRenderContext(request);

	if (StringUtils.isEmpty(skin))
	{
		skin = serverConfigurationService.getString("skin.default", "default");
	}

	String skinRepo = serverConfigurationService.getString("skin.repo");
	String uiService = serverConfigurationService.getString("ui.service", "Sakai");
	String passwordResetUrl = getPasswordResetUrl();

	String xloginChoice = serverConfigurationService.getString("xlogin.choice", null);
	String containerText = serverConfigurationService.getString("login.text.title", "Container Login");
	String loginContainerUrl = serverConfigurationService.getString("login.container.url");

	String eidWording = rb.getString("userid");
	String pwWording = rb.getString("log.pass");
	String loginRequired = rb.getString("log.logreq");
	String loginWording = rb.getString("log.login");
	String cancelWording = rb.getString("log.cancel");
	String passwordResetWording = rb.getString("log.password.reset");

	rcontext.put("action", response.encodeURL(Web.returnUrl(request, null)));
	rcontext.put("pageSkinRepo", skinRepo);
	rcontext.put("pageSkin", skin);
	rcontext.put("uiService", uiService);
	rcontext.put("pageScriptPath", getScriptPath());
	rcontext.put("pageWebjarsPath", getWebjarsPath());
	rcontext.put("loginEidWording", eidWording);
	rcontext.put("loginPwWording", pwWording);
	rcontext.put("loginRequired", loginRequired);
	rcontext.put("loginWording", loginWording);
	rcontext.put("cancelWording", cancelWording);
	rcontext.put("passwordResetUrl", passwordResetUrl);
	rcontext.put("passwordResetWording", passwordResetWording);
	rcontext.put("xloginChoice", xloginChoice);
	rcontext.put("containerText", containerText);
	rcontext.put("loginContainerUrl", loginContainerUrl);

	String eid = StringEscapeUtils.escapeHtml4(request.getParameter("eid"));
	String pw = StringEscapeUtils.escapeHtml4(request.getParameter("pw"));

	if (eid == null)
		eid = "";
	if (pw == null)
		pw = "";

	rcontext.put("eid", eid);
	rcontext.put("password", pw);

	return rcontext;
}
 
Example 19
Source File: Encoder.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 2 votes vote down vote up
/**
 * HTML-escapes the given String.
 * @param object the String.
 * @return an HTML-escaped representation.
 */
public String htmlEncode( String object )
{
    return StringEscapeUtils.escapeHtml4( object );
}
 
Example 20
Source File: XmlUtility.java    From jstarcraft-core with Apache License 2.0 2 votes vote down vote up
/**
 * 对字符串执行HTML4.0加密
 * 
 * @param string
 * @return
 */
public static final String escapeHtml4(String string) {
    return StringEscapeUtils.escapeHtml4(string);
}