List<PageElementTag> refTags = analysis.getTags(PageElementTag.TAG_WIKI_REF);
if ((refTags != null) && (refTags.size() > 0)) {
Iterator<PageElementTag> itRefTags = refTags.iterator();
while (!refFound && itRefTags.hasNext()) {
boolean usefulRef = true;
PageElementTag refTag = itRefTags.next();
if (analysis.getSurroundingTag(PageElementTag.TAG_WIKI_NOWIKI, refTag.getBeginIndex()) != null) {
usefulRef = false;
}
if (usefulRef) {
refFound = true;
}
}
}
if (!refFound) {
return false;
}
// Analyzing text for <references> tags
List<PageElementTag> referencesTags = analysis.getTags(PageElementTag.TAG_WIKI_REFERENCES);
if (referencesTags != null) {
for (PageElementTag referencesTag : referencesTags) {
if (referencesTag.isComplete()) {
return false;
}
}
}
// Search for templates like {{References}}
String templates = getSpecificProperty(
"templates", true, true, false);
if (templates == null) {
templates = getSpecificProperty(
"references_templates", true, true, false);
}
List<String> referencesTemplates = null;
if (templates != null) {
referencesTemplates = WPCConfiguration.convertPropertyToStringList(templates);
}
if (referencesTemplates != null) {
List<PageElementTemplate> allTemplates = analysis.getTemplates();
int templateNum = allTemplates.size();
while (templateNum > 0) {
templateNum--;
PageElementTemplate template = allTemplates.get(templateNum);
for (String referencesTemplate : referencesTemplates) {
if (Page.areSameTitle(template.getTemplateName(), referencesTemplate)) {
return false;
}
}
}
}
// Try to make some suggestions
if (errors == null) {
return true;
}
String contents = analysis.getContents();
if (referencesTags != null) {
for (PageElementTag referencesTag : referencesTags) {
CheckErrorResult errorResult = createCheckErrorResult(
analysis, referencesTag.getBeginIndex(), referencesTag.getEndIndex());
if (referencesTags.size() == 1) {
errorResult.addReplacement(
PageElementTag.createTag(PageElementTag.TAG_WIKI_REFERENCES, true, true),
GT._("Close tag"));
}
errors.add(errorResult);
if (referencesTags.size() == 1) {
int index = referencesTag.getEndIndex();
boolean ok = true;
while (ok && (index < contents.length())) {
char currentChar = contents.charAt(index);
if (Character.isWhitespace(currentChar)) {
index++;
} else if (currentChar == '<') {
PageElementTag tag = analysis.isInTag(index);
if ((tag != null) &&
(tag.getBeginIndex() == index) &&
(PageElementTag.TAG_WIKI_REF.equals(tag.getNormalizedName()))) {
index = tag.getCompleteEndIndex();
} else {
if (contents.startsWith("</references/>", index)) {
errorResult = createCheckErrorResult(analysis, index, index + 14);
errorResult.addReplacement(PageElementTag.createTag(
PageElementTag.TAG_WIKI_REFERENCES, true, false), true);