Search in sources :

Example 1 with TeiTagLibrarySerializer

use of de.catma.serialization.tei.TeiTagLibrarySerializer in project catma by forTEXT.

the class TagsetXMLExportStreamSource method getStream.

@Override
public InputStream getStream() {
    final UI ui = UI.getCurrent();
    Set<TagsetDefinition> tagsets = tagsetsSupplier.get();
    Project project = projectSupplier.get();
    if (tagsets != null && !tagsets.isEmpty()) {
        TeiDocumentFactory teiDocumentFactory = new TeiDocumentFactory();
        try {
            final TeiDocument teiDocument = teiDocumentFactory.createEmptyDocument(null);
            final TeiTagLibrarySerializer teiTagSerializer = new TeiTagLibrarySerializer(teiDocument);
            final TagManager tagManager = new TagManager(new TagLibrary());
            tagsets.forEach(tagset -> tagManager.addTagsetDefinition(tagset));
            final ContentInfoSet contentInfoSet = new ContentInfoSet(project.getUser().toString(), project.getDescription(), project.getUser().toString(), project.getName());
            teiDocument.getTeiHeader().setValues(contentInfoSet);
            teiTagSerializer.serialize(tagManager.getTagLibrary());
            File tempFile = File.createTempFile(new IDGenerator().generate() + "_TagLibrary_Export", "xml");
            try (FileOutputStream fos = new FileOutputStream(tempFile)) {
                teiDocument.printXmlDocument(fos);
            }
            return new FileInputStream(tempFile);
        } catch (Exception e) {
            ((ErrorHandler) ui).showAndLogError("Error exporting Tagsets to XML!", e);
        }
    }
    return null;
}
Also used : TagLibrary(de.catma.tag.TagLibrary) TeiDocumentFactory(de.catma.serialization.tei.TeiDocumentFactory) TeiTagLibrarySerializer(de.catma.serialization.tei.TeiTagLibrarySerializer) FileInputStream(java.io.FileInputStream) TagsetDefinition(de.catma.tag.TagsetDefinition) Project(de.catma.project.Project) TagManager(de.catma.tag.TagManager) ContentInfoSet(de.catma.document.source.ContentInfoSet) UI(com.vaadin.ui.UI) FileOutputStream(java.io.FileOutputStream) File(java.io.File) IDGenerator(de.catma.util.IDGenerator) TeiDocument(de.catma.serialization.tei.TeiDocument)

Aggregations

UI (com.vaadin.ui.UI)1 ContentInfoSet (de.catma.document.source.ContentInfoSet)1 Project (de.catma.project.Project)1 TeiDocument (de.catma.serialization.tei.TeiDocument)1 TeiDocumentFactory (de.catma.serialization.tei.TeiDocumentFactory)1 TeiTagLibrarySerializer (de.catma.serialization.tei.TeiTagLibrarySerializer)1 TagLibrary (de.catma.tag.TagLibrary)1 TagManager (de.catma.tag.TagManager)1 TagsetDefinition (de.catma.tag.TagsetDefinition)1 IDGenerator (de.catma.util.IDGenerator)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1