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 = "
else
label = "
label += "
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;
}