Class QRCodeHandler

java.lang.Object
org.primefaces.application.resource.BaseDynamicContentHandler
org.primefaces.application.resource.QRCodeHandler
All Implemented Interfaces:
DynamicContentHandler

public class QRCodeHandler extends BaseDynamicContentHandler
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected io.nayuki.qrcodegen.QrCode.Ecc
     
    void
    handle(javax.faces.context.FacesContext context)
     
    protected BufferedImage
    toImage(io.nayuki.qrcodegen.QrCode qr, int scale, int border)
     
    protected BufferedImage
    toImage(io.nayuki.qrcodegen.QrCode qr, int scale, int border, int lightColor, int darkColor)
    Returns a raster image depicting the specified QR Code, with the specified module scale, border modules, and module colors.
    protected String
    toSvgString(io.nayuki.qrcodegen.QrCode qr, int border, String lightColor, String darkColor)
    Returns a string of SVG code for an image depicting the specified QR Code, with the specified number of border modules.

    Methods inherited from class org.primefaces.application.resource.BaseDynamicContentHandler

    handleCache

    Methods inherited from class java.lang.Object

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

    • QRCodeHandler

      public QRCodeHandler()
  • Method Details

    • handle

      public void handle(javax.faces.context.FacesContext context) throws IOException
      Throws:
      IOException
    • getErrorCorrection

      protected io.nayuki.qrcodegen.QrCode.Ecc getErrorCorrection(String value)
    • toImage

      protected BufferedImage toImage(io.nayuki.qrcodegen.QrCode qr, int scale, int border)
    • toImage

      protected BufferedImage toImage(io.nayuki.qrcodegen.QrCode qr, int scale, int border, int lightColor, int darkColor)
      Returns a raster image depicting the specified QR Code, with the specified module scale, border modules, and module colors.

      For example, scale=10 and border=4 means to pad the QR Code with 4 light border modules on all four sides, and use 10×10 pixels to represent each module.

      Parameters:
      qr - the QR Code to render (not null)
      scale - the side length (measured in pixels, must be positive) of each module
      border - the number of border modules to add, which must be non-negative
      lightColor - the color to use for light modules, in 0xRRGGBB format
      darkColor - the color to use for dark modules, in 0xRRGGBB format
      Returns:
      a new image representing the QR Code, with padding and scaling
      Throws:
      NullPointerException - if the QR Code is null
      IllegalArgumentException - if the scale or border is out of range, or if {scale, border, size} cause the image dimensions to exceed Integer.MAX_VALUE
    • toSvgString

      protected String toSvgString(io.nayuki.qrcodegen.QrCode qr, int border, String lightColor, String darkColor)
      Returns a string of SVG code for an image depicting the specified QR Code, with the specified number of border modules. The string always uses Unix newlines (\n), regardless of the platform.
      Parameters:
      qr - the QR Code to render (not null)
      border - the number of border modules to add, which must be non-negative
      lightColor - the color to use for light modules, in any format supported by CSS, not null
      darkColor - the color to use for dark modules, in any format supported by CSS, not null
      Returns:
      a string representing the QR Code as an SVG XML document
      Throws:
      NullPointerException - if any object is null
      IllegalArgumentException - if the border is negative