Search in sources :

Example 11 with SourceDocumentInfo

use of de.catma.document.source.SourceDocumentInfo in project catma by forTEXT.

the class InspectContentStep method updatePreview.

private void updatePreview(UploadFile uploadFile) {
    Tika tika = new Tika();
    Metadata metadata = new Metadata();
    MediaType type = MediaType.parse(uploadFile.getMimetype());
    if (type.getBaseType().toString().equals(FileType.TEXT.getMimeType())) {
        metadata.set(Metadata.CONTENT_TYPE, new MediaType(type, uploadFile.getCharset()).toString());
    }
    try {
        String content = "";
        SourceDocumentInfo sourceDocumentInfo = new SourceDocumentInfo();
        IndexInfoSet indexInfoSet = new IndexInfoSet(Collections.emptyList(), Collections.emptyList(), uploadFile.getLocale());
        if (uploadFile.getMimetype().equals(FileType.XML2.getMimeType())) {
            XML2ContentHandler contentHandler = new XML2ContentHandler();
            TechInfoSet techInfoSet = new TechInfoSet(uploadFile.getOriginalFilename(), uploadFile.getMimetype(), uploadFile.getTempFilename());
            sourceDocumentInfo.setTechInfoSet(techInfoSet);
            contentHandler.setSourceDocumentInfo(sourceDocumentInfo);
            contentHandler.load();
            content = contentHandler.getContent();
        } else {
            try (FileInputStream fis = new FileInputStream(new File(uploadFile.getTempFilename()))) {
                content = tika.parseToString(fis, metadata, 3000);
            }
        }
        if (!content.isEmpty()) {
            content += " [...] ";
        }
        taPreview.setValue(content);
        if (indexInfoSet.isRightToLeftWriting()) {
            taPreview.addStyleName("document-wizard-rtl-preview");
        } else {
            taPreview.removeStyleName("document-wizard-rtl-preview");
        }
    } catch (Exception e) {
        Logger.getLogger(InspectContentStep.class.getName()).log(Level.SEVERE, String.format("Error loading preview of %1$s", uploadFile.getOriginalFilename()), e);
        String errorMsg = e.getMessage();
        if ((errorMsg == null) || (errorMsg.trim().isEmpty())) {
            errorMsg = "";
        }
        Notification.show("Error", String.format("Error loading content of %1$s! " + "Adding this file to your Project might fail!\n The underlying error message was:\n%2$s", uploadFile.getOriginalFilename(), errorMsg), Type.ERROR_MESSAGE);
    }
}
Also used : SourceDocumentInfo(de.catma.document.source.SourceDocumentInfo) IndexInfoSet(de.catma.document.source.IndexInfoSet) Metadata(org.apache.tika.metadata.Metadata) MediaType(org.apache.tika.mime.MediaType) XML2ContentHandler(de.catma.document.source.contenthandler.XML2ContentHandler) Tika(org.apache.tika.Tika) TechInfoSet(de.catma.document.source.TechInfoSet) File(java.io.File) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException)

Example 12 with SourceDocumentInfo

use of de.catma.document.source.SourceDocumentInfo in project catma by forTEXT.

the class TeiSourceDocumentInfoSerializationHandler method deserialize.

private SourceDocumentInfo deserialize(TeiDocument teiDocument) {
    ContentInfoSet contentInfoSet = teiDocument.getContentInfoSet();
    TechInfoSet techInfoSet = teiDocument.getTechInfoset();
    IndexInfoSet indexInfoSet = teiDocument.getIndexInfoSet();
    return new SourceDocumentInfo(indexInfoSet, contentInfoSet, techInfoSet);
}
Also used : ContentInfoSet(de.catma.document.source.ContentInfoSet) SourceDocumentInfo(de.catma.document.source.SourceDocumentInfo) IndexInfoSet(de.catma.document.source.IndexInfoSet) TechInfoSet(de.catma.document.source.TechInfoSet)

Aggregations

SourceDocumentInfo (de.catma.document.source.SourceDocumentInfo)12 TechInfoSet (de.catma.document.source.TechInfoSet)9 IndexInfoSet (de.catma.document.source.IndexInfoSet)8 File (java.io.File)8 FileInputStream (java.io.FileInputStream)8 ContentInfoSet (de.catma.document.source.ContentInfoSet)6 IDGenerator (de.catma.util.IDGenerator)6 XML2ContentHandler (de.catma.document.source.contenthandler.XML2ContentHandler)5 SourceDocument (de.catma.document.source.SourceDocument)4 JGitRepoManager (de.catma.repository.git.managers.JGitRepoManager)4 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 EventBus (com.google.common.eventbus.EventBus)3 BackgroundService (de.catma.backgroundservice.BackgroundService)3 TermExtractor (de.catma.indexer.TermExtractor)3 GitLabServerManagerTest (de.catma.repository.git.managers.GitLabServerManagerTest)3 UsernamePasswordCredentialsProvider (org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider)3 Test (org.junit.jupiter.api.Test)3 Notification (com.vaadin.ui.Notification)2