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/10/21 22:01:27 UTC

[2/5] jena git commit: JENA-1051: Clean initialization of IRIResolver.

JENA-1051: Clean initialization of IRIResolver.

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

Branch: refs/heads/master
Commit: 10625df1a5405d215350b43a4ff0c9b52e3983a8
Parents: fbf46ba
Author: Andy Seaborne <an...@apache.org>
Authored: Wed Oct 21 20:45:25 2015 +0100
Committer: Andy Seaborne <an...@apache.org>
Committed: Wed Oct 21 20:45:25 2015 +0100

----------------------------------------------------------------------
 .../apache/jena/riot/system/IRIResolver.java    | 69 +++++++++++++++-----
 1 file changed, 53 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/10625df1/jena-arq/src/main/java/org/apache/jena/riot/system/IRIResolver.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/riot/system/IRIResolver.java b/jena-arq/src/main/java/org/apache/jena/riot/system/IRIResolver.java
index 3c6bc2a..2ecb8d1 100644
--- a/jena-arq/src/main/java/org/apache/jena/riot/system/IRIResolver.java
+++ b/jena-arq/src/main/java/org/apache/jena/riot/system/IRIResolver.java
@@ -18,6 +18,7 @@
 
 package org.apache.jena.riot.system ;
 
+import java.io.PrintStream ;
 import java.util.concurrent.Callable ;
 
 import org.apache.jena.atlas.lib.Cache ;
@@ -27,6 +28,7 @@ import org.apache.jena.iri.IRI ;
 import org.apache.jena.iri.IRIException ;
 import org.apache.jena.iri.IRIFactory ;
 import org.apache.jena.iri.ViolationCodes ;
+import org.apache.jena.iri.impl.PatternCompiler ;
 import org.apache.jena.riot.RiotException ;
 
 /** IRI handling */
@@ -38,8 +40,10 @@ public abstract class IRIResolver
      *  
      *  @see IRIFactory
      */
-    public static final IRIFactory iriFactory     = new IRIFactory() ;
-    private static boolean         showExceptions = true ;
+    public static final IRIFactory iriFactory        = new IRIFactory();
+    private static boolean         showExceptions    = true;
+    
+    private static final boolean   ShowResolverSetup = false;
     static {
         // These two are from IRIFactory.iriImplementation() ...
         iriFactory.useSpecificationIRI(true) ;
@@ -48,30 +52,42 @@ public abstract class IRIResolver
         // Allow relative references for file: URLs.
         iriFactory.setSameSchemeRelativeReferences("file") ;
 
-        setErrorWarning(iriFactory, ViolationCodes.UNREGISTERED_IANA_SCHEME, false, false) ;
+        // Convert "SHOULD" to warning (default is "error").
+        // iriFactory.shouldViolation(false,true);
 
-        // XXX Default?
-        // TODO turn off?? (ignored in CheckerIRI.iriViolations anyway).
-        //set(iriFactory, ViolationCodes.LOWERCASE_PREFERRED, false, false) ;
-        //set(iriFactory, ViolationCodes.PERCENT_ENCODING_SHOULD_BE_UPPERCASE, false, false) ;
-        //set(iriFactory, ViolationCodes.SCHEME_PATTERN_MATCH_FAILED, false, false) ;
+        if ( ShowResolverSetup ) {
+            System.out.println("---- Default settings ----") ;
+            printSetting(iriFactory) ;
+        }
         
-        // iriFactory.shouldViolation(false,true);
+        setErrorWarning(iriFactory, ViolationCodes.UNREGISTERED_IANA_SCHEME, false, false) ;
+
+        // Turn off?? (ignored in CheckerIRI.iriViolations anyway).
+        // setErrorWarning(iriFactory, ViolationCodes.LOWERCASE_PREFERRED, false, false) ;
+        // setErrorWarning(iriFactory, ViolationCodes.PERCENT_ENCODING_SHOULD_BE_UPPERCASE, false, false) ;
+        // setErrorWarning(iriFactory, ViolationCodes.SCHEME_PATTERN_MATCH_FAILED, false, false) ;
         
-        //  NFC tests are not well understood and these cause confusion.
+        // NFC tests are not well understood and these cause confusion.
+        // See JENA-864
         //iriFactory.setIsError(ViolationCodes.NOT_NFC, false) ;
         //iriFactory.setIsError(ViolationCodes.NOT_NFKC, false) ;
 
         // ** Applies to various unicode blocks. 
-        // XXX Default?
-        // set(iriFactory, ViolationCodes.COMPATIBILITY_CHARACTER, false, false) ;
+        // setErrorWarning(iriFactory, ViolationCodes.COMPATIBILITY_CHARACTER, false, false) ;
+
+        // Moderate it -- allow unwise chars.
+        setErrorWarning(iriFactory, ViolationCodes.UNWISE_CHARACTER, false, false) ;
+        setErrorWarning(iriFactory, ViolationCodes.UNDEFINED_UNICODE_CHARACTER, false, false) ;
+
+        if ( ShowResolverSetup ) {
+            System.out.println("---- After initialization ----") ;
+            printSetting(iriFactory) ;
+        }
 
-        // XXX Default?
-        // Moderate it -- allow unwise chars and any scheme name.
-        //set(iriFactory, ViolationCodes.UNWISE_CHARACTER, false, false) ;
-        //set(iriFactory, ViolationCodes.UNDEFINED_UNICODE_CHARACTER, false, false) ;
     }
 
+    // ---- Initialization support
+    
     /** Set the error/warnign state of a violation code.
      * @param factory   IRIFactory
      * @param code      ViolationCodes constant
@@ -83,6 +99,27 @@ public abstract class IRIResolver
         factory.setIsWarning(code, isWarning);
     }
     
+    private static void printSetting(IRIFactory factory) {
+        PrintStream ps = System.out ;
+        printErrorWarning(ps, iriFactory, ViolationCodes.UNREGISTERED_IANA_SCHEME) ;
+        printErrorWarning(ps, iriFactory, ViolationCodes.NOT_NFC) ;
+        printErrorWarning(ps, iriFactory, ViolationCodes.NOT_NFKC) ;
+        printErrorWarning(ps, iriFactory, ViolationCodes.UNWISE_CHARACTER) ;
+        printErrorWarning(ps, iriFactory, ViolationCodes.UNDEFINED_UNICODE_CHARACTER) ;
+        printErrorWarning(ps, iriFactory, ViolationCodes.COMPATIBILITY_CHARACTER) ;
+        printErrorWarning(ps, iriFactory, ViolationCodes.LOWERCASE_PREFERRED) ;
+        printErrorWarning(ps, iriFactory, ViolationCodes.PERCENT_ENCODING_SHOULD_BE_UPPERCASE) ;
+        printErrorWarning(ps, iriFactory, ViolationCodes.SCHEME_PATTERN_MATCH_FAILED) ;
+        ps.println() ;
+    }
+    
+    private static void printErrorWarning(PrintStream ps, IRIFactory factory, int code) {
+        String x = PatternCompiler.errorCodeName(code);
+        ps.printf("%-40s : E:%-5s W:%-5s\n", x, factory.isError(code), factory.isWarning(code)) ;
+    }
+
+    // ---- System-wide operations.
+    
     /** Check an IRI string (does not resolve it) */
     public static boolean checkIRI(String iriStr) {
         IRI iri = parseIRI(iriStr) ;