package com.tngtech.xtab.converter;

import com.google.common.base.Charsets;
import org.dbunit.dataset.DataSetException;
import org.dbunit.dataset.IDataSet;
import org.dbunit.dataset.excel.XlsDataSet;
import org.dbunit.dataset.xml.XmlDataSetWriter;

import java.io.BufferedWriter;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;

import static com.google.common.base.Preconditions.checkArgument;

public class XtabConverter {

    public static void main(String[] args) throws Exception {
        checkArgument(args.length == 1, "usage: java ... <path to source file>");
        convertXlsToXtab(args[0]);
    }

    static void convertXlsToXtab(String pathname) throws IOException, DataSetException {
        File sourceFilePath = new File(pathname);
        IDataSet dataSet = new XlsDataSet(sourceFilePath);

        Path sourcePath = sourceFilePath.toPath();
        Path targetPath = sourcePath.resolveSibling(sourcePath.getFileName().toString().replaceFirst("\\.xls", ".xtab"));
        BufferedWriter writer = Files.newBufferedWriter(targetPath, Charsets.UTF_8);
        writer.write("<?xml version='1.0' encoding='" + Charsets.UTF_8.name() + "'?>\n");
        XmlDataSetWriter xmlWriter = new XmlDataSetWriter(writer);
        xmlWriter.write(dataSet);
    }
}

@@ -319,24 +319,57 @@
 OException;%0A
+import java.nio.charset.Charset;%0A
 import java.
@@ -756,28 +756,8 @@
 ows 
-IOException, DataSet
 Exce
@@ -845,14 +845,16 @@
 t = 
-new Xl
+readXlsA
 sDat
@@ -875,17 +875,16 @@
 ePath);%0A
-%0A
         
@@ -892,166 +892,627 @@
 ath 
+targetPath = deriveTargetPathFromSource(
 source
+File
 Path
- = sourceFilePath.to
+);%0A        writeDataSetAsXtab(dataSet, targetPath);%0A    %7D%0A%0A    private static XlsDataSet readXlsAsDataSet(File sourceFilePath) throws Exception %7B%0A        return new XlsDataSet(sourceFile
 Path
-(
 );%0A    
+%7D%0A%0A
     
-Path targetPath = sourcePath.resolveSibling(sourcePath.getFileName().toString().replaceFirst(%22%5C%5C.xls%22, %22.xtab%22))
+private static Path deriveTargetPathFromSource(File source) %7B%0A        Path sourcePath = source.toPath();%0A        return sourcePath.resolveSibling(sourcePath.getFileName().toString().replaceFirst(%22%5C%5C.xls%22, %22.xtab%22));%0A    %7D%0A%0A    private static void writeDataSetAsXtab(IDataSet dataSet, Path targetPath) throws Exception %7B%0A        Charset encoding = Charsets.UTF_8
 ;%0A  
@@ -1577,30 +1577,24 @@
 etPath, 
-Charsets.UTF_8
+encoding
 );%0A     
@@ -1644,30 +1644,24 @@
 ng='%22 + 
-Charsets.UTF_8
+encoding
 .name() 

apply newspaper article pattern