Class WebThumbs

java.lang.Object
com.iizix.server.webthumbs.WebThumbs

public class WebThumbs extends Object
Class holding all web thumbnails together and requesting only the ones needed.
Author:
Christopher Mindus
  • Field Details

  • Constructor Details

    • WebThumbs

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

    • siteToFileName

      public static String siteToFileName(String site, int width, int height, int quality)
      Gets the file name to use in the file provider for a Website thumbnail.
      Parameters:
      site - The Website 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()+"-thumbnail-"+width+'x'+height+".jpg".
      Throws:
      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 String siteToFileName(String site)
      Gets the file name to use in the file provider for a Website thumbnail.
      Parameters:
      site - The Website name, e.g. "oracle.com" or "www.oracle.com".
      Returns:
      File file name to use as "website-"+site.toLowerCase()+"-thumbnail.png".
    • fileNameToSite

      public static String fileNameToSite(String fileName)
      Converts a file name into a potential Website name.
      Parameters:
      fileName - The file name.
      Returns:
      The site name, or null is doesn't follow the rule "website-"+site.toLowerCase()+"-thumbnail.png".
    • urlToSite

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

      public static String urlToSite(InternetAddress address) throws MalformedURLException
      Converts an email address into a potential Website 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:
      MalformedURLException - If the address cannot be turned into a Website "URL".
    • stringToSite

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

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

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