package dk.daoas.adressevedligehold; import java.io.IOException; import java.util.List; import org.apache.commons.fileupload.FileItem; import com.google.common.base.Splitter; import dk.daoas.adressevedligehold.AddressSourceEntry.EntryType; public class AddressSourceFD extends AbstractAddressSource { String filenameFirst2; public AddressSourceFD(FileItem file) throws Exception { super(file); filenameFirst2 = file.getName().substring(0, 2).toUpperCase(); } @Override public void validate() throws IOException { super.validateWithHeader(9, ';'); } //TODO: Skal csv parsning klares med Apache Commons CSV ? @Override public AddressSourceEntry getNextEntry() throws IOException { String line = br.readLine(); if (line == null) // end of file return null; if (line.trim().equals("")) return null; //System.out.println(line); AddressSourceEntry entry = new AddressSourceEntry( EntryType.TypeSingleAddress); entry.distributor = "FD"; List parts = Splitter.on(';').splitToList(line); if (parts.size() != 9) { throw new IOException("Not enough fields in line " + line); } entry.postnr = Short.parseShort( parts.get(0) ); entry.vejnavn = parts.get(1); entry.husnr = Short.parseShort( parts.get(2) ); entry.litra = parts.get(3); entry.vejkode = Short.parseShort( parts.get(4) ); entry.kommunekode = Short.parseShort( parts.get(5) ); entry.gadeid = Integer.parseInt( parts.get(6) ); entry.rute = dirigeringsCache.getInstance( parts.get(7) ); entry.koreliste = dirigeringsCache.getInstance( parts.get(8) ); switch(filenameFirst2) { case "HV": entry.ugedage = EntryUgedage.MAN_FRE; break; case "LO": entry.ugedage = EntryUgedage.LOR; break; case "SO": entry.ugedage = EntryUgedage.SON; break; default: throw new IOException("Ukendt ugedage " + filenameFirst2); } lineCount++; return entry; } @Override public String getDistributor() { return "FD"; } }