Skip to content
Snippets Groups Projects
Commit bb499f84 authored by Thorsten Vitt's avatar Thorsten Vitt
Browse files

Improved mime.types parser RE.

Previously, lines containing a comment at the end and lines starting
with whitespace were not recognized.

git-svn-id: https://develop.sub.uni-goettingen.de/repos/textgrid/trunk/services/aggregator@14095 7c539038-3410-0410-b1ec-0f2a7bf1c452
parent c1715592
No related branches found
No related tags found
No related merge requests found
...@@ -27,7 +27,12 @@ public class FileExtensionMap { ...@@ -27,7 +27,12 @@ public class FileExtensionMap {
private static Logger logger = Logger.getLogger(FileExtensionMap.class); private static Logger logger = Logger.getLogger(FileExtensionMap.class);
protected FileExtensionMap() throws IOException { protected FileExtensionMap() throws IOException {
final Pattern mapLine = Pattern.compile("^([^# \t]+)[ \t]*([^#]+)$");
// Comments start with # and reach to the end of line.
// A matching line contains of a mime type and one or more extensions
// comments are stripped
// <whitespace>? <mimetype>¹ <whitespace> <extensions>² <whitespace>? <comment>?
final Pattern mapLine = Pattern.compile("^[ \t]*([^# \t]+)[ \t]*([^#]+)[ \t]*(#.*)?$");
final Pattern space = Pattern.compile("[ \t]+"); final Pattern space = Pattern.compile("[ \t]+");
final LineNumberReader reader = new LineNumberReader( final LineNumberReader reader = new LineNumberReader(
new InputStreamReader(getClass().getClassLoader() new InputStreamReader(getClass().getClassLoader()
......
...@@ -25,6 +25,11 @@ public void testGetExtensions() { ...@@ -25,6 +25,11 @@ public void testGetExtensions() {
Assert.assertEquals("Wrong extensions for XHTML", Assert.assertEquals("Wrong extensions for XHTML",
ImmutableList.of("xhtml", "xht"), xhtml); ImmutableList.of("xhtml", "xht"), xhtml);
} }
@Test
public void testTextGridTypes() {
Assert.assertEquals("aggregation", ext.getFirstExtension("text/tg.aggregation+xml").orNull());
}
@Test @Test
public void testGetFirstExtension() { public void testGetFirstExtension() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment