View Javadoc

1   /************************************************************************
2    * Copyright (c) 2000-2006 The Apache Software Foundation.             *
3    * All rights reserved.                                                *
4    * ------------------------------------------------------------------- *
5    * Licensed under the Apache License, Version 2.0 (the "License"); you *
6    * may not use this file except in compliance with the License. You    *
7    * may obtain a copy of the License at:                                *
8    *                                                                     *
9    *     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     *
14   * implied.  See the License for the specific language governing       *
15   * permissions and limitations under the License.                      *
16   ***********************************************************************/
17  
18  package org.apache.james.transport.mailets;
19  
20  import javax.mail.MessagingException;
21  import java.util.StringTokenizer;
22  
23  /***
24   * This mailet will attach text to the end of the message (like a footer).  Right
25   * now it only supports simple messages without multiple parts.
26   */
27  public class AddFooter extends AbstractAddFooter {
28  
29      /***
30       * This is the plain text version of the footer we are going to add
31       */
32      String text = "";
33      
34      /***
35       * Initialize the mailet
36       */
37      public void init() throws MessagingException {
38          text = getInitParameter("text");
39      }
40  
41      /***
42       * This is exposed as a method for easy subclassing to provide alternate ways
43       * to get the footer text.
44       *
45       * @return the footer text
46       */
47      public String getFooterText() {
48          return text;
49      }
50  
51      /***
52       * This is exposed as a method for easy subclassing to provide alternate ways
53       * to get the footer text.  By default, this will take the footer text,
54       * converting the linefeeds to <br> tags.
55       *
56       * @return the HTML version of the footer text
57       */
58      public String getFooterHTML() {
59          String text = getFooterText();
60          StringBuffer sb = new StringBuffer();
61          StringTokenizer st = new StringTokenizer(text, "\r\n", true);
62          while (st.hasMoreTokens()) {
63              String token = st.nextToken();
64              if (token.equals("\r")) {
65                  continue;
66              }
67              if (token.equals("\n")) {
68                  sb.append("<br />\n");
69              } else {
70                  sb.append(token);
71              }
72          }
73          return sb.toString();
74      }
75  
76      /***
77       * Return a string describing this mailet.
78       *
79       * @return a string describing this mailet
80       */
81      public String getMailetInfo() {
82          return "AddFooter Mailet";
83      } 
84  }