use of org.olat.core.util.xml.XMLParser in project openolat by klemens.
the class TextMarkerManagerImpl method loadTextMarkerList.
/**
* @see org.olat.core.gui.control.generic.textmarker.TextMarkerManager#loadTextMarkerList(org.olat.core.util.vfs.VFSLeaf)
*/
public List<TextMarker> loadTextMarkerList(VFSLeaf textMarkerFile) {
if (textMarkerFile == null) {
// filename not defined at all
return new ArrayList<TextMarker>();
}
XMLParser parser = new XMLParser();
InputStream stream = textMarkerFile.getInputStream();
if (stream == null) {
// e.g. file was removed
return new ArrayList<TextMarker>();
}
Document doc = parser.parse(stream, false);
Element root = doc.getRootElement();
if (root == null) {
// file was empty;
return new ArrayList<TextMarker>();
}
// Do version check. Not needed now, for future lazy migration code...
Attribute versionAttribute = root.attribute(XML_VERSION_ATTRIBUTE);
int version = (versionAttribute == null ? 1 : Integer.parseInt(versionAttribute.getStringValue()));
if (version != VERSION) {
// complain about version conflict or solve it
throw new OLATRuntimeException("Could not load glossary entries due to version conflict. Loaded version was::" + version, null);
}
// parse text marker objects and put them into a list
List markersElements = root.elements("textMarker");
List<TextMarker> markers = new ArrayList<TextMarker>();
Iterator iter = markersElements.iterator();
while (iter.hasNext()) {
Element textMarkerElement = (Element) iter.next();
TextMarker textMarker = new TextMarker(textMarkerElement);
markers.add(textMarker);
}
try {
stream.close();
} catch (IOException e) {
throw new OLATRuntimeException(this.getClass(), "Error while closing text marker file stream", e);
}
return markers;
}
use of org.olat.core.util.xml.XMLParser in project openolat by klemens.
the class QTIEditorPackageImpl method loadQTIDocument.
/**
* Load a document from file.
*
* @return the loaded document or null if loading failed
*/
private Document loadQTIDocument() {
File fIn = null;
FileInputStream in = null;
BufferedInputStream bis = null;
Document doc = null;
try {
fIn = new File(packageDir, ImsRepositoryResolver.QTI_FILE);
in = new FileInputStream(fIn);
bis = new BufferedInputStream(in);
XMLParser xmlParser = new XMLParser(new IMSEntityResolver());
doc = xmlParser.parse(bis, true);
} catch (Exception e) {
log.warn("Exception when parsing input QTI input stream for " + fIn != null ? fIn.getAbsolutePath() : "qti.xml", e);
return null;
} finally {
try {
if (in != null)
in.close();
if (bis != null)
bis.close();
} catch (Exception e) {
throw new OLATRuntimeException(this.getClass(), "Could not close input file stream ", e);
}
}
return doc;
}
use of org.olat.core.util.xml.XMLParser in project openolat by klemens.
the class QTIImportProcessor method readXml.
private Document readXml(InputStream in) {
Document doc = null;
try {
XMLParser xmlParser = new XMLParser(new IMSEntityResolver());
doc = xmlParser.parse(in, false);
return doc;
} catch (Exception e) {
return null;
}
}
use of org.olat.core.util.xml.XMLParser in project openolat by klemens.
the class QTIExportProcessor method readItemXml.
private Element readItemXml(VFSLeaf leaf) {
Document doc = null;
try {
InputStream is = leaf.getInputStream();
XMLParser xmlParser = new XMLParser(new IMSEntityResolver());
doc = xmlParser.parse(is, false);
Element item = (Element) doc.selectSingleNode("questestinterop/item");
is.close();
return item;
} catch (Exception e) {
log.error("", e);
return null;
}
}
use of org.olat.core.util.xml.XMLParser in project openolat by klemens.
the class IMSLoader method loadIMSDocument.
public static Document loadIMSDocument(Path documentPath) {
Document doc = null;
try (InputStream in = Files.newInputStream(documentPath)) {
XMLParser xmlParser = new XMLParser(new IMSEntityResolver());
doc = xmlParser.parse(in, false);
} catch (Exception e) {
return null;
}
return doc;
}
Aggregations