com.softicar.platform.common.ui.wiki.token.matcher.AbstractUrlTokenMatcher Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of platform-common Show documentation
Show all versions of platform-common Show documentation
The SoftiCAR Platform is a lightweight, Java-based library to create interactive business web applications.
package com.softicar.platform.common.ui.wiki.token.matcher;
import com.softicar.platform.common.ui.wiki.token.WikiToken;
import com.softicar.platform.common.ui.wiki.tokenizer.IWikiTokenizer;
import java.util.Optional;
import java.util.function.Function;
public class AbstractUrlTokenMatcher implements IWikiTokenMatcher {
private final String begin;
private final String end;
private final Function tokenFactory;
public AbstractUrlTokenMatcher(String begin, String end, Function tokenFactory) {
this.begin = begin;
this.end = end;
this.tokenFactory = tokenFactory;
}
@Override
public boolean match(IWikiTokenizer tokenizer) {
if (tokenizer.startsWith(begin)) {
Optional endIndex = tokenizer.findIndexOf(end);
if (endIndex.isPresent()) {
String text = tokenizer.getSubstring(0, endIndex.get() + 2);
tokenizer.addToken(tokenFactory.apply(text));
return true;
} else {
return false;
}
} else {
return false;
}
}
}