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

org.gramar.adaptor.GramarTsvAdaptor Maven / Gradle / Ivy

Go to download

A lightweght, pure-Java component that makes composite software architecture design patterns extremely consumable through code generation.

The newest version!
package org.gramar.adaptor;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import org.gramar.IModelAdaptor;
import org.gramar.exception.GramarException;
import org.gramar.model.DocumentHelper;
import org.gramar.model.XmlModel;
import org.w3c.dom.Document;

public class GramarTsvAdaptor extends GramarModelAdaptor implements
		IModelAdaptor {

	public GramarTsvAdaptor() {

	}

	@Override
	public String getId() {
		return "org.gramar.adaptor.GramarTsvAdaptor";
	}

	@Override
	public String getType() {
		return "tsv";
	}

	@Override
	public Document asDocument(String source) throws GramarException {

		String line[] = source.split("\n");
		String xml = null;
		
		int linenum = 0;
		while ((linenum");
		String hdr[] = line[linenum].split("\t");
		linenum++;
		
		while (linenum");
			linenum++;
		}
		
		sb.append("");
		xml = sb.toString();
		
		return DocumentHelper.buildModel(xml);
	}

	private String escape(String buf) {
		StringBuffer sb = new StringBuffer();
		for (int i = 0; i < buf.length(); i++) {
			char c = buf.charAt(i);
			if (c == '<') {
				sb.append("<");
			} else if (c == '>') {
				sb.append(">");
			} else if (c == '&') {
				sb.append("&");
			} else if (c == '\'') {
				sb.append("'");
			} else if (c == '\"') {
				sb.append(""");
			} else if (Character.isWhitespace(c)) {
				sb.append(c);
			} else if (c < 20) {
				sb.append("");
			} else {
				sb.append(c);
			}
		}
		return sb.toString();
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy