use of org.olat.search.service.document.file.FileDocumentFactory in project OpenOLAT by OpenOLAT.
the class FileArtefactHandler method getContent.
@Override
protected void getContent(AbstractArtefact artefact, StringBuilder sb, SearchResourceContext context, EPFrontendManager ePFManager) {
FileArtefact fileArtefact = (FileArtefact) artefact;
String filename = fileArtefact.getFilename();
VFSItem file = ePFManager.getArtefactContainer(artefact).resolve(filename);
if (file != null && file instanceof VFSLeaf) {
try {
FileDocumentFactory docFactory = CoreSpringFactory.getImpl(FileDocumentFactory.class);
if (docFactory.isFileSupported((VFSLeaf) file)) {
Document doc = docFactory.createDocument(context, (VFSLeaf) file);
String content = doc.get(AbstractOlatDocument.CONTENT_FIELD_NAME);
sb.append(content);
}
} catch (Exception e) {
log.error("Could not get content of file " + file.getName() + " (file-artefact " + artefact.getKey() + ")", e);
}
}
}
use of org.olat.search.service.document.file.FileDocumentFactory in project OpenOLAT by OpenOLAT.
the class LeafIndexer method doIndexVFSLeafByMySelf.
protected void doIndexVFSLeafByMySelf(SearchResourceContext leafResourceContext, VFSLeaf leaf, OlatFullIndexer indexWriter, String filePath) throws InterruptedException {
if (isLogDebugEnabled())
logDebug("Analyse VFSLeaf=" + leaf.getName());
try {
FileDocumentFactory documentFactory = CoreSpringFactory.getImpl(FileDocumentFactory.class);
if (documentFactory.isFileSupported(leaf)) {
String myFilePath = "";
if (filePath.endsWith("/")) {
myFilePath = filePath + leaf.getName();
} else {
myFilePath = filePath + "/" + leaf.getName();
}
leafResourceContext.setFilePath(myFilePath);
Document document = documentFactory.createDocument(leafResourceContext, leaf);
indexWriter.addDocument(document);
} else {
if (isLogDebugEnabled())
logDebug("Documenttype not supported. file=" + leaf.getName());
}
} catch (DocumentAccessException e) {
if (isLogDebugEnabled())
logDebug("Can not access document." + e.getMessage());
} catch (IOException ioEx) {
logWarn("IOException: Can not index leaf=" + leaf.getName(), ioEx);
} catch (InterruptedException iex) {
throw new InterruptedException(iex.getMessage());
} catch (Exception ex) {
logWarn("Exception: Can not index leaf=" + leaf.getName(), ex);
}
}
use of org.olat.search.service.document.file.FileDocumentFactory in project OpenOLAT by OpenOLAT.
the class AbstractQPoolServiceProvider method extractTextContent.
@Override
public String extractTextContent(QuestionItemFull item) {
String directory = item.getDirectory();
VFSContainer itemDir = getFileStorage().getContainer(directory);
VFSItem file = itemDir.resolve(item.getRootFilename());
if (file instanceof VFSLeaf) {
FileDocumentFactory docFactory = CoreSpringFactory.getImpl(FileDocumentFactory.class);
SearchResourceContext ctxt = new SearchResourceContext();
ctxt.setBusinessControlFor(item);
try {
String content = null;
Document doc = docFactory.createDocument(ctxt, (VFSLeaf) file);
for (IndexableField field : doc.getFields()) {
if (AbstractOlatDocument.CONTENT_FIELD_NAME.equals(field.name())) {
content = field.stringValue();
}
}
return content;
} catch (IOException e) {
log.error("", e);
} catch (DocumentAccessException e) {
log.warn("", e);
}
}
return null;
}
use of org.olat.search.service.document.file.FileDocumentFactory in project openolat by klemens.
the class AbstractQPoolServiceProvider method extractTextContent.
@Override
public String extractTextContent(QuestionItemFull item) {
String directory = item.getDirectory();
VFSContainer itemDir = getFileStorage().getContainer(directory);
VFSItem file = itemDir.resolve(item.getRootFilename());
if (file instanceof VFSLeaf) {
FileDocumentFactory docFactory = CoreSpringFactory.getImpl(FileDocumentFactory.class);
SearchResourceContext ctxt = new SearchResourceContext();
ctxt.setBusinessControlFor(item);
try {
String content = null;
Document doc = docFactory.createDocument(ctxt, (VFSLeaf) file);
for (IndexableField field : doc.getFields()) {
if (AbstractOlatDocument.CONTENT_FIELD_NAME.equals(field.name())) {
content = field.stringValue();
}
}
return content;
} catch (IOException e) {
log.error("", e);
} catch (DocumentAccessException e) {
log.warn("", e);
}
}
return null;
}
use of org.olat.search.service.document.file.FileDocumentFactory in project openolat by klemens.
the class FileArtefactHandler method getContent.
@Override
protected void getContent(AbstractArtefact artefact, StringBuilder sb, SearchResourceContext context, EPFrontendManager ePFManager) {
FileArtefact fileArtefact = (FileArtefact) artefact;
String filename = fileArtefact.getFilename();
VFSItem file = ePFManager.getArtefactContainer(artefact).resolve(filename);
if (file != null && file instanceof VFSLeaf) {
try {
FileDocumentFactory docFactory = CoreSpringFactory.getImpl(FileDocumentFactory.class);
if (docFactory.isFileSupported((VFSLeaf) file)) {
Document doc = docFactory.createDocument(context, (VFSLeaf) file);
String content = doc.get(AbstractOlatDocument.CONTENT_FIELD_NAME);
sb.append(content);
}
} catch (Exception e) {
log.error("Could not get content of file " + file.getName() + " (file-artefact " + artefact.getKey() + ")", e);
}
}
}
Aggregations