/** * 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.util; import serpro.mailarchiver.domain.metaarchive.BinaryBody; import serpro.mailarchiver.domain.metaarchive.ContentDispositionField; import serpro.mailarchiver.domain.metaarchive.ContentTypeField; import serpro.mailarchiver.domain.metaarchive.Entity; import serpro.mailarchiver.domain.metaarchive.SingleBody; import serpro.mailarchiver.domain.metaarchive.TextBody; public abstract class BodyVisitor { private boolean quitted; public final boolean isQuitted() { return quitted; } protected final void quit() { quitted = true; } public final void visitSingleBody(SingleBody singleBody) { if(singleBody == null) { return; } if(quitted) { return; } boolean isTextBody = (singleBody instanceof TextBody); boolean isBinaryBody = (singleBody instanceof BinaryBody); Entity entity = singleBody.getEntity(); ContentTypeField contentTypeField = (entity != null) ? entity.getContentTypeField() : null; boolean isTextType = (contentTypeField != null) ? contentTypeField.isTextMediaType() : true; boolean isImageType = (contentTypeField != null) ? contentTypeField.isImageMediaType() : false; boolean isAudioType = (contentTypeField != null) ? contentTypeField.isAudioMediaType() : false; boolean isVideoType = (contentTypeField != null) ? contentTypeField.isVideoMediaType() : false; ContentDispositionField contentDispositionField = (entity != null) ? entity.getContentDispositionField() : null; boolean isInlineDisposition = (contentDispositionField != null) ? contentDispositionField.isInlineDisposition() : false; boolean isAttachmentDisposition = (contentDispositionField != null) ? contentDispositionField.isAttachmentDisposition() : false; if(isTextBody && isTextType && !isAttachmentDisposition) { visitTextBody((TextBody)singleBody); } if(isBinaryBody) { visitBinaryBody((BinaryBody)singleBody); } if(isInlineDisposition && !isTextType) { visitInlineBody(singleBody); } else if(isAttachmentDisposition) { visitAttachmentBody(singleBody); } else { if(isImageType || isAudioType || isVideoType) { visitAttachmentBody(singleBody); } } } public void visitTextBody(TextBody textBody) {} public void visitBinaryBody(BinaryBody binaryBody) {} public void visitInlineBody(SingleBody singleBody) {} public void visitAttachmentBody(SingleBody singleBody) {} }