⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tablerow.java

📁 jsp写的wiki.比较新
💻 JAVA
字号:
package wiki;

import org.stringtree.regex.Pattern;

import org.stringtree.factory.AbstractStringFetcher;
import org.stringtree.juicer.string.RegexSplitStringFilter;
import org.stringtree.juicer.string.StringFilter;
import org.stringtree.juicer.string.StringStringSource;
import org.stringtree.util.StringUtils;

public class TableRow
	extends AbstractStringFetcher
{
	private static final Pattern bar = Pattern.compile("(?<!\\\\)\\|");

	private void renderCell(StringBuffer buf, String cell, int blanks)
	{
		buf.append("<td");
		if (blanks > 0)
		{
			buf.append(" colspan='");
			buf.append(blanks+1);
			buf.append("'");
		}
		buf.append(">");
		buf.append(cell);
		buf.append("</td>");
	}

	public void renderRow(String row, StringBuffer buf)
	{
		row = row.trim();
		if (row.endsWith("|")) row = row.substring(0,row.length()-1);
		String[] cells = bar.split(row);
		int blanks = 0;
		String lastCell = null;

		buf.append("\n<tr>");

		for (int i = 0; i < cells.length; ++i)
		{
			String cell = cells[i];
			if (StringUtils.isBlank(cell))
			{
				++blanks;
			}
			else
			{
				if(lastCell != null)
				{
					renderCell(buf, lastCell, blanks);
					blanks = 0;
				}
				lastCell = cell;
			}
		}

		if(lastCell != null)
		{
			renderCell(buf, lastCell, blanks);
		}

		buf.append("</tr>");
	}

	public Object getObject(String content)
	{
		StringBuffer buf = new StringBuffer();
		String prev = null;

		StringFilter rows = new RegexSplitStringFilter("(^|\n)\\|");
		rows.connectSource(new StringStringSource(content));

		for (String row = rows.nextString(); row != null; row = rows.nextString())
		{
			if (row.length()==0)
			{
				prev = "|";
			}
			else
			{
				if (prev != null)
				{
					row = prev + row;
				}
				renderRow(row, buf);
			}
		}

		String ret = buf.toString();
		return ret;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -