From 7193d86a4a88966b760925f6075578ae2f23b252 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joel=20H=C3=A5kansson?= Date: Wed, 28 Aug 2013 10:09:20 +0000 Subject: [PATCH] Separated bypass marker processor factory --- .gitattributes | 3 ++ ...anslator.attributes.MarkerProcessorFactory | 3 +- .../DefaultBypassMarkerProcessorFactory.java | 30 +++++++++++++++ .../sv_SE/SwedishMarkerProcessorFactory.java | 10 +---- ...faultBypassMarkerProcessorFactoryTest.java | 37 +++++++++++++++++++ .../SwedishMarkerProcessorFactoryTest.java | 20 ---------- .../MarkerProcessorFactoryTest.java | 30 +++++++++++++++ 7 files changed, 104 insertions(+), 29 deletions(-) create mode 100644 DotifyTranslator/src/org/daisy/dotify/impl/translator/DefaultBypassMarkerProcessorFactory.java create mode 100644 DotifyTranslator/test/org/daisy/dotify/impl/translator/DefaultBypassMarkerProcessorFactoryTest.java create mode 100644 DotifyTranslator/test/org/daisy/dotify/translator/attributes/MarkerProcessorFactoryTest.java diff --git a/.gitattributes b/.gitattributes index 459731ca..73eec3ab 100644 --- a/.gitattributes +++ b/.gitattributes @@ -512,6 +512,7 @@ DotifyTranslator/src/org/daisy/dotify/impl/hyphenator/latex/resource-files/utf8/ DotifyTranslator/src/org/daisy/dotify/impl/hyphenator/latex/resource-files/zh-latn.xml -text DotifyTranslator/src/org/daisy/dotify/impl/text/SwedishInteger2Text.java -text DotifyTranslator/src/org/daisy/dotify/impl/text/SwedishInteger2TextFactory.java -text +DotifyTranslator/src/org/daisy/dotify/impl/translator/DefaultBypassMarkerProcessorFactory.java -text DotifyTranslator/src/org/daisy/dotify/impl/translator/DefaultBypassTranslatorFactory.java -text DotifyTranslator/src/org/daisy/dotify/impl/translator/sv_SE/CapitalizationMarkers.java -text svneol=unset#text/plain DotifyTranslator/src/org/daisy/dotify/impl/translator/sv_SE/SwedishBrailleFilter.java -text svneol=unset#text/plain @@ -572,6 +573,7 @@ DotifyTranslator/test/org/daisy/dotify/hyphenator/SwedishHyphenation2Test.java - DotifyTranslator/test/org/daisy/dotify/hyphenator/SwedishHyphenationTest.java -text DotifyTranslator/test/org/daisy/dotify/impl/hyphenator/latex/LatexHyphenatorFactoryTest.java -text DotifyTranslator/test/org/daisy/dotify/impl/text/SwedishInteger2TextTest.java -text +DotifyTranslator/test/org/daisy/dotify/impl/translator/DefaultBypassMarkerProcessorFactoryTest.java -text DotifyTranslator/test/org/daisy/dotify/impl/translator/DefaultBypassTranslatorTest.java -text DotifyTranslator/test/org/daisy/dotify/impl/translator/sv_SE/CapitalizationMarkersTest.java -text DotifyTranslator/test/org/daisy/dotify/impl/translator/sv_SE/SwedishBrailleFilterTest.java -text @@ -583,3 +585,4 @@ DotifyTranslator/test/org/daisy/dotify/text/Integer2TextFactoryTest.java -text DotifyTranslator/test/org/daisy/dotify/translator/UncontractedBrailleFilterFactoryTest.java -text svneol=unset#text/plain DotifyTranslator/test/org/daisy/dotify/translator/attributes/DefaultMarkerProcessorTest.java -text DotifyTranslator/test/org/daisy/dotify/translator/attributes/DefaultTextAttributeTest.java -text +DotifyTranslator/test/org/daisy/dotify/translator/attributes/MarkerProcessorFactoryTest.java -text diff --git a/DotifyTranslator/src/META-INF/services/org.daisy.dotify.translator.attributes.MarkerProcessorFactory b/DotifyTranslator/src/META-INF/services/org.daisy.dotify.translator.attributes.MarkerProcessorFactory index 7f70fcbc..1e4fdf5a 100644 --- a/DotifyTranslator/src/META-INF/services/org.daisy.dotify.translator.attributes.MarkerProcessorFactory +++ b/DotifyTranslator/src/META-INF/services/org.daisy.dotify.translator.attributes.MarkerProcessorFactory @@ -1 +1,2 @@ -org.daisy.dotify.impl.translator.sv_SE.SwedishMarkerProcessorFactory \ No newline at end of file +org.daisy.dotify.impl.translator.sv_SE.SwedishMarkerProcessorFactory +org.daisy.dotify.impl.translator.DefaultBypassMarkerProcessorFactory \ No newline at end of file diff --git a/DotifyTranslator/src/org/daisy/dotify/impl/translator/DefaultBypassMarkerProcessorFactory.java b/DotifyTranslator/src/org/daisy/dotify/impl/translator/DefaultBypassMarkerProcessorFactory.java new file mode 100644 index 00000000..6527cfb7 --- /dev/null +++ b/DotifyTranslator/src/org/daisy/dotify/impl/translator/DefaultBypassMarkerProcessorFactory.java @@ -0,0 +1,30 @@ +package org.daisy.dotify.impl.translator; + +import org.daisy.dotify.text.FilterLocale; +import org.daisy.dotify.translator.BrailleTranslatorFactory; +import org.daisy.dotify.translator.UnsupportedSpecificationException; +import org.daisy.dotify.translator.attributes.DefaultMarkerProcessor; +import org.daisy.dotify.translator.attributes.Marker; +import org.daisy.dotify.translator.attributes.MarkerProcessor; +import org.daisy.dotify.translator.attributes.MarkerProcessorFactory; +import org.daisy.dotify.translator.attributes.SimpleMarkerDictionary; +import org.daisy.dotify.translator.attributes.StyleConstants; + +public class DefaultBypassMarkerProcessorFactory implements + MarkerProcessorFactory { + + public boolean supportsSpecification(FilterLocale locale, String mode) { + return mode.equals(BrailleTranslatorFactory.MODE_BYPASS); + } + + public MarkerProcessor newMarkerProcessor(FilterLocale locale, String mode) throws UnsupportedSpecificationException { + if (mode.equals(BrailleTranslatorFactory.MODE_BYPASS)) { + SimpleMarkerDictionary dd = new SimpleMarkerDictionary(new Marker("* ", "")); + + DefaultMarkerProcessor sap = new DefaultMarkerProcessor.Builder().addDictionary(StyleConstants.DD, dd).build(); + return sap; + } + throw new UnsupportedSpecificationException("Factory does not support " + locale + "/" + mode); + } + +} diff --git a/DotifyTranslator/src/org/daisy/dotify/impl/translator/sv_SE/SwedishMarkerProcessorFactory.java b/DotifyTranslator/src/org/daisy/dotify/impl/translator/sv_SE/SwedishMarkerProcessorFactory.java index 073ae528..5ba8c53e 100644 --- a/DotifyTranslator/src/org/daisy/dotify/impl/translator/sv_SE/SwedishMarkerProcessorFactory.java +++ b/DotifyTranslator/src/org/daisy/dotify/impl/translator/sv_SE/SwedishMarkerProcessorFactory.java @@ -20,7 +20,7 @@ public class SwedishMarkerProcessorFactory implements MarkerProcessorFactory { public boolean supportsSpecification(FilterLocale locale, String mode) { - return locale.equals(sv_SE) && (mode.equals(BrailleTranslatorFactory.MODE_UNCONTRACTED) || mode.equals(BrailleTranslatorFactory.MODE_BYPASS)); + return locale.equals(sv_SE) && mode.equals(BrailleTranslatorFactory.MODE_UNCONTRACTED); } public MarkerProcessor newMarkerProcessor(FilterLocale locale, String mode) throws UnsupportedSpecificationException { @@ -70,6 +70,7 @@ public boolean appliesTo(TextAttribute atts) { filter(subnodeFilter). build(); + // Redigering och avskrivning, page 148 SimpleMarkerDictionary dd = new SimpleMarkerDictionary(new Marker("\u2820\u2804\u2800", "")); DefaultMarkerProcessor sap = new DefaultMarkerProcessor.Builder(). @@ -81,13 +82,6 @@ public boolean appliesTo(TextAttribute atts) { build(); return sap; - } else if (mode.equals(BrailleTranslatorFactory.MODE_BYPASS)) { - SimpleMarkerDictionary dd = new SimpleMarkerDictionary(new Marker("* ", "")); - - DefaultMarkerProcessor sap = new DefaultMarkerProcessor.Builder(). - addDictionary(StyleConstants.DD, dd). - build(); - return sap; } } throw new UnsupportedSpecificationException("Factory does not support " + locale + "/" + mode); diff --git a/DotifyTranslator/test/org/daisy/dotify/impl/translator/DefaultBypassMarkerProcessorFactoryTest.java b/DotifyTranslator/test/org/daisy/dotify/impl/translator/DefaultBypassMarkerProcessorFactoryTest.java new file mode 100644 index 00000000..7c5be544 --- /dev/null +++ b/DotifyTranslator/test/org/daisy/dotify/impl/translator/DefaultBypassMarkerProcessorFactoryTest.java @@ -0,0 +1,37 @@ +package org.daisy.dotify.impl.translator; + +import static org.junit.Assert.assertEquals; + +import org.daisy.dotify.text.FilterLocale; +import org.daisy.dotify.translator.BrailleTranslatorFactory; +import org.daisy.dotify.translator.UnsupportedSpecificationException; +import org.daisy.dotify.translator.attributes.DefaultTextAttribute; +import org.daisy.dotify.translator.attributes.MarkerProcessor; +import org.junit.Test; + +public class DefaultBypassMarkerProcessorFactoryTest { + private final MarkerProcessor tp; + + public DefaultBypassMarkerProcessorFactoryTest() throws UnsupportedSpecificationException { + tp = new DefaultBypassMarkerProcessorFactory().newMarkerProcessor(FilterLocale.parse("sv-se"), BrailleTranslatorFactory.MODE_BYPASS); + } + + @Test + public void testDD_Text() { + String text = "3rd"; + DefaultTextAttribute.Builder atts = new DefaultTextAttribute.Builder(); + atts.add(new DefaultTextAttribute.Builder("dd").build(3)); + String actual = tp.processAttributes(atts.build(3), text); + assertEquals("", "* 3rd", actual); + } + + @Test + public void testEm_Text() { + String text = "3rd"; + DefaultTextAttribute.Builder atts = new DefaultTextAttribute.Builder(); + atts.add(new DefaultTextAttribute.Builder("em").build(3)); + String actual = tp.processAttributes(atts.build(3), text); + assertEquals("", "3rd", actual); + } + +} diff --git a/DotifyTranslator/test/org/daisy/dotify/impl/translator/sv_SE/SwedishMarkerProcessorFactoryTest.java b/DotifyTranslator/test/org/daisy/dotify/impl/translator/sv_SE/SwedishMarkerProcessorFactoryTest.java index bf3d0bf9..0aca47ee 100644 --- a/DotifyTranslator/test/org/daisy/dotify/impl/translator/sv_SE/SwedishMarkerProcessorFactoryTest.java +++ b/DotifyTranslator/test/org/daisy/dotify/impl/translator/sv_SE/SwedishMarkerProcessorFactoryTest.java @@ -11,11 +11,9 @@ public class SwedishMarkerProcessorFactoryTest { private final MarkerProcessor processor; - private final MarkerProcessor tp; public SwedishMarkerProcessorFactoryTest() throws UnsupportedSpecificationException { processor = new SwedishMarkerProcessorFactory().newMarkerProcessor(FilterLocale.parse("sv-se"), BrailleTranslatorFactory.MODE_UNCONTRACTED); - tp = new SwedishMarkerProcessorFactory().newMarkerProcessor(FilterLocale.parse("sv-se"), BrailleTranslatorFactory.MODE_BYPASS); } @Test @@ -71,22 +69,4 @@ public void testDD() { assertEquals("", "\u2820\u2804\u28003rd", actual); } - @Test - public void testDD_Text() { - String text = "3rd"; - DefaultTextAttribute.Builder atts = new DefaultTextAttribute.Builder(); - atts.add(new DefaultTextAttribute.Builder("dd").build(3)); - String actual = tp.processAttributes(atts.build(3), text); - assertEquals("", "* 3rd", actual); - } - - @Test - public void testEm_Text() { - String text = "3rd"; - DefaultTextAttribute.Builder atts = new DefaultTextAttribute.Builder(); - atts.add(new DefaultTextAttribute.Builder("em").build(3)); - String actual = tp.processAttributes(atts.build(3), text); - assertEquals("", "3rd", actual); - } - } diff --git a/DotifyTranslator/test/org/daisy/dotify/translator/attributes/MarkerProcessorFactoryTest.java b/DotifyTranslator/test/org/daisy/dotify/translator/attributes/MarkerProcessorFactoryTest.java new file mode 100644 index 00000000..03d32cb4 --- /dev/null +++ b/DotifyTranslator/test/org/daisy/dotify/translator/attributes/MarkerProcessorFactoryTest.java @@ -0,0 +1,30 @@ +package org.daisy.dotify.translator.attributes; + +import static org.junit.Assert.assertNotNull; + +import org.daisy.dotify.text.FilterLocale; +import org.daisy.dotify.translator.BrailleTranslatorFactory; +import org.daisy.dotify.translator.UnsupportedSpecificationException; +import org.junit.Test; + +public class MarkerProcessorFactoryTest { + + @Test + public void testFactory() throws UnsupportedSpecificationException { + MarkerProcessor m = MarkerProcessorFactoryMaker.newInstance().newMarkerProcessor(FilterLocale.parse("en-US"), BrailleTranslatorFactory.MODE_BYPASS); + assertNotNull("Factory exists", m); + } + + @Test + public void testSwedishBrailleFactory() throws UnsupportedSpecificationException { + MarkerProcessor m = MarkerProcessorFactoryMaker.newInstance().newMarkerProcessor(FilterLocale.parse("sv-SE"), BrailleTranslatorFactory.MODE_UNCONTRACTED); + assertNotNull("Factory exists", m); + } + + @Test + public void testSwedishTextFactory() throws UnsupportedSpecificationException { + MarkerProcessor m = MarkerProcessorFactoryMaker.newInstance().newMarkerProcessor(FilterLocale.parse("sv-SE"), BrailleTranslatorFactory.MODE_BYPASS); + assertNotNull("Factory exists", m); + } + +}