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

com.softicar.platform.common.ui.wiki.matchers.WikiParserColorMatcher 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.matchers;

import com.softicar.platform.common.string.scanning.ISimpleTextMatcher;
import com.softicar.platform.common.ui.color.IColor;
import com.softicar.platform.common.ui.color.RgbColor;
import com.softicar.platform.common.ui.wiki.ISimpleWikiParserCallback;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class WikiParserColorMatcher implements ISimpleTextMatcher {

	private static final String COLOR_BEGIN = "");
	private final ISimpleWikiParserCallback callback;
	private String colorCode;

	public WikiParserColorMatcher(ISimpleWikiParserCallback callback) {

		this.callback = callback;
	}

	@Override
	public int getMatchingLength(String text) {

		if (text.startsWith(COLOR_BEGIN)) {
			Matcher matcher = COLOR_BEGIN_PATTERN.matcher(text);
			if (matcher.lookingAt()) {
				this.colorCode = matcher.group(1);
				return matcher.group().length();
			} else {
				return 0;
			}
		} else if (text.startsWith(COLOR_END)) {
			return COLOR_END.length();
		} else {
			return 0;
		}
	}

	@Override
	public void consumeMatchingText(String text) {

		if (text.startsWith(COLOR_BEGIN)) {
			IColor color = RgbColor.parseHtmlCode(colorCode);
			callback.beginColor(color);
		} else if (text.equals(COLOR_END)) {
			callback.endColor();
		} else {
			throw new IllegalArgumentException(String.format("Text '%s' is not matching  pattern.", text));
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy