
package de.ivu.elect.was.exchange.wahl;

import java.io.IOException;
import java.io.InputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

import javax.inject.Inject;
import javax.xml.bind.JAXBException;

import de.ivu.elect.interfaces.core.Wahl;

public class WasWahlXmlZipImportMapper extends AbstractWahlXmlZipImportMapper implements WasWahlImportMapper {

  @Inject
  private transient WasWahlExternInternMapper mapper;

  public WasWahlXmlZipImportMapper() {
    super();
  }

  @Override
  protected WasWahlExternInternMapper getMapper() {
    return mapper;
  }

  public Wahl mappeZip(InputStream is) throws JAXBException {
    try {
      ZipInputStream zis = getZipInputStream(is);

      // erwartet wird genau ein Entry...
      ZipEntry entry = zis.getNextEntry();

      if (entry == null) {
        return null;
      }

      return super.mappe(zis);
    } catch (IOException e) {
      throw new RuntimeException(e.getMessage(), e);
    }
  }
}
