Search in sources :

Example 1 with GlossaryItemManager

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;
}
Also used : NotFoundMediaResource(org.olat.core.gui.media.NotFoundMediaResource) VFSContainer(org.olat.core.util.vfs.VFSContainer) GlossaryItemManager(org.olat.core.commons.modules.glossary.GlossaryItemManager) HttpServletResponse(javax.servlet.http.HttpServletResponse) StringMediaResource(org.olat.core.gui.media.StringMediaResource) File(java.io.File) LocalFolderImpl(org.olat.core.util.vfs.LocalFolderImpl)

Example 2 with GlossaryItemManager

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);
    }
}
Also used : GlossaryItemManager(org.olat.core.commons.modules.glossary.GlossaryItemManager) Properties(java.util.Properties)

Example 3 with GlossaryItemManager

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;
}
Also used : NotFoundMediaResource(org.olat.core.gui.media.NotFoundMediaResource) VFSContainer(org.olat.core.util.vfs.VFSContainer) HttpServletResponse(javax.servlet.http.HttpServletResponse) LocalFolderImpl(org.olat.core.util.vfs.LocalFolderImpl) GlossaryItemManager(org.olat.core.commons.modules.glossary.GlossaryItemManager) StringMediaResource(org.olat.core.gui.media.StringMediaResource) File(java.io.File) HashSet(java.util.HashSet) GlossaryItem(org.olat.core.commons.modules.glossary.GlossaryItem)

Example 4 with GlossaryItemManager

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();
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) OlatDocument(org.olat.search.model.OlatDocument) Filter(org.olat.core.util.filter.Filter) VFSContainer(org.olat.core.util.vfs.VFSContainer) GlossaryItemManager(org.olat.core.commons.modules.glossary.GlossaryItemManager) Date(java.util.Date)

Example 5 with GlossaryItemManager

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);
    }
}
Also used : GlossaryItemManager(org.olat.core.commons.modules.glossary.GlossaryItemManager) Properties(java.util.Properties)

Aggregations

GlossaryItemManager (org.olat.core.commons.modules.glossary.GlossaryItemManager)10 VFSContainer (org.olat.core.util.vfs.VFSContainer)6 File (java.io.File)4 Properties (java.util.Properties)4 HttpServletResponse (javax.servlet.http.HttpServletResponse)4 NotFoundMediaResource (org.olat.core.gui.media.NotFoundMediaResource)4 StringMediaResource (org.olat.core.gui.media.StringMediaResource)4 LocalFolderImpl (org.olat.core.util.vfs.LocalFolderImpl)4 Date (java.util.Date)2 HashSet (java.util.HashSet)2 GlossaryItem (org.olat.core.commons.modules.glossary.GlossaryItem)2 Filter (org.olat.core.util.filter.Filter)2 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)2 OlatDocument (org.olat.search.model.OlatDocument)2