Search in sources :

Example 81 with OLATRuntimeException

use of org.olat.core.logging.OLATRuntimeException in project openolat by klemens.

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 82 with OLATRuntimeException

use of org.olat.core.logging.OLATRuntimeException in project openolat by klemens.

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 83 with OLATRuntimeException

use of org.olat.core.logging.OLATRuntimeException in project openolat by klemens.

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 84 with OLATRuntimeException

use of org.olat.core.logging.OLATRuntimeException in project openolat by klemens.

the class OLATUpgrade_11_0_0 method checkEssay.

private boolean checkEssay(RepositoryEntry testEntry) {
    if (qtiEssayMap.containsKey(testEntry.getKey())) {
        return qtiEssayMap.get(testEntry.getKey()).booleanValue();
    }
    TestFileResource fr = new TestFileResource();
    fr.overrideResourceableId(testEntry.getOlatResource().getResourceableId());
    TransientIdentity pseudoIdentity = new TransientIdentity();
    pseudoIdentity.setName("transient");
    Translator translator = Util.createPackageTranslator(QTIModule.class, Locale.ENGLISH);
    try {
        QTIEditorPackage qtiPackage = new QTIEditorPackageImpl(pseudoIdentity, fr, null, translator);
        if (qtiPackage.getQTIDocument() != null && qtiPackage.getQTIDocument().getAssessment() != null) {
            Assessment ass = qtiPackage.getQTIDocument().getAssessment();
            // Sections with their Items
            List<Section> sections = ass.getSections();
            for (Section section : sections) {
                List<Item> items = section.getItems();
                for (Item item : items) {
                    String ident = item.getIdent();
                    if (ident != null && ident.startsWith("QTIEDIT:ESSAY")) {
                        qtiEssayMap.put(testEntry.getKey(), Boolean.TRUE);
                        return true;
                    }
                }
            }
        }
    } catch (OLATRuntimeException e) {
        log.warn("QTI without content in repository entry: " + testEntry.getKey(), e);
    }
    qtiEssayMap.put(testEntry.getKey(), Boolean.FALSE);
    return false;
}
Also used : TransientIdentity(org.olat.admin.user.imp.TransientIdentity) Item(org.olat.ims.qti.editor.beecom.objects.Item) Translator(org.olat.core.gui.translator.Translator) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) QTIEditorPackageImpl(org.olat.ims.qti.editor.QTIEditorPackageImpl) Assessment(org.olat.ims.qti.editor.beecom.objects.Assessment) TestFileResource(org.olat.ims.qti.fileresource.TestFileResource) QTIEditorPackage(org.olat.ims.qti.editor.QTIEditorPackage) Section(org.olat.ims.qti.editor.beecom.objects.Section)

Example 85 with OLATRuntimeException

use of org.olat.core.logging.OLATRuntimeException in project openolat by klemens.

the class ValidatingVisitor method handleDirties.

/**
 * to be called by Window.java or the AjaxController only!
 * this method is synchronized on the Window instance
 *
 * @return a updateUI-Command or null if there are no dirty components (normally not the case for sync (user-click) request, but often the case
 * for pull request, since nothing has changed yet on the screen.
 */
public Command handleDirties() throws CannotReplaceDOMFragmentException {
    // more accurately, the synchronized is needed when other classes than window call this method.
    synchronized (this) {
        Command com = null;
        boolean isDebugLog = log.isDebug();
        StringBuilder debugMsg = null;
        long start = 0;
        if (isDebugLog) {
            log.debug("Perf-Test: Window.handleDirties started...");
            start = System.currentTimeMillis();
        }
        final List<Component> dirties = new ArrayList<Component>();
        ComponentVisitor dirtyV = new ComponentVisitor() {

            public boolean visit(Component comp, UserRequest ureq) {
                boolean visitChildren = false;
                if (comp == null) {
                    log.warn("Ooops, a component is null");
                } else if (!comp.isVisible()) {
                    // a component just made -visible- still needs to be collected (detected by checking dirty flag)
                    if (comp.isDirty()) {
                        dirties.add(comp);
                        // clear manually here since this component will not be rendered
                        comp.setDirty(false);
                    }
                } else if (comp.isDirty()) {
                    dirties.add(comp);
                } else {
                    // visible and not dirty -> visit children
                    visitChildren = true;
                }
                return visitChildren;
            }
        };
        ComponentTraverser ct = new ComponentTraverser(dirtyV, getContentPane(), false);
        ct.visitAll(null);
        int dCnt = dirties.size();
        if (isDebugLog) {
            long durationVisitAll = System.currentTimeMillis() - start;
            log.debug("Perf-Test: Window.handleDirties after ct.visitAll durationVisitAll=" + durationVisitAll);
            log.debug("Perf-Test: Window.handleDirties dirties.size()=" + dirties.size());
        }
        if (dCnt > 0) {
            // collect the redraw dirties command
            try {
                JSONObject root = new JSONObject();
                root.put("cc", dirties.size());
                root.put("wts", timestamp);
                JSONArray ja = new JSONArray();
                root.put("cps", ja);
                GlobalSettings gsettings = wbackofficeImpl.getGlobalSettings();
                synchronized (render_mutex) {
                    // o_clusterOK by:fj
                    // we let all dirty components render themselves.
                    // not offered (since not usability-useful) is the include of new js-libraries and css-libraries here, since this may invoke a screen reload
                    // which disturbes the user and lets him/her loose the focus and the cursor.
                    AsyncMediaResponsible amr = null;
                    long rstart = 0;
                    if (isDebugLog) {
                        rstart = System.currentTimeMillis();
                        debugMsg = new StringBuilder("update:").append(String.valueOf(dCnt)).append(";");
                    }
                    for (int i = 0; i < dCnt; i++) {
                        Component toRender = dirties.get(i);
                        if (isDebugLog) {
                            log.debug("Perf-Test: Window.handleDirties toRender.getComponentName()=" + toRender.getComponentName());
                            log.debug("Perf-Test: Window.handleDirties toRender=" + toRender);
                        }
                        boolean wasDomR = toRender.isDomReplaceable();
                        if (!wasDomR) {
                            throw new CannotReplaceDOMFragmentException("cannot replace as dom fragment:" + toRender.getComponentName() + " (" + toRender.getClass().getName() + ")," + toRender.getExtendedDebugInfo());
                        }
                        Panel wrapper = new Panel("renderpanel");
                        // to omit <div> around the render helper panel
                        wrapper.setDomReplaceable(false);
                        RenderResult renderResult = null;
                        StringOutput jsol = null;
                        StringOutput hdr = null;
                        StringOutput result = null;
                        try {
                            toRender.setDomReplaceable(false);
                            wrapper.setContent(toRender);
                            String newTimestamp = String.valueOf(timestamp);
                            URLBuilder ubu = new URLBuilder(uriPrefix, getInstanceId(), newTimestamp);
                            renderResult = new RenderResult();
                            // if we have an around-component-interception
                            // set the handler for this render cycle
                            InterceptHandler interceptHandler = wbackofficeImpl.getInterceptHandler();
                            if (interceptHandler != null) {
                                InterceptHandlerInstance dhri = interceptHandler.createInterceptHandlerInstance();
                                renderResult.setInterceptHandlerRenderInstance(dhri);
                            }
                            Renderer fr = Renderer.getInstance(wrapper, null, ubu, renderResult, gsettings);
                            jsol = StringOutputPool.allocStringBuilder(2048);
                            fr.renderBodyOnLoadJSFunctionCall(jsol, toRender);
                            hdr = StringOutputPool.allocStringBuilder(2048);
                            fr.renderHeaderIncludes(hdr, toRender);
                            long pstart = 0;
                            if (isDebugLog) {
                                pstart = System.currentTimeMillis();
                            }
                            result = StringOutputPool.allocStringBuilder(100000);
                            fr.render(toRender, result, null);
                            if (isDebugLog) {
                                long pstop = System.currentTimeMillis();
                                debugMsg.append(toRender.getComponentName()).append(":").append((pstop - pstart));
                                if (i < dCnt - 1)
                                    debugMsg.append(",");
                            }
                        } catch (Exception e) {
                            throw new OLATRuntimeException("Unexpected error ", e);
                        } finally {
                            toRender.setDomReplaceable(true);
                        }
                        if (renderResult.getRenderException() != null) {
                            throw new OLATRuntimeException(Window.class, renderResult.getLogMsg(), renderResult.getRenderException());
                        }
                        AsyncMediaResponsible curAmr = renderResult.getAsyncMediaResponsible();
                        if (curAmr != null) {
                            if (amr != null) {
                                throw new AssertException("can set amr only once in a screen!");
                            } else {
                                amr = curAmr;
                            }
                        }
                        JSONObject jo = new JSONObject();
                        String cid = toRender.getDispatchID();
                        if (Settings.isDebuging()) {
                            // for debugging only
                            jo.put("cname", toRender.getComponentName());
                            jo.put("clisteners", toRender.getListenerInfo());
                            jo.put("hfragsize", result.length());
                        }
                        jo.put("cid", cid);
                        jo.put("cw", toRender.isDomReplacementWrapperRequired());
                        jo.put("cidvis", toRender.isVisible());
                        jo.put("hfrag", StringOutputPool.freePop(result));
                        jo.put("jsol", StringOutputPool.freePop(jsol));
                        jo.put("hdr", StringOutputPool.freePop(hdr));
                        ja.put(jo);
                    }
                    // to null otherwise it possible that e.g. pdf served as following click within a CP component
                    if (amr != null) {
                        setAsyncMediaResponsible(amr);
                    }
                    if (isDebugLog) {
                        long rstop = System.currentTimeMillis();
                        debugMsg.append(";inl_part_render:").append((rstop - rstart));
                        log.debug(debugMsg.toString());
                    }
                }
                com = CommandFactory.createDirtyComponentsCommand();
                com.setSubJSON(root);
                if (isDebugLog) {
                    long durationHandleDirties = System.currentTimeMillis() - start;
                    log.debug("Perf-Test:" + durationHandleDirties);
                }
                return com;
            } catch (JSONException e) {
                throw new AssertException("wrong data put into json object", e);
            }
        }
        if (isDebugLog) {
            long durationHandleDirties = System.currentTimeMillis() - start;
            log.debug("Perf-Test: Window.handleDirties finished 2  durationHandleDirties=" + durationHandleDirties);
        }
        return com;
    }
}
Also used : ComponentVisitor(org.olat.core.util.component.ComponentVisitor) ComponentTraverser(org.olat.core.util.component.ComponentTraverser) ArrayList(java.util.ArrayList) RenderResult(org.olat.core.gui.render.RenderResult) StringOutput(org.olat.core.gui.render.StringOutput) InterceptHandlerInstance(org.olat.core.gui.render.intercept.InterceptHandlerInstance) InterceptHandler(org.olat.core.gui.render.intercept.InterceptHandler) UserRequest(org.olat.core.gui.UserRequest) AssertException(org.olat.core.logging.AssertException) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) GlobalSettings(org.olat.core.gui.GlobalSettings) HistoryPoint(org.olat.core.id.context.HistoryPoint) AssertException(org.olat.core.logging.AssertException) JSONException(org.json.JSONException) InvalidRequestParameterException(org.olat.core.gui.components.form.flexible.impl.InvalidRequestParameterException) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) IOException(java.io.IOException) URLBuilder(org.olat.core.gui.render.URLBuilder) Panel(org.olat.core.gui.components.panel.Panel) AsyncMediaResponsible(org.olat.core.gui.media.AsyncMediaResponsible) JSONObject(org.json.JSONObject) JSCommand(org.olat.core.gui.control.winmgr.JSCommand) Command(org.olat.core.gui.control.winmgr.Command) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) Renderer(org.olat.core.gui.render.Renderer)

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