001 /**************************************************************** 002 * Licensed to the Apache Software Foundation (ASF) under one * 003 * or more contributor license agreements. See the NOTICE file * 004 * distributed with this work for additional information * 005 * regarding copyright ownership. The ASF licenses this file * 006 * to you under the Apache License, Version 2.0 (the * 007 * "License"); you may not use this file except in compliance * 008 * with the License. You may obtain a copy of the License at * 009 * * 010 * http://www.apache.org/licenses/LICENSE-2.0 * 011 * * 012 * Unless required by applicable law or agreed to in writing, * 013 * software distributed under the License is distributed on an * 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * 015 * KIND, either express or implied. See the License for the * 016 * specific language governing permissions and limitations * 017 * under the License. * 018 ****************************************************************/ 019 020 package org.apache.james.mime4j.field; 021 022 import org.apache.james.mime4j.util.ByteSequence; 023 import org.apache.james.mime4j.util.MimeUtil; 024 025 /** 026 * Represents a <code>Content-Transfer-Encoding</code> field. 027 */ 028 public class ContentTransferEncodingField extends AbstractField { 029 private String encoding; 030 031 ContentTransferEncodingField(String name, String body, ByteSequence raw) { 032 super(name, body, raw); 033 encoding = body.trim().toLowerCase(); 034 } 035 036 /** 037 * Gets the encoding defined in this field. 038 * 039 * @return the encoding or an empty string if not set. 040 */ 041 public String getEncoding() { 042 return encoding; 043 } 044 045 /** 046 * Gets the encoding of the given field if. Returns the default 047 * <code>7bit</code> if not set or if <code>f</code> is 048 * <code>null</code>. 049 * 050 * @return the encoding. 051 */ 052 public static String getEncoding(ContentTransferEncodingField f) { 053 if (f != null && f.getEncoding().length() != 0) { 054 return f.getEncoding(); 055 } 056 return MimeUtil.ENC_7BIT; 057 } 058 059 static final FieldParser PARSER = new FieldParser() { 060 public ParsedField parse(final String name, final String body, 061 final ByteSequence raw) { 062 return new ContentTransferEncodingField(name, body, raw); 063 } 064 }; 065 }