forked from brailleapps/dotify.task.impl
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from mtmse/move_task_code
Move task code to the task project.
- Loading branch information
Showing
7 changed files
with
650 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
src/META-INF/services/org.daisy.streamline.api.tasks.TaskGroupFactory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
org.daisy.dotify.tasks.impl.input.xml.XMLInputManagerFactory | ||
org.daisy.dotify.tasks.impl.input.text.TextInputManagerFactory | ||
org.daisy.dotify.tasks.impl.input.epub.Epub3InputManagerFactory | ||
org.daisy.dotify.tasks.impl.input.epub.Epub3InputManagerFactory | ||
org.daisy.dotify.tasks.impl.input.obfl.LayoutEngineFactory |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package org.daisy.dotify.tasks.impl.input.obfl; | ||
|
||
/** | ||
* Provides a set of keys commonly used within this bundle. | ||
* | ||
* @author Joel Håkansson | ||
*/ | ||
class Keys { | ||
|
||
/** | ||
* Provides a format name for pef files. | ||
*/ | ||
static final String PEF_FORMAT = "pef"; | ||
/** | ||
* Provides a format name for text files. | ||
*/ | ||
static final String FORMATTED_TEXT_FORMAT = "formatted-text"; | ||
/** | ||
* Provides a format name for obfl files. | ||
*/ | ||
static final String OBFL_FORMAT = "obfl"; | ||
/** | ||
* Defines a key for the input file. | ||
*/ | ||
static final String INPUT = "input"; | ||
/** | ||
* Defines a key for input uri. | ||
*/ | ||
static final String INPUT_URI = "input-uri"; | ||
|
||
/** | ||
* Defines a key for temp files directory. | ||
*/ | ||
static final String TEMP_FILES_DIRECTORY = "tempFilesDirectory"; | ||
|
||
private Keys() { | ||
} | ||
|
||
} |
78 changes: 78 additions & 0 deletions
78
src/org/daisy/dotify/tasks/impl/input/obfl/LayoutEngine.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package org.daisy.dotify.tasks.impl.input.obfl; | ||
|
||
import org.daisy.dotify.api.engine.FormatterEngineFactoryService; | ||
import org.daisy.dotify.api.translator.BrailleTranslatorFactoryMakerService; | ||
import org.daisy.dotify.api.writer.PagedMediaWriterFactoryMakerService; | ||
import org.daisy.streamline.api.tasks.InternalTask; | ||
import org.daisy.streamline.api.tasks.TaskGroup; | ||
import org.daisy.streamline.api.tasks.TaskGroupSpecification; | ||
import org.daisy.streamline.api.tasks.TaskSystemException; | ||
import org.daisy.streamline.api.validity.ValidatorFactoryMakerService; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Properties; | ||
|
||
/** | ||
* Provides a task group for running the Dotify formatter. | ||
* | ||
* @author Joel Håkansson | ||
*/ | ||
public class LayoutEngine implements TaskGroup { | ||
|
||
private final TaskGroupSpecification spec; | ||
private final PagedMediaWriterFactoryMakerService pmw; | ||
private final FormatterEngineFactoryService fe; | ||
private final ValidatorFactoryMakerService vf; | ||
private final BrailleTranslatorFactoryMakerService translatorFactory; | ||
|
||
/** | ||
* Creates a new layout engine with the specified parameters. | ||
* | ||
* @param spec the task group specification | ||
* @param pmw a paged media writer factory maker service | ||
* @param fe a formatter engine factory service | ||
* @param vf a validator factory service | ||
* @param translatorFactory a translator factory maker service | ||
*/ | ||
public LayoutEngine( | ||
TaskGroupSpecification spec, | ||
PagedMediaWriterFactoryMakerService pmw, | ||
FormatterEngineFactoryService fe, | ||
ValidatorFactoryMakerService vf, | ||
BrailleTranslatorFactoryMakerService translatorFactory | ||
) { | ||
this.spec = spec; | ||
this.pmw = pmw; | ||
this.fe = fe; | ||
this.vf = vf; | ||
this.translatorFactory = translatorFactory; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "Layout Engine"; | ||
} | ||
|
||
@Override | ||
public List<InternalTask> compile(Map<String, Object> parameters) throws TaskSystemException { | ||
|
||
ArrayList<InternalTask> ret = new ArrayList<>(); | ||
Properties p2 = new Properties(); | ||
p2.putAll(parameters); | ||
// Layout FLOW as PEF | ||
|
||
// Customize which parameters are sent to the PEFMediaWriter, as it | ||
// outputs all parameters for future reference | ||
// System file paths should be concealed for security reasons | ||
p2.remove(Keys.INPUT); | ||
p2.remove(Keys.INPUT_URI); | ||
p2.remove("output"); | ||
p2.remove("obfl-output-location"); | ||
p2.remove(Keys.TEMP_FILES_DIRECTORY); | ||
ret.add(new LayoutEngineTask(p2, spec, pmw, fe, vf, translatorFactory)); | ||
return ret; | ||
} | ||
|
||
} |
152 changes: 152 additions & 0 deletions
152
src/org/daisy/dotify/tasks/impl/input/obfl/LayoutEngineFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
package org.daisy.dotify.tasks.impl.input.obfl; | ||
|
||
import org.daisy.dotify.api.engine.FormatterEngineFactoryService; | ||
import org.daisy.dotify.api.engine.FormatterEngineMaker; | ||
import org.daisy.dotify.api.translator.BrailleTranslatorFactoryMaker; | ||
import org.daisy.dotify.api.translator.BrailleTranslatorFactoryMakerService; | ||
import org.daisy.dotify.api.writer.PagedMediaWriterFactoryMaker; | ||
import org.daisy.dotify.api.writer.PagedMediaWriterFactoryMakerService; | ||
import org.daisy.streamline.api.tasks.TaskGroup; | ||
import org.daisy.streamline.api.tasks.TaskGroupFactory; | ||
import org.daisy.streamline.api.tasks.TaskGroupInformation; | ||
import org.daisy.streamline.api.tasks.TaskGroupSpecification; | ||
import org.daisy.streamline.api.validity.ValidatorFactoryMaker; | ||
import org.daisy.streamline.api.validity.ValidatorFactoryMakerService; | ||
import org.osgi.service.component.annotations.Component; | ||
import org.osgi.service.component.annotations.Reference; | ||
import org.osgi.service.component.annotations.ReferenceCardinality; | ||
|
||
import java.util.Collections; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
/** | ||
* Provides a task group factory for running the Dotify formatter. | ||
* | ||
* @author Joel Håkansson | ||
*/ | ||
@Component | ||
public class LayoutEngineFactory implements TaskGroupFactory { | ||
private final Set<TaskGroupInformation> information; | ||
private PagedMediaWriterFactoryMakerService pmw; | ||
private FormatterEngineFactoryService fe; | ||
private ValidatorFactoryMakerService vf; | ||
private BrailleTranslatorFactoryMakerService translatorFactory; | ||
|
||
/** | ||
* Creates a new layout engine factory. | ||
*/ | ||
public LayoutEngineFactory() { | ||
Set<TaskGroupInformation> tmp = new HashSet<>(); | ||
tmp.add(TaskGroupInformation.newConvertBuilder("obfl", Keys.PEF_FORMAT).build()); | ||
tmp.add(TaskGroupInformation.newConvertBuilder("obfl", Keys.FORMATTED_TEXT_FORMAT).build()); | ||
information = Collections.unmodifiableSet(tmp); | ||
} | ||
|
||
@Override | ||
public boolean supportsSpecification(TaskGroupInformation spec) { | ||
return listAll().contains(spec); | ||
} | ||
|
||
@Override | ||
public TaskGroup newTaskGroup(TaskGroupSpecification spec) { | ||
return new LayoutEngine(spec, pmw, fe, vf, translatorFactory); | ||
} | ||
|
||
@Override | ||
public Set<TaskGroupInformation> listAll() { | ||
return information; | ||
} | ||
|
||
public void setCreatedWithSPI() { | ||
if (pmw == null) { | ||
pmw = PagedMediaWriterFactoryMaker.newInstance(); | ||
} | ||
if (fe == null) { | ||
fe = FormatterEngineMaker.newInstance().getFactory(); | ||
} | ||
if (vf == null) { | ||
vf = ValidatorFactoryMaker.newInstance(); | ||
} | ||
if (translatorFactory == null) { | ||
translatorFactory = BrailleTranslatorFactoryMaker.newInstance(); | ||
} | ||
} | ||
|
||
/** | ||
* Sets a factory dependency. | ||
* | ||
* @param service the dependency | ||
*/ | ||
@Reference(cardinality = ReferenceCardinality.MANDATORY) | ||
public void setPagedMediaWriterFactory(PagedMediaWriterFactoryMakerService service) { | ||
this.pmw = service; | ||
} | ||
|
||
/** | ||
* Removes a factory dependency. | ||
* | ||
* @param service the dependency to remove | ||
*/ | ||
public void unsetPagedMediaWriterFactory(PagedMediaWriterFactoryMakerService service) { | ||
this.pmw = null; | ||
} | ||
|
||
/** | ||
* Sets a factory dependency. | ||
* | ||
* @param service the dependency | ||
*/ | ||
@Reference(cardinality = ReferenceCardinality.MANDATORY) | ||
public void setFormatterEngineFactory(FormatterEngineFactoryService service) { | ||
this.fe = service; | ||
} | ||
|
||
/** | ||
* Removes a factory dependency. | ||
* | ||
* @param service the dependency to remove | ||
*/ | ||
public void unsetFormatterEngineFactory(FormatterEngineFactoryService service) { | ||
this.fe = null; | ||
} | ||
|
||
/** | ||
* Sets a factory dependency. | ||
* | ||
* @param service the dependency | ||
*/ | ||
@Reference(cardinality = ReferenceCardinality.MANDATORY) | ||
public void setValidatorFactory(ValidatorFactoryMakerService service) { | ||
this.vf = service; | ||
} | ||
|
||
/** | ||
* Removes a factory dependency. | ||
* | ||
* @param service the dependency to remove | ||
*/ | ||
public void unsetValidatorFactory(ValidatorFactoryMakerService service) { | ||
this.vf = null; | ||
} | ||
|
||
/** | ||
* Sets a factory dependency. | ||
* | ||
* @param service the dependency | ||
*/ | ||
@Reference(cardinality = ReferenceCardinality.OPTIONAL) | ||
public void setTranslator(BrailleTranslatorFactoryMakerService service) { | ||
this.translatorFactory = service; | ||
} | ||
|
||
/** | ||
* Removes a factory dependency. | ||
* | ||
* @param service the dependency to remove | ||
*/ | ||
public void unsetTranslator(BrailleTranslatorFactoryMakerService service) { | ||
this.translatorFactory = null; | ||
} | ||
|
||
} |
Oops, something went wrong.