jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject svn commit: r1490316 - /jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/system/IRIResolver.java
Date Thu, 06 Jun 2013 14:58:19 GMT
Author: andy
Date: Thu Jun  6 14:58:18 2013
New Revision: 1490316

URL: http://svn.apache.org/r1490316
Log:
Reformat

Modified:
    jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/system/IRIResolver.java

Modified: jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/system/IRIResolver.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/system/IRIResolver.java?rev=1490316&r1=1490315&r2=1490316&view=diff
==============================================================================
--- jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/system/IRIResolver.java (original)
+++ jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/system/IRIResolver.java Thu Jun
 6 14:58:18 2013
@@ -16,7 +16,7 @@
  * limitations under the License.
  */
 
-package org.apache.jena.riot.system;
+package org.apache.jena.riot.system ;
 
 import org.apache.jena.atlas.lib.Cache ;
 import org.apache.jena.atlas.lib.CacheFactory ;
@@ -30,92 +30,90 @@ import org.apache.jena.riot.RiotExceptio
 
 public abstract class IRIResolver
 {
-    //static IRIFactory iriFactory = IRIFactory.jenaImplementation() ;
-    //static IRIFactory iriFactory = IRIFactory.iriImplementation();
-    
+    // static IRIFactory iriFactory = IRIFactory.jenaImplementation() ;
+    // static IRIFactory iriFactory = IRIFactory.iriImplementation();
+
     /** The IRI checker setup - more than usual Jena but not full IRI. */
-    public static final IRIFactory iriFactory = new IRIFactory();
-    private static boolean showExceptions = true;
+    public static final IRIFactory iriFactory     = new IRIFactory() ;
+    private static boolean         showExceptions = true ;
     static {
         // IRIFactory.iriImplementation() ...
-        iriFactory.useSpecificationIRI(true);
-        iriFactory.useSchemeSpecificRules("*",true);
+        iriFactory.useSpecificationIRI(true) ;
+        iriFactory.useSchemeSpecificRules("*", true) ;
 
         // Allow relative references for file: URLs.
-        iriFactory.setSameSchemeRelativeReferences("file");
+        iriFactory.setSameSchemeRelativeReferences("file") ;
 
-        //iriFactory.shouldViolation(false,true);
+        // iriFactory.shouldViolation(false,true);
 
         // Moderate it -- allow unwise chars and any scheme name.
-//        iriFactory.setIsError(ViolationCodes.UNWISE_CHARACTER,false);
-//        iriFactory.setIsWarning(ViolationCodes.UNWISE_CHARACTER,false);
+        // iriFactory.setIsError(ViolationCodes.UNWISE_CHARACTER,false);
+        // iriFactory.setIsWarning(ViolationCodes.UNWISE_CHARACTER,false);
 
         // Various errors for unicode conditions.
-//        iriFactory.setIsError(ViolationCodes.NOT_NFC, false) ;
-//        iriFactory.setIsError(ViolationCodes.NOT_NFKC, false) ;
-//        iriFactory.setIsError(ViolationCodes.UNDEFINED_UNICODE_CHARACTER, false) ;
-//        iriFactory.setIsError(ViolationCodes.UNASSIGNED_UNICODE_CHARACTER, false) ;
-//        iriFactory.setIsError(ViolationCodes.COMPATIBILITY_CHARACTER, false) ;
-        
-        iriFactory.setIsError(ViolationCodes.UNREGISTERED_IANA_SCHEME,false);
-        iriFactory.setIsWarning(ViolationCodes.UNREGISTERED_IANA_SCHEME,false);
+        // iriFactory.setIsError(ViolationCodes.NOT_NFC, false) ;
+        // iriFactory.setIsError(ViolationCodes.NOT_NFKC, false) ;
+        // iriFactory.setIsError(ViolationCodes.UNDEFINED_UNICODE_CHARACTER,
+        // false) ;
+        // iriFactory.setIsError(ViolationCodes.UNASSIGNED_UNICODE_CHARACTER,
+        // false) ;
+        // iriFactory.setIsError(ViolationCodes.COMPATIBILITY_CHARACTER, false)
+        // ;
+
+        iriFactory.setIsError(ViolationCodes.UNREGISTERED_IANA_SCHEME, false) ;
+        iriFactory.setIsWarning(ViolationCodes.UNREGISTERED_IANA_SCHEME, false) ;
     }
 
     /** Check an IRI string (does not resolve it) */
-    public static boolean checkIRI(String iriStr)
-    {
-        IRI iri = parseIRI(iriStr);
+    public static boolean checkIRI(String iriStr) {
+        IRI iri = parseIRI(iriStr) ;
         return iri.hasViolation(false) ;
     }
 
     /** Check an IRI string (does not resolve it) - throw exception if not good */
-    public static void validateIRI(String iriStr) throws IRIException
-    {
-        parseIRIex(iriStr);
+    public static void validateIRI(String iriStr) throws IRIException {
+        parseIRIex(iriStr) ;
     }
 
     /** Parse an IRI (does not resolve it) */
-    public static IRI parseIRI(String iriStr)
-    {
-        return iriFactory.create(iriStr);
+    public static IRI parseIRI(String iriStr) {
+        return iriFactory.create(iriStr) ;
     }
 
     /** Parse an IRI (does not resolve it) - throws exception on a bad IRI */
-    public static IRI parseIRIex(String iriStr) throws IRIException
-    {
-        return iriFactory.construct(iriStr);
+    public static IRI parseIRIex(String iriStr) throws IRIException {
+        return iriFactory.construct(iriStr) ;
     }
-    
+
     /**
      * The current working directory, as a string.
      */
-    static private String globalBase = IRILib.filenameToIRI("./") ;
-    
+    static private String      globalBase         = IRILib.filenameToIRI("./") ;
+
     // The global resolver may be accessed by multiple threads
     // but also some actions need consistency across more than one access
-    // so just sync'd access to  globalResolver is not enough, and we need
+    // so just sync'd access to globalResolver is not enough, and we need
     // a lock object.
-    static private Object globalResolverLock = new Object() ;
+    static private Object      globalResolverLock = new Object() ;
     private static IRIResolver globalResolver ;
     // Don't pass out - use the statics here.
-    //public static IRIResolver get() { return globalResolver ; }
-    
+    // public static IRIResolver get() { return globalResolver ; }
+
     /**
      * The current global resolver based on the working directory
      */
     static {
         IRI cwd ;
         try {
-            cwd = iriFactory.construct(globalBase);
+            cwd = iriFactory.construct(globalBase) ;
         } catch (IRIException e) {
-            System.err.println("Unexpected IRIException in initializer: "
-                    + e.getMessage());
-            cwd = iriFactory.create("file:///");
+            System.err.println("Unexpected IRIException in initializer: " + e.getMessage())
;
+            cwd = iriFactory.create("file:///") ;
             e.printStackTrace(System.err) ;
         }
         globalResolver = IRIResolver.create(cwd) ;
     }
-    
+
     /**
      * Turn a filename into a well-formed file: URL relative to the working
      * directory.
@@ -123,17 +121,14 @@ public abstract class IRIResolver
      * @param filename
      * @return String The filename as an absolute URL
      */
-    static public String resolveFileURL(String filename) throws IRIException
-    {
-        synchronized(globalResolverLock)
-        {
-            IRI r = globalResolver.resolve(filename);
-            if (!r.getScheme().equalsIgnoreCase("file")) 
-            {
+    static public String resolveFileURL(String filename) throws IRIException {
+        synchronized (globalResolverLock) {
+            IRI r = globalResolver.resolve(filename) ;
+            if (!r.getScheme().equalsIgnoreCase("file")) {
                 // Pragmatic hack that copes with "c:"
-                return resolveFileURL("./" + filename);
+                return resolveFileURL("./" + filename) ;
             }
-            return r.toString();
+            return r.toString() ;
         }
     }
 
@@ -148,8 +143,7 @@ public abstract class IRIResolver
      * @throws RiotException
      *             If result would not be legal, absolute IRI
      */
-    static public IRI resolve(String relStr, String baseStr) throws RiotException
-    {
+    static public IRI resolve(String relStr, String baseStr) throws RiotException {
         return exceptions(resolveIRI(relStr, baseStr)) ;
     }
 
@@ -164,8 +158,7 @@ public abstract class IRIResolver
      * @throws RiotException
      *             If result would not be legal, absolute IRI
      */
-    static public String resolveString(String relStr, String baseStr) throws RiotException
-    {
+    static public String resolveString(String relStr, String baseStr) throws RiotException
{
         return exceptions(resolveIRI(relStr, baseStr)).toString() ;
     }
 
@@ -178,203 +171,229 @@ public abstract class IRIResolver
      * @throws RiotException
      *             If result would not be legal, absolute IRI
      */
-    static public String resolveString(String relStr) throws RiotException
-    {
+    static public String resolveString(String relStr) throws RiotException {
         return exceptions(resolveIRI(relStr)).toString() ;
     }
 
-
-    /** Resolve an IRI against whatever is the base for this process 
-     * (likely to be based on the current working directory of this process
-     * at the time of initialization of this class).
+    /**
+     * Resolve an IRI against whatever is the base for this process (likely to
+     * be based on the current working directory of this process at the time of
+     * initialization of this class).
      */
-    public static IRI resolveIRI(String uriStr)
-    {
+    public static IRI resolveIRI(String uriStr) {
         return exceptions(globalResolver.resolve(uriStr)) ;
     }
-    
+
     /*
      * No exception thrown by this method.
      */
-    static private IRI resolveIRI(String relStr, String baseStr)
-    {
-        synchronized(globalResolverLock)
-        {
-            IRI i = iriFactory.create(relStr);
+    static private IRI resolveIRI(String relStr, String baseStr) {
+        synchronized (globalResolverLock) {
+            IRI i = iriFactory.create(relStr) ;
             if (i.isAbsolute())
                 // removes excess . segments
-                return globalResolver.getBaseIRI().create(i);
+                return globalResolver.getBaseIRI().create(i) ;
 
-            IRI base = iriFactory.create(baseStr);
+            IRI base = iriFactory.create(baseStr) ;
 
             if ("file".equalsIgnoreCase(base.getScheme()))
-                return globalResolver.getBaseIRI().create(i);
-            return base.create(i);
+                return globalResolver.getBaseIRI().create(i) ;
+            return base.create(i) ;
         }
     }
 
-    public static IRIResolver create()                  { return new IRIResolverNormal()
; }
-    
-    public static IRIResolver create(String baseStr)    { return new IRIResolverNormal(baseStr)
; }
-    
-    public static IRIResolver create(IRI baseIRI)       { return new IRIResolverNormal(baseIRI)
; } 
+    public static IRIResolver create() {
+        return new IRIResolverNormal() ;
+    }
+
+    public static IRIResolver create(String baseStr) {
+        return new IRIResolverNormal(baseStr) ;
+    }
+
+    public static IRIResolver create(IRI baseIRI) {
+        return new IRIResolverNormal(baseIRI) ;
+    }
 
     // Used for N-triples, N-Quads
-    public static IRIResolver createNoResolve()         { return new IRIResolverNoOp() ;
} 
+    public static IRIResolver createNoResolve() {
+        return new IRIResolverNoOp() ;
+    }
 
     /**
-        To allow Eyeball to bypass IRI checking (because it's doing its own)
-    */
-    public static void suppressExceptions()
-    { showExceptions = false; }
+     * To allow Eyeball to bypass IRI checking (because it's doing its own)
+     */
+    public static void suppressExceptions() {
+        showExceptions = false ;
+    }
 
     /**
      * Choose a base URI based on the current directory
      * 
      * @return String Absolute URI
      */
-    
+
     static public IRI chooseBaseURI() {
-        synchronized(globalResolverLock)
-        {
+        synchronized (globalResolverLock) {
             return globalResolver.getBaseIRI() ;
         }
     }
 
-    public String getBaseIRIasString()
-    { 
+    public String getBaseIRIasString() {
         IRI iri = getBaseIRI() ;
-        if ( iri == null )
+        if (iri == null)
             return null ;
-        return iri.toString();
+        return iri.toString() ;
     }
+
     protected abstract IRI getBaseIRI() ;
-    
+
     /** Create a URI, resolving relative IRIs, and throw exception on bad a IRI */
     public abstract IRI resolve(String uriStr) ;
-    /** Create a URI, resolving relative IRIs, but do not throw exception on bad a IRI */
+
+    /**
+     * Create a URI, resolving relative IRIs, but do not throw exception on bad
+     * a IRI
+     */
     public abstract IRI resolveSilent(String uriStr) ;
-    
+
     /** Resolving relative IRIs, return a string */
-    public String resolveToString(String uriStr) { return resolve(uriStr).toString() ; }
-    
-    /** Resolving relative IRIs, return a string, but do not throw exception on bad a IRI
*/
-    public String resolveToStringSilent(String uriStr) { return resolveSilent(uriStr).toString()
; }
-    
-    protected IRIResolver() {}
-    
+    public String resolveToString(String uriStr) {
+        return resolve(uriStr).toString() ;
+    }
+
+    /**
+     * Resolving relative IRIs, return a string, but do not throw exception on
+     * bad a IRI
+     */
+    public String resolveToStringSilent(String uriStr) {
+        return resolveSilent(uriStr).toString() ;
+    }
+
+    protected IRIResolver()
+    {}
+
 //    /**
 //     * Print violations - convenience.
+//     * 
 //     * @param iri
 //     * @return iri
 //     */
 //    static private IRI exceptions2(IRI iri) {
 //        if (showExceptions && iri.hasViolation(false)) {
 //            try {
-//                IRI iri2 = cwd.create(iri);
+//                IRI iri2 = cwd.create(iri) ;
 //                Iterator<Violation> vIter = iri2.violations(true) ;
-//                for ( ; vIter.hasNext() ; )
-//                {
+//                for (; vIter.hasNext();) {
 //                    Violation v = vIter.next() ;
 //                    System.err.println(v) ;
 //                }
 //            } catch (IRIException e) {
-//                throw new RiotException(e);
+//                throw new RiotException(e) ;
 //            }
 //        }
-//        return iri;
+//        return iri ;
 //    }
-    
+
     /**
      * Throw any exceptions resulting from IRI.
+     * 
      * @param iri
      * @return iri
      */
     private static IRI exceptions(IRI iri) {
-        if ( !showExceptions ) return iri ;
-        if ( ! iri.hasViolation(false) ) return iri ;
+        if (!showExceptions)
+            return iri ;
+        if (!iri.hasViolation(false))
+            return iri ;
         String msg = iri.violations(false).next().getShortMessage() ;
         throw new RiotException(msg) ;
     }
 
     private static final int CacheSize = 1000 ;
 
-    /** A resolver that does not resolve IRIs against base.  Can generate relative IRIs.
**/ 
+    /**
+     * A resolver that does not resolve IRIs against base. Can generate relative
+     * IRIs.
+     **/
     static class IRIResolverNoOp extends IRIResolver
     {
-        protected IRIResolverNoOp() {}
+        protected IRIResolverNoOp()
+        {}
 
         private Cache<String, IRI> resolvedIRIs = CacheFactory.createCache(CacheSize)
;
 
         @Override
-        protected IRI getBaseIRI()
-        {
+        protected IRI getBaseIRI() {
             return null ;
         }
 
         @Override
-        public IRI resolve(String uriStr)
-        {
+        public IRI resolve(String uriStr) {
             return exceptions(resolveSilent(uriStr)) ;
         }
 
         @Override
-        public IRI resolveSilent(String uriStr)
-        {
-            if ( resolvedIRIs != null  &&  resolvedIRIs.containsKey(uriStr) )
+        public IRI resolveSilent(String uriStr) {
+            if (resolvedIRIs != null && resolvedIRIs.containsKey(uriStr))
                 return resolvedIRIs.get(uriStr) ;
             IRI iri = iriFactory.create(uriStr) ;
-            if ( resolvedIRIs != null )
+            if (resolvedIRIs != null)
                 resolvedIRIs.put(uriStr, iri) ;
             return iri ;
         }
 
         @Override
-        public String resolveToString(String uriStr)
-        {
+        public String resolveToString(String uriStr) {
             return uriStr ;
         }
     }
 
-    /** Resolving resolver **/   
+    /** Resolving resolver **/
     static class IRIResolverNormal extends IRIResolver
     {
-        final private IRI base;
+        final private IRI          base ;
         // Not static - contains relative IRIs
         // Could split into absolute (static, global cached) and relative.
         private Cache<String, IRI> resolvedIRIs = CacheFactory.createCache(CacheSize)
;
 
         /**
-         * Construct an IRIResolver with base as the 
-         * current working directory.
-         *
+         * Construct an IRIResolver with base as the current working directory.
+         * 
          */
-        public IRIResolverNormal() { this((String)null); }
+        public IRIResolverNormal()
+        {
+            this((String)null) ;
+        }
 
         /**
-         * Construct an IRIResolver with base determined
-         * by the argument URI. If this is relative,
-         * it is relative against the current working directory.
+         * 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 RiotException If resulting base unparsable.
+         * @throws RiotException
+         *             If resulting base unparsable.
          */
-        public IRIResolverNormal(String baseS) {
+        public IRIResolverNormal(String baseS)
+        {
             if (baseS == null)
-                base = chooseBaseURI();
+                base = chooseBaseURI() ;
             else
-                synchronized(globalResolverLock) {
+                synchronized (globalResolverLock) {
                     base = globalResolver.resolveSilent(baseS) ;
                 }
         }
 
-        public IRIResolverNormal(IRI baseIRI) {
+        public IRIResolverNormal(IRI baseIRI)
+        {
             if (baseIRI == null)
-                baseIRI = chooseBaseURI();
+                baseIRI = chooseBaseURI() ;
             base = baseIRI ;
         }
 
         /**
          * The base of this IRIResolver.
+         * 
          * @return String
          */
         @Override
@@ -383,34 +402,31 @@ public abstract class IRIResolver
         }
 
         /**
-         * Resolve the relative URI against the base of
-         * this IRIResolver.
+         * Resolve the relative URI against the base of this IRIResolver.
+         * 
          * @param relURI
          * @return the resolved IRI
          * @throws RiotException
          *             If resulting URI would not be legal, absolute IRI
-
          */
         @Override
-        public IRI resolve(String relURI)
-        {
+        public IRI resolve(String relURI) {
             return exceptions(resolveSilent(relURI)) ;
         }
 
         /**
-         * Resolve the relative URI against the base of
-         * this IRIResolver.  
+         * Resolve the relative URI against the base of this IRIResolver.
+         * 
          * @param relURI
          * @return the resolved IRI - not checked for violations.
          */
 
         @Override
-        public IRI resolveSilent(String relURI)
-        {
-            if ( resolvedIRIs != null && resolvedIRIs.containsKey(relURI) ) 
+        public IRI resolveSilent(String relURI) {
+            if (resolvedIRIs != null && resolvedIRIs.containsKey(relURI))
                 return resolvedIRIs.get(relURI) ;
             IRI iri = base.resolve(relURI) ;
-            if ( resolvedIRIs != null )
+            if (resolvedIRIs != null)
                 resolvedIRIs.put(relURI, iri) ;
             return iri ;
         }



Mime
View raw message