use of org.olat.core.util.xml.XMLParser in project OpenOLAT by OpenOLAT.
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 OpenOLAT.
the class CPManagerImpl method load.
/**
* @see org.olat.ims.cp.CPManager#load(org.olat.core.util.vfs.VFSContainer)
*/
public ContentPackage load(VFSContainer directory, OLATResourceable ores) {
XMLParser parser = new XMLParser();
ContentPackage cp;
VFSLeaf file = (VFSLeaf) directory.resolve("imsmanifest.xml");
if (file != null) {
try {
DefaultDocument doc = (DefaultDocument) parser.parse(file.getInputStream(), false);
cp = new ContentPackage(doc, directory, ores);
// identifier.
if (cp.getLastError() == null) {
if (cp.isOLATContentPackage() && CPCore.OLAT_ORGANIZATION_IDENTIFIER.equals(cp.getFirstOrganizationInManifest().getIdentifier())) {
setUniqueOrgaIdentifier(cp);
}
}
} catch (OLATRuntimeException e) {
cp = new ContentPackage(null, directory, ores);
logError("Reading imsmanifest failed. Dir: " + directory.getName() + ". Ores: " + ores.getResourceableId(), e);
cp.setLastError("Exception reading XML for IMS CP: invalid xml-file ( " + directory.getName() + ")");
}
} else {
cp = new ContentPackage(null, directory, ores);
cp.setLastError("Exception reading XML for IMS CP: IMS-Manifest not found in " + directory.getName());
logError("IMS manifiest xml couldn't be found in dir " + directory.getName() + ". Ores: " + ores.getResourceableId(), null);
throw new OLATRuntimeException(CPManagerImpl.class, "The imsmanifest.xml file was not found.", new IOException());
}
return cp;
}
use of org.olat.core.util.xml.XMLParser in project OpenOLAT by OpenOLAT.
the class ScormCPManifestTreeModel method loadDocument.
private Document loadDocument(File documentF) {
FileInputStream in = null;
BufferedInputStream bis = null;
Document doc = null;
try {
in = new FileInputStream(documentF);
bis = new BufferedInputStream(in);
XMLParser xmlParser = new XMLParser(new IMSEntityResolver());
doc = xmlParser.parse(bis, false);
} catch (IOException e) {
throw new OLATRuntimeException(ScormCPManifestTreeModel.class, "could not read and parse from file " + documentF.getAbsolutePath(), e);
} finally {
try {
if (in != null)
in.close();
if (bis != null)
bis.close();
} catch (Exception e) {
// we did our best to close the inputStream
}
}
return doc;
}
use of org.olat.core.util.xml.XMLParser in project OpenOLAT by OpenOLAT.
the class FilePersister method retreiveResultsReporting.
/**
* Retreive results for this user/aiid
*
* @param type The type of results
* @return
*/
public static Document retreiveResultsReporting(Identity subj, String type, long aiid) {
File fUserdataRoot = new File(WebappHelper.getUserDataRoot());
String path = RES_REPORTING + File.separator + subj.getName() + File.separator + type + File.separator + aiid + ".xml";
File fDoc = new File(fUserdataRoot, path);
Document doc = null;
try {
InputStream is = new FileInputStream(fDoc);
BufferedInputStream bis = new BufferedInputStream(is);
XMLParser xmlParser = new XMLParser(new IMSEntityResolver());
doc = xmlParser.parse(bis, false);
is.close();
bis.close();
} catch (Exception e) {
throw new OLATRuntimeException(FilePersister.class, "Error retrieving results reporting for subject: '" + subj.getName() + "'; assessment id: '" + aiid + "'", e);
}
return doc;
}
use of org.olat.core.util.xml.XMLParser in project OpenOLAT by OpenOLAT.
the class CPManifestTreeModel method loadDocument.
private Document loadDocument(String documentStr) throws IOException {
InputStream in = null;
Document doc = null;
try {
in = new ByteArrayInputStream(documentStr.getBytes());
XMLParser xmlParser = new XMLParser(new IMSEntityResolver());
doc = xmlParser.parse(in, false);
in.close();
} catch (IOException e) {
throw e;
} catch (Exception e) {
throw new IOException("could not read and parse from string " + documentStr, e);
} finally {
IOUtils.closeQuietly(in);
}
return doc;
}
Aggregations