end++;
}
if (end > internalLink.getEndIndex()) {
text = text + contents.substring(internalLink.getEndIndex(), end);
}
ConfigurationValueStyle styleType = null;
if (disambiguation) {
styleType = ConfigurationValueStyle.INTERNAL_LINK_DAB;
// Check if a template is after the link to ask for help
List<String> templatesAfter = wikipedia.getConfiguration().getStringList(
WPCConfigurationStringList.TEMPLATES_AFTER_HELP_ASKED);
if ((templatesAfter != null) && !templatesAfter.isEmpty()) {
int maxSize = contents.length();
int currentPos = end;
while ((currentPos < maxSize) && (contents.charAt(currentPos) == ' ')) {
currentPos++;
}
if ((currentPos < maxSize) && (contents.charAt(currentPos) == '{')) {
PageElementTemplate nextTemplate = pageAnalysis.isInTemplate(currentPos);
if (nextTemplate != null) {
for (String templateAfter : templatesAfter) {
if (Page.areSameTitle(templateAfter, nextTemplate.getTemplateName())) {
styleType = ConfigurationValueStyle.HELP_REQUESTED;
end = nextTemplate.getEndIndex();
}
}
}
}
}
List<String> commentsAfter = wikipedia.getConfiguration().getStringList(
WPCConfigurationStringList.COMMENTS_FOR_DAB_LINK);
if ((commentsAfter != null) && !commentsAfter.isEmpty()) {
int maxSize = contents.length();
int currentPos = end;
while ((currentPos < maxSize) && (contents.charAt(currentPos) == ' ')) {
currentPos++;
}
if ((currentPos < maxSize) && (contents.charAt(currentPos) == '<')) {
PageElementComment comment = pageAnalysis.isInComment(currentPos);
if (comment != null) {
for (String commentAfter : commentsAfter) {
String comment2 = comment.getComment();
if ((comment2 != null) && (comment2.length() >= commentAfter.length())) {
comment2 = comment2.substring(0, commentAfter.length());
if (comment2.equalsIgnoreCase(commentAfter)) {
styleType = ConfigurationValueStyle.INTERNAL_LINK_NORMAL;
end = comment.getEndIndex();
}
}
}
}
}
}
} else if (link.isRedirect()) {
styleType = ConfigurationValueStyle.INTERNAL_LINK_REDIRECT;
} else if (Boolean.TRUE.equals(link.isExisting())) {
styleType = ConfigurationValueStyle.INTERNAL_LINK_NORMAL;
} else {
styleType = ConfigurationValueStyle.INTERNAL_LINK_MISSING;
}
Style attr = doc.getStyle(styleType.getName());
if (attr == null) {
return;
}
attr = (Style) attr.copyAttributes();
attr.addAttribute(ATTRIBUTE_PAGE, link);