1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
   | public final class FormParamEdition extends HttpServlet {
	public static final String LOGO				= "logo";
 
	public static final String TABLEAU_UTILISATEUR	= "TUtilisateur";
 
	private Map<String, String> erreur = new HashMap<String, String>();
 
	public BeanUtilisateur TraitParamEdition(HttpServletRequest request) {
                String logo = null;
		Part part	= null;
 
		try {
			part = request.getPart( LOGO );
			logo = getNomFichier( part );
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ServletException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
 
 
		if ( logo != null && !logo.isEmpty() ) {
 
			InsertLogo formIL 	= new InsertLogo();
			BeanUtilisateur u	= formIL.TraitInsertLogo(request, logo, util2.getEmail());
 
			if(!formIL.getErreur().isEmpty()) {
				for(HashMap.Entry<String, String> entry : formIL.getErreur().entrySet()) {
					String value = entry.getValue();
 
					setErreur("E", value);
				}
				return util;
			}
		}
 
		UpdateUtilisateur form = new UpdateUtilisateur();
		BeanUtilisateur util3 = form.TraitUpdateUtilisateur(request, util.getMention1(), util.getMention2(), util.getMention3(), util.getMention4(), util.getMention5(), util.getMerciClient(), util.getSignatureDevis(), util2.getEmail(), util.isGestionStock(), util.isTrimestre(), util.getMdp(), util.getCle());
 
		return util;
	}
 
	private static String getNomFichier( Part part ) {
	    /* Boucle sur chacun des paramètres de l'en-tête "content-disposition". */
	    for (String contentDisposition : part.getHeader( "content-disposition" ).split( ";" ) ) {
	    	/* Recherche de l'éventuelle présence du paramètre "filename". */
	        if ( contentDisposition.trim().startsWith("filename") ) {
	            /* Si "filename" est présent, alors renvoi de sa valeur, c'est-à-dire du nom de fichier. */
	        	String s = contentDisposition.substring( contentDisposition.indexOf( '=' ) + 2 );
	            return s.substring(0, s.length() -1);
 
	        }
	    }
	    /* Et pour terminer, si rien n'a été trouvé... */
	    return null;
 
	}
 
	public Map<String, String> getErreur() {
		return erreur;
	}
 
	public void setErreur(String key, String message) {
		erreur.put(key, message);
	}
} | 
Partager