From: <svn...@os...> - 2012-03-19 09:16:10
|
Author: bencaradocdavies Date: 2012-03-19 02:15:58 -0700 (Mon, 19 Mar 2012) New Revision: 38635 Added: trunk/modules/library/referencing/src/main/java/org/geotools/referencing/factory/gridshift/DataUtilities.java Modified: trunk/modules/library/referencing/src/main/java/org/geotools/referencing/factory/gridshift/NADCONGridShiftFactory.java trunk/modules/library/referencing/src/main/java/org/geotools/referencing/factory/gridshift/NTv2GridShiftFactory.java Log: Fix for build failure caused by bad URL to File conversions [GEOT-4080] Added: trunk/modules/library/referencing/src/main/java/org/geotools/referencing/factory/gridshift/DataUtilities.java =================================================================== --- trunk/modules/library/referencing/src/main/java/org/geotools/referencing/factory/gridshift/DataUtilities.java (rev 0) +++ trunk/modules/library/referencing/src/main/java/org/geotools/referencing/factory/gridshift/DataUtilities.java 2012-03-19 09:15:58 UTC (rev 38635) @@ -0,0 +1,80 @@ +/* + * GeoTools - The Open Source Java GIS Toolkit + * http://geotools.org + * + * (C) 2012, Open Source Geospatial Foundation (OSGeo) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + */ + +package org.geotools.referencing.factory.gridshift; + +import java.io.File; +import java.io.UnsupportedEncodingException; +import java.net.URL; +import java.net.URLDecoder; + +/** + * Part of DataUtilities from gt-main, which cannot be used here because of cyclic Maven + * dependencies. + * + * <p> + * + * FIXME: module dependencies should be refactored until this class does not need to exist. + * + * @author Ben Caradoc-Davies (CSIRO Earth Science and Resource Engineering) + */ +public class DataUtilities { + + /** + * Copy of DataUtilities.urlToFile(URL url) in gt-main, which cannot be used here because of + * cyclic Maven dependencies. + */ + public static File urlToFile(URL url) { + if (!"file".equals(url.getProtocol())) { + return null; // not a File URL + } + String string = url.toExternalForm(); + if (string.contains("+")) { + // this represents an invalid URL created using either + // file.toURL(); or + // file.toURI().toURL() on a specific version of Java 5 on Mac + string = string.replace("+", "%2B"); + } + try { + string = URLDecoder.decode(string, "UTF-8"); + } catch (UnsupportedEncodingException e) { + throw new RuntimeException("Could not decode the URL to UTF-8 format", e); + } + String path3; + String simplePrefix = "file:/"; + String standardPrefix = "file://"; + String os = System.getProperty("os.name"); + if (os.toUpperCase().contains("WINDOWS") && string.startsWith(standardPrefix)) { + // win32: host/share reference + path3 = string.substring(standardPrefix.length() - 2); + } else if (string.startsWith(standardPrefix)) { + path3 = string.substring(standardPrefix.length()); + } else if (string.startsWith(simplePrefix)) { + path3 = string.substring(simplePrefix.length() - 1); + } else { + String auth = url.getAuthority(); + String path2 = url.getPath().replace("%20", " "); + if (auth != null && !auth.equals("")) { + path3 = "//" + auth + path2; + } else { + path3 = path2; + } + } + return new File(path3); + } + +} Property changes on: trunk/modules/library/referencing/src/main/java/org/geotools/referencing/factory/gridshift/DataUtilities.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:keywords + Id URL Added: svn:eol-style + native Modified: trunk/modules/library/referencing/src/main/java/org/geotools/referencing/factory/gridshift/NADCONGridShiftFactory.java =================================================================== --- trunk/modules/library/referencing/src/main/java/org/geotools/referencing/factory/gridshift/NADCONGridShiftFactory.java 2012-03-17 19:58:42 UTC (rev 38634) +++ trunk/modules/library/referencing/src/main/java/org/geotools/referencing/factory/gridshift/NADCONGridShiftFactory.java 2012-03-19 09:15:58 UTC (rev 38635) @@ -134,8 +134,8 @@ private NADConGridShift loadGridShiftInternal(URL latGridURL, URL longGridURL) throws FactoryException { // decide if text or binary grid will be used - String latGridName = latGridURL.getFile(); - String longGridName = longGridURL.getFile(); + String latGridName = DataUtilities.urlToFile(latGridURL).getPath(); + String longGridName = DataUtilities.urlToFile(longGridURL).getPath(); try { if ((latGridName.endsWith(".las") && longGridName.endsWith(".los")) || (latGridName.endsWith(".LAS") && longGridName.endsWith(".LOS"))) { @@ -316,7 +316,7 @@ ReadableByteChannel channel = null; if (url.getProtocol().equals("file")) { - File file = new File(url.getFile()); + File file = DataUtilities.urlToFile(url); if (!file.exists() || !file.canRead()) { throw new IOException(Errors.format(ErrorKeys.FILE_DOES_NOT_EXIST_$1, file)); Modified: trunk/modules/library/referencing/src/main/java/org/geotools/referencing/factory/gridshift/NTv2GridShiftFactory.java =================================================================== --- trunk/modules/library/referencing/src/main/java/org/geotools/referencing/factory/gridshift/NTv2GridShiftFactory.java 2012-03-17 19:58:42 UTC (rev 38634) +++ trunk/modules/library/referencing/src/main/java/org/geotools/referencing/factory/gridshift/NTv2GridShiftFactory.java 2012-03-19 09:15:58 UTC (rev 38635) @@ -142,7 +142,7 @@ // in memory, but is a quick method to see if file format // is NTv2. if (url.getProtocol().equals("file")) { - File file = new File(url.getFile()); + File file = DataUtilities.urlToFile(url); if (!file.exists() || !file.canRead()) { throw new IOException(Errors.format(ErrorKeys.FILE_DOES_NOT_EXIST_$1, file)); |