MailAttach.java

  1. /*
  2.  * GovWay - A customizable API Gateway
  3.  * https://govway.org
  4.  *
  5.  * Copyright (c) 2005-2025 Link.it srl (https://link.it).
  6.  *
  7.  * This program is free software: you can redistribute it and/or modify
  8.  * it under the terms of the GNU General Public License version 3, as published by
  9.  * the Free Software Foundation.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  18.  *
  19.  */

  20. package org.openspcoop2.utils.mail;

  21. import org.openspcoop2.utils.mime.MimeTypes;

  22. /**
  23.  * MailAttach
  24.  *
  25.  * @author Poli Andrea (apoli@link.it)
  26.  * @author $Author$
  27.  * @version $Rev$, $Date$
  28.  */
  29. public abstract class MailAttach {

  30.     private String name;
  31.     private String contentType;
  32.    
  33.     public MailAttach(String name, String contentType){
  34.         this.name = name;
  35.         this.contentType = contentType;
  36.     }
  37.    
  38.     public String getName() {
  39.         return this.name;
  40.     }
  41.     public void setName(String name) {
  42.         this.name = name;
  43.     }
  44.     public String getContentType() {
  45.         if(this.contentType!=null)
  46.             return this.contentType;
  47.         else{
  48.             MimeTypes mimeTypes = null;
  49.             try{
  50.                 mimeTypes = MimeTypes.getInstance();
  51.                 if(this.name!=null){
  52.                     if(this.name.contains(".")){
  53.                         String ext = this.name.substring(this.name.lastIndexOf('.')+1, this.name.length());
  54.                         return mimeTypes.getMimeType(ext);
  55.                     }
  56.                 }
  57.             }catch(Exception e){
  58.                 e.printStackTrace(System.err);
  59.                
  60.             }
  61.             // default
  62.             if(mimeTypes!=null)
  63.                 return mimeTypes.getMimeType("bin");
  64.             else
  65.                 return "application/octet-stream";
  66.         }
  67.     }
  68.     public void setContentType(String contentType) {
  69.         this.contentType = contentType;
  70.     }
  71. }