You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by an...@apache.org on 2015/05/23 21:46:46 UTC

[1/3] jena git commit: Reformat

Repository: jena
Updated Branches:
  refs/heads/master 2d07790f2 -> 575a2b417


Reformat

Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/3cebc515
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/3cebc515
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/3cebc515

Branch: refs/heads/master
Commit: 3cebc515086ca3376bdb35ad1fc437bf38a828ba
Parents: 2d07790
Author: Andy Seaborne <an...@apache.org>
Authored: Sat May 23 20:16:14 2015 +0100
Committer: Andy Seaborne <an...@apache.org>
Committed: Sat May 23 20:16:14 2015 +0100

----------------------------------------------------------------------
 .../org/apache/jena/riot/system/RiotChars.java  | 44 +++++++++++---------
 1 file changed, 24 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/3cebc515/jena-arq/src/main/java/org/apache/jena/riot/system/RiotChars.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/riot/system/RiotChars.java b/jena-arq/src/main/java/org/apache/jena/riot/system/RiotChars.java
index a1ac83d..927a932 100644
--- a/jena-arq/src/main/java/org/apache/jena/riot/system/RiotChars.java
+++ b/jena-arq/src/main/java/org/apache/jena/riot/system/RiotChars.java
@@ -73,8 +73,7 @@ PN_LOCAL       ::=  ( PN_CHARS_U | [0-9] ) ((PN_CHARS|'.')* PN_CHARS)?
 Notes: PN_CHARS_BASE has a hole above #xD800 -- these are the  surrogate pairs 
      */
     
-    public static boolean isPNCharsBase(int ch)
-    {
+    public static boolean isPNCharsBase(int ch) {
         // PN_CHARS_BASE ::= [A-Z] | [a-z] | [#x00C0-#x00D6] | [#x00D8-#x00F6] | [#x00F8-#x02FF] | 
         //                   [#x0370-#x037D] | [#x037F-#x1FFF] | [#x200C-#x200D] | [#x2070-#x218F] |
         //                   [#x2C00-#x2FEF] | [#x3001-#xD7FF] | [#xF900-#xFDCF] | [#xFDF0-#xFFFD] | 
@@ -89,46 +88,51 @@ Notes: PN_CHARS_BASE has a hole above #xD800 -- these are the  surrogate pairs
             r(ch, 0x10000, 0xEFFFF) ; // Outside the basic plain. 
     }
     
-    public static boolean isPNChars_U(int ch)
-    {
+    public static boolean isPNChars_U(int ch) {
         //PN_CHARS_BASE | '_'
         return isPNCharsBase(ch) || ( ch == '_' ) ;
     }
     
-    public static boolean isPNChars_U_N(int ch)
-    {
+    public static boolean isPNChars_U_N(int ch) {
         // PN_CHARS_U | [0-9] 
         return isPNCharsBase(ch) || ( ch == '_' ) || isDigit(ch) ;
     }
     
-    public static boolean isPNChars(int ch)
-    {
+    public static boolean isPNChars(int ch) {
         // PN_CHARS ::=  PN_CHARS_U | '-' | [0-9] | #x00B7 | [#x0300-#x036F] | [#x203F-#x2040]
         return isPNChars_U(ch) || isDigit(ch) || ( ch == '-' ) || ch == 0x00B7 || r(ch, 0x300, 0x036F) || r(ch, 0x203F, 0x2040) ;
     }
     
+    public static boolean isPN_LOCAL_ESC(char ch) {
+        //[172s]  PN_LOCAL_ESC    ::=     '\' ('_' | '~' | '.' | '-' | '!' | '$' | '&' | "'" | '(' | ')' | '*' | '+' | ',' | ';' | '=' | '/' | '?' | '#' | '@' | '%')
+        switch (ch) {
+            case '\\': case '_':  case '~': case '.': case '-': case '!': case '$':
+            case '&':  case '\'': case '(': case ')': case '*': case '+': case ',':
+            case ';':  case '=':  case '/': case '?': case '#': case '@': case '%':
+                return true ;
+            default:
+                return false ;
+        }
+    }
+    
     /** Hexadecimal character */
-    public static boolean isHexChar(int ch)
-    {
+    public static boolean isHexChar(int ch) {
         return range(ch, '0', '9') || range(ch, 'a', 'f') || range(ch, 'A', 'F') ;
     }
     
-    public static int valHexChar(int ch)
-    {
+    public static int valHexChar(int ch) {
         if ( range(ch, '0', '9') )
-            return ch-'0' ;
+            return ch - '0' ;
         if ( range(ch, 'a', 'f') )
-            return ch-'a'+10 ;
+            return ch - 'a' + 10 ;
         if ( range(ch, 'A', 'F') )
-            return ch-'A'+10 ;
+            return ch - 'A' + 10 ;
         return -1 ;
     }
 
     private static boolean r(int ch, int a, int b) { return ( ch >= a && ch <= b ) ; }
-    
-    
-    public static boolean range(int ch, char a, char b)
-    {
-        return ( ch >= a && ch <= b ) ;
+
+    public static boolean range(int ch, char a, char b) {
+        return (ch >= a && ch <= b) ;
     }
 }


[2/3] jena git commit: JENA-907 : Splitting IRIs (Turtle rules).

Posted by an...@apache.org.
JENA-907 : Splitting IRIs (Turtle rules).

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

Branch: refs/heads/master
Commit: a3907db4eaa6f0f52ceaca586459b28ffce27291
Parents: 3cebc51
Author: Andy Seaborne <an...@apache.org>
Authored: Sat May 23 20:21:38 2015 +0100
Committer: Andy Seaborne <an...@apache.org>
Committed: Sat May 23 20:21:38 2015 +0100

----------------------------------------------------------------------
 .../java/org/apache/jena/util/SplitIRI.java     | 313 +++++++++++++++++++
 1 file changed, 313 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/a3907db4/jena-core/src/main/java/org/apache/jena/util/SplitIRI.java
----------------------------------------------------------------------
diff --git a/jena-core/src/main/java/org/apache/jena/util/SplitIRI.java b/jena-core/src/main/java/org/apache/jena/util/SplitIRI.java
new file mode 100644
index 0000000..5399e4a
--- /dev/null
+++ b/jena-core/src/main/java/org/apache/jena/util/SplitIRI.java
@@ -0,0 +1,313 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.util;
+
+import org.apache.jena.graph.Node ;
+import org.apache.jena.rdf.model.impl.Util ;
+//import org.apache.jena.riot.system.RiotChars ;
+
+/**
+ * Code to split an URI or IRI into prefix and local part.
+ * Historically, 'prefix' is referred to as 'namespace'
+ * reflecting RDF/XML history.
+ * <p>
+ * For display, use {@link #localname} and {@link #namespace}.
+ * This follows Turtle, adds some pragmatic rulesm but does not escape
+ * any characters. A URI is split never split before the last {@code /} 
+ * or last {@code #}, if present.
+ * See {@link #splitpoint} for more details.
+ * <p>
+ * This code form the machinary behind {@link Node#getLocalName}
+ * {@link Node#getNameSpace} for URI Nodes.   
+ * <p>
+ * {@link #localnameTTL} is strict Turtle; it is the same local name as
+ * before, but escaped if necessary.
+ * <p>
+ * The functions {@link #namespaceXML} and {@link #localnameXML}
+ * apply the rules for XML qnames. 
+ */
+public class SplitIRI
+{
+    /** Return the 'namespace' (prefix) for a URI string. 
+     * Use with {@link #localname}
+     */
+    public static String namespace(String string) {
+        int i = splitpoint(string) ;
+        if ( i < 0 )
+            return string ;
+        return string.substring(0, i) ;
+    }
+    
+    /** Calculate a localname - do not escape PN_LOCAL_ESC.
+     * This is not guaranteed to be legal Turtle.
+     * Use with {@link #namespace}
+     */
+    public static String localname(String string) {
+        int i = splitpoint(string) ;
+        if ( i < 0 )
+            return "" ;
+        return string.substring(i) ;
+    }
+    
+    /** Return the 'namespace' (prefix) for a URI string, 
+     * legal for Turtle and goes with {@link #localnameTTL}
+     */
+    public static String namespaceTTL(String string) {
+        return namespaceTTL(string) ;
+    }
+
+    /** Calculate a localname - enforce legal Turle
+     * escape PN_LOCAL_ESC, check for final '.'
+     * Use with {@link #namespaceTTL}
+     */
+    public static String localnameTTL(String string) {
+        String x = localname(string) ;
+        if ( x.isEmpty())
+            return x ;
+        return escape_PN_LOCAL_ESC(x) ;
+    }
+    
+    private static String escape_PN_LOCAL_ESC(String x) {
+        // Assume that escapes are rare so scan once to make sure there
+        // is work to do then scan again doing the work.
+        //'\' ('_' | '~' | '.' | '-' | '!' | '$' | '&' | "'" | '(' | ')' | '*' | '+' | ',' | ';' | '=' | '/' | '?' | '#' | '@' | '%')
+        
+        int N = x.length() ;
+        boolean escchar = false ;
+        for ( int i = 0 ; i < N ; i++ ) {
+            char ch = x.charAt(i) ;
+            if ( needsEscape(ch, (i==N-1)) ) {
+                escchar = true ;
+                break ;
+            }
+        }
+        if ( ! escchar )
+            return x ;
+        StringBuilder sb = new StringBuilder(N+10) ;
+        for ( int i = 0 ; i < N ; i++ ) {
+            char ch = x.charAt(i) ;
+            // DOT only needs escaping at the end
+            if ( needsEscape(ch, (i==N-1) )  )
+                sb.append('\\') ;
+            sb.append(ch) ;
+        }
+        return sb.toString() ; 
+    }
+
+    private static boolean needsEscape(char ch, boolean finalChar) {
+        if ( ch == '.' )
+            return finalChar ;
+        return isPN_LOCAL_ESC(ch) ; 
+    }
+    
+    public static boolean /*RiotChars.*/isPN_LOCAL_ESC(char ch) {
+        switch (ch) {
+            case '\\': case '_':  case '~': case '.': case '-': case '!': case '$':
+            case '&':  case '\'': case '(': case ')': case '*': case '+': case ',':
+            case ';':  case '=':  case '/': case '?': case '#': case '@': case '%':
+                return true ;
+            default:
+                return false ;
+        }
+    }
+    
+    /* From the RDf 1.1 Turtle specification:
+[136s]  PrefixedName    ::=     PNAME_LN | PNAME_NS
+Productions for terminals
+
+
+[163s]  PN_CHARS_BASE   ::=     [A-Z] | [a-z] | [#x00C0-#x00D6] | [#x00D8-#x00F6] | [#x00F8-#x02FF] | [#x0370-#x037D] | [#x037F-#x1FFF] | [#x200C-#x200D] | [#x2070-#x218F] | [#x2C00-#x2FEF] | [#x3001-#xD7FF] | [#xF900-#xFDCF] | [#xFDF0-#xFFFD] | [#x10000-#xEFFFF]
+[164s]  PN_CHARS_U  ::=     PN_CHARS_BASE | '_'
+[166s]  PN_CHARS    ::=     PN_CHARS_U | '-' | [0-9] | #x00B7 | [#x0300-#x036F] | [#x203F-#x2040]
+[167s]  PN_PREFIX   ::=     PN_CHARS_BASE ((PN_CHARS | '.')* PN_CHARS)?
+
+[168s]  PN_LOCAL    ::=     (PN_CHARS_U | ':' | [0-9] | PLX) ((PN_CHARS | '.' | ':' | PLX)* (PN_CHARS | ':' | PLX))?
+[169s]  PLX     ::=     PERCENT | PN_LOCAL_ESC
+[170s]  PERCENT     ::=     '%' HEX HEX
+[171s]  HEX     ::=     [0-9] | [A-F] | [a-f]
+[172s]  PN_LOCAL_ESC    ::=     '\' ('_' | '~' | '.' | '-' | '!' | '$' | '&' | "'" | '(' | ')' | '*' | '+' | ',' | ';' | '=' | '/' | '?' | '#' | '@' | '%')
+*/
+
+    /** Find the URI split point, return the index into the string that is the
+     * first character of a legal Turtle local name.   
+     * <p>
+     * This is a pragmatic choice, not just finding the maximal point.
+     * For example, with escaping '/' can be included but that means 
+     * {@code http://example/path/abc} could split to give {@code http://example/}
+     * and {@code path/abc} .
+     * <p>
+     * Split URN's after ':'.  
+     *   
+     * @param uri URI string
+     * @return The split point, or -1 for "not found".
+     */
+    
+    public static int splitpoint(String uri) {
+        boolean isURN = uri.startsWith("urn:") ;
+        // Fast track.  Still need to check validity of the prefix part.
+        int idx1 = uri.lastIndexOf('#') ;
+        // Not so simple - \/ in local names 
+        int idx2 = 
+            isURN ? uri.lastIndexOf(':') : uri.lastIndexOf('/') ;
+
+        // If absolute.
+        int idx3 = uri.indexOf(':') ; 
+    
+        // Special case.
+        // A final "." makes it illegal Turtle. 
+        if ( uri.endsWith(".") ) {
+            
+        }
+        
+        // Test the discovered local part.
+        // Limit is exclusive.
+        int limit = Math.max(idx1, idx2) ;
+        limit = Math.max(limit, idx3) ;
+        limit = Math.max(-1, limit) ;
+        
+        int splitPoint = -1 ;
+        // Work backwards, checking for 
+        // ((PN_CHARS | '.' | ':' | PLX)*
+        for ( int i = uri.length()-1 ; i > limit ; i-- ) {
+            char ch = uri.charAt(i) ;
+            
+            if ( /*RiotChars.*/isPNChars_U_N(ch) || /*RiotChars.*/isPN_LOCAL_ESC(ch) || ch == ':' || ch == '-' || ch == '.' ) 
+                continue ;
+            splitPoint = i+1 ;
+            break ;
+        }
+        // limit was at the end.  No split point (we could escape the limit point)
+        if ( splitPoint == -1 )
+            splitPoint = limit+1 ;
+        // No split point.
+        if ( splitPoint >= uri.length() )
+            return -1 ;
+        
+        // Check the first character of the local name.
+        // All character are legal localname name characters but may not satisfy the additional
+        // first character rule.  Move forward to first legal first character.    
+        int ch = uri.charAt(splitPoint) ;
+        while ( ch == '.' || ch == '-' ) {
+            splitPoint++ ;
+            if ( splitPoint >= uri.length() )
+                return -1 ;
+            ch = uri.charAt(splitPoint) ;
+        }
+
+        // Checking the final '.' is done when checking for escapes.
+        return splitPoint ;
+    }
+    
+    private static boolean checkhex(String uri, int i) {
+        return /*RiotChars.*/isHexChar(uri.charAt(i)) ;
+    }
+
+    // Assuming legal URIs, there is no work to be done
+    // for %XX.  If illegal (e.g. %X), the best we can do
+    // is not mess them up.
+    /*
+        // %  - just need to check that it is followed by two hex. 
+        if ( ch == '%' ) {
+            if ( i+2 >= uri.length() ) {
+                // Too short
+                return -1 ;
+            }
+            if ( ! checkhex(uri, i+1) || ! checkhex(uri, i+2) )
+                return -1 ;
+        }
+     
+     */
+    /** Split point, according to XML rules. */
+    public static int splitXML(String string) { return Util.splitNamespaceXML(string) ; }
+
+    /** Namespace, according to XML qname rules.
+     * Use with {@link #localnameXML}.
+     */
+    public static String namespaceXML(String string) { 
+        int i = splitXML(string) ;
+        return string.substring(0, i) ;
+    }
+
+    /** Localname, according to XML qname rules. */
+    public static String localnameXML(String string) { 
+        int i = splitXML(string) ;
+        return string.substring(i) ;
+    }
+
+    // Extracted from RiotChars
+    // When/if RIOT becomes accessible to this code, then refactor 
+    
+    /** ASCII 0-9 */
+    private static boolean isDigit(int ch) {
+        return range(ch, '0', '9') ;
+    }
+    
+    private static boolean isPNCharsBase(int ch) {
+        // PN_CHARS_BASE ::= [A-Z] | [a-z] | [#x00C0-#x00D6] | [#x00D8-#x00F6] | [#x00F8-#x02FF] | 
+        //                   [#x0370-#x037D] | [#x037F-#x1FFF] | [#x200C-#x200D] | [#x2070-#x218F] |
+        //                   [#x2C00-#x2FEF] | [#x3001-#xD7FF] | [#xF900-#xFDCF] | [#xFDF0-#xFFFD] | 
+        //                   [#x10000-#xEFFFF]
+        return 
+            r(ch, 'a', 'z') || r(ch, 'A', 'Z') || r(ch, 0x00C0, 0x00D6) || r(ch, 0x00D8, 0x00F6) || r(ch, 0x00F8, 0x02FF) ||
+            r(ch, 0x0370, 0x037D) || r(ch, 0x037F, 0x1FFF) || r(ch, 0x200C, 0x200D) || r(ch, 0x2070, 0x218F) ||
+            r(ch, 0x2C00, 0x2FEF) || r(ch, 0x3001, 0xD7FF) ||
+            // Surrogate pairs
+            r(ch, 0xD800, 0xDFFF) ||
+            r(ch, 0xF900, 0xFDCF) || r(ch, 0xFDF0, 0xFFFD) || 
+            r(ch, 0x10000, 0xEFFFF) ; // Outside the basic plain. 
+    }
+    
+    private static boolean isPNChars_U(int ch) {
+        //PN_CHARS_BASE | '_'
+        return isPNCharsBase(ch) || ( ch == '_' ) ;
+    }
+    
+    private static boolean isPNChars_U_N(int ch) {
+        // PN_CHARS_U | [0-9] 
+        return isPNCharsBase(ch) || ( ch == '_' ) || isDigit(ch) ;
+    }
+    
+    private static boolean isPNChars(int ch) {
+        // PN_CHARS ::=  PN_CHARS_U | '-' | [0-9] | #x00B7 | [#x0300-#x036F] | [#x203F-#x2040]
+        return isPNChars_U(ch) || isDigit(ch) || ( ch == '-' ) || ch == 0x00B7 || r(ch, 0x300, 0x036F) || r(ch, 0x203F, 0x2040) ;
+    }
+    
+    /** Hexadecimal character */
+    private static boolean isHexChar(int ch) {
+        return range(ch, '0', '9') || range(ch, 'a', 'f') || range(ch, 'A', 'F') ;
+    }
+    
+    private static int valHexChar(int ch) {
+        if ( range(ch, '0', '9') )
+            return ch - '0' ;
+        if ( range(ch, 'a', 'f') )
+            return ch - 'a' + 10 ;
+        if ( range(ch, 'A', 'F') )
+            return ch - 'A' + 10 ;
+        return -1 ;
+    }
+
+    private static boolean r(int ch, int a, int b) { return ( ch >= a && ch <= b ) ; }
+
+    private static boolean range(int ch, char a, char b) {
+        return (ch >= a && ch <= b) ;
+    }
+    
+}
+


[3/3] jena git commit: JENA-907 : Tests for splitting IRIs.

Posted by an...@apache.org.
JENA-907 : Tests for splitting IRIs.

Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/575a2b41
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/575a2b41
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/575a2b41

Branch: refs/heads/master
Commit: 575a2b41746b67603bb125b60ee6cd8353077f67
Parents: a3907db
Author: Andy Seaborne <an...@apache.org>
Authored: Sat May 23 20:21:58 2015 +0100
Committer: Andy Seaborne <an...@apache.org>
Committed: Sat May 23 20:21:58 2015 +0100

----------------------------------------------------------------------
 .../java/org/apache/jena/util/TestPackage.java  |   7 +-
 .../org/apache/jena/util/TestSplitIRI_TTL.java  | 160 +++++++++++++++++++
 .../org/apache/jena/util/TestSplitIRI_XML.java  | 138 ++++++++++++++++
 .../java/org/apache/jena/util/TestUtil.java     | 138 ----------------
 4 files changed, 302 insertions(+), 141 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/575a2b41/jena-core/src/test/java/org/apache/jena/util/TestPackage.java
----------------------------------------------------------------------
diff --git a/jena-core/src/test/java/org/apache/jena/util/TestPackage.java b/jena-core/src/test/java/org/apache/jena/util/TestPackage.java
index dc213e6..22d5a58 100644
--- a/jena-core/src/test/java/org/apache/jena/util/TestPackage.java
+++ b/jena-core/src/test/java/org/apache/jena/util/TestPackage.java
@@ -40,10 +40,11 @@ public class TestPackage extends TestSuite {
         addTest( "TestHashUtils",         TestCollectionFactory.suite() );
         addTest( "TestLocationMapper",    TestLocationMapper.suite() ) ;
         addTest( "TestFileManager",       TestFileManager.suite()) ;
-        addTest( "TestMonitors",       TestMonitors.suite()) ;
-        addTest( "TestPrintUtil",       TestPrintUtil.suite()) ;
+        addTest( "TestMonitors",          TestMonitors.suite()) ;
+        addTest( "TestPrintUtil",         TestPrintUtil.suite()) ;
         addTest( TestIteratorCollection.suite() );
-        addTest( "TestUtil",            TestUtil.suite()) ;
+        addTest( "TestSplitIRI_XML",      TestSplitIRI_XML.suite()) ;
+        addTest( "TestSplitIRI_TTL",      TestSplitIRI_TTL.suite()) ;
         addTestSuite( TestLocators.class );
         addTestSuite( TestOneToManyMap.class );
     }

http://git-wip-us.apache.org/repos/asf/jena/blob/575a2b41/jena-core/src/test/java/org/apache/jena/util/TestSplitIRI_TTL.java
----------------------------------------------------------------------
diff --git a/jena-core/src/test/java/org/apache/jena/util/TestSplitIRI_TTL.java b/jena-core/src/test/java/org/apache/jena/util/TestSplitIRI_TTL.java
new file mode 100644
index 0000000..a698e6e
--- /dev/null
+++ b/jena-core/src/test/java/org/apache/jena/util/TestSplitIRI_TTL.java
@@ -0,0 +1,160 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.util;
+
+import static org.apache.jena.util.SplitIRI.* ;
+
+import java.util.Objects ;
+
+import junit.framework.JUnit4TestAdapter ;
+import org.junit.Assert ;
+import org.junit.Test ;
+
+/** Test splitting IRI strings using Turtle rules.
+ */
+public class TestSplitIRI_TTL {
+    public static junit.framework.Test suite() {
+        return new JUnit4TestAdapter(TestSplitIRI_TTL.class) ;
+    }
+    
+    // Basics
+    @Test public void split_basic_00() { testSplit("http://example/foo", "http://example/".length()) ; }
+    @Test public void split_basic_01() { testPrefixLocalname("http://example/foo",            "http://example/",      "foo"       ) ; }
+    @Test public void split_basic_02() { testPrefixLocalname("http://example/foo#bar",        "http://example/foo#",  "bar"       ) ; }
+    @Test public void split_basic_03() { testPrefixLocalname("http://example/foo#",           "http://example/foo#",  ""          ) ; }
+    @Test public void split_basic_04() { testPrefixLocalname("http://example/",               "http://example/",      ""          ) ; }
+    @Test public void split_basic_05() { testPrefixLocalname("http://example/1abc",           "http://example/",      "1abc"      ) ; }
+    @Test public void split_basic_06() { testPrefixLocalname("http://example/1.2.3.4",        "http://example/",      "1.2.3.4"   ) ; }
+    @Test public void split_basic_07() { testPrefixLocalname("http://example/xyz#1.2.3.4",    "http://example/xyz#",  "1.2.3.4"   ) ; }
+    @Test public void split_basic_08() { testPrefixLocalname("http://example/xyz#_abc",       "http://example/xyz#",  "_abc"      ) ; }
+    @Test public void split_basic_09() { testPrefixLocalname("http://example/xyz/_1.2.3.4",   "http://example/xyz/", "_1.2.3.4"   ) ; }
+    
+    // Relative URIs 
+    @Test public void split_rel_1() { testPrefixLocalname("xyz/_1.2.3.4",  "xyz/", "_1.2.3.4" ) ; }
+    @Test public void split_rel_2() { testPrefixLocalname("xyz",           "",     "xyz" ) ; }
+    @Test public void split_rel_3() { testPrefixLocalname("",              "",     "" ) ; }
+    
+    // Bizarre but legal URIs
+    @Test public void split_weird_1() { testPrefixLocalname("abc:def",       "abc:", "def" ) ; }
+    
+
+    // Turtle details.
+    // "." leading dot is not legal.
+    @Test public void split_ttl_01() { testPrefixLocalname("http://example/foo#bar:baz",    "http://example/foo#",  "bar:baz"   ) ; }
+    @Test public void split_ttl_02() { testPrefixLocalname("http://example/a:b:c",          "http://example/",      "a:b:c"     ) ; }
+    @Test public void split_ttl_03() { testPrefixLocalname("http://example/.2.3.4",         "http://example/.",     "2.3.4"     ) ; }
+
+    // "." leading dot is not legal.
+    @Test public void split_ttl_04() { testPrefixLocalname("abc:xyz/.def",       "abc:xyz/.", "def" ) ; }
+    // "-" leading dash is not legal.
+    @Test public void split_ttl_05() { testPrefixLocalname("abc:xyz/-def",       "abc:xyz/-", "def" ) ; }
+    @Test public void split_ttl_06() { testPrefixLocalname("abc:xyz/-.-.-def",       "abc:xyz/-.-.-", "def" ) ; }
+    @Test public void split_ttl_07() { testPrefixLocalname("http://example/id=89",          "http://example/",      "id=89"   ) ; }
+    // Trailing '.'
+    @Test public void split_ttl_08() { testPrefixLocalname("http://example/2.3.",           "http://example/",      "2.3."     ) ; }
+    
+    // Turtle details, including escaping.
+    // Test for PrefixLocalnameEsc
+    @Test public void split_ttl_esc_01() { testPrefixLocalnameEsc("http://example/id=89",  "id\\=89"   ) ; }
+    @Test public void split_ttl_esc_02() { testPrefixLocalnameEsc("http://example/a,b",  "a\\,b"   ) ; }
+    // Trailing '.'
+    @Test public void split_ttl_esc_033() { testPrefixLocalnameEsc("http://example/2.3.", "2.3\\."     ) ; }
+    
+    // URNs split differently.
+    @Test public void split_urn_01() { testPrefixLocalname("urn:foo:bar",                   "urn:foo:",              "bar"       ) ; }
+
+    // Anti-tests
+    @Test public void split_51() { testPrefixLocalnameNot("http://example/foo#bar:baz", "http://example/foo#bar", "baz"     ) ; }
+
+    
+    
+    private void testSplit(String string, int expected) {
+        int i = splitpoint(string) ;
+        Assert.assertEquals(expected, i) ;
+    }
+
+    // ??
+    private void testTurtle(String string, String expectedPrefix, String expectedLocalname) {
+        int i = splitpoint(string) ;
+        String ns = string ;
+        String ln = "" ;
+        if ( i > 0 ) {
+            ns = string.substring(0, i) ;
+            ln = string.substring(i) ;
+        }
+        
+        if ( expectedPrefix != null )
+            Assert.assertEquals(expectedPrefix, ns);
+        if ( expectedLocalname != null )
+            Assert.assertEquals(expectedLocalname, ln);
+        if (  expectedPrefix != null && expectedLocalname != null ) {
+            String x = ns+ln ;
+            Assert.assertEquals(string, x) ;
+        }
+    }
+
+    private void testPrefixLocalnameNoSplit(String string) {
+        int i = splitpoint(string) ;
+        String msg = string ;
+        if ( i != -1 ) {
+            // Better error message.
+            String ns = namespace(string) ;
+            String ln = localname(string) ;
+            msg = "Unexpected split of '"+string+"' into ("+ns+", "+ln+") [index="+i+"]" ;
+        }
+        Assert.assertEquals(msg, -1, i) ;
+    }
+    
+    private void testPrefixLocalname(String string, String expectedPrefix, String expectedLocalname) {
+        String ns = namespace(string) ;
+        String ln = localname(string) ;
+
+        if ( expectedPrefix != null )
+            Assert.assertEquals(expectedPrefix, ns);
+        if ( expectedLocalname != null )
+            Assert.assertEquals(expectedLocalname, ln);
+        if (  expectedPrefix != null && expectedLocalname != null ) {
+            String x = ns+ln ;
+            Assert.assertEquals(string, x) ;
+        }
+    }
+
+    private void testPrefixLocalnameEsc(String string, String expectedLocalname) {
+      String ln = localnameTTL(string) ;
+      Assert.assertEquals(expectedLocalname, ln);
+  }
+
+    private void testPrefixLocalnameNot(String string, String expectedPrefix, String expectedLocalname) {
+//      Node n = NodeFactory.createURI(string) ;
+//      String ns = n.getNameSpace() ;
+//      String ln = n.getLocalName() ;
+        String ns = namespace(string) ;
+        String ln = localname(string) ;
+
+        boolean b1 = Objects.equals(expectedPrefix, ns) ;
+        boolean b2 = Objects.equals(expectedLocalname, ln) ;
+
+        // Test not both true.
+        Assert.assertFalse("Wrong: ("+ns+","+ln+")", b1&&b2);
+        // But it still combines.
+        String x = ns+ln ;
+        Assert.assertEquals(string, x) ;
+    }
+}
+

http://git-wip-us.apache.org/repos/asf/jena/blob/575a2b41/jena-core/src/test/java/org/apache/jena/util/TestSplitIRI_XML.java
----------------------------------------------------------------------
diff --git a/jena-core/src/test/java/org/apache/jena/util/TestSplitIRI_XML.java b/jena-core/src/test/java/org/apache/jena/util/TestSplitIRI_XML.java
new file mode 100644
index 0000000..5719886
--- /dev/null
+++ b/jena-core/src/test/java/org/apache/jena/util/TestSplitIRI_XML.java
@@ -0,0 +1,138 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.util;
+
+import junit.framework.JUnit4TestAdapter;
+import org.apache.jena.rdf.model.impl.Util ;
+import org.junit.Test;
+import static org.junit.Assert.*;
+public class TestSplitIRI_XML
+{
+     public static junit.framework.Test suite() {
+         return new JUnit4TestAdapter(TestSplitIRI_XML.class) ;
+     }
+    
+    // Intermediate : JUnit 3 and JUnit 4.
+     
+    @Test public void splitNS_01()
+    { split("http://example/xyz", "http://example/", "xyz") ; }
+    
+    @Test public void splitNS_02()
+    { split("http://example/ns#xyz", "http://example/ns#", "xyz") ; }
+    
+    @Test public void splitNS_03()
+    { no_split("http://example/ns#") ; }
+    
+    @Test public void splitNS_04()
+    { no_split("http://example/") ; }
+    
+    @Test public void splitNS_05()  // Illegal URI
+    { split("http://example", "http://", "example") ; }
+    
+    @Test public void splitNS_06()   // localname must be at least the NCStartChar - not empty
+    { split("mailto:me", "mailto:m", "e") ; }
+
+    @Test public void splitNS_07()
+    { split("urn:abc:xyz","urn:abc:", "xyz") ; } 
+
+    @Test public void splitNS_08()
+    { no_split("urn:abc:xyz:") ; } 
+
+    @Test public void splitNS_09()
+    { split("http://bio2rdf.org/pdb:Pentane-3%2C4-diol-5-phosphate", "http://bio2rdf.org/pdb:Pentane-3%2C4-", "diol-5-phosphate") ; }
+
+    @Test public void splitNS_10()
+    { split("http://bio2rdf.org/pdb:Pentane-3,4-diol-5-phosphate", "http://bio2rdf.org/pdb:Pentane-3,4-", "diol-5-phosphate") ; }
+
+    // Don't split inside a %encoding. 
+    @Test public void splitNS_11()
+    { split("http://host/abc%AAdef", "http://host/abc%AA", "def") ; } 
+
+    @Test public void splitNS_12()
+    { split("http://host/abc%1Adef", "http://host/abc%1A", "def") ; } 
+    
+    @Test public void splitNS_13()
+    { split("http://host/abc%A1def", "http://host/abc%A1", "def") ; } 
+    
+    @Test public void splitNS_14()
+    { split("http://host/abc%AA22def", "http://host/abc%AA22", "def") ; } 
+
+    @Test public void splitNS_15()
+    { no_split("http://host/abc%AA22") ; } 
+
+    // Other schemes
+    
+    @Test public void splitNS_50()
+    { split("file:///x/y", "file:///x/", "y") ; } 
+
+    @Test public void splitNS_51()
+    { split("file:///x", "file:///", "x") ; } 
+
+    @Test public void splitNS_52()
+    { split("file:x", "file:", "x") ; } 
+
+    @Test public void splitNS_53()
+    // Not ideal but some URI schemes dislike a URI with just the scheme
+    { split("file:foo", "file:", "foo") ; } 
+
+    @Test public void splitNS_54()
+    { split("file:c:/foo", "file:c:/", "foo") ; } 
+    
+    // urn:uuid:d871c7f4-2926-11b2-8073-a5e169788449 - legal type 1 uuid as urn
+    // uuid:3cf3e43a-3a5d-40d8-a93c-8697b162a1c0 - legal type 4 uuid as uri
+    
+    @Test public void splitNS_55()
+    { split("urn:uuid:d871c7f4-2926-11b2-8073-a5e169788449", "urn:uuid:", "d871c7f4-2926-11b2-8073-a5e169788449") ; }
+
+    @Test public void splitNS_56()
+    { split("uuid:3cf3e43a-3a5d-40d8-a93c-8697b162a1c0", "uuid:3", "cf3e43a-3a5d-40d8-a93c-8697b162a1c0") ; }
+    
+    @Test public void splitNS_57()
+    { split("urn:abc:def", "urn:abc:", "def") ; }
+
+    // --------
+    
+    static void  no_split(String string)
+    { split(string, null, null) ; }
+
+    static void split(String uriStr, String namespace, String localname)
+    {
+        if ( namespace == null && localname != null )
+            fail("Bad test - namespace is null but local name is not") ;
+        if ( namespace != null && localname == null )
+            fail("Bad test - namespace is not null but local name is") ;
+        
+        int idx = Util.splitNamespaceXML(uriStr) ;
+        if ( idx == uriStr.length() ) 
+        {
+            // No split.
+            if ( namespace != null )
+                fail("Expected a split ("+namespace+","+localname+") - but none found") ;
+            return ;
+            
+        }
+        // Split
+        String ns = uriStr.substring(0,idx) ;
+        String ln = uriStr.substring(idx) ;
+        assertEquals(namespace, ns) ;
+        assertEquals(localname, ln) ;
+    }
+    
+    
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/575a2b41/jena-core/src/test/java/org/apache/jena/util/TestUtil.java
----------------------------------------------------------------------
diff --git a/jena-core/src/test/java/org/apache/jena/util/TestUtil.java b/jena-core/src/test/java/org/apache/jena/util/TestUtil.java
deleted file mode 100644
index 9eb0538..0000000
--- a/jena-core/src/test/java/org/apache/jena/util/TestUtil.java
+++ /dev/null
@@ -1,138 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.jena.util;
-
-import junit.framework.JUnit4TestAdapter;
-import org.apache.jena.rdf.model.impl.Util ;
-import org.junit.Test;
-import static org.junit.Assert.*;
-public class TestUtil
-{
-     public static junit.framework.Test suite() {
-         return new JUnit4TestAdapter(TestUtil.class) ;
-     }
-    
-    // Intermediate : JUnit 3 and JUnit 4.
-     
-    @Test public void splitNS_01()
-    { split("http://example/xyz", "http://example/", "xyz") ; }
-    
-    @Test public void splitNS_02()
-    { split("http://example/ns#xyz", "http://example/ns#", "xyz") ; }
-    
-    @Test public void splitNS_03()
-    { no_split("http://example/ns#") ; }
-    
-    @Test public void splitNS_04()
-    { no_split("http://example/") ; }
-    
-    @Test public void splitNS_05()  // Illegal URI
-    { split("http://example", "http://", "example") ; }
-    
-    @Test public void splitNS_06()   // localname must be at least the NCStartChar - not empty
-    { split("mailto:me", "mailto:m", "e") ; }
-
-    @Test public void splitNS_07()
-    { split("urn:abc:xyz","urn:abc:", "xyz") ; } 
-
-    @Test public void splitNS_08()
-    { no_split("urn:abc:xyz:") ; } 
-
-    @Test public void splitNS_09()
-    { split("http://bio2rdf.org/pdb:Pentane-3%2C4-diol-5-phosphate", "http://bio2rdf.org/pdb:Pentane-3%2C4-", "diol-5-phosphate") ; }
-
-    @Test public void splitNS_10()
-    { split("http://bio2rdf.org/pdb:Pentane-3,4-diol-5-phosphate", "http://bio2rdf.org/pdb:Pentane-3,4-", "diol-5-phosphate") ; }
-
-    // Don't split inside a %encoding. 
-    @Test public void splitNS_11()
-    { split("http://host/abc%AAdef", "http://host/abc%AA", "def") ; } 
-
-    @Test public void splitNS_12()
-    { split("http://host/abc%1Adef", "http://host/abc%1A", "def") ; } 
-    
-    @Test public void splitNS_13()
-    { split("http://host/abc%A1def", "http://host/abc%A1", "def") ; } 
-    
-    @Test public void splitNS_14()
-    { split("http://host/abc%AA22def", "http://host/abc%AA22", "def") ; } 
-
-    @Test public void splitNS_15()
-    { no_split("http://host/abc%AA22") ; } 
-
-    // Other schemes
-    
-    @Test public void splitNS_50()
-    { split("file:///x/y", "file:///x/", "y") ; } 
-
-    @Test public void splitNS_51()
-    { split("file:///x", "file:///", "x") ; } 
-
-    @Test public void splitNS_52()
-    { split("file:x", "file:", "x") ; } 
-
-    @Test public void splitNS_53()
-    // Not ideal but some URI schemes dislike a URI with just the scheme
-    { split("file:foo", "file:", "foo") ; } 
-
-    @Test public void splitNS_54()
-    { split("file:c:/foo", "file:c:/", "foo") ; } 
-    
-    // urn:uuid:d871c7f4-2926-11b2-8073-a5e169788449 - legal type 1 uuid as urn
-    // uuid:3cf3e43a-3a5d-40d8-a93c-8697b162a1c0 - legal type 4 uuid as uri
-    
-    @Test public void splitNS_55()
-    { split("urn:uuid:d871c7f4-2926-11b2-8073-a5e169788449", "urn:uuid:", "d871c7f4-2926-11b2-8073-a5e169788449") ; }
-
-    @Test public void splitNS_56()
-    { split("uuid:3cf3e43a-3a5d-40d8-a93c-8697b162a1c0", "uuid:3", "cf3e43a-3a5d-40d8-a93c-8697b162a1c0") ; }
-    
-    @Test public void splitNS_57()
-    { split("urn:abc:def", "urn:abc:", "def") ; }
-
-    // --------
-    
-    static void  no_split(String string)
-    { split(string, null, null) ; }
-
-    static void split(String uriStr, String namespace, String localname)
-    {
-        if ( namespace == null && localname != null )
-            fail("Bad test - namespace is null but local name is not") ;
-        if ( namespace != null && localname == null )
-            fail("Bad test - namespace is not null but local name is") ;
-        
-        int idx = Util.splitNamespaceXML(uriStr) ;
-        if ( idx == uriStr.length() ) 
-        {
-            // No split.
-            if ( namespace != null )
-                fail("Expected a split ("+namespace+","+localname+") - but none found") ;
-            return ;
-            
-        }
-        // Split
-        String ns = uriStr.substring(0,idx) ;
-        String ln = uriStr.substring(idx) ;
-        assertEquals(namespace, ns) ;
-        assertEquals(localname, ln) ;
-    }
-    
-    
-}