Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get header url and height from geOrchestra datadir #79

Merged
merged 2 commits into from
Jul 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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