package org.jetel.data.formatter.provider;

import org.jetel.data.formatter.FixLenDataFormatter;
import org.jetel.data.formatter.Formatter;

/**
 * Provides support for getting the lixlen data formatter.
 * 
 * @author Jan Ausperger (jan.ausperger@javlinconsulting.cz)
 *         (c) Javlin Consulting (www.javlinconsulting.cz)
 */
public class FixLenDataFormatterProvider implements FormatterProvider {

	private String charEncoder;
	private String header;
	private Character chRecordFiller;
	private Character chFieldFiller;
	private Character recordFiller;
	private Character fieldFiller;
	private String charSet;
	
	/**
	 * Contructors.
	 */
	public FixLenDataFormatterProvider() {
	}
	public FixLenDataFormatterProvider(String charEncoder) {
		this.charEncoder = charEncoder;
	}

	/**
	 * Creates new data formatter.
	 * 
	 * @return data formatter
	 */
	public Formatter getNewFormatter() {
		FixLenDataFormatter formatter;
		if (charEncoder == null) {
			formatter =	new FixLenDataFormatter();
		} else {
			formatter =	new FixLenDataFormatter(charEncoder);
		}
		formatter.setHeader(header);
		formatter.setRecordFiller(chRecordFiller);
		formatter.setFieldFiller(chFieldFiller);
		recordFiller = formatter.getRecordFiller();
		fieldFiller = formatter.getFieldFiller();
		charSet = formatter.getCharSetName();
		return formatter;
	}

	/**
	 * Gets charset.
	 * 
	 * @return
	 */
	public String getCharSetName() {
		return charSet;
	}

	/**
	 * Sets header.
	 * 
	 * @param header
	 */
	public void setHeader(String header) {
    	this.header = header;
    }
	
	public void setRecordFiller(Character filler) {
		this.chRecordFiller = filler;
	}

    public Character getRecordFiller() {
        return recordFiller;
    }

	public void setFieldFiller(Character filler) {
        this.chFieldFiller = filler;
	}

    public Character getFieldFiller() {
        return fieldFiller;
    }

}

@@ -610,18 +610,76 @@
 harSet;%0A
+%09private Boolean chLeftAlign;%0A%09private Boolean leftAlign;%0A
 %09%0A
-
 %09/**%0A%09 *
@@ -1239,16 +1239,104 @@
 iller);%0A
+%09%09if (chLeftAlign != null) %7B%0A%09%09%09formatter.setLeftAlign(chLeftAlign.booleanValue());%0A%09%09%7D%0A
 %09%09record
@@ -1457,16 +1457,55 @@
 Name();%0A
+%09%09leftAlign = formatter.isLeftAlign();%0A
 %09%09return
@@ -2072,10 +2072,155 @@
 %0A    %7D%0A%0A
+    public void setLeftAlign(Boolean leftAlign) %7B%0A%09%09this.chLeftAlign = leftAlign;%0A%09%7D%0A    %0A%09public Boolean isLeftAlign() %7B%0A%09%09return leftAlign;%0A%09%7D%0A
 %7D%0A

add choice of alignment