java.lang.Object
javax.servlet.GenericServlet
javax.servlet.http.HttpServlet
net.i2p.imagegen.QRServlet
- All Implemented Interfaces:
Serializable, Servlet, ServletConfig
This servlet generates QR code images.
- See Also:
Field Summary
FieldsModifier and TypeFieldDescriptionprivate IdenticonCacheCache of rendered identicons, keyed by seed.private static final StringFont used when the request names none.private static final longDefault time before an identicon expires.private static final StringImage format name the writer is asked for.private static final StringMime type of the identicon raster image.private static final StringMime type of the identicon SVG image.private longHow long a rendered identicon stays in the cache.private static final StringInit parameter naming the cache provider class.private static final StringInit parameter naming the image version.private static final StringRequest parameter for the image format.private static final StringRequest parameter for the identicon code.private static final StringRequest parameter for the identicon size.private static final StringRequest parameter for the identicon text.private static final longThe serialization version of the servlet.private intBumped when the rendered output format changes.Constructor Summary
ConstructorsConstructorDescriptionA servlet with no init parameters applied yet; the container calls init() before the first request, so construction alone configures nothing.Method Summary
Modifier and TypeMethodDescriptionprivate static booleanCheck if client accepts SVG.private static intappendQrPath(StringBuilder sb, BitMatrix matrix, int width, int height, int yOffset) Append SVG path data for QR modules.private static StringbitMatrixToSvg(BitMatrix matrix, String text, String textName) Convert QR BitMatrix to SVG markup.protected voiddoGet(HttpServletRequest request, HttpServletResponse response) Handle GET request: generate QR code image or SVG.private static StringEscape XML special characters.voidinit(ServletConfig cfg) Load configuration from servlet initialization parameters.Methods inherited from class HttpServlet
doDelete, doHead, doOptions, doPost, doPut, doTrace, getLastModified, service, serviceMethods inherited from class GenericServlet
destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log
Field Details
serialVersionUID
private static final long serialVersionUIDThe serialization version of the servlet.- See Also:
INIT_PARAM_VERSION
Init parameter naming the image version.- See Also:
INIT_PARAM_CACHE_PROVIDER
Init parameter naming the cache provider class.- See Also:
PARAM_IDENTICON_SIZE_SHORT
Request parameter for the identicon size.- See Also:
PARAM_IDENTICON_CODE_SHORT
Request parameter for the identicon code.- See Also:
PARAM_IDENTICON_TEXT_SHORT
Request parameter for the identicon text.- See Also:
PARAM_FORMAT
Request parameter for the image format.- See Also:
IDENTICON_IMAGE_FORMAT
Image format name the writer is asked for.- See Also:
IDENTICON_IMAGE_MIMETYPE
Mime type of the identicon raster image.- See Also:
IDENTICON_SVG_MIMETYPE
Mime type of the identicon SVG image.- See Also:
DEFAULT_IDENTICON_EXPIRES_IN_MILLIS
private static final long DEFAULT_IDENTICON_EXPIRES_IN_MILLISDefault time before an identicon expires.- See Also:
DEFAULT_FONT_NAME
Font used when the request names none.version
private int versionBumped when the rendered output format changes.cache
Cache of rendered identicons, keyed by seed.identiconExpiresInMillis
private long identiconExpiresInMillisHow long a rendered identicon stays in the cache.
Constructor Details
QRServlet
public QRServlet()A servlet with no init parameters applied yet; the container calls init() before the first request, so construction alone configures nothing.
Method Details
acceptsSvg
Check if client accepts SVG.- Parameters:
req- the request whose Accept header is inspected- Returns:
- true if the Accept header mentions image/svg+xml
bitMatrixToSvg
Convert QR BitMatrix to SVG markup.- Parameters:
matrix- the QR code modules to rendertext- the label to draw under the QR code, may be nulltextName- the label used when text is null or empty- Returns:
- the complete SVG document markup, with the label text only if a non-empty label was given
appendQrPath
private static int appendQrPath(StringBuilder sb, BitMatrix matrix, int width, int height, int yOffset) Append SVG path data for QR modules.- Parameters:
sb- the buffer the path data is appended tomatrix- the QR code modules to scanwidth- the number of columns to scanheight- the number of rows to scanyOffset- rows added to each module's y coordinate- Returns:
- the largest y coordinate written, for placing the label text
escapeXml
init
Load configuration from servlet initialization parameters.- Specified by:
initin interfaceServlet- Overrides:
initin classGenericServlet- Throws:
ServletException
doGet
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException Handle GET request: generate QR code image or SVG.- Overrides:
doGetin classHttpServlet- Throws:
ServletExceptionIOException