当前位置: 首页 > 工具软件 > EscapeHTML > 使用案例 >

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

姜鸿
2023-12-01

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;

}

 类似资料: