01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.cocoon.mail;
18:
19: import javax.mail.MessagingException;
20: import javax.mail.internet.MimePart;
21:
22: /**
23: * A simple MimePart preference selecting algorithm
24: *
25: * @author Bernhard Huber
26: * @since 26. Oktober 2002
27: * @version $Id: MailCtPref.java 468095 2006-10-26 18:50:50Z vgritsenko $
28: */
29: public class MailCtPref implements ContentTypePreference {
30:
31: /**
32: * Yield preference
33: *
34: *@param part Examine the content of this part
35: *@return preference, a higher preference value signals higher preference,
36: * eg. a part evaluating preference 10, signals preference over
37: * a part evaluating preference of 5
38: */
39: public int preference(MimePart part) {
40: try {
41: if (part.isMimeType("text/html")) {
42: return 5;
43: }
44: if (part.isMimeType("text/*")) {
45: return 10;
46: }
47: if (part.isMimeType("text")) {
48: return 9;
49: }
50: return 0;
51: } catch (MessagingException messagingexception) {
52: return 0;
53: }
54: }
55: }
|