package de.finetech.utils;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.TreeMap;
import java.util.Vector;

import de.abas.eks.jfop.remote.FO;

/**
 * stellt das ergebnis eines Infosystem aufrufs dar.
 * 
 * @author MKürbis
 *
 */
public class InfosystemcallResult {

	private TreeMap<String, String> head;
	private Vector<TreeMap<String, String>> table;

	private Infosystemcall call;

	private Vector<String[]> lines;

	private Vector<String[]> getLinesOfFile(String file) throws IOException {
		Vector<String[]> lines = new Vector<String[]>();
		if (file != null) {
			BufferedReader br = new BufferedReader(new FileReader(file));
			for (String line; (line = br.readLine()) != null;) {
				lines.add(line.split("\\["));
			}
			br.close();
		}
		return lines;
	}

	protected InfosystemcallResult(Infosystemcall call) throws IOException {
		this.call = call;
		this.head = new TreeMap<String, String>();
		this.table = new Vector<TreeMap<String, String>>();
		this.lines = this.getLinesOfFile(call.outputFile);
		boolean headFields = call.showAllHeadFields
				|| call.headOutputFields.size() > 0;
		if (headFields) {
			for (int i = 0; i < lines.get(0).length; i++) {
				String key = lines.get(0)[i];
				head.put(key, lines.get(1)[i]);
			}
		}
		if (call.showAllTableFields || call.tableOutputFields.size() > 0) {
			// index der Variablennamen zeile in der Outputdatei festlegen
			int row = (headFields) ? 2 : 0;
			// zeile mit den Variablennamen speichern
			String[] keys = lines.get(row);
			// für jede Datenzeile
			for (int j = row + 1; j < lines.size(); j++) {
				TreeMap<String, String> foo = new TreeMap<String, String>();
				for (int i = 0; i < keys.length; i++) {
					foo.put(keys[i], lines.get(j)[i]);
				}
				table.add(foo);
			}
		}
	}

	public TreeMap<String, String> getHead() {
		return this.head;
	}

	public Vector<TreeMap<String, String>> getTable() {
		return this.table;
	}

	public String getOutputFile() {
		return call.outputFile;
	}

	public String getInfosystem() {
		return call.infosystem;
	}
	
	public String getCommando(){
		return call.getCommand();
	}

	public void printFile() {
		for (String[] line : lines) {
			for (String column : line) {
				FO.println("-lfsuppress " + column + ";");
			}
			FO.println("");
		}
	}

}

@@ -1473,16 +1473,44 @@
  2 : 0;%0A
+%09%09%09if (!lines.isEmpty()) %7B%0A%09
 %09%09%09// ze
@@ -1549,16 +1549,17 @@
 hern%0A%09%09%09
+%09
 String%5B%5D
@@ -1582,16 +1582,17 @@
 t(row);%0A
+%09
 %09%09%09// f%C3%BC
@@ -1608,24 +1608,25 @@
 tenzeile%0A%09%09%09
+%09
 for (int j =
@@ -1656,24 +1656,25 @@
 e(); j++) %7B%0A
+%09
 %09%09%09%09TreeMap%3C
@@ -1726,24 +1726,25 @@
 ing%3E();%0A%09%09%09%09
+%09
 for (int i =
@@ -1776,16 +1776,17 @@
  %7B%0A%09%09%09%09%09
+%09
 foo.put(
@@ -1812,16 +1812,17 @@
 j)%5Bi%5D);%0A
+%09
 %09%09%09%09%7D%0A%09%09
@@ -1823,16 +1823,17 @@
 %09%09%7D%0A%09%09%09%09
+%09
 table.ad
@@ -1840,16 +1840,22 @@
 d(foo);%0A
+%09%09%09%09%7D%0A
 %09%09%09%7D%0A%09%09%7D
@@ -2130,17 +2130,16 @@
 tem;%0A%09%7D%0A
-%09
 %0A%09public
@@ -2159,16 +2159,17 @@
 mmando()
+ 
 %7B%0A%09%09retu

Update InfosystemcallResult.java