Skip to content

Commit

Permalink
Merge pull request #6 from mtmse/move_task_code
Browse files Browse the repository at this point in the history
Move task code to the task project.
  • Loading branch information
kalaspuffar authored Apr 17, 2020
2 parents 75dbacc + f742a33 commit d378252
Show file tree
Hide file tree
Showing 7 changed files with 650 additions and 1 deletion.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ repositories {

dependencies {
compileOnly 'org.osgi:org.osgi.service.component.annotations:1.3.0'
compile "org.daisy.dotify:dotify.api:5.0.2"
compile 'org.daisy.streamline:streamline-api:1.5.0'
compile 'org.daisy.dotify:dotify.common:4.4.1'
compile (group: 'org.daisy.libs', name: 'jing', version: '20120724.0.0') {
Expand Down
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
39 changes: 39 additions & 0 deletions src/org/daisy/dotify/tasks/impl/input/obfl/Keys.java
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 src/org/daisy/dotify/tasks/impl/input/obfl/LayoutEngine.java
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 src/org/daisy/dotify/tasks/impl/input/obfl/LayoutEngineFactory.java
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;
}

}
Loading

0 comments on commit d378252

Please sign in to comment.