package org.opencompare.api.java.io;

import com.opencsv.CSVWriter;
import org.opencompare.api.java.*;

import java.io.IOException;
import java.io.StringWriter;
import java.util.*;

/**
 * Created by gbecan on 3/19/15.
 */
public class CSVExporter implements PCMExporter {

    PCMMetadata currentMetadata = null;

    @Override
    public String export(PCMContainer container) {
        currentMetadata = container.getMetadata();
        return export(container.getPcm());
    }

    private String export(PCM pcm) {
        StringWriter stringWriter = new StringWriter();
        CSVWriter csvWriter = new CSVWriter(stringWriter);

        // Export features
        if (currentMetadata  == null) currentMetadata = new PCMMetadata(pcm);

        List<Feature> features = currentMetadata.getSortedFeatures();
        List<Product> products = currentMetadata.getSortedProducts();
        List<String> featureLine = new ArrayList<>();

        featureLine.add("Product");

        for (Feature feature : features) {
            featureLine.add(feature.getName());
        }

        csvWriter.writeNext(featureLine.toArray(new String[featureLine.size()]));

        // Export products
        for (Product product : products) {
            List<String> productLine = new ArrayList<>();

            productLine.add(product.getName());
            for (Feature feature : features) {
                Cell cell = product.findCell(feature);
                if (cell == null) {
                    productLine.add("");
                } else {
                    productLine.add(cell.getContent());
                }

            }

            csvWriter.writeNext(productLine.toArray(new String[productLine.size()]));
        }


        try {
            csvWriter.close();
        } catch (IOException e) {
            e.printStackTrace();
        }

        return stringWriter.toString();
    }
}

@@ -306,16 +306,284 @@
  = null;
+%0A    char separator = ',';%0A    char quote = '%22';%0A%0A    public CSVExporter setSeparator(char separator) %7B%0A        this.separator = separator;%0A        return this;%0A    %7D%0A%0A    public CSVExporter setQuote(char quote) %7B%0A        this.quote = quote;%0A        return this;%0A    %7D
 %0A%0A    @O
@@ -891,16 +891,34 @@
 ngWriter
+, separator, quote
 );%0A%0A    

Add separator and quote option in CSVExporter