Skip to content

Commit

Permalink
Minor media handling improvements.
Browse files Browse the repository at this point in the history
  • Loading branch information
noboomu committed Sep 5, 2019
1 parent 171b039 commit b180b7d
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion core/src/main/java/io/sinistral/proteus/server/MediaType.java
Original file line number Diff line number Diff line change
Expand Up @@ -1038,14 +1038,14 @@ public class MediaType
public static final MediaType MODEL_X3D_XML = create("model/x3d+xml", "x3d", "x3dz");
public static final MediaType TEXT_CACHE_MANIFEST = create("text/cache-manifest", "appcache", "manifest");
public static final MediaType TEXT_CALENDAR = create("text/calendar", "ics", "icz", "ifb");

public static final MediaType TEXT_CSS_UTF8 = createUTF8("text/css", "css");
public static final MediaType TEXT_CSV_UTF8 = createUTF8("text/csv", "csv");
public static final MediaType TEXT_H323 = create("text/h323", "323");
public static final MediaType TEXT_HTML_UTF8 = createUTF8("text/html", "html", "htm", "shtml");
public static final MediaType TEXT_IULS = create("text/iuls", "uls");
public static final MediaType TEXT_MATHML = create("text/mathml", "mml");
public static final MediaType TEXT_N3 = create("text/n3", "n3");
public static final MediaType TEXT_PLAIN = create("text/plain");
public static final MediaType TEXT_PLAIN_UTF8 = createUTF8("text/plain", "asc", "txt", "text", "conf", "def",
"pot", "brf", "LIST", "LOG", "IN");
public static final MediaType TEXT_PRS_LINES_TAG = create("text/prs.lines.tag", "dsc");
Expand Down Expand Up @@ -1201,12 +1201,18 @@ public static synchronized MediaType create(String type, String[] attributes, St

public static synchronized MediaType createUTF8(String type, String... fileExtensisons)
{
for (String ext : fileExtensisons) {
if(!FILE_EXTENSIONS.containsKey(ext)) {
FILE_EXTENSIONS.put(ext, create(type, fileExtensisons));
}
}
return create(type, UTF8_ATTR, fileExtensisons);
}

public static synchronized MediaType getByFileExtension(String fileExtension)
{
return FILE_EXTENSIONS.get(fileExtension);

}

public static synchronized MediaType getByFileName(String filename)
Expand Down Expand Up @@ -1292,6 +1298,11 @@ public String subType()
return this.contentType.substring(this.contentType.lastIndexOf("/") + 1, Math.max(this.contentType.lastIndexOf(";"),this.contentType.length()));
}

public String baseType()
{
return this.contentType.substring(0,this.contentType.lastIndexOf(";"));
}

private static final Map<String,MediaType> TYPE_MAP = new HashMap<>();

private static final Map<MediaType,List<String>> EXTENSION_MAP = new HashMap<>();
Expand Down Expand Up @@ -1373,4 +1384,5 @@ public String info()

return toString();
}

}

0 comments on commit b180b7d

Please sign in to comment.