Search in sources :

Example 36 with OLATRuntimeException

use of org.olat.core.logging.OLATRuntimeException in project OpenOLAT by OpenOLAT.

the class WikiManager method saveWikiPage.

/**
 * persists a wiki page on the filesystem. It moves the recent page and the
 * metadata to the versions folder with the version on the tail and saves new
 * page with metadata to the wiki folder. Does not need to be synchronized as
 * editing is locked on page level by the
 *
 * @see WikiMainController
 * @param ores
 * @param page
 */
public void saveWikiPage(OLATResourceable ores, WikiPage page, boolean incrementVersion, Wiki wiki) {
    // cluster_OK by guido
    VFSContainer versionsContainer = getWikiContainer(ores, VERSION_FOLDER_NAME);
    VFSContainer wikiContentContainer = getWikiContainer(ores, WIKI_RESOURCE_FOLDER_NAME);
    // rename existing content file to version x and copy it to the version
    // container
    VFSItem item = wikiContentContainer.resolve(page.getPageId() + "." + WIKI_FILE_SUFFIX);
    if (item != null && incrementVersion) {
        if (page.getVersion() > 0) {
            versionsContainer.copyFrom(item);
            VFSItem copiedItem = versionsContainer.resolve(page.getPageId() + "." + WIKI_FILE_SUFFIX);
            String fileName = page.getPageId() + "." + WIKI_FILE_SUFFIX + "-" + page.getVersion();
            copiedItem.rename(fileName);
        }
        item.delete();
    }
    // rename existing meta file to version x and copy it to the version
    // container
    item = wikiContentContainer.resolve(page.getPageId() + "." + WIKI_PROPERTIES_SUFFIX);
    if (item != null && incrementVersion) {
        // TODO renaming and coping does not work. Bug?? felix fragen
        if (page.getVersion() > 0) {
            versionsContainer.copyFrom(item);
            VFSItem copiedItem = versionsContainer.resolve(page.getPageId() + "." + WIKI_PROPERTIES_SUFFIX);
            String fileName = page.getPageId() + "." + WIKI_PROPERTIES_SUFFIX + "-" + page.getVersion();
            copiedItem.rename(fileName);
        }
        item.delete();
    }
    // store recent content file
    VFSLeaf leaf = wikiContentContainer.createChildLeaf(page.getPageId() + "." + WIKI_FILE_SUFFIX);
    if (leaf == null)
        throw new AssertException("Tried to save wiki page with id (" + page.getPageId() + ") and Olatresource: " + ores.getResourceableId() + " but page already existed!");
    FileUtils.save(leaf.getOutputStream(false), page.getContent(), "utf-8");
    // store recent properties file
    leaf = wikiContentContainer.createChildLeaf(page.getPageId() + "." + WIKI_PROPERTIES_SUFFIX);
    if (leaf == null)
        throw new AssertException("could not create file for wiki page " + page.getPageId() + ", ores: " + ores.getResourceableTypeName() + ":" + ores.getResourceableId() + ", wikicontainer:" + wikiContentContainer);
    if (incrementVersion)
        page.incrementVersion();
    // update modification time
    if (!page.getContent().equals(""))
        page.setModificationTime(System.currentTimeMillis());
    Properties p = getPageProperties(page);
    try {
        OutputStream os = leaf.getOutputStream(false);
        p.store(os, "wiki page meta properties");
        os.close();
    // if (incrementVersion) page.incrementVersion();
    } catch (IOException e) {
        throw new OLATRuntimeException(WikiManager.class, "failed to save wiki page properties for page with id: " + page.getPageId() + " and olatresource: " + ores.getResourceableId(), e);
    }
    // reset view count of the page
    page.setViewCount(0);
    // update cache to inform all nodes about the change
    if (wikiCache != null) {
        wikiCache.update(OresHelper.createStringRepresenting(ores), wiki);
    }
    if (ThreadLocalUserActivityLogger.getLoggedIdentity() != null) {
        // do logging only for real user
        ThreadLocalUserActivityLogger.log(LearningResourceLoggingAction.LEARNING_RESOURCE_UPDATE, getClass());
    }
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) AssertException(org.olat.core.logging.AssertException) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) VFSContainer(org.olat.core.util.vfs.VFSContainer) OutputStream(java.io.OutputStream) VFSItem(org.olat.core.util.vfs.VFSItem) IOException(java.io.IOException) Properties(java.util.Properties)

Example 37 with OLATRuntimeException

use of org.olat.core.logging.OLATRuntimeException in project OpenOLAT by OpenOLAT.

the class WikiToCPExport method wikiPageToHtml.

protected String wikiPageToHtml(WikiPage page) {
    StringBuilder sb = new StringBuilder();
    sb.append("<html>");
    sb.append("<head>\n");
    sb.append("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\n");
    sb.append("<style type=\"text/css\">img {float:right;padding:10px;}</style>\n");
    // sb.append("<script type=\"text/javascript\" src=\"cp_offline_menu_mat/jsMath/easy/load.js\"></script>\n");
    sb.append("<script type=\"text/javascript\" src=\"cp_offline_menu_mat/wiki.js\"></script>\n");
    sb.append("<script type=\"text/javascript\" src=\"mapping.js\"></script>\n");
    sb.append("<link rel=\"StyleSheet\" href=\"cp_offline_menu_mat/wiki.css\" type=\"text/css\" media=\"screen, print\">\n");
    sb.append("</head>\n");
    sb.append("<body>\n");
    sb.append("<h3>").append(getTranslatedWikiPageName(page)).append("</h3>");
    sb.append("<hr><div id=\"olat-wiki\">");
    try {
        ParserDocument doc = parser.parseHTML(page.getContent());
        sb.append(doc.getContent());
    } catch (Exception e) {
        throw new OLATRuntimeException("error while parsing from wiki to CP. ores:" + ores.getResourceableId(), e);
    }
    sb.append("</div></body></html>");
    return sb.toString();
}
Also used : OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) ParserDocument(org.jamwiki.parser.ParserDocument) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException)

Example 38 with OLATRuntimeException

use of org.olat.core.logging.OLATRuntimeException in project OpenOLAT by OpenOLAT.

the class WikiMarkupRenderer method render.

/**
 * @see org.olat.core.gui.components.ComponentRenderer#render(org.olat.core.gui.render.Renderer,
 *      org.olat.core.gui.render.StringOutput,
 *      org.olat.core.gui.components.Component,
 *      org.olat.core.gui.render.URLBuilder,
 *      org.olat.core.gui.translator.Translator,
 *      org.olat.core.gui.render.RenderResult, java.lang.String[])
 */
@Override
public void render(Renderer renderer, StringOutput sb, Component source, URLBuilder ubu, Translator translator, RenderResult renderResult, String[] args) {
    WikiMarkupComponent wikiComp = (WikiMarkupComponent) source;
    AJAXFlags flags = renderer.getGlobalSettings().getAjaxFlags();
    boolean iframePostEnabled = flags.isIframePostEnabled();
    ParserInput input = new ParserInput();
    input.setWikiUser(null);
    input.setAllowSectionEdit(false);
    input.setDepth(10);
    input.setContext("");
    // input.setTableOfContents(null);
    input.setLocale(new Locale("en"));
    // input.setVirtualWiki(Long.toString(wikiComp.getOres().getResourceableId()));
    input.setTopicName("dummy");
    input.setUserIpAddress("0.0.0.0");
    OlatWikiDataHandler dataHandler = new OlatWikiDataHandler(wikiComp.getOres(), wikiComp.getImageBaseUri());
    input.setDataHandler(dataHandler);
    StringOutput out = new StringOutput(100);
    ubu.buildURI(out, null, null, iframePostEnabled ? AJAXFlags.MODE_TOBGIFRAME : AJAXFlags.MODE_NORMAL);
    String uri = out.toString();
    ParserDocument parsedDoc = null;
    String uniqueId = "o_wiki".concat(wikiComp.getDispatchID());
    try {
        uri = URLDecoder.decode(uri, "utf-8");
        input.setVirtualWiki(uri.substring(1, uri.length() - 1));
        if (iframePostEnabled) {
            String targetUrl = " onclick=\"o_XHREvent(jQuery(this).attr('href'),false,true); return false;\"";
            input.setURLTarget(targetUrl);
        }
        sb.append("<div style=\"min-height:" + wikiComp.getMinHeight() + "px\" id=\"");
        sb.append(uniqueId);
        sb.append("\">");
        JFlexParser parser = new JFlexParser(input);
        parsedDoc = parser.parseHTML(wikiComp.getWikiContent());
    } catch (UnsupportedEncodingException e) {
    // encoding utf-8 should be ok
    } catch (Exception e) {
        throw new OLATRuntimeException(this.getClass(), "error while rendering wiki page with content:" + wikiComp.getWikiContent(), e);
    }
    // Use global js math formatter for latex formulas
    sb.append(Formatter.formatLatexFormulas(parsedDoc.getContent()));
    sb.append("</div>");
    // set targets of media, image and external links to target "_blank"
    sb.append("<script type=\"text/javascript\">/* <![CDATA[ */ ");
    String instanceUrl = Settings.getServerContextPathURI();
    sb.append("changeAnchorTargets('").append(uniqueId).append("','").append(instanceUrl).append("');");
    sb.append("/* ]]> */</script>");
}
Also used : Locale(java.util.Locale) JFlexParser(org.jamwiki.parser.jflex.JFlexParser) AJAXFlags(org.olat.core.gui.control.winmgr.AJAXFlags) ParserInput(org.jamwiki.parser.ParserInput) UnsupportedEncodingException(java.io.UnsupportedEncodingException) StringOutput(org.olat.core.gui.render.StringOutput) ParserDocument(org.jamwiki.parser.ParserDocument) UnsupportedEncodingException(java.io.UnsupportedEncodingException) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException)

Example 39 with OLATRuntimeException

use of org.olat.core.logging.OLATRuntimeException in project OpenOLAT by OpenOLAT.

the class Wiki method assignPropertiesToPage.

public static WikiPage assignPropertiesToPage(VFSLeaf leaf) {
    Properties p = new Properties();
    if (leaf != null) {
        try (InputStream is = leaf.getInputStream()) {
            p.load(is);
        } catch (IOException e) {
            throw new OLATRuntimeException("Wiki page couldn't be read! Pagename:" + leaf.getName(), e);
        }
        String pageName = p.getProperty(WikiManager.PAGENAME);
        if (pageName == null) {
            log.warn("wiki properties page is persent but without content. Name:" + leaf.getName());
            return null;
        }
        String initialPageName = p.getProperty(WikiManager.INITIAL_PAGENAME);
        WikiPage page = new WikiPage(pageName, initialPageName);
        String oldPageNames = p.getProperty(WikiManager.OLD_PAGENAME);
        if (StringHelper.containsNonWhitespace(oldPageNames)) {
            String[] names = oldPageNames.split("[,]");
            if (names.length > 0) {
                page.setOldPageNames(Arrays.asList(names));
            }
        }
        page.setCreationTime(p.getProperty(WikiManager.C_TIME));
        page.setVersion(p.getProperty(WikiManager.VERSION));
        page.setForumKey(p.getProperty(WikiManager.FORUM_KEY));
        page.setInitalAuthor(p.getProperty(WikiManager.INITIAL_AUTHOR));
        page.setModificationTime(p.getProperty(WikiManager.M_TIME));
        page.setModifyAuthor(p.getProperty(WikiManager.MODIFY_AUTHOR));
        page.setViewCount(p.getProperty(WikiManager.VIEW_COUNT));
        page.setUpdateComment(p.getProperty(WikiManager.UPDATE_COMMENT));
        return page;
    } else {
        return new WikiPage("dummy");
    }
}
Also used : OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) InputStream(java.io.InputStream) IOException(java.io.IOException) Properties(java.util.Properties)

Example 40 with OLATRuntimeException

use of org.olat.core.logging.OLATRuntimeException in project OpenOLAT by OpenOLAT.

the class SearchClientProxy method spellCheck.

/**
 * Uses Request/reply mechanism for synchronous operation.
 * @see org.olat.search.service.searcher.OLATSearcher#spellCheck(java.lang.String)
 */
public Set<String> spellCheck(String query) throws ServiceNotAvailableException {
    Session session = null;
    try {
        session = acquireSession();
        TextMessage requestMessage = session.createTextMessage(query);
        Message returnedMessage = doSearchRequest(session, requestMessage);
        if (returnedMessage != null) {
            @SuppressWarnings("unchecked") List<String> spellStringList = (List<String>) ((ObjectMessage) returnedMessage).getObject();
            return new HashSet<String>(spellStringList);
        } else {
            // null returnedMessage
            throw new ServiceNotAvailableException("spellCheck, communication error with JMS - cannot receive messages!!!");
        }
    } catch (JMSException e) {
        throw new ServiceNotAvailableException("spellCheck, communication error with JMS - cannot send messages!!!");
    } catch (ServiceNotAvailableException e) {
        throw e;
    } catch (Throwable th) {
        throw new OLATRuntimeException("ClusteredSearchRequester.spellCheck() error!!!", th);
    } finally {
        releaseSession(session);
    }
}
Also used : ServiceNotAvailableException(org.olat.search.ServiceNotAvailableException) ObjectMessage(javax.jms.ObjectMessage) Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) LinkedList(java.util.LinkedList) List(java.util.List) JMSException(javax.jms.JMSException) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session) HashSet(java.util.HashSet)

Aggregations

OLATRuntimeException (org.olat.core.logging.OLATRuntimeException)268 IOException (java.io.IOException)104 File (java.io.File)50 ModuleConfiguration (org.olat.modules.ModuleConfiguration)26 ArrayList (java.util.ArrayList)22 AssertException (org.olat.core.logging.AssertException)22 FileOutputStream (java.io.FileOutputStream)20 OutputStream (java.io.OutputStream)20 Properties (java.util.Properties)20 FileInputStream (java.io.FileInputStream)18 HashMap (java.util.HashMap)18 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)18 QTIItemObject (org.olat.ims.qti.export.helper.QTIItemObject)18 DefaultElement (org.dom4j.tree.DefaultElement)16 Element (org.jdom.Element)16 InputStream (java.io.InputStream)14 BufferedInputStream (java.io.BufferedInputStream)12 List (java.util.List)12 Document (org.dom4j.Document)12 CPItem (org.olat.ims.cp.objects.CPItem)12