use of org.olat.core.util.openxml.OpenXMLDocumentWriter in project openolat by klemens.
the class QTI12And21PoolWordExport method exportItems.
private void exportItems(List<QuestionItemFull> fullItems, OutputStream out, boolean withResponses) {
ZipOutputStream zout = null;
try {
OpenXMLDocument document = new OpenXMLDocument();
document.setDocumentHeader("");
Translator qti12Translator = Util.createPackageTranslator(QTIWordExport.class, locale);
Translator translator = Util.createPackageTranslator(AssessmentTestDisplayController.class, locale, Util.createPackageTranslator(AssessmentTestComposerController.class, locale, qti12Translator));
AssessmentHtmlBuilder htmlBuilder = new AssessmentHtmlBuilder();
for (Iterator<QuestionItemFull> itemIt = fullItems.iterator(); itemIt.hasNext(); ) {
QuestionItemFull fullItem = itemIt.next();
if (QTIConstants.QTI_12_FORMAT.equals(fullItem.getFormat())) {
String dir = fullItem.getDirectory();
VFSContainer container = qpoolFileStorage.getContainer(dir);
document.setMediaContainer(container);
VFSItem rootItem = container.resolve(fullItem.getRootFilename());
Item item = QTIEditHelper.readItemXml((VFSLeaf) rootItem);
if (item.isAlient()) {
QTIWordExport.renderAlienItem(item, document, translator);
} else {
QTIWordExport.renderItem(item, document, withResponses, translator);
}
} else {
File resourceDirectory = qpoolService.getRootDirectory(fullItem);
VFSContainer resourceContainer = qpoolService.getRootContainer(fullItem);
document.setMediaContainer(resourceContainer);
File resourceFile = qpoolService.getRootFile(fullItem);
URI assessmentItemUri = resourceFile.toURI();
ResolvedAssessmentItem resolvedAssessmentItem = qtiService.loadAndResolveAssessmentItem(assessmentItemUri, resourceDirectory);
AssessmentItem item = resolvedAssessmentItem.getItemLookup().extractIfSuccessful();
QTI21WordExport.renderAssessmentItem(item, resourceFile, resourceDirectory, document, withResponses, translator, htmlBuilder);
}
if (itemIt.hasNext()) {
document.appendPageBreak();
}
}
zout = new ZipOutputStream(out);
zout.setLevel(9);
OpenXMLDocumentWriter writer = new OpenXMLDocumentWriter();
writer.createDocument(zout, document);
} catch (Exception e) {
log.error("", e);
} finally {
if (zout != null) {
try {
zout.finish();
} catch (IOException e) {
log.error("", e);
}
}
}
}
use of org.olat.core.util.openxml.OpenXMLDocumentWriter in project openolat by klemens.
the class QTI21WordExport method exportTest.
private void exportTest(AssessmentTest assessmentTest, String header, ZipOutputStream out, boolean withResponses) {
try (ShieldOutputStream sout = new ShieldOutputStream(out);
ZipOutputStream zout = new ZipOutputStream(sout)) {
zout.setLevel(9);
OpenXMLDocument document = new OpenXMLDocument();
document.setMediaContainer(mediaContainer);
document.setDocumentHeader(header);
Translator translator = Util.createPackageTranslator(AssessmentTestDisplayController.class, locale, Util.createPackageTranslator(AssessmentTestComposerController.class, locale));
renderAssessmentTest(assessmentTest, document, translator);
for (TestPart testPart : assessmentTest.getChildAbstractParts()) {
List<AssessmentSection> assessmentSections = testPart.getAssessmentSections();
for (AssessmentSection assessmentSection : assessmentSections) {
renderAssessmentSection(assessmentSection, document, withResponses, translator);
}
}
OpenXMLDocumentWriter writer = new OpenXMLDocumentWriter();
writer.createDocument(zout, document);
} catch (Exception e) {
log.error("", e);
}
}
use of org.olat.core.util.openxml.OpenXMLDocumentWriter in project openolat by klemens.
the class QTIWordExport method exportTest.
private void exportTest(String header, OutputStream out, boolean withResponses) {
ZipOutputStream zout = null;
try {
OpenXMLDocument document = new OpenXMLDocument();
document.setMediaContainer(mediaContainer);
document.setDocumentHeader(header);
Translator translator = Util.createPackageTranslator(QTIWordExport.class, locale, Util.createPackageTranslator(QTIEditorMainController.class, locale));
Assessment assessment = rootNode.getAssessment();
renderAssessment(assessment, document, translator);
for (Section section : assessment.getSections()) {
renderSection(section, document);
List<Item> items = section.getItems();
for (Iterator<Item> itemIt = items.iterator(); itemIt.hasNext(); ) {
Item item = itemIt.next();
if (item.isAlient()) {
renderAlienItem(item, document, translator);
} else {
renderItem(item, document, withResponses, translator);
}
if (itemIt.hasNext()) {
document.appendPageBreak();
}
}
}
zout = new ZipOutputStream(out);
zout.setLevel(9);
OpenXMLDocumentWriter writer = new OpenXMLDocumentWriter();
writer.createDocument(zout, document);
} catch (Exception e) {
log.error("", e);
} finally {
if (zout != null) {
try {
zout.finish();
} catch (IOException e) {
log.error("", e);
}
}
}
}
use of org.olat.core.util.openxml.OpenXMLDocumentWriter in project OpenOLAT by OpenOLAT.
the class ForumDownloadResource method exportForum.
private Map<File, DocReference> exportForum(OutputStream out) {
try (ZipOutputStream zout = new ZipOutputStream(out)) {
zout.setLevel(9);
ForumOpenXMLFormatter openXmlFormatter = new ForumOpenXMLFormatter(mediaContainer, locale);
if (topMessageId != null) {
ForumArchiveManager.getInstance().applyFormatterForOneThread(openXmlFormatter, forum.getKey(), topMessageId);
} else {
ForumArchiveManager.getInstance().applyFormatter(openXmlFormatter, forum.getKey(), foCallback);
}
OpenXMLDocumentWriter writer = new OpenXMLDocumentWriter();
writer.createDocument(zout, openXmlFormatter.getOpenXMLDocument());
return openXmlFormatter.getAttachments();
} catch (Exception e) {
log.error("", e);
return null;
}
}
use of org.olat.core.util.openxml.OpenXMLDocumentWriter in project OpenOLAT by OpenOLAT.
the class QTIWordExport method exportTest.
private void exportTest(String header, OutputStream out, boolean withResponses) {
ZipOutputStream zout = null;
try {
OpenXMLDocument document = new OpenXMLDocument();
document.setMediaContainer(mediaContainer);
document.setDocumentHeader(header);
Translator translator = Util.createPackageTranslator(QTIWordExport.class, locale, Util.createPackageTranslator(QTIEditorMainController.class, locale));
Assessment assessment = rootNode.getAssessment();
renderAssessment(assessment, document, translator);
for (Section section : assessment.getSections()) {
renderSection(section, document);
List<Item> items = section.getItems();
for (Iterator<Item> itemIt = items.iterator(); itemIt.hasNext(); ) {
Item item = itemIt.next();
if (item.isAlient()) {
renderAlienItem(item, document, translator);
} else {
renderItem(item, document, withResponses, translator);
}
if (itemIt.hasNext()) {
document.appendPageBreak();
}
}
}
zout = new ZipOutputStream(out);
zout.setLevel(9);
OpenXMLDocumentWriter writer = new OpenXMLDocumentWriter();
writer.createDocument(zout, document);
} catch (Exception e) {
log.error("", e);
} finally {
if (zout != null) {
try {
zout.finish();
} catch (IOException e) {
log.error("", e);
}
}
}
}
Aggregations