Search in sources :

Example 1 with I18NLanguageNotFoundException

use of org.asqatasun.referential.creator.exception.I18NLanguageNotFoundException in project Asqatasun by Asqatasun.

the class CodeGeneratorMojo method getCsv.

/**
     *
     * @return
     */
private Iterable<CSVRecord> getCsv() {
    // we parse the csv file to extract the first line and get the headers 
    LineIterator lineIterator;
    try {
        lineIterator = FileUtils.lineIterator(dataFile, Charset.defaultCharset().name());
    } catch (IOException ex) {
        Logger.getLogger(CodeGeneratorMojo.class.getName()).log(Level.SEVERE, null, ex);
        lineIterator = null;
    }
    String[] csvHeaders = lineIterator != null ? lineIterator.next().split(String.valueOf(delimiter)) : new String[0];
    isCriterionPresent = extractCriterionFromCsvHeader(csvHeaders);
    try {
        extractAvailableLangsFromCsvHeader(csvHeaders);
    } catch (I18NLanguageNotFoundException ex) {
        Logger.getLogger(CodeGeneratorMojo.class.getName()).log(Level.SEVERE, null, ex);
        return null;
    }
    // from here we just add each line to a build to re-create the csv content
    // without the first line.
    StringBuilder strb = new StringBuilder();
    while (lineIterator.hasNext()) {
        strb.append(lineIterator.next());
        strb.append("\n");
    }
    Reader in;
    try {
        in = new StringReader(strb.toString());
        CSVFormat csvf = CSVFormat.newFormat(delimiter).withHeader(csvHeaders);
        return csvf.parse(in);
    } catch (FileNotFoundException ex) {
        Logger.getLogger(CodeGeneratorMojo.class.getName()).log(Level.SEVERE, null, ex);
        return null;
    } catch (IOException ex) {
        Logger.getLogger(CodeGeneratorMojo.class.getName()).log(Level.SEVERE, null, ex);
        return null;
    }
}
Also used : I18NLanguageNotFoundException(org.asqatasun.referential.creator.exception.I18NLanguageNotFoundException) StringReader(java.io.StringReader) FileNotFoundException(java.io.FileNotFoundException) Reader(java.io.Reader) StringReader(java.io.StringReader) CSVFormat(org.apache.commons.csv.CSVFormat) IOException(java.io.IOException) LineIterator(org.apache.commons.io.LineIterator)

Aggregations

FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 Reader (java.io.Reader)1 StringReader (java.io.StringReader)1 CSVFormat (org.apache.commons.csv.CSVFormat)1 LineIterator (org.apache.commons.io.LineIterator)1 I18NLanguageNotFoundException (org.asqatasun.referential.creator.exception.I18NLanguageNotFoundException)1