
fitnesse.wikitext.parser.WikiWordBuilder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of fitnesse Show documentation
Show all versions of fitnesse Show documentation
The fully integrated standalone wiki, and acceptance testing framework.
The newest version!
package fitnesse.wikitext.parser;
import fitnesse.html.HtmlTag;
public class WikiWordBuilder {
private final SourcePage currentPage;
private final String linkBody;
private final String wikiWordPath;
private final String qualifiedName;
public WikiWordBuilder(SourcePage currentPage, String pagePath, String linkBody) {
this.currentPage = currentPage;
this.linkBody = linkBody;
this.wikiWordPath = makePath(currentPage, pagePath);
this.qualifiedName = currentPage.makeFullPathOfTarget(wikiWordPath);
}
public String buildLink(String pageSuffix, String originalName) {
if (currentPage.targetExists(wikiWordPath)) {
return makeLinkToExistingWikiPage(qualifiedName + pageSuffix, linkBody, null);
} else if ("FitNesse".equals(originalName)) {
return "" + originalName + "";
} else {
return makeLinkToNonExistentWikiPage(originalName, currentPage.makeUrl(wikiWordPath));
}
}
public String makeEditabeLink(String originalName) {
if (currentPage.targetExists(wikiWordPath)) {
return makeLinkToExistingWikiPage(qualifiedName, linkBody, null) + " " +
makeLinkToExistingWikiPage(qualifiedName + "?edit&redirectToReferer=true&redirectAction=", "(edit)", "edit");
} else {
return makeLinkToNonExistentWikiPage(originalName, currentPage.makeUrl(wikiWordPath));
}
}
private String makePath(SourcePage page, String content) {
if (content.startsWith("^") || content.startsWith(">")) {
return makeChildPath(page, content);
}
if (content.startsWith("<")) {
return makeParentPath(page, content);
}
return content;
}
private String makeLinkToExistingWikiPage(String qualifiedName, String linkBody, String linkClass) {
HtmlTag link = new HtmlTag("a", linkBody);
link.addAttribute("href", qualifiedName);
if (linkClass != null) {
link.addAttribute("class", linkClass);
}
return link.htmlInline();
}
private String makeLinkToNonExistentWikiPage(String text, String url) {
HtmlTag link = new HtmlTag("a", "[?]");
link.addAttribute("title", "create page");
link.addAttribute("href", url+ "?edit&nonExistent=true");
return text + link.htmlInline();
}
private String makeParentPath(SourcePage page, String content) {
return page.findParentPath(content.substring(1));
}
private String makeChildPath(SourcePage page, String content) {
return String.format("%s.%s", page.getName(), content.substring(1));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy