use of org.olat.ims.resources.IMSEntityResolver in project OpenOLAT by OpenOLAT.
the class QTIQPoolServiceProvider method extractTextContent.
@Override
public String extractTextContent(QuestionItemFull item) {
String content = null;
if (item.getRootFilename() != null) {
String dir = item.getDirectory();
VFSContainer container = qpoolFileStorage.getContainer(dir);
VFSItem file = container.resolve(item.getRootFilename());
if (file instanceof VFSLeaf) {
VFSLeaf leaf = (VFSLeaf) file;
InputStream is = leaf.getInputStream();
QTI12SAXHandler handler = new QTI12SAXHandler();
try {
XMLReader parser = XMLReaderFactory.createXMLReader();
parser.setContentHandler(handler);
parser.setEntityResolver(new IMSEntityResolver());
parser.setFeature("http://xml.org/sax/features/validation", false);
parser.parse(new InputSource(is));
} catch (Exception e) {
log.error("", e);
} finally {
FileUtils.closeSafely(is);
}
return handler.toString();
}
}
return content;
}
use of org.olat.ims.resources.IMSEntityResolver in project OpenOLAT by OpenOLAT.
the class ItemFileResourceValidator method readDocument.
private Document readDocument(InputStream in) {
try {
SAXReader reader = new SAXReader();
reader.setEntityResolver(new IMSEntityResolver());
reader.setValidation(false);
return reader.read(in, "");
} catch (Exception e) {
return null;
}
}
use of org.olat.ims.resources.IMSEntityResolver 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.ims.resources.IMSEntityResolver 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.ims.resources.IMSEntityResolver 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;
}
Aggregations