Skip to content
This repository has been archived by the owner on Nov 9, 2018. It is now read-only.

Commit

Permalink
Separated bypass marker processor factory
Browse files Browse the repository at this point in the history
  • Loading branch information
Joel Håkansson committed Aug 28, 2013
1 parent c4a0916 commit 7193d86
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 29 deletions.
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
org.daisy.dotify.impl.translator.sv_SE.SwedishMarkerProcessorFactory
org.daisy.dotify.impl.translator.sv_SE.SwedishMarkerProcessorFactory
org.daisy.dotify.impl.translator.DefaultBypassMarkerProcessorFactory
Original file line number Diff line number Diff line change
@@ -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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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().
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}

}
Original file line number Diff line number Diff line change
@@ -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);
}

}

0 comments on commit 7193d86

Please sign in to comment.