Skip to content

Commit

Permalink
change the way AppConfig and localization manager access resources
Browse files Browse the repository at this point in the history
  • Loading branch information
nilsnolde authored and Timothy Ellersiek committed May 23, 2019
1 parent 095dc84 commit a0e16f4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 17 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Makes docker and docker-compose deployment of openrouteservice more customizable (Issue #434)
- Add the possibility to predefine standard maximum search radii in general and for each used profile in the config file (Issue #418)
### Fixed
- fix classpath issues for resources, Windows builds now (#489)
- isochrone geojson bbox now format compliant (#493)
- v2 isochrones now respects max_locations in app.config (#482)
- Updated documentation to reflect correct isochrone smoothing algorithm (Issue #471)
Expand Down
11 changes: 4 additions & 7 deletions openrouteservice/src/main/java/heigit/ors/config/AppConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import java.io.File;
import java.io.FileFilter;
import java.io.IOException;
import java.net.URL;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand All @@ -29,7 +28,6 @@

import org.apache.log4j.Logger;

import heigit.ors.routing.RoutingProfileManager;
import heigit.ors.util.StringUtility;
import heigit.ors.util.FileUtility;
import org.springframework.core.io.ClassPathResource;
Expand All @@ -48,20 +46,19 @@ public AppConfig(String path)
}

public AppConfig() {
URL url = RoutingProfileManager.class.getClassLoader().getResource("../app.config");
File file;

String appConfigName = "app.config";
if(System.getenv("ORS_APP_CONFIG") != null)
appConfigName = System.getenv("ORS_APP_CONFIG");
try {

ClassPathResource rs = new ClassPathResource(appConfigName);
url = rs.getURL();
file = rs.getFile();
_config = ConfigFactory.parseFile(file);
} catch (IOException ioe) {
LOGGER.error(ioe);
}

File file = new File(url.getPath());
_config = ConfigFactory.parseFile(file);

//Modification by H Leuschner: Save md5 hash of map file in static String for access with every request
File graphsDir = new File(getServiceParameter("routing.profiles.default_params", "graphs_root_path"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
package heigit.ors.localization;

import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Locale;
Expand All @@ -31,6 +29,9 @@

import heigit.ors.util.StringUtility;

import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;

public class LocalizationManager {
protected static Logger LOGGER = LoggerFactory.getLogger(LocalizationManager.class);

Expand Down Expand Up @@ -59,20 +60,19 @@ public static LocalizationManager getInstance() throws Exception

private void loadLocalizations() throws Exception
{
File classFile = new File(getClass().getProtectionDomain().getCodeSource().getLocation().getFile());
String classPath = classFile.getAbsolutePath();
String classesPath = classPath.substring(0, classPath.indexOf("classes") + "classes".length());
Path localesPath = Paths.get(classesPath, "resources", "locales");
PathMatchingResourcePatternResolver resource_pattern = new PathMatchingResourcePatternResolver(this.getClass().getClassLoader());

String filePattern = "ors_(.*?).resources";
Pattern pattern = Pattern.compile(filePattern);
String resourcePattern = "/resources/**/ors_*.resources";

File[] files = new File(localesPath.toString()).listFiles();
Resource[] resources = resource_pattern.getResources(resourcePattern);
Pattern pattern = Pattern.compile(filePattern);

if (files == null)
if (resources.length == 0)
throw new Exception("Resources can not be found.");

for (File file : files) {
for (Resource res : resources) {
File file = res.getFile();
try
{
if (file.isFile()) {
Expand Down

0 comments on commit a0e16f4

Please sign in to comment.