From b359ca89d855a5c31b3c7e92bccbd4eceff0e40f Mon Sep 17 00:00:00 2001 From: Julien Acroute Date: Mon, 2 Jul 2018 20:02:54 +0200 Subject: [PATCH 1/2] Get header url and height from geOrchestra datadir It uses: * headerUrl * headerHeight properties from default.properties or geonetwork/geonetwork.properties from geOrchestra datadir --- .../java/org/fao/geonet/util/XslUtil.java | 88 ++++++++++++++++++- web/src/main/webapp/xslt/base-layout.xsl | 2 +- .../webapp/xslt/common/base-variables.xsl | 3 + 3 files changed, 88 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/org/fao/geonet/util/XslUtil.java b/core/src/main/java/org/fao/geonet/util/XslUtil.java index 149584d5a3..ae7e05f852 100644 --- a/core/src/main/java/org/fao/geonet/util/XslUtil.java +++ b/core/src/main/java/org/fao/geonet/util/XslUtil.java @@ -75,11 +75,11 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; +import java.io.File; +import java.io.FileInputStream; import java.io.IOException; -import java.util.Arrays; -import java.util.HashMap; -import java.util.Map; -import java.util.Random; +import java.io.InputStreamReader; +import java.util.*; import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; @@ -103,6 +103,86 @@ public final class XslUtil { private static final char CS_WKT = ' '; private static ThreadLocal allowScripting = new InheritableThreadLocal(); + private static String headerUrl; + private static String headerHeight; + + + public static String getGeorchestraHeaderUrl(){ + + if(XslUtil.headerUrl == null) { + + // Set default value + XslUtil.headerUrl = "/header/"; + + // Load value from datadir + Properties properties = XslUtil.loadDatadirProperties(); + if (properties.containsKey("headerUrl")) + XslUtil.headerUrl = properties.getProperty("headerUrl"); + } + + return XslUtil.headerUrl; + } + + public static String getGeorchestraHeaderHeight(){ + + if(XslUtil.headerHeight == null) { + + // Set default value + XslUtil.headerHeight = "90"; + + // Load value from datadir + Properties properties = XslUtil.loadDatadirProperties(); + if (properties.containsKey("headerHeight")) + XslUtil.headerHeight = properties.getProperty("headerHeight"); + } + + return XslUtil.headerHeight; + } + + private static Properties loadProperties(File path, Properties prop) throws IOException { + FileInputStream fisProp = null; + try { + fisProp = new FileInputStream(path); + InputStreamReader isrProp = new InputStreamReader(fisProp, "UTF8"); + prop.load(isrProp); + } finally { + if (fisProp != null) { + fisProp.close(); + } + } + return prop; + } + + private static Properties loadDatadirProperties(){ + + String globalDatadirPath = System.getProperty("georchestra.datadir"); + Properties properties = new Properties(); + + if (globalDatadirPath != null) { + File defaultConfiguration = new File(String.format("%s%s%s", globalDatadirPath, + File.separator, "default.properties")); + File geoserverConfiguration = new File(String.format("%s%s%s%s%s", globalDatadirPath, + File.separator, "geonetwork", File.separator, "geonetwork.properties")); + + if (defaultConfiguration.canRead()) { + try { + XslUtil.loadProperties(defaultConfiguration, properties); + } catch (IOException e) { + e.printStackTrace(); + } + } + if (geoserverConfiguration.canRead()) { + try { + XslUtil.loadProperties(geoserverConfiguration, properties); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + return properties; + } + + /** * clean the src of ' and <> */ diff --git a/web/src/main/webapp/xslt/base-layout.xsl b/web/src/main/webapp/xslt/base-layout.xsl index 3d322842ad..1e87e37b23 100644 --- a/web/src/main/webapp/xslt/base-layout.xsl +++ b/web/src/main/webapp/xslt/base-layout.xsl @@ -68,7 +68,7 @@ and a facet search to get main site information. --> - +
diff --git a/web/src/main/webapp/xslt/common/base-variables.xsl b/web/src/main/webapp/xslt/common/base-variables.xsl index 6249cfccff..8b86a84ced 100644 --- a/web/src/main/webapp/xslt/common/base-variables.xsl +++ b/web/src/main/webapp/xslt/common/base-variables.xsl @@ -33,6 +33,9 @@ + + + From ac68c71d9efab915180e7351eea2e2bcc565a160 Mon Sep 17 00:00:00 2001 From: Julien Acroute Date: Mon, 9 Jul 2018 14:24:52 +0200 Subject: [PATCH 2/2] Fix name of variable --- core/src/main/java/org/fao/geonet/util/XslUtil.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/org/fao/geonet/util/XslUtil.java b/core/src/main/java/org/fao/geonet/util/XslUtil.java index ae7e05f852..2733ec2e2d 100644 --- a/core/src/main/java/org/fao/geonet/util/XslUtil.java +++ b/core/src/main/java/org/fao/geonet/util/XslUtil.java @@ -161,7 +161,7 @@ private static Properties loadDatadirProperties(){ if (globalDatadirPath != null) { File defaultConfiguration = new File(String.format("%s%s%s", globalDatadirPath, File.separator, "default.properties")); - File geoserverConfiguration = new File(String.format("%s%s%s%s%s", globalDatadirPath, + File geonetworkConfiguration = new File(String.format("%s%s%s%s%s", globalDatadirPath, File.separator, "geonetwork", File.separator, "geonetwork.properties")); if (defaultConfiguration.canRead()) { @@ -171,9 +171,9 @@ private static Properties loadDatadirProperties(){ e.printStackTrace(); } } - if (geoserverConfiguration.canRead()) { + if (geonetworkConfiguration.canRead()) { try { - XslUtil.loadProperties(geoserverConfiguration, properties); + XslUtil.loadProperties(geonetworkConfiguration, properties); } catch (IOException e) { e.printStackTrace(); }