Search in sources :

Example 6 with DocumentFactory

use of org.dom4j.DocumentFactory in project OpenOLAT by OpenOLAT.

the class QTIEditHelper method itemToXml.

public static Document itemToXml(Item qtiItem) {
    try {
        DocumentFactory df = DocumentFactory.getInstance();
        Document doc = df.createDocument();
        doc.addDocType(QTIConstants.XML_DOCUMENT_ROOT, null, QTIConstants.XML_DOCUMENT_DTD);
        Element questestinteropEl = df.createElement(QTIDocument.DOCUMENT_ROOT);
        doc.setRootElement(questestinteropEl);
        qtiItem.addToElement(questestinteropEl);
        return doc;
    } catch (Exception e) {
        log.error("", e);
        return null;
    }
}
Also used : DocumentFactory(org.dom4j.DocumentFactory) Element(org.dom4j.Element) Document(org.dom4j.Document) QTIDocument(org.olat.ims.qti.editor.beecom.objects.QTIDocument) IOException(java.io.IOException)

Example 7 with DocumentFactory

use of org.dom4j.DocumentFactory in project openolat by klemens.

the class QTIExportProcessor method createSectionBasedAssessment.

private Element createSectionBasedAssessment(String title) {
    DocumentFactory df = DocumentFactory.getInstance();
    Document doc = df.createDocument();
    doc.addDocType(QTIConstants.XML_DOCUMENT_ROOT, null, QTIConstants.XML_DOCUMENT_DTD);
    /*
		<questestinterop>
  		<assessment ident="frentix_9_87230240084930" title="SR Test">
		 */
    Element questestinterop = doc.addElement(QTIConstants.XML_DOCUMENT_ROOT);
    Element assessment = questestinterop.addElement("assessment");
    assessment.addAttribute("ident", CodeHelper.getGlobalForeverUniqueID());
    assessment.addAttribute("title", title);
    // metadata
    /*
		<qtimetadata>
      	<qtimetadatafield>
        <fieldlabel>qmd_assessmenttype</fieldlabel>
        <fieldentry>Assessment</fieldentry>
      </qtimetadatafield>
    </qtimetadata>
		*/
    Element qtimetadata = assessment.addElement("qtimetadata");
    addMetadataField("qmd_assessmenttype", "Assessment", qtimetadata);
    // section
    /*
		<section ident="frentix_9_87230240084931" title="Section">
    	<selection_ordering>
      	<selection/>
      	<order order_type="Sequential"/>
    	</selection_ordering>
    */
    Element section = assessment.addElement("section");
    section.addAttribute("ident", CodeHelper.getGlobalForeverUniqueID());
    section.addAttribute("title", "Section");
    Element selectionOrdering = section.addElement("selection_ordering");
    selectionOrdering.addElement("selection");
    Element order = selectionOrdering.addElement("order");
    order.addAttribute("order_type", "Sequential");
    return section;
}
Also used : DocumentFactory(org.dom4j.DocumentFactory) Element(org.dom4j.Element) Document(org.dom4j.Document)

Example 8 with DocumentFactory

use of org.dom4j.DocumentFactory in project openolat by klemens.

the class QTIImportProcessor method processAssessmentFiles.

protected void processAssessmentFiles(QuestionItemImpl item, ItemInfos itemInfos) {
    // a package with an item
    String dir = item.getDirectory();
    String rootFilename = item.getRootFilename();
    VFSContainer container = qpoolFileStorage.getContainer(dir);
    VFSLeaf endFile = container.createChildLeaf(rootFilename);
    // embed in <questestinterop>
    DocumentFactory df = DocumentFactory.getInstance();
    Document itemDoc = df.createDocument();
    Element questestinteropEl = df.createElement(QTIDocument.DOCUMENT_ROOT);
    itemDoc.setRootElement(questestinteropEl);
    Element deepClone = (Element) itemInfos.getItemEl().clone();
    questestinteropEl.add(deepClone);
    // write
    try {
        OutputStream os = endFile.getOutputStream(false);
        ;
        XMLWriter xw = new XMLWriter(os, new OutputFormat("  ", true));
        xw.write(itemDoc.getRootElement());
        xw.close();
        os.close();
    } catch (IOException e) {
        log.error("", e);
    }
    // there perhaps some other materials
    if (importedFilename.toLowerCase().endsWith(".zip")) {
        processAssessmentMaterials(deepClone, container);
    }
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) DocumentFactory(org.dom4j.DocumentFactory) VFSContainer(org.olat.core.util.vfs.VFSContainer) Element(org.dom4j.Element) BufferedOutputStream(java.io.BufferedOutputStream) OutputStream(java.io.OutputStream) OutputFormat(org.dom4j.io.OutputFormat) IOException(java.io.IOException) Document(org.dom4j.Document) QTIDocument(org.olat.ims.qti.editor.beecom.objects.QTIDocument) XMLWriter(org.dom4j.io.XMLWriter)

Example 9 with DocumentFactory

use of org.dom4j.DocumentFactory in project openolat by klemens.

the class QTIEditHelper method itemToXml.

public static Document itemToXml(Item qtiItem) {
    try {
        DocumentFactory df = DocumentFactory.getInstance();
        Document doc = df.createDocument();
        doc.addDocType(QTIConstants.XML_DOCUMENT_ROOT, null, QTIConstants.XML_DOCUMENT_DTD);
        Element questestinteropEl = df.createElement(QTIDocument.DOCUMENT_ROOT);
        doc.setRootElement(questestinteropEl);
        qtiItem.addToElement(questestinteropEl);
        return doc;
    } catch (Exception e) {
        log.error("", e);
        return null;
    }
}
Also used : DocumentFactory(org.dom4j.DocumentFactory) Element(org.dom4j.Element) Document(org.dom4j.Document) QTIDocument(org.olat.ims.qti.editor.beecom.objects.QTIDocument) IOException(java.io.IOException)

Example 10 with DocumentFactory

use of org.dom4j.DocumentFactory in project openolat by klemens.

the class TextMarkerManagerImpl method saveToFile.

/**
 * @see org.olat.core.gui.control.generic.textmarker.TextMarkerManager#saveToFile(org.olat.core.util.vfs.VFSLeaf,
 *      java.util.List)
 */
public void saveToFile(VFSLeaf textMarkerFile, List<TextMarker> textMarkerList) {
    DocumentFactory df = DocumentFactory.getInstance();
    Document doc = df.createDocument();
    // create root element with version information
    Element root = df.createElement(XML_ROOT_ELEMENT);
    root.addAttribute(XML_VERSION_ATTRIBUTE, String.valueOf(VERSION));
    doc.setRootElement(root);
    // add TextMarker elements
    for (TextMarker textMarker : textMarkerList) {
        textMarker.addToElement(root);
    }
    OutputStream stream = textMarkerFile.getOutputStream(false);
    try {
        XMLWriter writer = new XMLWriter(stream);
        writer.write(doc);
        writer.close();
        stream.close();
    } catch (UnsupportedEncodingException e) {
        log.error("Error while saving text marker file", e);
    } catch (IOException e) {
        log.error("Error while saving text marker file", e);
    }
}
Also used : DocumentFactory(org.dom4j.DocumentFactory) Element(org.dom4j.Element) OutputStream(java.io.OutputStream) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) Document(org.dom4j.Document) XMLWriter(org.dom4j.io.XMLWriter)

Aggregations

DocumentFactory (org.dom4j.DocumentFactory)12 Element (org.dom4j.Element)12 Document (org.dom4j.Document)10 IOException (java.io.IOException)6 OutputStream (java.io.OutputStream)4 XMLWriter (org.dom4j.io.XMLWriter)4 QTIDocument (org.olat.ims.qti.editor.beecom.objects.QTIDocument)4 BufferedOutputStream (java.io.BufferedOutputStream)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 Date (java.util.Date)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Iterator (java.util.Iterator)2 List (java.util.List)2 Set (java.util.Set)2 XPath (org.dom4j.XPath)2 OutputFormat (org.dom4j.io.OutputFormat)2 Translator (org.olat.core.gui.translator.Translator)2 User (org.olat.core.id.User)2 VFSContainer (org.olat.core.util.vfs.VFSContainer)2