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);
}
}
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);
}
}
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;
}
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;
}
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);
}
}
Aggregations