package be.iminds.ilabt.jfed.groovy_dsl.impl.events;

import be.iminds.ilabt.jfed.groovy_dsl.DSLStreamException;
import be.iminds.ilabt.jfed.groovy_dsl.events.PropertyElement;
import org.apache.commons.lang.StringEscapeUtils;

import java.io.IOException;
import java.io.Writer;

/**
 * User: twalcari
 * Date: 5/18/2015
 * Time: 16:31
 */
public class StringPropertyElementImpl extends DSLEventImpl implements PropertyElement<String> {

    private final String name;
    private final String value;

    public StringPropertyElementImpl(String name, String value) {
        this.name = name;
        this.value = value;
    }

    @Override
    public void write(Writer writer) throws DSLStreamException {
        try {
            writer.write(name);
            writer.write(" = \"");
            writer.write(StringEscapeUtils.escapeJava(value));
            writer.write("\"\n");
        } catch (IOException e) {
            throw new DSLStreamException(e);
        }
    }

    @Override
    public String getName() {
        return name;
    }

    @Override
    public String getValue() {
        return value;
    }
}
