commonsrdf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From st...@apache.org
Subject incubator-commonsrdf git commit: Escape BlankNode labels - if needed
Date Tue, 03 May 2016 22:27:11 GMT
Repository: incubator-commonsrdf
Updated Branches:
  refs/heads/rdf4j b58505747 -> c3ee194a4


Escape BlankNode labels - if needed


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

Branch: refs/heads/rdf4j
Commit: c3ee194a4f380660d2c878226ae5f51527e7f69c
Parents: b585057
Author: Stian Soiland-Reyes <stain@apache.org>
Authored: Tue May 3 23:27:05 2016 +0100
Committer: Stian Soiland-Reyes <stain@apache.org>
Committed: Tue May 3 23:27:05 2016 +0100

----------------------------------------------------------------------
 .../commons/rdf/rdf4j/Rdf4JRDFTermFactory.java  | 24 ++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/c3ee194a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/Rdf4JRDFTermFactory.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/Rdf4JRDFTermFactory.java b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/Rdf4JRDFTermFactory.java
index 9c0007c..9619299 100644
--- a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/Rdf4JRDFTermFactory.java
+++ b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/Rdf4JRDFTermFactory.java
@@ -17,6 +17,7 @@
  */
 package org.apache.commons.rdf.rdf4j;
 
+import java.nio.charset.StandardCharsets;
 import java.util.Objects;
 import java.util.Optional;
 import java.util.UUID;
@@ -298,8 +299,27 @@ public class Rdf4JRDFTermFactory implements RDFTermFactory {
 		
 		@Override
 		public String ntriplesString() {
-			// FIXME: Don't expose value.getID() if it's not valid ntriplesString();
-			return "_:" + value.getID();
+			if (isValidBlankNodeLabel(value.getID())) { 
+				return "_:" + value.getID();
+			} else {
+				return "_:" + UUID.nameUUIDFromBytes(value.getID().getBytes(StandardCharsets.UTF_8));
+			}
+		}
+
+		private boolean isValidBlankNodeLabel(String id) {
+			// FIXME: Replace with a regular expression?			
+			if (id.isEmpty()) { 
+				return false;
+			}
+			if (! TurtleUtil.isBLANK_NODE_LABEL_StartChar(id.codePointAt(0)))  {
+				return false;
+			}
+			for (int i=1; i<id.length(); i++) { 
+				if (! TurtleUtil.isBLANK_NODE_LABEL_Char(id.codePointAt(i))) { 
+					return false;
+				}
+			}
+			return true;
 		}
 
 		@Override


Mime
View raw message