Skip to content

Commit

Permalink
[GEOS-11050] Refactor Resources and Paths API to support alternative …
Browse files Browse the repository at this point in the history
…ResourceStore implementations
  • Loading branch information
NielsCharlier authored and jodygarnett committed Feb 29, 2024
1 parent a5f13f9 commit ce2c876
Showing 1 changed file with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import java.io.File;
import java.io.IOException;
import java.io.Serializable;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand All @@ -19,7 +21,7 @@
import org.geoserver.catalog.WorkspaceInfo;
import org.geoserver.importer.job.ProgressMonitor;
import org.geoserver.platform.GeoServerExtensions;
import org.geoserver.platform.resource.Files;
import org.geoserver.platform.resource.FilePaths;
import org.geoserver.platform.resource.Paths;
import org.geotools.api.data.DataStoreFactorySpi;
import org.geotools.api.data.FileDataStoreFactorySpi;
Expand Down Expand Up @@ -114,9 +116,19 @@ protected String relativeDataFileURL(String url, Catalog catalog) {
return url;
}
File baseDirectory = catalog.getResourceLoader().getBaseDirectory();
File f = Files.url(baseDirectory, url);
File f;
try {
f = new File(new URL(url).getFile());
} catch (MalformedURLException e) {
f = new File(url);
}

return f == null ? url : "file:" + Paths.convert(baseDirectory, f);
String relativePath = Paths.convert(baseDirectory, f);
if (!FilePaths.isAbsolute(relativePath)) {
return "file:" + relativePath;
} else {
return url;
}
}

public abstract String getName();
Expand Down

0 comments on commit ce2c876

Please sign in to comment.