Skip to content
Snippets Groups Projects
Commit 6e4740bf authored by Georg Graßnick's avatar Georg Graßnick :thinking:
Browse files

Merge branch 'master' into feat/CSV_data_importer_overhaul

parents 1f70ad47 d47f64ef
No related branches found
No related tags found
1 merge request!11Feat/csv data importer overhaul
Showing
with 1181 additions and 8 deletions
...@@ -3,6 +3,7 @@ build ...@@ -3,6 +3,7 @@ build
out out
*gradle* *gradle*
!build.gradle !build.gradle
!integrationTest.gradle
# IntelliJ # IntelliJ
.idea .idea
......
...@@ -43,7 +43,7 @@ dependencies { ...@@ -43,7 +43,7 @@ dependencies {
compile "com.opencsv:opencsv:4.6" compile "com.opencsv:opencsv:4.6"
} }
test { tasks.withType(Test) {
useJUnitPlatform() useJUnitPlatform()
} }
...@@ -60,7 +60,11 @@ jar { ...@@ -60,7 +60,11 @@ jar {
} }
} }
checkstyleTest{ checkstyleTest {
showViolations = true showViolations = true
checkstyleTest.enabled = false checkstyleTest.enabled = false
} }
\ No newline at end of file
// Needed for Integrationtests
apply from: "$rootDir/integrationTest.gradle"
\ No newline at end of file
sourceSets {
integrationTest {
java.srcDir 'src/integrationTest'
resources.srcDir 'src/test/resources'
compileClasspath += sourceSets.main.output + configurations.testRuntimeClasspath
runtimeClasspath += output + compileClasspath
}
}
task integrationTest(type: Test) {
group = 'verification'
description = 'Runs Integrationtests.'
testClassesDirs = sourceSets.integrationTest.output.classesDirs
classpath = sourceSets.integrationTest.runtimeClasspath
mustRunAfter test
checkstyleIntegrationTest.enabled = false
}
\ No newline at end of file
import de.tudresden.inf.mci.brailleplot.commandline.CommandLineParser;
import de.tudresden.inf.mci.brailleplot.commandline.SettingsReader;
import de.tudresden.inf.mci.brailleplot.commandline.SettingsWriter;
import de.tudresden.inf.mci.brailleplot.configparser.Format;
import de.tudresden.inf.mci.brailleplot.configparser.JavaPropertiesConfigurationParser;
import de.tudresden.inf.mci.brailleplot.configparser.Printer;
import de.tudresden.inf.mci.brailleplot.printerbackend.PrintDirector;
import de.tudresden.inf.mci.brailleplot.printerbackend.PrinterCapability;
import de.tudresden.inf.mci.brailleplot.printabledata.MatrixData;
import de.tudresden.inf.mci.brailleplot.printabledata.SimpleMatrixDataImpl;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import javax.print.DocFlavor;
import java.io.File;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
/**
* Integrationtests for the components PrintableData and Exporter.
* Because most of the Exporter Unit tests depend heavily on the packages PrintableData and configParser,
* these are also located here. Most, if not all unittests for the exporter are tested via Reflection. It is
* contestable if these tests are really needed, but the with more LOC Coverage, there comes more possible stability.
* @author Andrey Ruzhanskiy
* @version 30.07.2019
*/
public class PrintableDataExporterIntegTest {
private static String[] args;
private static CommandLineParser cliParser;
private static SettingsWriter settings;
private static SettingsReader settingsReader;
private static Printer printer;
private static Format format;
private static MatrixData<Boolean> data;
/**
* Setup Method for testing the exporter package.
*/
@BeforeAll
public static void setUp() {
Assertions.assertDoesNotThrow(() -> {
String correct = getResource("config/correct.properties").getAbsolutePath();
String standard = getResource("config/default.properties").getAbsolutePath();
JavaPropertiesConfigurationParser configParser = new JavaPropertiesConfigurationParser(correct, standard);
printer = configParser.getPrinter();
printer.getProperty("brailletable").toString();
format = configParser.getFormat("A4");
data = new SimpleMatrixDataImpl<>(printer, format, 18, 20, true);
});
}
public static File getResource(String fileName) {
ClassLoader classLoader = ClassLoader.getSystemClassLoader();
File resourceFile = new File(classLoader.getResource(fileName).getFile());
return resourceFile;
}
/**
* Unittest/Integrationtest for the private Print method with a Null Servive.
* Expected: Nullpointerexception.
*/
@Test
public void testPrivatePrintWithNullService() {
Assertions.assertThrows(NullPointerException.class, () -> {
Method privatePrint = PrintDirector.class.getDeclaredMethod("print", byte[].class);
privatePrint.setAccessible(true);
try {
privatePrint.invoke(new PrintDirector(PrinterCapability.NORMALPRINTER,printer), new byte[] {0x55});
} catch (InvocationTargetException e) {
throw e.getTargetException();
}
});
}
/**
* Unittest/Integrationtest for private print method with a null byte.
* Expected: Nullpointerexception.
*/
@Test
public void testPrivatePrintWithNullByte() {
Assertions.assertThrows(NullPointerException.class, () -> {
Method privatePrint = PrintDirector.class.getDeclaredMethod("print", byte[].class);
privatePrint.setAccessible(true);
try {
privatePrint.invoke(new PrintDirector(PrinterCapability.NORMALPRINTER,printer), (Object) null);
} catch (InvocationTargetException e) {
throw e.getTargetException();
}
});
}
/**
* Unittest/Integrationtest for private print method with non existing Docflavour.
* Expected: Nullpointerexception.
*/
@Test
public void testPrivatePrintWithNoDocFlavour() {
Assertions.assertThrows(NullPointerException.class, () -> {
Method privatePrint = PrintDirector.class.getDeclaredMethod("print", byte[].class);
privatePrint.setAccessible(true);
Method setUpService = PrintDirector.class.getDeclaredMethod("setUpService");
setUpService.setAccessible(true);
try {
PrintDirector printD = new PrintDirector(PrinterCapability.NORMALPRINTER,printer);
setUpService.invoke(printD);
privatePrint.invoke(printD, new byte[] {0x55});
} catch (InvocationTargetException e) {
throw e.getTargetException();
}
});
}
/**
* Unittest/Integrationtest for private print Method with non existing Printer.
* Expected: RuntimeException
*/
@Test
public void testPrivateSetUpServiceWithNotExistentPrinter() {
Assertions.assertThrows(RuntimeException.class, () -> {
Method setUpService = PrintDirector.class.getDeclaredMethod("setUpService");
setUpService.setAccessible(true);
Field mPrinterName = PrintDirector.class.getDeclaredField("mPrinterName");
mPrinterName.setAccessible(true);
try {
PrintDirector printD = new PrintDirector(PrinterCapability.NORMALPRINTER, printer);
mPrinterName.set(printD, "please dont exist, please please please");
setUpService.invoke(printD);
} catch (InvocationTargetException e) {
throw e.getTargetException();
}
});
}
/**
* Unittest/Integrationtest for Method SetUpService with NullPrinter.
* Expected: Nullpointerexception.
*/
@Test
public void testPrivateSetUpServiceWithNullPrinter() {
Assertions.assertThrows(NullPointerException.class, () -> {
Method setUpService = PrintDirector.class.getDeclaredMethod("setUpService");
setUpService.setAccessible(true);
Field mPrinterName = PrintDirector.class.getDeclaredField("mPrinterName");
mPrinterName.setAccessible(true);
try {
PrintDirector printD = new PrintDirector(PrinterCapability.NORMALPRINTER, printer);
mPrinterName.set(printD, (Object)null);
setUpService.invoke(printD);
} catch (InvocationTargetException e) {
throw e.getTargetException();
}
});
}
/**
* Unittest/Integrationtest for setting a Wrong Doc Flavor and trying to print with it.
* Expected: RuntimeException.
*/
@Test
public void testWrongDocFlavor() {
Assertions.assertThrows(RuntimeException.class, () -> {
Field mDocflavor = PrintDirector.class.getDeclaredField("mDocflavor");
mDocflavor.setAccessible(true);
PrintDirector printD = new PrintDirector(PrinterCapability.NORMALPRINTER, printer);
mDocflavor.set(printD, new DocFlavor("text/html", "[B"));
Method setUpService = PrintDirector.class.getDeclaredMethod("setUpService");
setUpService.setAccessible(true);
Method privatePrint = PrintDirector.class.getDeclaredMethod("print", byte[].class);
privatePrint.setAccessible(true);
try {
setUpService.invoke(printD);
privatePrint.invoke(printD, new byte[] {0x50});
} catch (InvocationTargetException e){
throw e.getTargetException();
}
});
}
// Positve Testcases
@Test
public void testFloatingDotCapability() {
Assertions.assertDoesNotThrow(() -> {
PrintDirector printD = new PrintDirector(PrinterCapability.INDEX_EVEREST_D_V4_FLOATINGDOT_PRINTER, printer);
});
}
@Test
public void testGraphicPrintCapability() {
Assertions.assertDoesNotThrow(() -> {
PrintDirector printD = new PrintDirector(PrinterCapability.INDEX_EVEREST_D_V4_GRAPHIC_PRINTER, printer);
});
}
@Test
public void testIsPrintServiceOn() {
Assertions.assertTrue(PrintDirector.isPrintServiceOn());
}
}
# JProperties Printer & Format Configuration
#
# Embosser: Index Everest-D V4
# Version 1 Rev. 8 (19-07-19)
#
# Description:
# This is the main configuration file for use with the braille plot application
# when embossing with the 'Index Everest-D V4'.
# The configuration specifies the general printer abilities and defines
# pre-selectable formats for this embosser.
#
# https://gitlab.hrz.tu-chemnitz.de/s9444737--tu-dresden.de/brailleplot/wikis/Software%20Design#configuration-files
# =============================================================================
### General Printer Properties
### ==========================
printer.name=Dummy Printer
printer.mode=normalprinter
printer.brailletable=src/integrationTest/resources/mapping/eurobraille.properties
printer.floatingDot.support=true
printer.floatingDot.resolution=0.05
# The following values represent the fixed indentation and maximum technical printing area of the embosser.
# If the outputs don't fit on the page you might want to tweak this values. (Check the format too.)
printer.constraint.top=5.0
printer.constraint.left=0
#printer.constraint.width=? TODO: Check out manual, Conduct printing tests with bigger formats
#printer.constraint.height=?
# The second constraint in the printer.raster namespace helps to limit the available printing area in steps of
# whole cells, for example if the printer enforces a maximum char per line limit or borders are activated.
printer.raster.constraint.top=0
printer.raster.constraint.left=1
printer.raster.constraint.width=35
printer.raster.constraint.height=29
# The following properties define the exact grid spacing.
printer.raster.cellDistance.horizontal=3.6
printer.raster.cellDistance.vertical=4.8
printer.raster.dotDistance.horizontal=2.5
printer.raster.dotDistance.vertical=2.5
printer.raster.dotDiameter=1.5
### Format Definitions
### ==================
# A4 Format
format.A4.page.width=210
format.A4.page.height=297
format.A4.margin.top=0
format.A4.margin.left=0
format.A4.margin.bottom=0
format.A4.margin.right=0
# A5 Format
format.A5.page.width=148
format.A5.page.height=210
format.A5.margin.top=0
format.A5.margin.left=0
format.A5.margin.bottom=0
format.A5.margin.right=0
# Wide Format
format.wide.page.width=272
format.wide.page.height=210
format.wide.margin.top=0
format.wide.margin.left=0
format.wide.margin.bottom=0
format.wide.margin.right=0
\ No newline at end of file
# JProperties Printer & Format Configuration
#
# Embosser: Dummy Default
# Test Revision (19-07-18) (DON'T USE FOR PRINTING)
#
# Description:
# This is the default configuration file for the braille plot application.
# The configuration specifies the default values of required properties.
#
# https://gitlab.hrz.tu-chemnitz.de/s9444737--tu-dresden.de/brailleplot/wikis/Software%20Design#configuration-files
# =============================================================================
# ATTENTION: Changes to this configuration will affect settings for ALL printer and format definitions which
# are not overriding the defaults.
printer.mode=normalprinter
printer.brailletable=src/test/resources/mapping/eurobraille.properties
printer.floatingDot.support=false
# The following values represent the fixed indentation and maximum technical printing area of the embosser.
# If the outputs don't fit on the page you might want to tweak this values. (Check the format too.)
printer.constraint.top=0
printer.constraint.left=0
# The second constraint in the printer.raster namespace helps to limit the available printing area in steps of
# whole cells, for example if the printer enforces a maximum char per line limit or borders are activated.
printer.raster.constraint.top=0
printer.raster.constraint.left=0
printer.raster.constraint.width=200
printer.raster.constraint.height=300
# Overall grid layout / type
printer.raster.type=6-dot
# The following properties define the exact grid spacing. Standard values based on the
# 'Marburg Medium' publication standard as described in the FFI braille technical guideline:
# https://www.ffi.de/assets/Uploads/Technische-Richtlinie-Blindenschrift.pdf
# See also: # https://codes.iccsafe.org/content/ICCA117_12003/chapter-7-communication-elements-and-features#ICCA117.1_2003_Ch07_Sec703
printer.raster.cellDistance.horizontal=3.5
printer.raster.cellDistance.vertical=5.0
printer.raster.dotDistance.horizontal=2.5
printer.raster.dotDistance.vertical=2.5
printer.raster.dotDiameter=1.5
### Format Definitions
### ==================
# Default Format Definition
format.default.page.height=297
format.default.margin.top=10
format.default.margin.left=10
format.default.margin.bottom=10
format.default.margin.right=10
# This is a template. Do not define concrete formats in this file. Use the specific user config file for this purpose.
\ No newline at end of file
# JProperties Printer & Format Configuration
#
# Embosser: Index Everest-D V4
# Version 1 Rev. 8 (19-07-19)
#
# Description:
# This is the main configuration file for use with the braille plot application
# when embossing with the 'Index Everest-D V4'.
# The configuration specifies the general printer abilities and defines
# pre-selectable formats for this embosser.
#
# https://gitlab.hrz.tu-chemnitz.de/s9444737--tu-dresden.de/brailleplot/wikis/Software%20Design#configuration-files
# =============================================================================
### General Printer Properties
### ==========================
printer.name=Index Everest-D V4
printer.mode=normalKek
printer.brailletable=src/main/resources/mapping/eurobraille.propertiesKek
printer.floatingDot.support=true
printer.floatingDot.resolution=0.05
# The following values represent the fixed indentation and maximum technical printing area of the embosser.
# If the outputs don't fit on the page you might want to tweak this values. (Check the format too.)
printer.constraint.top=5.0
printer.constraint.left=0
#printer.constraint.width=? TODO: Check out manual, Conduct printing tests with bigger formats
#printer.constraint.height=?
# The second constraint in the printer.raster namespace helps to limit the available printing area in steps of
# whole cells, for example if the printer enforces a maximum char per line limit or borders are activated.
printer.raster.constraint.top=0
printer.raster.constraint.left=1
printer.raster.constraint.width=35
printer.raster.constraint.height=29
# The following properties define the exact grid spacing.
printer.raster.cellDistance.horizontal=3.6
printer.raster.cellDistance.vertical=4.8
printer.raster.dotDistance.horizontal=2.5
printer.raster.dotDistance.vertical=2.5
printer.raster.dotDiameter=1.5
### Format Definitions
### ==================
# A4 Format
format.A4.page.width=210
format.A4.page.height=297
format.A4.margin.top=0
format.A4.margin.left=0
format.A4.margin.bottom=0
format.A4.margin.right=0
# A5 Format
format.A5.page.width=148
format.A5.page.height=210
format.A5.margin.top=0
format.A5.margin.left=0
format.A5.margin.bottom=0
format.A5.margin.right=0
# Wide Format
format.wide.page.width=272
format.wide.page.height=210
format.wide.margin.top=0
format.wide.margin.left=0
format.wide.margin.bottom=0
format.wide.margin.right=0
\ No newline at end of file
# JProperties Printer & Format Configuration
#
# Embosser: Index Everest-D V4
# Version 1 Rev. 8 (19-07-19)
#
# Description:
# This is the main configuration file for use with the braille plot application
# when embossing with the 'Index Everest-D V4'.
# The configuration specifies the general printer abilities and defines
# pre-selectable formats for this embosser.
#
# https://gitlab.hrz.tu-chemnitz.de/s9444737--tu-dresden.de/brailleplot/wikis/Software%20Design#configuration-files
# =============================================================================
### General Printer Properties
### ==========================
printer.name=Index Everest-D V4
printer.mode=normalKek
printer.brailletable=src/main/resources/mapping/eurobraille.properties
printer.floatingDot.support=true
printer.floatingDot.resolution=0.05
# The following values represent the fixed indentation and maximum technical printing area of the embosser.
# If the outputs don't fit on the page you might want to tweak this values. (Check the format too.)
printer.constraint.top=5.0
printer.constraint.left=0
#printer.constraint.width=? TODO: Check out manual, Conduct printing tests with bigger formats
#printer.constraint.height=?
# The second constraint in the printer.raster namespace helps to limit the available printing area in steps of
# whole cells, for example if the printer enforces a maximum char per line limit or borders are activated.
printer.raster.constraint.top=0
printer.raster.constraint.left=1
printer.raster.constraint.width=35
printer.raster.constraint.height=29
# The following properties define the exact grid spacing.
printer.raster.cellDistance.horizontal=3.6
printer.raster.cellDistance.vertical=4.8
printer.raster.dotDistance.horizontal=2.5
printer.raster.dotDistance.vertical=2.5
printer.raster.dotDiameter=1.5
### Format Definitions
### ==================
# A4 Format
format.A4.page.width=210
format.A4.page.height=297
format.A4.margin.top=0
format.A4.margin.left=0
format.A4.margin.bottom=0
format.A4.margin.right=0
# A5 Format
format.A5.page.width=148
format.A5.page.height=210
format.A5.margin.top=0
format.A5.margin.left=0
format.A5.margin.bottom=0
format.A5.margin.right=0
# Wide Format
format.wide.page.width=272
format.wide.page.height=210
format.wide.margin.top=0
format.wide.margin.left=0
format.wide.margin.bottom=0
format.wide.margin.right=0
\ No newline at end of file
# JProperties Mapping BrailleTable
#
# Table: eurobraille
# Version 1 Rev. 3 (19-07-18)
#
# Description:
# This table contains a mapping from 6-bit-strings to decimal ascii byte values.
# It is used by the printer backend to encode data sent to the embosser.
# The pairs are ordered by ascending ascii byte value.
#
# =============================================================================
# 0-31:NUL-US (non visible characters)
# Space
000000=32
# !
000010=33
# "
000100=34
# #
001111=35
# $
000101=36
# %
111111=37
# &
111101=38
# '
000001=39
# (
011001=40
# )
001011=41
# *
001010=42
# +
011010=43
# ,
010000=44
# -
001001=45
# .
001000=46
# /
010011=47
# 0
001101=48
# 1
100001=49
# 2
110001=50
# 3
100101=51
# 4
100111=52
# 5
100011=53
# 6
110101=54
# 7
110111=55
# 8
110011=56
# 9
010101=57
# :
010010=58
# ;
011000=59
# <
000011=60
# =
011011=61
# >
000110=62
# ?
010001=63
# 64-90:@-Z
# [
111011=91
# 92:\
# 93:]
# 94:^
# _
000111=95
# `
001110=96
# a
100000=97
# b
110000=98
# c
100100=99
# d
100110=100
# e
100010=101
# f
110100=102
# g
110110=103
# h
110010=104
# i
010100=105
# j
010110=106
# k
101000=107
# l
111000=108
# m
101100=109
# n
101110=110
# o
101010=111
# p
111100=112
# q
111110=113
# r
111010=114
# s
011100=115
# t
011110=116
# u
101001=117
# v
111001=118
# w
010111=119
# x
101101=120
# y
101111=121
# z
101011=122
# {
011111=123
# |
001100=124
# ~
011101=126
# 127:DEL
\ No newline at end of file
package de.tudresden.inf.mci.brailleplot; package de.tudresden.inf.mci.brailleplot;
import de.tudresden.inf.mci.brailleplot.configparser.Format;
import de.tudresden.inf.mci.brailleplot.configparser.JavaPropertiesConfigurationParser;
import de.tudresden.inf.mci.brailleplot.configparser.Printer;
import de.tudresden.inf.mci.brailleplot.printerbackend.PrintDirector;
import de.tudresden.inf.mci.brailleplot.printerbackend.PrinterCapability;
import de.tudresden.inf.mci.brailleplot.printabledata.MatrixData;
import de.tudresden.inf.mci.brailleplot.printabledata.SimpleMatrixDataImpl;
import de.tudresden.inf.mci.brailleplot.commandline.CommandLineParser; import de.tudresden.inf.mci.brailleplot.commandline.CommandLineParser;
import de.tudresden.inf.mci.brailleplot.commandline.SettingType; import de.tudresden.inf.mci.brailleplot.commandline.SettingType;
import de.tudresden.inf.mci.brailleplot.commandline.SettingsReader; import de.tudresden.inf.mci.brailleplot.commandline.SettingsReader;
...@@ -30,7 +40,7 @@ import java.util.concurrent.ConcurrentLinkedDeque; ...@@ -30,7 +40,7 @@ import java.util.concurrent.ConcurrentLinkedDeque;
/** /**
* Main class. * Main class.
* Set up the application and run it. * Set up the application and run it.
* @author Georg Graßnick * @author Georg Graßnick, Andrey Ruzhanskiy
* @version 06.06.19 * @version 06.06.19
*/ */
...@@ -165,7 +175,26 @@ public final class App { ...@@ -165,7 +175,26 @@ public final class App {
SimpleMatrixDataImpl<Boolean> mat = (SimpleMatrixDataImpl<Boolean>) canvas.getCurrentPage(); SimpleMatrixDataImpl<Boolean> mat = (SimpleMatrixDataImpl<Boolean>) canvas.getCurrentPage();
mLogger.debug("Render preview:\n" + mat.toBoolString()); mLogger.debug("Render preview:\n" + mat.toBoolString());
// ... // Config Parsing
// Check if some SpoolerService/Printservice exists
if (!PrintDirector.isPrintServiceOn()) {
throw new Exception("Can't find any Printservices on this System.");
}
// Parse properties File
Optional<String> configPath = settingsReader.getSetting(SettingType.PRINTER_CONFIG_PATH);
JavaPropertiesConfigurationParser configParser = new JavaPropertiesConfigurationParser(configPath.get(), "src/main/resources/config/default.properties");
Printer printer = configParser.getPrinter();
printer.getProperty("brailletable").toString();
Format formatA4 = configParser.getFormat("A4");
// Last Step: Printing
@SuppressWarnings("checkstyle:MagicNumber")
MatrixData<Boolean> data = new SimpleMatrixDataImpl<>(printer, formatA4, 18, 20, true);
String printerConfigUpperCase = printer.getProperty("mode").toString().toUpperCase();
PrintDirector printD = new PrintDirector(PrinterCapability.valueOf(printerConfigUpperCase), printer);
printD.print(data);
} catch (final Exception e) { } catch (final Exception e) {
terminateWithException(e); terminateWithException(e);
...@@ -175,5 +204,4 @@ public final class App { ...@@ -175,5 +204,4 @@ public final class App {
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
} }
package de.tudresden.inf.mci.brailleplot.brailleparser;
/**
* Defines an interface which should be implemented in all parsers of braille tables.
*/
public interface AbstractBrailleTableParser {
/**
* Common method for querying the braille table.
* @param key Braille cell, represented as string ("111000).
* @return Byte, represented as int, corresponding to the given braille cell.
*/
int getValue(String key);
}
package de.tudresden.inf.mci.brailleplot.brailleparser;
/**
* Class representing a Json parser entity.
* @author Andrey Ruzhanskiy
* @version 12.07.2019
*/
public class JsonParser implements AbstractBrailleTableParser {
/**
* Currently not supported.
* @param filePath File path to the braille table.
*/
public JsonParser(final String filePath) {
throw new UnsupportedOperationException();
}
/**
* Currently not supported.
* @param key Braille cell, represented as string ("111000).
* @return The byte(int) representing the Braille cell specified in the braille table.
*/
@Override
public int getValue(final String key) {
throw new UnsupportedOperationException();
}
}
package de.tudresden.inf.mci.brailleplot.brailleparser;
import java.io.FileInputStream;
import java.util.Objects;
import java.util.Properties;
/**
* Class representing a properties parser.
* @author Andrey Ruzhanskiy
* @version 12.07.2019
*/
public class PropertiesParser implements AbstractBrailleTableParser {
private Properties mProperties = new Properties();
/**
* Constructor for properties parser. Takes a filePath to the braille table file with the .properties file extension.
* @param filePath The path to the braille table.
* @throws RuntimeException If the file Path does not exists.
*/
public PropertiesParser(final String filePath) {
Objects.requireNonNull(filePath);
FileInputStream stream;
try {
stream = new FileInputStream(filePath);
mProperties.load(stream);
stream.close();
} catch (java.io.IOException e) {
throw new RuntimeException(e);
}
}
/**
* Method for querying the byte (represented via int) for a given cell from the braille table.
* @param key The braille cell, represented as a string (for example "111000" for 6 braille cell).
* @return The byte(int) representing the braille cell specified in the braille table,
*/
@Override
public int getValue(final String key) {
Objects.requireNonNull(key);
return Integer.parseInt(mProperties.getProperty(key));
}
}
package de.tudresden.inf.mci.brailleplot.brailleparser;
/**
* Class representing a XML parser entity.
* @author Andrey Ruzhanskiy
* @version 12.07.2019
*/
public class XmlParser implements AbstractBrailleTableParser {
/**
* Currently not supported.
*
* @param filePath Path to the braille table.
*/
public XmlParser(final String filePath) {
throw new UnsupportedOperationException();
}
/**
* Currently not supported.
* @param key braille cell, represented as String ("111000).
* @return The byte(int) representing the braille cell specified in the braille table.
*/
@Override
public int getValue(final String key) {
throw new UnsupportedOperationException();
}
}
/**
* This package contains all the required classes and interfaces for braille table parsing.
*/
package de.tudresden.inf.mci.brailleplot.brailleparser;
\ No newline at end of file
package de.tudresden.inf.mci.brailleplot.configparser; package de.tudresden.inf.mci.brailleplot.configparser;
import de.tudresden.inf.mci.brailleplot.printerbackend.PrinterCapability;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -11,8 +14,8 @@ import java.util.regex.Pattern; ...@@ -11,8 +14,8 @@ import java.util.regex.Pattern;
/** /**
* Concrete validator for properties parsed from configuration files in Java Property File format. * Concrete validator for properties parsed from configuration files in Java Property File format.
* @author Leonard Kupper * @author Leonard Kupper, Andrey Ruzhanskiy
* @version 2019.07.18 * @version 2019.07.30
*/ */
class JavaPropertiesConfigurationValidator implements ConfigurationValidator { class JavaPropertiesConfigurationValidator implements ConfigurationValidator {
...@@ -240,4 +243,29 @@ class JavaPropertiesConfigurationValidator implements ConfigurationValidator { ...@@ -240,4 +243,29 @@ class JavaPropertiesConfigurationValidator implements ConfigurationValidator {
} }
return true; return true;
} }
private static boolean checkIfEnum(final String name) {
for (PrinterCapability p : PrinterCapability.values()) {
if (p.toString().toLowerCase().equals(name)) {
return true;
}
}
PrinterCapability[] possibleValues = PrinterCapability.values();
StringBuilder sBuilder = new StringBuilder();
for (int i = 0; i < possibleValues.length; i++) {
sBuilder.append(possibleValues[i]).append(",");
}
String result = sBuilder.deleteCharAt(sBuilder.length() - 1).toString();
throw new RuntimeException("The given mode '"
+ name + "' is currently not supported/not found in"
+ " the system. Currently, the possible values are: " + result);
}
/**
* Static method for checking if the printer, which was given, exists in the Printer System Dialog.
* @param printerName The name of the printer to check.
* @return True if printer exists. False if not.
*/
} }
...@@ -101,4 +101,20 @@ public final class BrailleCell6<T> { ...@@ -101,4 +101,20 @@ public final class BrailleCell6<T> {
} }
return sb.toString(); return sb.toString();
} }
/**
* Method for getting the Bit Representation of the Cell (110001). Should only be used if T is boolean.
* @return String containing the Bit Representation.
*/
public String getBitRepresentationFromBool() {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < mDots.length; i++) {
if (Boolean.parseBoolean(mDots[i].toString())) {
sb.append("1");
} else {
sb.append("0");
}
}
return sb.toString();
}
} }
package de.tudresden.inf.mci.brailleplot.printerbackend;
import de.tudresden.inf.mci.brailleplot.brailleparser.AbstractBrailleTableParser;
import de.tudresden.inf.mci.brailleplot.brailleparser.JsonParser;
import de.tudresden.inf.mci.brailleplot.brailleparser.PropertiesParser;
import de.tudresden.inf.mci.brailleplot.brailleparser.XmlParser;
import de.tudresden.inf.mci.brailleplot.configparser.Printer;
import de.tudresden.inf.mci.brailleplot.printabledata.MatrixData;
/**
* This class provides an extension point for further implementation
* and protocol building for documents that need to be send to the printer.
* The common Interface is the getDocument() and assemble() method.
* Its usable for all braille printers.
* @param <T> Type of MatrixData.
* @author Andrey Ruzhanskiy
* @version 28.05.2019
*/
abstract class AbstractDocumentBuilder<T> {
MatrixData<T> mData;
AbstractBrailleTableParser mParser;
/**
* Complex method for complex construction of an document for the printer.
* @param data Raw data to be printed without any escapes equences
* @return Fully build document as byte[]
*/
abstract byte[] assemble(MatrixData<T> data);
/**
* Method for setting the correct parser. Reads the file from the printer configuration, then checks
* if the file extension is supported.
* @throws NotSupportedFileExtensionException If the file extension is not supported.
*/
void setParser() throws NotSupportedFileExtensionException {
//read braille table path
Printer printer = mData.getPrinterConfig();
String brailleTablePath = printer.getProperty("brailletable").toString();
//read which kind of parser is needed (properties, json, xml,...)
String fileEnding = brailleTablePath.split("\\.")[1];
switch (fileEnding) {
case "properties": mParser = new PropertiesParser(printer.getProperty("brailletable").toString()); break;
case "json": mParser = new JsonParser(printer.getProperty("brailletable").toString()); break;
case "xml": mParser = new XmlParser(printer.getProperty("brailletable").toString()); break;
default: throw new NotSupportedFileExtensionException("The Fileextension " + fileEnding + "is currently not supported.");
}
}
}
package de.tudresden.inf.mci.brailleplot.printerbackend;
/**
* Abstract class for Documents, that need special escape sequences for the Index Everest-V4.
* All special documents (i.e. Floating Dot Area) should implement this class. All information taken
* from the Index PrinterCapability Interface Protocol V5_V4 2ß16-05-13. All the variables with the respective values have no
* particular order (except mStartTemporaryDoc, which must be at the beginning). All the variable names are set to
* final, these are PrinterCapability specific values that should not be changed.
* @author Andrey Ruzhanskiy
* @version 31.05.2019
*/
@SuppressWarnings("checkstyle:MagicNumber")
abstract class AbstractIndexV4Builder extends AbstractDocumentBuilder {
/**
* Standard byte Sequence to announce StartTemporary document ([ESC]D).
* Must be always at the beginning.
*/
final byte[] mStartTemporaryDoc = new byte[] {0x1B, 0x44};
/**
* Standard variable name for binding margin (BI).
*/
final byte[] mBindingMarginName = new byte[] {0x42, 0x49};
/**
* Standard value for Everest-V4 A4 Paper Size(4). Possible Values:
* 0
* to
* 10,
* whereas the number encodes the #charracters to leave empty on the line to the
* left and right.
*/
byte[] mBindingMarginValue = new byte[] {0x34};
/**
* Standard variable name for characters per line (CH).
*/
final byte[] mCharsPerLineName = new byte[] {0x43, 0x48};
/**
* Standard value for Everest-V4 A4 Paper Size(30).If used, there must be also
* a corresponding binding margin. Possible values are:
* 0: may not be usefull
* to
* 48:Absolute maximum due to printer heads total movement and only applicable to the printers
* that can use papers that big.
*/
byte[] mCharsPerLineValue = new byte[] {0x33, 0x30};
/**
* Standard variable name for PageMode (Duplex) (DP).
*/
final byte[] mPageModeName = new byte[] {0x44, 0x50};
/**
* Standard value for page mode (2, double sided).
* Possible values are:
* 1 Single sided (normal horizontal printing)
* 2 Double sided (normal horizontal printing)
* 3 Double sided z-folding (normal horizontal printing)
* 5 Single sided z-folding (normal horizontal printing)
* 6 Double sided sideways z-folding (vertical printing)
* 7 Single sided sideways z-folding (vertical printing)
*/
byte[] mPageModeValue = new byte[] {0x32};
/**
* Standard variable name for braille table (BT).
*/
final byte[] mBrailleTableName = new byte[] {0x42, 0x54};
/**
* Currently, there is no standard braille table.
*/
byte[] mBrailleTableValue = null;
/**
* Standard variable name for Driver Version (DV).
*/
final byte[] mDriverVersionName = new byte[] {0x44, 0x56};
/**
* Standard value for driver version (not used currently TODO).
*/
byte[] mDriverVersion = null;
/**
* Standard variable name for first line offset (FO).
*/
final byte[] mFirstLineOffsetName = new byte[] {0x46, 0x4F};
/**
* Standard value for first line offset (~50/60).
* Possible values: equal or greater then 0.
* The value is specified in tenths of mm.
*
*/
byte[] mFirstLineOffsetValue = null;
/**
* Standard variable name for graphic dot distance (GD).
*/
final byte[] mGraphicDotDistanceName = new byte[] {0x47, 0x44};
/**
* Standard value for graphic dot distance. Possible values are 0, 1, 2.
* 0 = 2.0 mm
* 1 = 2.5 mm
* 2 = 1.6 mm
* Standard is 1 (2.5 mm).
*/
byte[] mGraphicDotDistanceValue = new byte[] {0x31};
/**
* Standard variable name for lines per page (LP).
*/
final byte[] mLinesPerPageName = new byte[] {0x4C, 0x50};
/**
* Standard value for lines per page (28). If this parameter is set, one must include
* the TM parameter as well.
*/
byte[] mLinesPerPageValue = new byte[] {0x32, 0x38};
/**
* Standard variable name for line spacing (LS).
*/
final byte[] mLineSpacingName = new byte[] {0x4C, 0x53};
/**
* Standard value for line spacing (GD). This parameter can only be specified in the beginning of a document
* and is ignored if a row has been added to the first page. Line spacing is ignored if DP is set to DP4 and DP8.
* Possible values are:
* 50: 5.0 mm (single -normal)
* to
* 100: 10.0 mm (double)
*/
byte[] mLineSpacingValue = new byte[] {0x35, 0x30};
/**
* Standard variable name for multiple copies (MC).
*/
final byte[] mMultipleCopiesName = new byte[] {0x4D, 0x43};
/**
* Standard value for multiple copies (1). Possible values are:
* 1
* to
* 10000
*/
byte[] mMultipleCopiesValue = new byte[] {0x31};
/**
* Standard variable name for multiple impact (MI).
*/
final byte[] mMultipleImpactName = new byte[] {0x4D, 0x49};
/**
* Standard value for multiple impact (1).To impact the hammers multiple times
* for a braille row this parameter can be specified. Possible values are:
* 1
* to
* 3.
*/
byte[] mMultipleImpactValue = new byte[] {0x31};
/**
* Standard variable name for page number (PN).
*/
final byte[] mPageNumberName = new byte[] {0x50, 0x4E};
/**
* Standard value for page number (0). This parameter needs to be specified before the first row is added
* to the first page. Possible values are:
* 0: None
* 1: Top (require top margin greater than 0)
* 2: Top-left (require top margin greater than 0)
* 3: Top-right (require top margin greater than 0)
* 4: Bottom (require bottom margin greater than 0)
* 5: Bottom left (require bottom margin greater than 0)
* 6: Bottom right (require bottom margin greater than 0)
*/
byte[] mPageNumberValue = new byte[] {0x30};
/**
* Standard variable name for braille cell size (TD).
*/
final byte[] mBrailleCellSizeName = new byte[] {0x54, 0x44};
/**
* Standard value for braille cell size (0). Possible values are:
* 0: 2.5 mm
* 1: 2.2 mm
* 2: 3.2 mm
*/
byte[] mBrailleCellSizeValue = new byte[] {0x30};
/**
* Standard variable name for top margin (TM).
*/
final byte[] mTopMarginName = new byte[] {0x54, 0x4D};
/**
* Standard value for top margin(not researched). The top margin is
* always specified in lines. Possible values are:
* 0
* to
* 10
*/
byte[] mTopMarginValue = null;
/**
* Separator for values (,).
*/
final byte[] mComma = new byte[] {0x2C};
/**
* Colon character.
*/
final byte[] mColon = new byte[] {0x3A};
/**
* End of escape sequence (;). Must be always at the end.
*/
final byte[] mSemicolon = new byte[] {0x3B};
}
package de.tudresden.inf.mci.brailleplot.printerbackend;
import de.tudresden.inf.mci.brailleplot.printabledata.MatrixData;
/**
* Class representing the FloatingDotAre protocol for the braille Index Everest V4 for printing
* variable areas on paper via coordinates.
* @author Andrey Ruzhanskiy, Leonard Kupper
* @version 29.05.2019
*/
class FloatingDotAreaBuilder extends AbstractIndexV4Builder {
/**
* Constructor. Does not have any functionality. Should only be used in {@link PrintDirector}
*/
FloatingDotAreaBuilder() { }
/**
* Currently not implemented.
* @param data Raw data to be printed without any escape sequences
* @return Exception.
*/
byte[] assemble(final MatrixData data) {
throw new UnsupportedOperationException();
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment