Skip to content
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@

package edu.ucla.library.iiif.fester.verticles;

import java.util.Set;

import info.freelibrary.util.FileUtils;
import info.freelibrary.util.Logger;
import info.freelibrary.util.LoggerFactory;

Expand All @@ -25,6 +28,8 @@ public abstract class AbstractFesterVerticle extends AbstractVerticle {

private static final Logger LOGGER = LoggerFactory.getLogger(AbstractFesterVerticle.class, Constants.MESSAGES);

private static final Set<String> WEB_IMAGE_EXTENSIONS = Set.of("jpg", "jpeg", "png", "gif", "webp", "svg");

@Override
public void start() throws Exception {
LOGGER.debug(MessageCodes.MFS_110, getClass().getName(), deploymentID());
Expand Down Expand Up @@ -112,4 +117,14 @@ protected void error(final Message<JsonObject> aMessage, final Throwable aThrowa
aMessage.fail(HTTP.INTERNAL_SERVER_ERROR, log);
}
}

/**
* Checks whether the supplied URI ends with a known/supported image extension.
*
* @param aURI A URI to check
* @return True is the static image file extension is found; else, false
*/
protected boolean isStaticFile(final String aURI) {
return WEB_IMAGE_EXTENSIONS.contains(FileUtils.getExt(aURI)); // Returns EMPTY if none, which won't match
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,8 @@ private Canvas[] createCanvases(final CsvHeaders aCsvHeaders, final List<String[
imageResource.setWidth(mediaWidth);
imageResource.setHeight(mediaHeight);

if (!accessURI.matches("^.+\\.[^.]+$")) { // Does the URI have a file extension?
// Does the URI have a file extension?
if (!isStaticFile(accessURI)) {
imageResource.setService(new ImageInfoService(APIComplianceLevel.TWO, pageURI));
} else {
staticImage = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,8 @@ private Canvas[] createCanvases(final CsvHeaders aCsvHeaders, final List<String[
height = Integer.parseInt(mediaHeight.get());
image = new ImageContent(resourceURI);

if (!accessURI.matches("^.+\\.[^.]+$")) { // Does the URI have a file extension?
// Does the URI have a file extension?
if (!isStaticFile(accessURI)) {
image.setServices(new ImageService2(pageURI));
}
} else {
Expand Down
Loading