<% /****************************************************************************** * Copyright (c) 2000-2005 e-Deal * * e-Deal S.A. * 55 rue Brillat Savarin * 75013 Paris * France * * T: +33 (0)1 53 80 80 30 * F: +33 (0)1 73 01 69 77 * http://www.e-deal.com * * La diffusion de ce code source sous quelque forme que ce soit sans * l'autorisation de E-DEAL est interdite. * * Vous êtes autorisés à modifier ce code source uniquement pour votre usage * propre et sous réserve que les mentions de copyright demeurent intactes. * * Ce code est fourni en l'état. Aucune garantie d'aucune sorte, explicite ou * implicite n'est donnée. En aucun cas E-DEAL ne pourra être tenu pour * responsable des dommages pouvant résulter de l'utilisation de ce code * source. ******************************************************************************/ %> <%@ page session="true" contentType="text/html; charset=UTF-8" %> <%@ page import="com.edeal.frontline.navigation.FlRequest" %> <%@ page import="java.util.*" %> <%@ page import="java.io.*" %> <%@ page import="com.edeal.frontline.*" %> <%@taglib uri="http://www.e-deal.com/taglib/fl" prefix="fl" %> <%! private class FormDataSource implements javax.activation.DataSource { private InputStream dataStream = null; private String contentType = null; public FormDataSource(String pType, InputStream pDataStream) { this.contentType = pType; this.dataStream = pDataStream; } public String getContentType() { return this.contentType; } public InputStream getInputStream() throws IOException { if (this.dataStream == null) { throw new IOException("no data"); } return this.dataStream; } public String getName() { return "dummy"; } public OutputStream getOutputStream() throws IOException { throw new IOException("cannot do this"); } } %> <% final org.apache.commons.logging.Log logger = org.apache.commons.logging.LogFactory.getLog(getClass()); FlRequest flRequest = new FlRequest(request); FlContext context = flRequest.getContext(); DataDictionary dico = context.getDataDictionary(); String strActID = (String)session.getAttribute("actorID"); String strContentType = null; byte[] strFile = null; String strCode = null; if(request.getContentType() != null && request.getContentType().startsWith("multipart/form-data")) { long delay = System.currentTimeMillis(); FormDataSource frmSrc = new FormDataSource(request.getContentType(), request.getInputStream()); javax.mail.internet.MimeMultipart content = new javax.mail.internet.MimeMultipart(frmSrc); for(int i = 0; i < content.getCount() && strFile == null; i++) { javax.mail.BodyPart part = content.getBodyPart(i); if(part.getFileName() != null) { strContentType = part.getContentType(); ByteArrayOutputStream outFile = null; try { outFile = new ByteArrayOutputStream(); InputStream inFile = part.getInputStream(); byte[] buffer = new byte[1024 * 1024]; int nbRead; while((nbRead = inFile.read(buffer)) > 0) outFile.write(buffer, 0, nbRead); strFile = outFile.toByteArray(); } finally { try { outFile.close(); } catch (Exception ex) {} outFile = null; } } else { String[] strHeaders = part.getHeader("Content-Disposition"); if(strHeaders != null && strHeaders.length > 0 && strHeaders[0].startsWith("form-data; name=\"") && strHeaders[0].length() > "form-data; name=\"\"".length()) { String strName = strHeaders[0].substring("form-data; name=\"".length(), strHeaders[0].length() - 1); if("DitCode".equals(strName)) { strCode = part.getContent() == null ? null : part.getContent().toString().trim(); } } } } content = null; frmSrc = null; //logger.debug("[/admin/ditranscode/import_validate.jsp] delay = " + (System.currentTimeMillis() - delay)); } int[] counter = new int[]{0, 0, 0}; if(strCode != null && strFile != null) { java.sql.Connection cx = null; java.sql.PreparedStatement pstmtInsert = null; java.sql.PreparedStatement pstmtUpdate = null; java.sql.PreparedStatement pstmtDelete = null; com.edeal.frontline.dataimport.CSVInSource in = null; IdFactory idFactory = context.getIdFactory(); try { java.util.Date dt = new java.util.Date(); cx = context.getConnection(); String insertQuery = "INSERT INTO DITranscode (DitID, DitCode, DitKey, DitValue, DitCreID, DitCrDt, DitModID, DitUpd) VALUES (?, " + Utils.formatToSQL(context, strCode) + ", ?, ?, " + Utils.formatToSQL(context, strActID) + ", " + Utils.formatToSQL(context, dt) + ", " + Utils.formatToSQL(context, strActID) + ", " + Utils.formatToSQL(context, dt) + ")"; insertQuery = Utils.formatPreparedStatementQueryForUnicode(context, insertQuery, new int[]{1, 2, 3}); String updateQuery = "UPDATE DITranscode SET DitValue = ?, DitModID = " + Utils.formatToSQL(context, strActID) + ", DitUpd = " + Utils.formatToSQL(context, dt) + " WHERE DitCode = " + Utils.formatToSQL(context, strCode) + " AND DitKey = ?"; updateQuery = Utils.formatPreparedStatementQueryForUnicode(context, updateQuery, new int[]{1, 2}); String deleteQuery = "DELETE FROM DITranscode WHERE DitCode = " + Utils.formatToSQL(context, strCode) + " AND DitKey = ?"; deleteQuery = Utils.formatPreparedStatementQueryForUnicode(context, deleteQuery, new int[]{1}); pstmtInsert = cx.prepareStatement(insertQuery); pstmtUpdate = cx.prepareStatement(updateQuery); pstmtDelete = cx.prepareStatement(deleteQuery); in = new com.edeal.frontline.dataimport.CSVInSource(); in.setSeparator(";"); in.setDelimiter("\""); in.open(new ByteArrayInputStream(strFile)); Vector vect = null; while((vect = in.next()) != null) { if(vect.size() >= 2) { if(vect.size() >= 3) { String strFlag = (String)vect.elementAt(2); if(strFlag != null && ("yes".equalsIgnoreCase(strFlag.trim()) || "true".equalsIgnoreCase(strFlag.trim()) || "1".equalsIgnoreCase(strFlag.trim()))) { pstmtDelete.setString(1, (String)vect.elementAt(0)); counter[2] += pstmtDelete.executeUpdate(); continue; } } pstmtUpdate.setString(1, (String)vect.elementAt(1)); pstmtUpdate.setString(2, (String)vect.elementAt(0)); int nb = pstmtUpdate.executeUpdate(); if(nb > 0) { counter[1] += nb; } else { pstmtInsert.setString(1, idFactory.getID()); pstmtInsert.setString(2, (String)vect.elementAt(0)); pstmtInsert.setString(3, (String)vect.elementAt(1)); counter[0] += pstmtInsert.executeUpdate(); } } } } catch (Exception ex) { logger.error("[/admin/ditranscode/import_validate.jsp] " + ex.getClass().getName() + " : " + ex.getMessage()); } finally { try { in.close(); } catch (Exception ex) {} try { pstmtDelete.close(); } catch (Exception ex) {} try { pstmtUpdate.close(); } catch (Exception ex) {} try { pstmtInsert.close(); } catch (Exception ex) {} try { cx.close(); } catch (Exception ex) {} } } %> ">
<%= counter[0] %>
<%= counter[1] %>
<%= counter[2] %>
 
<% /****************************************************************************** * * * a.stouky@e-deal.ma : 2006/08/24 * * *****************************************************************************/ %>