protected void appendInternalLink(String topic, String hashSection,
String topicDescription, String cssClass, boolean parseRecursive,
boolean topicExists) {
String hrefLink;
String description = topicDescription.trim();
WPATag aTagNode = new WPATag();
if (topic.length() > 0) {
String title = Encoder.normaliseTitle(topic, true, ' ', true);
if (hashSection == null) {
String pageName = Encoder.normaliseTitle(fPageTitle, true, ' ',
true);
// self link?
if (title.equals(pageName)) {
HTMLTag selfLink = new HTMLTag("strong");
selfLink.addAttribute("class", "selflink", false);
pushNode(selfLink);
selfLink.addChild(new ContentToken(description));
popNode();
return;
}
}
String encodedtopic = encodeTitleToUrl(topic, true);
if (replaceColon()) {
encodedtopic = encodedtopic.replace(':', '/');
}
hrefLink = getWikiBaseURL().replace("${title}", encodedtopic);
if (!topicExists) {
if (cssClass == null) {
cssClass = "new";
}
if (hrefLink.indexOf('?') != -1) {
hrefLink += "&";
} else {
hrefLink += "?";
}
hrefLink += "action=edit&redlink=1";
String redlinkString = Messages.getString(getResourceBundle(),
Messages.WIKI_TAGS_RED_LINK,
"${title} (page does not exist)");
title = redlinkString.replace("${title}", title);
}
aTagNode.addAttribute("title", title, true);
} else {
// assume, the own topic exists
if (hashSection != null) {
hrefLink = "";
if (description.length() == 0) {
description = "#" + hashSection; // #....
}
} else {
hrefLink = getWikiBaseURL().replace("${title}", "");
}
}
String href = hrefLink;
if (topicExists && hashSection != null) {
href = href + '#' + encodeTitleDotUrl(hashSection, false);
}
aTagNode.addAttribute("href", href, true);
if (cssClass != null) {
aTagNode.addAttribute("class", cssClass, true);
}
aTagNode.addObjectAttribute("wikilink", topic);
pushNode(aTagNode);
if (parseRecursive) {
WikipediaPreTagParser
.parseRecursive(description, this, false, true);
} else {
aTagNode.addChild(new ContentToken(description));
}
popNode();
}