[6785] | 1 | /** |
---|
| 2 | * MailArchiver is an application that provides services for storing and managing e-mail messages through a Web Services SOAP interface. |
---|
| 3 | * Copyright (C) 2012 Marcio Andre Scholl Levien and Fernando Alberto Reuter Wendt and Jose Ronaldo Nogueira Fonseca Junior |
---|
| 4 | * |
---|
| 5 | * This program is free software: you can redistribute it and/or modify |
---|
| 6 | * it under the terms of the GNU Affero General Public License as |
---|
| 7 | * published by the Free Software Foundation, either version 3 of the |
---|
| 8 | * License, or (at your option) any later version. |
---|
| 9 | * |
---|
| 10 | * This program is distributed in the hope that it will be useful, |
---|
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 13 | * GNU Affero General Public License for more details. |
---|
| 14 | * |
---|
| 15 | * You should have received a copy of the GNU Affero General Public License |
---|
| 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
| 17 | */ |
---|
| 18 | |
---|
| 19 | /******************************************************************************\ |
---|
| 20 | * |
---|
| 21 | * This product was developed by |
---|
| 22 | * |
---|
| 23 | * SERVIÃO FEDERAL DE PROCESSAMENTO DE DADOS (SERPRO), |
---|
| 24 | * |
---|
| 25 | * a government company established under Brazilian law (5.615/70), |
---|
| 26 | * at Department of Development of Porto Alegre. |
---|
| 27 | * |
---|
| 28 | \******************************************************************************/ |
---|
| 29 | |
---|
| 30 | package serpro.mailarchiver.domain.metaarchive; |
---|
| 31 | |
---|
| 32 | import java.util.List; |
---|
| 33 | |
---|
| 34 | import javax.jdo.JDOHelper; |
---|
| 35 | import javax.jdo.annotations.NotPersistent; |
---|
| 36 | import javax.jdo.annotations.PersistenceCapable; |
---|
| 37 | |
---|
| 38 | import serpro.mailarchiver.util.Logger; |
---|
| 39 | |
---|
| 40 | @PersistenceCapable |
---|
| 41 | public class UnstructuredField |
---|
| 42 | extends Field |
---|
| 43 | { |
---|
| 44 | /* |
---|
| 45 | * "Subject", "Content-Description", "Message-Id", "Content-Id" |
---|
| 46 | * "Content-Md5", "Resent-Msg-Id", "Comments", "Keywords" |
---|
| 47 | * etc |
---|
| 48 | */ |
---|
| 49 | |
---|
| 50 | @NotPersistent |
---|
| 51 | private static final Logger log = Logger.getLocalLogger(); |
---|
| 52 | |
---|
| 53 | //**** P E R S I S T E N T **** |
---|
| 54 | private String text; |
---|
| 55 | //***************************** |
---|
| 56 | |
---|
| 57 | public final String getText() { |
---|
| 58 | return text; |
---|
| 59 | } |
---|
| 60 | |
---|
| 61 | public final void setText(String text) { |
---|
| 62 | this.text = text; |
---|
| 63 | } |
---|
| 64 | |
---|
| 65 | //-------------------------------------------------------------------------- |
---|
| 66 | @Override |
---|
| 67 | final void dumpTree(StringBuilder sb, String pad) { |
---|
| 68 | sb.append(toString(pad + " ")); |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | @Override |
---|
| 72 | final String toString(String pad) { |
---|
| 73 | String idx = (getEntity() == null) ? "" : ("[" + String.valueOf(getEntityIdx()) + "]"); |
---|
| 74 | return String.format( |
---|
| 75 | "UnstructuredField %1$s%n" |
---|
| 76 | + "%2$sjdoState: %3$s%n" |
---|
| 77 | + "%2$soid: %4$s%n" |
---|
| 78 | + "%2$shash: %5$x%n" |
---|
| 79 | + "%2$sname: %6$s%n" |
---|
| 80 | + "%2$stext: %7$s%n" |
---|
| 81 | + "%2$svalid: %8$b" |
---|
| 82 | , idx |
---|
| 83 | , pad |
---|
| 84 | , JDOHelper.getObjectState(this) |
---|
| 85 | , getOid() |
---|
| 86 | , hashCode() |
---|
| 87 | , getName() |
---|
| 88 | , getText() |
---|
| 89 | , isValid()); |
---|
| 90 | } |
---|
| 91 | |
---|
| 92 | @NotPersistent |
---|
| 93 | private Field decorator; |
---|
| 94 | |
---|
| 95 | public <T extends Field> T getDecorator() { |
---|
| 96 | if(decorator == null) { |
---|
| 97 | if(getName().equalsIgnoreCase("references")) { |
---|
| 98 | decorator = this.new MessageIdSequenceField(); |
---|
| 99 | } |
---|
| 100 | else if(getName().equalsIgnoreCase("in-reply-to")) { |
---|
| 101 | decorator = this.new MessageIdSequenceField(); |
---|
| 102 | } |
---|
| 103 | else if(getName().equalsIgnoreCase("mime-version")) { |
---|
| 104 | decorator = this.new MimeVersionField(); |
---|
| 105 | } |
---|
| 106 | else if(getName().equalsIgnoreCase("content-length")) { |
---|
| 107 | decorator = this.new ContentLengthField(); |
---|
| 108 | } |
---|
| 109 | else if(getName().equalsIgnoreCase("content-language")) { |
---|
| 110 | decorator = this.new ContentLanguageField(); |
---|
| 111 | } |
---|
| 112 | else if(getName().equalsIgnoreCase("content-location")) { |
---|
| 113 | decorator = this.new ContentLocationField(); |
---|
| 114 | } |
---|
| 115 | else if(getName().equalsIgnoreCase("content-encoding")) { |
---|
| 116 | decorator = this.new ContentEncodingField(); |
---|
| 117 | } |
---|
| 118 | else if(getName().equalsIgnoreCase("content-transfer-encoding")) { |
---|
| 119 | decorator = this.new ContentTransferEncodingField(); |
---|
| 120 | } |
---|
| 121 | else { |
---|
| 122 | decorator = this; |
---|
| 123 | } |
---|
| 124 | } |
---|
| 125 | return (T) decorator; |
---|
| 126 | } |
---|
| 127 | |
---|
| 128 | |
---|
| 129 | //<editor-fold defaultstate="collapsed" desc=" UnstructuredFieldDecorator "> |
---|
| 130 | private abstract class UnstructuredFieldDecorator extends Field { |
---|
| 131 | |
---|
| 132 | @Override |
---|
| 133 | public String getOid() { |
---|
| 134 | return UnstructuredField.this.getOid(); |
---|
| 135 | } |
---|
| 136 | |
---|
| 137 | @Override |
---|
| 138 | public void setOid(String oid) { |
---|
| 139 | throw new UnsupportedOperationException(); |
---|
| 140 | } |
---|
| 141 | |
---|
| 142 | //-------------------------------------------------------------------------- |
---|
| 143 | @Override |
---|
| 144 | public final Entity getEntity() { |
---|
| 145 | return UnstructuredField.this.getEntity(); |
---|
| 146 | } |
---|
| 147 | |
---|
| 148 | @Override |
---|
| 149 | public final void setEntity(Entity entity) { |
---|
| 150 | throw new UnsupportedOperationException(); |
---|
| 151 | } |
---|
| 152 | |
---|
| 153 | //-------------------------------------------------------------------------- |
---|
| 154 | @Override |
---|
| 155 | public final String getName() { |
---|
| 156 | return UnstructuredField.this.getName(); |
---|
| 157 | } |
---|
| 158 | |
---|
| 159 | @Override |
---|
| 160 | public final void setName(String name) { |
---|
| 161 | throw new UnsupportedOperationException(); |
---|
| 162 | } |
---|
| 163 | |
---|
| 164 | //-------------------------------------------------------------------------- |
---|
| 165 | @Override |
---|
| 166 | public final boolean isValid() { |
---|
| 167 | return UnstructuredField.this.isValid(); |
---|
| 168 | } |
---|
| 169 | |
---|
| 170 | @Override |
---|
| 171 | public final void setValid(boolean valid) { |
---|
| 172 | throw new UnsupportedOperationException(); |
---|
| 173 | } |
---|
| 174 | |
---|
| 175 | //-------------------------------------------------------------------------- |
---|
| 176 | @Override |
---|
| 177 | public final String getParseExceptionStackTrace() { |
---|
| 178 | return UnstructuredField.this.getParseExceptionStackTrace(); |
---|
| 179 | } |
---|
| 180 | |
---|
| 181 | @Override |
---|
| 182 | public final void setParseExceptionStackTrace(String parseExceptionStackTrace) { |
---|
| 183 | throw new UnsupportedOperationException(); |
---|
| 184 | } |
---|
| 185 | |
---|
| 186 | @Override |
---|
| 187 | public final void addParseExceptionStackTrace(Throwable t) { |
---|
| 188 | throw new UnsupportedOperationException(); |
---|
| 189 | } |
---|
| 190 | |
---|
| 191 | //-------------------------------------------------------------------------- |
---|
| 192 | @Override |
---|
| 193 | final String toString(String pad) { |
---|
| 194 | return UnstructuredField.this.toString(pad); |
---|
| 195 | } |
---|
| 196 | |
---|
| 197 | //-------------------------------------------------------------------------- |
---|
| 198 | @Override |
---|
| 199 | final void dumpTree(StringBuilder sb, String pad) { |
---|
| 200 | UnstructuredField.this.dumpTree(sb, pad); |
---|
| 201 | } |
---|
| 202 | } |
---|
| 203 | //</editor-fold> |
---|
| 204 | |
---|
| 205 | |
---|
| 206 | //<editor-fold defaultstate="collapsed" desc=" MessageIdSequenceField "> |
---|
| 207 | public final class MessageIdSequenceField |
---|
| 208 | extends UnstructuredFieldDecorator |
---|
| 209 | { |
---|
| 210 | /* |
---|
| 211 | * "References", "In-Reply-To" |
---|
| 212 | */ |
---|
| 213 | |
---|
| 214 | public final List<String> getIds() { |
---|
| 215 | //TODO |
---|
| 216 | return null; |
---|
| 217 | } |
---|
| 218 | } |
---|
| 219 | //</editor-fold> |
---|
| 220 | |
---|
| 221 | |
---|
| 222 | //<editor-fold defaultstate="collapsed" desc=" MimeVersionField "> |
---|
| 223 | public final class MimeVersionField |
---|
| 224 | extends UnstructuredFieldDecorator |
---|
| 225 | { |
---|
| 226 | /* |
---|
| 227 | * "Mime-Version" |
---|
| 228 | */ |
---|
| 229 | |
---|
| 230 | public final int getMajorVersion() { |
---|
| 231 | //TODO |
---|
| 232 | return 0; |
---|
| 233 | } |
---|
| 234 | |
---|
| 235 | public final int getMinorVersion() { |
---|
| 236 | //TODO |
---|
| 237 | return 0; |
---|
| 238 | } |
---|
| 239 | } |
---|
| 240 | //</editor-fold> |
---|
| 241 | |
---|
| 242 | |
---|
| 243 | //<editor-fold defaultstate="collapsed" desc=" ContentLengthField "> |
---|
| 244 | public final class ContentLengthField |
---|
| 245 | extends UnstructuredFieldDecorator |
---|
| 246 | { |
---|
| 247 | /* |
---|
| 248 | * "Content-Length" |
---|
| 249 | */ |
---|
| 250 | |
---|
| 251 | public final int getLength() { |
---|
| 252 | //TODO |
---|
| 253 | return 0; |
---|
| 254 | } |
---|
| 255 | } |
---|
| 256 | //</editor-fold> |
---|
| 257 | |
---|
| 258 | |
---|
| 259 | //<editor-fold defaultstate="collapsed" desc=" ContentLanguageField "> |
---|
| 260 | public final class ContentLanguageField |
---|
| 261 | extends UnstructuredFieldDecorator |
---|
| 262 | { |
---|
| 263 | /* |
---|
| 264 | * "Content-Language" |
---|
| 265 | */ |
---|
| 266 | |
---|
| 267 | public final List<String> getLanguageTags() { |
---|
| 268 | //TODO |
---|
| 269 | return null; |
---|
| 270 | } |
---|
| 271 | } |
---|
| 272 | //</editor-fold> |
---|
| 273 | |
---|
| 274 | |
---|
| 275 | //<editor-fold defaultstate="collapsed" desc=" ContentLocationField "> |
---|
| 276 | public final class ContentLocationField |
---|
| 277 | extends UnstructuredFieldDecorator |
---|
| 278 | { |
---|
| 279 | /* |
---|
| 280 | * "Content-Location" |
---|
| 281 | */ |
---|
| 282 | |
---|
| 283 | //TODO |
---|
| 284 | } |
---|
| 285 | //</editor-fold> |
---|
| 286 | |
---|
| 287 | |
---|
| 288 | //<editor-fold defaultstate="collapsed" desc=" ContentEncodingField "> |
---|
| 289 | public final class ContentEncodingField |
---|
| 290 | extends UnstructuredFieldDecorator |
---|
| 291 | { |
---|
| 292 | /* |
---|
| 293 | * "Content-Encoding" |
---|
| 294 | */ |
---|
| 295 | |
---|
| 296 | //TODO |
---|
| 297 | } |
---|
| 298 | //</editor-fold> |
---|
| 299 | |
---|
| 300 | |
---|
| 301 | //<editor-fold defaultstate="collapsed" desc=" ContentTransferEncodingField "> |
---|
| 302 | public final class ContentTransferEncodingField |
---|
| 303 | extends UnstructuredFieldDecorator |
---|
| 304 | { |
---|
| 305 | /* |
---|
| 306 | * "Content-Transfer-Encoding" |
---|
| 307 | */ |
---|
| 308 | |
---|
| 309 | public final String getEncoding() { |
---|
| 310 | return text; |
---|
| 311 | } |
---|
| 312 | |
---|
| 313 | public final boolean is7bitEncoding() { |
---|
| 314 | return text.equalsIgnoreCase("7bit"); |
---|
| 315 | } |
---|
| 316 | |
---|
| 317 | public final boolean is8bitEncoding() { |
---|
| 318 | return text.equalsIgnoreCase("8bit"); |
---|
| 319 | } |
---|
| 320 | |
---|
| 321 | public final boolean isBinaryEncoding() { |
---|
| 322 | return text.equalsIgnoreCase("binary"); |
---|
| 323 | } |
---|
| 324 | |
---|
| 325 | public final boolean isIdentityEncoding() { |
---|
| 326 | return ( is7bitEncoding() || is8bitEncoding() || isBinaryEncoding() ); |
---|
| 327 | } |
---|
| 328 | |
---|
| 329 | public final boolean isQuotedPrintableEncoding() { |
---|
| 330 | return text.equalsIgnoreCase("quoted-printable"); |
---|
| 331 | } |
---|
| 332 | |
---|
| 333 | public final boolean isBase64Encoding() { |
---|
| 334 | return text.equalsIgnoreCase("base64"); |
---|
| 335 | } |
---|
| 336 | } |
---|
| 337 | //</editor-fold> |
---|
| 338 | |
---|
| 339 | } |
---|