package com.k_int.webapp3;

import java.io.ByteArrayInputStream;

import javax.xml.parsers.ParserConfigurationException;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.k_int.bank.service.dto.ImportReportDTO;
import com.k_int.webapp3.util.DTOToDoc;
import com.k_int.zthes.service.impl.ZThesServiceImpl;

public class CreateOrUpdateVocabAction extends AbstractXmlOrHtmlAction {
  private static final long serialVersionUID = 1L;
  private final Log log = LogFactory.getLog(CreateOrUpdateVocabAction.class);
  private String xml;  
  
  public void setXml(String xml) { this.xml = xml; }
  public String getString()      { return xml;     }
  
  
  public String responseSpecificExecute() throws Exception {
    try {
      log.debug("Getting zthes service and running import");
      ZThesServiceImpl svc   = (ZThesServiceImpl) ctx.getBean("ZThesService");
      ImportReportDTO report = svc.importThesRevisionPart(new ByteArrayInputStream(xml.getBytes()));

      log.debug("Import done... getting results");
      doc = DTOToDoc.createReportDocument(report);
      
    } catch (ParserConfigurationException pce) {
      pce.printStackTrace();
    }

    return SUCCESS;
  }
}
