Skip to content
Snippets Groups Projects
Commit 6a4d236f authored by Andrey Ruzhanskiy's avatar Andrey Ruzhanskiy
Browse files

Added new Exception, first code cleanup.

parent cb6b5e0a
No related branches found
No related tags found
1 merge request!8Feat/rasterizer 10
Showing
with 209 additions and 150 deletions
......@@ -16,8 +16,8 @@ plugins {
id 'checkstyle'
}
sourceCompatibility = 11
targetCompatibility = 11
sourceCompatibility = 12
targetCompatibility = 12
repositories {
// Use jcenter for resolving your dependencies.
......@@ -38,6 +38,11 @@ dependencies {
// Units
compile group: 'javax.measure', name: 'unit-api', version: '2.0-PRD'
compile group: 'tec.units', name: 'unit-ri', version: '1.0.3'
// Parsing
compile group: 'javax.json', name: 'javax.json-api', version: '1.0'
compile group: 'org.glassfish', name: 'javax.json', version: '1.1.4'
}
test {
......
package de.tudresden.inf.mci.brailleplot;
import de.tudresden.inf.mci.brailleplot.configparser.Format;
import de.tudresden.inf.mci.brailleplot.configparser.Printer;
import de.tudresden.inf.mci.brailleplot.configparser.*;
import de.tudresden.inf.mci.brailleplot.exporter.PrintDirector;
import de.tudresden.inf.mci.brailleplot.exporter.PrinterConfiguration;
......@@ -139,6 +138,12 @@ public final class App {
// Config Parsing
// TODO make it default if nothing is found in p.
Optional<String> configPath = settingsReader.getSetting(SettingType.PRINTER_CONFIG_PATH);
JavaPropertiesConfigurationParser configParser = new JavaPropertiesConfigurationParser(configPath.get());
Printer indexV4Printer = configParser.getPrinter();
indexV4Printer.getProperty("brailletable").toString();
Format A4Format = configParser.getFormat("A4");
......@@ -151,8 +156,7 @@ public final class App {
System.out.println("Nein");
}
MatrixData<Boolean> data = new SimpleMatrixDataImpl<Boolean>(new Printer(), new Format(), 20, 18, true);
MatrixData<Boolean> data = new SimpleMatrixDataImpl<Boolean>(indexV4Printer, A4Format, 18, 20, true);
PrintDirector printD = new PrintDirector(PrinterConfiguration.NORMALPRINTER);
printD.print("Index Everest-D V4", data);
/*
......@@ -169,5 +173,43 @@ public final class App {
return EXIT_SUCCESS;
}
/*
public void dummyConfigurationParsing() {
String workingDir = System.getProperty("user.dir");
String defaultConfigPath = workingDir + "/defaultConfig.properties";
String concreteConfigPath = workingDir + "/dummyPrinterConfig.properties";
// create parser and parse default config
try {
JavaPropertiesConfigurationParser configParser = new JavaPropertiesConfigurationParser(defaultConfigPath);
Printer defaultPrinter = configParser.getPrinter();
Format defaultFormat = configParser.getFormat("default");
// parse concrete configuration with set defaults
configParser = new JavaPropertiesConfigurationParser(
concreteConfigPath,
defaultPrinter,
defaultFormat
);
Printer printerConfig = configParser.getPrinter();
for (String property : printerConfig.getPropertyNames()) {
System.out.println("Property: " + property + "=" + printerConfig.getProperty(property));
}
for (String formatName : configParser.getFormatNames()) {
System.out.println("Format: " + formatName);
Format formatConfig = configParser.getFormat(formatName);
for (String property : formatConfig.getPropertyNames()) {
System.out.println("Property: " + property + "=" + formatConfig.getProperty(property));
}
}
} catch (ConfigurationValidationException e) {
System.out.println(e.getMessage());
} catch (ConfigurationParsingException e) {
System.out.println(e.getMessage());
}
}
*/
}
......@@ -24,7 +24,7 @@ public class CommandLineParser {
mOptions.addOption("h", SettingType.DISPLAY_HELP.toString(), false, "Print help and exit")
.addOption("c", SettingType.CSV_LOCATION.toString(), true, "Path to CSV")
.addOption("s", SettingType.SEMANTIC_MAPPING.toString(), true, "Literal for semantic mapping")
.addOption("p", SettingType.PRINTER_CONFIG_PATH.toString(), true, "path to printer configuration file");
.addOption("p", SettingType.PRINTER_CONFIG_PATH.toString(), true, "Path to printer configuration file");
}
/**
......
......@@ -11,7 +11,6 @@ public enum SettingType {
CSV_LOCATION("csv-path"),
PRINTER_CONFIG_PATH("printer-config-path"),
SEMANTIC_MAPPING("semantic-mapping");
private final String mName;
SettingType(final String name) {
......
package de.tudresden.inf.mci.brailleplot.configparser;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
......@@ -25,6 +27,7 @@ class JavaPropertiesConfigurationValidator implements ConfigurationValidator {
Predicate<String> requireDouble = JavaPropertiesConfigurationValidator::checkIfDouble;
Predicate<String> requireBoolean = JavaPropertiesConfigurationValidator::checkIfBoolean;
Predicate<String> requirePositive = JavaPropertiesConfigurationValidator::checkIfPositive;
Predicate<String> requireFileExists = JavaPropertiesConfigurationValidator::checkIfFileExists;
// Definition of valid printer properties
Map<String, Predicate<String>> p = new HashMap<>();
......@@ -38,6 +41,7 @@ class JavaPropertiesConfigurationValidator implements ConfigurationValidator {
p.put("max.characterDistance", requireDouble.and(requirePositive));
p.put("min.lineDistance", requireDouble.and(requirePositive));
p.put("max.lineDistance", requireDouble.and(requirePositive));
p.put("brailletable", requireFileExists);
// Definition of valid format properties
Map<String, Predicate<String>> f = new HashMap<>();
......@@ -146,4 +150,13 @@ class JavaPropertiesConfigurationValidator implements ConfigurationValidator {
return false;
}
}
private static boolean checkIfFileExists(final String filePath){
try {
FileInputStream stream = new FileInputStream(filePath);
} catch (FileNotFoundException e) {
return false;
}
return true;
}
}
......@@ -5,7 +5,7 @@ package de.tudresden.inf.mci.brailleplot.configparser;
* @author Leonard Kupper
* @version 2019.06.04
*/
abstract class ValidProperty {
public abstract class ValidProperty {
String mName;
String mValue;
......
package de.tudresden.inf.mci.brailleplot.exporter;
public interface AbstractBrailleTableParser {
int getValue(String key);
}
package de.tudresden.inf.mci.brailleplot.exporter;
import de.tudresden.inf.mci.brailleplot.configparser.Printer;
import de.tudresden.inf.mci.brailleplot.printabledata.MatrixData;
import de.tudresden.inf.mci.brailleplot.printabledata.SimpleMatrixDataImpl;
/**
* This Class provides an Extension Point for further implementation
......@@ -17,6 +19,11 @@ public abstract class AbstractDocumentBuilder {
protected byte[] mDocument;
private MatrixData data;
AbstractBrailleTableParser mParser;
/**
* Complex method for complex construction of an Document for the printer.
* @param data Raw Data to be printed without any escapesequences
......@@ -34,4 +41,21 @@ public abstract class AbstractDocumentBuilder {
return mDocument;
}
protected void setParser() throws NotSupportedFileExtension {
//read brailletablepath
Printer printer = data.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();
case "json": mParser = new JsonParser();
case "xml": mParser = new XmlParser();
default: throw new NotSupportedFileExtension();
}
}
}
......@@ -11,7 +11,8 @@ import java.util.Map;
* @version 28.06.2019
*/
public interface BrailleAlphabet {
public byte[] getValue(BrailleCell6 cell);
public abstract class BrailleAlphabet {
public abstract <T> byte[] getValue(BrailleCell6 cell);
public AbstractBrailleTableParser mParser;
public Map<BrailleCell6, byte[]> mAlphabet = new HashMap<>();
}
package de.tudresden.inf.mci.brailleplot.exporter;
import de.tudresden.inf.mci.brailleplot.printabledata.BrailleCell6;
/**
* This Class represents the German 6 Dot Braille Alphabet.
*
* @author Andrey Ruzhanskiy
* @version 28.06.2019
*/
public class BrailleGerman6Dots implements BrailleAlphabet{
@Override
public byte[] getValue(BrailleCell6 cell) {
if(cell == null){
throw new NullPointerException();
}
return mAlphabet.get(cell);
}
public BrailleGerman6Dots() {
/*
Letter A
1
*/
/*
BrailleCell A = new BrailleCell();
A.setFirst();
mAlphabet.put(A, new byte[0x41]);
*/
/*
Letter B
1
2
*/
/*
BrailleCell B = new BrailleCell();
B.setFirst();
B.setSecond();
mAlphabet.put(B, new byte[]{0x42});
*/
/*
Letter C
1 4
*/
/*
BrailleCell C = new BrailleCell();
C.setFirst();
C.setFourth();
mAlphabet.put(C, new byte[]{0x43});
*/
/*
Letter D
1 4
5
*/
/*
BrailleCell D = new BrailleCell();
D.setFirst();
D.setFourth();
D.setFifth();
mAlphabet.put(D, new byte[]{0x44});
*/
/*
Letter E
1
5
*/
/*
BrailleCell E = new BrailleCell();
E.setFirst();
E.setFifth();
mAlphabet.put(E, new byte[]{0x45});
*/
/*
Letter F
1 4
2
*/
/*
BrailleCell F = new BrailleCell();
F.setFirst();
F.setSecond();
F.setFourth();
mAlphabet.put(F, new byte[]{0x46});
*/
/*
Letter G
1 4
2 5
*/
/*
BrailleCell G = new BrailleCell();
G.setFirst();
G.setSecond();
G.setFourth();
G.setFifth();
mAlphabet.put(G, new byte[]{0x47});
*/
}
}
package de.tudresden.inf.mci.brailleplot.exporter;
import de.tudresden.inf.mci.brailleplot.printabledata.BrailleCell6;
/**
* Implements the Braille German 8 Dots Alphabet.
* @author Andrey Ruzhanskiy
* @version 28.06.2019
*/
public class BrailleGerman8Dots implements BrailleAlphabet {
@Override
public byte[] getValue(BrailleCell6 cell) {
if (cell == null){
throw new NullPointerException();
}
return mAlphabet.get(cell);
}
}
package de.tudresden.inf.mci.brailleplot.exporter;
public class JsonParser implements AbstractBrailleTableParser {
@Override
public int getValue(String key) {
return 0;
}
}
package de.tudresden.inf.mci.brailleplot.exporter;
import de.tudresden.inf.mci.brailleplot.configparser.Printer;
import de.tudresden.inf.mci.brailleplot.configparser.ValidProperty;
import de.tudresden.inf.mci.brailleplot.printabledata.BrailleCell6;
import de.tudresden.inf.mci.brailleplot.printabledata.MatrixData;
import java.io.ByteArrayOutputStream;
import java.io.FileNotFoundException;
import java.util.Iterator;
import java.util.Properties;
/**
* Class representing a normal Document (for example a .txt) to print without
* any Escapesequences.
* @author Andrey Ruzhanskiy
* @version
*/
@SuppressWarnings("checkstyle:MagicNumber")
public class NormalBuilder extends AbstractDocumentBuilder {
@Override
public byte[] assemble(final MatrixData data) {
if(data == null) {
if (data == null) {
throw new NullPointerException();
}
//6 Point Braille
Iterator iter = data.getDotIterator(2, 3);
while (iter.hasNext()){
for (int i = 0; i < 6; i++) {
try {
setParser();
} catch (NotSupportedFileExtension e) {
throw new RuntimeException();
}
Iterator<BrailleCell6<Boolean>> iter = data.getBrailleCell6Iterator();
ByteArrayOutputStream stream = new ByteArrayOutputStream();
}
// data.getFormatConfig().getProperty()
while (iter.hasNext()) {
stream.write(mParser.getValue(iter.next().toShortString()));
}
return null;
return stream.toByteArray();
}
protected NormalBuilder(){
}
}
package de.tudresden.inf.mci.brailleplot.exporter;
/**
* Exception Class for not recogniced/not supported FIleExtension for brailletables.
* Used in NormalBuilder.
* @author Andrey Ruzhanskiy
* @version 11.07.2019
*/
public class NotSupportedFileExtension extends Exception {
public NotSupportedFileExtension() { }
public NotSupportedFileExtension(final String message) {
super(message);
}
public NotSupportedFileExtension(final Throwable cause) {
super(cause);
}
public NotSupportedFileExtension(final String message, final Throwable cause) {
super(message, cause);
}
}
......@@ -18,6 +18,7 @@ public class PrintDirector {
private PrintService mService;
private String mPrinterName;
private DocFlavor mDocflavor;
private AbstractBrailleTableParser mParser;
/**
......@@ -54,6 +55,7 @@ public class PrintDirector {
return false;
}
/**
* Method for setting the Printer.
* @param printerName
......@@ -74,7 +76,7 @@ public class PrintDirector {
@SuppressWarnings("checkstyle:MagicNumber")
public <T> void print(final String printerName, final MatrixData<T> data) {
if (printerName == null || data == null){
if (printerName == null || data == null) {
throw new NullPointerException();
}
setUpDoc();
......@@ -101,11 +103,12 @@ public class PrintDirector {
*/
private void print(final byte[] data) {
if(data == null){
if (data == null) {
throw new NullPointerException();
}
Doc doc = new SimpleDoc(data, mDocflavor, null);
PrintRequestAttributeSet asset = new HashPrintRequestAttributeSet();
mService = PrintServiceLookup.lookupDefaultPrintService();
DocPrintJob job = mService.createPrintJob();
try {
job.print(doc, asset);
......
package de.tudresden.inf.mci.brailleplot.exporter;
public class PropertiesParser implements AbstractBrailleTableParser {
@Override
public int getValue(String key) {
return 0;
}
}
package de.tudresden.inf.mci.brailleplot.exporter;
public class XmlParser implements AbstractBrailleTableParser {
@Override
public int getValue(String key) {
return 0;
}
}
......@@ -49,7 +49,7 @@ public final class BrailleCell6<T> {
* @param vals An array of values to obtain the values from.
* @throws IllegalArgumentException If the length is not equal to 6.
*/
BrailleCell6(final T[] vals) {
public BrailleCell6(final T[] vals) {
if (vals.length != DOT_COUNT) {
throw new IllegalArgumentException("Input Array must be of length " + DOT_COUNT);
}
......@@ -101,4 +101,17 @@ public final class BrailleCell6<T> {
}
return sb.toString();
}
public String toShortString(){
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();
}
}
......@@ -20,7 +20,8 @@ public class PrintDirectorTest {
public void testPrinterDoesNotExist(){
Assertions.assertEquals(false, PrintDirector.printerExists("kek"));
}
/*
@Test
public void testNullPointerInPrintString(){
Assertions.assertThrows(NullPointerException.class, () -> {
......@@ -30,5 +31,5 @@ public class PrintDirectorTest {
});
});
}
*/
}
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