Class WebLogos


  • public class WebLogos
    extends java.lang.Object
    Class holding all web site logos together and requesting only the ones needed.
    Author:
    Christopher Mindus
    • Field Summary

      Fields 
      Modifier and TypeFieldDescription
      static booleanDEBUG
      The debug flag.
      static java.lang.String[]FILE_EXTS
      Supported file extensions: ".png", ".jpg", ".jpeg", ".gif", ".bmp", ...
    • Constructor Summary

      Constructors 
      ConstructorDescription
      WebLogos​(ServerShell server)
      Constructor.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and TypeMethodDescription
      static java.lang.StringfileNameToSite​(java.lang.String fileName)
      Converts a logo file name into a potential web site name.
      WSFileProvidergetFileProvider()
      Gets the file provider for logos that are persistent.
      WebLogorequestWebLogo​(java.lang.String site)
      Requests a new logo for a web site.
      static java.io.FilesiteToFileName​(java.io.File root, java.lang.String site)
      Gets the file name to use in the file provider for a web site logo.
      static java.lang.StringsiteToFileName​(java.lang.String site)
      Gets the file name to use in the file provider for a web site logo.
      static java.lang.StringsiteToFileName​(java.lang.String site, int width, int height, int quality)
      Gets the file name to use in the file provider for a web site logo.
      static java.lang.StringstringToSite​(java.lang.String site)
      Converts an URL or email to a potential web site.
      static java.lang.StringurlToSite​(java.net.URL url)
      Converts a URL into a potential web site name.
      static java.lang.StringurlToSite​(InternetAddress address)
      Converts an email address into a potential web site name.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • FILE_EXTS

        public static final java.lang.String[] FILE_EXTS
        Supported file extensions: ".png", ".jpg", ".jpeg", ".gif", ".bmp", ... (".svg" later on).
    • Constructor Detail

      • WebLogos

        public WebLogos​(ServerShell server)
                 throws java.io.IOException
        Constructor. This constructor should NOT be called directly, it is handled from the Server itself.
        Parameters:
        server - The server instance.
        Throws:
        java.io.IOException - If the COMMON_PERSISTENT file provider could not
        java.lang.IllegalStateException - If constructor is called outside of the server itself.
    • Method Detail

      • siteToFileName

        public static java.lang.String siteToFileName​(java.lang.String site,
                                                      int width,
                                                      int height,
                                                      int quality)
        Gets the file name to use in the file provider for a web site logo.
        Parameters:
        site - The web site name, e.g. "oracle.com" or "www.oracle.com".
        width - The requested width of the image, range 10-1000.
        height - The requested height of the image, range 10-1000.
        quality - The quality of the image (0=pixel-perfect as PNG, otherwise 1-100 for JPG quality).
        Returns:
        File file name to use as below. File name ends with ".jpg" when quality is 1-100, or ".png" when quality is zero (loss-less). "website-"+site.toLowerCase()+"-logo-"+width+'x'+height+".jpg".
        Throws:
        java.lang.IllegalArgumentException - If width is not in range of 10-1000, height is not in range of 10-1000, or quality is not in range of 0-100.
      • siteToFileName

        public static java.io.File siteToFileName​(java.io.File root,
                                                  java.lang.String site)
        Gets the file name to use in the file provider for a web site logo.
        Parameters:
        root - The root of the file provider that contains the web site logos. The lastest updated file will be returned with the file name supported.
        site - The web site name, e.g. "oracle.com" or "www.oracle.com".
        Returns:
        File use as "website-"+site.toLowerCase()+"-logo.[png|jpg|...]". The root will be searched for file names that matches the file extensions (.png, .jpg, ...). The one with the latest date is returned. If none is found, null is returned. If a valid file is returned, it is canonical.
      • siteToFileName

        public static java.lang.String siteToFileName​(java.lang.String site)
        Gets the file name to use in the file provider for a web site logo.
        Parameters:
        site - The web site name, e.g. "oracle.com" or "www.oracle.com".
        Returns:
        File file name to use as "website-"+site.toLowerCase()+"-logo.[png|jpg|...]". The default is to return the "png" file extension, although that may not be the one actually used (it is very common though).
      • fileNameToSite

        public static java.lang.String fileNameToSite​(java.lang.String fileName)
        Converts a logo file name into a potential web site name.
        Parameters:
        fileName - The file name.
        Returns:
        The site name, or null is doesn't follow the rule "website-"+site.toLowerCase()+"-logo.[png|jpg|...]".
      • urlToSite

        public static java.lang.String urlToSite​(java.net.URL url)
                                          throws java.net.MalformedURLException
        Converts a URL into a potential web site name.
        Parameters:
        url - The URL.
        Returns:
        The site name, or null it cannot be established properly. The protocol is not specified (http/https).
        Throws:
        java.net.MalformedURLException - If the address cannot be turned into a web site "URL".
      • urlToSite

        public static java.lang.String urlToSite​(InternetAddress address)
                                          throws java.net.MalformedURLException
        Converts an email address into a potential web site name.
        Parameters:
        address - The mail address.
        Returns:
        The site name, or null it cannot be established properly. The protocol is not specified (http/https).
        Throws:
        java.net.MalformedURLException - If the address cannot be turned into a web site "URL".
      • stringToSite

        public static java.lang.String stringToSite​(java.lang.String site)
                                             throws java.net.MalformedURLException
        Converts an URL or email to a potential web site.
        Parameters:
        site - The string as a potential site.
        Returns:
        The web site name, never null. The protocol is not specified (http/https).
        Throws:
        java.net.MalformedURLException
      • getFileProvider

        public WSFileProvider getFileProvider()
        Gets the file provider for logos that are persistent.
        Returns:
        The file provider.
      • requestWebLogo

        public WebLogo requestWebLogo​(java.lang.String site)
                               throws java.net.MalformedURLException,
                                      java.lang.IllegalStateException
        Requests a new logo for a web site. If already present, it will be returned directly, otherwise you might have to wait for it using the WebLogo.waitForCompletion(Runnable).
        Parameters:
        site - A URL string where the protocol will be stripped.
        Returns:
        The instance of a WebThumbnail.
        Throws:
        java.net.MalformedURLException - If the protocol in invalid.
        java.lang.IllegalStateException - If the WebThumbs instance is disposed of or was not initialized with a proper API key.