📄 cmessage.java
字号:
// jSMSEngine API.
// An open-source API package for sending and receiving SMS via a GSM device.
// Copyright (C) 2002-2006, Thanasis Delenikas, Athens/GREECE
// Web Site: http://www.jsmsengine.org
//
// jSMSEngine is distributed under the GPL license.
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// version 2 as published by the Free Software Foundation
//
// This program 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
package org.jsmsengine;
import java.util.*;
/**
This class encapsulates the basic characteristics of an SMS message. A message
is further subclassed to an "Incoming" message and an "Outgoing" message.
<br><br>
This class is <strong>never</strong> used directly. Please use one of its descendants.
@see CIncomingMessage
@see CStatusReportMessage
@see COutgoingMessage
@see CPhoneBook
*/
public class CMessage implements java.io.Serializable
{
public static final int MESSAGE_ENCODING_7BIT = 1;
public static final int MESSAGE_ENCODING_8BIT = 2;
public static final int MESSAGE_ENCODING_UNICODE = 3;
public static final int TYPE_INCOMING = 1;
public static final int TYPE_OUTGOING = 2;
public static final int TYPE_STATUS_REPORT = 3;
public static final int CLASS_ALL = 0;
public static final int CLASS_REC_UNREAD = 1;
public static final int CLASS_REC_READ = 2;
public static final int CLASS_STO_UNSENT = 3;
public static final int CLASS_STO_SENT = 4;
private int type;
protected String id;
protected int refNo;
protected int memIndex;
protected Date date;
protected Date dispatchDate;
protected String originator;
protected String recipient;
protected String text;
protected int messageEncoding;
protected Date dateOriginal;
protected Date dateReceived;
protected int mpRefNo;
protected int mpMaxNo;
protected int mpSeqNo;
protected String mpMemIndex;
protected int validityPeriod;
protected boolean statusReport;
protected boolean flashSms;
protected int srcPort;
protected int dstPort;
/**
Default constructor of the class.
@param type the type (incoming/outgoing) of the message.
@param date the creation date of the message.
@param originator the originator's number. Applicable only for incoming messages.
@param recipient the recipient's number. Applicable only for outgoing messages.
@param text the actual text of the message.
@param memIndex the index of the memory location in the GSM device where
this message is stored. Applicable only for incoming messages.
<br><br>Notes:<br>
<ul>
<li>Phone numbers are represented in their international format (e.g. +306974... for Greece).</li>
<li>"Recipient" may be an entry from the phonebook.</li>
</ul>
*/
public CMessage(int type, Date date, String originator, String recipient, String text, int memIndex)
{
this.type = type;
this.id = null;
this.refNo = -1;
this.memIndex = memIndex;
this.date = date;
this.originator = originator;
this.recipient = recipient;
this.text = text;
this.messageEncoding = MESSAGE_ENCODING_7BIT;
dispatchDate = null;
dateOriginal = null;
dateReceived = null;
mpRefNo = 0;
mpMaxNo = 0;
mpSeqNo = 0;
mpMemIndex = "";
validityPeriod = -1;
statusReport = false;
flashSms = false;
srcPort = -1;
dstPort = -1;
}
/**
Returns the type of the message. Type is either incoming or outgoing, as denoted
by the class' static values INCOMING and OUTGOING.
@return the type of the message.
*/
public int getType() { return type; }
/**
Returns the id of the message.
@return the id of the message.
*/
public String getId() { return id; }
/**
Returns the Reference Number of the message.
The Reference Number is returned from the SMSC upon succesful dispatch of a message.
@return the Reference Number of the message.
*/
public int getRefNo() { return refNo; }
/**
Returns the memory index of the GSM device, where the message is stored.
Applicable only for incoming messages.
@return the memory index of the message.
*/
public int getMemIndex() { return memIndex; }
/**
Returns the date of the message. For incoming messages, this is the sent date.
For outgoing messages, this is the creation date.
@return the date of the message.
*/
public Date getDate() { return date; }
/**
Returns the Originator of the message.
@return the originator of the message.
*/
public String getOriginator() { return originator; }
/**
Returns the Recipient of the message.
@return the recipient of the message.
*/
public String getRecipient() { return recipient; }
/**
Returns the actual text of the message (ASCII).
@return the text of the message.
*/
public String getText() { return text; }
/**
Returns the dispatch date of the message.
@return The dispatch date of the message.
*/
public Date getDispatchDate() { return dispatchDate; }
/**
Returns the date of the original message.
@return the date of the original message.
*/
public Date getDateOriginal() { return dateOriginal; }
/**
Returns the date on which the original message was received by recipient.
@return the date of receipt.
*/
public Date getDateReceived() { return dateReceived; }
/**
Returns the encoding method of the message. Returns of the constants
MESSAGE_ENCODING_7BIT, MESSAGE_ENCODING_8BIT, MESSAGE_ENCODING_UNICODE.
This is meaningful only when working in PDU mode.
@return the message encoding.
*/
public int getMessageEncoding() { return messageEncoding; }
public int getMpRefNo() { return mpRefNo; }
public int getMpMaxNo() { return mpMaxNo; }
public int getMpSeqNo() { return mpSeqNo; }
public String getMpMemIndex() { return mpMemIndex; }
/**
Returns the validity period (hours).
@return The validity period (hours).
*/
public int getValidityPeriod() { return validityPeriod; }
/**
Returns true if a status report is requested.
@return True if a status report is requested.
*/
public boolean getStatusReport() { return statusReport; }
/**
Returns true if this is a flash message.
@return True if this is a flash message.
*/
public boolean getFlashSms() { return flashSms; }
/**
Returns the source port. -1 means no port.
@return The source port.
*/
public int getSourcePort() { return srcPort; }
/**
Returns the destination port. -1 means no port.
@return The destination port.
*/
public int getDestinationPort() { return dstPort; }
/**
Set the id of the message.
@param id the id of the message.
*/
public void setId(String id) { this.id = id; }
/**
Set the Reference Number of the message.
@param refNo the id of the message.
*/
public void setRefNo(int refNo) { this.refNo = refNo; }
/**
Set the text of the message.
@param text the text of the message.
*/
public void setText(String text) { this.text = text; }
/**
Adds (concatenates) to the text of the message.
@param text the text to be added.
*/
public void addText(String text) { this.text += text; }
/**
Set the date of the message.
@param date the date of the message.
*/
public void setDate(Date date) { this.date = date; }
/**
Sets the dispatch date of the message.
@param date the dispatch date of the message.
*/
protected void setDispatchDate(Date date) { this.dispatchDate = date; }
/**
Set the phone number of the recipient. Applicable to outgoing messages.
@param recipient the recipient's phone number (international format).
*/
public void setRecipient(String recipient) { this.recipient = recipient; }
/**
Set the message encoding. Should be one of the constants
MESSAGE_ENCODING_7BIT, MESSAGE_ENCODING_8BIT, MESSAGE_ENCODING_UNICODE.
This is meaningful only when working in PDU mode - default is 7bit.
@param messageEncoding one of the message encoding contants.
*/
public void setMessageEncoding(int messageEncoding) { this.messageEncoding = messageEncoding; }
protected void setMpRefNo(int mpRefNo) { this.mpRefNo = mpRefNo; }
protected void setMpSeqNo(int mpSeqNo) { this.mpSeqNo = mpSeqNo; }
protected void setMemIndex(int memIndex) { this.memIndex = memIndex; }
protected void setMpMemIndex(int memIndex) { this.mpMemIndex += (mpMemIndex.length() == 0 ? "" : ",") + memIndex; }
/**
Sets the validity period.
@param hours The hours of validity period. Validity is expressed in relative format, i.e. starts counting
from the time the SMSC receives the message. A value of -1 will set the maximum validity period.
*/
public void setValidityPeriod(int hours) { this.validityPeriod = hours; }
/**
Sets if a status report is requested.
@param statusReport True if a status report is requested. Default is false (no status report).
*/
public void setStatusReport(boolean statusReport) { this.statusReport = statusReport; }
/**
Sets the message to be delivered as a flash message.
@param flashSms True if the message should be delivered as a flash SMS message.
*/
public void setFlashSms(boolean flashSms) { this.flashSms = flashSms; }
/**
Sets the source port. Set to -1 for no port.
@param port The source port (16bit addressing).
*/
public void setSourcePort(int port) { this.srcPort = port; }
/**
Sets the destination port. Set to -1 for no port.
@param port The destination port (16bit addressing).
*/
public void setDestinationPort(int port) { this.dstPort = port; }
public String toString()
{
String str;
str = "** GSM MESSAGE **\n";
str += " Type: " + (type == TYPE_INCOMING ? "Incoming" : (type == TYPE_OUTGOING ? "Outgoing" : "Status Report")) + "\n";
if (type == TYPE_INCOMING) str += " RefNo: " + mpRefNo + " / MaxNo: " + mpMaxNo + " / SeqNo: " + mpSeqNo + "\n";
str += " Id: " + id + "\n";
str += " SMSC Ref No: " + refNo + "\n";
str += " Memory Index: " + memIndex + "\n";
str += " MP Memory Index: " + mpMemIndex + "\n";
str += " Date: " + date + "\n";
str += " Originator: " + originator + "\n";
str += " Recipient: " + recipient + "\n";
str += " Text: " + text + "\n";
str += " Encoding: ";
switch (messageEncoding)
{
case MESSAGE_ENCODING_7BIT:
str += "7-Bit\n";
break;
case MESSAGE_ENCODING_8BIT:
str += "8-Bit\n";
break;
case MESSAGE_ENCODING_UNICODE:
str += "Unicode\n";
break;
}
if (type == TYPE_OUTGOING)
{
str += " Dispatch Date: " + dispatchDate + "\n";
str += " Validity Period (hours): " + validityPeriod + "\n";
str += " Source Port: " + srcPort + "\n";
str += " Destination Port: " + dstPort + "\n";
str += " Flash SMS: " + flashSms + "\n";
}
if (type == TYPE_STATUS_REPORT)
{
str += " Status Report extra information:\n";
str += " Reference No: " + refNo + "\n";
str += " Original Sent Date: " + dateOriginal + "\n";
str += " Date Received by Recipient: " + dateReceived + "\n";
}
str += "***\n";
return str;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -