Class AbstractQRGenerator
java.lang.Object
se.swedenconnect.bankid.rpapi.service.impl.AbstractQRGenerator
- All Implemented Interfaces:
QRGenerator
- Direct Known Subclasses:
ZxingQRGenerator
Abstract base class for QR generation.
- Author:
- Martin Lindström
-
Nested Class Summary
Nested classes/interfaces inherited from interface se.swedenconnect.bankid.rpapi.service.QRGenerator
QRGenerator.ImageFormat
-
Field Summary
Modifier and TypeFieldDescriptionstatic final QRGenerator.ImageFormat
The default image format to use for generated QR images.static final int
The default width and height (in pixels) to use for generated QR images. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected String
buildAnimatedInput
(String qrStartToken, String qrStartSecret, Instant orderTime) Generates the QR data for an "animated" QR code.protected String
buildInput
(String autoStartToken) Builds the URI that is used as input for the static QR generation.generateAnimatedQRCodeBase64Image
(String qrStartToken, String qrStartSecret, Instant orderTime) Generates an "animated" QR code image as a Base64 encoded image using default settings for size and the image format.generateAnimatedQRCodeBase64Image
(String qrStartToken, String qrStartSecret, Instant orderTime, int size, QRGenerator.ImageFormat format) Generates an "animated" QR code image as a Base64 encoded image.byte[]
generateAnimatedQRCodeImage
(String qrStartToken, String qrStartSecret, Instant orderTime) Generates an "animated" QR code image using default settings for size and the image format.generateQRCodeBase64Image
(String autoStartToken) Generates a (static) QR code image as a Base64 encoded image using default settings for size and the image format.generateQRCodeBase64Image
(String autoStartToken, int size, QRGenerator.ImageFormat format) Generates a (static) QR code image as a Base64 encoded image.byte[]
generateQRCodeImage
(String autoStartToken) Generates a (static) QR code image using default settings for size and the image format.void
setDefaultImageFormat
(QRGenerator.ImageFormat defaultImageFormat) Assigns the configured default image format to use for generated QR images.void
setDefaultSize
(int defaultSize) Assigns the default width and height (in pixels) to use for generated QR images.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface se.swedenconnect.bankid.rpapi.service.QRGenerator
generateAnimatedQRCodeImage, generateQRCodeImage
-
Field Details
-
DEFAULT_SIZE
public static final int DEFAULT_SIZEThe default width and height (in pixels) to use for generated QR images.- See Also:
-
DEFAULT_IMAGE_FORMAT
The default image format to use for generated QR images.
-
-
Constructor Details
-
AbstractQRGenerator
public AbstractQRGenerator()
-
-
Method Details
-
buildInput
Builds the URI that is used as input for the static QR generation.- Parameters:
autoStartToken
- the BankID autostart token- Returns:
- an URI string
-
buildAnimatedInput
protected String buildAnimatedInput(String qrStartToken, String qrStartSecret, Instant orderTime) throws IOException Generates the QR data for an "animated" QR code.- Parameters:
qrStartToken
- the QR start token (seeOrderResponse.getQrStartToken()
)qrStartSecret
- the QR start secret (seeOrderResponse.getQrStartSecret()
)orderTime
- the instant when the result from anBankIDClient.authenticate(se.swedenconnect.bankid.rpapi.service.AuthenticateRequest)
orBankIDClient.sign(se.swedenconnect.bankid.rpapi.service.SignatureRequest)
call was received- Returns:
- the QR data
- Throws:
IOException
- for errors calculating the code
-
generateQRCodeImage
Generates a (static) QR code image using default settings for size and the image format.- Specified by:
generateQRCodeImage
in interfaceQRGenerator
- Parameters:
autoStartToken
- the BankID autostart token- Returns:
- an byte array representing the generated QR code
- Throws:
IOException
- for errors during generation- See Also:
-
generateAnimatedQRCodeImage
public byte[] generateAnimatedQRCodeImage(String qrStartToken, String qrStartSecret, Instant orderTime) throws IOException Generates an "animated" QR code image using default settings for size and the image format.- Specified by:
generateAnimatedQRCodeImage
in interfaceQRGenerator
- Parameters:
qrStartToken
- the QR start token (seeOrderResponse.getQrStartToken()
)qrStartSecret
- the QR start secret (seeOrderResponse.getQrStartSecret()
)orderTime
- the instant when the result from anBankIDClient.authenticate(AuthenticateRequest)
or aBankIDClient.sign(SignatureRequest)
call was received- Returns:
- an byte array representing the generated QR code
- Throws:
IOException
- for errors during generation- See Also:
-
generateQRCodeBase64Image
public String generateQRCodeBase64Image(String autoStartToken, int size, QRGenerator.ImageFormat format) throws IOException Generates a (static) QR code image as a Base64 encoded image.For example:
data:image/png;base64, iVBORw0KGgoAAAANSUhEUgAAAAUA AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO 9TXL0Y4OHwAAAABJRU5ErkJggg==
The image may then be directly inserted in HTML code as:
<img src="data:image/png;base64, iVBORw0KGgoAAAANSUhEUgAAAAUA AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO 9TXL0Y4OHwAAAABJRU5ErkJggg==" scale="0">
- Specified by:
generateQRCodeBase64Image
in interfaceQRGenerator
- Parameters:
autoStartToken
- the BankID autostart tokensize
- the width and height of the generated QR code (in pixels)format
- the format for the generated QR code- Returns:
- the base64 encoded image
- Throws:
IOException
- for errors during generation- See Also:
-
generateQRCodeBase64Image
Generates a (static) QR code image as a Base64 encoded image using default settings for size and the image format.- Specified by:
generateQRCodeBase64Image
in interfaceQRGenerator
- Parameters:
autoStartToken
- the BankID autostart token- Returns:
- the base64 encoded image
- Throws:
IOException
- for errors during generation- See Also:
-
generateAnimatedQRCodeBase64Image
public String generateAnimatedQRCodeBase64Image(String qrStartToken, String qrStartSecret, Instant orderTime, int size, QRGenerator.ImageFormat format) Generates an "animated" QR code image as a Base64 encoded image.For example:
data:image/png;base64, iVBORw0KGgoAAAANSUhEUgAAAAUA AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO 9TXL0Y4OHwAAAABJRU5ErkJggg==
The image may then be directly inserted in HTML code as:
<img src="data:image/png;base64, iVBORw0KGgoAAAANSUhEUgAAAAUA AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO 9TXL0Y4OHwAAAABJRU5ErkJggg==" scale="0">
- Specified by:
generateAnimatedQRCodeBase64Image
in interfaceQRGenerator
- Parameters:
qrStartToken
- the QR start token (seeOrderResponse.getQrStartToken()
)qrStartSecret
- the QR start secret (seeOrderResponse.getQrStartSecret()
)orderTime
- the instant when the result from anBankIDClient.authenticate(AuthenticateRequest)
or aBankIDClient.sign(SignatureRequest)
call was receivedsize
- the width and height of the generated QR code (in pixels)format
- the format for the generated QR code- Returns:
- the base64 encoded image
- See Also:
-
generateAnimatedQRCodeBase64Image
public String generateAnimatedQRCodeBase64Image(String qrStartToken, String qrStartSecret, Instant orderTime) Generates an "animated" QR code image as a Base64 encoded image using default settings for size and the image format.- Specified by:
generateAnimatedQRCodeBase64Image
in interfaceQRGenerator
- Parameters:
qrStartToken
- the QR start token (seeOrderResponse.getQrStartToken()
)qrStartSecret
- the QR start secret (seeOrderResponse.getQrStartSecret()
)orderTime
- the instant when the order was received- Returns:
- the base64 encoded image
- See Also:
-
setDefaultSize
public void setDefaultSize(int defaultSize) Assigns the default width and height (in pixels) to use for generated QR images.If not assigned,
DEFAULT_SIZE
will be used.- Parameters:
defaultSize
- default width and height
-
setDefaultImageFormat
Assigns the configured default image format to use for generated QR images.If not assigned,
DEFAULT_IMAGE_FORMAT
will be used.- Parameters:
defaultImageFormat
- the default format
-