commonsrdf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From st...@apache.org
Subject [1/2] incubator-commonsrdf git commit: RDFSyntax adds fileExtension and supportsDataset
Date Mon, 28 Mar 2016 17:45:50 GMT
Repository: incubator-commonsrdf
Updated Branches:
  refs/heads/rdfsyntax-enum [created] 2ef97f162


RDFSyntax adds fileExtension and supportsDataset


Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/c896bf79
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/c896bf79
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/c896bf79

Branch: refs/heads/rdfsyntax-enum
Commit: c896bf79b27e8bdcb85b1b08b48a28776b767133
Parents: 1a63f48
Author: Stian Soiland-Reyes <stain@apache.org>
Authored: Mon Mar 28 18:34:21 2016 +0100
Committer: Stian Soiland-Reyes <stain@apache.org>
Committed: Mon Mar 28 18:34:21 2016 +0100

----------------------------------------------------------------------
 .../org/apache/commons/rdf/api/RDFSyntax.java   | 63 +++++++++++++---
 .../apache/commons/rdf/api/RDFSyntaxTest.java   | 77 +++++++++++++++-----
 2 files changed, 109 insertions(+), 31 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/c896bf79/api/src/main/java/org/apache/commons/rdf/api/RDFSyntax.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/RDFSyntax.java b/api/src/main/java/org/apache/commons/rdf/api/RDFSyntax.java
index c1b5ea1..9148cd2 100644
--- a/api/src/main/java/org/apache/commons/rdf/api/RDFSyntax.java
+++ b/api/src/main/java/org/apache/commons/rdf/api/RDFSyntax.java
@@ -25,7 +25,8 @@ import java.util.Optional;
  * <p>
  * This enumeration lists the W3C standardized 
  * RDF 1.1 syntaxes like {@link #TURTLE} and {@link #JSONLD}.  
- * Note the existence of other RDF syntaxes that are not included here, e.g. <a href="http://www.w3.org/TeamSubmission/n3/">N3</a>

+ * Note the existence of other RDF syntaxes that are not included here, 
+ * e.g. <a href="http://www.w3.org/TeamSubmission/n3/">N3</a> 
  * and <a href="https://en.wikipedia.org/wiki/TriX_%28syntax%29">TriX</a>.
  * 
  * @see <a href="https://www.w3.org/TR/rdf11-primer/#section-graph-syntax">RDF 1.1
Primer</a>
@@ -39,57 +40,57 @@ public enum RDFSyntax {
 	 * @see <a href="https://www.w3.org/TR/json-ld/">https://www.w3.org/TR/json-ld/</a>
 	 * 
 	 */
-	JSONLD("JSON-LD 1.0", "application/ld+json"),
+	JSONLD("JSON-LD 1.0", "application/ld+json", ".jsonld", true),
 
 	/**
 	 * RDF 1.1 Turtle
 	 * 
-	 * @see <a href="https://www.w3.org/TR/turtle/">RDF 1.1 Turtle</a>
+	 * @see <a href="https://www.w3.org/TR/turtle/">https://www.w3.org/TR/turtle/</a>
 	 *
 	 */
-	TURTLE("RDF 1.1 Turtle", "text/turtle"), 
+	TURTLE("RDF 1.1 Turtle", "text/turtle", ".ttl", false), 
 
 	/**
 	 * RDF 1.1 N-Quads
 	 * 
 	 * @see <a href="https://www.w3.org/TR/n-quads/">https://www.w3.org/TR/n-quads/</a>
 	 */
-	NQUADS("RDF 1.1 N-Quads", "application/n-quads"),
+	NQUADS("RDF 1.1 N-Quads", "application/n-quads", ".nq", true),
 
 	/**
 	 * RDF 1.1 N-Triples
 	 * 
 	 * @see <a href="https://www.w3.org/TR/n-triples/">https://www.w3.org/TR/n-triples/</a>
 	 */
-	NTRIPLES("RDF 1.1 N-Triples", "application/n-triples"),
+	NTRIPLES("RDF 1.1 N-Triples", "application/n-triples", ".nt", false),
 	
 	/**
 	 * HTML+RDFa 1.1
 	 * 
 	 * @see <a href="https://www.w3.org/TR/html-rdfa/">https://www.w3.org/TR/html-rdfa/</a>
 	 */
-	RDFA_HTML("HTML+RDFa 1.1", "text/html"),
+	RDFA_HTML("HTML+RDFa 1.1", "text/html", ".html", false),
 	
 	/**
 	 * XHTML+RDFa 1.1 
 	 * 
 	 * @see <a href="https://www.w3.org/TR/xhtml-rdfa/">https://www.w3.org/TR/xhtml-rdfa/</a>

 	 */
-	RDFA_XHTML("XHTML+RDFa 1.1", "application/xhtml+xml"),
+	RDFA_XHTML("XHTML+RDFa 1.1", "application/xhtml+xml", ".xhtml", false),
 	
 	/**
 	 * RDF 1.1 XML Syntax
 	 * 
 	 * @see <a href="https://www.w3.org/TR/rdf-syntax-grammar/">https://www.w3.org/TR/rdf-syntax-grammar/</a>
 	 */
-	RDFXML("RDF 1.1 XML Syntax", "application/rdf+xml"),
+	RDFXML("RDF 1.1 XML Syntax", "application/rdf+xml", ".rdf", false),
 	
 	/**
 	 * RDF 1.1 TriG
 	 * 
 	 * @see <a href="https://www.w3.org/TR/trig/">https://www.w3.org/TR/trig/</a>
 	 */
-	TRIG("RDF 1.1 TriG", "application/trig");
+	TRIG("RDF 1.1 TriG", "application/trig", ".trig", true);
 
 	/** 
 	 * The <a href="https://tools.ietf.org/html/rfc2046">IANA media type</a> for
the RDF syntax.
@@ -100,7 +101,19 @@ public enum RDFSyntax {
 	 * <a href="https://tools.ietf.org/html/rfc7231#section-3.1.1.1">HTTP protocol</a>.

 	 */
 	public final String mediaType;
-		
+	
+	/**
+	 * The <a href="https://tools.ietf.org/html/rfc2046">IANA-registered</a> file
extension.
+	 * <p>
+	 * The file extension includes the leading period, e.g. <code>.jsonld</code>
+	 */
+	public final String fileExtension;
+	
+	/**
+	 * Indicate if this RDF syntax supports <a href="https://www.w3.org/TR/rdf11-concepts/#section-dataset">RDF
Datasets</a>. 
+	 */
+	public final boolean supportsDataset;
+	
 	private final String name;
 	
 	/** 
@@ -113,9 +126,11 @@ public enum RDFSyntax {
 		return name;
 	}
 	
-	private RDFSyntax(String name, String mediaType) {
+	private RDFSyntax(String name, String mediaType, String fileExtension, boolean supportsDataset)
{
 		this.name = name;
 		this.mediaType = mediaType;
+		this.fileExtension = fileExtension;
+		this.supportsDataset = supportsDataset;
 	}
 	
 	/**
@@ -149,4 +164,28 @@ public enum RDFSyntax {
 		return Optional.empty();
 	}
 
+	/**
+	 * Return the RDFSyntax with the specified file extension.
+	 * <p>
+	 * The <code>fileExtension</code> is compared in lower case, therefore it
+	 * might not be equal to the {@link RDFSyntax#fileExtension} of the returned
+	 * RDFSyntax.
+	 * 
+	 * @param fileExtension
+	 *            The fileExtension to match, starting with <code>.</code>
+	 * @return If {@link Optional#isPresent()}, the {@link RDFSyntax} which has
+	 *         a matching {@link RDFSyntax#fileExtension}, otherwise
+	 *         {@link Optional#empty()} indicating that no matching file
+	 *         extension was found.
+	 */
+	public static Optional<RDFSyntax> byFileExtension(String fileExtension) {
+		fileExtension = fileExtension.toLowerCase(Locale.ENGLISH);
+		for (RDFSyntax syntax : RDFSyntax.values()) {
+			if (fileExtension.equals(syntax.fileExtension)) {
+				return Optional.of(syntax);
+			}
+		}
+		return Optional.empty();
+	}
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/c896bf79/api/src/test/java/org/apache/commons/rdf/api/RDFSyntaxTest.java
----------------------------------------------------------------------
diff --git a/api/src/test/java/org/apache/commons/rdf/api/RDFSyntaxTest.java b/api/src/test/java/org/apache/commons/rdf/api/RDFSyntaxTest.java
index 701545f..5781822 100644
--- a/api/src/test/java/org/apache/commons/rdf/api/RDFSyntaxTest.java
+++ b/api/src/test/java/org/apache/commons/rdf/api/RDFSyntaxTest.java
@@ -26,15 +26,30 @@ import org.junit.Test;
 public class RDFSyntaxTest {
 
 	@Test
-	public void mediaType() throws Exception {
-		assertEquals("application/ld+json", RDFSyntax.JSONLD.mediaType);
-		assertEquals("application/n-quads", RDFSyntax.NQUADS.mediaType);
-		assertEquals("application/n-triples", RDFSyntax.NTRIPLES.mediaType);
-		assertEquals("text/html", RDFSyntax.RDFA_HTML.mediaType);
-		assertEquals("application/xhtml+xml", RDFSyntax.RDFA_XHTML.mediaType);
-		assertEquals("application/rdf+xml", RDFSyntax.RDFXML.mediaType);
-		assertEquals("application/trig", RDFSyntax.TRIG.mediaType);
-		assertEquals("text/turtle", RDFSyntax.TURTLE.mediaType);
+	public void byFileExtension() throws Exception {
+		assertEquals(RDFSyntax.JSONLD, RDFSyntax.byFileExtension(".jsonld").get());
+		assertEquals(RDFSyntax.NQUADS, RDFSyntax.byFileExtension(".nq").get());
+		assertEquals(RDFSyntax.NTRIPLES, RDFSyntax.byFileExtension(".nt").get());
+		assertEquals(RDFSyntax.RDFA_HTML, RDFSyntax.byFileExtension(".html").get());
+		assertEquals(RDFSyntax.RDFA_XHTML, RDFSyntax.byFileExtension(".xhtml").get());
+		assertEquals(RDFSyntax.RDFXML, RDFSyntax.byFileExtension(".rdf").get());
+		assertEquals(RDFSyntax.TRIG, RDFSyntax.byFileExtension(".trig").get());
+		assertEquals(RDFSyntax.TURTLE, RDFSyntax.byFileExtension(".ttl").get());
+	}
+
+	@Test
+	public void byFileExtensionFailsWithoutDot() throws Exception {
+		assertEquals(Optional.empty(), RDFSyntax.byFileExtension("rdf"));
+	}
+
+	@Test
+	public void byFileExtensionLowerCase() throws Exception {
+		assertEquals(RDFSyntax.TURTLE, RDFSyntax.byFileExtension(".TtL").get());
+	}
+
+	@Test
+	public void byFileExtensionUnknown() throws Exception {
+		assertEquals(Optional.empty(), RDFSyntax.byFileExtension(".tar"));
 	}
 
 	@Test
@@ -50,9 +65,16 @@ public class RDFSyntaxTest {
 	}
 
 	@Test
-	public void name() throws Exception {
-		assertEquals("JSON-LD 1.0", RDFSyntax.JSONLD.toString());
-		assertEquals("RDF 1.1 Turtle", RDFSyntax.TURTLE.toString());
+	public void byMediaTypeContentType() throws Exception {
+		assertEquals(RDFSyntax.TURTLE, RDFSyntax.byMediaType("text/turtle; charset=\"UTF-8\"").get());
+		assertEquals(RDFSyntax.TURTLE, RDFSyntax.byMediaType("text/turtle ; charset=\"UTF-8\"").get());
+		assertEquals(RDFSyntax.TURTLE, RDFSyntax.byMediaType("text/turtle, text/plain").get());
+		assertEquals(Optional.empty(), RDFSyntax.byMediaType(" text/turtle"));
+	}
+
+	@Test
+	public void byMediaTypeLowerCase() throws Exception {
+		assertEquals(RDFSyntax.JSONLD, RDFSyntax.byMediaType("APPLICATION/ld+JSON").get());
 	}
 
 	@Test
@@ -61,16 +83,33 @@ public class RDFSyntaxTest {
 	}
 
 	@Test
-	public void byMediaTypeLowerCase() throws Exception {
-		assertEquals(RDFSyntax.JSONLD, RDFSyntax.byMediaType("APPLICATION/ld+JSON").get());
+	public void fileExtension() throws Exception {
+		assertEquals(".jsonld", RDFSyntax.JSONLD.fileExtension);
+		assertEquals(".nq", RDFSyntax.NQUADS.fileExtension);
+		assertEquals(".nt", RDFSyntax.NTRIPLES.fileExtension);
+		assertEquals(".html", RDFSyntax.RDFA_HTML.fileExtension);
+		assertEquals(".xhtml", RDFSyntax.RDFA_XHTML.fileExtension);
+		assertEquals(".rdf", RDFSyntax.RDFXML.fileExtension);
+		assertEquals(".trig", RDFSyntax.TRIG.fileExtension);
+		assertEquals(".ttl", RDFSyntax.TURTLE.fileExtension);
 	}
 
 	@Test
-	public void byMediaTypeContentType() throws Exception {
-		assertEquals(RDFSyntax.TURTLE, RDFSyntax.byMediaType("text/turtle; charset=\"UTF-8\"").get());
-		assertEquals(RDFSyntax.TURTLE, RDFSyntax.byMediaType("text/turtle ; charset=\"UTF-8\"").get());
-		assertEquals(RDFSyntax.TURTLE, RDFSyntax.byMediaType("text/turtle, text/plain").get());
-		assertEquals(Optional.empty(), RDFSyntax.byMediaType(" text/turtle"));
+	public void mediaType() throws Exception {
+		assertEquals("application/ld+json", RDFSyntax.JSONLD.mediaType);
+		assertEquals("application/n-quads", RDFSyntax.NQUADS.mediaType);
+		assertEquals("application/n-triples", RDFSyntax.NTRIPLES.mediaType);
+		assertEquals("text/html", RDFSyntax.RDFA_HTML.mediaType);
+		assertEquals("application/xhtml+xml", RDFSyntax.RDFA_XHTML.mediaType);
+		assertEquals("application/rdf+xml", RDFSyntax.RDFXML.mediaType);
+		assertEquals("application/trig", RDFSyntax.TRIG.mediaType);
+		assertEquals("text/turtle", RDFSyntax.TURTLE.mediaType);
+	}
+
+	@Test
+	public void name() throws Exception {
+		assertEquals("JSON-LD 1.0", RDFSyntax.JSONLD.toString());
+		assertEquals("RDF 1.1 Turtle", RDFSyntax.TURTLE.toString());
 	}
 
 }


Mime
View raw message