Skip to content

Commit

Permalink
Merge pull request #4 from europeana/develop
Browse files Browse the repository at this point in the history
## Add Rdf Format and common module
  • Loading branch information
SrishtiSingh-eu committed Oct 18, 2023
2 parents 4a53d91 + 210f724 commit 6b96ced
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 0 deletions.
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<module>record-api-impl</module>
<module>record-api-mongo</module>
<module>record-api-web</module>
<module>record-api-common</module>
</modules>

<parent>
Expand Down
19 changes: 19 additions & 0 deletions record-api-common/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>record-api</artifactId>
<groupId>eu.europeana.api</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>record-api-common</artifactId>

<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
</properties>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package eu.europeana.api.format;

public enum RdfFormat {
JSONLD("jsonld", "json", "application/ld+json", "application/json"),
XML("rdf", "xml", "application/rdf+xml", "application/xml", "text/xml", "rdf/xml"),
TURTLE("ttl", null, "text/turtle", "application/turtle", "application/x-turtle"),
N3("n3", null, "text/n3", "text/rdf+n3", "application/n3"),
NT("nt", null, "application/n-triples", "application/ntriples", "text/nt");

private String extension;
private String alternative;
private String[] mediaTypes;

RdfFormat(String extension, String alternative, String... mediaTypes) {
this.extension = extension;
this.alternative = alternative;
this.mediaTypes = mediaTypes;
}

public static RdfFormat getFormatByExtension(String extension) {
for (RdfFormat format : RdfFormat.values()) {
if (format.acceptsExtension(extension)) {
return format;
}
}
return null;
}

public static RdfFormat getFormatByMediaType(String mediaType) {
for (RdfFormat format : RdfFormat.values()) {
if (format.acceptsMediaType(mediaType)) {
return format;
}
}
return null;
}

public String getExtension() {
return extension;
}

public String getAlternative() {
return alternative;
}

public String getMediaType() {
return mediaTypes[0];
}

public boolean acceptsExtension(String extension) {
return (this.extension.equals(extension)
|| (this.alternative != null && this.alternative.equals(extension)));
}

public boolean acceptsMediaType(String mediaType) {
for (String mType : mediaTypes) {
if (mType.equals(mediaType)) {
return true;
}
}
return false;
}
}

0 comments on commit 6b96ced

Please sign in to comment.