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

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

import java.util.ArrayList;
import java.util.Collection;

public class WikiTableRowToken extends WikiToken {

	private final Collection cells;

	public WikiTableRowToken(String text) {

		super(WikiTokenType.TABLE_ROW, text);

		this.cells = new CellsParser(text).parse();
	}

	public Collection getCells() {

		return cells;
	}

	public static class Cell {

		private final String text;
		private final boolean header;

		public Cell(String text, boolean header) {

			this.text = text;
			this.header = header;
		}

		public String getText() {

			return text;
		}

		public boolean isHeader() {

			return header;
		}
	}

	private class CellsParser {

		private final String text;
		private final Collection parsedCells;
		private StringBuilder builder;
		private boolean header;

		public CellsParser(String text) {

			this.text = text.trim();
			this.parsedCells = new ArrayList<>();
		}

		public Collection parse() {

			this.header = false;
			this.builder = new StringBuilder();
			for (int i = 0; i < text.length(); i++) {
				char character = text.charAt(i);
				if (character == '^' || character == '|') {
					finishCell();
					header = character == '^';
				} else {
					builder.append(character);
				}
			}
			finishCell();
			return parsedCells;
		}

		private void finishCell() {

			if (builder.length() > 0) {
				parsedCells.add(new Cell(builder.toString().trim(), header));
				builder = new StringBuilder();
			}
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy