package net.sf.pzfilereader.examples.csvheaderandtrailer;

/*
 * Created on Dec 31, 2004
 *
 */

import java.io.File;

import net.sf.pzfilereader.DataSet;

/**
 * @author zepernick
 * 
 * TODO To change the template for this generated type comment go to Window -
 * Preferences - Java - Code Style - Code Templates
 */
public class CSVHeaderAndTrailer {
    public static void main(final String[] args) throws Exception {
        call(getDefaultMapping(), getDefaultDataFile());
    }

    public static String getDefaultMapping() {
        return "PEOPLE-DelimitedWithHeaderTrailer.pzmap.xml";
    }

    public static String getDefaultDataFile() {
        return "PEOPLE-CommaDelimitedWithQualifier.txt";
    }

    public static void call(final String mapping, final String data) throws Exception {
        File mapFile = new File(mapping);
        File dataFile = new File(data);
        // delimited by a comma
        // text qualified by double quotes
        // ignore first record
        DataSet ds = new DataSet(mapFile, dataFile, ',', '"', true, false); 

        while (ds.next()) {

            if (ds.isRecordID("header")) {
                System.out.println(">>>>>>Found Header Record");
                System.out.println("COLUMN NAME: RECORDINDICATOR VALUE: " + ds.getString("RECORDINDICATOR"));
                System.out.println("COLUMN NAME: HEADERDATA VALUE: " + ds.getString("HEADERDATA"));
                System.out.println("===========================================================================");
                continue;
            }

            if (ds.isRecordID("trailer")) {
                System.out.println(">>>>>>Found Trailer Record");
                System.out.println("COLUMN NAME: RECORDINDICATOR VALUE: " + ds.getString("RECORDINDICATOR"));
                System.out.println("COLUMN NAME: TRAILERDATA VALUE: " + ds.getString("TRAILERDATA"));
                System.out.println("===========================================================================");
                continue;
            }

            System.out.println("COLUMN NAME: FIRSTNAME VALUE: " + ds.getString("FIRSTNAME"));
            System.out.println("COLUMN NAME: LASTNAME VALUE: " + ds.getString("LASTNAME"));
            System.out.println("COLUMN NAME: ADDRESS VALUE: " + ds.getString("ADDRESS"));
            System.out.println("COLUMN NAME: CITY VALUE: " + ds.getString("CITY"));
            System.out.println("COLUMN NAME: STATE VALUE: " + ds.getString("STATE"));
            System.out.println("COLUMN NAME: ZIP VALUE: " + ds.getString("ZIP"));
            System.out.println("===========================================================================");
        }

        if (ds.getErrors() != null && ds.getErrors().size() > 0) {
            System.out.println("FOUND ERRORS IN FILE");
        }
    }
}

@@ -149,22 +149,113 @@
 reader.D
-ataSet
+efaultPZParserFactory;%0D%0Aimport net.sf.pzfilereader.IDataSet;%0D%0Aimport net.sf.pzfilereader.PZParser
 ;%0D%0A%0D%0A/**
@@ -921,24 +921,30 @@
  %7B%0D%0A        
+final 
 File mapFile
@@ -974,16 +974,22 @@
         
+final 
 File dat
@@ -1120,16 +1120,17 @@
 t record
+ 
 %0D%0A      
@@ -1135,32 +1135,89 @@
     
-DataSet ds = new DataSet
+final PZParser pzparser = DefaultPZParserFactory.getInstance().newDelimitedParser
 (map
@@ -1236,22 +1236,41 @@
 le, 
+%0D%0A                
 ',', '
+%5C
 %22', true
 , fa
@@ -1269,20 +1269,57 @@
 true
-, false); %0D%0A
+);%0D%0A        final IDataSet ds = pzparser.parse();
 %0D%0A  

converted to factory classes