View Javadoc
1   /* ***** BEGIN LICENSE BLOCK *****
2    * Version: MPL 1.1
3    *
4    * The contents of this file are subject to the Mozilla Public License Version
5    * 1.1 (the "License"); you may not use this file except in compliance with
6    * the License. You may obtain a copy of the License at
7    * http://www.mozilla.org/MPL/
8    *
9    * Software distributed under the License is distributed on an "AS IS" basis,
10   * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11   * for the specific language governing rights and limitations under the
12   * License.
13   *
14   * The Original Code is "SMS Library for the Java platform".
15   *
16   * The Initial Developer of the Original Code is Markus Eriksson.
17   * Portions created by the Initial Developer are Copyright (C) 2002
18   * the Initial Developer. All Rights Reserved.
19   *
20   * Contributor(s):
21   *
22   * ***** END LICENSE BLOCK ***** */
23  package org.marre.sms.nokia;
24  
25  import java.io.UnsupportedEncodingException;
26  
27  /***
28   * Nokia Picture message
29   * <p>
30   * @author Markus Eriksson
31   * @version $Id: NokiaPictureMessage.java,v 1.8 2002/10/09 19:30:32 c95men Exp $
32   */
33  public class NokiaPictureMessage extends NokiaMultipartMessage
34  {
35      /***
36       * Creates a Nokia Picture Message
37       *
38       * @param theBitmap
39       * @param theMsg
40       */
41      public NokiaPictureMessage(OtaBitmap theBitmap, String theMsg)
42      {
43          this(theBitmap, theMsg, false);
44      }
45  
46      /***
47       * Creates a Nokia Picture Message
48       *
49       * @param theBitmap
50       * @param theMsg
51       */
52      public NokiaPictureMessage(byte[] theBitmap, String theMsg)
53      {
54          this(theBitmap, theMsg, false);
55      }
56  
57      /***
58       * Creates a Nokia Picture Message
59       *
60       * @param theBitmap
61       * @param theMsg
62       * @param asUnicode Set to true if text should be sent as unicode
63       */
64      public NokiaPictureMessage(OtaBitmap theBitmap, String theMsg, boolean asUnicode)
65      {
66          this(theBitmap.getBytes(), theMsg, asUnicode);
67      }
68  
69      /***
70       * Creates a Nokia Picture Message
71       *
72       * @param theBitmap
73       * @param theMsg
74       * @param asUnicode Set to true if text should be sent as unicode
75       */
76      public NokiaPictureMessage(byte[] theBitmap, String theMsg, boolean asUnicode)
77      {
78          addBitmap(theBitmap);
79          addText(theMsg, asUnicode);
80      }
81  
82      /***
83       * Used internally to add the image
84       *
85       * @param theBitmap
86       */
87      private void addBitmap(byte[] theBitmap)
88      {
89          addMultipart(NokiaPart.ITEM_OTA_BITMAP, theBitmap);
90      }
91  
92      /***
93       * Used internally to add the image
94       * @param theBitmap
95       */
96      private void addBitmap(OtaBitmap theBitmap)
97      {
98          addMultipart(NokiaPart.ITEM_OTA_BITMAP, theBitmap.getBytes());
99      }
100 
101     /***
102      * Used internally to add text
103      *
104      * @param theMsg
105      * @param asUnicode
106      */
107     private void addText(String theMsg, boolean asUnicode)
108     {
109         try
110         {
111             if (asUnicode)
112             {
113                 addMultipart(NokiaPart.ITEM_TEXT_UNICODE, theMsg.getBytes("UTF-16BE"));
114             }
115             else
116             {
117                 addMultipart(NokiaPart.ITEM_TEXT_ISO_8859_1, theMsg.getBytes("ISO-8859-1"));
118             }
119         }
120         catch (UnsupportedEncodingException ex)
121         {
122             //myLog.fatal("Shouldn't happen, 'UTF-16BE' and 'ISO-8859-1' are in the standard", ex);
123         }
124     }
125 }
126