Search in sources :

Example 1 with Onyx38ToQtiWorksHandler

use of org.olat.ims.qti21.model.xml.Onyx38ToQtiWorksHandler 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;
    }
}
Also used : Onyx38ToQtiWorksHandler(org.olat.ims.qti21.model.xml.Onyx38ToQtiWorksHandler) DefaultHandler2(org.xml.sax.ext.DefaultHandler2) QTI21Infos(org.olat.ims.qti21.model.xml.QTI21Infos) OnyxToQtiWorksHandler(org.olat.ims.qti21.model.xml.OnyxToQtiWorksHandler) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) IOException(java.io.IOException) FactoryConfigurationError(javax.xml.stream.FactoryConfigurationError)

Example 2 with Onyx38ToQtiWorksHandler

use of org.olat.ims.qti21.model.xml.Onyx38ToQtiWorksHandler 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;
    }
}
Also used : Onyx38ToQtiWorksHandler(org.olat.ims.qti21.model.xml.Onyx38ToQtiWorksHandler) DefaultHandler2(org.xml.sax.ext.DefaultHandler2) QTI21Infos(org.olat.ims.qti21.model.xml.QTI21Infos) OnyxToQtiWorksHandler(org.olat.ims.qti21.model.xml.OnyxToQtiWorksHandler) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) IOException(java.io.IOException) FactoryConfigurationError(javax.xml.stream.FactoryConfigurationError)

Aggregations

IOException (java.io.IOException)2 FactoryConfigurationError (javax.xml.stream.FactoryConfigurationError)2 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)2 Onyx38ToQtiWorksHandler (org.olat.ims.qti21.model.xml.Onyx38ToQtiWorksHandler)2 OnyxToQtiWorksHandler (org.olat.ims.qti21.model.xml.OnyxToQtiWorksHandler)2 QTI21Infos (org.olat.ims.qti21.model.xml.QTI21Infos)2 DefaultHandler2 (org.xml.sax.ext.DefaultHandler2)2