StringBuilder html = new StringBuilder();
if (!references.isEmpty()) {
html.append("<ol class=\"references\">");
}
while (!references.isEmpty()) {
WikiReference reference = references.get(0);
references.remove(0);
html.append("<li id=\"").append(reference.getNotationName()).append("\">");
html.append("<sup>");
int pos = 0;
List<WikiReference> citations = new ArrayList<WikiReference>();
while (pos < references.size()) {
WikiReference temp = references.get(pos);
if (temp.getName() != null && reference.getName() != null && reference.getName().equals(temp.getName())) {
citations.add(temp);
if (StringUtils.isBlank(reference.getContent()) && !StringUtils.isBlank(temp.getContent())) {
reference.setContent(temp.getContent());
}
references.remove(pos);
continue;
}
pos++;
}
if (!citations.isEmpty()) {
html.append("<a href=\"#").append(reference.getReferenceName()).append("\" title=\"\">");
html.append(reference.getCitation()).append('.').append(reference.getCount()).append("</a> ");
while (!citations.isEmpty()) {
WikiReference citation = citations.get(0);
html.append(" <a href=\"#").append(citation.getReferenceName()).append("\" title=\"\">");
html.append(citation.getCitation()).append('.').append(citation.getCount()).append("</a> ");
citations.remove(0);
}
} else {
html.append("<a href=\"#").append(reference.getReferenceName()).append("\" title=\"\">");
html.append(reference.getCitation()).append("</a> ");