use of org.olat.ims.qti21.model.xml.OnyxToQtiWorksHandler in project OpenOLAT by OpenOLAT.
the class CopyAndConvertVisitor method convertXmlFile.
/**
* Convert the XML files, assessmentItem or assessmentTest
*
* @param inputFile
* @param outputFile
*/
public boolean convertXmlFile(Path inputFile, Path outputFile) {
try {
boolean validated = true;
QTI21Infos fileInfos = scanFile(inputFile);
// inherit from test if needed
if (fileInfos.getEditor() == null && infos.getEditor() != null) {
fileInfos.setEditor(infos.getEditor());
fileInfos.setVersion(infos.getVersion());
}
if (onyx38Family(fileInfos)) {
validated = convertXmlFile(inputFile, outputFile, fileInfos.getType(), new HandlerProvider() {
@Override
public DefaultHandler2 create(XMLStreamWriter xtw) {
return new Onyx38ToQtiWorksHandler(xtw);
}
});
} else if (onyxWebFamily(fileInfos)) {
validated = convertXmlFile(inputFile, outputFile, fileInfos.getType(), new HandlerProvider() {
@Override
public DefaultHandler2 create(XMLStreamWriter xtw) {
return new OnyxToQtiWorksHandler(xtw, infos);
}
});
if (validated && fileInfos.getType() == InputType.assessmentItem) {
// check templateVariables
checkAssessmentItem(outputFile);
}
} else {
Files.copy(inputFile, outputFile, StandardCopyOption.REPLACE_EXISTING);
}
return validated;
} catch (IOException | FactoryConfigurationError e) {
log.error("", e);
return false;
}
}
use of org.olat.ims.qti21.model.xml.OnyxToQtiWorksHandler in project openolat by klemens.
the class QTI21ImportProcessor method convertXmlFile.
private void convertXmlFile(Path inputFile, Path outputFile, QTI21Infos infos) {
try (InputStream in = Files.newInputStream(inputFile);
Writer out = Files.newBufferedWriter(outputFile, Charset.forName("UTF-8"))) {
XMLOutputFactory xof = XMLOutputFactory.newInstance();
XMLStreamWriter xtw = xof.createXMLStreamWriter(out);
SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser();
OnyxToQtiWorksHandler myHandler = new OnyxToQtiWorksHandler(xtw, infos);
saxParser.setProperty("http://xml.org/sax/properties/lexical-handler", myHandler);
saxParser.parse(in, myHandler);
} catch (Exception e) {
log.error("", e);
}
}
use of org.olat.ims.qti21.model.xml.OnyxToQtiWorksHandler in project openolat by klemens.
the class CopyAndConvertVisitor method convertXmlFile.
/**
* Convert the XML files, assessmentItem or assessmentTest
*
* @param inputFile
* @param outputFile
*/
public boolean convertXmlFile(Path inputFile, Path outputFile) {
try {
boolean validated = true;
QTI21Infos fileInfos = scanFile(inputFile);
// inherit from test if needed
if (fileInfos.getEditor() == null && infos.getEditor() != null) {
fileInfos.setEditor(infos.getEditor());
fileInfos.setVersion(infos.getVersion());
}
if (onyx38Family(fileInfos)) {
validated = convertXmlFile(inputFile, outputFile, fileInfos.getType(), new HandlerProvider() {
@Override
public DefaultHandler2 create(XMLStreamWriter xtw) {
return new Onyx38ToQtiWorksHandler(xtw);
}
});
} else if (onyxWebFamily(fileInfos)) {
validated = convertXmlFile(inputFile, outputFile, fileInfos.getType(), new HandlerProvider() {
@Override
public DefaultHandler2 create(XMLStreamWriter xtw) {
return new OnyxToQtiWorksHandler(xtw, infos);
}
});
if (validated && fileInfos.getType() == InputType.assessmentItem) {
// check templateVariables
checkAssessmentItem(outputFile);
}
} else {
Files.copy(inputFile, outputFile, StandardCopyOption.REPLACE_EXISTING);
}
return validated;
} catch (IOException | FactoryConfigurationError e) {
log.error("", e);
return false;
}
}
use of org.olat.ims.qti21.model.xml.OnyxToQtiWorksHandler in project OpenOLAT by OpenOLAT.
the class QTI21ImportProcessor method convertXmlFile.
private void convertXmlFile(Path inputFile, Path outputFile, QTI21Infos infos) {
try (InputStream in = Files.newInputStream(inputFile);
Writer out = Files.newBufferedWriter(outputFile, Charset.forName("UTF-8"))) {
XMLOutputFactory xof = XMLOutputFactory.newInstance();
XMLStreamWriter xtw = xof.createXMLStreamWriter(out);
SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser();
OnyxToQtiWorksHandler myHandler = new OnyxToQtiWorksHandler(xtw, infos);
saxParser.setProperty("http://xml.org/sax/properties/lexical-handler", myHandler);
saxParser.parse(in, myHandler);
} catch (Exception e) {
log.error("", e);
}
}
Aggregations