Skip to content

Commit 4410a07

Browse files
committed
[feature] New approach to Internet Media Type configuration, mapping, and resolution
1 parent 4b3dc2f commit 4410a07

File tree

34 files changed

+3385
-84
lines changed

34 files changed

+3385
-84
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
4+
Copyright (C) 2014, Evolved Binary Ltd
5+
6+
This file was originally ported from FusionDB to Elemental by
7+
Evolved Binary, for the benefit of the Elemental Open Source community.
8+
Only the ported code as it appears in this file, at the time that
9+
it was contributed to Elemental, was re-licensed under The GNU
10+
Lesser General Public License v2.1 only for use in Elemental.
11+
12+
This license grant applies only to a snapshot of the code as it
13+
appeared when ported, it does not offer or infer any rights to either
14+
updates of this source code or access to the original source code.
15+
16+
The GNU Lesser General Public License v2.1 only license follows.
17+
18+
=====================================================================
19+
20+
Elemental
21+
Copyright (C) 2024, Evolved Binary Ltd
22+
23+
24+
https://www.evolvedbinary.com | https://www.elemental.xyz
25+
26+
This library is free software; you can redistribute it and/or
27+
modify it under the terms of the GNU Lesser General Public
28+
License as published by the Free Software Foundation; version 2.1.
29+
30+
This library is distributed in the hope that it will be useful,
31+
but WITHOUT ANY WARRANTY; without even the implied warranty of
32+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
33+
Lesser General Public License for more details.
34+
35+
You should have received a copy of the GNU Lesser General Public
36+
License along with this library; if not, write to the Free Software
37+
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
38+
39+
-->
40+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
41+
<modelVersion>4.0.0</modelVersion>
42+
43+
<parent>
44+
<groupId>xyz.elemental</groupId>
45+
<artifactId>elemental-media-type</artifactId>
46+
<version>7.5.0-SNAPSHOT</version>
47+
<relativePath>..</relativePath>
48+
</parent>
49+
50+
<artifactId>elemental-media-type-api</artifactId>
51+
52+
<name>Elemental Internet Media Type Resolver API</name>
53+
<description>Internet Media Type Resolver API for Elemental</description>
54+
55+
<scm>
56+
<connection>scm:git:https://github.com/evolvedbinary/elemental.git</connection>
57+
<developerConnection>scm:git:https://github.com/evolvedbinary/elemental.git</developerConnection>
58+
<url>scm:git:https://github.com/evolvedbinary/elemental.git</url>
59+
</scm>
60+
61+
<dependencies>
62+
<dependency>
63+
<groupId>com.google.code.findbugs</groupId>
64+
<artifactId>jsr305</artifactId>
65+
</dependency>
66+
</dependencies>
67+
68+
<build>
69+
<plugins>
70+
<plugin>
71+
<groupId>com.mycila</groupId>
72+
<artifactId>license-maven-plugin</artifactId>
73+
<configuration>
74+
<licenseSets>
75+
<licenseSet>
76+
<header>${project.parent.relativePath}/../elemental-parent/FDB-backport-to-EDB-LGPL-21-ONLY-license.template.txt</header>
77+
</licenseSet>
78+
</licenseSets>
79+
</configuration>
80+
</plugin>
81+
</plugins>
82+
</build>
83+
84+
</project>
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
/*
2+
* Copyright (C) 2014, Evolved Binary Ltd
3+
*
4+
* This file was originally ported from FusionDB to Elemental by
5+
* Evolved Binary, for the benefit of the Elemental Open Source community.
6+
* Only the ported code as it appears in this file, at the time that
7+
* it was contributed to Elemental, was re-licensed under The GNU
8+
* Lesser General Public License v2.1 only for use in Elemental.
9+
*
10+
* This license grant applies only to a snapshot of the code as it
11+
* appeared when ported, it does not offer or infer any rights to either
12+
* updates of this source code or access to the original source code.
13+
*
14+
* The GNU Lesser General Public License v2.1 only license follows.
15+
*
16+
* =====================================================================
17+
*
18+
* Elemental
19+
* Copyright (C) 2024, Evolved Binary Ltd
20+
*
21+
22+
* https://www.evolvedbinary.com | https://www.elemental.xyz
23+
*
24+
* This library is free software; you can redistribute it and/or
25+
* modify it under the terms of the GNU Lesser General Public
26+
* License as published by the Free Software Foundation; version 2.1.
27+
*
28+
* This library is distributed in the hope that it will be useful,
29+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
30+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
31+
* Lesser General Public License for more details.
32+
*
33+
* You should have received a copy of the GNU Lesser General Public
34+
* License along with this library; if not, write to the Free Software
35+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
36+
*/
37+
package xyz.elemental.mediatype;
38+
39+
import javax.annotation.Nullable;
40+
41+
/**
42+
* Information about a Media Type (aka MIME Type)
43+
* and how resources of that type should be stored into
44+
* the database.
45+
*
46+
* @author <a href="mailto:[email protected]">Adam Retter</a>
47+
*/
48+
public interface MediaType {
49+
50+
/**
51+
* Get the identifier of the Media Type.
52+
*
53+
* For example {@code application/xml}.
54+
*
55+
* @return the identifier of the Media Type
56+
*/
57+
String getIdentifier();
58+
59+
/**
60+
* Get the file extensions that are known
61+
* to be associated with the Media Type.
62+
*
63+
* @return the known file extensions associated with the Media Type, or null if there are none
64+
*/
65+
@Nullable String[] getKnownFileExtensions();
66+
67+
/**
68+
* Get the database storage type that should
69+
* be used for resources of this Media Type.
70+
*
71+
* @return the database storage type of the Media Type
72+
*/
73+
StorageType getStorageType();
74+
75+
// <editor-fold desc="List of common Media Type Identifiers">
76+
String APPLICATION_BZIP2 = "application/x-bzip2";
77+
String APPLICATION_EXISTDB_COLLECTION_CONFIG_XML = "application/prs.existdb.collection-config+xml";
78+
String APPLICATION_EXPATH_PACKAGE_ZIP = "application/prs.expath.package+zip";
79+
String APPLICATION_GZIP = "application/gzip";
80+
String APPLICATION_JAVA_ARCHIVE = "application/java-archive";
81+
String APPLICATION_JSON = "application/json";
82+
String APPLICATION_OCTET_STREAM = "application/octet-stream";
83+
String APPLICATION_PDF = "application/pdf";
84+
String APPLICATION_RELAXNG_COMPACT = "application/relax-ng-compact-syntax";
85+
String APPLICATION_TAR = "application/x-tar";
86+
String APPLICATION_WWW_FORM_URLENCODED = "application/x-www-form-urlencoded";
87+
String APPLICATION_XML = "application/xml";
88+
String APPLICATION_XML_DTD = "application/xml-dtd";
89+
String APPLICATION_XHTML_XML = "application/xhtml+xml";
90+
String APPLICATION_XPROC_XML = "application/xproc+xml";
91+
String APPLICATION_XSLT_XML = "application/xslt+xml";
92+
String APPLICATION_XQUERY = "application/xquery";
93+
String APPLICATION_XZ = "application/x-xz";
94+
String APPLICATION_ZIP = "application/zip";
95+
String APPLICATION_ZSTD = "application/zstd";
96+
97+
String TEXT_CSV = "text/csv";
98+
String TEXT_CSV_SCHEMA = "text/csv-schema";
99+
String TEXT_INVISIBLE_XML = "text/prs.ixml.grammar";
100+
String TEXT_HTML = "text/html";
101+
String TEXT_JAVASCRIPT = "text/javascript";
102+
String TEXT_MARKDOWN = "text/markdown";
103+
String TEXT_PLAIN = "text/plain";
104+
String TEXT_URI_LIST = "text/uri-list";
105+
// </editor-fold>
106+
}
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
/*
2+
* Copyright (C) 2014, Evolved Binary Ltd
3+
*
4+
* This file was originally ported from FusionDB to Elemental by
5+
* Evolved Binary, for the benefit of the Elemental Open Source community.
6+
* Only the ported code as it appears in this file, at the time that
7+
* it was contributed to Elemental, was re-licensed under The GNU
8+
* Lesser General Public License v2.1 only for use in Elemental.
9+
*
10+
* This license grant applies only to a snapshot of the code as it
11+
* appeared when ported, it does not offer or infer any rights to either
12+
* updates of this source code or access to the original source code.
13+
*
14+
* The GNU Lesser General Public License v2.1 only license follows.
15+
*
16+
* =====================================================================
17+
*
18+
* Elemental
19+
* Copyright (C) 2024, Evolved Binary Ltd
20+
*
21+
22+
* https://www.evolvedbinary.com | https://www.elemental.xyz
23+
*
24+
* This library is free software; you can redistribute it and/or
25+
* modify it under the terms of the GNU Lesser General Public
26+
* License as published by the Free Software Foundation; version 2.1.
27+
*
28+
* This library is distributed in the hope that it will be useful,
29+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
30+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
31+
* Lesser General Public License for more details.
32+
*
33+
* You should have received a copy of the GNU Lesser General Public
34+
* License along with this library; if not, write to the Free Software
35+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
36+
*/
37+
package xyz.elemental.mediatype;
38+
39+
import javax.annotation.Nullable;
40+
import java.nio.file.Path;
41+
42+
/**
43+
* Finds Media Types for resources.
44+
*
45+
* @author <a href="mailto:[email protected]">Adam Retter</a>
46+
*/
47+
public interface MediaTypeResolver {
48+
49+
/**
50+
* Resolve the Media Type for the filename.
51+
*
52+
* @param path the Path containing the filename.
53+
*
54+
* @return The MediaType for the filename, or null if there is no known or configured media type
55+
*/
56+
@Nullable MediaType fromFileName(@Nullable final Path path);
57+
58+
/**
59+
* Resolve the MediaType for the filename.
60+
*
61+
* @param path the file path containing the filename.
62+
*
63+
* @return The MediaType for the filename, or null if there is no known or configured media type.
64+
*/
65+
@Nullable MediaType fromFileName(@Nullable final String path);
66+
67+
/**
68+
* Resolve the MediaType from the name/identifier
69+
* of the media type.
70+
*
71+
* @param mediaType the name/identifier of the media type.
72+
*
73+
* @return The MediaType for the name/identifier, or null if the media type is unknown.
74+
*/
75+
@Nullable MediaType fromString(@Nullable final String mediaType);
76+
77+
/**
78+
* Returns the MediaType to be used for
79+
* unknown types of resources.
80+
*
81+
* This is typically used as a catch-all.
82+
*
83+
* @return the MediaType to use for unknown
84+
* types of resources.
85+
*/
86+
MediaType forUnknown();
87+
88+
/**
89+
* The Instantiation Exception is thrown
90+
* if an error occurs when the factory
91+
* tries to instantiate a new Media Type Resolver.
92+
*/
93+
class InstantiationException extends Exception {
94+
public InstantiationException(final String message) {
95+
super(message);
96+
}
97+
98+
public InstantiationException(final String message, final Throwable cause) {
99+
super(message, cause);
100+
}
101+
102+
public InstantiationException(final Throwable cause) {
103+
super(cause);
104+
}
105+
}
106+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
* Copyright (C) 2014, Evolved Binary Ltd
3+
*
4+
* This file was originally ported from FusionDB to Elemental by
5+
* Evolved Binary, for the benefit of the Elemental Open Source community.
6+
* Only the ported code as it appears in this file, at the time that
7+
* it was contributed to Elemental, was re-licensed under The GNU
8+
* Lesser General Public License v2.1 only for use in Elemental.
9+
*
10+
* This license grant applies only to a snapshot of the code as it
11+
* appeared when ported, it does not offer or infer any rights to either
12+
* updates of this source code or access to the original source code.
13+
*
14+
* The GNU Lesser General Public License v2.1 only license follows.
15+
*
16+
* =====================================================================
17+
*
18+
* Elemental
19+
* Copyright (C) 2024, Evolved Binary Ltd
20+
*
21+
22+
* https://www.evolvedbinary.com | https://www.elemental.xyz
23+
*
24+
* This library is free software; you can redistribute it and/or
25+
* modify it under the terms of the GNU Lesser General Public
26+
* License as published by the Free Software Foundation; version 2.1.
27+
*
28+
* This library is distributed in the hope that it will be useful,
29+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
30+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
31+
* Lesser General Public License for more details.
32+
*
33+
* You should have received a copy of the GNU Lesser General Public
34+
* License along with this library; if not, write to the Free Software
35+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
36+
*/
37+
package xyz.elemental.mediatype;
38+
39+
import javax.annotation.Nullable;
40+
import java.nio.file.Path;
41+
import xyz.elemental.mediatype.MediaTypeResolver.InstantiationException;
42+
43+
/**
44+
* Factory for instantiating Media Type Resolvers.
45+
*
46+
* @author <a href="mailto:[email protected]">Adam Retter</a>
47+
*/
48+
public interface MediaTypeResolverFactory {
49+
50+
/**
51+
* Instantiate a new Media Type Resolver.
52+
*
53+
* @return a new Media Type Resolver.
54+
*
55+
* @throws InstantiationException if an error occurs
56+
* whilst instantiating the MediaTypeResolver.
57+
*/
58+
MediaTypeResolver newMediaTypeResolver()
59+
throws InstantiationException;
60+
61+
/**
62+
* Instantiate a new Media Type Resolver.
63+
*
64+
* @param configDirs paths to directories which contain configuration
65+
* files for the media type resolver.
66+
*
67+
* @return a new Media Type Resolver.
68+
*
69+
* @throws InstantiationException if an error occurs
70+
* whilst instantiating the MediaTypeResolver.
71+
*/
72+
MediaTypeResolver newMediaTypeResolver(@Nullable final Path... configDirs)
73+
throws InstantiationException;
74+
75+
}

0 commit comments

Comments
 (0)