1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/net/fortuna/ical4j/model/parameter/Encoding.java Tue Feb 10 18:12:00 2015 +0100 1.3 @@ -0,0 +1,141 @@ 1.4 +/** 1.5 + * Copyright (c) 2012, Ben Fortuna 1.6 + * All rights reserved. 1.7 + * 1.8 + * Redistribution and use in source and binary forms, with or without 1.9 + * modification, are permitted provided that the following conditions 1.10 + * are met: 1.11 + * 1.12 + * o Redistributions of source code must retain the above copyright 1.13 + * notice, this list of conditions and the following disclaimer. 1.14 + * 1.15 + * o Redistributions in binary form must reproduce the above copyright 1.16 + * notice, this list of conditions and the following disclaimer in the 1.17 + * documentation and/or other materials provided with the distribution. 1.18 + * 1.19 + * o Neither the name of Ben Fortuna nor the names of any other contributors 1.20 + * may be used to endorse or promote products derived from this software 1.21 + * without specific prior written permission. 1.22 + * 1.23 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1.24 + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1.25 + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1.26 + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 1.27 + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 1.28 + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 1.29 + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 1.30 + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 1.31 + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 1.32 + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 1.33 + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 1.34 + */ 1.35 +package net.fortuna.ical4j.model.parameter; 1.36 + 1.37 +import net.fortuna.ical4j.model.Parameter; 1.38 +import net.fortuna.ical4j.model.ParameterFactoryImpl; 1.39 +import net.fortuna.ical4j.util.Strings; 1.40 + 1.41 +/** 1.42 + * $Id$ [18-Apr-2004] 1.43 + * 1.44 + * Defines an Inline Encoding parameter. Constants are provided for all encodings specified in <a 1.45 + * href="http://www.ietf.org/rfc/rfc2045.txt">RFC2045</a>. 1.46 + * 1.47 + * <pre> 1.48 + * 4.2.7 Inline Encoding 1.49 + * 1.50 + * Parameter Name: ENCODING 1.51 + * 1.52 + * Purpose: To specify an alternate inline encoding for the property 1.53 + * value. 1.54 + * 1.55 + * Format Definition: The property parameter is defined by the following 1.56 + * notation: 1.57 + * 1.58 + * encodingparam = "ENCODING" "=" 1.59 + * ("8BIT" 1.60 + * ; "8bit" text encoding is defined in [RFC 2045] 1.61 + * / "BASE64" 1.62 + * ; "BASE64" binary encoding format is defined in [RFC 2045] 1.63 + * / iana-token 1.64 + * ; Some other IANA registered iCalendar encoding type 1.65 + * / x-name) 1.66 + * ; A non-standard, experimental encoding type 1.67 + * 1.68 + * Description: The property parameter identifies the inline encoding 1.69 + * used in a property value. The default encoding is "8BIT", 1.70 + * corresponding to a property value consisting of text. The "BASE64" 1.71 + * encoding type corresponds to a property value encoded using the 1.72 + * "BASE64" encoding defined in [RFC 2045]. 1.73 + * 1.74 + * If the value type parameter is ";VALUE=BINARY", then the inline 1.75 + * encoding parameter MUST be specified with the value 1.76 + * ";ENCODING=BASE64". 1.77 + * 1.78 + * Example: 1.79 + * 1.80 + * ATTACH;FMTYPE=IMAGE/JPEG;ENCODING=BASE64;VALUE=BINARY:MIICajC 1.81 + * CAdOgAwIBAgICBEUwDQYJKoZIhvcNAQEEBQAwdzELMAkGA1UEBhMCVVMxLDA 1.82 + * qBgNVBAoTI05ldHNjYXBlIENvbW11bmljYXRpb25zIENvcnBvcmF0aW9uMRw 1.83 + * <...remainder of "BASE64" encoded binary data...> 1.84 + * </pre> 1.85 + * 1.86 + * @author Ben Fortuna 1.87 + */ 1.88 +public class Encoding extends Parameter { 1.89 + 1.90 + private static final long serialVersionUID = 7536336461076399077L; 1.91 + 1.92 + private static final String VALUE_SEVEN_BIT = "7BIT"; 1.93 + 1.94 + private static final String VALUE_EIGHT_BIT = "8BIT"; 1.95 + 1.96 + private static final String VALUE_BINARY = "BINARY"; 1.97 + 1.98 + private static final String VALUE_QUOTED_PRINTABLE = "QUOTED-PRINTABLE"; 1.99 + 1.100 + private static final String VALUE_BASE64 = "BASE64"; 1.101 + 1.102 + /** 1.103 + * 7 bit encoding. 1.104 + */ 1.105 + public static final Encoding SEVEN_BIT = new Encoding(VALUE_SEVEN_BIT); 1.106 + 1.107 + /** 1.108 + * 8 bit encoding. 1.109 + */ 1.110 + public static final Encoding EIGHT_BIT = new Encoding(VALUE_EIGHT_BIT); 1.111 + 1.112 + /** 1.113 + * Binary encoding. 1.114 + */ 1.115 + public static final Encoding BINARY = new Encoding(VALUE_BINARY); 1.116 + 1.117 + /** 1.118 + * Quoted printable encoding. 1.119 + */ 1.120 + public static final Encoding QUOTED_PRINTABLE = new Encoding( 1.121 + VALUE_QUOTED_PRINTABLE); 1.122 + 1.123 + /** 1.124 + * Base64 encoding. 1.125 + */ 1.126 + public static final Encoding BASE64 = new Encoding(VALUE_BASE64); 1.127 + 1.128 + private String value; 1.129 + 1.130 + /** 1.131 + * @param aValue a string representation of an Inline Encoding 1.132 + */ 1.133 + public Encoding(final String aValue) { 1.134 + super(ENCODING, ParameterFactoryImpl.getInstance()); 1.135 + this.value = Strings.unquote(aValue); 1.136 + } 1.137 + 1.138 + /** 1.139 + * {@inheritDoc} 1.140 + */ 1.141 + public final String getValue() { 1.142 + return value; 1.143 + } 1.144 +}