/**
* 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.domain.metaarchive;
import java.util.List;
import javax.jdo.JDOHelper;
import javax.jdo.annotations.NotPersistent;
import javax.jdo.annotations.PersistenceCapable;
import serpro.mailarchiver.util.Logger;
@PersistenceCapable
public class UnstructuredField
extends Field
{
/*
* "Subject", "Content-Description", "Message-Id", "Content-Id"
* "Content-Md5", "Resent-Msg-Id", "Comments", "Keywords"
* etc
*/
@NotPersistent
private static final Logger log = Logger.getLocalLogger();
//**** P E R S I S T E N T ****
private String text;
//*****************************
public final String getText() {
return text;
}
public final void setText(String text) {
this.text = text;
}
//--------------------------------------------------------------------------
@Override
final void dumpTree(StringBuilder sb, String pad) {
sb.append(toString(pad + " "));
}
@Override
final String toString(String pad) {
String idx = (getEntity() == null) ? "" : ("[" + String.valueOf(getEntityIdx()) + "]");
return String.format(
"UnstructuredField %1$s%n"
+ "%2$sjdoState: %3$s%n"
+ "%2$soid: %4$s%n"
+ "%2$shash: %5$x%n"
+ "%2$sname: %6$s%n"
+ "%2$stext: %7$s%n"
+ "%2$svalid: %8$b"
, idx
, pad
, JDOHelper.getObjectState(this)
, getOid()
, hashCode()
, getName()
, getText()
, isValid());
}
@NotPersistent
private Field decorator;
public T getDecorator() {
if(decorator == null) {
if(getName().equalsIgnoreCase("references")) {
decorator = this.new MessageIdSequenceField();
}
else if(getName().equalsIgnoreCase("in-reply-to")) {
decorator = this.new MessageIdSequenceField();
}
else if(getName().equalsIgnoreCase("mime-version")) {
decorator = this.new MimeVersionField();
}
else if(getName().equalsIgnoreCase("content-length")) {
decorator = this.new ContentLengthField();
}
else if(getName().equalsIgnoreCase("content-language")) {
decorator = this.new ContentLanguageField();
}
else if(getName().equalsIgnoreCase("content-location")) {
decorator = this.new ContentLocationField();
}
else if(getName().equalsIgnoreCase("content-encoding")) {
decorator = this.new ContentEncodingField();
}
else if(getName().equalsIgnoreCase("content-transfer-encoding")) {
decorator = this.new ContentTransferEncodingField();
}
else {
decorator = this;
}
}
return (T) decorator;
}
//
private abstract class UnstructuredFieldDecorator extends Field {
@Override
public String getOid() {
return UnstructuredField.this.getOid();
}
@Override
public void setOid(String oid) {
throw new UnsupportedOperationException();
}
//--------------------------------------------------------------------------
@Override
public final Entity getEntity() {
return UnstructuredField.this.getEntity();
}
@Override
public final void setEntity(Entity entity) {
throw new UnsupportedOperationException();
}
//--------------------------------------------------------------------------
@Override
public final String getName() {
return UnstructuredField.this.getName();
}
@Override
public final void setName(String name) {
throw new UnsupportedOperationException();
}
//--------------------------------------------------------------------------
@Override
public final boolean isValid() {
return UnstructuredField.this.isValid();
}
@Override
public final void setValid(boolean valid) {
throw new UnsupportedOperationException();
}
//--------------------------------------------------------------------------
@Override
public final String getParseExceptionStackTrace() {
return UnstructuredField.this.getParseExceptionStackTrace();
}
@Override
public final void setParseExceptionStackTrace(String parseExceptionStackTrace) {
throw new UnsupportedOperationException();
}
@Override
public final void addParseExceptionStackTrace(Throwable t) {
throw new UnsupportedOperationException();
}
//--------------------------------------------------------------------------
@Override
final String toString(String pad) {
return UnstructuredField.this.toString(pad);
}
//--------------------------------------------------------------------------
@Override
final void dumpTree(StringBuilder sb, String pad) {
UnstructuredField.this.dumpTree(sb, pad);
}
}
//
//
public final class MessageIdSequenceField
extends UnstructuredFieldDecorator
{
/*
* "References", "In-Reply-To"
*/
public final List getIds() {
//TODO
return null;
}
}
//
//
public final class MimeVersionField
extends UnstructuredFieldDecorator
{
/*
* "Mime-Version"
*/
public final int getMajorVersion() {
//TODO
return 0;
}
public final int getMinorVersion() {
//TODO
return 0;
}
}
//
//
public final class ContentLengthField
extends UnstructuredFieldDecorator
{
/*
* "Content-Length"
*/
public final int getLength() {
//TODO
return 0;
}
}
//
//
public final class ContentLanguageField
extends UnstructuredFieldDecorator
{
/*
* "Content-Language"
*/
public final List getLanguageTags() {
//TODO
return null;
}
}
//
//
public final class ContentLocationField
extends UnstructuredFieldDecorator
{
/*
* "Content-Location"
*/
//TODO
}
//
//
public final class ContentEncodingField
extends UnstructuredFieldDecorator
{
/*
* "Content-Encoding"
*/
//TODO
}
//
//
public final class ContentTransferEncodingField
extends UnstructuredFieldDecorator
{
/*
* "Content-Transfer-Encoding"
*/
public final String getEncoding() {
return text;
}
public final boolean is7bitEncoding() {
return text.equalsIgnoreCase("7bit");
}
public final boolean is8bitEncoding() {
return text.equalsIgnoreCase("8bit");
}
public final boolean isBinaryEncoding() {
return text.equalsIgnoreCase("binary");
}
public final boolean isIdentityEncoding() {
return ( is7bitEncoding() || is8bitEncoding() || isBinaryEncoding() );
}
public final boolean isQuotedPrintableEncoding() {
return text.equalsIgnoreCase("quoted-printable");
}
public final boolean isBase64Encoding() {
return text.equalsIgnoreCase("base64");
}
}
//
}