Application properties
(3Q20)
This article provides information on working with property files for exist applications.
Introduction
For most applications it is a good idea to provide settings in a property file. An exist-db-addons library, available in maven central, enables you to do so.
usage
Below a setup for exist-db for properties.
Include exist-db-addons
For example in a Dockerfile:
ARG EXISTADDONSERSION=2.3
COPY exist-db-addons-${EXISTADDONSERSION}.jar $EXIST_HOME/lib/
ENV CLASSPATH=$EXIST_HOME/lib/exist.uber.jar:$EXIST_HOME/lib/exist-db-addons-${EXISTADDONSERSION}.jar
Or include a dependency in exist-db's pom.xml:
<dependency>
<groupId>
org.fryske-akademy
</groupId>
<artifactId>
exist-db-addons
</artifactId>
<version>
2.3
</version>
</dependency>
configure in conf.xml
add the module to exist:
<module uri="http://exist-db.org/xquery/properties" class="org.fryske_akademy.exist.properties.PropertiesModule">
<parameter name="basePath" value="/run/secrets"/>
</module>
use properties in xquery
load and use properties in your xquery
declare namespace properties="http://exist-db.org/xquery/properties";
declare variable $teidictjson:props := properties:loadProperties("teidictjson.properties");
declare function teidictjson:getProperty($key as xs:string, $default as xs:string) as xs:string {
if (map:contains($teidictjson:props,$key)) then
map:get($teidictjson:props,$key)
else
$default
};
optionally mount properties as docker secret
In docker-compose.yml:
secrets:
- source: ${APPNAME}.properties
target: teidictjson.properties
mode: 0444
secrets:
fhwbjson.properties:
external: true