use of de.catma.serialization.tei.TeiUserMarkupCollectionSerializationHandler in project catma by forTEXT.
the class CorpusExporter method export.
public void export(String exportName, Corpus corpus, OutputStream os) throws IOException {
OutputStream tarFileOs = new GZIPOutputStream(os);
TarArchiveOutputStream taOut = new TarArchiveOutputStream(tarFileOs, "UTF-8");
try {
taOut.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU);
taOut.setBigNumberMode(TarArchiveOutputStream.BIGNUMBER_POSIX);
for (SourceDocument sd : corpus.getSourceDocuments()) {
TarArchiveEntry sdEntry = new TarArchiveEntry(getSourceDocEntryName(exportName, sd));
byte[] sdContent = sd.getContent().getBytes(Charset.forName("UTF8"));
sdEntry.setSize(sdContent.length);
taOut.putArchiveEntry(sdEntry);
taOut.write(sdContent);
taOut.closeArchiveEntry();
for (AnnotationCollectionReference umcRef : corpus.getUserMarkupCollectionRefs(sd)) {
AnnotationCollection umc = repo.getUserMarkupCollection(umcRef);
TeiUserMarkupCollectionSerializationHandler handler = new TeiUserMarkupCollectionSerializationHandler(repo.getTagManager(), false);
ByteArrayOutputStream teiDocOut = new ByteArrayOutputStream();
handler.serialize(repo.getUserMarkupCollection(umcRef), sd, teiDocOut);
byte[] umcContent = teiDocOut.toByteArray();
String umcEntryName = getUmcEntryName(exportName, umc, sd);
TarArchiveEntry umcEntry = new TarArchiveEntry(umcEntryName);
umcEntry.setSize(umcContent.length);
taOut.putArchiveEntry(umcEntry);
taOut.write(umcContent);
taOut.closeArchiveEntry();
}
}
} finally {
taOut.finish();
taOut.close();
}
}
use of de.catma.serialization.tei.TeiUserMarkupCollectionSerializationHandler in project catma by forTEXT.
the class MarkupCollectionExportOptionsDialog method createExportResultStream.
private InputStream createExportResultStream(Project repository, SourceDocument sd, AnnotationCollectionReference umcRef, boolean withText) {
TeiUserMarkupCollectionSerializationHandler handler = new TeiUserMarkupCollectionSerializationHandler(repository.getTagManager(), withText);
ByteArrayOutputStream teiDocOut = new ByteArrayOutputStream();
try {
handler.serialize(repository.getUserMarkupCollection(umcRef), sd, teiDocOut);
final ByteArrayInputStream teiDownloadStream = new ByteArrayInputStream(teiDocOut.toByteArray());
return teiDownloadStream;
} catch (IOException e) {
((CatmaApplication) UI.getCurrent()).showAndLogError(Messages.getString("MarkupCollectionExportOptionsDialog.errorExportingAnnotations"), // $NON-NLS-1$
e);
}
return null;
}
Aggregations