// Path: src/main/java/com/neva/felix/webconsole/plugins/search/utils/PrettifierUtils.java
// public final class PrettifierUtils {
// 
// 	private PrettifierUtils() {
// 		// hidden constructor
// 	}
// 
// 	public static String escape(String source) {
// 		String[] search = { "<", ">", };
// 		String[] replace = { "&lt;", "&gt;" };
// 
// 		return StringUtils.replaceEach(source, search, replace);
// 	}
// 
// 	public static String highlight(String line) {
// 		return String.format("<span class=\"highlighted\">%s</span>", line);
// 	}
// 
// }


import com.neva.felix.webconsole.plugins.search.utils.PrettifierUtils;
import com.google.common.base.Joiner;
import com.google.common.base.Splitter;
import com.google.common.collect.Lists;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.io.IOCase;
import org.apache.commons.lang3.StringUtils;
import java.util.Collections;
import java.util.List;
import java.util.Map;

	/**
	 * Compose human readable parameter list as description
	 */
	public static String composeDescription(Map<String, Object> params) {
		List<String> lines = Lists.newArrayList();
		for (Map.Entry<String, Object> entry : params.entrySet()) {
			Object value = entry.getValue();
			if (value instanceof String[]) {
				value = "[" + StringUtils.join((String[] )value, ", ") + "]";
			}

			lines.add(String.format("%s: %s", entry.getKey(), value));
		}

		return StringUtils.join(lines, "\n");
	}

	public static List<String> findContexts(String phrase, String source, int contextLineCount) {
		List<String> contexts = Lists.newLinkedList();
		List<String> lines = Splitter.on(LINE_DELIMITER).splitToList(source);

		int i = 0;
		for (String line : lines) {
			if (StringUtils.containsIgnoreCase(line, phrase)) {
				String before = Joiner.on("\n")
						.join(lines.subList(Math.max(0, i - contextLineCount - 1), Math.max(0, i - 1)));
				String after = Joiner.on("\n").join(lines.subList(Math.min(i + 1, lines.size()),
						Math.min(lines.size(), i + 1 + contextLineCount)));
				String context = PrettifierUtils.escape(before) + "\n" + PrettifierUtils
// Path: src/main/java/com/neva/felix/webconsole/plugins/search/utils/PrettifierUtils.java
// public final class PrettifierUtils {
// 
// 	private PrettifierUtils() {
// 		// hidden constructor
// 	}
// 
// 	public static String escape(String source) {
// 		String[] search = { "<", ">", };
// 		String[] replace = { "&lt;", "&gt;" };
// 
// 		return StringUtils.replaceEach(source, search, replace);
// 	}
// 
// 	public static String highlight(String line) {
// 		return String.format("<span class=\"highlighted\">%s</span>", line);
// 	}
// 
// }


// Path: src/main/java/com/neva/felix/webconsole/plugins/search/core/SearchUtils.java
import com.neva.felix.webconsole.plugins.search.utils.PrettifierUtils;
import com.google.common.base.Joiner;
import com.google.common.base.Splitter;
import com.google.common.collect.Lists;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.io.IOCase;
import org.apache.commons.lang3.StringUtils;
import java.util.Collections;
import java.util.List;
import java.util.Map;


	/**
	 * Compose human readable parameter list as description
	 */
	public static String composeDescription(Map<String, Object> params) {
		List<String> lines = Lists.newArrayList();
		for (Map.Entry<String, Object> entry : params.entrySet()) {
			Object value = entry.getValue();
			if (value instanceof String[]) {
				value = "[" + StringUtils.join((String[] )value, ", ") + "]";
			}

			lines.add(String.format("%s: %s", entry.getKey(), value));
		}

		return StringUtils.join(lines, "\n");
	}

	public static List<String> findContexts(String phrase, String source, int contextLineCount) {
		List<String> contexts = Lists.newLinkedList();
		List<String> lines = Splitter.on(LINE_DELIMITER).splitToList(source);

		int i = 0;
		for (String line : lines) {
			if (StringUtils.containsIgnoreCase(line, phrase)) {
				String before = Joiner.on("\n")
						.join(lines.subList(Math.max(0, i - contextLineCount - 1), Math.max(0, i - 1)));
				String after = Joiner.on("\n").join(lines.subList(Math.min(i + 1, lines.size()),
						Math.min(lines.size(), i + 1 + contextLineCount)));
				String context = PrettifierUtils.escape(before) + "\n" + PrettifierUtils
						.highlight(PrettifierUtils.escape(line)) + "\n" + PrettifierUtils.escape(after);