FileExtension.java

  1. /*
  2.  * #%L
  3.  * wcm.io
  4.  * %%
  5.  * Copyright (C) 2014 wcm.io
  6.  * %%
  7.  * Licensed under the Apache License, Version 2.0 (the "License");
  8.  * you may not use this file except in compliance with the License.
  9.  * You may obtain a copy of the License at
  10.  *
  11.  *      http://www.apache.org/licenses/LICENSE-2.0
  12.  *
  13.  * Unless required by applicable law or agreed to in writing, software
  14.  * distributed under the License is distributed on an "AS IS" BASIS,
  15.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16.  * See the License for the specific language governing permissions and
  17.  * limitations under the License.
  18.  * #L%
  19.  */
  20. package io.wcm.wcm.commons.contenttype;

  21. import java.util.Collections;
  22. import java.util.Set;

  23. import org.apache.commons.lang3.StringUtils;
  24. import org.jetbrains.annotations.NotNull;
  25. import org.jetbrains.annotations.Nullable;
  26. import org.osgi.annotation.versioning.ProviderType;

  27. /**
  28.  * Frequently used file extensions.
  29.  */
  30. @ProviderType
  31. @SuppressWarnings("null")
  32. public final class FileExtension {

  33.   private FileExtension() {
  34.     // constants only
  35.   }

  36.   /**
  37.    * HTML
  38.    */
  39.   public static final String HTML = "html";

  40.   /**
  41.    * HTML, configured as non-caching
  42.    */
  43.   public static final String HTML_UNCACHED = "htx";

  44.   /**
  45.    * JSON
  46.    */
  47.   public static final String JSON = "json";

  48.   /**
  49.    * Plain text
  50.    */
  51.   public static final String PLAINTEXT = "txt";

  52.   /**
  53.    * CSS
  54.    */
  55.   public static final String CSS = "css";

  56.   /**
  57.    * JavaScript
  58.    */
  59.   public static final String JAVASCRIPT = "js";

  60.   /**
  61.    * XML
  62.    */
  63.   public static final String XML = "xml";

  64.   /**
  65.    * XHTML
  66.    */
  67.   public static final String XHTML = "html";

  68.   /**
  69.    * ZIP
  70.    */
  71.   public static final String ZIP = "zip";

  72.   /**
  73.    * GIF image
  74.    */
  75.   public static final String GIF = "gif";

  76.   /**
  77.    * JPEG image
  78.    */
  79.   public static final String JPEG = "jpg";

  80.   /**
  81.    * PNG image
  82.    */
  83.   public static final String PNG = "png";

  84.   /**
  85.    * Flash file
  86.    */
  87.   public static final String SWF = "swf";

  88.   /**
  89.    * CSV
  90.    */
  91.   public static final String CSV = "csv";

  92.   /**
  93.    * PDF
  94.    */
  95.   public static final String PDF = "pdf";

  96.   /**
  97.    * SVG
  98.    */
  99.   public static final String SVG = "svg";

  100.   /**
  101.    * TIFF
  102.    */
  103.   public static final String TIFF = "tif";

  104.   /**
  105.    * WebP
  106.    */
  107.   public static final String WEBP = "webp";


  108.   /**
  109.    * all file extensions that will be displayed by an image tag
  110.    */
  111.   private static final Set<String> IMAGE_FILE_EXTENSIONS = Set.of(
  112.       GIF,
  113.       JPEG,
  114.       PNG,
  115.       "jpeg" // check for this alternative JEPG extension as well
  116.       );

  117.   /**
  118.    * all file extensions that will be displayed as flash
  119.    */
  120.   private static final Set<String> FLASH_FILE_EXTENSIONS = Set.of(
  121.       SWF
  122.       );

  123.   /**
  124.    * Check if the given file extension is a standard image format supported by web browsers and AEM Layer
  125.    * implementations.
  126.    * @param fileExtension File extension
  127.    * @return true if image
  128.    * @deprecated Use <code>io.wcm.handler.media.MediaFileType.isImage</code> instead.
  129.    */
  130.   @Deprecated(since = "1.5.0")
  131.   public static boolean isImage(@Nullable String fileExtension) {
  132.     if (StringUtils.isEmpty(fileExtension)) {
  133.       return false;
  134.     }
  135.     return IMAGE_FILE_EXTENSIONS.contains(fileExtension.toLowerCase());
  136.   }

  137.   /**
  138.    * @return Image file extensions for standard image formats supported by web browsers and AEM Layer implementations.
  139.    * @deprecated Use <code>io.wcm.handler.media.MediaFileType.getImageFileExtensions</code> instead.
  140.    */
  141.   @Deprecated(since = "1.5.0")
  142.   public static @NotNull Set<String> getImageFileExtensions() {
  143.     return Collections.unmodifiableSet(IMAGE_FILE_EXTENSIONS);
  144.   }

  145.   /**
  146.    * Check if the given file extension is an flash.
  147.    * @param fileExtension File extension
  148.    * @return true if flash
  149.    * @deprecated Use <code>io.wcm.handler.media.MediaFileType.isFlash</code> instead.
  150.    */
  151.   @Deprecated(since = "1.5.0")
  152.   public static boolean isFlash(@Nullable String fileExtension) {
  153.     if (StringUtils.isEmpty(fileExtension)) {
  154.       return false;
  155.     }
  156.     return FLASH_FILE_EXTENSIONS.contains(fileExtension.toLowerCase());
  157.   }

  158.   /**
  159.    * @return Flash file extensions
  160.    * @deprecated Use <code>io.wcm.handler.media.MediaFileType.getFlashFileExtensions</code> instead.
  161.    */
  162.   @Deprecated(since = "1.5.0")
  163.   public static @NotNull Set<String> getFlashFileExtensions() {
  164.     return Collections.unmodifiableSet(FLASH_FILE_EXTENSIONS);
  165.   }

  166. }