You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MediaTypes.java 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2023 SonarSource SA
  4. * mailto:info AT sonarsource DOT com
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 3 of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with this program; if not, write to the Free Software Foundation,
  18. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. package org.sonarqube.ws;
  21. import java.util.HashMap;
  22. import java.util.Locale;
  23. import java.util.Map;
  24. import static org.sonarqube.ws.WsUtils.isNullOrEmpty;
  25. /**
  26. * @since 5.3
  27. */
  28. public final class MediaTypes {
  29. public static final String CSV = "text/csv";
  30. public static final String DEFAULT = "application/octet-stream";
  31. public static final String HTML = "text/html";
  32. public static final String JAVASCRIPT = "text/javascript";
  33. public static final String JSON = "application/json";
  34. public static final String PROTOBUF = "application/x-protobuf";
  35. public static final String SVG = "image/svg+xml";
  36. public static final String TXT = "text/plain";
  37. public static final String XML = "application/xml";
  38. public static final String ZIP = "application/zip";
  39. private static final String BMP = "image/bmp";
  40. private static final String CSS = "text/css";
  41. private static final String DTD = "application/xml-dtd";
  42. private static final String GIF = "image/gif";
  43. private static final String ICO = "image/x-icon";
  44. private static final String JAR = "application/java-archive";
  45. private static final String JNLP = "application/jnlp";
  46. private static final String JPEG = "image/jpeg";
  47. private static final String JPG = "image/jpeg";
  48. private static final String PNG = "image/png";
  49. private static final String POSTSCRIPT = "application/postscript";
  50. private static final String PPT = "application/vnd.ms-powerpoint";
  51. private static final String RTF = "text/rtf";
  52. private static final String TAR = "application/x-tar";
  53. private static final String TIFF = "image/tiff";
  54. private static final String TGZ = "application/tgz";
  55. private static final String TSV = "text/tab-separated-values";
  56. private static final String XLS = "application/vnd.ms-excel";
  57. private static final String XSLT = "application/xslt+xml";
  58. private static final Map<String, String> MAP;
  59. static {
  60. MAP = new HashMap<>(27);
  61. MAP.put("js", JAVASCRIPT);
  62. MAP.put("json", JSON);
  63. MAP.put("zip", ZIP);
  64. MAP.put("tgz", TGZ);
  65. MAP.put("ps", POSTSCRIPT);
  66. MAP.put("jnlp", JNLP);
  67. MAP.put("jar", JAR);
  68. MAP.put("xls", XLS);
  69. MAP.put("ppt", PPT);
  70. MAP.put("tar", TAR);
  71. MAP.put("xml", XML);
  72. MAP.put("dtd", DTD);
  73. MAP.put("xslt", XSLT);
  74. MAP.put("bmp", BMP);
  75. MAP.put("gif", GIF);
  76. MAP.put("jpg", JPG);
  77. MAP.put("jpeg", JPEG);
  78. MAP.put("tiff", TIFF);
  79. MAP.put("png", PNG);
  80. MAP.put("svg", SVG);
  81. MAP.put("ico", ICO);
  82. MAP.put("txt", TXT);
  83. MAP.put("csv", CSV);
  84. MAP.put("properties", TXT);
  85. MAP.put("rtf", RTF);
  86. MAP.put("html", HTML);
  87. MAP.put("css", CSS);
  88. MAP.put("tsv", TSV);
  89. }
  90. private MediaTypes() {
  91. // only static methods
  92. }
  93. public static String getByFilename(String filename) {
  94. String extension = FilenameUtils.getExtension(filename);
  95. String mime = null;
  96. if (!isNullOrEmpty(extension)) {
  97. mime = MAP.get(extension.toLowerCase(Locale.ENGLISH));
  98. }
  99. return mime != null ? mime : DEFAULT;
  100. }
  101. }