use of org.olat.search.service.SearchResourceContext in project OpenOLAT by OpenOLAT.
the class FileDocumentFactoryTest method testCreateHtmlDocument.
@Test
public void testCreateHtmlDocument() {
String filePath = "SearchTestFolder";
String htmlFileName = "test.html";
String htmlText = "<html><head><meta name=\"generator\" content=\"olat-tinymce-1\"><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"></head><body>" + "<H1>Test HTML Seite fuer JUnit Test</H1>" + "Dies ist<br />der Test Text" + // Text = 'Dies ist der Test Text'
"</body></html>";
// must include '\u00A0' !!! 19.5.2010/cg
String text = "Test HTML Seite fuer JUnit Test Dies ist der Test\u00A0Text";
// Create a test HTML File
OlatRootFolderImpl rootFolder = new OlatRootFolderImpl(rootPath, null);
OlatNamedContainerImpl namedFolder = new OlatNamedContainerImpl(filePath, rootFolder);
VFSLeaf leaf = (VFSLeaf) namedFolder.resolve(htmlFileName);
if (leaf != null) {
leaf.delete();
}
leaf = namedFolder.createChildLeaf(htmlFileName);
FileUtils.save(leaf.getOutputStream(false), htmlText, "utf-8");
try {
SearchResourceContext resourceContext = new SearchResourceContext();
resourceContext.setBusinessControlFor(OresHelper.createOLATResourceableType("FileDocumentFactoryTest"));
resourceContext.setFilePath(filePath + "/" + leaf.getName());
Document htmlDocument = fileDocumentFactory.createDocument(resourceContext, leaf);
// 1. Check content
String content = htmlDocument.get(OlatDocument.CONTENT_FIELD_NAME);
assertEquals("Wrong HTML content=" + content.trim() + " , must be =" + text.trim(), text.trim(), content.trim());
// 2. Check resourceUrl
String resourceUrl = htmlDocument.get(OlatDocument.RESOURCEURL_FIELD_NAME);
assertEquals("Wrong ResourceUrl", "[FileDocumentFactoryTest:0][path=" + filePath + "/" + htmlFileName + "]", resourceUrl);
// 3. Check File-Type
String fileType = htmlDocument.get(OlatDocument.FILETYPE_FIELD_NAME);
assertEquals("Wrong file-type", "type.file.html", fileType);
} catch (IOException e) {
fail("IOException=" + e.getMessage());
} catch (DocumentAccessException e) {
fail("DocumentAccessException=" + e.getMessage());
}
}
use of org.olat.search.service.SearchResourceContext in project OpenOLAT by OpenOLAT.
the class DocumentPoolIndexer method doIndex.
@Override
public void doIndex(SearchResourceContext parentResourceContext, Object object, OlatFullIndexer indexerWriter) throws IOException, InterruptedException {
String taxonomyTreeKey = documentPoolModule.getTaxonomyTreeKey();
if (StringHelper.isLong(taxonomyTreeKey)) {
Long taxonomyKey = new Long(taxonomyTreeKey);
Taxonomy taxonomy = taxonomyService.getTaxonomy(new TaxonomyRefImpl(taxonomyKey));
OLATResourceable docPoolOres = OresHelper.createOLATResourceableInstanceWithoutCheck(getSupportedTypeName(), 0l);
SearchResourceContext searchResourceContext = new SearchResourceContext(parentResourceContext);
searchResourceContext.setBusinessControlFor(docPoolOres);
searchResourceContext.setTitle(taxonomy.getDisplayName());
searchResourceContext.setDescription(taxonomy.getDescription());
searchResourceContext.setLastModified(taxonomy.getLastModified());
searchResourceContext.setCreatedDate(taxonomy.getCreationDate());
doIndexTaxonomyLibrary(searchResourceContext, taxonomy, indexerWriter);
}
}
use of org.olat.search.service.SearchResourceContext 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.SearchResourceContext 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.SearchResourceContext in project openolat by klemens.
the class FileDocumentFactoryTest method testCreateHtmlDocument.
@Test
public void testCreateHtmlDocument() {
String filePath = "SearchTestFolder";
String htmlFileName = "test.html";
String htmlText = "<html><head><meta name=\"generator\" content=\"olat-tinymce-1\"><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"></head><body>" + "<H1>Test HTML Seite fuer JUnit Test</H1>" + "Dies ist<br />der Test Text" + // Text = 'Dies ist der Test Text'
"</body></html>";
// must include '\u00A0' !!! 19.5.2010/cg
String text = "Test HTML Seite fuer JUnit Test Dies ist der Test\u00A0Text";
// Create a test HTML File
OlatRootFolderImpl rootFolder = new OlatRootFolderImpl(rootPath, null);
OlatNamedContainerImpl namedFolder = new OlatNamedContainerImpl(filePath, rootFolder);
VFSLeaf leaf = (VFSLeaf) namedFolder.resolve(htmlFileName);
if (leaf != null) {
leaf.delete();
}
leaf = namedFolder.createChildLeaf(htmlFileName);
FileUtils.save(leaf.getOutputStream(false), htmlText, "utf-8");
try {
SearchResourceContext resourceContext = new SearchResourceContext();
resourceContext.setBusinessControlFor(OresHelper.createOLATResourceableType("FileDocumentFactoryTest"));
resourceContext.setFilePath(filePath + "/" + leaf.getName());
Document htmlDocument = fileDocumentFactory.createDocument(resourceContext, leaf);
// 1. Check content
String content = htmlDocument.get(OlatDocument.CONTENT_FIELD_NAME);
assertEquals("Wrong HTML content=" + content.trim() + " , must be =" + text.trim(), text.trim(), content.trim());
// 2. Check resourceUrl
String resourceUrl = htmlDocument.get(OlatDocument.RESOURCEURL_FIELD_NAME);
assertEquals("Wrong ResourceUrl", "[FileDocumentFactoryTest:0][path=" + filePath + "/" + htmlFileName + "]", resourceUrl);
// 3. Check File-Type
String fileType = htmlDocument.get(OlatDocument.FILETYPE_FIELD_NAME);
assertEquals("Wrong file-type", "type.file.html", fileType);
} catch (IOException e) {
fail("IOException=" + e.getMessage());
} catch (DocumentAccessException e) {
fail("DocumentAccessException=" + e.getMessage());
}
}
Aggregations