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

The following are Jave code examples for showing how to use escapeHtml4() of the org.apache.commons.lang3.StringEscapeUtils class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: gitplex-mit   File: AssistPanel.java   View Source Code Vote up 7 votes
private Component newSuggestionItem(String itemId, InputCompletion suggestion) {
	WebMarkupContainer item = new WebMarkupContainer(itemId);
	WebMarkupContainer link = new WebMarkupContainer("link");
	Range matchRange = suggestion.getMatchRange();
	String label = suggestion.getLabel();
	if (matchRange != null) {
		String prefix = StringEscapeUtils.escapeHtml4(label.substring(0, matchRange.getFrom()));
		String suffix = StringEscapeUtils.escapeHtml4(label.substring(matchRange.getTo()));
		String matched = StringEscapeUtils.escapeHtml4(label.substring(matchRange.getFrom(), matchRange.getTo()));
		link.add(new Label("label", prefix + "<b>" + matched + "</b>" + suffix).setEscapeModelStrings(false));
	} else {
		link.add(new Label("label", label));
	}
	item.add(link);
	if (suggestion.getDescription() != null)
		item.add(new Label("description", suggestion.getDescription()));
	else
		item.add(new Label("description").setVisible(false));
	item.add(AttributeAppender.append("data-content", suggestion.complete(inputStatus).getContent()));
	item.add(AttributeAppender.append("data-caret", suggestion.getCaret()));
	item.setOutputMarkupId(true);
	return item;
}
 
Example 2
Project: hotelApp   File: ClearServlet.java   View Source Code Vote up 6 votes
/**
 * doPost method to clear particular field of MyPage.
 *
 * @param request
 * @param response
 * @throws IOException
 */
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
    Map<String, List<String>> types = getTypesMap();
    String type = StringEscapeUtils.escapeHtml4(request.getParameter("type"));
    String username = getUsername(request);
    PrintWriter out = response.getWriter();

    if (username != null && types.containsKey(type)) {
        try {
            out.println(dbhandler.clearMyData(types.get(type), username));
        }
        catch (SQLException e) {
            System.out.println(e);
        }
    }
}
 
Example 3
Project: telemarket-skittle-alley   File: UserMsgHandler.java   View Source Code Vote up 6 votes
@Override
public void apply(ApiRequest request, ApiResponse response, WebSocketSession session) {
    String msg = StringEscapeUtils.escapeHtml4(request.getMsg());
    if (StringUtils.isBlank(msg)) {
        return;
    }
    Map<String, Object> attributes = session.getAttributes();
    String id = session.getId();
    DrawPlayerInfo info = ((DrawPlayerInfo) attributes.get("info"));
    DrawGuessContext ctx = (DrawGuessContext) attributes.get("ctx");
    DrawGameStatus status = ctx.status();
    ArrayList<String> msgs = new ArrayList<>(2);
    if (status == DrawGameStatus.RUN) {
        if (StringUtils.equals(id, ctx.getCurrentUser())) {
            protectSecret(info, ctx, msg, msgs);
        } else {
            processGussPerson(info, ctx, msg, msgs);
        }
    } else {
        msgs.add("<b>" + info.getName() + "</b>: " + msg);
    }
    response.setCode(DrawCode.DRAW_MSG.getCode()).setData(msgs);
}
 
Example 4
Project: hotelApp   File: LikeServlet.java   View Source Code Vote up 6 votes
/**
 * doPost method to handle operations: like review, save hotel, check Expedia link.
 *
 * @param request
 * @param response
 * @throws IOException
 */
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
    List<String> types = getTypes();
    String type = StringEscapeUtils.escapeHtml4(request.getParameter("type"));
    String id = StringEscapeUtils.escapeHtml4(request.getParameter("id"));
    String username = getUsername(request);
    PrintWriter out = response.getWriter();

    if (username != null && types.contains(type)) {
        try {
            out.println(dbhandler.setLike(type, id, username));
        }
        catch (SQLException e) {
            System.out.println(e);
        }
    }
}
 
Example 5
Project: DolphinNG   File: JIRAClient.java   View Source Code Vote up 6 votes
/**
 * Prepares the description of bug body. By adding build url, a nice header, a note and
 * excaptes html tags, json tags.
 *
 * @param description
 * @return
 */
private String prepareBugDescriptionForBugCreation(String description)
{
    description = "*[Automation failed tests]*\n" +
            "||Testcase failing|| Parameters||\n" +
            description + "\n" +
            System.getProperty(AUTO_CREATE_ADDITIONAL_DETAILS,
                    configuration.getProperty(AUTO_CREATE_ADDITIONAL_DETAILS, "")) + "\n" +
            "Build url: " + buildUrl;
    description = description + "\n\n\n" + "Note: This bug is created automatically by DolphinNG." +
            " Please do not edit summary line of the bug.";
    description = StringEscapeUtils.escapeHtml3(description);
    description = StringEscapeUtils.escapeHtml4(description);
    description = JSONObject.escape(description);
    return description;
}
 
Example 6
Project: buenojo   File: HangManExerciseOptionResource.java   View Source Code Vote up 5 votes
/**
 * GET  /hangManExercises -> get all the hangManExercises.
 */
@RequestMapping(value = "/hangManExerciseOptions/container/{id}",
    method = RequestMethod.GET,
    produces = MediaType.APPLICATION_JSON_VALUE)
@Timed
public List<Object> getAllHangManOptionByContainer(@PathVariable Long id) {
    log.debug("REST request to get all HangManExercises");
    List<Object> output;
    output= hangManExerciseOptionService.getFixedOptionsRandomOrder(id, 10);
    for (Object o: output)
    	((Object[]) o)[1] = StringEscapeUtils.escapeHtml4(((Object[]) o)[1].toString());
    return output;
}
 
Example 7
Project: scijava-jupyter-kernel   File: ObjectToHTMLNotebookConverter.java   View Source Code Vote up 5 votes
@Override
public HTMLNotebookOutput convert(final Object object) {
    final String escaped = StringEscapeUtils.escapeHtml4(object.toString());
    // Add in zero width space character (&#8203;) before @, ., $, _, and #
    final String wordBreaks = escaped.replaceAll("([@.$_#])", "&#8203;$1");
    return new HTMLNotebookOutput(wordBreaks);
}
 
Example 8
Project: YiDu-Novel   File: TArticle.java   View Source Code Vote up 5 votes
/**
 * 获取HTML格式的小说简介信息
 * 
 * @return HTML格式的小说简介信息
 */
public String getIntroForHtml() {
    if (getIntro() != null) {
        // 替换换行和空格
        String html = StringEscapeUtils.escapeHtml4(getIntro());
        return html.replaceAll("\r\n", "<br/>").replaceAll("\n", "<br/>").replaceAll("\\s", "&nbsp;");
    }
    return null;
}
 
Example 9
Project: ATEBot   File: UserModHandler.java   View Source Code Vote up 5 votes
public static String name(IUser u, IGuild g, boolean showRealName) {
	String s = StringEscapeUtils.escapeHtml4(u.getName()+"#"+u.getDiscriminator());
	if(!u.getName().equals(u.getDisplayName(g)) && showRealName)s+=" ("+u.getDisplayName(g)+") ";
	if(u.isBot())s+=" <span class='usermod_bot'>"+Main.lang.getLangage("tools.usermod.bot").toUpperCase()+"</span>";
	try{if(Main.appid==u.getLongID())s+=" <span class='usermod_me'>"+Main.lang.getLangage("tools.usermod.me").toUpperCase()+"</span>";}catch(Exception e) {}
	return s;
}
 
Example 10
Project: hotelApp   File: MyPageServlet.java   View Source Code Vote up 5 votes
/**
 * doPost method to display user's data in MyPage, five rows of data per request.
 *
 * @param request
 * @param response
 * @throws IOException
 */
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
    Map<String, List<String>> types = getTypesMap();
    String type = StringEscapeUtils.escapeHtml4(request.getParameter("type"));
    int finish = Integer.parseInt(request.getParameter("finish"));
    String username = getUsername(request);

    if (username != null && types.containsKey(type) && finish == 0) {
        try (ResultSet result = dbhandler.getMyData(types.get(type), username)) {
            StringBuilder sb = new StringBuilder();
            PrintWriter out = response.getWriter();
            int data = Integer.parseInt(request.getParameter("data"));
            int count = 0, display = 0;

            while (result.next()) {
                count++;
                if (count > data && display < 5) {
                    display++;
                    sb.append("<tr><td name=\"" + type + "Data\" onclick=\"" + getFunction(type, result) + "\">");
                    sb.append(result.getString(types.get(type).get(3)));
                    sb.append("</td></tr>");
                }
            }

            if (count == 0) {
                sb.append("<tr><td name=\"" + type + "Finish\">No result.</td></tr>");
            }
            else if (count == data + display) {
                sb.append("<tr hidden><td name=\"" + type + "Finish\"></td></tr>");
            }

            out.println(sb.toString());
        }
        catch (SQLException e) {
            System.out.println(e);
        }
    }
}
 
Example 11
Project: convertigo-engine   File: UIText.java   View Source Code Vote up 5 votes
@Override
public String computeTemplate() {
	if (isEnabled()) {
		return StringEscapeUtils.escapeHtml4(getTextValue()) + System.getProperty("line.separator");
	}
	else {
		return "";
	}
}
 
Example 12
Project: Yidu   File: TArticle.java   View Source Code Vote up 5 votes
/**
 * 获取HTML格式的小说简介信息
 * 
 * @return HTML格式的小说简介信息
 */
public String getIntroForHtml() {
    if (getIntro() != null) {
        // 替换换行和空格
        String html = StringEscapeUtils.escapeHtml4(getIntro());
        return html.replaceAll("\r\n", "<br/>").replaceAll("\n", "<br/>").replaceAll("\\s", "&nbsp;");
    }
    return null;
}
 
Example 13
Project: DolphinNG   File: JIRAClient.java   View Source Code Vote up 5 votes
/**
 * Adds a comment to the jira ticket
 *
 * @param jiraTicket - jira ticket id
 * @param comment    - comment to add
 * @return
 * @throws MalformedURLException
 */
public boolean addCommentToIssue(String jiraTicket, String comment) throws MalformedURLException
{
    URL request = new URL("https://" + configuration.getProperty(DEFECT_MGMT_HOST) +
            configuration.getProperty(BUG_API) + "/" + jiraTicket + "/comment");
    comment = comment + "\n\n\n" + "Test Run URL: " + buildUrl;
    comment = comment + "\n" + "Note: This comment is created automatically by DolphinNG.";
    comment = StringEscapeUtils.escapeHtml3(comment);
    comment = StringEscapeUtils.escapeHtml4(comment);
    comment = JSONObject.escape(comment);
    String payload =
            "{" +
                    "\"body\":" + "\"" + comment + "\"" +
                    "}";
    RestAssured.enableLoggingOfRequestAndResponseIfValidationFails();
    RequestSpecification given = RestAssured.given();
    given = given.header(authenticationHeader);
    Response response = given
            .contentType(CONTENT_TYPE_APPLICATION_JSON)
            .accept(CONTENT_TYPE_APPLICATION_JSON)
            .when().body(payload).post(request).then()
            .extract().response();
    LOG.info("JIRA ticket creation result--->  StatusCode=" +
            response.getStatusCode() + " status=" + response.getStatusLine() +
            " payload=" + payload +
            " Response=" + response.getBody().prettyPrint());
    return response.getStatusCode() == 201;
}
 
Example 14
Project: NEILREN4J   File: Encodes.java   View Source Code Vote up 4 votes
/**
 * Html 转码.
 */
public static String escapeHtml(String html) {
    return StringEscapeUtils.escapeHtml4(html);
}
 
Example 15
Project: opencron   File: Encodes.java   View Source Code Vote up 4 votes
/**
 * Html 转码.
 */
public static String escapeHtml(String html) {
    return StringEscapeUtils.escapeHtml4(html);
}
 
Example 16
Project: slides-converter   File: PowerPointToHTML.java   View Source Code Vote up 4 votes
private String escape(String text) {
	return StringEscapeUtils.escapeHtml4(text);
}
 
Example 17
Project: lemon   File: StringUtils.java   View Source Code Vote up 4 votes
public static String escapeHtml(String text) {
    return StringEscapeUtils.escapeHtml4(text);
}
 
Example 18
Project: Yidu   File: SearchAction.java   View Source Code Vote up 3 votes
/**
 * 获取 key
 * 
 * @return key
 */
public String getKey() {
    return StringEscapeUtils.escapeHtml4(key);
}
 
Example 19
Project: IJPay   File: StringUtils.java   View Source Code Vote up 2 votes
/**
 * 转义HTML用于安全过滤
 * @param html
 * @return {String}
 */
public static String escapeHtml(String html) {
	return StringEscapeUtils.escapeHtml4(html);
}
 
Example 20
Project: sling-org-apache-sling-testing-clients   File: XSSUtils.java   View Source Code Vote up 2 votes
/**
 * Use to encapsulate old-style escaping of HTML (using StringEscapeUtils).
 * NB: newer code uses XSSAPI (based on OWASP's ESAPI).
 *
 * @param htmlString the string to be escaped
 * @return the escaped string
 */
public static String escapeHtml(String htmlString) {
    return StringEscapeUtils.escapeHtml4(htmlString);
}