-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Joel Håkansson
committed
Nov 8, 2013
0 parents
commit 31e8378
Showing
123 changed files
with
8,686 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="src" output="bin" path="src"/> | ||
<classpathentry kind="src" output="bin_test" path="test"/> | ||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/> | ||
<classpathentry kind="con" path="aQute.bnd.classpath.container"/> | ||
<classpathentry kind="lib" path="/DotifyShared/junit-4.7.jar"/> | ||
<classpathentry kind="output" path="bin"/> | ||
</classpath> |
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,23 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>dotify.formatter.impl</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>org.eclipse.jdt.core.javabuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
<buildCommand> | ||
<name>bndtools.core.bndbuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.eclipse.jdt.core.javanature</nature> | ||
<nature>bndtools.core.bndnature</nature> | ||
</natures> | ||
</projectDescription> |
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,11 @@ | ||
eclipse.preferences.version=1 | ||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled | ||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 | ||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve | ||
org.eclipse.jdt.core.compiler.compliance=1.5 | ||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate | ||
org.eclipse.jdt.core.compiler.debug.localVariable=generate | ||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate | ||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error | ||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error | ||
org.eclipse.jdt.core.compiler.source=1.5 |
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,18 @@ | ||
Private-Package: org.example,\ | ||
org.daisy.dotify.engine.impl,\ | ||
org.daisy.dotify.formatter.impl,\ | ||
org.daisy.dotify.obfl.impl | ||
Service-Component: * | ||
Include-Resource: / = src/ | ||
-sources: false | ||
-buildpath: osgi.core,\ | ||
osgi.cmpn,\ | ||
biz.aQute.bnd.annotation,\ | ||
junit.osgi,\ | ||
dotify.api;version=latest,\ | ||
javax.xml.stream,\ | ||
dotify.common;version=latest,\ | ||
com.sun.enterprise.stax-osgi | ||
Export-Package: org.daisy.dotify.obfl,\ | ||
org.daisy.dotify.tools,\ | ||
org.daisy.dotify.writer |
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,7 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project name="project" default="build"> | ||
|
||
<!-- --> | ||
|
||
<import file="../cnf/build.xml" /> | ||
</project> |
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,14 @@ | ||
-runfw: org.apache.felix.framework;version='[4,5)' | ||
-runee: JavaSE-1.6 | ||
-runsystemcapabilities: ${native_capability} | ||
|
||
-resolve.effective: active | ||
|
||
-runbundles:\ | ||
org.apache.felix.gogo.runtime,\ | ||
org.apache.felix.gogo.shell,\ | ||
org.apache.felix.gogo.command | ||
|
||
-runrequires:\ | ||
osgi.identity;filter:='(osgi.identity=org.apache.felix.gogo.shell)',\ | ||
osgi.identity;filter:='(osgi.identity=org.apache.felix.gogo.command)' |
1 change: 1 addition & 0 deletions
1
src/META-INF/services/org.daisy.dotify.api.engine.FormatterEngineFactoryService
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 @@ | ||
org.daisy.dotify.engine.impl.LayoutEngineFactoryImpl |
1 change: 1 addition & 0 deletions
1
src/META-INF/services/org.daisy.dotify.api.formatter.FormatterFactory
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 @@ | ||
org.daisy.dotify.formatter.impl.FormatterFactoryImpl |
1 change: 1 addition & 0 deletions
1
src/META-INF/services/org.daisy.dotify.api.obfl.ExpressionFactory
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 @@ | ||
org.daisy.dotify.obfl.impl.ExpressionFactoryImpl |
95 changes: 95 additions & 0 deletions
95
src/org/daisy/dotify/engine/impl/LayoutEngineFactoryImpl.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,95 @@ | ||
package org.daisy.dotify.engine.impl; | ||
|
||
import javax.xml.stream.XMLEventFactory; | ||
import javax.xml.stream.XMLInputFactory; | ||
import javax.xml.stream.XMLOutputFactory; | ||
|
||
import org.daisy.dotify.api.engine.FormatterEngineFactoryService; | ||
import org.daisy.dotify.api.formatter.FormatterFactory; | ||
import org.daisy.dotify.api.obfl.ExpressionFactory; | ||
import org.daisy.dotify.api.translator.MarkerProcessorFactoryMakerService; | ||
import org.daisy.dotify.api.translator.TextBorderFactoryMakerService; | ||
import org.daisy.dotify.api.writer.PagedMediaWriter; | ||
|
||
import aQute.bnd.annotation.component.Component; | ||
import aQute.bnd.annotation.component.Reference; | ||
|
||
@Component | ||
public class LayoutEngineFactoryImpl implements FormatterEngineFactoryService { | ||
private FormatterFactory ff; | ||
private MarkerProcessorFactoryMakerService mpf; | ||
private TextBorderFactoryMakerService tbf; | ||
private ExpressionFactory ef; | ||
private XMLInputFactory in; | ||
private XMLEventFactory xef; | ||
private XMLOutputFactory of; | ||
|
||
public LayoutEngineImpl newFormatterEngine(String locale, String mode, PagedMediaWriter writer) { | ||
return new LayoutEngineImpl(locale, mode, writer, ff, mpf, tbf, ef, in, xef, of); | ||
} | ||
|
||
// FIXME: not a service | ||
@Reference | ||
public void setFormatterFactory(FormatterFactory formatterFactory) { | ||
this.ff = formatterFactory; | ||
} | ||
|
||
public void unsetFormatterFactory(FormatterFactory formatterFactory) { | ||
this.ff = null; | ||
} | ||
|
||
@Reference | ||
public void setMarkerProcessor(MarkerProcessorFactoryMakerService mp) { | ||
this.mpf = mp; | ||
} | ||
|
||
public void unsetMarkerProcessor(MarkerProcessorFactoryMakerService mp) { | ||
this.mpf = null; | ||
} | ||
|
||
@Reference | ||
public void setTextBorderFactoryMaker(TextBorderFactoryMakerService tbf) { | ||
this.tbf = tbf; | ||
} | ||
|
||
public void unsetTextBorderFactoryMaker(TextBorderFactoryMakerService tbf) { | ||
this.tbf = null; | ||
} | ||
|
||
@Reference | ||
public void setExpressionFactory(ExpressionFactory ef) { | ||
this.ef = ef; | ||
} | ||
|
||
public void unsetExpressionFactory(ExpressionFactory ef) { | ||
this.ef = null; | ||
} | ||
|
||
@Reference | ||
public void setXMLInputFactory(XMLInputFactory in) { | ||
this.in = in; | ||
} | ||
|
||
public void unsetXMLInputFactory(XMLInputFactory in) { | ||
this.in = null; | ||
} | ||
|
||
@Reference | ||
public void setXMLEventFactory(XMLEventFactory xef) { | ||
this.xef = xef; | ||
} | ||
|
||
public void unsetXMLEventFactory(XMLEventFactory xef) { | ||
this.xef = null; | ||
} | ||
|
||
@Reference | ||
public void setXMLOutputFactory(XMLOutputFactory of) { | ||
this.of = of; | ||
} | ||
|
||
public void unsetXMLOutputFactory(XMLOutputFactory of) { | ||
this.of = null; | ||
} | ||
|
||
} |
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,141 @@ | ||
package org.daisy.dotify.engine.impl; | ||
|
||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.FileNotFoundException; | ||
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.OutputStream; | ||
import java.util.logging.Logger; | ||
|
||
import javax.xml.stream.XMLEventFactory; | ||
import javax.xml.stream.XMLInputFactory; | ||
import javax.xml.stream.XMLOutputFactory; | ||
import javax.xml.stream.XMLStreamException; | ||
|
||
import org.daisy.dotify.api.engine.FormatterEngine; | ||
import org.daisy.dotify.api.engine.LayoutEngineException; | ||
import org.daisy.dotify.api.formatter.FormatterFactory; | ||
import org.daisy.dotify.api.obfl.ExpressionFactory; | ||
import org.daisy.dotify.api.translator.MarkerProcessor; | ||
import org.daisy.dotify.api.translator.MarkerProcessorConfigurationException; | ||
import org.daisy.dotify.api.translator.MarkerProcessorFactoryMakerService; | ||
import org.daisy.dotify.api.translator.TextBorderFactoryMakerService; | ||
import org.daisy.dotify.api.writer.PagedMediaWriter; | ||
import org.daisy.dotify.api.writer.PagedMediaWriterException; | ||
import org.daisy.dotify.obfl.OBFLParserException; | ||
import org.daisy.dotify.obfl.OBFLWsNormalizer; | ||
import org.daisy.dotify.obfl.ObflParser; | ||
|
||
/** | ||
* <p> | ||
* The LayoutEngineTask converts an OBFL-file into a file format defined by the | ||
* supplied {@link PagedMediaWriter}.</p> | ||
* | ||
* <p>The LayoutEngineTask is an advanced text-only layout system.</p> | ||
* <p>Input file must be of type OBFL.</p> | ||
* | ||
* @author Joel Håkansson | ||
* | ||
*/ | ||
class LayoutEngineImpl implements FormatterEngine { | ||
private final String locale; | ||
private final String mode; | ||
private final PagedMediaWriter writer; | ||
private final Logger logger; | ||
private boolean normalize; | ||
private final FormatterFactory ff; | ||
private final MarkerProcessorFactoryMakerService mpf; | ||
private final TextBorderFactoryMakerService tbf; | ||
private final ExpressionFactory ef; | ||
private final XMLInputFactory in; | ||
private final XMLEventFactory xef; | ||
private final XMLOutputFactory of; | ||
|
||
/** | ||
* Creates a new instance of LayoutEngineTask. | ||
* @param name a descriptive name for the task | ||
* @param translator the translator to use | ||
* @param writer the output writer | ||
*/ | ||
public LayoutEngineImpl(String locale, String mode, PagedMediaWriter writer, FormatterFactory ff, MarkerProcessorFactoryMakerService mpf, TextBorderFactoryMakerService tbf, ExpressionFactory ef, XMLInputFactory in, XMLEventFactory xef, XMLOutputFactory of) { | ||
this.locale = locale; | ||
this.mode = mode; | ||
//this.locale = locale; | ||
this.writer = writer; | ||
this.logger = Logger.getLogger(LayoutEngineImpl.class.getCanonicalName()); | ||
this.normalize = true; | ||
this.ff = ff; | ||
this.mpf = mpf; | ||
this.tbf = tbf; | ||
this.ef = ef; | ||
this.of = of; | ||
this.xef = xef; | ||
this.in = in; | ||
} | ||
|
||
public boolean isNormalizing() { | ||
return normalize; | ||
} | ||
|
||
public void setNormalizing(boolean normalize) { | ||
this.normalize = normalize; | ||
} | ||
|
||
public void convert(InputStream input, OutputStream output) throws LayoutEngineException { | ||
File f = null; | ||
try { | ||
if (normalize) { | ||
logger.info("Normalizing obfl..."); | ||
try { | ||
f = File.createTempFile("temp", ".tmp"); | ||
f.deleteOnExit(); | ||
OBFLWsNormalizer normalizer = new OBFLWsNormalizer(in.createXMLEventReader(input), xef, new FileOutputStream(f)); | ||
normalizer.parse(of); | ||
input = new FileInputStream(f); | ||
} catch (Exception e) { | ||
throw new LayoutEngineException(e); | ||
} | ||
} | ||
try { | ||
logger.info("Parsing input..."); | ||
|
||
MarkerProcessor mp; | ||
try { | ||
mp = mpf.newMarkerProcessor(locale, mode); | ||
} catch (MarkerProcessorConfigurationException e) { | ||
throw new IllegalArgumentException(e); | ||
} | ||
ObflParser obflParser = new ObflParser(locale, mode, mp, ff, tbf, ef); | ||
obflParser.parse(in.createXMLEventReader(input)); | ||
|
||
logger.info("Rendering output..."); | ||
writer.open(output, obflParser.getMetaData()); | ||
|
||
WriterHandler wh = new WriterHandler(); | ||
wh.write(obflParser.getFormattedResult(), writer); | ||
writer.close(); | ||
|
||
} catch (FileNotFoundException e) { | ||
throw new LayoutEngineException("FileNotFoundException while running task. ", e); | ||
} catch (IOException e) { | ||
throw new LayoutEngineException("IOException while running task. ", e); | ||
} catch (PagedMediaWriterException e) { | ||
throw new LayoutEngineException("Could not open media writer.", e); | ||
} catch (XMLStreamException e) { | ||
throw new LayoutEngineException("XMLStreamException while running task.", e); | ||
} catch (OBFLParserException e) { | ||
throw new LayoutEngineException("FormatterException while running task.", e); | ||
} | ||
} finally { | ||
if (f != null) { | ||
if (!f.delete()) { | ||
f.deleteOnExit(); | ||
} | ||
} | ||
} | ||
} | ||
|
||
} | ||
|
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,55 @@ | ||
package org.daisy.dotify.engine.impl; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
import org.daisy.dotify.api.formatter.LayoutMaster; | ||
import org.daisy.dotify.api.formatter.Page; | ||
import org.daisy.dotify.api.formatter.PageSequence; | ||
import org.daisy.dotify.api.formatter.Volume; | ||
import org.daisy.dotify.api.writer.PagedMediaWriter; | ||
|
||
/** | ||
* Provides a method for writing pages to a PagedMediaWriter, | ||
* adding headers and footers as required by the layout. | ||
* @author Joel Håkansson | ||
*/ | ||
class WriterHandler { | ||
|
||
public WriterHandler() { | ||
} | ||
/** | ||
* Writes this structure to the suppled PagedMediaWriter. | ||
* @param writer the PagedMediaWriter to write to | ||
* @throws IOException if IO fails | ||
*/ | ||
public void write(Iterable<Volume> volumes, PagedMediaWriter writer) { | ||
for (Volume v : volumes) { | ||
boolean firstInVolume = true; | ||
for (PageSequence s : v.getContents()) { | ||
LayoutMaster lm = s.getLayoutMaster(); | ||
if (firstInVolume) { | ||
firstInVolume = false; | ||
writer.newVolume(lm); | ||
} | ||
writer.newSection(lm); | ||
for (Page p : s.getPages()) { | ||
writePage(writer, p); | ||
} | ||
} | ||
} | ||
} | ||
|
||
private void writePage(PagedMediaWriter writer, Page p) { | ||
writer.newPage(); | ||
List<String> rows = p.getRows(); | ||
for (String r : rows) { | ||
if (r.length() > 0) { | ||
writer.newRow(r); | ||
} else { | ||
writer.newRow(); | ||
} | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.