java escape html_Java HtmlEscape.escapeHtml5方法代码示例

import org.unbescape.html.HtmlEscape; //导入方法依赖的package包/类

private Component newItem(String itemId, String itemValue) {

String ref;

if (itemValue.startsWith(COMMIT_FLAG))

ref = itemValue.substring(COMMIT_FLAG.length());

else if (itemValue.startsWith(ADD_FLAG))

ref = itemValue.substring(ADD_FLAG.length());

else

ref = itemValue;

AjaxLink link = new ViewStateAwareAjaxLink("link") {

@Override

protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {

super.updateAjaxAttributes(attributes);

attributes.getAjaxCallListeners().add(new ConfirmLeaveListener());

}

@Override

public void onClick(AjaxRequestTarget target) {

if (itemValue.startsWith(ADD_FLAG)) {

onCreateRef(target, ref);

} else {

selectRevision(target, ref);

}

}

@Override

protected void onComponentTag(ComponentTag tag) {

super.onComponentTag(tag);

if (!itemValue.startsWith(ADD_FLAG)) {

String url = getRevisionUrl(ref);

if (url != null)

tag.put("href", url);

}

}

};

if (itemValue.startsWith(COMMIT_FLAG)) {

link.add(new Label("label", ref));

link.add(AttributeAppender.append("class", "icon commit"));

} else if (itemValue.startsWith(ADD_FLAG)) {

String label;

if (branchesActive)

label = "

Create branch " + HtmlEscape.escapeHtml5(ref) + "
";

else

label = "

Create tag " + HtmlEscape.escapeHtml5(ref) + "
";

label += "

from " + HtmlEscape.escapeHtml5(revision) + "
";

link.add(new Label("label", label).setEscapeModelStrings(false));

link.add(AttributeAppender.append("class", "icon add"));

} else if (ref.equals(revision)) {

link.add(new Label("label", ref));

link.add(AttributeAppender.append("class", "icon current"));

} else {

link.add(new Label("label", ref));

}

WebMarkupContainer item = new WebMarkupContainer(itemId);

item.setOutputMarkupId(true);

item.add(AttributeAppender.append("data-value", HtmlEscape.escapeHtml5(itemValue)));

item.add(link);

return item;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值