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

📄 mmmessage.java

📁 用于开发mms应用的Java库
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* ***** BEGIN LICENSE BLOCK *****
 * Version: MPL 1.1
 *
 * The contents of this file are subject to the Mozilla Public License Version
 * 1.1 (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 * for the specific language governing rights and limitations under the
 * License.
 *
 * The Original Code is the Tambur MMS library.
 *
 * The Initial Developer of the Original Code is FlyerOne Ltd.
 * Portions created by the Initial Developer are Copyright (C) 2005
 * the Initial Developer. All Rights Reserved.
 *
 * Contributor(s):
 * 	Anders Lindh <alindh@flyerone.com>
 *
 * ***** END LICENSE BLOCK ***** */

package net.tambur.mms;
 
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
 
/**
 * This class represents a multimedia message. A multimedia message consists
 * of several parts, each containing headers and body (as in a mime message). 
 * <p>
 * The resulting message is encoded according to [MMSEncapsulation] with well-known
 * headers and corresponding values encoded according to [WAPWSP].
 * <p>
 * This class fully represents a MMS message (as specified in [MMSEncapsulation]), 
 * encoding and decoding functions are done by the MMEncoder and MMDecoder classes. 
 * <p>
 * References: 
 * <p>
 * <a href="http://www1.wapforum.org/tech/documents/WAP-209-MMSEncapsulation-20020105-a.pdf">
 * [MMSEncapsulation] WAP-209-MMSEncapsulation-20020105-a 
 * </a><br>
 * <a href="http://www1.wapforum.org/tech/documents/WAP-230-WSP-20010705-a.pdf">
 * [WAPWSP] WAP-230-WSP-20010705-a</a> 
 * <p>
 * 
 * <strong>Example 1: Composing a message</strong><p>
 * <pre>
 * 	MMMessage msg = new MMMessage();
 * 	msg.setMessageType(MMMessage.MESSAGE_TYPE_M_SEND_REQ);
 * 	msg.setTransactionId("0001");
 * 	msg.setFrom("+358405134265/TYPE=PLMN");
 * 	msg.setSubject("This is an example");
 * 
 * 	// add content
 * 	msg.addPart("text/smil", "<smil></smil>".getBytes(), false, null, null)
 * 
 * 	// print out (or do whatever)
 * 	System.out.println(msg); 
 * </pre>
 * <p>
 *
 * <strong>Example 2: Reading a message from file (decoding)</strong><p>
 * <pre>
 * 	String filename = "input.mms";
 * 	File f = new File(filename);
 *	
 * 	try {
 * 		FileInputStream fis = new FileInputStream(f);
 *			
 *		byte[] data = new byte[(int) f.length()];
 *		fis.read(data);
 *		fis.close();
 *			
 *		MMMessage msg = MMDecoder.decode(data);
 *
 *	} catch (Exception e) {
 *		System.out.println(e);
 *	} 
 * </pre>
 * <p>
 * <strong>Example 3: Writing (encoding) a message</strong><p> 
 * <pre>
 *	MMessage msg = ... // a created MMMessage
 *   
 * 	try {
 * 		File f = new File("output.mms");
 *		byte[] out = msg.encode();
 *		FileOutputStream fos = new FileOutputStream(f);
 *		fos.write(out);
 *		fos.flush();
 *		fos.close(); 
 * 	} catch (Exception e) {
 * 		System.out.println(e);
 * 	}
 * </pre>
 * <p>
 * 
 * @author Anders Lindh
 * @copyright Copyright FlyerOne Ltd 2005
 * @version $Revision: 1.1.1.1 $ $Date: 2005/04/14 09:04:10 $
 * @see MimeMessage
 *
 */
public class MMMessage extends MimeMessage implements Serializable {

	protected ArrayList bcc = null;
	protected ArrayList cc = null;
	protected String contentLocation = null;
	protected Date date = null;
	protected Boolean deliveryReport = null;
	protected Date deliveryTime = null;
	protected boolean deliveryTimeAbsolute = true;
	protected Date expiry = null;	
	protected boolean expiryAbsolute = true;
	protected String from = null;
	protected int messageClass = -1;
	protected String messageId = null;
	protected int messageType = -1;
	protected long messageSize = -1;
	protected int version = -1;
	protected int priority = -1;
	protected Boolean readReply = null;
	protected Boolean reportAllowed = null;
	protected int responseStatus = -1;
	protected String responseText = null;
	protected Boolean senderVisibility = null;
	protected int status = -1;
	protected String subject = null;
	protected ArrayList to = null; 
	protected String transactionId = null;	
	
	//protected boolean bModified = false; // wether this class has been modofied
	//protected byte[] rawContent = null;

	/**
	 * Set bcc (blind carbon copy). This is a shotcut to clearBcc(), addBccAddress(...)
	 */	
	public void setBcc(String s) { 
		clearBcc();
		addBccAddress(s);
	}
	
	/**
	 * Get Bcc (blind carbon copy) addresses, returns an empty ArrayList if none is set
	 */
	public ArrayList getBcc() { if (bcc == null) return new ArrayList(); else return bcc; }
	
	/**
	 * Remove all Bcc recipients
	 */
	public void clearBcc() { this.bcc = null; }
	
	/**
	 * Add a Bcc recipient
	 */
	public void addBccAddress(String s) { if (bcc == null) bcc = new ArrayList(); bcc.add(s); }

	/**
	 * Set Cc (carbon copy) field. This is a shotcut to clearCc(), addCcAddress(...)
	 */	
	public void setCc(String s) { 
		clearCc();
		addCcAddress(s);
	}

	/**
	 * Get Cc (carbon copy) recipient addresses, returns an empty ArrayList if none is set
	 */	
	public ArrayList getCc() { if (cc == null) return new ArrayList(); else return cc; }
	
	/**
	 * Remove all Cc recipients
	 */
	public void clearCc() { this.cc = null; }
	
	/**
	 * Add a Cc recipient
	 */	
	public void addCcAddress(String s) { if (cc == null) cc = new ArrayList(); cc.add(s); }

	/**
	 * Set Content-Location
	 */	
	public void setContentLocation(String loc) { this.contentLocation = loc; }
	
	/**
	 * Return Content-Location
	 */	
	public String getContentLocation() { return this.contentLocation; }
		
	/**
	 * Set Date
	 */
	public void setDate(Date date) { this.date = date; }
	
	/**
	 * Return Date
	 */
	public Date getDate() { return this.date; }
	
	/**
	 * Return string representation of date
	 */
	public String getDateStr() { return MMDecoder.formatDate(this.date); }

	/**
	 * Set X-MMS-Delivery-Report. Set to null to disable
	 */
	public void setDeliveryReport(Boolean b) { this.deliveryReport = b; }
	
	/**
	 * Return X-MMS-Delivery-Report. False is returned if null.
	 */
	public boolean getDeliveryReport() { if (deliveryReport == null) return false; return this.deliveryReport.booleanValue(); }

	/**
	 * Set X-MMS-Delivery-Time
	 */
	public void setDeliveryTime(Date date) { this.deliveryTime = date; }
	
	public void setDeliveryTimeAbsolute(boolean b) { this.deliveryTimeAbsolute = b; }
	public boolean getDeliveryTimeAbsolute() { return this.deliveryTimeAbsolute; }
	
	/**
	 * Get X-MMS-Delivery-Time
	 */
	public Date getDeliveryTime() { return this.deliveryTime; }
	
	/**
	 * Get X-MMS-Delivery-Time as String
	 */
	public String getDeliveryTimeStr() { 
		if (deliveryTimeAbsolute) return MMDecoder.formatDate(this.deliveryTime); else
			return MMDecoder.formatDate(new Date(this.deliveryTime.getTime() + System.currentTimeMillis()));
	}

	/**
	 * Set X-MMS-Expiry
	 */
	public void setExpiry(Date date) { this.expiry = date; }
	
	/**
	 * Return X-MMS-Expiry
	 */
	public Date getExpiry() { return this.expiry; }

	public void setExpiryAbsolute(boolean b) { this.expiryAbsolute = b; }
	public boolean getExpiryAbsolute() { return this.expiryAbsolute; }
	
	/**
	 * Return X-MMS-Expiry time as String
	 */
	public String getExpiryStr() { 
		if (expiryAbsolute) return MMDecoder.formatDate(this.expiry); else
			return MMDecoder.formatDate(new Date(this.expiry.getTime() + System.currentTimeMillis()));
	}

	/**
	 * Set From address
	 */
	public void setFrom(String from) { this.from = from; }
	
	/**
	 * Get From address
	 */
	public String getFrom() { return this.from; }

	/**
	 * Set X-MMS-Message-Class
	 */
	public void setMessageClass(int c) { messageClass = c; }
	
	/**
	 * Return X-MMS-Message-Class
	 */
	public int getMessageClass() { if (messageClass == -1) return 0; else return messageClass; }
	
	/**
	 * Return string representation of X-MMS-Message-Class
	 */
	public String getMessageClassStr() { if (messageClass == -1) return null; return MMConstants.MESSAGE_CLASSES[messageClass]; }

	/**
	 * Set Message-ID
	 */
	public void setMessageId(String id) { this.messageId = id; }
	
	/**
	 * Return Message-ID
	 */
	public String getMessageId() { if (messageId == null) return ""; else return this.messageId; }
	
	/**
	 * set X-MMS-Message-Type
	 */
	public void setMessageType(int type) { messageType = type; }
	
	/**
	 * Return X-MMS-Message-Type
	 */
	public int getMessageType() { return messageType; }

	/**
	 * Return string representation of X-MMS-Message-Type
	 */

⌨️ 快捷键说明

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