Search in sources :

Example 91 with OLATRuntimeException

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

the class QTI21ServiceImpl method storeStateDocument.

private void storeStateDocument(Document stateXml, File sessionFile) {
    XsltSerializationOptions xsltSerializationOptions = new XsltSerializationOptions();
    xsltSerializationOptions.setIndenting(true);
    xsltSerializationOptions.setIncludingXMLDeclaration(false);
    Transformer serializer = XsltStylesheetManager.createSerializer(xsltSerializationOptions);
    try (OutputStream resultStream = new FileOutputStream(sessionFile)) {
        serializer.transform(new DOMSource(stateXml), new StreamResult(resultStream));
    } catch (TransformerException | IOException e) {
        throw new OLATRuntimeException("Unexpected Exception serializing state DOM", e);
    }
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) Transformer(javax.xml.transform.Transformer) StreamResult(javax.xml.transform.stream.StreamResult) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) FileOutputStream(java.io.FileOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) XsltSerializationOptions(uk.ac.ed.ph.jqtiplus.xmlutils.xslt.XsltSerializationOptions) IOException(java.io.IOException) TransformerException(javax.xml.transform.TransformerException)

Example 92 with OLATRuntimeException

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

the class QTI21ServiceImpl method loadFilteredStateDocument.

private Document loadFilteredStateDocument(File sessionFile) {
    try (InputStream in = new FileInputStream(sessionFile)) {
        String xmlContent = IOUtils.toString(in, "UTF-8");
        String filteredContent = FilterFactory.getXMLValidEntityFilter().filter(xmlContent);
        DocumentBuilder documentBuilder = XmlFactories.newDocumentBuilder();
        return documentBuilder.parse(new InputSource(new StringReader(filteredContent)));
    } catch (final Exception e) {
        throw new OLATRuntimeException("Could not parse serialized state XML. This is an internal error as we currently don't expose this data to clients", e);
    }
}
Also used : InputSource(org.xml.sax.InputSource) DocumentBuilder(javax.xml.parsers.DocumentBuilder) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) StringReader(java.io.StringReader) FileInputStream(java.io.FileInputStream) QtiXmlInterpretationException(uk.ac.ed.ph.jqtiplus.reading.QtiXmlInterpretationException) TransformerException(javax.xml.transform.TransformerException) IOException(java.io.IOException) XmlResourceNotFoundException(uk.ac.ed.ph.jqtiplus.xmlutils.XmlResourceNotFoundException) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException)

Example 93 with OLATRuntimeException

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

the class QTIStatisticsResource method getQTIItemConfigs.

/**
 * Copy of QTIArchiveWizardController.getQTIItemConfigs but with all options set
 * to true except for the time column.
 *
 * @param itemList
 * @return
 */
private static final Map<Class<?>, QTIExportItemFormatConfig> getQTIItemConfigs(List<QTIItemObject> itemList) {
    Map<Class<?>, QTIExportItemFormatConfig> itConfigs = new HashMap<>();
    for (Iterator<QTIItemObject> iter = itemList.iterator(); iter.hasNext(); ) {
        QTIItemObject item = iter.next();
        if (item.getItemIdent().startsWith(ItemParser.ITEM_PREFIX_SCQ)) {
            if (itConfigs.get(QTIExportSCQItemFormatConfig.class) == null) {
                QTIExportSCQItemFormatConfig confSCQ = new QTIExportSCQItemFormatConfig(true, true, true, false);
                itConfigs.put(QTIExportSCQItemFormatConfig.class, confSCQ);
            }
        } else if (item.getItemIdent().startsWith(ItemParser.ITEM_PREFIX_MCQ)) {
            if (itConfigs.get(QTIExportMCQItemFormatConfig.class) == null) {
                QTIExportMCQItemFormatConfig confMCQ = new QTIExportMCQItemFormatConfig(true, true, true, false);
                itConfigs.put(QTIExportMCQItemFormatConfig.class, confMCQ);
            }
        } else if (item.getItemIdent().startsWith(ItemParser.ITEM_PREFIX_KPRIM)) {
            if (itConfigs.get(QTIExportKPRIMItemFormatConfig.class) == null) {
                QTIExportKPRIMItemFormatConfig confKPRIM = new QTIExportKPRIMItemFormatConfig(true, true, true, false);
                itConfigs.put(QTIExportKPRIMItemFormatConfig.class, confKPRIM);
            }
        } else if (item.getItemIdent().startsWith(ItemParser.ITEM_PREFIX_ESSAY)) {
            if (itConfigs.get(QTIExportEssayItemFormatConfig.class) == null) {
                QTIExportEssayItemFormatConfig confEssay = new QTIExportEssayItemFormatConfig(true, false);
                itConfigs.put(QTIExportEssayItemFormatConfig.class, confEssay);
            }
        } else if (item.getItemIdent().startsWith(ItemParser.ITEM_PREFIX_FIB)) {
            if (itConfigs.get(QTIExportFIBItemFormatConfig.class) == null) {
                QTIExportFIBItemFormatConfig confFIB = new QTIExportFIBItemFormatConfig(true, true, false);
                itConfigs.put(QTIExportFIBItemFormatConfig.class, confFIB);
            }
        } else // if cannot find the type via the ItemParser, look for the QTIItemObject type
        if (item.getItemType().equals(QTIItemObject.TYPE.A)) {
            QTIExportEssayItemFormatConfig confEssay = new QTIExportEssayItemFormatConfig(true, false);
            itConfigs.put(QTIExportEssayItemFormatConfig.class, confEssay);
        } else if (item.getItemType().equals(QTIItemObject.TYPE.R)) {
            QTIExportSCQItemFormatConfig confSCQ = new QTIExportSCQItemFormatConfig(true, true, true, false);
            itConfigs.put(QTIExportSCQItemFormatConfig.class, confSCQ);
        } else if (item.getItemType().equals(QTIItemObject.TYPE.C)) {
            QTIExportMCQItemFormatConfig confMCQ = new QTIExportMCQItemFormatConfig(true, true, true, false);
            itConfigs.put(QTIExportMCQItemFormatConfig.class, confMCQ);
        } else if (item.getItemType().equals(QTIItemObject.TYPE.B)) {
            QTIExportFIBItemFormatConfig confFIB = new QTIExportFIBItemFormatConfig(true, true, false);
            itConfigs.put(QTIExportFIBItemFormatConfig.class, confFIB);
        } else {
            throw new OLATRuntimeException(null, "Can not resolve QTIItem type", null);
        }
    }
    return itConfigs;
}
Also used : QTIExportEssayItemFormatConfig(org.olat.ims.qti.export.QTIExportEssayItemFormatConfig) QTIExportMCQItemFormatConfig(org.olat.ims.qti.export.QTIExportMCQItemFormatConfig) HashMap(java.util.HashMap) QTIItemObject(org.olat.ims.qti.export.helper.QTIItemObject) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) QTIExportSCQItemFormatConfig(org.olat.ims.qti.export.QTIExportSCQItemFormatConfig) QTIExportKPRIMItemFormatConfig(org.olat.ims.qti.export.QTIExportKPRIMItemFormatConfig) QTIExportItemFormatConfig(org.olat.ims.qti.export.QTIExportItemFormatConfig) QTIExportFIBItemFormatConfig(org.olat.ims.qti.export.QTIExportFIBItemFormatConfig)

Example 94 with OLATRuntimeException

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

the class CoreSpringFactory method getBean.

/**
 * @param beanName
 *            The bean name to check for. Be sure the bean does exist,
 *            otherwise an NoSuchBeanDefinitionException will be thrown
 * @return The bean
 */
public static Object getBean(Class<?> interfaceName) {
    ApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(CoreSpringFactory.servletContext);
    Map<String, ?> m = context.getBeansOfType(interfaceName);
    if (m.size() > 1) {
        // more than one bean found -> excecption
        throw new OLATRuntimeException("found more than one bean for: " + interfaceName + ". Calling this method should only find one bean!", null);
    } else if (m.size() == 1) {
        return new ArrayList<Object>(m.values()).get(0);
    }
    // fallback for beans named like the fully qualified path (legacy)
    Object o = context.getBean(interfaceName.getName());
    return o;
}
Also used : WebApplicationContext(org.springframework.web.context.WebApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) ArrayList(java.util.ArrayList)

Example 95 with OLATRuntimeException

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

the class VelocityHelper method merge.

/**
 * @param template e.g. org/olat/demo/_content/index.html
 * @param c the context
 * @param theme the theme e.g. "accessibility" or "printing". may be null if the default theme ("") should be taken
 * @return String the rendered template
 */
private void merge(String template, Context c, Writer wOut, String theme) {
    try {
        Template vtemplate = null;
        if (isLogDebugEnabled())
            logDebug("Merging template::" + template + " for theme::" + theme, null);
        if (theme != null) {
            // try the theme first, if resource not found exception, fallback to normal resource.
            // e.g. try /_accessibility/index.html first, if not found, try /index.html.
            // this allows for themes to only provide the delta to the default templates
            // todo we could avoid those string operations, if the performance gain is measureable
            int latestSlash = template.lastIndexOf('/');
            StringBuilder sb = new StringBuilder(template.substring(0, latestSlash));
            sb.append("/_").append(theme).append("/").append(template.substring(latestSlash + 1));
            String themedTemplatePath = sb.toString();
            // check cache
            boolean notFound = resourcesNotFound.contains(themedTemplatePath);
            if (!notFound) {
                // never tried before -> try to load it
                if (!ve.resourceExists(themedTemplatePath)) {
                    // this will happen once for each theme when a resource does not exist in its themed variant but only in the default theme.
                    if (!Settings.isDebuging()) {
                        resourcesNotFound.add(themedTemplatePath);
                    }
                // for debugging, allow introduction of themed files without restarting the application
                } else {
                    // template exists -> load it
                    vtemplate = ve.getTemplate(themedTemplatePath, VelocityModule.getInputEncoding());
                }
            }
            // if not found, fallback to standard
            if (vtemplate == null) {
                vtemplate = ve.getTemplate(template, VelocityModule.getInputEncoding());
            }
        } else {
            // no theme, load the standard template
            vtemplate = ve.getTemplate(template, VelocityModule.getInputEncoding());
        }
        vtemplate.merge(c, wOut);
    } catch (MethodInvocationException me) {
        throw new OLATRuntimeException(VelocityHelper.class, "MethodInvocationException occured while merging template: methName:" + me.getMethodName() + ", refName:" + me.getReferenceName(), me.getWrappedThrowable());
    } catch (Exception e) {
        throw new OLATRuntimeException(VelocityHelper.class, "exception occured while merging template: " + e.getMessage(), e);
    }
}
Also used : OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) MethodInvocationException(org.apache.velocity.exception.MethodInvocationException) AssertException(org.olat.core.logging.AssertException) MethodInvocationException(org.apache.velocity.exception.MethodInvocationException) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) Template(org.apache.velocity.Template)

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