⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mmsmessage.java.svn-base

📁 编解码MMS彩信的Java类库
💻 SVN-BASE
📖 第 1 页 / 共 2 页
字号:
/* * Copyright (C) 2008 Andrea Zito *  * This file is part of jMmsLib. * * jMmsLib is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as  * published by the Free Software Foundation, either version 3 of  * the License, or  (at your option) any later version. * * jMmsLib is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public  * License along with jMmsLib.  If not, see <http://www.gnu.org/licenses/>. */ package net.sourceforge.jmmslib;import java.util.ArrayList;import java.util.Date;import java.util.Iterator;import java.util.List;/** * Represents an mms message.<br> * <p>This class is used to fill the field of an mms message and do some basic data * validation.</p> *  * <p>The field required for the various type of mms messages are listed on the document * <i>WAP-209-MMSEncapsulation-20020105-a</i>, avaiable at the  * <a href="http://www.openmobilealliance.org/tech/affiliates/wap/wapindex.html">Open Mobile Alliance</a> web site.  *  * @author Andrea Zito * */public class MmsMessage {	private static final String NL = "\r\n";		/*=========================================================================	 * Header Name Constants	 *=========================================================================*/	public static final String MMS_MESSAGE_TYPE = "X-Mms-Message-Type";	public static final String MMS_TRANSACTION_ID = "X-Mms-Transaction-ID";	public static final String MMS_VERSION = "X-Mms-MMS-Version";	public static final String MMS_DATE = "Date";	public static final String MMS_FROM = "From";	public static final String MMS_TO = "To";	public static final String MMS_CC = "CC";	public static final String MMS_BCC = "BCC";		public static final String MMS_SUBJECT = "Subject";	public static final String MMS_CLASS = "X-Mms-Message-Class";	public static final String MMS_EXPIRY = "X-Mms-Expiry";	public static final String MMS_DELIVERY_TIME = "X-Mms-Delivery-Time";	public static final String MMS_PRIORITY = "X-Mms-Priority";	public static final String MMS_SENDER_VISIBILITY = "X-Mms-Sender-Visibility";	public static final String MMS_DELIVERY_REPORT = "X-Mms-Delivery-Report";	public static final String MMS_READ_REPLY = "X-Mms-Read-Reply";	public static final String MMS_CONTENT_TYPE = "Content-Type";	public static final String MMS_RESPONSE_STATUS = "X-Mms-Response-Status";	public static final String MMS_RESPONSE_TEXT = "X-Mms-Response-Text";	public static final String MMS_MESSAGE_ID = "Message-ID";	/*=========================================================================	 * Header Value Constants	 *=========================================================================*/	public static final String CHARSET_US_ASCII = "us-ascii";	public static final String CHARSET_UTF8 = "utf-8";	public static final String MMS_MESSAGE_TYPE_SEND_REQUEST = "m-send-req";	public static final String MMS_MESSAGE_TYPE_SEND_CONF = "m-send-conf";		public static final String MMS_VERSION_1 = "1.0"; 		public static final String MMS_DELIVERY_REPORT_YES = "Yes";	public static final String MMS_DELIVERY_REPORT_NO = "No";		public static final String MMS_CLASS_PERSONAL = "Personal";	public static final String MMS_CLASS_ADVERTISEMENT = "Advertisement";	public static final String MMS_CLASS_INFORMATIONAL = "Informational";	public static final String MMS_CLASS_AUTO = "Auto";		public static final String MMS_PRIORITY_LOW = "Low";	public static final String MMS_PRIORITY_NORMAL = "Normal";	public static final String MMS_PRIORITY_HIGH = "High";		public static final String MMS_READ_REPLY_YES = "Yes";	public static final String MMS_READ_REPLY_NO = "No";		public static final String MMS_RESPONSE_STATUS_OK = "OK"; 	public static final String MMS_RESPONSE_STATUS_ERROR_UNSPECIFIED = "Error-unspecified";	public static final String MMS_RESPONSE_STATUS_ERROR_SERVICE_DENIED = "Error-service-denied";	public static final String MMS_RESPONSE_STATUS_ERROR_MESSAGE_FORMAT_CORRUPT = "Error-message-format-corrupt";	public static final String  MMS_RESPONSE_STATUS_ERROR_SENDING_ADDRESS_UNRESOLVED = "Error-sending-address-unresolved";	public static final String MMS_RESPONSE_STATUS_ERROR_MESSAGE_NOT_FOUND = "Error-message-not-found";	public static final String MMS_RESPONSE_STATUS_ERROR_NETWORK_PROBLEM = "Error-network-problem";	public static final String MMS_RESPONSE_STATUS_ERROR_CONTENT_NOT_ACCEPTED = "Error-contant-not-accepted";	public static final String MMS_RESPONSE_STATUS_ERROR_UNSUPPORTED_MESSAGE = "Error-unsupported-message"; 		public static final String MMS_SENDER_VISIBILITY_HIDE = "Hide";	public static final String MMS_SENDER_VISIBILITY_SHOW = "Show";		public static final String MMS_ADDRESS_TYPE_MOBILE_NUMBER = "/TYPE=PLMN";	public static final String MMS_ADDRESS_TYPE_MAIL = "";	public static final String MMS_ADDRESS_TYPE_IPV4 = "/TYPE=IPV4";	public static final String MMS_ADDRESS_TYPE_IPV6 = "/TYPE=IPV6";			/*=========================================================================	 * CONTENT TYPE CONSTANTS	 *=========================================================================*/		public static final String CTYPE_UNKNOWN = "*/*";	public static final String CTYPE_TEXT =       "text/*";	public static final String CTYPE_TEXT_PLAIN = "text/plain";	public static final String CTYPE_TEXT_HTML =  "text/html";	public static final String CTYPE_TEXT_WML =  "text/wnd.vap.wml";	public static final String CTYPE_IMAGE      = "image/*";	public static final String CTYPE_IMAGE_JPEG = "image/jpeg";	public static final String CTYPE_IMAGE_GIF  = "image/gif";	public static final String CTYPE_IMAGE_TIFF = "image/tiff";	public static final String CTYPE_IMAGE_PNG  = "image/png";	public static final String CTYPE_IMAGE_VND_WAP_WBMP = "image/vnd.wap.wbmp";	public static final String CTYPE_MULTIPART         = "multipart/*";	public static final String CTYPE_MULTIPART_MIXED   = "multipart/mixed";	public static final String CTYPE_APPLICATION_MULTIPART_MIXED = "application/vnd.wap.multipart.mixed";	public static final String CTYPE_APPLICATION_MULTIPART_RELATED = "application/vnd.wap.multipart.related";			/*=========================================================================	 * CLASS VARIABLES	 *=========================================================================*/	private String mmsMessageType;	private String mmsTransactionId;	private String mmsVersion;	private Date mmsDate;	private String mmsFrom;	private ArrayList<String> mmsTo;	private ArrayList<String> mmsCC;	private ArrayList<String> mmsBCC;	private String mmsSubject;	private String mmsClass;		private Date mmsExpiryTime;	private Boolean mmsExpiryTimeAbsolute;		private Date mmsDeliveryTime;	private Boolean mmsDeliveryTimeAbsolute;		private String mmsPriority;	private String mmsSenderVisibility;	private Boolean mmsDeliveryReport;	private Boolean mmsReadReply;	private String mmsContentType;	private String mmsResponseStatus;	private String mmsResponseText;	private String mmsMessageID;	private ArrayList<MmsPart> mmsParts;		/*=========================================================================	 * CONSTRUCTORS	 *=========================================================================*/	/**	 * Creates an MmsMessage object.	 */	public MmsMessage(){		this.mmsTo = new ArrayList<String>(); 		this.mmsCC = new ArrayList<String>(); 		this.mmsBCC = new ArrayList<String>();		this.mmsParts = new ArrayList<MmsPart>();	}		/*=========================================================================	 * METHODS	 *=========================================================================*/		/**	 * Sets the MMS message type.<br>	 * 	 * Supported types:	 * <ol>	 * 	<li>{@link MmsMessage#MMS_MESSAGE_TYPE_SEND_REQUEST}</li>	 * 	<li>{@link MmsMessage#MMS_MESSAGE_TYPE_SEND_CONF}</li>	 * </ol>	 * @param type type of the message	 * @throws MmsMessageException message type not supported	 */	public void setMessageType(String type) throws MmsMessageException{		if (type.equals(MMS_MESSAGE_TYPE_SEND_REQUEST))			this.mmsMessageType = type;					else if (type.equals(MMS_MESSAGE_TYPE_SEND_CONF))			this.mmsMessageType = type;		else			throw new MmsMessageException("Message type \"" + type + "\" not supported.");	}		/**	 * Checks if the message type is specified.	 * @return true if message type is specified, false otherwise	 */	public boolean isMessageTypeSet(){		return mmsMessageType != null;	}	/**	 * Sets the transaction id.	 * @param id transaction id	 */	public void setTransactionID(String id){		this.mmsTransactionId = id;	}		/**	 * Checks if the transaction identifier is set	 * @return true if set	 */	public boolean isTransactionIDSet(){		return mmsTransactionId != null;	}		/**	 * Sets the version of the MMS message.<br>	 * The only supported value is {@link MmsMessage#MMS_VERSION_1}.	 * @param version version of the MMS message	 * @throws MmsMessageException version not supported	 */	public void setVersion(String version) throws MmsMessageException{		if (version.equals(MMS_VERSION_1))			this.mmsVersion = version;		else			throw new MmsMessageException("Message version \"" + version + "\" not supported.");	}	/**	 * Checks if the version is present.	 * @return true if present, false otherwise	 */	public boolean isVersionSet(){		return mmsVersion != null;	}		/**	 * Sets the message date.	 * @param d date	 */	public void setMessageDate(Date d){		this.mmsDate = d;	}			/**	 * Sets the message date.	 * @param d date	 */	public void setMessageDate(long d){		this.mmsDate = new Date(d);	}	/**	 * Checks if the message date is present.	 * @return true if present, false otherwise	 */	public boolean isMessageDateSet(){		return mmsDate != null;	}		/**	 * Set the message sender.<br>	 * 	 * Supported values for <i>addressType</i>	 * <ol>	 * 	<li>{@link #MMS_ADDRESS_TYPE_IPV4}</li>	 * 	<li>{@link #MMS_ADDRESS_TYPE_IPV6}</li>	 * 	<li>{@link #MMS_ADDRESS_TYPE_MAIL}</li>	 * 	<li>{@link #MMS_ADDRESS_TYPE_MOBILE_NUMBER}</li>	 * </ol>	 * @param sender sender address	 * @param addressType address type	 * @throws MmsMessageException address type not supported	 */	public void setMessageSender(String sender, String addressType) throws MmsMessageException{		if (!addressType.equals(MMS_ADDRESS_TYPE_IPV4) &&			!addressType.equals(MMS_ADDRESS_TYPE_IPV6) &&			!addressType.equals(MMS_ADDRESS_TYPE_MAIL) &&			!addressType.equals(MMS_ADDRESS_TYPE_MOBILE_NUMBER)		) throw new MmsMessageException("Address type \"" + addressType + "\" not supported.");		this.mmsFrom = sender + addressType;	}	/**	 * Checks if the message sender is specified.	 * @return true if present	 */	public boolean isMessageSenderSet(){		return mmsFrom != null;	}		/**	 * Adds a message receiver.	 * 	 * @param receiver receiver address	 * @param addressType address type	 * @throws MmsMessageException address type not supported	 * @see #setMessageSender(String, String)	 */	public void addMessageReceiver(String receiver, String addressType) throws MmsMessageException{		if (!addressType.equals(MMS_ADDRESS_TYPE_IPV4) &&				!addressType.equals(MMS_ADDRESS_TYPE_IPV6) &&				!addressType.equals(MMS_ADDRESS_TYPE_MAIL) &&				!addressType.equals(MMS_ADDRESS_TYPE_MOBILE_NUMBER)			) throw new MmsMessageException("Address type \"" + addressType + "\" not supported.");		this.mmsTo.add(receiver + addressType);	}		/**	 * Checks if there is at least one receiver.	 * @return true if a receiver is present	 */	public boolean isMessageReceiverSet(){		return mmsTo.size() > 0;	}			/**	 * Returns the receivers for this MMS message.	 * @return receivers list	 */	public List<String> getMessageReceivers(){		return mmsTo;	}		/**	 * Adds a message CC.	 * @param receiver CC address	 * @param addressType address type	 * @throws MmsMessageException address type not supported	 * @see #setMessageSender(String, String)	 */	public void addMessageCC(String receiver, String addressType) throws MmsMessageException{		if (!addressType.equals(MMS_ADDRESS_TYPE_IPV4) &&				!addressType.equals(MMS_ADDRESS_TYPE_IPV6) &&				!addressType.equals(MMS_ADDRESS_TYPE_MAIL) &&				!addressType.equals(MMS_ADDRESS_TYPE_MOBILE_NUMBER)			) throw new MmsMessageException("Address type \"" + addressType + "\" not supported.");		this.mmsCC.add(receiver + addressType);	}		/**	 * Checks if there is at least one message CC.	 * @return true if one or more CC are present	 */	public boolean isMessageCCSet(){		return mmsCC.size() > 0;	}		/**	 * Return the CCs list.	 * @return CC list	 */	public List<String> getMessageCC(){		return mmsCC;	}		/**	 * Adds a message BCC	 * @param receiver BCC address	 * @param addressType address type	 * @throws MmsMessageException address type not supported	 * @see #setMessageSender(String, String)	 */	public void addMessaceBCC(String receiver, String addressType) throws MmsMessageException{		if (!addressType.equals(MMS_ADDRESS_TYPE_IPV4) &&				!addressType.equals(MMS_ADDRESS_TYPE_IPV6) &&				!addressType.equals(MMS_ADDRESS_TYPE_MAIL) &&				!addressType.equals(MMS_ADDRESS_TYPE_MOBILE_NUMBER)			) throw new MmsMessageException("Address type \"" + addressType + "\" not supported.");				this.mmsBCC.add(receiver + addressType);	}		/**	 * Checks if at least one BCC is present.	 * @return true if present	 */	public boolean isMessageBCCSet(){		return mmsBCC.size() > 0;	}		/**	 * Return the BCCs list	 * @return BCC list	 */	public List<String> getMessageBCC(){		return mmsBCC;	}			/**	 * Sets the message subject	 * @param subject	 */	public void setMessageSubject(String subject){		this.mmsSubject = subject;	}		/**	 * Checks if the subject is present.	 * @return true if present	 */	public boolean isMessageSubjectSet(){		return mmsSubject != null;	}		/**	 * Sets the message class.<br>	 * 	 * Supported class:	 * <ol>	 * 	<li>{@link #MMS_CLASS_AUTO}</li>	 * 	<li>{@link #MMS_CLASS_PERSONAL}</li>	 * 	<li>{@link #MMS_CLASS_INFORMATIONAL}</li>	 * 	<li>{@link #MMS_CLASS_ADVERTISEMENT}</li>	 * </ol>		 * @param messageClass message class	 * @throws MmsMessageException the message class is not supported	 */	public void setMessageClass(String messageClass) throws MmsMessageException{		if (!messageClass.equals(MMS_CLASS_AUTO) &&			!messageClass.equals(MMS_CLASS_PERSONAL) &&			!messageClass.equals(MMS_CLASS_INFORMATIONAL) &&			!messageClass.equals(MMS_CLASS_ADVERTISEMENT)		) throw new MmsMessageException("Message class \"" + messageClass + "\" not supported");		this.mmsClass = messageClass;	}		/**	 * Checks if the message class is present.	 * @return true if present	 */	public boolean isMessageClassSet(){		return mmsClass != null;	}		/**	 * Sets the message expiry time.<br>	 * 	 * If the <i>absolute</i> parameter is true, then <i>time</i> is considered the exact date	 * of expire for the mms message. Otherwise <i>time</i> will be added to the message date	 * to calculate the exact expire date.	 * @param time Time value	 * @param absolute Specifies if the time is relative or absolute	 */	public void setMessageExpiryTime(Date time, boolean absolute){		this.mmsExpiryTimeAbsolute = absolute;		this.mmsExpiryTime = time;	}		/**	 * Checks if the expiry time is specified.	 * @return true if present	 */	public boolean isMessageExpiryTimeSet(){		return mmsExpiryTime != null;	}		/**	 * Sets the message delivery time.	 * 	 * @param time time value	 * @param absolute specifies if the time is relative or absolute	 * @see #setMessageExpiryTime(Date, boolean)	 */	public void setMessageDeliveryTime(Date time, boolean absolute){

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -