diff --git a/docet-core/src/main/java/docet/DocetUtils.java b/docet-core/src/main/java/docet/DocetUtils.java index daa31de..75cb24d 100644 --- a/docet-core/src/main/java/docet/DocetUtils.java +++ b/docet-core/src/main/java/docet/DocetUtils.java @@ -35,6 +35,9 @@ import docet.model.DocetPackageDescriptor; import io.netty.util.internal.PlatformDependent; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; /** @@ -170,4 +173,30 @@ public static Integer[] convertHexColorToRgb(final String hex) { Integer.valueOf( hexCode.substring( 5, 7 ), 16 ) }; } + + public static boolean extensionAllowed(String extension) { + List forbiddenExtensions = new ArrayList<>(); + + for (ForbiddenExtensions fe : ForbiddenExtensions.values()) { + forbiddenExtensions.add(fe.extension()); + } + + return forbiddenExtensions.contains(extension) == false; + } + + private enum ForbiddenExtensions { + JPEG("jpeg"), + JPG("jpg"); + + private final String extension; + + private ForbiddenExtensions(final String extension) { + this.extension = extension; + } + + public String extension() { + return extension; + } + } + } diff --git a/docet-core/src/main/java/docet/engine/DocetManager.java b/docet-core/src/main/java/docet/engine/DocetManager.java index 3de9e3b..c1d9a92 100644 --- a/docet-core/src/main/java/docet/engine/DocetManager.java +++ b/docet-core/src/main/java/docet/engine/DocetManager.java @@ -60,6 +60,7 @@ import docet.DocetLanguage; import docet.DocetPackageLocator; import docet.DocetUtils; +import static docet.DocetUtils.extensionAllowed; import docet.SimpleDocetDocumentAccessor; import docet.SimplePackageLocator; import docet.StatsCollector; @@ -1163,15 +1164,15 @@ private void servePackageListRequest(final String lang, final String[] packageId } private void serveImageRequest(final String packageId, final String imageName, final String lang, - final DocetExecutionContext ctx, final HttpServletResponse response) - throws DocetException { - final String imageFormat = imageName.substring(imageName.indexOf('.') + 1); - if (!"png".equals(imageFormat)) { + final DocetExecutionContext ctx, final HttpServletResponse response) + throws DocetException { + String imageExtension = imageName.substring(imageName.indexOf('.') + 1); + if (!extensionAllowed(imageExtension)) { throw new DocetException(DocetException.CODE_RESOURCE_NOTFOUND, - "Unsupported image file format " + imageFormat); + "Unsupported image file format " + imageExtension); } - response.setContentType("image/png"); - try (OutputStream out = response.getOutputStream();) { + response.setContentType("image/" + imageExtension); + try (OutputStream out = response.getOutputStream()) { this.getImageBylangForPackage(imageName, lang, packageId, out, ctx); } catch (DocetException ex) { LOGGER.log(Level.SEVERE, "Error on serving Image " + imageName + " packageid " + packageId + " lang ", ex); diff --git a/docet-sample-doc/src/main/docs/en/imgs/samples/sampleimage.gif b/docet-sample-doc/src/main/docs/en/imgs/samples/sampleimage.gif new file mode 100644 index 0000000..0e8b0a6 Binary files /dev/null and b/docet-sample-doc/src/main/docs/en/imgs/samples/sampleimage.gif differ diff --git a/docet-sample-doc/src/main/docs/en/pages/sample-docs/sd001.html b/docet-sample-doc/src/main/docs/en/pages/sample-docs/sd001.html index fd289ad..d9362ab 100644 --- a/docet-sample-doc/src/main/docs/en/pages/sample-docs/sd001.html +++ b/docet-sample-doc/src/main/docs/en/pages/sample-docs/sd001.html @@ -8,6 +8,8 @@

Sample Style Document

A styling guide is essential in order to start writing down a guide. Whether you adopt your own style or customize the one presented here, it is fundamental to get acquainted with docet source language

The following is a brandnew sample image: +

And a brandnew sample image gif: +