From 9bc998d8267c3ec4b08e0d1eef7064db44ca9ae6 Mon Sep 17 00:00:00 2001 From: srosse <none@none> Date: Thu, 4 Dec 2014 09:51:10 +0100 Subject: [PATCH] OO-1279: better check of null in case of NFS file system --- .../modules/bc/commands/CmdServeResource.java | 72 ++++++++++--------- .../olat/core/util/vfs/LocalFolderImpl.java | 4 ++ 2 files changed, 42 insertions(+), 34 deletions(-) diff --git a/src/main/java/org/olat/core/commons/modules/bc/commands/CmdServeResource.java b/src/main/java/org/olat/core/commons/modules/bc/commands/CmdServeResource.java index 718539a93d5..921192ebfe9 100644 --- a/src/main/java/org/olat/core/commons/modules/bc/commands/CmdServeResource.java +++ b/src/main/java/org/olat/core/commons/modules/bc/commands/CmdServeResource.java @@ -88,43 +88,47 @@ public class CmdServeResource implements FolderCommand { // set the http content-type and the encoding // try to load in iso-8859-1 InputStream is = vfsfile.getInputStream(); - String page = FileUtils.load(is, DEFAULT_ENCODING); - // search for the <meta content="text/html; charset=utf-8" - // http-equiv="Content-Type" /> tag - // if none found, assume iso-8859-1 - String enc = DEFAULT_ENCODING; - boolean useLoaded = false; - // <meta.*charset=([^"]*)" - Matcher m = PATTERN_ENCTYPE.matcher(page); - boolean found = m.find(); - if (found) { - String htmlcharset = m.group(1); - enc = htmlcharset; - if (htmlcharset.equals(DEFAULT_ENCODING)) { + if(is == null) { + mr = new NotFoundMediaResource(path); + } else { + String page = FileUtils.load(is, DEFAULT_ENCODING); + // search for the <meta content="text/html; charset=utf-8" + // http-equiv="Content-Type" /> tag + // if none found, assume iso-8859-1 + String enc = DEFAULT_ENCODING; + boolean useLoaded = false; + // <meta.*charset=([^"]*)" + Matcher m = PATTERN_ENCTYPE.matcher(page); + boolean found = m.find(); + if (found) { + String htmlcharset = m.group(1); + enc = htmlcharset; + if (htmlcharset.equals(DEFAULT_ENCODING)) { + useLoaded = true; + } + } else { useLoaded = true; } - } else { - useLoaded = true; - } - // set the new encoding to remember for any following .js file loads - g_encoding = enc; - if (useLoaded) { - StringMediaResource smr = new StringMediaResource(); - String mimetype = forceDownload ? VFSMediaResource.MIME_TYPE_FORCE_DOWNLOAD : "text/html;charset=" + enc; - smr.setContentType(mimetype); - smr.setEncoding(enc); - smr.setData(page); - mr = smr; - } else { - // found a new charset other than iso-8859-1 -> let it load again - // as bytes (so we do not need to convert to string and back - // again) - VFSMediaResource vmr = new VFSMediaResource(vfsfile); - vmr.setEncoding(enc); - if(forceDownload) { - vmr.setDownloadable(true); + // set the new encoding to remember for any following .js file loads + g_encoding = enc; + if (useLoaded) { + StringMediaResource smr = new StringMediaResource(); + String mimetype = forceDownload ? VFSMediaResource.MIME_TYPE_FORCE_DOWNLOAD : "text/html;charset=" + enc; + smr.setContentType(mimetype); + smr.setEncoding(enc); + smr.setData(page); + mr = smr; + } else { + // found a new charset other than iso-8859-1 -> let it load again + // as bytes (so we do not need to convert to string and back + // again) + VFSMediaResource vmr = new VFSMediaResource(vfsfile); + vmr.setEncoding(enc); + if(forceDownload) { + vmr.setDownloadable(true); + } + mr = vmr; } - mr = vmr; } } else if (path.endsWith(".js")) { // a javascript library VFSMediaResource vmr = new VFSMediaResource(vfsfile); diff --git a/src/main/java/org/olat/core/util/vfs/LocalFolderImpl.java b/src/main/java/org/olat/core/util/vfs/LocalFolderImpl.java index 8db7ad2b282..ec48aad3c80 100644 --- a/src/main/java/org/olat/core/util/vfs/LocalFolderImpl.java +++ b/src/main/java/org/olat/core/util/vfs/LocalFolderImpl.java @@ -91,12 +91,16 @@ public class LocalFolderImpl extends LocalImpl implements VFSContainer { /** * @see org.olat.core.util.vfs.VFSContainer#getItems(org.olat.core.util.vfs.filters.VFSItemFilter) */ + @Override public List<VFSItem> getItems(VFSItemFilter filter) { File aFolder = getBasefile(); if(! aFolder.isDirectory()){ throw new AssertException("basefile is not a directory: "+aFolder.getAbsolutePath()); } File[] children = aFolder.listFiles(); + if(children == null) { + children = new File[0]; + } int len = children.length; List<VFSItem> res = new ArrayList<VFSItem>(len); -- GitLab