Set ouput

This commit is contained in:
Georgy Litvinov 2020-02-28 13:56:03 +01:00
parent 30110ee2af
commit 3c0519cc22
3 changed files with 24 additions and 39 deletions

View file

@ -4,6 +4,7 @@ import java.io.File;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;
@ -28,10 +29,11 @@ public class DocumentStructure {
private HashMap<String, DocumentPart> inputParts;
private final String TS = "https://iph.ras.ru/text_structures#";
private final String PARSERNAME = "w2phtml";
private final String EXCERPT = "Excerpt";
private final String EXCERPT = "textExcerpt";
private final String TOC_ELEMENT = "TOCElement";
private final String ELENPHARTICLE = "elenphArticle";
private String documentID = "DOC_ID";
private String documentID = "12DOC_ID";
private OntModel m;
private OntClass excerptClass;
@ -90,13 +92,8 @@ public class DocumentStructure {
}
return emptyPath.toString();
}
public void printModel() {
m.write(System.out, "RDF/XML-ABBREV");
}
public void printModel(String fileName) {
//RDFWriter writer = m.getWriter();
//writer.setProperty("showXmlDeclaration","true");
File outFile = new File(fileName + ".rdf");
FileWriter fw = null;
try {
@ -117,6 +114,9 @@ public class DocumentStructure {
}
}
public void printModel(OutputStream os) {
m.write(os,"RDF/XML-ABBREV");
}
private void addPart(DocumentPart docExcerpt) {

View file

@ -51,8 +51,6 @@ public final class RDFConverter extends Converter {
@Override public ConverterResult convert(InputStream is, String sTargetFileName) throws IOException {
setOpenPubStructure(false);
ConverterResult xhtmlResult = super.convert(is, "chapter");
createRDF(sTargetFileName);
return createPackage(xhtmlResult,sTargetFileName);
}
@ -61,21 +59,11 @@ public final class RDFConverter extends Converter {
return createPackage(xhtmlResult,sTargetFileName);
}
private void createRDF(String sTargetFileName) {
DocumentStructure structure = new DocumentStructure(this.outFiles);
structure.createTree();
structure.printModel(sTargetFileName);
}
private ConverterResult createPackage(ConverterResult xhtmlResult, String sTargetFileName) {
ConverterResultImpl rdfResult = new ConverterResultImpl();
RDFWriter rdfWriter = new RDFWriter(xhtmlResult,sTargetFileName,3,getXhtmlConfig());
rdfResult.addDocument(rdfWriter);
rdfResult.setMetaData(xhtmlResult.getMetaData());
return rdfResult;
ConverterResultImpl rdfConverterResult = new ConverterResultImpl();
RDFDocumentResult rdfDocument = new RDFDocumentResult(this.outFiles,sTargetFileName,getXhtmlConfig());
rdfConverterResult.addDocument(rdfDocument);
return rdfConverterResult;
}
}

View file

@ -4,6 +4,7 @@ import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Iterator;
import java.util.Vector;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
@ -11,30 +12,33 @@ import writer2latex.api.ConverterResult;
import writer2latex.api.OutputFile;
import writer2latex.util.Misc;
import writer2latex.xhtml.XhtmlConfig;
import writer2latex.xhtml.XhtmlDocument;
public class RDFWriter implements OutputFile {
public class RDFDocumentResult implements OutputFile {
private ConverterResult xhtmlResult;
private String sFileName;
private int nVersion;
private XhtmlConfig config;
private DocumentStructure rdfStructure = null;
public RDFWriter(ConverterResult xhtmlResult, String sFileName, int nVersion, XhtmlConfig config) {
this.xhtmlResult = xhtmlResult;
public RDFDocumentResult(Vector<XhtmlDocument> outFiles, String sFileName, XhtmlConfig config) {
this.sFileName = Misc.removeExtension(sFileName);
this.nVersion = nVersion;
this.config = config;
rdfStructure = new DocumentStructure(outFiles);
rdfStructure.createTree();
}
@Override public String getFileName() {
return sFileName+".rdf";
}
@Override public String getMIMEType() {
return "application/epub+zip";
return "rdf";
}
@Override public boolean isMasterDocument() {
@ -42,18 +46,11 @@ public class RDFWriter implements OutputFile {
}
@Override public boolean containsMath() {
// We don't really care about this
return nVersion==3;
return false;
}
@Override public void write(OutputStream os) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
// Finally XHTML content
Iterator<OutputFile> iter = xhtmlResult.iterator();
while (iter.hasNext()) {
OutputFile excerptFile = iter.next();
}
rdfStructure.printModel(os);
}
}