esmska.data
Class DefaultGateway
java.lang.Object
esmska.data.DefaultGateway
- All Implemented Interfaces:
- Gateway, GatewayInfo, java.lang.Comparable<Gateway>
public class DefaultGateway
- extends java.lang.Object
- implements Gateway
Default implementation of the Gateway interface.
This implementation caches all information retrieved from gateway script
in order to reduce the performance impact caused by javascript invocations.
|
Constructor Summary |
DefaultGateway(java.net.URL script)
Creates new DefaultGateway. |
|
Method Summary |
int |
compareTo(Gateway o)
|
boolean |
equals(java.lang.Object obj)
|
int |
getDelayBetweenMessages()
The delay in seconds that must be kept between sending messages. |
java.lang.String |
getDescription()
Short description of the website (purpose, restrictions, etc). |
javax.swing.Icon |
getIcon()
Gateway logo icon. |
java.lang.String |
getMaintainer()
Maintainer of the script. |
int |
getMaxChars()
Maximum message length the gateway allows to send. |
int |
getMaxParts()
Number of allowed messages which user can send at once. |
java.lang.String |
getMinProgramVersion()
Minimal program version required to run this script. |
java.lang.String |
getName()
Gateway name. |
java.lang.String[] |
getPreferredPrefixes()
List of telephone prefixes that are preferred by this gateway. |
java.net.URL |
getScript()
URL of gateway script (file or jar URL). |
int |
getSignatureExtraLength()
Number of extra characters used to display signature. |
int |
getSMSLength()
Length of one SMS. |
java.lang.String[] |
getSupportedLanguages()
Indicates for which website languages the script is working. |
java.lang.String[] |
getSupportedPrefixes()
List of telephone prefixes that are supported by this gateway. |
java.lang.String |
getVersion()
Version of the script. |
java.lang.String |
getWebsite()
The URL of the webpage of this gateway. |
int |
hashCode()
|
boolean |
isFavorite()
Return whether this gateway has been marked as user favorite |
boolean |
isHidden()
Return whether this gateway has been marked as hidden from the user interface |
boolean |
isLoginRequired()
Indicates whether this gateway requires login with username and
password. |
void |
setFavorite(boolean favorite)
Set this gateway as user favorite |
void |
setHidden(boolean hidden)
Set this gateway as hidden from user interface |
java.lang.String |
toString()
|
| Methods inherited from class java.lang.Object |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
DefaultGateway
public DefaultGateway(java.net.URL script)
throws java.io.IOException,
javax.script.ScriptException,
java.security.PrivilegedActionException,
java.beans.IntrospectionException
- Creates new DefaultGateway.
- Parameters:
script - system resource containing gateway script
- Throws:
java.io.IOException - When there are problem accessing the script file
javax.script.ScriptException - When gateway script is invalid
java.security.PrivilegedActionException - When gateway script is invalid
java.beans.IntrospectionException - When current JRE does not support JavaScript execution
java.lang.IllegalArgumentException - When gateway name is not valid
compareTo
public int compareTo(Gateway o)
- Specified by:
compareTo in interface java.lang.Comparable<Gateway>
hashCode
public int hashCode()
- Overrides:
hashCode in class java.lang.Object
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals in class java.lang.Object
toString
public java.lang.String toString()
- Overrides:
toString in class java.lang.Object
getScript
public java.net.URL getScript()
- Description copied from interface:
Gateway
- URL of gateway script (file or jar URL).
- Specified by:
getScript in interface Gateway
getIcon
public javax.swing.Icon getIcon()
- Description copied from interface:
Gateway
- Gateway logo icon.
Should be a 16x16px PNG with transparent background.
- Specified by:
getIcon in interface Gateway
getName
public java.lang.String getName()
- Description copied from interface:
GatewayInfo
- Gateway name.
This name will be visible in the list od available gateways.
The name must be in the form "[CC]Gateway", where CC is country code as defined
in ISO 3166-1 alpha-2
and Gateway is the very name of the gateway.
Country code should denote which country is the main interest of the gateway, for example:
- The gateway is only available in the language of that country.
- The gateway sends messages only to customers of that country's operator.
- The gateway requires a SIM card bought from that country's operator.
For international gateways, allowing to send SMS to multiple countries, use [INT]Gateway.
This name must be unique amongst other gateway names.
- Specified by:
getName in interface GatewayInfo
getVersion
public java.lang.String getVersion()
- Description copied from interface:
GatewayInfo
- Version of the script.
This is the the datum of last script modification in the YYYY-MM-DD format.
- Specified by:
getVersion in interface GatewayInfo
getMaintainer
public java.lang.String getMaintainer()
- Description copied from interface:
GatewayInfo
- Maintainer of the script.
This is the name and email of the maintainer (often the author) of the script.
The maintainer must be in format "NAME <EMAIL>". Name and email are mandatory.
- Specified by:
getMaintainer in interface GatewayInfo
getMinProgramVersion
public java.lang.String getMinProgramVersion()
- Description copied from interface:
GatewayInfo
- Minimal program version required to run this script.
This string is in a format "x.y.z", where x,y,z are numbers.
- Specified by:
getMinProgramVersion in interface GatewayInfo
getWebsite
public java.lang.String getWebsite()
- Description copied from interface:
GatewayInfo
- The URL of the webpage of this gateway. On this URL users can get more information
about this gateway, register an account, check if it is working, etc.
Can be an empty string, but that is strongly discouraged. The website address should
be provided if possible.
- Specified by:
getWebsite in interface GatewayInfo
getDescription
public java.lang.String getDescription()
- Description copied from interface:
GatewayInfo
- Short description of the website (purpose, restrictions, etc). Just one or two
sentences. Write it in a language corresponding to the gateway (i.e. english
for [INT] websites, local language for local gateways). Can be empty.
- Specified by:
getDescription in interface GatewayInfo
getSupportedPrefixes
public java.lang.String[] getSupportedPrefixes()
- Description copied from interface:
GatewayInfo
- List of telephone prefixes that are supported by this gateway.
All prefixes that are not mentioned here are *not supported* by this gateway.
For example for a gateway that can send messages only to numbers originating
from Czech Republic (country prefix: +420), and nowhere else, the value is
["+420"]. (The gateway doesn't have to support all numbers starting with +420,
but it certainly doesn't support any other prefix.)
The supported prefixes will usually map to country codes. The prefix always
starts with "+" sign and is 1-3 digits long. List of country calling codes is on
Wikipedia.
If the gateway works internationally, allowing to send SMS to multiple countries,
this will be an empty array.
- Specified by:
getSupportedPrefixes in interface GatewayInfo
- Returns:
- list of supported prefixes; empty array if gateway sends anywhere in the world
getPreferredPrefixes
public java.lang.String[] getPreferredPrefixes()
- Description copied from interface:
GatewayInfo
- List of telephone prefixes that are preferred by this gateway.
Preferred prefixes means that there is really high probability that this
gateway will be able to send message to a phone number with that prefix. Sometimes
a gateway support just a certain set of customers (of a single cell operator
for example) and this is a way how to mark them. It usually concerns just
free gateway, paid ones usually send everywhere.
If the gateway sends messages to any phone number within the supported
prefixes (see GatewayInfo.getSupportedPrefixes()) then this will be an empty
array.
Example: When the supported prefix is ["+420"] and this gateway allows sending
messages to an operator who owns prefixes "606" and "777", then the resulting
array of preferred prefixes is ["+420606", "+420777"].
- Specified by:
getPreferredPrefixes in interface GatewayInfo
- Returns:
- list of preferred prefixes; empty array if gateway sends to any phone number
in supported prefixes
getSMSLength
public int getSMSLength()
- Description copied from interface:
GatewayInfo
- Length of one SMS.
Usually, this number wil be around 160. Many gateways add some characters when sending
from their website, therefore this number can be often smaller.
It can happen that length of the sms can't be determined (it is different for
different numbers). In this case provide a negative number.
- Specified by:
getSMSLength in interface GatewayInfo
getMaxParts
public int getMaxParts()
- Description copied from interface:
GatewayInfo
- Number of allowed messages which user can send at once.
This is a multiplier of the getMaxChars() number. Some gateways offer only
very short crippled messages (eg. max 60 chars, rest with advertisement).
You can allow user to write a multiple of this number. The message will be
split in the program and send as separate standard messages. Be judicius when
specifying this number. Eg. in case of forementioned 60 chars max, multiplier
of 5 (therefore writing up to 300 chars) should be absolutely sufficient.
For "non-crippled" gateways, you should declare '1' here.
- Specified by:
getMaxParts in interface GatewayInfo
getMaxChars
public int getMaxChars()
- Description copied from interface:
GatewayInfo
- Maximum message length the gateway allows to send.
This is the maximum number of characters the user is allowed to type in
into the textarea on the gateway website.
- Specified by:
getMaxChars in interface GatewayInfo
getSignatureExtraLength
public int getSignatureExtraLength()
- Description copied from interface:
GatewayInfo
- Number of extra characters used to display signature.
Some gateways allow to add signature at the end of the message.
This is the number of characters used for "From: " label or something similar.
This number will be subtracted from the maximum message length.
If your gateway doesn't support signatures, declare '0' here.
- Specified by:
getSignatureExtraLength in interface GatewayInfo
getDelayBetweenMessages
public int getDelayBetweenMessages()
- Description copied from interface:
GatewayInfo
- The delay in seconds that must be kept between sending messages. The program
will wait for at least this number of seconds before attempting to send
another message. If there are no gateway restrictions, use '0'.
- Specified by:
getDelayBetweenMessages in interface GatewayInfo
isLoginRequired
public boolean isLoginRequired()
- Description copied from interface:
GatewayInfo
- Indicates whether this gateway requires login with username and
password. If this is true, it means that user must have some credentials
assigned from the operator or must register at gateway website prior to
using this gateway in program.
- Specified by:
isLoginRequired in interface GatewayInfo
getSupportedLanguages
public java.lang.String[] getSupportedLanguages()
- Description copied from interface:
GatewayInfo
- Indicates for which website languages the script is working.
This method is included because gateways may have their website translated
into many languages and therefore the response may come somehow localized.
If the script works independently of website language (no matching on sentences is done),
specify just an empty array.
In this case default user language will be used for retrieving the website.
If the script works only with one or more specific languages, provide their
two-letter codes (as specified by the ISO 639-1 Code) in an array.
In this case default user language will be used if it exists in the array,
otherwise first language in the array will be used (therefore it is reasonable
to specify the most widely used - like english - as first).
- Specified by:
getSupportedLanguages in interface GatewayInfo
- Returns:
- list of two-letter language codes for which this script works,
or empty array if the script works independently of language
isFavorite
public boolean isFavorite()
- Description copied from interface:
Gateway
- Return whether this gateway has been marked as user favorite
- Specified by:
isFavorite in interface Gateway
setFavorite
public void setFavorite(boolean favorite)
- Description copied from interface:
Gateway
- Set this gateway as user favorite
- Specified by:
setFavorite in interface Gateway
isHidden
public boolean isHidden()
- Description copied from interface:
Gateway
- Return whether this gateway has been marked as hidden from the user interface
- Specified by:
isHidden in interface Gateway
setHidden
public void setHidden(boolean hidden)
- Description copied from interface:
Gateway
- Set this gateway as hidden from user interface
- Specified by:
setHidden in interface Gateway