Class BarcodeURN

java.lang.Object
com.iizix.urn.URN
com.iizix.barcode.BarcodeURN
All Implemented Interfaces:
Serializable, Cloneable

public class BarcodeURN extends URN implements Cloneable, Serializable
Barcode Uniform Resource Naming (URN) instance class, holding the barcode type and data string.

For better control of the barcode and additional parameters use the BarcodeBuilder from a call to {@link BarcodeType#createBuilder()}.

Barcode URN's are encoded in IIZI as:

    urn:iz-barcode:type:text[:width=w][:height:h][:param1=value1:...:paramN=valueN]

where the valid types are (in lower case):

  • AZTEC *,
  • CODABAR,
  • CODE_39,
  • CODE_93,
  • CODE_128,
  • DATA_MATRIX *,
  • EAN_8,
  • EAN_13,
  • ITF,
  • PDF_417 *,
  • QR_CODE *,
  • UPC_A; and
  • UPC_E.

The types marked with an asterisk '*' are two dimensional. Generally all barcodes needs a width and height to be displayed properly.

Author:
Christopher Mindus
See Also:
  • Method Details

    • from

      public static BarcodeURN from(BarcodeType format, String text, int width, int height) throws BarcodeException
      Creates a BarcodeURN for a barcode format or type.

      Note: if you specify a width or height that is too small, the resulting barcode might be larger.

      For better control of the barcode and additional parameters use the BarcodeBuilder from a call to {@link BarcodeType#createBuilder()}.

      Parameters:
      format - The barcode format or type, must be non-null. If the format is a QR code, the error correction level will be set to L = Lowest = ~7%.
      text - The barcode text string, must be non-null.
      width - The width, or zero for smallest, negative width is set to zero (smallest).
      height - The height, or zero for smallest, negative height is set to zero (smallest).
      Throws:
      BarcodeException - If there are missing or invalid parameters assigned in this builder encountered during barcode encoding.
    • from

      public static BarcodeURN from(BarcodeType format, String text, int width, int height, ErrorCorrectionLevel errorCorrectionLevel) throws BarcodeException
      Creates a BarcodeURN for a barcode format or type, and for the QR code format, an optional error correction level.

      Note: if you specify a width or height that is too small, the resulting barcode might be larger.

      For better control of the barcode and additional parameters use the BarcodeBuilder from a call to {@link BarcodeType#createBuilder()}.

      Parameters:
      format - The barcode format or type, must be non-null. If the format is a QR code, the error correction level will be set to L = Lowest = ~7%.
      text - The barcode text string, must be non-null.
      width - The width, or zero for smallest, negative width is set to zero (smallest).
      height - The height, or zero for smallest, negative height is set to zero (smallest).
      errorCorrectionLevel - Only applies to BarcodeType.QR_CODE, null for default L = Low = ~7% error correction level. If the barcode type is anything else but a QR code, this parameter will be set to null.
      Throws:
      BarcodeException - If there are missing or invalid parameters assigned in this builder encountered during barcode encoding.
    • createBuilder

      public BarcodeBuilder createBuilder()
      Creates a barcode builder for this barcode URN. This method is useful if e.g. a barcode has been read from an image (file) and the size is not present.
      Returns:
      A new barcode builder for this barcode URN.
    • getSVG

      public String getSVG()
      Gets the URL of this as a data URL containing SVG code for the barcode.
      Returns:
      The data URL as data:image/svg+xml;base64,<i>data</i>.
    • getURL

      public String getURL() throws IOException
      Gets the URL of this as a data URL containing SVG code for the barcode.
      Specified by:
      getURL in class URN
      Returns:
      The data URL as data:image/svg+xml;base64,<i>data</i>.
      Throws:
      IOException - If there was a problem retrieving the file, an SQL error or other I/O error that caused the URL not to be possible to get (e.g. barcode failure).
    • isImageTargetSupported

      public boolean isImageTargetSupported()
      Checks if this instance supports returning the image target interface {@link IImageTarget}.
      Overrides:
      isImageTargetSupported in class URN
      Returns:
      true as Barcode URN's always supports images in SVG.
    • getImageTarget

      public IImageTarget getImageTarget()
      Gets the image target interface for this URN instance.
      Overrides:
      getImageTarget in class URN
      Returns:
      The image target interface to an SVG image target.
    • getParamString

      public String getParamString()
      Gets the parameter string for the URN.toString() method.
      Specified by:
      getParamString in class URN
      Returns:
      The parameter string, always non-null.
    • hashCode

      public int hashCode()
      Hashcode of this instance.
      Specified by:
      hashCode in class URN
      Returns:
      The hashcode.
    • equals

      public boolean equals(Object obj)
      Checks if two instances are equal.
      Specified by:
      equals in class URN
      Parameters:
      obj - The other instance.
      Returns:
      The equals flag.