1 | /**************************************************************** |
---|
2 | * Licensed to the Apache Software Foundation (ASF) under one * |
---|
3 | * or more contributor license agreements. See the NOTICE file * |
---|
4 | * distributed with this work for additional information * |
---|
5 | * regarding copyright ownership. The ASF licenses this file * |
---|
6 | * to you under the Apache License, Version 2.0 (the * |
---|
7 | * "License"); you may not use this file except in compliance * |
---|
8 | * with the License. You may obtain a copy of the License at * |
---|
9 | * * |
---|
10 | * http://www.apache.org/licenses/LICENSE-2.0 * |
---|
11 | * * |
---|
12 | * Unless required by applicable law or agreed to in writing, * |
---|
13 | * software distributed under the License is distributed on an * |
---|
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * |
---|
15 | * KIND, either express or implied. See the License for the * |
---|
16 | * specific language governing permissions and limitations * |
---|
17 | * under the License. * |
---|
18 | ****************************************************************/ |
---|
19 | |
---|
20 | package org.apache.james.mime4j.field; |
---|
21 | |
---|
22 | import org.apache.james.mime4j.codec.DecodeMonitor; |
---|
23 | import org.apache.james.mime4j.dom.field.FieldRawData; |
---|
24 | import org.apache.james.mime4j.dom.field.ParseException; |
---|
25 | import org.apache.james.mime4j.dom.field.ParsedField; |
---|
26 | import org.apache.james.mime4j.util.ByteSequence; |
---|
27 | |
---|
28 | /** |
---|
29 | * The base class of all field classes. |
---|
30 | */ |
---|
31 | public abstract class AbstractField implements ParsedField, FieldRawData { |
---|
32 | |
---|
33 | private final String name; |
---|
34 | private final String body; |
---|
35 | private final ByteSequence raw; |
---|
36 | protected DecodeMonitor monitor; |
---|
37 | |
---|
38 | protected AbstractField( |
---|
39 | final String name, |
---|
40 | final String body, |
---|
41 | final ByteSequence raw, |
---|
42 | final DecodeMonitor monitor) { |
---|
43 | this.name = name; |
---|
44 | this.body = body; |
---|
45 | this.raw = raw; |
---|
46 | this.monitor = monitor != null ? monitor : DecodeMonitor.SILENT; |
---|
47 | } |
---|
48 | |
---|
49 | /** |
---|
50 | * Gets the name of the field (<code>Subject</code>, |
---|
51 | * <code>From</code>, etc). |
---|
52 | * |
---|
53 | * @return the field name. |
---|
54 | */ |
---|
55 | public String getName() { |
---|
56 | return name; |
---|
57 | } |
---|
58 | |
---|
59 | /** |
---|
60 | * Gets the unfolded, unparsed and possibly encoded (see RFC 2047) field |
---|
61 | * body string. |
---|
62 | * |
---|
63 | * @return the unfolded unparsed field body string. |
---|
64 | */ |
---|
65 | public String getBody() { |
---|
66 | return body; |
---|
67 | } |
---|
68 | |
---|
69 | /** |
---|
70 | * Gets original (raw) representation of the field, if available, |
---|
71 | * <code>null</code> otherwise. |
---|
72 | */ |
---|
73 | public ByteSequence getRaw() { |
---|
74 | return raw; |
---|
75 | } |
---|
76 | |
---|
77 | /** |
---|
78 | * @see ParsedField#isValidField() |
---|
79 | */ |
---|
80 | public boolean isValidField() { |
---|
81 | return getParseException() == null; |
---|
82 | } |
---|
83 | |
---|
84 | /** |
---|
85 | * @see ParsedField#getParseException() |
---|
86 | */ |
---|
87 | public ParseException getParseException() { |
---|
88 | return null; |
---|
89 | } |
---|
90 | |
---|
91 | @Override |
---|
92 | public String toString() { |
---|
93 | return name + ": " + body; |
---|
94 | } |
---|
95 | |
---|
96 | } |
---|