Search in sources :

Example 1 with TeiUserMarkupCollectionSerializationHandler

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();
    }
}
Also used : AnnotationCollection(de.catma.document.annotation.AnnotationCollection) GZIPOutputStream(java.util.zip.GZIPOutputStream) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) TarArchiveOutputStream(org.apache.commons.compress.archivers.tar.TarArchiveOutputStream) GZIPOutputStream(java.util.zip.GZIPOutputStream) SourceDocument(de.catma.document.source.SourceDocument) AnnotationCollectionReference(de.catma.document.annotation.AnnotationCollectionReference) TarArchiveOutputStream(org.apache.commons.compress.archivers.tar.TarArchiveOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) TeiUserMarkupCollectionSerializationHandler(de.catma.serialization.tei.TeiUserMarkupCollectionSerializationHandler) TarArchiveEntry(org.apache.commons.compress.archivers.tar.TarArchiveEntry)

Example 2 with TeiUserMarkupCollectionSerializationHandler

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;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) TeiUserMarkupCollectionSerializationHandler(de.catma.serialization.tei.TeiUserMarkupCollectionSerializationHandler)

Aggregations

TeiUserMarkupCollectionSerializationHandler (de.catma.serialization.tei.TeiUserMarkupCollectionSerializationHandler)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 AnnotationCollection (de.catma.document.annotation.AnnotationCollection)1 AnnotationCollectionReference (de.catma.document.annotation.AnnotationCollectionReference)1 SourceDocument (de.catma.document.source.SourceDocument)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 GZIPOutputStream (java.util.zip.GZIPOutputStream)1 TarArchiveEntry (org.apache.commons.compress.archivers.tar.TarArchiveEntry)1 TarArchiveOutputStream (org.apache.commons.compress.archivers.tar.TarArchiveOutputStream)1