All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.softicar.platform.common.ui.wiki.token.matcher.AbstractUrlTokenMatcher Maven / Gradle / Ivy

Go to download

The SoftiCAR Platform is a lightweight, Java-based library to create interactive business web applications.

There is a newer version: 50.0.0
Show newest version
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;
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy