Search in sources :

Example 6 with Wiki

use of org.olat.modules.wiki.Wiki in project openolat by klemens.

the class WikiArtefactHandler method prefillArtefactAccordingToSource.

/**
 * @see org.olat.portfolio.EPAbstractHandler#prefillArtefactAccordingToSource(org.olat.portfolio.model.artefacts.AbstractArtefact, java.lang.Object)
 */
@Override
public void prefillArtefactAccordingToSource(AbstractArtefact artefact, Object source) {
    super.prefillArtefactAccordingToSource(artefact, source);
    WikiPage page = null;
    OLATResourceable ores = null;
    if (source instanceof OLATResourceable) {
        ores = (OLATResourceable) source;
        // fxdiff: FXOLAT-148 a wiki from a businessgroup needs to be wrapped accordingly!
        if (artefact.getBusinessPath().contains(BusinessGroup.class.getSimpleName())) {
            ores = OresHelper.createOLATResourceableInstance(BusinessGroup.class, ores.getResourceableId());
        }
        Wiki wiki = WikiManager.getInstance().getOrLoadWiki(ores);
        String pageName = getPageName(artefact.getBusinessPath());
        page = wiki.getPage(pageName, true);
    } else if (source instanceof WikiPage) {
        page = (WikiPage) source;
    }
    if (page != null) {
        artefact.setSource(getSourceInfo(artefact.getBusinessPath(), ores));
        artefact.setTitle(page.getPageName());
        artefact.setFulltextContent(page.getContent());
        artefact.setSignature(70);
    }
}
Also used : OLATResourceable(org.olat.core.id.OLATResourceable) BusinessGroup(org.olat.group.BusinessGroup) WikiPage(org.olat.modules.wiki.WikiPage) Wiki(org.olat.modules.wiki.Wiki)

Example 7 with Wiki

use of org.olat.modules.wiki.Wiki in project openolat by klemens.

the class OlatWikiDataHandler method exists.

/**
 * @see org.jamwiki.DataHandler#exists(java.lang.String, java.lang.String)
 */
public boolean exists(String virtualWiki, String topic) {
    if (!StringUtils.hasText(topic)) {
        return false;
    }
    if (PseudoTopicHandler.isPseudoTopic(topic)) {
        return true;
    }
    if (InterWikiHandler.isInterWiki(topic)) {
        return true;
    }
    // try {
    // Utilities.validateTopicName(topic);
    // } catch (WikiException e) {
    // throw new OLATRuntimeException(this.getClass(), "invalid topic name!", e);
    // }
    Wiki wiki = WikiManager.getInstance().getOrLoadWiki(ores);
    if (topic.startsWith(IMAGE_NAMESPACE) || topic.startsWith(MEDIA_NAMESPACE)) {
        return wiki.pageExists(topic);
    }
    String pageId = WikiManager.generatePageId(FilterUtil.normalizeWikiLink(topic));
    return wiki.pageExists(pageId);
}
Also used : Wiki(org.olat.modules.wiki.Wiki)

Example 8 with Wiki

use of org.olat.modules.wiki.Wiki in project OpenOLAT by OpenOLAT.

the class OlatWikiDataHandler method lookupTopic.

/**
 * @see org.jamwiki.DataHandler#lookupTopic(java.lang.String,
 *      java.lang.String, boolean, java.lang.Object)
 */
public Topic lookupTopic(String virtualWiki, String topicName, boolean deleteOK, Object transactionObject) throws Exception {
    String decodedName = null;
    Wiki wiki = WikiManager.getInstance().getOrLoadWiki(ores);
    try {
        decodedName = URLDecoder.decode(topicName, "utf-8");
    } catch (UnsupportedEncodingException e) {
    // 
    }
    if (log.isDebug()) {
        log.debug("page name not normalized: " + topicName);
        log.debug("page name normalized: " + FilterUtil.normalizeWikiLink(topicName));
        try {
            log.debug("page name urldecoded name: " + URLDecoder.decode(topicName, "utf-8"));
            log.debug("page name urldecoded and normalized: " + FilterUtil.normalizeWikiLink(URLDecoder.decode(topicName, "utf-8")));
            log.debug("page name urldecoded normalized and transformed to id: " + wiki.generatePageId(FilterUtil.normalizeWikiLink(decodedName)));
        } catch (UnsupportedEncodingException e) {
        // 
        }
    }
    Topic topic = new Topic();
    if (decodedName.startsWith(IMAGE_NAMESPACE)) {
        String imageName = topicName.substring(IMAGE_NAMESPACE.length());
        if (!wiki.mediaFileExists(imageName))
            return null;
        topic.setName(imageName);
        topic.setTopicType(Topic.TYPE_IMAGE);
        return topic;
    } else if (decodedName.startsWith(MEDIA_NAMESPACE)) {
        String mediaName = topicName.substring(MEDIA_NAMESPACE.length(), topicName.length());
        if (!wiki.mediaFileExists(mediaName))
            return null;
        topic.setName(mediaName);
        topic.setTopicType(Topic.TYPE_FILE);
        return topic;
    }
    if (wiki.pageExists(wiki.generatePageId(FilterUtil.normalizeWikiLink(decodedName)))) {
        topic.setName(topicName);
        return topic;
    }
    return null;
}
Also used : Wiki(org.olat.modules.wiki.Wiki) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Topic(org.jamwiki.model.Topic)

Example 9 with Wiki

use of org.olat.modules.wiki.Wiki in project OpenOLAT by OpenOLAT.

the class WikiArtefactHandler method prefillArtefactAccordingToSource.

/**
 * @see org.olat.portfolio.EPAbstractHandler#prefillArtefactAccordingToSource(org.olat.portfolio.model.artefacts.AbstractArtefact, java.lang.Object)
 */
@Override
public void prefillArtefactAccordingToSource(AbstractArtefact artefact, Object source) {
    super.prefillArtefactAccordingToSource(artefact, source);
    WikiPage page = null;
    OLATResourceable ores = null;
    if (source instanceof OLATResourceable) {
        ores = (OLATResourceable) source;
        // fxdiff: FXOLAT-148 a wiki from a businessgroup needs to be wrapped accordingly!
        if (artefact.getBusinessPath().contains(BusinessGroup.class.getSimpleName())) {
            ores = OresHelper.createOLATResourceableInstance(BusinessGroup.class, ores.getResourceableId());
        }
        Wiki wiki = WikiManager.getInstance().getOrLoadWiki(ores);
        String pageName = getPageName(artefact.getBusinessPath());
        page = wiki.getPage(pageName, true);
    } else if (source instanceof WikiPage) {
        page = (WikiPage) source;
    }
    if (page != null) {
        artefact.setSource(getSourceInfo(artefact.getBusinessPath(), ores));
        artefact.setTitle(page.getPageName());
        artefact.setFulltextContent(page.getContent());
        artefact.setSignature(70);
    }
}
Also used : OLATResourceable(org.olat.core.id.OLATResourceable) BusinessGroup(org.olat.group.BusinessGroup) WikiPage(org.olat.modules.wiki.WikiPage) Wiki(org.olat.modules.wiki.Wiki)

Example 10 with Wiki

use of org.olat.modules.wiki.Wiki in project OpenOLAT by OpenOLAT.

the class WikiCourseNodeIndexer method doIndex.

@Override
public void doIndex(SearchResourceContext repositoryResourceContext, ICourse course, CourseNode courseNode, OlatFullIndexer indexWriter) {
    String repoEntryName = "*name not available*";
    try {
        SearchResourceContext courseNodeResourceContext = createSearchResourceContext(repositoryResourceContext, courseNode, TYPE);
        Document nodeDocument = CourseNodeDocument.createDocument(courseNodeResourceContext, courseNode);
        indexWriter.addDocument(nodeDocument);
        RepositoryEntry repositoryEntry = courseNode.getReferencedRepositoryEntry();
        if (repositoryEntry == null)
            return;
        repoEntryName = repositoryEntry.getDisplayname();
        Wiki wiki = WikiManager.getInstance().getOrLoadWiki(repositoryEntry.getOlatResource());
        // loop over all wiki pages
        List<WikiPage> wikiPageList = wiki.getAllPagesWithContent();
        for (WikiPage wikiPage : wikiPageList) {
            try {
                courseNodeResourceContext.setFilePath(wikiPage.getPageName());
                Document document = WikiPageDocument.createDocument(courseNodeResourceContext, wikiPage);
                indexWriter.addDocument(document);
            } catch (Exception e) {
                log.error("Error indexing wiki page:" + (wikiPage == null ? "null" : wikiPage.getPageName()), e);
            }
        }
    } catch (Exception e) {
        log.error("Error indexing wiki:" + repoEntryName, e);
    }
}
Also used : SearchResourceContext(org.olat.search.service.SearchResourceContext) WikiPage(org.olat.modules.wiki.WikiPage) Wiki(org.olat.modules.wiki.Wiki) RepositoryEntry(org.olat.repository.RepositoryEntry) WikiPageDocument(org.olat.search.service.document.WikiPageDocument) Document(org.apache.lucene.document.Document) CourseNodeDocument(org.olat.search.service.document.CourseNodeDocument)

Aggregations

Wiki (org.olat.modules.wiki.Wiki)14 WikiPage (org.olat.modules.wiki.WikiPage)8 Document (org.apache.lucene.document.Document)6 SearchResourceContext (org.olat.search.service.SearchResourceContext)6 WikiPageDocument (org.olat.search.service.document.WikiPageDocument)6 IOException (java.io.IOException)4 OLATResourceable (org.olat.core.id.OLATResourceable)4 BusinessGroup (org.olat.group.BusinessGroup)4 RepositoryEntry (org.olat.repository.RepositoryEntry)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 Date (java.util.Date)2 Topic (org.jamwiki.model.Topic)2 CollaborationTools (org.olat.collaboration.CollaborationTools)2 AssertException (org.olat.core.logging.AssertException)2 VFSContainer (org.olat.core.util.vfs.VFSContainer)2 CourseNodeDocument (org.olat.search.service.document.CourseNodeDocument)2