Package esmska.data

Class 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 class  Gateway.Feature
      This enum attributes indicate which various features are supported by a given gateway.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int maxMessageLength  
      static java.lang.String UNKNOWN  
    • 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
      int compareTo​(Gateway o)  
      boolean equals​(java.lang.Object obj)  
      GatewayConfig getConfig()  
      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).
      java.lang.String[] getFeatures()
      The list of all supported features by this gateway.
      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).
      java.lang.String getSenderName()
      Get sender name signature that should be prepended to the message before it is sent.
      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.
      boolean hasFeature​(Gateway.Feature feature)
      Decide whether this particular gateway supports given feature.
      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
      void setConfig​(GatewayConfig config)  
      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
    • Field Detail

      • UNKNOWN

        public static final java.lang.String UNKNOWN
    • Constructor Detail

      • Gateway

        public Gateway​(java.net.URL script)
                throws java.io.IOException,
                       javax.script.ScriptException,
                       java.security.PrivilegedActionException,
                       java.beans.IntrospectionException
        Creates new Gateway.
        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
    • 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.
      • 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:
        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
      • 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
      • 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
      • 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
      • 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
      • getFeatures

        public java.lang.String[] getFeatures()
        Description copied from interface: GatewayInfo
        The list of all supported features by this gateway. It is a list of strings matching the Gateway.Feature attributes.
        Specified by:
        getFeatures in interface GatewayInfo