fitnesse.wikitext.parser.Translator 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;
public abstract class Translator {
private SourcePage currentPage;
protected abstract Translation getTranslation(SymbolType symbolType);
public SourcePage getPage() { return currentPage; }
protected Translator(SourcePage currentPage) {
this.currentPage = currentPage;
}
public String translateTree(Symbol syntaxTree) {
StringBuilder result = new StringBuilder();
for (Symbol symbol : syntaxTree.getChildren()) {
result.append(translate(symbol));
}
return result.toString();
}
public String translate(Symbol symbol) {
if (getTranslation(symbol.getType()) != null) {
return getTranslation(symbol.getType()).toTarget(this, symbol);
}
else {
StringBuilder result = new StringBuilder(symbol.getContent());
for (Symbol child: symbol.getChildren()) {
result.append(translate(child));
}
return result.toString();
}
}
public String formatMessage(String message) {
return translate(new Symbol(SymbolType.Meta).add(message));
}
}