Search in sources :

Example 6 with SourceContentHandler

use of de.catma.document.source.contenthandler.SourceContentHandler in project catma by forTEXT.

the class GitSourceDocumentHandler method open.

public SourceDocument open(@Nonnull String projectId, @Nonnull String sourceDocumentId) throws IOException {
    try (ILocalGitRepositoryManager localGitRepoManager = this.localGitRepositoryManager) {
        String projectRootRepositoryName = GitProjectManager.getProjectRootRepositoryName(projectId);
        localGitRepoManager.open(projectId, projectRootRepositoryName);
        String sourceDocumentSubmoduleName = String.format("%s/%s", GitProjectHandler.SOURCE_DOCUMENT_SUBMODULES_DIRECTORY_NAME, sourceDocumentId);
        File sourceDocumentSubmodulePath = new File(localGitRepoManager.getRepositoryWorkTree().toString(), sourceDocumentSubmoduleName);
        File headerFile = new File(sourceDocumentSubmodulePath, HEADER_FILE_NAME);
        String serializedHeaderFile = FileUtils.readFileToString(headerFile, StandardCharsets.UTF_8);
        SourceDocumentInfo sourceDocumentInfo = new SerializationHelper<SourceDocumentInfo>().deserialize(serializedHeaderFile, SourceDocumentInfo.class);
        SourceDocumentHandler sourceDocumentHandler = new SourceDocumentHandler();
        SourceContentHandler sourceContentHandler = new StandardContentHandler();
        sourceContentHandler.setSourceDocumentInfo(sourceDocumentInfo);
        SourceDocument sourceDocument = sourceDocumentHandler.loadSourceDocument(sourceDocumentId, sourceContentHandler);
        String sourceDocumentRevisionHash = localGitRepoManager.getSubmoduleHeadRevisionHash(sourceDocumentSubmoduleName);
        sourceDocument.setRevisionHash(sourceDocumentRevisionHash);
        return sourceDocument;
    }
}
Also used : ILocalGitRepositoryManager(de.catma.repository.git.interfaces.ILocalGitRepositoryManager) StandardContentHandler(de.catma.document.source.contenthandler.StandardContentHandler) File(java.io.File) SourceContentHandler(de.catma.document.source.contenthandler.SourceContentHandler)

Aggregations

SourceContentHandler (de.catma.document.source.contenthandler.SourceContentHandler)6 AnnotationCollection (de.catma.document.annotation.AnnotationCollection)1 FileOSType (de.catma.document.source.FileOSType)1 SourceDocument (de.catma.document.source.SourceDocument)1 SourceDocumentInfo (de.catma.document.source.SourceDocumentInfo)1 StandardContentHandler (de.catma.document.source.contenthandler.StandardContentHandler)1 TikaContentHandler (de.catma.document.source.contenthandler.TikaContentHandler)1 XML2ContentHandler (de.catma.document.source.contenthandler.XML2ContentHandler)1 ILocalGitRepositoryManager (de.catma.repository.git.interfaces.ILocalGitRepositoryManager)1 File (java.io.File)1 IOException (java.io.IOException)1 CRC32 (java.util.zip.CRC32)1