-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from europeana/develop
## Add Rdf Format and common module
- Loading branch information
Showing
3 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
63 changes: 63 additions & 0 deletions
63
record-api-common/src/main/java/eu.europeana.api.format/RdfFormat.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |