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

📄 mmsmessage.java

📁 编解码MMS彩信的Java类库
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
		this.mmsDeliveryTimeAbsolute = absolute;		this.mmsDeliveryTime = time;	}		/**	 * Checks if the delivery time is present.	 * @return true if present	 */	public boolean isMessageDeliveryTimeSet(){		return mmsDeliveryTime != null;	}			/**	 * Sets the message priority.<br>	 * 	 * Supported priorities:	 * <ol>	 * 	<li>{@link #MMS_PRIORITY_HIGH}</li>	 * <li>{@link #MMS_PRIORITY_NORMAL}</li>	 * <li>{@link #MMS_PRIORITY_LOW}</li>	 * </ol>	 * @param priority priority of the message	 * @throws MmsMessageException priority not supported	 */	public void setMessagePriority(String priority) throws MmsMessageException{		if (!priority.equals(MMS_PRIORITY_HIGH) &&			!priority.equals(MMS_PRIORITY_NORMAL) &&			!priority.equals(MMS_PRIORITY_LOW)		) throw new MmsMessageException("Priority \"" + priority + "\" not supported");		this.mmsPriority = priority;	}		/**	 * Checks if the priority is specified.	 * @return true if specified	 */	public boolean isMessagePrioritySet(){		return mmsPriority != null;	}			/**	 * Sets the sender visibility.<br>	 * 	 * Supported visibilities:	 * <ol>	 * 	<li>{@link #MMS_SENDER_VISIBILITY_HIDE}</li>	 * <li>{@link #MMS_SENDER_VISIBILITY_SHOW}</li>	 * </ol>	 * 	 * @param visibility visibility value	 * @throws MmsMessageException visibility not supported	 */	public void setSenderVisibility(String visibility) throws MmsMessageException{		if (!visibility.equals(MMS_SENDER_VISIBILITY_SHOW) &&			!visibility.equals(MMS_SENDER_VISIBILITY_HIDE)			) throw new MmsMessageException("Sender visibility \"" + visibility + "\" not supported");		this.mmsSenderVisibility = visibility;	}		/**	 * Checks if the visibility is present.	 * @return true if present	 */	public boolean isSenderVisibilitySet(){		return mmsSenderVisibility != null;	}		/**	 * Enables/disables the message delivery report.	 * @param enabled whether to enable the message delivery report	 */	public void setDeliveryReport(boolean enabled){		this.mmsDeliveryReport = new Boolean(enabled);	}		/**	 * Enables/disables the message read reply.	 * @param enabled whether to enable the message read reply	 */	public void setReadReply(boolean enabled){		this.mmsReadReply = new Boolean(enabled);	}		/**	 * Set the response status.<br>	 * 	 * Supported responses:	 * <ol>	 * 	<li>{@link #MMS_RESPONSE_STATUS_ERROR_CONTENT_NOT_ACCEPTED}</li>	 * 	<li>{@link #MMS_RESPONSE_STATUS_ERROR_MESSAGE_FORMAT_CORRUPT}</li>	 * 	<li>{@link #MMS_RESPONSE_STATUS_ERROR_MESSAGE_NOT_FOUND}</li>	 * 	<li>{@link #MMS_RESPONSE_STATUS_ERROR_NETWORK_PROBLEM}</li>	 * 	<li>{@link #MMS_RESPONSE_STATUS_ERROR_SENDING_ADDRESS_UNRESOLVED}</li>	 * 	<li>{@link #MMS_RESPONSE_STATUS_ERROR_SERVICE_DENIED}</li>	 * 	<li>{@link #MMS_RESPONSE_STATUS_ERROR_UNSPECIFIED}</li>	 * 	<li>{@link #MMS_RESPONSE_STATUS_ERROR_UNSUPPORTED_MESSAGE}</li>	 * 	<li>{@link #MMS_RESPONSE_STATUS_OK}</li>		 * </ol>	 * @param status response status	 * @throws MmsMessageException status not supported	 */	public void setResponseStatus(String status) throws MmsMessageException{		if (!status.equals(MMS_RESPONSE_STATUS_ERROR_CONTENT_NOT_ACCEPTED) &&			!status.equals(MMS_RESPONSE_STATUS_ERROR_MESSAGE_FORMAT_CORRUPT) &&			!status.equals(MMS_RESPONSE_STATUS_ERROR_MESSAGE_NOT_FOUND) &&			!status.equals(MMS_RESPONSE_STATUS_ERROR_NETWORK_PROBLEM) &&			!status.equals(MMS_RESPONSE_STATUS_ERROR_SENDING_ADDRESS_UNRESOLVED) &&			!status.equals(MMS_RESPONSE_STATUS_ERROR_SERVICE_DENIED) &&			!status.equals(MMS_RESPONSE_STATUS_ERROR_UNSPECIFIED) &&			!status.equals(MMS_RESPONSE_STATUS_ERROR_UNSUPPORTED_MESSAGE) &&			!status.equals(MMS_RESPONSE_STATUS_OK)		)throw new MmsMessageException("Status \"" + status + "\" not supported");		this.mmsResponseStatus = status;	}		/**	 * Checks if the response status is present.	 * @return true if present	 */	public boolean isResponseStatusSet(){		return mmsSubject != null;	}			/**	 * Sets the response text.	 * @param text response	 */	public void setResponseText(String text){		this.mmsResponseText = text;	}		/**	 * Checks if the response text is present.	 * @return true if present	 */	public boolean isResonseTextSet(){		return mmsResponseText != null;	}	public boolean isDeliveryReportSet(){		return this.mmsDeliveryReport != null;	}	public boolean isReadReplySet(){		return this.mmsReadReply != null;	}		/**	 * Sets the message identifier.	 * @param id message identifier	 */	public void setMessageID(String id){		this.mmsMessageID = id;	}		/**	 * Checks if the message identifier is present.	 * @return true if present	 */	public boolean isMessageIDSet(){		return mmsMessageID != null;	}			/**	 * Sets the content type for the message.<br>	 * 	 * Supported content types:	 * <ol>	 * 	<li>{@link #CTYPE_APPLICATION_MULTIPART_MIXED}</li>	 * 	<li>{@link #CTYPE_APPLICATION_MULTIPART_RELATED}</li>	 * 	<li>{@link #CTYPE_IMAGE}</li>	 * 	<li>{@link #CTYPE_IMAGE_GIF}</li>	 * 	<li>{@link #CTYPE_IMAGE_JPEG}</li>	 * 	<li>{@link #CTYPE_IMAGE_PNG}</li>	 *  <li>{@link #CTYPE_IMAGE_TIFF}</li>	 *  <li>{@link #CTYPE_IMAGE_VND_WAP_WBMP}</li>	 *  <li>{@link #CTYPE_MULTIPART}</li>	 *  <li>{@link #CTYPE_MULTIPART_MIXED}</li>	 *  <li>{@link #CTYPE_TEXT}</li>	 *  <li>{@link #CTYPE_TEXT_HTML}</li>	 *  <li>{@link #CTYPE_TEXT_PLAIN}</li>	 *  <li>{@link #CTYPE_TEXT_WML}</li>	 *  <li>{@link #CTYPE_UNKNOWN}</li>	 * </ol>	 * @param type content type	 */	public void setMessageContentType(String type){		this.mmsContentType = type;	}	/**	 * Chekcs if the message content type is present.	 * @return true if present	 */	public boolean isMessageContentTypeSet(){		return mmsContentType != null;	}		/**	 * Add a part to the MMS message.<br>	 * Checks if the content type of the message is compatible with the content type of the part.	 * 	 * @param part part to add to the message	 * @throws MmsMessageException the part is not compatible with the message	 */	public void addPart(MmsPart part) throws MmsMessageException{		if (mmsContentType.equals(CTYPE_MULTIPART) ||				mmsContentType.equals(CTYPE_MULTIPART_MIXED) ||				mmsContentType.equals(CTYPE_APPLICATION_MULTIPART_MIXED) ||				//Multipart related not yet supported				//mmsContentType.equals(CTYPE_APPLICATION_MULTIPART_RELATED) ||				mmsContentType.equals(CTYPE_UNKNOWN))			mmsParts.add(part);		else if (mmsParts.size() == 0) mmsParts.add(part);		else throw new MmsMessageException("Only one part admitted in a non Multipart message");	}		/**	 * Return the number of parts in the message.	 * @return parts number	 */	public int getPartsNumber(){		return mmsParts.size();	}		/**	 * Returns the mms parts in the message.	 * @return mms parts	 */	public List<MmsPart> getParts(){		return mmsParts;	}		/**	 * Returns the ith part or null if <i>i</i> is greater then parts number.	 * @param i part number desidered	 * @return ith part number	 */	public MmsPart getPart(int i){		try{			return mmsParts.get(i);		}catch (IndexOutOfBoundsException e){return null;}	}		/**	 * Returns the message type.	 * @return message type	 */	public String getMessageType(){		return this.mmsMessageType;	}		/**	 * Returns the transaction id.	 * @return transaction id	 */	public String getTransactionID(){		return this.mmsTransactionId;	}		/**	 * Return the version of the MMS Protocol.	 * @return version of MMS	 */	public String getVersion(){		return this.mmsVersion;	}		/**	 * Returns the date of the message.	 * @return message's date	 */	public Date getMessageDate(){		return this.mmsDate;	}		/**	 * Return the message sender.	 * @return sender	 */	public String getMessageSender(){		return this.mmsFrom;	}	/**	 * Return the message subject.	 * @return message subject	 */	public String getMessageSubject(){		return this.mmsSubject;	}		/**	 * Returns the message class.	 * @return message class	 */	public String getMessageClass(){		return this.mmsClass;	}		/**	 * Returns the message expiry time.	 * @return expiry time	 */	public Date getMessageExpiryTime(){		return this.mmsExpiryTime;	}		/**	 * Checks if the expiry time is absolute.	 * @return true if absolute, false otherwise	 */	public boolean isMessageExpiryTimeAbsolute(){		if (mmsExpiryTimeAbsolute == null) throw new IllegalStateException("Expiry Time not specified");		return this.mmsExpiryTimeAbsolute.booleanValue();	}		/**	 * Returns the delivery time of the message.	 * @return delivery time	 */	public Date getMessageDeliveryTime(){		return this.mmsDeliveryTime;	}		/**	 * Checks if the delivery time is absolute.	 * @return true if absolute, false otherwise	 */	public boolean isMessageDeliveryTimeAbsolute(){		if (mmsDeliveryTimeAbsolute == null) throw new IllegalStateException("Delivery Time not specified");		return this.mmsDeliveryTimeAbsolute.booleanValue();	}		/**	 * Returns the message priority.	 * @return message priority	 */	public String getMessagePriority(){		return this.mmsPriority;	}		/**	 * Returns the sender visibility.	 * @return sender visibility	 */	public String getSenderVisibility(){		return this.mmsSenderVisibility;	}		/**	 * Checks whether the delivery report is enabled	 * @return true if enabled	 */	public boolean isDeliveryReportEnabled(){		return this.mmsDeliveryReport;	}		/**	 * Checks whether the read reply is enabled	 * @return true if enabled	 */	public boolean isReadReplyEnabled(){		return this.mmsReadReply;	}		/**	 * Returns the response status.	 * @return response status	 */	public String getResponseStatus(){		return this.mmsResponseStatus;	}		/**	 * Returns the response text	 * @return response text	 */	public String getResponseText(){		return this.mmsResponseText;	}		/**	 * Returns the message identifier	 * @return message identifier	 */	public String getMessageID(){		return this.mmsMessageID;	}		/**	 * Returns the message content type.	 * @return message content type	 */	public String getMessageContentType(){		return this.mmsContentType;	}			/**	 * Produce a string representation of the message easily readable by a human.	 * @return string representation of the message 	 */	public String toString(){		String mmsMessage = "";				if (!isMessageTypeSet()) return "MessageType not defined";		if (!isTransactionIDSet()) return "transactionID not defined";		if (!isVersionSet()) return "Version not defined";		if (!isMessageContentTypeSet()) return "Content type not defined";								/* MessageType, TransactionId and Version MUST be the first header in this order*/		mmsMessage += MMS_MESSAGE_TYPE + " " + getMessageType() + NL;		mmsMessage += MMS_TRANSACTION_ID + " " + getTransactionID() + NL;		mmsMessage += MMS_VERSION + " " + getVersion() + NL;				if (isMessageIDSet()) mmsMessage += MMS_MESSAGE_ID + " " + getMessageID() + NL;				if (isMessageDateSet()) mmsMessage += MMS_DATE + " " + getMessageDate().getTime()/1000 + NL;		if (isMessageSenderSet()) mmsMessage += MMS_FROM + " " + getMessageSender() + NL;		if (isMessageReceiverSet()) mmsMessage += MMS_TO + " " + getMessageReceivers() + NL;		if (isMessageCCSet()) mmsMessage += MMS_CC + " " + getMessageCC() + NL;		if (isMessageBCCSet()) mmsMessage += MMS_BCC + " " + getMessageBCC() + NL;		if (isMessageSubjectSet()) mmsMessage += MMS_SUBJECT + " " + getMessageSubject() + NL;				if (isDeliveryReportEnabled())			if (isDeliveryReportEnabled()) mmsMessage += MMS_DELIVERY_REPORT + " " + MMS_DELIVERY_REPORT_YES + NL;			else mmsMessage += MMS_DELIVERY_REPORT + " " + MMS_DELIVERY_REPORT_NO + NL;					if (isReadReplyEnabled())					if (isReadReplyEnabled()) mmsMessage += MMS_READ_REPLY + " " + MMS_READ_REPLY_YES + NL;			else mmsMessage += MMS_READ_REPLY + " " + MMS_READ_REPLY_NO + NL;		if (isSenderVisibilitySet())				mmsMessage += MMS_SENDER_VISIBILITY + " " + getSenderVisibility() + NL;				if (isMessageClassSet())				mmsMessage += MMS_CLASS + " " + getMessageClass() + NL;				if (isMessageExpiryTimeSet())					if (isMessageExpiryTimeAbsolute()) 				mmsMessage += MMS_EXPIRY + " absolute " + getMessageExpiryTime().getTime()/1000 + NL;			else mmsMessage += MMS_EXPIRY + " relative " + getMessageExpiryTime().getTime()/1000 + NL;				if (isMessageDeliveryTimeSet())		if (isMessageDeliveryTimeAbsolute())			mmsMessage += MMS_DELIVERY_TIME + " absolute " + getMessageDeliveryTime().getTime()/1000 + NL;		else mmsMessage += MMS_DELIVERY_TIME + " relative " + getMessageDeliveryTime().getTime()/1000 + NL;				if (isMessagePrioritySet()) mmsMessage += MMS_PRIORITY + " " + getMessagePriority() + NL;				/* ContentType MUST be the last header followed by the body */		if (isMessageContentTypeSet()) mmsMessage += MMS_CONTENT_TYPE + " " + getMessageContentType() + NL;						Iterator<MmsPart> i = mmsParts.iterator();		MmsPart part;		byte[]  partContent;		while(i.hasNext()){			part = i.next();			mmsMessage += "Part " + part.getPartId() + NL;			mmsMessage += "ContentType " + part.getPartContentType() + NL;			partContent = part.getPartContent();			mmsMessage += "ContentLength " + partContent.length + NL;			for (int j=0; j<partContent.length; j++) mmsMessage += partContent[j];			mmsMessage += NL;		}				return mmsMessage;	}}

⌨️ 快捷键说明

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