This is an automated email from the ASF dual-hosted git repository.

andy pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/jena.git

commit 8e3ca85a950afd0e736512d39adf683c76fe9f09
Author: Andy Seaborne <[email protected]>
AuthorDate: Sat Jan 11 09:04:15 2025 +0000

    GH-2800: Update test-only bootstrap Turtle parser to use IRIx
---
 .../src/main/java/org/apache/jena/irix/IRIs.java   |   2 +-
 .../org/apache/jena/ttl_test/JenaReaderBase.java   |   7 +-
 .../org/apache/jena/ttl_test/JenaURIException.java |  28 --
 .../java/org/apache/jena/ttl_test/ManifestOld.java |   4 +-
 .../org/apache/jena/ttl_test/N3IRIResolver.java    | 255 ---------------
 .../apache/jena/ttl_test/RelativeURIException.java |  24 --
 .../jena/ttl_test/TestFactoryManifestOld.java      |  21 +-
 .../jena/ttl_test/test/TestN3IRIResolver.java      | 345 ---------------------
 .../jena/ttl_test/turtle/TurtleParserBase.java     | 154 ++++-----
 9 files changed, 95 insertions(+), 745 deletions(-)

diff --git a/jena-core/src/main/java/org/apache/jena/irix/IRIs.java 
b/jena-core/src/main/java/org/apache/jena/irix/IRIs.java
index b9890e41da..c8b5a6d41f 100644
--- a/jena-core/src/main/java/org/apache/jena/irix/IRIs.java
+++ b/jena-core/src/main/java/org/apache/jena/irix/IRIs.java
@@ -111,7 +111,7 @@ public class IRIs {
         return resolver(getSystemBase());
     }
 
-    /** Return a general purpose resolver, with the current system base as its 
base IRI. */
+    /** Return a general purpose resolver, with the given IRI as as its base 
IRI. */
     public static IRIxResolver resolver(String base) {
         return 
IRIxResolver.create(base).resolve(true).allowRelative(false).build();
     }
diff --git 
a/jena-core/src/test/java/org/apache/jena/ttl_test/JenaReaderBase.java 
b/jena-core/src/test/java/org/apache/jena/ttl_test/JenaReaderBase.java
index f585fbe8a8..fa19c6ba35 100644
--- a/jena-core/src/test/java/org/apache/jena/ttl_test/JenaReaderBase.java
+++ b/jena-core/src/test/java/org/apache/jena/ttl_test/JenaReaderBase.java
@@ -23,15 +23,16 @@ import java.nio.charset.StandardCharsets ;
 import java.io.* ;
 
 import org.apache.jena.graph.GraphEvents ;
+import org.apache.jena.irix.IRIs;
 import org.apache.jena.rdf.model.* ;
 import org.apache.jena.shared.* ;
 import org.apache.jena.util.FileUtils ;
 import org.slf4j.LoggerFactory;
 
-/** Abstract class that sorts out input streams, readers and base URIs, to 
call a
+/**
+ * Abstract class that sorts out input streams, readers and base URIs, to call 
a
  * single worker function with model, UTF8 reader and visited base
  */
-@SuppressWarnings("deprecation")
 public abstract class JenaReaderBase implements RDFReaderI
 {
        protected RDFErrorHandler errorHandler = null ;
@@ -104,7 +105,7 @@ public abstract class JenaReaderBase implements RDFReaderI
         // The reader has been checked, if possible, by now or
         // constructed correctly by code here.
         if ( base != null )
-            base = N3IRIResolver.resolveGlobal(base) ;
+            base = IRIs.resolve(base);
         try {
             model.notifyEvent( GraphEvents.startRead );
             readWorker(model, reader,  base) ;
diff --git 
a/jena-core/src/test/java/org/apache/jena/ttl_test/JenaURIException.java 
b/jena-core/src/test/java/org/apache/jena/ttl_test/JenaURIException.java
deleted file mode 100644
index a530caeaff..0000000000
--- a/jena-core/src/test/java/org/apache/jena/ttl_test/JenaURIException.java
+++ /dev/null
@@ -1,28 +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.ttl_test;
-
-import org.apache.jena.shared.JenaException ;
-
-
-public class JenaURIException extends JenaException
-{
-    public JenaURIException(Exception e)    { super(e) ; }
-    public JenaURIException(String msg)     { super(msg) ; }
-}
diff --git a/jena-core/src/test/java/org/apache/jena/ttl_test/ManifestOld.java 
b/jena-core/src/test/java/org/apache/jena/ttl_test/ManifestOld.java
index 7fdf90daff..d662072ce1 100644
--- a/jena-core/src/test/java/org/apache/jena/ttl_test/ManifestOld.java
+++ b/jena-core/src/test/java/org/apache/jena/ttl_test/ManifestOld.java
@@ -22,6 +22,7 @@ import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
 
+import org.apache.jena.irix.IRIs;
 import org.apache.jena.rdf.model.* ;
 import org.apache.jena.util.FileManager ;
 import org.apache.jena.util.junit.ManifestOldItemHandler;
@@ -48,11 +49,10 @@ public class ManifestOld
     Resource manifestRes = null ;
 
 
-    @SuppressWarnings("deprecation")
     public ManifestOld(String fn)
     {
         log.debug("Manifest = "+fn ) ;
-        filename = org.apache.jena.ttl_test.N3IRIResolver.resolveGlobal(fn) ;
+        filename = IRIs.resolve(fn) ;
         log.debug("         = "+filename ) ;
         manifest = FileManager.getInternal().loadModelInternal(filename) ;
         parseIncludes() ;
diff --git 
a/jena-core/src/test/java/org/apache/jena/ttl_test/N3IRIResolver.java 
b/jena-core/src/test/java/org/apache/jena/ttl_test/N3IRIResolver.java
deleted file mode 100644
index aad24420b2..0000000000
--- a/jena-core/src/test/java/org/apache/jena/ttl_test/N3IRIResolver.java
+++ /dev/null
@@ -1,255 +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.ttl_test;
-
-
-import java.io.File;
-
-import org.apache.jena.iri.IRI;
-import org.apache.jena.iri.IRIException;
-import org.apache.jena.iri.IRIFactory;
-import org.apache.jena.iri.ViolationCodes;
-
-/** A simple class to access IRI resolution.
- * 
- * Replaced by {@code org.apache.jena.riot.system.IRIResolver}
- * 
- * Only exists for jena-core tests  
- */
-
-@Deprecated
-public class N3IRIResolver {
-       /**
-        * The current working directory, as a string.
-        * Ends in "/".
-        */
-       static private String globalBase = "http://localhost/LocalHostBase/"; ;
-       
-       // Try to set the global base from the current directory.  
-       // Security (e.g. Tomcat) may prevent this in which case we
-       // use a common default set above.
-       static {
-           try { globalBase = cwdURL(); }
-           catch (Throwable th) {}
-       }
-       
-       /** The current directory as a "file:" URL */
-    private static String cwdURL()
-    {
-        /**
-         * Convert a File, note java.net.URI does the right thing.
-         * viz:
-         *   Convert to absolute path.
-         *   Convert all % to %25.
-         *   then convert all ' ' to %20.
-         *   It quite probably does more e.g. ? #
-         * But has one /, not three, at beginning
-         */
-        return "file://" + new File("").toURI().toString().substring(5);
-    }
-           
-       /**
-        * The current working directory, as an IRI.
-        */
-       static final IRI cwd;
-
-       /**
-        * An IRIFactory appropriately configuired.
-        */
-       static final IRIFactory factory = new 
IRIFactory(IRIFactory.jenaImplementation());
-       static {
-           factory.shouldViolation(false,false);
-           factory.securityViolation(false,false);
-        factory.setIsWarning(ViolationCodes.UNREGISTERED_IANA_SCHEME, false);
-        factory.setIsError(ViolationCodes.UNREGISTERED_IANA_SCHEME, false);
-               factory.setSameSchemeRelativeReferences("file");
-       }
-
-       static {
-               
-               IRI cwdx;
-               try {
-                       cwdx = factory.construct(globalBase);
-               } catch (IRIException e) {
-                       System.err.println("Unexpected IRIException in 
initializer: "
-                                       + e.getMessage());
-                       cwdx = factory.create("file:///");
-               }
-               cwd = cwdx;
-       }
-
-
-       
-       /**
-        * Turn a filename into a well-formed file: URL relative to the working
-        * directory.
-        * 
-        * @param filename
-        * @return String The filename as an absolute URL
-        */
-       static public String resolveFileURL(String filename) throws 
IRIException {
-               IRI r = cwd.resolve(filename);
-               if (!r.getScheme().equalsIgnoreCase("file")) {
-                       return resolveFileURL("./" + filename);
-               }
-               return r.toString();
-       }
-
-       /**
-        * Create resolve a URI against a base. If baseStr is a relative file 
IRI
-        * then it is first resolved against the current working directory.
-        * 
-        * @param relStr
-        * @param baseStr
-        *            Can be null if relStr is absolute
-        * @return String An absolute URI
-        * @throws JenaURIException
-        *             If result would not be legal, absolute IRI
-        */
-       static public String resolve(String relStr, String baseStr)
-                       throws JenaURIException {
-               return exceptions(resolveIRI(relStr, baseStr)).toString();
-       }
-
-       /*
-        * No exception thrown by this method.
-        */
-       static private IRI resolveIRI(String relStr, String baseStr) {
-               IRI i = factory.create(relStr);
-               if (i.isAbsolute())
-                       // removes excess . segments
-                       return cwd.create(i);
-
-               IRI base = factory.create(baseStr);
-
-               if ("file".equalsIgnoreCase(base.getScheme()))
-                       return cwd.create(base).create(i);
-               return base.create(i);
-       }
-
-       final private IRI base;
-
-       /**
-        * Construct an IRIResolver with base as the 
-        * current working directory.
-        *
-        */
-       public N3IRIResolver() {
-               this(null);
-       }
-
-       /**
-        * Construct an IRIResolver with base determined
-        * by the argument URI. If this is relative,
-        * it is relative against the current working directory.
-        * @param baseS
-        * 
-        * @throws JenaURIException
-        *             If resulting base would not be legal, absolute IRI
-        */
-       public N3IRIResolver(String baseS) {
-               if (baseS == null)
-                       baseS = chooseBaseURI();
-               // IRI aaa = RelURI.factory.construct(baseS);
-               base = exceptions(cwd.create(baseS));
-       }
-
-       /**
-        * The base of this IRIResolver.
-        * @return String
-        */
-       public String getBaseIRI() {
-               return base.toString();
-       }
-
-       /**
-        * Resolve the relative URI against the base of
-        * this IRIResolver.
-        * @param relURI
-        * @return the resolved IRI
-        * @throws JenaURIException
-        *             If resulting URI would not be legal, absolute IRI
-       
-        */
-       public String resolve(String relURI) {
-               return exceptions(base.resolve(relURI)).toString();
-       }
-
-       
-       /**
-        * Throw any exceptions resulting from IRI.
-        * @param iri
-        * @return iri
-        */
-       static private IRI exceptions(IRI iri) {
-               if (showExceptions && iri.hasViolation(false)) {
-                       try {
-                               cwd.construct(iri);
-                       } catch (IRIException e) {
-                               throw new JenaURIException(e);
-                       }
-               }
-               return iri;
-       }
-       
-       private static boolean showExceptions = true;
-
-       /**
-           To allow Eyeball to bypass IRI checking (because it's doing its own)
-       */
-       public static void suppressExceptions()
-       { setShowExceptions(false) ; }
-
-       /** To allow Eyeball to bypass IRI checking (because it's doing its 
own) */
-       public static void setShowExceptions(boolean state)
-       { showExceptions = state ; }
-
-/**
-        * Resolve the relative URI str against the current
-        * working directory.
-        * @param str
-        * @return String
-        */
-       public static String resolveGlobal(String str) {
-               return exceptions(cwd.resolve(str)).toString();
-       }
-
-       /**
-        * Choose a base URI based on the current directory
-        * 
-        * @return String Absolute URI
-        */
-
-       static public String chooseBaseURI() {
-               return chooseBaseURI(null);
-       }
-
-       /**
-        * Choose a baseURI based on a suggestion
-        * 
-        * @return String URI (if relative, relative to current working 
directory).
-        */
-
-       static public String chooseBaseURI(String baseURI) {
-               if (baseURI == null)
-                       baseURI = "file:.";
-               return resolveGlobal(baseURI);
-       }
-
-}
diff --git 
a/jena-core/src/test/java/org/apache/jena/ttl_test/RelativeURIException.java 
b/jena-core/src/test/java/org/apache/jena/ttl_test/RelativeURIException.java
deleted file mode 100644
index 09178d87cf..0000000000
--- a/jena-core/src/test/java/org/apache/jena/ttl_test/RelativeURIException.java
+++ /dev/null
@@ -1,24 +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.ttl_test;
-
-public class RelativeURIException extends JenaURIException
-{
-    public RelativeURIException(String msg) { super(msg) ; }
-}
diff --git 
a/jena-core/src/test/java/org/apache/jena/ttl_test/TestFactoryManifestOld.java 
b/jena-core/src/test/java/org/apache/jena/ttl_test/TestFactoryManifestOld.java
index cf1361efeb..1469ab42ce 100644
--- 
a/jena-core/src/test/java/org/apache/jena/ttl_test/TestFactoryManifestOld.java
+++ 
b/jena-core/src/test/java/org/apache/jena/ttl_test/TestFactoryManifestOld.java
@@ -27,19 +27,18 @@ import org.apache.jena.util.junit.ManifestOldItemHandler;
 import org.apache.jena.util.junit.TestUtils;
 import org.slf4j.LoggerFactory;
 
-
 public abstract class TestFactoryManifestOld implements ManifestOldItemHandler
 {
     private TestSuite currentTestSuite = null ;
     private TestSuite testSuite = null ;
-    
+
     public TestFactoryManifestOld() {}
-    
+
     public TestSuite process(String filename)
     {
         return oneManifest(filename) ;
     }
-    
+
     private TestSuite oneManifest(String filename)
     {
         TestSuite ts1 = new TestSuite() ;
@@ -47,7 +46,7 @@ public abstract class TestFactoryManifestOld implements 
ManifestOldItemHandler
         try {
             m = new ManifestOld(filename) ;
         } catch (JenaException ex)
-        { 
+        {
             LoggerFactory.getLogger(TestFactoryManifestOld.class).warn("Failed 
to load: "+filename+"\n"+ex.getMessage(), ex) ;
             ts1.setName("BROKEN") ;
             return ts1 ;
@@ -55,7 +54,7 @@ public abstract class TestFactoryManifestOld implements 
ManifestOldItemHandler
         if ( m.getName() != null )
             ts1.setName(TestUtils.safeName(m.getName())) ;
         else
-            ts1.setName("Unnamed Manifest") ; 
+            ts1.setName("Unnamed Manifest") ;
 
         // Recurse
         for (Iterator <String>iter = m.includedManifests() ; iter.hasNext() ; )
@@ -65,14 +64,14 @@ public abstract class TestFactoryManifestOld implements 
ManifestOldItemHandler
             currentTestSuite = ts2 ;
             ts1.addTest(ts2) ;
         }
-      
+
         currentTestSuite = ts1 ;
         m.apply(this) ;
         return ts1 ;
     }
-    
+
     protected TestSuite getTestSuite() { return currentTestSuite ; }
-    
+
     /** Handle an item in a manifest */
     @Override
     public final boolean processManifestItem(Resource manifest ,
@@ -87,11 +86,11 @@ public abstract class TestFactoryManifestOld implements 
ManifestOldItemHandler
         return true ;
     }
 
-    
+
     protected abstract Test makeTest(Resource manifest ,
                            Resource item ,
                            String testName ,
                            Resource action ,
                            Resource result) ;
-    
+
 }
diff --git 
a/jena-core/src/test/java/org/apache/jena/ttl_test/test/TestN3IRIResolver.java 
b/jena-core/src/test/java/org/apache/jena/ttl_test/test/TestN3IRIResolver.java
deleted file mode 100644
index 84d4924771..0000000000
--- 
a/jena-core/src/test/java/org/apache/jena/ttl_test/test/TestN3IRIResolver.java
+++ /dev/null
@@ -1,345 +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.ttl_test.test;
-
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-import org.apache.jena.ttl_test.JenaURIException;
-import org.apache.jena.ttl_test.N3IRIResolver;
-@SuppressWarnings("deprecation")
-// Tests the old N3IRIResolver which is now only used for tests. 
-public class TestN3IRIResolver extends TestCase
-{
-    public static TestSuite suite()
-    {
-        TestSuite ts = new TestSuite(TestN3IRIResolver.class) ;
-        ts.setName("TestURI") ;
-        return ts ;
-    }
-    
-    public void testBase1()
-    {
-        N3IRIResolver resolver = new N3IRIResolver() ;
-        assertNotNull(resolver.getBaseIRI()) ;
-        String base = resolver.getBaseIRI() ;
-        assertTrue(base.indexOf(':') > 0 ) ; 
-    }
-    
-    public void testBase2()
-    {
-        N3IRIResolver resolver = new N3IRIResolver("x") ;
-        assertNotNull(resolver.getBaseIRI()) ;
-        // Active when IRI library integrated - currently the resolver takes a 
raw base string.
-//        String base = resolver.getBaseIRI() ;
-//        assertTrue(base.indexOf(':') > 0 ) ; 
-    }
-
-    public void testBase3()
-    {
-        String b = N3IRIResolver.resolveGlobal("x") ;
-        N3IRIResolver resolver = new N3IRIResolver(b) ;
-        assertNotNull(resolver.getBaseIRI()) ;
-        String base = resolver.getBaseIRI() ;
-        assertTrue(base.indexOf(':') > 0 ) ; 
-    }
-    
-    public void testBadBase1() {
-       execException("%G",JenaURIException.class);
-    }
-    public void testBadBase2() {
-       execException("/%G",JenaURIException.class);
-    }
-    public void testBadBase3() {
-       execException("file:/%/",JenaURIException.class);
-    }
-    public void testBadBase4() {
-       execException("http://example.org/%",JenaURIException.class);
-    }
-
-    public void testBadChoice1() {
-       chooseException("%G",JenaURIException.class);
-    }
-    public void testBadChoice2() {
-       chooseException("/%G",JenaURIException.class);
-    }
-    public void testBadChoice3() {
-       chooseException("file:/%/",JenaURIException.class);
-    }
-    public void testChoice1() {
-       choose("file:a");
-    }
-    public void testChoice2() {
-       choose("file:a");
-    }
-    // ---- Basic
-    
-    public void testURI_1()   { execTest("", "http://example.org/";, 
"http://example.org/";); }
-    public void testURI_2()   { execTest("", "http://example.org/xyz_2007";, 
"http://example.org/xyz_2007";); }
-    // RDF URI References - space in URI.  Not IRIs.
-    //public void testURI_3()   { execTest("", "http://example.org/xyz 2007", 
"http://example.org/xyz 2007"); }
-    public void testURI_4()   { execTest("", "http://example.org/xyz__2007";, 
"http://example.org/xyz__2007";); }
-    public void testURI_5()   { execTest("", "http://example.org/xyz__abc";, 
"http://example.org/xyz__abc";); }
-    
-    // ---- Relative URIs
-    
-    public void testURI_relX_1()  { execTest("x", "http://example.org/ns";, 
"http://example.org/x";); }
-
-    public void testURI_relX_2()  { execTest("x", "http://example.org/";, 
"http://example.org/x";); }
-    
-    public void testURI2_relHashX_1()  { execTest("#x", 
"http://example.org/ns";, "http://example.org/ns#x";); }
-    
-    public void testURI2_relHashX_2()  { execTest("#x", 
"http://example.org/ns/";, "http://example.org/ns/#x";); }
-
-    public void testURI_blank_1()  { execTest("", "http://example.org/ns";, 
"http://example.org/ns";) ; }
-
-    public void testURI_blank_2()  { execTest("", "http://example.org/ns/";, 
"http://example.org/ns/";) ; }
-
-    public void testURI_hash_1()  { execTest("#", "http://example.org/ns";, 
"http://example.org/ns#";) ; }
-
-    public void testURI_hash_2()  { execTest("#", "http://example.org/ns/";, 
"http://example.org/ns/#";) ; }
-
-    public void testBaseHash_1() { execTest("x", "http://example.org/ns#";, 
"http://example.org/x";) ; }
-
-    public void testBaseHash_2() { execTest("x", "http://example.org#";, 
"http://example.org/x";) ; }
-    
-    public void testBaseHash_3() { execTest("#", "base:x", "base:x#") ; }
-
-//    // Java5: exception
-//    // Java6 & GNUclasspath: correctly get "base:#"
-//    public void testBaseHash_4() { execTest("#", "base:", "base:#") ; }
-
-    public void testScheme_1() { execTest("x", "base:", "base:x") ; }
-
-    public void testScheme_2() { execTest("/x", "base:", "base:/x") ; }
-
-    public void testScheme_3() { execTestMatch("x", "file:", "^file:///.*/x$") 
; }
-    
-    public void testScheme_4() { execTestMatch("file:x", null, 
"^file:///.*/x$") ; }
-    
-//    public void testURI_file_1()  { execTestMatch("file:x", 
"http://example.org/ns";, "^file:///.*/x$") ; }
-
-    public void testURI_file_2()  { execTest("x", "file:///A/B/C", 
"file:///A/B/x") ; }
-
-    public void testURI_file_3()  { execTest("x", "file:///A/B/", 
"file:///A/B/x") ; }
-
-
-    // ---- Absolute URIs are left alone 
-    
-    public void testURI_abs_1()   { execTest("http://host/x";, 
"http://example.org/ns";, "http://host/x";) ; }
-    
-    public void testURI_abs_2()   { execTest("file:///x", 
"http://example.org/ns";, "file:///x") ; }
-
-    public void testURI_abs_3()   { execTest("tag:foo", 
"http://example.org/ns";, "tag:foo") ; }
-
-    public void testURI_abs_4()   { execTest("tag:/foo", 
"http://example.org/ns";, "tag:/foo") ; }
-
-    public void testURI_abs_5()   { execTest("tag:/foo/", 
"http://example.org/ns";, "tag:/foo/") ; }
-
-    public void testURI_abs_6()   { execTest("scheme99:/foo/", 
"http://example.org/ns";, "scheme99:/foo/") ; }
-    
-    // Null base
-    
-    public void testURI_nullBase_1()   { execTest("scheme99:/foo/", null, 
"scheme99:/foo/") ; }
-    
-    // resolved against current directory
-    public void testURI_nullBase_2()   { execTestMatch("foo", null, ".*/foo") 
; }
-
-    // ---- Hierarchical URIs
-
-    public void testHierURI_1()   { execTest("../foo", "file:///dir/file", 
"file:///foo") ; }
-
-    public void testHierURI_2()   { execTest("../foo", 
"http://host/dir/file.html";, "http://host/foo";) ; }
-    
-    public void testHierURI_3()   { execTest("../foo", "http://host/dir/";, 
"http://host/foo";) ; }
-
-    public void testHierURI_4()   { execTest("../foo", "http://host/";, 
"http://host/foo";) ; }
-    
-    public void testHierURI_5()   { execTest("../foo", "http://host/xyz";, 
"http://host/foo";) ; }
-    
-    public void testHierURI_6()   { execTest(".", "http://host/xyz";, 
"http://host/";) ; }
-
-    public void testHierURI_7()   { execTest(".", "http://host/xyz/";, 
"http://host/xyz/";) ; }
-    
-    public void testHierURI_8()   { execTest(".", "http://host/";, 
"http://host/";) ; }
-    
-    public void testHierURI_9()   { execTest(".", "file:///dir/file", 
"file:///dir/") ; }
-    // ---- File URIs
-    
-    public void testFileURI_1()   { execFileTest("file:///foo", "file:///foo") 
; }
-
-    public void testFileURI_2()   { execFileTest("file://foo", "file://foo") ; 
}
-
-    public void testFileURI_3()   { execFileTest("file:/foo", "file:///foo") ; 
}
-
-    
- // Bad.
-    public void testBad_1()   { execException("%G", "http://example.org/";, 
JenaURIException.class); }
-    public void testBad_2()   { execException("foo", "http://example.org/%HH";, 
JenaURIException.class); }
-    public void testBad_3()   { execException("bar", "http://example.org/%3";, 
JenaURIException.class); }
-    
-    
-    public void testBaseEmpty() { execTestMatch("x", "", "^file:///.*/x$") ; }
-
-    // Resolved against current directory.
-    public void testBaseNull() { execTestMatch("x", null, ".*/x" ) ; }
-
-    public void testRelBase_1() {execTestMatch("x", "ns", ".*/x" );  }
-    
-    public void testRelBase_2() { execTestMatch("x", "/ns", ".*/x" ); }
-
-    // ---- Opaque
-    
-    public void testURI_opaque_1()  { execTest("#x", "tag:A", "tag:A#x") ; }
-
-    public void testURI_opaque_2()  { execTest("#x", "urn:x-jena:A", 
"urn:x-jena:A#x") ; }
-    
-//    public void testURI_opaque_3()  { execException("#x", "urn:x-jena:A", 
RelativeURIException.class) ; }
-
-    // ---- Opaque file URLs
-    
-    // Should these be errors? Yes.
-    //public void testURI_file_4()  { execTest("x", "file:A", "file:Ax") ; }
-    public void testURI_file_4()  {  execTestMatch("x", 
"file:A","^file:///.*/x") ;}
-    
-    public void testURI_file_5()  { execTestMatch("#x", 
"file:A","^file:///.*/A#x") ; }
-    //public void testURI_file_5()  { execException("#x", "file:A", 
RelativeURIException.class) ; }
-    
-    //public void testURI_file_6()   { execTest("foo", "file:///xyz abc/", 
"file:///xyz abc/foo" ) ; }
-    
-    public void testURI_file_7()   { execTestMatch("file:foo", "file:xyz", 
"^file:///.*foo$") ; }
-
-    // RDF URI References - space in URI.  Not IRIs.
-    //public void testURI_file_8()   { execTestMatch("file:foo", "file:a b", 
"^file:///.*foo$") ; }
-    
-    
-    // File URLs - test aren't exact as the depend where they are run.
-    
-    public void testFileURI_rel_1() { execTestFileRelURI("file:foo") ; }
-    
-    public void testFileURI_rel_2() { execTestFileRelURI("file:foo/bar") ; }
-    
-    public void testFileURI_rel_3() { execTestFileRelURI("file:foo/") ; }
-    
-    public void testFileURI_rel_4() { execTestFileRelURI("file:foo/bar/") ; }
-    
-
-    private void execTest(String u, String base, String result)
-    {
-        N3IRIResolver resolver = new N3IRIResolver(base) ;
-        String res = resolver.resolve(u) ;
-
-        if (result == null )
-        {
-            assertNull("("+u+","+base+") => <null> :: Got: "+res, res) ;
-            return ;
-        }
-        
-        assertNotNull("("+u+","+base+") => "+result+" :: Got: <null>", res) ;
-        assertTrue("("+u+","+base+") => "+result+" :: Got: "+res, 
res.equals(result)) ;
-    }
-    
-    // A test for resolved names that depend on where the tests are run.
-    private void execTestMatch(String u, String base, String resultPattern)
-    {
-        N3IRIResolver resolver = new N3IRIResolver(base) ;
-        String res = resolver.resolve(u) ;
-
-        if (resultPattern == null )
-        {
-            assertNull("("+u+","+base+") => <null> :: Got: "+res, res) ;
-            return ;
-        }
-        
-        boolean r = res.matches(resultPattern) ;
-        assertTrue("Does not match: "+res+" -- "+resultPattern, r) ;
-    }
-    
-    private void execFileTest(String fn1, String fn2)
-    {
-        String s = N3IRIResolver.resolveFileURL(fn1) ;
-        assertEquals(s,fn2) ;
-    }
-    
-    private void execTestFileRelURI(String fn)
-    {
-        String relName = fn.substring("file:".length()) ;
-        String s = N3IRIResolver.resolveFileURL(fn) ;
-        assertTrue("Lost relative name: ("+fn+"=>"+s+")", s.endsWith(relName) 
) ;
-        assertTrue("Not absolute: ("+fn+"=>"+s+")", s.startsWith("file:///") ) 
;
-    }
-    
-    private void execException(String u, String base, Class<?> ex)
-    {
-        String s = ex.getSimpleName() ;
-        try {
-            N3IRIResolver resolver = new N3IRIResolver(base) ;
-            String res = resolver.resolve(u) ;
-            if ( res == null )
-                fail("("+u+","+base+") => <null> :: Expected exception: " +s) ;
-            else
-                fail("("+u+","+base+") => "+res+" :: Expected exception: " +s) 
;
-        } catch (Exception ex2)
-        {
-            // Should test whether ex2 is a subclass of ex
-            assertEquals(ex, ex2.getClass()) ;
-        }
-    }
-    private void execException(String base, Class<?> ex)
-    {
-        String s = ex.getSimpleName() ;
-        try {
-            new N3IRIResolver(base) ;
-                 fail("("+base+") => OK :: Expected exception: " +s) ;
-        } catch (Exception ex2)
-        {
-            // Shoudl test whether ex2 is a subclass of ex
-            assertEquals(ex, ex2.getClass()) ;
-        }
-    }
-    private void choose(String base)
-    {
-        
-            N3IRIResolver.chooseBaseURI(base) ;
-        
-    }
-    private void chooseException(String base, Class<?> ex)
-    {
-        String s = ex.getSimpleName() ;
-        try {
-            N3IRIResolver.chooseBaseURI(base) ;
-                 fail("("+base+") => OK :: Expected exception: " +s) ;
-        } catch (Exception ex2)
-        {
-            // Shoudl test whether ex2 is a subclass of ex
-            assertEquals(ex, ex2.getClass()) ;
-        }
-    }
-//    private void execTestGlobal(String u, String result)
-//    {
-//        String res = IRIResolver.resolveGlobal(u) ;
-//        if (result == null )
-//        {
-//            assertNull("("+u+") => <null> :: Got: "+res, res) ;
-//            return ;
-//        }
-//        
-//        assertNotNull("("+u+") => "+result+" :: Got: <null>", res) ;
-//        assertTrue("("+u+") => "+result+" :: Got: "+res, res.equals(result)) 
;
-//    }
-}
diff --git 
a/jena-core/src/test/java/org/apache/jena/ttl_test/turtle/TurtleParserBase.java 
b/jena-core/src/test/java/org/apache/jena/ttl_test/turtle/TurtleParserBase.java
index 3a704ff801..4ed423bb63 100644
--- 
a/jena-core/src/test/java/org/apache/jena/ttl_test/turtle/TurtleParserBase.java
+++ 
b/jena-core/src/test/java/org/apache/jena/ttl_test/turtle/TurtleParserBase.java
@@ -24,25 +24,25 @@ import org.apache.jena.datatypes.xsd.XSDDatatype ;
 import org.apache.jena.graph.Node ;
 import org.apache.jena.graph.NodeFactory ;
 import org.apache.jena.graph.Triple ;
+import org.apache.jena.irix.IRIException;
+import org.apache.jena.irix.IRIs;
+import org.apache.jena.irix.IRIxResolver;
 import org.apache.jena.shared.PrefixMapping ;
 import org.apache.jena.shared.impl.PrefixMappingImpl ;
-import org.apache.jena.ttl_test.JenaURIException;
-import org.apache.jena.ttl_test.N3IRIResolver;
 import org.apache.jena.vocabulary.RDF ;
 
-@SuppressWarnings("deprecation")
 public class TurtleParserBase
 {
     // Should be the same as ARQ ParserBase and Prologues.
     protected final Node XSD_TRUE   = NodeFactory.createLiteral("true", null, 
XSDDatatype.XSDboolean) ;
     protected final Node XSD_FALSE  = NodeFactory.createLiteral("false", null, 
XSDDatatype.XSDboolean) ;
-    
+
     protected final Node nRDFtype       = RDF.type.asNode() ;
-    
+
     protected final Node nRDFnil        = RDF.nil.asNode() ;
     protected final Node nRDFfirst      = RDF.first.asNode() ;
     protected final Node nRDFrest       = RDF.rest.asNode() ;
-    
+
     protected final Node nRDFsubject    = RDF.subject.asNode() ;
     protected final Node nRDFpredicate  = RDF.predicate.asNode() ;
     protected final Node nRDFobject     = RDF.object.asNode() ;
@@ -50,72 +50,72 @@ public class TurtleParserBase
     protected final String SWAP_NS      = "http://www.w3.org/2000/10/swap/"; ;
     protected final String SWAP_LOG_NS  = 
"http://www.w3.org/2000/10/swap/log#"; ;
     protected final Node nLogImplies    = 
NodeFactory.createURI(SWAP_LOG_NS+"implies") ;
-    
+
     protected final Node nOwlSameAs     = 
NodeFactory.createURI("http://www.w3.org/2002/07/owl#sameAs";) ;
-    
+
     protected boolean strictTurtle = true ;
-    protected boolean skolomizedBNodes = true ; 
-    
+    protected boolean skolomizedBNodes = true ;
+
+    protected PrefixMapping prefixMapping = new PrefixMappingImpl() ;
+    protected IRIxResolver resolver = IRIs.stdResolver();
+
     public TurtleParserBase() {}
-    
-    PrefixMapping prefixMapping = new PrefixMappingImpl() ;
-    N3IRIResolver resolver = new N3IRIResolver() ;
-    
-    protected String getBaseURI()       { return resolver.getBaseIRI() ; }
+
+    protected String getBaseURI()       { return resolver.getBaseURI() ; }
     public void setBaseURI(String u)
     {
-        resolver = new N3IRIResolver(u) ;
+        resolver = IRIxResolver.create(u).build();
     }
-    
+
     protected void setBase(String iriStr , int line, int column)
     {
         // Already resolved.
         setBaseURI(iriStr) ;
     }
-    
+
     public PrefixMapping getPrefixMapping() { return prefixMapping ; }
-    
+
     // label => bNode for construct templates patterns
     LabelToNodeMap bNodeLabels = new LabelToNodeMap() ;
-    
-    TurtleEventHandler handler = null ; 
+
+    TurtleEventHandler handler = null ;
     public void setEventHandler(TurtleEventHandler h) { handler = h ; }
-    
+
     protected void emitTriple(int line, int col, Triple triple)
     {
         handler.triple(line, col, triple) ;
     }
-    
+
     protected void startFormula(int line, int col)
     { handler.startFormula(line, col) ; }
-    
+
     protected void endFormula(int line, int col)
     {handler.endFormula(line, col) ; }
-    
+
     protected void setPrefix(int line, int col, String prefix, String uri)
     {
         prefixMapping.setNsPrefix(prefix, uri) ;
         handler.prefix(line, col, prefix, uri) ;
     }
-    
+
     protected int makePositiveInteger(String lexicalForm)
     {
         if ( lexicalForm == null )
             return -1 ;
-        
+
         return Integer.parseInt(lexicalForm) ;
     }
-    
+
     protected Node createLiteralInteger(String lexicalForm)
     {
         return NodeFactory.createLiteral(lexicalForm, null, 
XSDDatatype.XSDinteger) ;
     }
-    
+
     protected Node createLiteralDouble(String lexicalForm)
     {
         return NodeFactory.createLiteral(lexicalForm, null, 
XSDDatatype.XSDdouble) ;
     }
-    
+
     protected Node createLiteralDecimal(String lexicalForm)
     {
         return NodeFactory.createLiteral(lexicalForm, null, 
XSDDatatype.XSDdecimal) ;
@@ -126,7 +126,7 @@ public class TurtleParserBase
         String uri = (datatype==null) ? null : datatype.getURI() ;
         return createLiteral(lexicalForm, langTag,  uri) ;
     }
-    
+
     protected Node createLiteral(String lexicalForm, String langTag, String 
datatypeURI)
     {
         Node n = null ;
@@ -140,7 +140,7 @@ public class TurtleParserBase
             n = NodeFactory.createLiteral(lexicalForm, langTag, null) ;
         return n ;
     }
-    
+
     protected long integerValue(String s)
     {
         if ( s.startsWith("+") )
@@ -153,25 +153,25 @@ public class TurtleParserBase
         }
         return Long.parseLong(s) ;
     }
-    
+
     protected double doubleValue(String s)
     {
         if ( s.startsWith("+") )
             s = s.substring(1) ;
         double valDouble = Double.parseDouble(s) ;
-        return valDouble ; 
+        return valDouble ;
     }
-    
+
     protected String stripQuotes(String s)
     {
         return s.substring(1,s.length()-1)  ;
     }
-    
+
     protected String stripQuotes3(String s)
     {
         return s.substring(3,s.length()-3)  ;
     }
-    
+
     protected String stripChars(String s, int n)
     {
         return s.substring(n, s.length())  ;
@@ -182,24 +182,26 @@ public class TurtleParserBase
         iriStr = stripQuotes(iriStr) ;
         return resolveIRI(iriStr, line, column) ;
     }
-    
+
     protected String resolveIRI(String iriStr , int line, int column)
     {
         if ( isBNodeIRI(iriStr) )
             return iriStr ;
-        
+
         if ( resolver != null )
             iriStr = _resolveIRI(iriStr, line, column) ;
         return iriStr ;
     }
-    
-    private String _resolveIRI(String iriStr , int line, int column)
-    {
-        try { iriStr = resolver.resolve(iriStr) ; }
-        catch (JenaURIException ex) { throwParseException(ex.getMessage(), 
line, column) ; }
-        return iriStr ;
+
+    private String _resolveIRI(String iriStr, int line, int column) {
+        try {
+            return resolver.resolve(iriStr).str();
+        } catch (IRIException ex) {
+            throwParseException(ex.getMessage(), line, column);
+            return null;
+        }
     }
-    
+
     protected String resolvePName(String qname, int line, int column)
     {
         String s = myExpandPrefix(prefixMapping, qname) ;
@@ -219,7 +221,7 @@ public class TurtleParserBase
             // there is no prefix but what s the expanded and original form are
             // actually the same character string ?
             int colon = qname.indexOf( ':' );
-            if (colon < 0) 
+            if (colon < 0)
                 return null ;
             String prefix = qname.substring( 0, colon ) ;
             if ( prefixMapping.getNsPrefixURI(prefix) != null )
@@ -229,17 +231,17 @@ public class TurtleParserBase
         }
         return s ;
     }
-    
+
     final static String bNodeLabelStart = "_:" ;
-    
+
     protected Node createListNode() { return createBNode() ; }
 
     // Unlabelled bNode.
     protected Node createBNode() { return bNodeLabels.allocNode() ; }
-    
+
     //  Labelled bNode.
     protected Node createBNode(String label, int line, int column)
-    { 
+    {
         return bNodeLabels.asNode(label) ;
     }
     protected Node createVariable(String s, int line, int column)
@@ -247,7 +249,7 @@ public class TurtleParserBase
         s = s.substring(1) ; // Drop the marker
         return NodeFactory.createVariable(s) ;
     }
-    
+
     protected Node createNode(String iri)
     {
         // Is it a bNode label? i.e. <_:xyz>
@@ -259,19 +261,19 @@ public class TurtleParserBase
         }
         return NodeFactory.createURI(iri) ;
     }
-    
+
     protected boolean isBNodeIRI(String iri)
     {
         return skolomizedBNodes && iri.startsWith(bNodeLabelStart) ;
     }
-    
 
-    
+
+
 //    protected Node createNodeFromURI(String s, int line, int column)
 //    {
 //        s = stripQuotes(s) ;
 //        String uriStr = s ;     // Mutated
-//        
+//
 //        try {
 //            uriStr = resolver.resolve(uriStr) ;
 //        } catch (JenaURIException ex)
@@ -280,21 +282,21 @@ public class TurtleParserBase
 //        }
 //        return Node.createURI(uriStr) ;
 //    }
-    
+
     protected void throwParseException(String s , int line, int column)
     {
         throw new TurtleParseException(exMsg(s, line, column)) ;
     }
-    
+
     protected String fixupPrefix(String prefix, int line, int column)
     {
         if ( prefix.endsWith(":") )
             prefix = prefix.substring(0, prefix.length()-1) ;
-        return prefix ; 
+        return prefix ;
     }
-    
+
     // Utilities to remove escapes
-    
+
     // Testing interface
     public static String unescapeStr(String s)
     { return unescape(s, '\\', false, 1, 1) ; }
@@ -305,18 +307,18 @@ public class TurtleParserBase
 //    protected String unescapeCodePoint(String s, int line, int column)
 //    { return unescape(s, '\\', true, line, column) ; }
 
-    
+
     protected String unescapeStr(String s, int line, int column)
     { return unescape(s, '\\', false, line, column) ; }
-    
+
     // Worker function
     private static String unescape(String s, char escape, boolean 
pointCodeOnly, int line, int column)
     {
         int i = s.indexOf(escape) ;
-        
+
         if ( i == -1 )
             return s ;
-        
+
         // Dump the initial part straight into the string buffer
         StringBuilder sb = new StringBuilder(s.substring(0,i)) ;
         int len = s.length() ;
@@ -326,7 +328,7 @@ public class TurtleParserBase
             // Keep line and column numbers.
             switch (ch)
             {
-                case '\n': 
+                case '\n':
                 case '\r':
                     line++ ;
                     column = 1 ;
@@ -341,14 +343,14 @@ public class TurtleParserBase
                 sb.append(ch) ;
                 continue ;
             }
-                
+
             // Escape
             if ( i >= len-1 )
                 throw new TurtleParseException(exMsg("Illegal escape at end of 
string", line, column)) ;
             char ch2 = s.charAt(i+1) ;
             column = column+1 ;
             i = i + 1 ;
-            
+
             // \\u and \\U
             if ( ch2 == 'u' )
             {
@@ -374,10 +376,10 @@ public class TurtleParserBase
                 column = column+8 ;
                 continue ;
             }
-            
+
             // Are we doing just point code escapes?
-            // If so, \X-anything else is legal as a literal "\" and "X" 
-            
+            // If so, \X-anything else is legal as a literal "\" and "X"
+
             if ( pointCodeOnly )
             {
                 sb.append('\\') ;
@@ -385,12 +387,12 @@ public class TurtleParserBase
                 i = i + 1 ;
                 continue ;
             }
-            
+
             // Not just codepoints.  Must be a legal escape.
             char ch3 = 0 ;
             switch (ch2)
             {
-                case 'n': ch3 = '\n' ;  break ; 
+                case 'n': ch3 = '\n' ;  break ;
                 case 't': ch3 = '\t' ;  break ;
                 case 'r': ch3 = '\r' ;  break ;
                 case 'b': ch3 = '\b' ;  break ;
@@ -411,7 +413,7 @@ public class TurtleParserBase
     {
 //        if ( i+len >= s.length() )
 //        {
-//            
+//
 //        }
         int x = 0 ;
         for ( int j = i ; j < i+len ; j++ )
@@ -421,7 +423,7 @@ public class TurtleParserBase
            int k = 0  ;
            switch (ch)
            {
-               case '0': k = 0 ; break ; 
+               case '0': k = 0 ; break ;
                case '1': k = 1 ; break ;
                case '2': k = 2 ; break ;
                case '3': k = 3 ; break ;
@@ -444,7 +446,7 @@ public class TurtleParserBase
         }
         return x ;
     }
-    
+
     protected static String exMsg(String msg, int line, int column)
     {
         return "Line " + line + ", column " + column + ": " + msg ;


Reply via email to