...
When the include
processing instruction is used, the contents of the file specified are read and inserted into the configuration tree at the location where the include tag was specified.
Code Block | |||||||
---|---|---|---|---|---|---|---|
| |||||||
<?xml version="1.0" encoding="UTF-8"?>
<config xmlns="urn:com.cohga.server.config#1.0"...
<?include client_main.xml?>
</config>
|
the client_main.xml
file could contain
Code Block | |||||||
---|---|---|---|---|---|---|---|
| |||||||
<?xml version="1.0" encoding="UTF-8"?>
<config xmlns="urn:com.cohga.server.config#1.0" xmlns:client="urn:com.cohga.html.client#1.0">
<client:config id="main">
<default>true</default>
<debug>false</debug>
<theme>grey</theme>
...
</client:config>
</config>
|
...
The set
instruction can supplement the include
instruction by providing support for variable substitution within the configuration file.
A variation on the previous example can be used when only the hostname needs to change between the development and production servers, so this time config.xml could contain
Code Block | |||||||
---|---|---|---|---|---|---|---|
| |||||||
<?xml version="1.0" encoding="UTF-8"?>
<config xmlns="urn:com.cohga.server.config#1.0"...
<jdbc:dataSource id="datasource.main">
<driver>oracle.jdbc.driver.OracleDriver</driver>
<url><![CDATA[jdbc:oracle:thin:@${HOSTNAME}:1521:GIS]]></url>
<username>reader</username>
<password>0hn0w3rdun</password>
<pool:pool>
<maxActive>15</maxActive>
<minIdle>2</minIdle>
<maxIdle>2</maxIdle>
<testOnBorrow>true</testOnBorrow>
<timeBetweenEvictionRunsMillis>60000</timeBetweenEvictionRunsMillis>
<minEvictableIdleTimeMillis>1200000</minEvictableIdleTimeMillis>
<whenExhaustedAction>grow</whenExhaustedAction>
</pool:pool>
</jdbc:dataSource>
</config>
|
Then the datasource.xml
file on the development server could contain
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
<?set HOSTNAME=development.example.com?>
|
and the datasource.xml
file on the production server could contain
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
<?set HOSTNAME=production.example.com?>
|
...
Of course set
can also be used to locate commonly referenced items in a single location at the start of the config.xml file to allow them to be easily changed later. For example passwords that are updated every month or defaults for functions such as connection timeouts.The
Externally defined values
In addition to the set processing instruction, the value for a substitution variable can also come from system properties , or from a property as defined during the startup of the Java Virtual Machine , not just values set using the set
processing instruction(JVM option). ${property_name} notation can then be used to substitute the values in place.