diff --git a/api/src/org/labkey/api/data/AbstractFileDisplayColumn.java b/api/src/org/labkey/api/data/AbstractFileDisplayColumn.java index a0f0b2fea8c..d4bfc869c23 100644 --- a/api/src/org/labkey/api/data/AbstractFileDisplayColumn.java +++ b/api/src/org/labkey/api/data/AbstractFileDisplayColumn.java @@ -62,6 +62,11 @@ public void renderGridCellContents(RenderContext ctx, Writer out) throws IOExcep /** @return the short name of the file (not including full path) */ protected abstract String getFileName(RenderContext ctx, Object value); + protected String getFileName(RenderContext ctx, Object value, boolean isDisplay) + { + return getFileName(ctx, value); + } + protected abstract InputStream getFileContents(RenderContext ctx, Object value) throws FileNotFoundException; protected void renderIconAndFilename(RenderContext ctx, Writer out, String filename, boolean link, boolean thumbnail) throws IOException @@ -103,7 +108,7 @@ protected void renderIconAndFilename(RenderContext ctx, Writer out, String filen } } - String displayName = getFileName(ctx, filename); + String displayName = getFileName(ctx, filename, true); boolean isImage = isImage(filename); FileImageRenderHelper renderHelper = createRenderHelper(ctx, url, filename, displayName, fileIconUrl, popupIconUrl, thumbnail, isImage); diff --git a/api/src/org/labkey/api/study/assay/FileLinkDisplayColumn.java b/api/src/org/labkey/api/study/assay/FileLinkDisplayColumn.java index 43016921add..079bbe806be 100644 --- a/api/src/org/labkey/api/study/assay/FileLinkDisplayColumn.java +++ b/api/src/org/labkey/api/study/assay/FileLinkDisplayColumn.java @@ -49,6 +49,7 @@ import java.io.InputStream; import java.io.Writer; import java.net.URI; +import java.net.URISyntaxException; import java.util.List; import java.util.Map; import java.util.Set; @@ -247,15 +248,26 @@ protected String getFileName(RenderContext ctx, Object value) return getFileName(ctx, value, false); } + @Override protected String getFileName(RenderContext ctx, Object value, boolean isDisplay) { String result = value == null ? null : StringUtils.trimToNull(value.toString()); if (result != null) { - File f; + File f = null; if (result.startsWith("file:")) - f = new File(URI.create(result)); - else + { + try + { + f = new File(new URI(result)); + } + catch (URISyntaxException x) + { + // try to recover + result = result.substring("file:".length()); + } + } + if (null == f) f = FileUtil.getAbsoluteCaseSensitiveFile(new File(result)); NetworkDrive.ensureDrive(f.getPath()); List fileRootTypes = List.of(FileContentService.ContentType.files, FileContentService.ContentType.pipeline, FileContentService.ContentType.assayfiles); @@ -270,7 +282,7 @@ protected String getFileName(RenderContext ctx, Object value, boolean isDisplay) result = f.getName(); } - if (isDisplay && !f.exists()) + if (isDisplay && !f.exists() && !result.endsWith("(unavailable)")) result += " (unavailable)"; } return result; @@ -339,7 +351,7 @@ else if (f.isDirectory()) else { // It's not on the file system anymore, so don't offer a link and tell the user it's unavailable - super.renderIconAndFilename(ctx, out, filename + " (unavailable)", Attachment.getFileIcon(filename), null, false, false); + super.renderIconAndFilename(ctx, out, filename, Attachment.getFileIcon(filename), null, false, false); } } else