Skip to content

Commit

Permalink
Merge pull request #79 from georchestra/factorize_header_url
Browse files Browse the repository at this point in the history
Get header url and height from geOrchestra datadir
  • Loading branch information
fvanderbiest committed Jul 9, 2018
2 parents 904ab94 + ac68c71 commit a960992
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 5 deletions.
88 changes: 84 additions & 4 deletions core/src/main/java/org/fao/geonet/util/XslUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -103,6 +103,86 @@ public final class XslUtil {
private static final char CS_WKT = ' ';
private static ThreadLocal<Boolean> allowScripting = new InheritableThreadLocal<Boolean>();

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 geonetworkConfiguration = 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 (geonetworkConfiguration.canRead()) {
try {
XslUtil.loadProperties(geonetworkConfiguration, properties);
} catch (IOException e) {
e.printStackTrace();
}
}
}
return properties;
}


/**
* clean the src of ' and <>
*/
Expand Down
2 changes: 1 addition & 1 deletion web/src/main/webapp/xslt/base-layout.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
and a facet search to get main site information.
-->
<body data-ng-controller="GnCatController">
<iframe src="/header/?active=geonetwork" style="width:100%;height:90px;border:none;overflow:hidden;" scrolling="no" frameborder="0"></iframe>
<iframe src="{$headerUrl}?active=geonetwork" style="width:100%;height:{$headerHeight}px;border:none;overflow:hidden;" scrolling="no" frameborder="0"></iframe>

<div data-gn-alert-manager=""></div>

Expand Down
3 changes: 3 additions & 0 deletions web/src/main/webapp/xslt/common/base-variables.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
<xsl:output name="default-indent-mode" indent="yes"
omit-xml-declaration="yes"/>

<xsl:variable name="headerUrl" select="util:getGeorchestraHeaderUrl()"/>
<xsl:variable name="headerHeight" select="util:getGeorchestraHeaderHeight()"/>

<!--
-->
<xsl:variable name="gnUri" select="'http://www.fao.org/geonetwork'"/>
Expand Down

0 comments on commit a960992

Please sign in to comment.