/**
* MailArchiver is an application that provides services for storing and managing e-mail messages through a Web Services SOAP interface.
* Copyright (C) 2012 Marcio Andre Scholl Levien and Fernando Alberto Reuter Wendt and Jose Ronaldo Nogueira Fonseca Junior
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
*/
/******************************************************************************\
*
* This product was developed by
*
* SERVIÇO FEDERAL DE PROCESSAMENTO DE DADOS (SERPRO),
*
* a government company established under Brazilian law (5.615/70),
* at Department of Development of Porto Alegre.
*
\******************************************************************************/
package serpro.mailarchiver.service.dto;
import javax.xml.bind.annotation.XmlRootElement;
import serpro.mailarchiver.domain.metaarchive.BinaryBody;
import serpro.mailarchiver.domain.metaarchive.ContentTypeField;
import serpro.mailarchiver.domain.metaarchive.UnstructuredField.ContentTransferEncodingField;
@XmlRootElement(name="Attachment")
public class TAttachment implements Identifiable, Comparable {
private String id;
@Override
public String getId() { return id; }
@Override
public void setId(String id) { this.id = id; }
//--------------------------------------------------------------------------
private String name;
public String getName() { return name; }
public void setName(String name) { this.name = name; }
//--------------------------------------------------------------------------
private long size;
public long getSize() { return size; }
public void setSize(long size) { this.size = size; }
//--------------------------------------------------------------------------
private String contentType;
public String getContentType() { return contentType; }
public void setContentType(String contentType) { this.contentType = contentType; }
//--------------------------------------------------------------------------
private String encoding;
public String getEncodinng() { return encoding; }
public void setEncoding(String encoding) { this.encoding = encoding; }
//--------------------------------------------------------------------------
// TODO ?
//private String url;
//==========================================================================
public TAttachment() {}
public TAttachment(BinaryBody body) {
id = body.getOid();
name = "todo";
size = body.getSize();
ContentTypeField contentTypeField = body.getEntity().getContentTypeField();
contentType = (contentTypeField != null) ? contentTypeField.getMediaType() + "/" + contentTypeField.getSubType() : "";
ContentTransferEncodingField contentTransferEncodingField = body.getEntity().getContentTransferEncoding();
encoding = (contentTransferEncodingField != null) ? contentTransferEncodingField.getEncoding() : "";
//DEBUG
System.out.println(toString());
}
@Override
public String toString() {
return String.format(
"TAttachment%n"
+ "%1$sid: %2$s%n"
+ "%1$sname: %3$s%n"
+ "%1$ssize: %4$d%n"
+ "%1$scontentType: %5$s%n"
+ "%1$sencoding: %6$s"
, " "
, id
, name
, size
, contentType
, encoding);
}
//==========================================================================
@Override
public int compareTo(TAttachment o) {
return getName().compareTo(o.getName());
}
}