Skip to content
Snippets Groups Projects
Commit 98a68246 authored by srosse's avatar srosse
Browse files

OO-289: catch the error reading the CP and show an error message and not a red screen

parent aafd9c08
No related branches found
No related tags found
No related merge requests found
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
package org.olat.modules.cp; package org.olat.modules.cp;
import java.io.IOException;
import java.util.List; import java.util.List;
import org.olat.core.CoreSpringFactory; import org.olat.core.CoreSpringFactory;
...@@ -139,10 +140,17 @@ public class CPDisplayController extends BasicController implements Activateable ...@@ -139,10 +140,17 @@ public class CPDisplayController extends BasicController implements Activateable
// even if we do not show the menu, we need to build parse the manifest and // even if we do not show the menu, we need to build parse the manifest and
// find the first node to display at startup // find the first node to display at startup
VFSItem mani = rootContainer.resolve("imsmanifest.xml"); VFSItem mani = rootContainer.resolve("imsmanifest.xml");
if (mani == null || !(mani instanceof VFSLeaf)) { throw new OLATRuntimeException("error.manifest.missing", null, this.getClass() if (mani == null || !(mani instanceof VFSLeaf)) {
.getPackage().getName(), "CP " + rootContainer + " has no imsmanifest", null); } showError("error.manifest.missing");
return;
}
// initialize tree model in any case // initialize tree model in any case
ctm = new CPManifestTreeModel((VFSLeaf) mani); try {
ctm = new CPManifestTreeModel((VFSLeaf) mani);
} catch (IOException e) {
showError("error.manifest.corrupted");
return;
}
if (showMenu) { if (showMenu) {
// the menu is only initialized when needed. // the menu is only initialized when needed.
......
...@@ -35,6 +35,7 @@ import java.util.Iterator; ...@@ -35,6 +35,7 @@ import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.apache.commons.io.IOUtils;
import org.dom4j.Document; import org.dom4j.Document;
import org.dom4j.Element; import org.dom4j.Element;
import org.dom4j.XPath; import org.dom4j.XPath;
...@@ -42,7 +43,6 @@ import org.olat.core.gui.components.tree.GenericTreeModel; ...@@ -42,7 +43,6 @@ import org.olat.core.gui.components.tree.GenericTreeModel;
import org.olat.core.gui.components.tree.GenericTreeNode; import org.olat.core.gui.components.tree.GenericTreeNode;
import org.olat.core.gui.components.tree.TreeNode; import org.olat.core.gui.components.tree.TreeNode;
import org.olat.core.logging.AssertException; import org.olat.core.logging.AssertException;
import org.olat.core.logging.OLATRuntimeException;
import org.olat.core.util.vfs.VFSLeaf; import org.olat.core.util.vfs.VFSLeaf;
import org.olat.core.util.xml.XMLParser; import org.olat.core.util.xml.XMLParser;
import org.olat.ims.resources.IMSEntityResolver; import org.olat.ims.resources.IMSEntityResolver;
...@@ -63,7 +63,7 @@ public class CPManifestTreeModel extends GenericTreeModel { ...@@ -63,7 +63,7 @@ public class CPManifestTreeModel extends GenericTreeModel {
* Constructor of the content packaging tree model * Constructor of the content packaging tree model
* @param manifest the imsmanifest.xml file * @param manifest the imsmanifest.xml file
*/ */
CPManifestTreeModel(VFSLeaf manifest) { CPManifestTreeModel(VFSLeaf manifest) throws IOException {
Document doc = loadDocument(manifest); Document doc = loadDocument(manifest);
// get all organization elements. need to set namespace // get all organization elements. need to set namespace
rootElement = doc.getRootElement(); rootElement = doc.getRootElement();
...@@ -182,7 +182,7 @@ public class CPManifestTreeModel extends GenericTreeModel { ...@@ -182,7 +182,7 @@ public class CPManifestTreeModel extends GenericTreeModel {
return gtn; return gtn;
} }
private Document loadDocument(VFSLeaf documentF) { private Document loadDocument(VFSLeaf documentF) throws IOException {
InputStream in = null; InputStream in = null;
Document doc = null; Document doc = null;
try { try {
...@@ -190,20 +190,14 @@ public class CPManifestTreeModel extends GenericTreeModel { ...@@ -190,20 +190,14 @@ public class CPManifestTreeModel extends GenericTreeModel {
XMLParser xmlParser = new XMLParser(new IMSEntityResolver()); XMLParser xmlParser = new XMLParser(new IMSEntityResolver());
doc = xmlParser.parse(in, false); doc = xmlParser.parse(in, false);
in.close(); in.close();
} } catch (IOException e) {
catch (IOException e) { throw e;
throw new OLATRuntimeException(CPManifestTreeModel.class, "could not read and parse from file " + documentF, e); } catch(Exception e) {
throw new IOException("could not read and parse from file " + documentF, e);
} }
finally { finally {
try { IOUtils.closeQuietly(in);
if (in != null)
in.close();
}
catch (Exception e) {
// we did our best to close the inputStream
}
} }
return doc; return doc;
} }
} }
...@@ -65,7 +65,7 @@ import org.olat.fileresource.FileResourceManager; ...@@ -65,7 +65,7 @@ import org.olat.fileresource.FileResourceManager;
public class CPOfflineReadableManager { public class CPOfflineReadableManager {
private static CPOfflineReadableManager instance = new CPOfflineReadableManager(); private static CPOfflineReadableManager instance = new CPOfflineReadableManager();
OLog logger = Tracing.createLoggerFor(CPOfflineReadableManager.class); private static final OLog log = Tracing.createLoggerFor(CPOfflineReadableManager.class);
private static final String DIRNAME_CPOFFLINEMENUMAT = "cp_offline_menu_mat"; private static final String DIRNAME_CPOFFLINEMENUMAT = "cp_offline_menu_mat";
private static final String FILENAME_START = "_START_.html"; private static final String FILENAME_START = "_START_.html";
...@@ -115,9 +115,13 @@ public class CPOfflineReadableManager { ...@@ -115,9 +115,13 @@ public class CPOfflineReadableManager {
* the resulting zip-filename * the resulting zip-filename
*/ */
public void makeCPOfflineReadable(File unzippedDir, File targetZip) { public void makeCPOfflineReadable(File unzippedDir, File targetZip) {
writeOfflineCPStartHTMLFile(unzippedDir); try {
File cpOfflineMat = new File(WebappHelper.getContextRoot() + "/static/" + DIRNAME_CPOFFLINEMENUMAT); writeOfflineCPStartHTMLFile(unzippedDir);
zipOfflineReadableCP(unzippedDir, targetZip, cpOfflineMat); File cpOfflineMat = new File(WebappHelper.getContextRoot() + "/static/" + DIRNAME_CPOFFLINEMENUMAT);
zipOfflineReadableCP(unzippedDir, targetZip, cpOfflineMat);
} catch (IOException e) {
log.error("", e);
}
} }
/** /**
...@@ -132,17 +136,21 @@ public class CPOfflineReadableManager { ...@@ -132,17 +136,21 @@ public class CPOfflineReadableManager {
* the resulting zip-filename * the resulting zip-filename
*/ */
public void makeCPOfflineReadable(OLATResourceable ores, String zipName) { public void makeCPOfflineReadable(OLATResourceable ores, String zipName) {
String repositoryHome = FolderConfig.getCanonicalRepositoryHome(); try {
FileResourceManager fm = FileResourceManager.getInstance(); String repositoryHome = FolderConfig.getCanonicalRepositoryHome();
String relPath = fm.getUnzippedDirRel(ores); FileResourceManager fm = FileResourceManager.getInstance();
String resId = ores.getResourceableId().toString(); String relPath = fm.getUnzippedDirRel(ores);
String resId = ores.getResourceableId().toString();
File unzippedDir = new File(repositoryHome + "/" + relPath); File unzippedDir = new File(repositoryHome + "/" + relPath);
File targetZip = new File(repositoryHome + "/" + resId + "/" + zipName); File targetZip = new File(repositoryHome + "/" + resId + "/" + zipName);
File cpOfflineMat = new File(WebappHelper.getContextRoot() + "/static/" + DIRNAME_CPOFFLINEMENUMAT); File cpOfflineMat = new File(WebappHelper.getContextRoot() + "/static/" + DIRNAME_CPOFFLINEMENUMAT);
writeOfflineCPStartHTMLFile(unzippedDir); writeOfflineCPStartHTMLFile(unzippedDir);
zipOfflineReadableCP(unzippedDir, targetZip, cpOfflineMat); zipOfflineReadableCP(unzippedDir, targetZip, cpOfflineMat);
} catch (IOException e) {
log.error("", e);
}
} }
/** /**
...@@ -154,7 +162,7 @@ public class CPOfflineReadableManager { ...@@ -154,7 +162,7 @@ public class CPOfflineReadableManager {
* @param unzippedDir * @param unzippedDir
* the directory that contains the unzipped CP * the directory that contains the unzipped CP
*/ */
private void writeOfflineCPStartHTMLFile(File unzippedDir) { private void writeOfflineCPStartHTMLFile(File unzippedDir) throws IOException {
/* first, we do the menu-tree */ /* first, we do the menu-tree */
File mani = new File(unzippedDir, FILENAME_IMSMANIFEST); File mani = new File(unzippedDir, FILENAME_IMSMANIFEST);
...@@ -178,9 +186,9 @@ public class CPOfflineReadableManager { ...@@ -178,9 +186,9 @@ public class CPOfflineReadableManager {
String template = FileUtils.load(CPOfflineReadableManager.class.getResourceAsStream("_content/cpofflinereadable.html"), "utf-8"); String template = FileUtils.load(CPOfflineReadableManager.class.getResourceAsStream("_content/cpofflinereadable.html"), "utf-8");
boolean evalResult = velocityEngine.evaluate(ctx, sw, "cpexport", template); boolean evalResult = velocityEngine.evaluate(ctx, sw, "cpexport", template);
if (!evalResult) if (!evalResult)
logger.error("Could not evaluate velocity template for CP Export"); log.error("Could not evaluate velocity template for CP Export");
} catch (IOException e) { } catch (IOException e) {
logger.error("Error while evaluating velovity template for CP Export",e); log.error("Error while evaluating velovity template for CP Export",e);
} }
File f = new File(unzippedDir, FILENAME_START); File f = new File(unzippedDir, FILENAME_START);
...@@ -270,7 +278,7 @@ public class CPOfflineReadableManager { ...@@ -270,7 +278,7 @@ public class CPOfflineReadableManager {
boolean zipResult = ZipUtil.zip(allFilesInUnzippedDir, unzippedDir, targetZip, true); boolean zipResult = ZipUtil.zip(allFilesInUnzippedDir, unzippedDir, targetZip, true);
if(!targetZip.exists()){ if(!targetZip.exists()){
logger.warn("targetZip does not exists after zipping. zip-result is: "+ zipResult); log.warn("targetZip does not exists after zipping. zip-result is: "+ zipResult);
} }
} }
......
...@@ -4,4 +4,5 @@ print.node=Drucken ...@@ -4,4 +4,5 @@ print.node=Drucken
print.node.list=Seite print.node.list=Seite
print.node.list.title=Druckkonfiguration print.node.list.title=Druckkonfiguration
print.node.list.desc=W\u00E4hlen Sie eine oder mehrere Seiten f\u00FCr den Ausdruck aus print.node.list.desc=W\u00E4hlen Sie eine oder mehrere Seiten f\u00FCr den Ausdruck aus
error.manifest.missing=Dieser CP-Lerninhalt ist ung\u00FCltig\: Fehlendes imsmanifest.xml. Mehr Informationen dazu finden Sie unter http\://www.imsglobal.org. error.manifest.missing=Dieser CP-Lerninhalt ist ung\u00FCltig\: Fehlendes imsmanifest.xml. Mehr Informationen dazu finden Sie unter http\://www.imsglobal.org.
\ No newline at end of file error.manifest.corrupted=Dieser CP-Lerninhalt ist ung\u00FCltig\: imsmanifest.xml ist ung\u00FCltig. Mehr Informationen dazu finden Sie unter http\://www.imsglobal.org.
\ No newline at end of file
#Mon May 16 17:33:59 CEST 2011 #Mon May 16 17:33:59 CEST 2011
error.manifest.missing=This CP learning content is invalid\: missing imsmanifest.xml. For more information see http\://www.imsglobal.org. error.manifest.missing=This CP learning content is invalid\: missing imsmanifest.xml. For more information see http\://www.imsglobal.org.
error.manifest.corrupted=This CP learning content is invalid\: imsmanifest.xml is probably invalid. For more information see http\://www.imsglobal.org.
previous=Back previous=Back
print.node=Print print.node=Print
print.node.list=Page print.node.list=Page
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment