|
1 /** |
|
2 * Copyright (c) 2012, Ben Fortuna |
|
3 * All rights reserved. |
|
4 * |
|
5 * Redistribution and use in source and binary forms, with or without |
|
6 * modification, are permitted provided that the following conditions |
|
7 * are met: |
|
8 * |
|
9 * o Redistributions of source code must retain the above copyright |
|
10 * notice, this list of conditions and the following disclaimer. |
|
11 * |
|
12 * o Redistributions in binary form must reproduce the above copyright |
|
13 * notice, this list of conditions and the following disclaimer in the |
|
14 * documentation and/or other materials provided with the distribution. |
|
15 * |
|
16 * o Neither the name of Ben Fortuna nor the names of any other contributors |
|
17 * may be used to endorse or promote products derived from this software |
|
18 * without specific prior written permission. |
|
19 * |
|
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
|
24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
|
25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
|
26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
|
27 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
|
28 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
|
29 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
|
30 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
31 */ |
|
32 package net.fortuna.ical4j.model.parameter; |
|
33 |
|
34 import net.fortuna.ical4j.model.Parameter; |
|
35 import net.fortuna.ical4j.model.ParameterFactoryImpl; |
|
36 import net.fortuna.ical4j.util.Strings; |
|
37 |
|
38 /** |
|
39 * $Id$ [18-Apr-2004] |
|
40 * |
|
41 * Defines an Inline Encoding parameter. Constants are provided for all encodings specified in <a |
|
42 * href="http://www.ietf.org/rfc/rfc2045.txt">RFC2045</a>. |
|
43 * |
|
44 * <pre> |
|
45 * 4.2.7 Inline Encoding |
|
46 * |
|
47 * Parameter Name: ENCODING |
|
48 * |
|
49 * Purpose: To specify an alternate inline encoding for the property |
|
50 * value. |
|
51 * |
|
52 * Format Definition: The property parameter is defined by the following |
|
53 * notation: |
|
54 * |
|
55 * encodingparam = "ENCODING" "=" |
|
56 * ("8BIT" |
|
57 * ; "8bit" text encoding is defined in [RFC 2045] |
|
58 * / "BASE64" |
|
59 * ; "BASE64" binary encoding format is defined in [RFC 2045] |
|
60 * / iana-token |
|
61 * ; Some other IANA registered iCalendar encoding type |
|
62 * / x-name) |
|
63 * ; A non-standard, experimental encoding type |
|
64 * |
|
65 * Description: The property parameter identifies the inline encoding |
|
66 * used in a property value. The default encoding is "8BIT", |
|
67 * corresponding to a property value consisting of text. The "BASE64" |
|
68 * encoding type corresponds to a property value encoded using the |
|
69 * "BASE64" encoding defined in [RFC 2045]. |
|
70 * |
|
71 * If the value type parameter is ";VALUE=BINARY", then the inline |
|
72 * encoding parameter MUST be specified with the value |
|
73 * ";ENCODING=BASE64". |
|
74 * |
|
75 * Example: |
|
76 * |
|
77 * ATTACH;FMTYPE=IMAGE/JPEG;ENCODING=BASE64;VALUE=BINARY:MIICajC |
|
78 * CAdOgAwIBAgICBEUwDQYJKoZIhvcNAQEEBQAwdzELMAkGA1UEBhMCVVMxLDA |
|
79 * qBgNVBAoTI05ldHNjYXBlIENvbW11bmljYXRpb25zIENvcnBvcmF0aW9uMRw |
|
80 * <...remainder of "BASE64" encoded binary data...> |
|
81 * </pre> |
|
82 * |
|
83 * @author Ben Fortuna |
|
84 */ |
|
85 public class Encoding extends Parameter { |
|
86 |
|
87 private static final long serialVersionUID = 7536336461076399077L; |
|
88 |
|
89 private static final String VALUE_SEVEN_BIT = "7BIT"; |
|
90 |
|
91 private static final String VALUE_EIGHT_BIT = "8BIT"; |
|
92 |
|
93 private static final String VALUE_BINARY = "BINARY"; |
|
94 |
|
95 private static final String VALUE_QUOTED_PRINTABLE = "QUOTED-PRINTABLE"; |
|
96 |
|
97 private static final String VALUE_BASE64 = "BASE64"; |
|
98 |
|
99 /** |
|
100 * 7 bit encoding. |
|
101 */ |
|
102 public static final Encoding SEVEN_BIT = new Encoding(VALUE_SEVEN_BIT); |
|
103 |
|
104 /** |
|
105 * 8 bit encoding. |
|
106 */ |
|
107 public static final Encoding EIGHT_BIT = new Encoding(VALUE_EIGHT_BIT); |
|
108 |
|
109 /** |
|
110 * Binary encoding. |
|
111 */ |
|
112 public static final Encoding BINARY = new Encoding(VALUE_BINARY); |
|
113 |
|
114 /** |
|
115 * Quoted printable encoding. |
|
116 */ |
|
117 public static final Encoding QUOTED_PRINTABLE = new Encoding( |
|
118 VALUE_QUOTED_PRINTABLE); |
|
119 |
|
120 /** |
|
121 * Base64 encoding. |
|
122 */ |
|
123 public static final Encoding BASE64 = new Encoding(VALUE_BASE64); |
|
124 |
|
125 private String value; |
|
126 |
|
127 /** |
|
128 * @param aValue a string representation of an Inline Encoding |
|
129 */ |
|
130 public Encoding(final String aValue) { |
|
131 super(ENCODING, ParameterFactoryImpl.getInstance()); |
|
132 this.value = Strings.unquote(aValue); |
|
133 } |
|
134 |
|
135 /** |
|
136 * {@inheritDoc} |
|
137 */ |
|
138 public final String getValue() { |
|
139 return value; |
|
140 } |
|
141 } |