PageRenderTime 109ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/jasperreports/src/net/sf/jasperreports/components/barcode4j/BarcodeEvaluator.java

https://gitlab.com/samuel-davis/JasperReports-OSGI
Java | 181 lines | 128 code | 26 blank | 27 comment | 4 complexity | 801b14bf2768d7d64f2b253a13ad1f6d MD5 | raw file
  1. /*
  2. * JasperReports - Free Java Reporting Library.
  3. * Copyright (C) 2001 - 2016 TIBCO Software Inc. All rights reserved.
  4. * http://www.jaspersoft.com
  5. *
  6. * Unless you have purchased a commercial license agreement from Jaspersoft,
  7. * the following license terms apply:
  8. *
  9. * This program is part of JasperReports.
  10. *
  11. * JasperReports is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Lesser General Public License as published by
  13. * the Free Software Foundation, either version 3 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * JasperReports is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Lesser General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Lesser General Public License
  22. * along with JasperReports. If not, see <http://www.gnu.org/licenses/>.
  23. */
  24. package net.sf.jasperreports.components.barcode4j;
  25. import net.sf.jasperreports.engine.JRException;
  26. import net.sf.jasperreports.engine.JRExpression;
  27. import net.sf.jasperreports.engine.JRRuntimeException;
  28. import net.sf.jasperreports.engine.component.FillContext;
  29. import net.sf.jasperreports.engine.util.JRStringUtil;
  30. import org.krysalis.barcode4j.impl.code128.EAN128Bean;
  31. /**
  32. *
  33. * @author Lucian Chirita (lucianc@users.sourceforge.net)
  34. */
  35. public class BarcodeEvaluator extends AbstractBarcodeEvaluator
  36. {
  37. private final FillContext fillContext;
  38. private final byte evaluationType;
  39. public BarcodeEvaluator(FillContext fillContext, byte evaluationType)
  40. {
  41. super(
  42. fillContext.getFiller().getJasperReportsContext(),
  43. fillContext.getComponentElement(),
  44. fillContext.getDefaultStyleProvider()
  45. );
  46. this.fillContext = fillContext;
  47. this.evaluationType = evaluationType;
  48. }
  49. protected void evaluateBaseBarcode(BarcodeComponent barcodeComponent)
  50. {
  51. message = JRStringUtil.getString(evaluateExpression(barcodeComponent.getCodeExpression()));
  52. }
  53. protected void evaluateBaseBarcode(Barcode4jComponent barcodeComponent)
  54. {
  55. evaluateBaseBarcode((BarcodeComponent)barcodeComponent);
  56. String pattern = JRStringUtil.getString(evaluateExpression(barcodeComponent.getPatternExpression()));
  57. if (pattern != null)
  58. {
  59. barcodeBean.setPattern(pattern);
  60. }
  61. }
  62. protected Object evaluateExpression(JRExpression expression)
  63. {
  64. try
  65. {
  66. return fillContext.evaluate(expression, evaluationType);
  67. }
  68. catch (JRException e)
  69. {
  70. throw new JRRuntimeException(e);
  71. }
  72. }
  73. @Override
  74. protected void evaluateCodabar(CodabarComponent codabar)
  75. {
  76. evaluateBaseBarcode(codabar);
  77. }
  78. @Override
  79. protected void evaluateCode128(Code128Component code128)
  80. {
  81. evaluateBaseBarcode(code128);
  82. }
  83. @Override
  84. protected void evaluateDataMatrix(DataMatrixComponent dataMatrix)
  85. {
  86. evaluateBaseBarcode(dataMatrix);
  87. }
  88. @Override
  89. protected void evaluateEANCode128(EAN128Component ean128)
  90. {
  91. evaluateBaseBarcode(ean128);
  92. String template = JRStringUtil.getString(evaluateExpression(ean128.getTemplateExpression()));
  93. if (template != null)
  94. {
  95. ((EAN128Bean)barcodeBean).setTemplate(template);
  96. }
  97. }
  98. @Override
  99. protected void evaluateCode39(Code39Component code39)
  100. {
  101. evaluateBaseBarcode(code39);
  102. }
  103. @Override
  104. protected void evaluateUPCA(UPCAComponent upcA)
  105. {
  106. evaluateBaseBarcode(upcA);
  107. }
  108. @Override
  109. protected void evaluateUPCE(UPCEComponent upcE)
  110. {
  111. evaluateBaseBarcode(upcE);
  112. }
  113. @Override
  114. protected void evaluateEAN13(EAN13Component ean13)
  115. {
  116. evaluateBaseBarcode(ean13);
  117. }
  118. @Override
  119. protected void evaluateEAN8(EAN8Component ean8)
  120. {
  121. evaluateBaseBarcode(ean8);
  122. }
  123. @Override
  124. protected void evaluateInterleaved2Of5(Interleaved2Of5Component interleaved2Of5)
  125. {
  126. evaluateBaseBarcode(interleaved2Of5);
  127. }
  128. @Override
  129. protected void evaluateRoyalMailCustomer(
  130. RoyalMailCustomerComponent royalMailCustomer)
  131. {
  132. evaluateBaseBarcode(royalMailCustomer);
  133. }
  134. @Override
  135. protected void evaluateUSPSIntelligentMail(
  136. USPSIntelligentMailComponent intelligentMail)
  137. {
  138. evaluateBaseBarcode(intelligentMail);
  139. }
  140. @Override
  141. protected void evaluatePOSTNET(POSTNETComponent intelligentMail)
  142. {
  143. evaluateBaseBarcode(intelligentMail);
  144. }
  145. @Override
  146. protected void evaluatePDF417(PDF417Component pdf417)
  147. {
  148. evaluateBaseBarcode(pdf417);
  149. }
  150. @Override
  151. protected void evaluateQRCode(QRCodeComponent qrCode)
  152. {
  153. evaluateBaseBarcode(qrCode);
  154. }
  155. }