boolean result = false;
int index = 0;
while (index < galleryTags.size()) {
// Check for error
PageElementTag galleryTag = galleryTags.get(index);
boolean found = false;
if (galleryTag.isFullTag() || !galleryTag.isComplete()) {
found = true;
}
int beginIndex = galleryTag.getBeginIndex();
if (found) {
if (analysis.getSurroundingTag(PageElementTag.TAG_WIKI_NOWIKI, beginIndex) != null) {
found = false;
}
}
if (found) {
if (errors == null) {
return true;
}
result = true;
// Check if an other <gallery> tag is just after and can be used
PageElementTag nextTag = null;
if (!galleryTag.isEndTag() && (index + 1 < galleryTags.size())) {
nextTag = galleryTags.get(index + 1);
int currentIndex = galleryTag.getEndIndex();
while ((nextTag != null) && (currentIndex < nextTag.getBeginIndex())) {
char currentChar = contents.charAt(currentIndex);
if ((currentChar != ' ') && (currentChar != '\n')) {
nextTag = null;
}
currentIndex++;
}
if (nextTag != null) {
if ((galleryTag.getParametersCount() > 0) &&
(nextTag.getParametersCount() > 0)) {
nextTag = null;
}
}
}
// Report error
int endIndex = (nextTag != null) ? nextTag.getEndIndex() : galleryTag.getEndIndex();
CheckErrorResult errorResult = createCheckErrorResult(
analysis, beginIndex, endIndex);
if (nextTag == null) {
errorResult.addReplacement("");
index++;
} else if (nextTag.getParametersCount() == 0) {
errorResult.addReplacement(contents.substring(
galleryTag.getBeginIndex(), galleryTag.getEndIndex()));
errorResult.addReplacement(contents.substring(
nextTag.getBeginIndex(), nextTag.getEndIndex()));
index += 2;
} else {
errorResult.addReplacement(contents.substring(
nextTag.getBeginIndex(), nextTag.getEndIndex()));
errorResult.addReplacement(contents.substring(
galleryTag.getBeginIndex(), galleryTag.getEndIndex()));
index += 2;
}
errors.add(errorResult);