@Override public void handle(FacesContext context) throws IOException { Map<String, String> params = context.getExternalContext().getRequestParameterMap(); ExternalContext externalContext = context.getExternalContext(); String sessionKey = params.get(Constants.DYNAMIC_CONTENT_PARAM); Map<String, Object> session = externalContext.getSessionMap(); Map<String, String> barcodeMapping = (Map) session.get(Constants.BARCODE_MAPPING); String value = barcodeMapping.get(sessionKey); if (value != null) { boolean cache = Boolean.parseBoolean(params.get(Constants.DYNAMIC_CONTENT_CACHE_PARAM)); externalContext.setResponseStatus(200); externalContext.setResponseContentType("image/png"); handleCache(externalContext, cache); ErrorCorrectionLevel ecl = ErrorCorrectionLevel.L; String errorCorrection = params.get("qrec"); if (!LangUtils.isValueBlank(errorCorrection)) { ecl = ErrorCorrectionLevel.valueOf(errorCorrection); } QRCode.from(value).to(ImageType.PNG).withErrorCorrection(ecl).withCharset("UTF-8") .writeTo(externalContext.getResponseOutputStream()); externalContext.responseFlushBuffer(); context.responseComplete(); } }
try imageBytes = QRCode.from( qrCodeContent ) .withCharset( PwmConstants.DEFAULT_CHARSET.toString() ) .withSize( width, height ) .stream() .toByteArray();
/** * returns a {@link File} representation of the QR code. The file is set to be deleted on exit (i.e. {@link * java.io.File#deleteOnExit()}). If you want the file to live beyond the life of the jvm process, you should make a copy. * * @return qrcode as file */ public File file() { File file; try { file = createTempFile(); MatrixToImageWriter.writeToPath(createMatrix(), imageType.toString(), file.toPath()); } catch (Exception e) { throw new QRGenerationException("Failed to create QR image from text due to underlying exception", e); } return file; }
/** * Create a QR code from the given text. <br/><br/> * <p/> * There is a size limitation to how much you can put into a QR code. This has been tested to work with up to a length of 2950 * characters.<br/><br/> * <p/> * The QRCode will have the following defaults: <br/> {size: 100x100}<br/>{imageType:PNG} <br/><br/> * <p/> * Both size and imageType can be overridden: <br/> Image type override is done by calling {@link * QRCode#to(net.glxn.qrgen.image.ImageType)} e.g. QRCode.from("hello world").to(JPG) <br/> Size override is done by calling * {@link QRCode#withSize} e.g. QRCode.from("hello world").to(JPG).withSize(125, 125) <br/> * * @param text the text to encode to a new QRCode, this may fail if the text is too large. <br/> * @return the QRCode object <br/> */ public static QRCode from(String text) { return new QRCode(text); }
/** * Overrides the default charset by supplying a {@link com.google.zxing.EncodeHintType#CHARACTER_SET} hint to {@link * com.google.zxing.qrcode.QRCodeWriter#encode} * * @return the current QRCode object */ public QRCode withCharset(String charset) { return withHint(EncodeHintType.CHARACTER_SET, charset); }
private void writeToStream(OutputStream stream) throws IOException, WriterException { MatrixToImageWriter.writeToStream(createMatrix(), imageType.toString(), stream); }
/** * returns a {@link File} representation of the QR code. The file has the given name. The file is set to be deleted on exit * (i.e. {@link java.io.File#deleteOnExit()}). If you want the file to live beyond the life of the jvm process, you should * make a copy. * * @param name name of the created file * @return qrcode as file * @see #file() */ public File file(String name) { File file; try { file = createTempFile(name); MatrixToImageWriter.writeToPath(createMatrix(), imageType.toString(), file.toPath()); } catch (Exception e) { throw new QRGenerationException("Failed to create QR image from text due to underlying exception", e); } return file; }
/** * Creates a a QR Code from the given {@link VCard}. * <p/> * The QRCode will have the following defaults: <br/> {size: 100x100}<br/>{imageType:PNG} <br/><br/> * * @param vcard the vcard to encode as QRCode * @return the QRCode object */ public static QRCode from(VCard vcard) { return new QRCode(vcard.toString()); }
/** * Overrides the default error correction by supplying a {@link com.google.zxing.EncodeHintType#ERROR_CORRECTION} hint to * {@link com.google.zxing.qrcode.QRCodeWriter#encode} * * @return the current QRCode object */ public QRCode withErrorCorrection(ErrorCorrectionLevel level) { return withHint(EncodeHintType.ERROR_CORRECTION, level); }
public void handle(FacesContext context) throws IOException { Map<String, String> params = context.getExternalContext().getRequestParameterMap(); ExternalContext externalContext = context.getExternalContext(); String sessionKey = (String) params.get(Constants.DYNAMIC_CONTENT_PARAM); Map<String, Object> session = externalContext.getSessionMap(); Map<String, String> barcodeMapping = (Map) session.get(Constants.BARCODE_MAPPING); String value = barcodeMapping.get(sessionKey); if (value != null) { boolean cache = Boolean.valueOf(params.get(Constants.DYNAMIC_CONTENT_CACHE_PARAM)); externalContext.setResponseStatus(200); externalContext.setResponseContentType("image/png"); handleCache(externalContext, cache); ErrorCorrectionLevel ecl = ErrorCorrectionLevel.L; String errorCorrection = params.get("qrec"); if (!ComponentUtils.isValueBlank(errorCorrection)) { ecl = ErrorCorrectionLevel.valueOf(errorCorrection); } QRCode.from(value).to(ImageType.PNG).withErrorCorrection(ecl).withCharset("UTF-8") .writeTo(externalContext.getResponseOutputStream()); externalContext.responseFlushBuffer(); context.responseComplete(); } }