Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

renderIconAndFilename() expects actual path #6052

Merged
merged 3 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion api/src/org/labkey/api/data/AbstractFileDisplayColumn.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
22 changes: 17 additions & 5 deletions api/src/org/labkey/api/study/assay/FileLinkDisplayColumn.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<FileContentService.ContentType> fileRootTypes = List.of(FileContentService.ContentType.files, FileContentService.ContentType.pipeline, FileContentService.ContentType.assayfiles);
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down