Class FontDownloadServlet

java.lang.Object
jakarta.servlet.GenericServlet
jakarta.servlet.http.HttpServlet
com.levigo.jadice.web.server.FontDownloadServlet
All Implemented Interfaces:
jakarta.servlet.Servlet, jakarta.servlet.ServletConfig, Serializable
Direct Known Subclasses:
FontResourceServlet

@WebServlet(description="Servlet providing downloadable fonts", displayName="jadice web toolkit font download", name="jwtFontDownloadServlet", urlPatterns="/jwt/font/*") public class FontDownloadServlet extends jakarta.servlet.http.HttpServlet

A servlet providing TrueType fonts, which are available in the server sided FontManager, for download purposes. These fonts are designated to be used for browser and client independent rendering of annotations

Usage: http://<base-url>/jwt/font?name=<font-name>&style=<styles>

parameters
Parameter Name required Description
name yes Name of the font to retrieve, may either be a symbolic name (e.g. "Serif") or a concrete font name (e.g. "Times New Roman")
style no a comma separated list of styles the font shall have. These may be plain, bold and italic. If this parameter is omitted plain will be assumed
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected String
     
    protected long
     

    Fields inherited from class jakarta.servlet.http.HttpServlet

    LEGACY_DO_HEAD
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    addCacheHeaders(jakarta.servlet.http.HttpServletResponse response)
    Add cache headers to response according to the chosen cacheTimeToLive.
    protected boolean
    clientSupportsWoff(String ua, boolean woff2)
    Tests if a Client supports WOFF or WOFF2.
    protected void
    doGet(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response)
     
    long
    Get the time to live in seconds signaled to clients for downloaded fonts.
    protected String
    Calculates the MD5-Hash of a given stream.
    void
    init(jakarta.servlet.ServletConfig config)
    This servlet is configured via the WebServlet-Annotation.
    void
    setCacheTimeToLive(long cacheTimeToLive)
    Set the time to live in seconds signaled to clients for downloaded fonts.

    Methods inherited from class jakarta.servlet.http.HttpServlet

    doDelete, doHead, doOptions, doPost, doPut, doTrace, getLastModified, service, service

    Methods inherited from class jakarta.servlet.GenericServlet

    destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log

    Methods inherited from class java.lang.Object

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

    • accessControlAllowOriginHeader

      protected String accessControlAllowOriginHeader
    • cacheTimeToLive

      protected long cacheTimeToLive
  • Constructor Details

    • FontDownloadServlet

      public FontDownloadServlet()
  • Method Details

    • init

      public void init(jakarta.servlet.ServletConfig config) throws jakarta.servlet.ServletException
      This servlet is configured via the WebServlet-Annotation. An integrator can configure the init-params with web.xml as web.xml has a higher order than the annotation.
      Specified by:
      init in interface jakarta.servlet.Servlet
      Overrides:
      init in class jakarta.servlet.http.HttpServlet
      Throws:
      jakarta.servlet.ServletException
    • doGet

      protected void doGet(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) throws jakarta.servlet.ServletException, IOException
      Overrides:
      doGet in class jakarta.servlet.http.HttpServlet
      Throws:
      jakarta.servlet.ServletException
      IOException
    • getStreamHash

      protected String getStreamHash(InputStream inputStream)
      Calculates the MD5-Hash of a given stream.
      Parameters:
      inputStream - the stream that provides the data
      Returns:
      the MD5-hash or null if an error occurred
    • addCacheHeaders

      protected void addCacheHeaders(jakarta.servlet.http.HttpServletResponse response)
      Add cache headers to response according to the chosen cacheTimeToLive.
      Parameters:
      response - the HttpServletResponse
    • getCacheTimeToLive

      public long getCacheTimeToLive()
      Get the time to live in seconds signaled to clients for downloaded fonts.
      Returns:
      a time to live in seconds
    • setCacheTimeToLive

      public void setCacheTimeToLive(long cacheTimeToLive)
      Set the time to live in seconds signaled to clients for downloaded fonts.
      Parameters:
      cacheTimeToLive - a time to live in seconds
    • clientSupportsWoff

      protected boolean clientSupportsWoff(String ua, boolean woff2)
      Tests if a Client supports WOFF or WOFF2. The test is based on the user-agent and is not 100% reliable. This is b/c only the major version is checked, also mobile is not considered. For font loading, this is not a problem, in the worst case a Client could handle WOFF but gets the TTF fallback.
      Parameters:
      ua - the User-Agent
      woff2 - test for WOFF2 if true, for WOFF if false
      Returns:
      true if browser supports WOFF/WOFF2, false otherwise