property-interpolation.rst 4.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. .. _app-schema.property-interpolation:
  2. Property Interpolation
  3. ======================
  4. Interpolation in this context means the substitution of variables into strings. GeoServer app-schema supports the interpolation of properties (the Java equivalent of environment variables) into app-schema mapping files. This can be used, for example, to simplify the management of database connection parameters that would otherwise be hardcoded in a particular mapping file. This enables data directories to be given to third parties without inapplicable authentication or system configuration information. Externalising these parameters make management easier.
  5. Defining properties
  6. -------------------
  7. * If the system property ``app-schema.properties`` is not set, properties are loaded from ``WEB-INF/classes/app-schema.properties`` (or another resource ``/app-schema.properties`` on the classpath).
  8. * If the system property ``app-schema.properties`` is set, properties are loaded from the file named as the value of the property. This is principally intended for debugging, and is designed to be used in an Eclipse launch configuration.
  9. * For example, if the JVM is started with ``-Dapp-schema.properties=/path/to/some/local.properties``, properties are loaded from ``/path/to/some/local.properties``.
  10. * System properties override properties defined in a configuration file, so if you define ``-Dsome.property`` at the java command line, it will override a value specified in the ``app-schema.properties`` file. This is intended for debugging, so you can set a property file in an Eclipse launch configuration, but override some of the properties contained in the file by setting them explicitly as system properties.
  11. * All system properties are available for interpolation in mapping files.
  12. Predefined properties
  13. ---------------------
  14. If not set elsewhere, the following properties are set for each mapping file:
  15. * ``config.file`` is set to the name of the mapping file
  16. * ``config.parent`` is set to the name of the directory containing the mapping file
  17. Using properties
  18. ----------------
  19. * Using ``${some.property}`` anywhere in the mapping file will cause it to be replaced by the value of the property ``some.property``.
  20. * It is an error for a property that has not been set to be used for interpolation.
  21. * Interpolation is performed repeatedly, so values can contain new interpolations. Use this behaviour with caution because it may cause an infinite loop.
  22. * Interpolation is performed before XML parsing, so can be used to include arbitrary chunks of XML.
  23. Example of property interpolation
  24. ---------------------------------
  25. This example defines an Oracle data store, where the connection parameter are interpolated from properties::
  26. <sourceDataStores>
  27. <DataStore>
  28. <id>datastore</id>
  29. <parameters>
  30. <Parameter>
  31. <name>dbtype</name>
  32. <value>Oracle</value>
  33. </Parameter>
  34. <Parameter>
  35. <name>host</name>
  36. <value>${example.host}</value>
  37. </Parameter>
  38. <Parameter>
  39. <name>port</name>
  40. <value>1521</value>
  41. </Parameter>
  42. <Parameter>
  43. <name>database</name>
  44. <value>${example.database}</value>
  45. </Parameter>
  46. <Parameter>
  47. <name>user</name>
  48. <value>${example.user}</value>
  49. </Parameter>
  50. <Parameter>
  51. <name>passwd</name>
  52. <value>${example.passwd}</value>
  53. </Parameter>
  54. </parameters>
  55. </DataStore>
  56. </sourceDataStores>
  57. Example property file
  58. ---------------------
  59. This sample property file gives the property values that are interpolated into the mapping file fragment above. These properties can be installed in ``WEB-INF/classes/app-schema.properties`` in your GeoServer installation::
  60. example.host = database.example.com
  61. example.database = example
  62. example.user = dbuser
  63. example.passwd = s3cr3t