commonsrdf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From st...@apache.org
Subject [29/33] incubator-commonsrdf git commit: Added JenaRDFParserBuilder
Date Mon, 28 Mar 2016 04:55:25 GMT
Added JenaRDFParserBuilder


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

Branch: refs/heads/jena
Commit: 8088d1c9408563f0cf29fbd0e8fef5b01af51db1
Parents: 9029396
Author: Stian Soiland-Reyes <stain@apache.org>
Authored: Mon Mar 28 05:40:28 2016 +0100
Committer: Stian Soiland-Reyes <stain@apache.org>
Committed: Mon Mar 28 05:40:28 2016 +0100

----------------------------------------------------------------------
 jena/pom.xml                                    |  9 +++++
 .../apache/commons/rdf/jena/JenaCommonsRDF.java | 12 ++++++
 .../commons/rdf/jena/JenaRDFParserBuilder.java  | 40 ++++++++++++++++++++
 .../commons/rdf/jena/RDFTermFactoryJena.java    |  2 +-
 4 files changed, 62 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/8088d1c9/jena/pom.xml
----------------------------------------------------------------------
diff --git a/jena/pom.xml b/jena/pom.xml
index 2a1abbf..e0c4efc 100644
--- a/jena/pom.xml
+++ b/jena/pom.xml
@@ -46,9 +46,18 @@
         </dependency>
 	    <dependency>
 	      <groupId>org.apache.jena</groupId>
+	      <artifactId>apache-jena-libs</artifactId>
+	      <version>${ver.jena}</version>
+	      <type>pom</type>
+	      <scope>optional</scope>
+	    </dependency>        
+<!-- 
+	    <dependency>
+	      <groupId>org.apache.jena</groupId>
 	      <artifactId>jena-osgi</artifactId>
 	      <version>${ver.jena}</version>
 	    </dependency>        
+ -->
         <dependency>
             <groupId>${project.parent.groupId}</groupId>
             <artifactId>commons-rdf-api</artifactId>

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/8088d1c9/jena/src/main/java/org/apache/commons/rdf/jena/JenaCommonsRDF.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/JenaCommonsRDF.java b/jena/src/main/java/org/apache/commons/rdf/jena/JenaCommonsRDF.java
index 8bf8b6d..881b176 100644
--- a/jena/src/main/java/org/apache/commons/rdf/jena/JenaCommonsRDF.java
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/JenaCommonsRDF.java
@@ -18,12 +18,17 @@
 
 package org.apache.commons.rdf.jena;
 
+import java.util.Optional;
+
 import org.apache.commons.rdf.api.* ;
 import org.apache.commons.rdf.jena.impl.*;
 import org.apache.jena.datatypes.RDFDatatype ;
 import org.apache.jena.datatypes.xsd.XSDDatatype ;
 import org.apache.jena.graph.Node ;
 import org.apache.jena.graph.NodeFactory ;
+import org.apache.jena.riot.Lang;
+import org.apache.jena.riot.RDFDataMgr;
+import org.apache.jena.riot.RDFLanguages;
 import org.apache.jena.riot.system.StreamRDF ;
 import org.apache.jena.sparql.graph.GraphFactory ;
 
@@ -163,5 +168,12 @@ public class JenaCommonsRDF {
    public static void conversionError(String msg) {
         throw new ConversionException(msg) ;
     }
+
+   public static Optional<Lang> rdfSyntaxToLang(RDFSyntax rdfSyntax) {
+	   return Optional.ofNullable(RDFLanguages.contentTypeToLang(rdfSyntax.mediaType));	
+   }
+   public static Optional<RDFSyntax> langToRdfSyntax(Lang lang) {
+	   return RDFSyntax.byMediaType(lang.getContentType().getContentType());
+   }
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/8088d1c9/jena/src/main/java/org/apache/commons/rdf/jena/JenaRDFParserBuilder.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/JenaRDFParserBuilder.java b/jena/src/main/java/org/apache/commons/rdf/jena/JenaRDFParserBuilder.java
new file mode 100644
index 0000000..13af108
--- /dev/null
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/JenaRDFParserBuilder.java
@@ -0,0 +1,40 @@
+package org.apache.commons.rdf.jena;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.file.Files;
+import java.text.ParseException;
+
+import org.apache.commons.rdf.api.IRI;
+import org.apache.commons.rdf.api.RDFParserBuilder;
+import org.apache.commons.rdf.api.RDFTermFactory;
+import org.apache.commons.rdf.simple.AbstractRDFParserBuilder;
+import org.apache.jena.riot.Lang;
+import org.apache.jena.riot.RDFDataMgr;
+import org.apache.jena.riot.system.StreamRDF;
+
+public class JenaRDFParserBuilder extends AbstractRDFParserBuilder implements RDFParserBuilder
{
+
+	protected RDFTermFactory createRDFTermFactory() {
+		return new RDFTermFactoryJena();
+	}
+
+	@Override
+	protected void parseSynchronusly() throws IOException, IllegalStateException, ParseException
{
+		StreamRDF dest = JenaCommonsRDF.streamJenaToCommonsRDF(rdfTermFactory.get(), intoGraph.get());
+
+		Lang lang = contentTypeSyntax.flatMap(JenaCommonsRDF::rdfSyntaxToLang).orElse(null);
+		String baseStr = base.map(IRI::getIRIString).orElse(null);
+
+		if (sourceIri.isPresent()) {
+			RDFDataMgr.parse(dest, sourceIri.get().toString(), baseStr, lang, null);
+		} else if (sourceFile.isPresent()) {
+			try (InputStream s = Files.newInputStream(sourceFile.get())) {
+				RDFDataMgr.parse(dest, s, baseStr, lang, null);
+			}
+		} else {
+			RDFDataMgr.parse(dest, sourceInputStream.get(), baseStr, lang, null);
+		}
+	}
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/8088d1c9/jena/src/main/java/org/apache/commons/rdf/jena/RDFTermFactoryJena.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/RDFTermFactoryJena.java b/jena/src/main/java/org/apache/commons/rdf/jena/RDFTermFactoryJena.java
index 08572c1..3d73459 100644
--- a/jena/src/main/java/org/apache/commons/rdf/jena/RDFTermFactoryJena.java
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/RDFTermFactoryJena.java
@@ -26,7 +26,7 @@ import org.apache.commons.rdf.jena.impl.JCR_Factory;
  *  
  *  @see RDFTermFactory
  */
-public class RDFTermFactoryJena implements RDFTermFactory {
+public final class RDFTermFactoryJena implements RDFTermFactory {
     
     @Override
     public BlankNode createBlankNode() {


Mime
View raw message