use of org.olat.core.commons.modules.glossary.GlossaryItemManager in project OpenOLAT by OpenOLAT.
the class GlossaryTermMapper method handle.
/**
* @see org.olat.core.dispatcher.mapper.Mapper#handle(java.lang.String,
* javax.servlet.http.HttpServletRequest)
*/
public MediaResource handle(String relPath, HttpServletRequest request) {
GlossaryItemManager gIM = GlossaryItemManager.getInstance();
// security checks are done by MapperRegistry
String[] parts = relPath.split("/");
String glossaryId = parts[1];
String glossaryFolderString = FolderConfig.getCanonicalRoot() + FolderConfig.getRepositoryHome() + "/" + glossaryId + "/" + GlossaryMarkupItemController.INTERNAL_FOLDER_NAME;
File glossaryFolderFile = new File(glossaryFolderString);
if (!glossaryFolderFile.isDirectory()) {
logWarn("GlossaryTerms delivery failed; path to glossaryFolder not existing: " + relPath, null);
return new NotFoundMediaResource();
}
VFSContainer glossaryFolder = new LocalFolderImpl(glossaryFolderFile);
if (!gIM.isFolderContainingGlossary(glossaryFolder)) {
logWarn("GlossaryTerms delivery failed; glossaryFolder doesn't contain a valid Glossary: " + glossaryFolder, null);
return new NotFoundMediaResource();
}
// Create a media resource
StringMediaResource resource = new StringMediaResource() {
@Override
public void prepare(HttpServletResponse hres) {
// don't use normal string media headers which prevent caching,
// use standard browser caching based on last modified timestamp
}
};
resource.setLastModified(gIM.getGlossaryLastModifiedTime(glossaryFolder));
resource.setContentType("text/javascript");
// Get data
String glossaryArrayData = TextMarkerJsGenerator.loadGlossaryItemListAsJSArray(glossaryFolder);
resource.setData(glossaryArrayData);
// UTF-8 encoding used in this js file since explicitly set in the ajax
// call (usually js files are 8859-1)
resource.setEncoding("utf-8");
return resource;
}
use of org.olat.core.commons.modules.glossary.GlossaryItemManager in project OpenOLAT by OpenOLAT.
the class GlossaryEditSettingsController method formInnerEvent.
/**
* @see org.olat.core.gui.components.form.flexible.impl.FormBasicController#formInnerEvent(org.olat.core.gui.UserRequest, org.olat.core.gui.components.form.flexible.FormItem, org.olat.core.gui.components.form.flexible.impl.FormEvent)
*/
@Override
protected void formInnerEvent(UserRequest ureq, FormItem source, FormEvent event) {
if (source == editByUserEnabled) {
boolean editByUserChecked = editByUserEnabled.isSelected(0);
GlossaryItemManager gIM = GlossaryItemManager.getInstance();
Properties glossProps = gIM.getGlossaryConfig(glossaryFolder);
glossProps.put(GlossaryItemManager.EDIT_USERS, String.valueOf(editByUserChecked));
gIM.setGlossaryConfig(glossaryFolder, glossProps);
}
}
use of org.olat.core.commons.modules.glossary.GlossaryItemManager in project openolat by klemens.
the class GlossaryDefinitionMapper method handle.
/**
* @see org.olat.core.dispatcher.mapper.Mapper#handle(java.lang.String,
* javax.servlet.http.HttpServletRequest)
*/
public MediaResource handle(String relPath, HttpServletRequest request) {
GlossaryItemManager gIM = GlossaryItemManager.getInstance();
String[] parts = relPath.split("/");
String glossaryId = parts[1];
String glossaryFolderString = FolderConfig.getCanonicalRoot() + FolderConfig.getRepositoryHome() + "/" + glossaryId + "/" + GlossaryMarkupItemController.INTERNAL_FOLDER_NAME;
File glossaryFolderFile = new File(glossaryFolderString);
if (!glossaryFolderFile.isDirectory()) {
logWarn("GlossaryDefinition delivery failed; path to glossaryFolder not existing: " + relPath, null);
return new NotFoundMediaResource();
}
VFSContainer glossaryFolder = new LocalFolderImpl(glossaryFolderFile);
if (!gIM.isFolderContainingGlossary(glossaryFolder)) {
logWarn("GlossaryDefinition delivery failed; glossaryFolder doesn't contain a valid Glossary: " + glossaryFolder, null);
return new NotFoundMediaResource();
}
String glossaryMainTerm = parts[2];
if (parts.length > 2) {
// this handle / or \ in a term
for (int i = 3; i < parts.length; i++) {
glossaryMainTerm += "/" + parts[i];
}
}
// cut away ".html" if necessary
if (glossaryMainTerm.endsWith(".html")) {
glossaryMainTerm = glossaryMainTerm.substring(0, glossaryMainTerm.length() - 5);
}
glossaryMainTerm = glossaryMainTerm.toLowerCase();
Set<String> alternatives = new HashSet<>();
prepareAlternatives(glossaryMainTerm, alternatives);
// Create a media resource
StringMediaResource resource = new StringMediaResource() {
@Override
public void prepare(HttpServletResponse hres) {
// don't use normal string media headers which prevent caching,
// use standard browser caching based on last modified timestamp
}
};
resource.setLastModified(gIM.getGlossaryLastModifiedTime(glossaryFolder));
resource.setContentType("text/html");
List<GlossaryItem> glossItems = gIM.getGlossaryItemListByVFSItem(glossaryFolder);
GlossaryItem foundItem = null;
for (GlossaryItem glossaryItem : glossItems) {
String item = glossaryItem.getGlossTerm().toLowerCase();
if (alternatives.contains(item)) {
foundItem = glossaryItem;
break;
}
}
if (foundItem == null) {
return new NotFoundMediaResource();
}
StringBuilder sb = new StringBuilder();
sb.append("<dd><dt>").append(foundItem.getGlossTerm()).append("</dt><dl>").append(foundItem.getGlossDef()).append("</dl></dd>");
resource.setData(sb.toString());
resource.setEncoding("utf-8");
if (isLogDebugEnabled())
logDebug("loaded definition for " + glossaryMainTerm, null);
return resource;
}
use of org.olat.core.commons.modules.glossary.GlossaryItemManager in project openolat by klemens.
the class GlossaryManagerImpl method getIndexerDocument.
/**
* Creates a lucene index document for this glossary
*
* @param repositoryEntry
* @param searchResourceContext
* @return Document the index document
*/
@Override
public Document getIndexerDocument(RepositoryEntry repositoryEntry, SearchResourceContext searchResourceContext) {
GlossaryItemManager gIMgr = GlossaryItemManager.getInstance();
VFSContainer glossaryFolder = getGlossaryRootFolder(repositoryEntry.getOlatResource());
VFSLeaf glossaryFile = gIMgr.getGlossaryFile(glossaryFolder);
if (glossaryFile == null) {
return null;
}
String glossaryContent = gIMgr.getGlossaryContent(glossaryFolder);
// strip all html tags
Filter htmlTagsFilter = FilterFactory.getHtmlTagsFilter();
glossaryContent = htmlTagsFilter.filter(glossaryContent);
// create standard olat index document with this data
OlatDocument glossaryDocument = new OlatDocument();
if (repositoryEntry.getInitialAuthor() != null) {
glossaryDocument.setAuthor(repositoryEntry.getInitialAuthor());
}
if (repositoryEntry.getDisplayname() != null) {
glossaryDocument.setTitle(repositoryEntry.getDisplayname());
}
if (repositoryEntry.getDescription() != null) {
glossaryDocument.setDescription(htmlTagsFilter.filter(repositoryEntry.getDescription()));
}
glossaryDocument.setContent(glossaryContent);
glossaryDocument.setCreatedDate(repositoryEntry.getCreationDate());
glossaryDocument.setLastChange(new Date(glossaryFile.getLastModified()));
glossaryDocument.setResourceUrl(searchResourceContext.getResourceUrl());
glossaryDocument.setDocumentType(searchResourceContext.getDocumentType());
glossaryDocument.setCssIcon("o_FileResource-GLOSSARY_icon");
return glossaryDocument.getLuceneDocument();
}
use of org.olat.core.commons.modules.glossary.GlossaryItemManager in project openolat by klemens.
the class GlossaryRegisterSettingsController method formInnerEvent.
/**
* @see org.olat.core.gui.components.form.flexible.impl.FormBasicController#formInnerEvent(org.olat.core.gui.UserRequest, org.olat.core.gui.components.form.flexible.FormItem, org.olat.core.gui.components.form.flexible.impl.FormEvent)
*/
@Override
protected void formInnerEvent(UserRequest ureq, FormItem source, FormEvent event) {
if (source == regOnOff) {
boolean regOnChecked = regOnOff.isSelected(0);
GlossaryItemManager gIM = GlossaryItemManager.getInstance();
Properties glossProps = gIM.getGlossaryConfig(glossaryFolder);
glossProps.put(GlossaryItemManager.REGISTER_ONOFF, String.valueOf(regOnChecked));
gIM.setGlossaryConfig(glossaryFolder, glossProps);
}
}
Aggregations