Search in sources :

Example 11 with Wiki

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

the class WikiCourseNode method archiveNodeData.

@Override
public boolean archiveNodeData(Locale locale, ICourse course, ArchiveOptions options, ZipOutputStream exportStream, String charset) {
    String repoRef = (String) getModuleConfiguration().get("reporef");
    OLATResourceable ores = RepositoryManager.getInstance().lookupRepositoryEntryBySoftkey(repoRef, true).getOlatResource();
    Wiki wiki = WikiManager.getInstance().getOrLoadWiki(ores);
    if (wiki.getAllPagesWithContent().isEmpty()) {
        return false;
    }
    // OK, there is something to archive
    String currentPath = "wiki_" + StringHelper.transformDisplayNameToFileSystemName(getShortName()) + "_" + Formatter.formatDatetimeFilesystemSave(new Date(System.currentTimeMillis()));
    VFSContainer container = WikiManager.getInstance().getWikiContainer(ores, WikiManager.WIKI_RESOURCE_FOLDER_NAME);
    if (container != null) {
        // the container could be null if the wiki is an old empty one - so nothing to archive
        try {
            VFSContainer parent = container.getParentContainer();
            WikiToZipUtils.wikiToZip(parent, currentPath, exportStream);
        } catch (IOException e) {
            log.error("", e);
        }
    }
    return true;
}
Also used : OLATResourceable(org.olat.core.id.OLATResourceable) VFSContainer(org.olat.core.util.vfs.VFSContainer) Wiki(org.olat.modules.wiki.Wiki) IOException(java.io.IOException) Date(java.util.Date)

Example 12 with Wiki

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

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 13 with Wiki

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

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)

Example 14 with Wiki

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

the class WikiCourseNode method archiveNodeData.

@Override
public boolean archiveNodeData(Locale locale, ICourse course, ArchiveOptions options, ZipOutputStream exportStream, String charset) {
    String repoRef = (String) getModuleConfiguration().get("reporef");
    OLATResourceable ores = RepositoryManager.getInstance().lookupRepositoryEntryBySoftkey(repoRef, true).getOlatResource();
    Wiki wiki = WikiManager.getInstance().getOrLoadWiki(ores);
    if (wiki.getAllPagesWithContent().isEmpty()) {
        return false;
    }
    // OK, there is something to archive
    String currentPath = "wiki_" + StringHelper.transformDisplayNameToFileSystemName(getShortName()) + "_" + Formatter.formatDatetimeFilesystemSave(new Date(System.currentTimeMillis()));
    VFSContainer container = WikiManager.getInstance().getWikiContainer(ores, WikiManager.WIKI_RESOURCE_FOLDER_NAME);
    if (container != null) {
        // the container could be null if the wiki is an old empty one - so nothing to archive
        try {
            VFSContainer parent = container.getParentContainer();
            WikiToZipUtils.wikiToZip(parent, currentPath, exportStream);
        } catch (IOException e) {
            log.error("", e);
        }
    }
    return true;
}
Also used : OLATResourceable(org.olat.core.id.OLATResourceable) VFSContainer(org.olat.core.util.vfs.VFSContainer) Wiki(org.olat.modules.wiki.Wiki) IOException(java.io.IOException) Date(java.util.Date)

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