diff --git a/docs/userguide/src/site/pages/thredds/ThreddsConfigRef.md b/docs/userguide/src/site/pages/thredds/ThreddsConfigRef.md index 9b5c45f34b..5544c8f1db 100644 --- a/docs/userguide/src/site/pages/thredds/ThreddsConfigRef.md +++ b/docs/userguide/src/site/pages/thredds/ThreddsConfigRef.md @@ -236,6 +236,7 @@ The following shows all the configuration options available in the WMS section o true false wmsPalettes + wmsStyles 2048 2048 @@ -259,6 +260,13 @@ where they are contained. * More information on the format of palette files can also be found in the [ncWMS documentation](https://reading-escience-centre.gitbooks.io/ncwms-user-guide/content/06-development.html#:~:text=To%20add%20new,in%20hexadecimal%20notation.). * If you created palette files for TDS 4.x and would like to use them in TDS 5.x, an open source tool named [Magic Palette Converter](https://github.com/billyz313/magic-palette-converter){:target="_blank"} for THREDDS is available to assist in the conversion (special thanks to [Billy Ashmall](https://github.com/Unidata/tds/discussions/346){:target="_blank"}!) +* `stylesLocationDir`: optionally specify the location of the directory containing your own style files, by specifying the directory + where they are contained. + * If the directory location starts with a `/`, the path is absolute, otherwise it is relative to `${tds.content.root.path}/thredds/`. + * The default directory for custom styles files is `${tds.content.root.path}/thredds/wmsStyles`. + * If you don't specify a custom styles directory, or specify it incorrectly, the default directory will be used. + * More information on the format of style files can also be found in the + [ncWMS documentation](https://reading-escience-centre.gitbooks.io/ncwms-user-guide/content/06-development.html#styles). * `maxImageWidth`: the maximum image width in pixels that this WMS service will return. * `maxImageHeight`: the maximum image height in pixels that this WMS service will return. diff --git a/tds/src/main/java/thredds/server/config/TdsConfigMapper.java b/tds/src/main/java/thredds/server/config/TdsConfigMapper.java index dd56f5160b..cb1e3a640b 100644 --- a/tds/src/main/java/thredds/server/config/TdsConfigMapper.java +++ b/tds/src/main/java/thredds/server/config/TdsConfigMapper.java @@ -16,6 +16,7 @@ import thredds.server.wms.ThreddsWmsCatalogue; import thredds.server.wms.config.WmsDetailedConfig; import uk.ac.rdg.resc.edal.graphics.utils.ColourPalette; +import uk.ac.rdg.resc.edal.graphics.utils.SldTemplateStyleCatalogue; /** * Centralize the mapping of threddsConfig.xml configuration settings to the data objects used by @@ -173,6 +174,7 @@ enum WmsConfigMappings { WMS_ALLOW("WMS.allow", null, "true"), WMS_ALLOW_REMOTE("WMS.allowRemote", null, "false"), WMS_PALETTE_LOCATION_DIR("WMS.paletteLocationDir", null, null), + WMS_STYLES_LOCATION_DIR("WMS.stylesLocationDir", null, null), WMS_MAXIMUM_IMAGE_WIDTH("WMS.maxImageWidth", null, "2048"), WMS_MAXIMUM_IMAGE_HEIGHT("WMS.maxImageHeight", null, "2048"), WMS_CONFIG_FILE("WMS.configFile", null, null); @@ -200,14 +202,14 @@ String getValueFromThreddsConfig() { static void load(WmsConfigBean wmsConfig, TdsContext tdsContext) { final String defaultPaletteLocation = tdsContext.getThreddsDirectory() + "/wmsPalettes"; + final String defaultStylesLocation = tdsContext.getThreddsDirectory() + "/wmsStyles"; final String defaultWmsConfigFile = tdsContext.getThreddsDirectory() + "/wmsConfig.xml"; wmsConfig.setAllow(Boolean.parseBoolean(WMS_ALLOW.getValueFromThreddsConfig())); wmsConfig.setAllowRemote(Boolean.parseBoolean(WMS_ALLOW_REMOTE.getValueFromThreddsConfig())); - String paletteLocation = WMS_PALETTE_LOCATION_DIR.getValueFromThreddsConfig(); - if (paletteLocation == null) - paletteLocation = defaultPaletteLocation; + final String paletteLocation = + getValueFromThreddsConfigOrDefault(WMS_PALETTE_LOCATION_DIR, defaultPaletteLocation); wmsConfig.setPaletteLocationDir(paletteLocation); try { ColourPalette.addPaletteDirectory(new File(paletteLocation)); @@ -221,9 +223,17 @@ static void load(WmsConfigBean wmsConfig, TdsContext tdsContext) { } } - String wmsConfigFile = WMS_CONFIG_FILE.getValueFromThreddsConfig(); - if (wmsConfigFile == null) - wmsConfigFile = defaultWmsConfigFile; + final String stylesLocation = getValueFromThreddsConfigOrDefault(WMS_STYLES_LOCATION_DIR, defaultStylesLocation); + wmsConfig.setStylesLocationDir(stylesLocation); + try { + SldTemplateStyleCatalogue.getStyleCatalogue().addStylesInDirectory(new File(stylesLocation)); + } catch (FileNotFoundException e) { + if (!stylesLocation.equals(defaultStylesLocation)) { + startupLog.warn("Could not find custom styles directory {}", stylesLocation, e); + } + } + + final String wmsConfigFile = getValueFromThreddsConfigOrDefault(WMS_CONFIG_FILE, defaultWmsConfigFile); WmsDetailedConfig wdc = WmsDetailedConfig.fromLocation(wmsConfigFile); if (wdc == null) { @@ -261,6 +271,14 @@ static void load(WmsConfigBean wmsConfig, TdsContext tdsContext) { } } + private static String getValueFromThreddsConfigOrDefault(WmsConfigMappings property, String defaultValue) { + final String value = property.getValueFromThreddsConfig(); + if (value == null) { + return defaultValue; + } + return value; + } + enum TdsUpdateConfigMappings { TDSUPDAATE_LOGVERSIONINFO("TdsUpdateConfig.logVersionInfo", null, "true"); diff --git a/tds/src/main/java/thredds/server/config/WmsConfigBean.java b/tds/src/main/java/thredds/server/config/WmsConfigBean.java index d2bdb4f7e0..4051006e95 100644 --- a/tds/src/main/java/thredds/server/config/WmsConfigBean.java +++ b/tds/src/main/java/thredds/server/config/WmsConfigBean.java @@ -19,6 +19,7 @@ public class WmsConfigBean { private boolean allow; private boolean allowRemote; private String paletteLocationDir; + private String stylesLocationDir; private int maxImageWidth; private int maxImageHeight; @@ -49,6 +50,14 @@ public void setPaletteLocationDir(String paletteLocationDir) { this.paletteLocationDir = paletteLocationDir; } + public String getStylesLocationDir() { + return stylesLocationDir; + } + + public void setStylesLocationDir(String stylesLocationDir) { + this.stylesLocationDir = stylesLocationDir; + } + public int getMaxImageWidth() { return maxImageWidth; }