Package esmska.data
Class Gateway
- java.lang.Object
-
- esmska.data.Gateway
-
- All Implemented Interfaces:
GatewayInfo,java.lang.Comparable<Gateway>
public class Gateway extends java.lang.Object implements GatewayInfo, java.lang.Comparable<Gateway>
Class representing a web gateway. This implementation caches all information retrieved from gateway script in order to reduce the performance impact caused by javascript invocations.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classGateway.FeatureThis enum attributes indicate which various features are supported by a given gateway.
-
Field Summary
Fields Modifier and Type Field Description static intmaxMessageLengthstatic java.lang.StringUNKNOWN
-
Constructor Summary
Constructors Constructor Description Gateway(java.net.URL script)Creates new Gateway.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intcompareTo(Gateway o)booleanequals(java.lang.Object obj)GatewayConfiggetConfig()intgetDelayBetweenMessages()The delay in seconds that must be kept between sending messages.java.lang.StringgetDescription()Short description of the website (purpose, restrictions, etc).java.lang.String[]getFeatures()The list of all supported features by this gateway.javax.swing.IcongetIcon()Gateway logo icon.java.lang.StringgetMaintainer()Maintainer of the script.intgetMaxChars()Maximum message length the gateway allows to send.intgetMaxParts()Number of allowed messages which user can send at once.java.lang.StringgetMinProgramVersion()Minimal program version required to run this script.java.lang.StringgetName()Gateway name.java.lang.String[]getPreferredPrefixes()List of telephone prefixes that are preferred by this gateway.java.net.URLgetScript()URL of gateway script (file or jar URL).java.lang.StringgetSenderName()Get sender name signature that should be prepended to the message before it is sent.intgetSMSLength()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.StringgetVersion()Version of the script.java.lang.StringgetWebsite()The URL of the webpage of this gateway.booleanhasFeature(Gateway.Feature feature)Decide whether this particular gateway supports given feature.inthashCode()booleanisFavorite()Return whether this gateway has been marked as user favoritebooleanisHidden()Return whether this gateway has been marked as hidden from the user interfacevoidsetConfig(GatewayConfig config)voidsetFavorite(boolean favorite)Set this gateway as user favoritevoidsetHidden(boolean hidden)Set this gateway as hidden from user interfacejava.lang.StringtoString()
-
-
-
Field Detail
-
UNKNOWN
public static final java.lang.String UNKNOWN
-
maxMessageLength
public static final int maxMessageLength
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Gateway
public Gateway(java.net.URL script) throws java.io.IOException, javax.script.ScriptException, java.security.PrivilegedActionException, java.beans.IntrospectionExceptionCreates new Gateway.- Parameters:
script- system resource containing gateway script- Throws:
java.io.IOException- When there are problem accessing the script filejavax.script.ScriptException- When gateway script is invalidjava.security.PrivilegedActionException- When gateway script is invalidjava.beans.IntrospectionException- When current JRE does not support JavaScript executionjava.lang.IllegalArgumentException- When gateway name is not valid
-
-
Method Detail
-
getScript
public java.net.URL getScript()
URL of gateway script (file or jar URL).
-
getIcon
public javax.swing.Icon getIcon()
Gateway logo icon. Should be a 16x16px PNG with transparent background.
-
isFavorite
public boolean isFavorite()
Return whether this gateway has been marked as user favorite
-
setFavorite
public void setFavorite(boolean favorite)
Set this gateway as user favorite
-
isHidden
public boolean isHidden()
Return whether this gateway has been marked as hidden from the user interface
-
setHidden
public void setHidden(boolean hidden)
Set this gateway as hidden from user interface
-
hasFeature
public boolean hasFeature(Gateway.Feature feature)
Decide whether this particular gateway supports given feature.
-
getMaxParts
public int getMaxParts()
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). To alleviate this problem, the user can write a longer text (a multiple of the allowed messages) and it will be split into separate messages automatically. This number will get computed dynamically. It will be the highest multiplier of getMaxChars() which doesn't exceed maxMessageLength chars message length and simmultaneously a maximum multiplier maxMaxParts.
-
getConfig
public GatewayConfig getConfig()
-
setConfig
public void setConfig(GatewayConfig config)
-
getSenderName
public java.lang.String getSenderName()
Get sender name signature that should be prepended to the message before it is sent.- Returns:
- empty string if user does not want any signature to be added; otherwise user name signature
-
compareTo
public int compareTo(Gateway o)
- Specified by:
compareToin interfacejava.lang.Comparable<Gateway>
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
getName
public java.lang.String getName()
Description copied from interface:GatewayInfoGateway 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.
This name must be unique amongst other gateway names.- Specified by:
getNamein interfaceGatewayInfo
-
getVersion
public java.lang.String getVersion()
Description copied from interface:GatewayInfoVersion of the script. This is the the datum of last script modification in the YYYY-MM-DD format.- Specified by:
getVersionin interfaceGatewayInfo
-
getMaintainer
public java.lang.String getMaintainer()
Description copied from interface:GatewayInfoMaintainer 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:
getMaintainerin interfaceGatewayInfo
-
getMinProgramVersion
public java.lang.String getMinProgramVersion()
Description copied from interface:GatewayInfoMinimal program version required to run this script. This string is in a format "x.y.z", where x,y,z are numbers.- Specified by:
getMinProgramVersionin interfaceGatewayInfo
-
getWebsite
public java.lang.String getWebsite()
Description copied from interface:GatewayInfoThe 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:
getWebsitein interfaceGatewayInfo
-
getDescription
public java.lang.String getDescription()
Description copied from interface:GatewayInfoShort 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:
getDescriptionin interfaceGatewayInfo
-
getSupportedPrefixes
public java.lang.String[] getSupportedPrefixes()
Description copied from interface:GatewayInfoList 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:
getSupportedPrefixesin interfaceGatewayInfo- Returns:
- list of supported prefixes; empty array if gateway sends anywhere in the world
-
getPreferredPrefixes
public java.lang.String[] getPreferredPrefixes()
Description copied from interface:GatewayInfoList 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 (seeGatewayInfo.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:
getPreferredPrefixesin interfaceGatewayInfo- 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:GatewayInfoLength 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:
getSMSLengthin interfaceGatewayInfo
-
getMaxChars
public int getMaxChars()
Description copied from interface:GatewayInfoMaximum 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:
getMaxCharsin interfaceGatewayInfo
-
getDelayBetweenMessages
public int getDelayBetweenMessages()
Description copied from interface:GatewayInfoThe 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:
getDelayBetweenMessagesin interfaceGatewayInfo
-
getSupportedLanguages
public java.lang.String[] getSupportedLanguages()
Description copied from interface:GatewayInfoIndicates 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:
getSupportedLanguagesin interfaceGatewayInfo- Returns:
- list of two-letter language codes for which this script works, or empty array if the script works independently of language
-
getFeatures
public java.lang.String[] getFeatures()
Description copied from interface:GatewayInfoThe list of all supported features by this gateway. It is a list of strings matching theGateway.Featureattributes.- Specified by:
getFeaturesin interfaceGatewayInfo
-
-