throws Throwable {
ExportActionForm form = (ExportActionForm) actionForm;
form.setGenerate(false);
Site site = getAdminBean(request).getSite();
createAdditionalInfo(form, site);
ItemSimpleTransformation transformation = null;
if (form.getExportType().equals(Constants.IE_EXPORT_TYPE_CSV)) {
transformation = new ItemSimpleCsvTransformation(Long.valueOf(form.getIeProfileHeaderId()), site, form.getExportLocation());
}
else {
transformation = new ItemSimpleXmlTransformation();
}
ActionMessages errors = validate(form, request);
if (errors.size() != 0) {
saveMessages(request, errors);
return actionMapping.findForward("error");
}
try {
EntityManager em = JpaConnection.getInstance().getCurrentEntityManager();
String sql = "from SiteProfileClass siteProfileClass where siteProfileClass.site.siteId = :siteId";
Query query = em.createQuery(sql);
query.setParameter("siteId", site.getSiteId());
SiteProfileClass siteProfileClasses[] = new SiteProfileClass[query.getResultList().size()];
query.getResultList().toArray(siteProfileClasses);
sql = "from SiteCurrencyClass siteCurrencyClass where siteCurrencyClass.site.siteId = :siteId";
query = em.createQuery(sql);
query.setParameter("siteId", site.getSiteId());
SiteCurrencyClass siteCurrencyClasses[] = new SiteCurrencyClass[query.getResultList().size()];
query.getResultList().toArray(siteCurrencyClasses);
OutputStream outputStream = null;
if (form.getExportLocation().equals(Constants.IE_EXPORT_LOCATION_LOCAL)) {
if (form.getExportType().equals(Constants.IE_EXPORT_TYPE_CSV)) {
response.setContentType("text/csv");
response.setHeader("Content-disposition", "attachment; filename=\"" +"jadaexport" + "_" + Format.getSortDate(new Date()) + ".csv" +"\"");
}
else {
response.setContentType("text/plain");
response.setHeader("Content-disposition", "attachment; filename=\"" +"jadaexport" + "_" + Format.getSortDate(new Date()) + ".txt" +"\"");
}
response.setHeader("Content-Transfer-Encoding", "binary");
outputStream = response.getOutputStream();
}
else {
outputStream = new FileOutputStream(new File(form.getHostFileName()));
}
String header = transformation.getHeader();
if (header != null) {
outputStream.write(header.getBytes());
}
ItemApi itemApi = new ItemApi(site);
sql = "from Item item where item.site.siteId = :siteId";
query = em.createQuery(sql);
query.setParameter("siteId", site.getSiteId());
Iterator<?> iterator = query.getResultList().iterator();
boolean error = false;
while (iterator.hasNext()) {
Item item = (Item) iterator.next();
for (SiteProfileClass siteProfileClass : siteProfileClasses) {
for (SiteCurrencyClass siteCurrencyClass : siteCurrencyClasses) {
String result = "";
try {
com.jada.xml.ie.Item i = itemApi.export(item);
ItemSimple itemSimpleXml = new ItemSimple(i,
siteProfileClass.getSiteProfileClassId(),
siteProfileClass.getSiteProfileClassName(),
siteCurrencyClass.getSiteCurrencyClassId(),
siteCurrencyClass.getSiteCurrencyClassName());
result = transformation.toExport(itemSimpleXml);
}
catch (Exception e) {
result = "Unable to export item with sku code " + item.getItemSkuCd() + System.getProperty("line.separator");
result += Utility.getStackTrace(e);
error = true;
outputStream.write(result.getBytes(Constants.SYSTEM_ENCODING));
break;
}
outputStream.write(result.getBytes(Constants.SYSTEM_ENCODING));
}
if (error) {
break;
}
}
if (error) {
break;
}
}
String footer = transformation.getFooter();
if (footer != null) {
outputStream.write(footer.getBytes());
}
if (form.getExportLocation().equals(Constants.IE_EXPORT_LOCATION_SERVER)) {