Adding Settings

GeoNetwork TV developers tips

rant

When you're new to GeoNetwork development, you may find yourself spending disappropriate amounts of time doing seemingly simple tasks. This is likely caused much by the way GeoNetwork is made; from its HTML style (probably the greatest density of <table> for layout you've ever seen), to the little detail that you must be an experienced XSLT programmer to change anything in the GUI, to the myriad Javascript functions that, while littering all pages, often do not seem to have much point.

what are settings?

Ranting done, let's get on with it. This page shows you which files you need to modify in order to add some new Settings to GeoNetwork. Settings are generally used to enable admin users to manage various aspects of the system through the GeoNetwork GUI. They're stored in a database table, appropriately named "settings", that has a hierarchical structure through a foreign key relation between a setting and its parent setting.

adding settings

The files you'll need to modify are listed here. Don't worry about the order in which to make your changes, you'll need to do all of this to get it to work. When testing, keep in mind that GeoNetwork's Saxon by default does not re-compile XSLTs; that GeoNetwork's Jetty may lock i18n property files so you can't edit them while it's running; and that Firefox sometimes needs some extra persuasion to actually reload Javascript files (try clearing its cache if Ctrl+F5 doesn't seem to do the trick).

xslt changes

[geonetwork-root]/web/geonetwork/xsl/config/config.xsl
XML to HTML transformation which produces the page in the GUI where admin users can edit the values of settings.
[geonetwork-root]/web/geonetwork/xsl/xml/config.xsl
XML to XML transformation used in the "xml.config.get" service.
[geonetwork-root]/web/geonetwork/xsl/xml/env.xsl
XML to XML transformation used in the "env" service.

In case you're wondering why those latter two transformations even exist (after all, the desired result format could have been put out in one go already), well this kind of throwing in a few extra transformations when no-one's looking is among GeoNetwork's fortes.

javascript changes

[geonetwork-root]/web/geonetwork/scripts/config/model.js
JS functions to gather data from the page and send it to the server (Ajax, of course, why not?) and retrieve data from the server and set it to elements on the page.
[geonetwork-root]/web/geonetwork/scripts/config/view.js
Together with the JS file above, is intended to provide some in-page "MVC framework" to manage the hefty task of sending/receiving a form.

i18n changes

You'll want to localize the title of the new settings in the admin settings page, along with the tooltip description that appears when one hovers over your settings. Both are in the i18n file "config.xml" and you'll need to do it for each supported language.

  • [geonetwork-root]/web/geonetwork/loc/ar/xml/config.xml
  • [geonetwork-root]/web/geonetwork/loc/cn/xml/config.xml
  • [geonetwork-root]/web/geonetwork/loc/de/xml/config.xml
  • [geonetwork-root]/web/geonetwork/loc/en/xml/config.xml
  • [geonetwork-root]/web/geonetwork/loc/es/xml/config.xml
  • [geonetwork-root]/web/geonetwork/loc/fr/xml/config.xml
  • [geonetwork-root]/web/geonetwork/loc/nl/xml/config.xml
  • [geonetwork-root]/web/geonetwork/loc/ru/xml/config.xml

java changes

[geonetwork-root]/src/org/fao/geonet/services/config/Set.java
Service to set settings, includes a domain model class for settings that niftily maps the request values to the DB hierarchy (that is to say, it prepends "system/" to each setting in the request).

gast changes

Settings must be present in the DB in order to save their values; or at the very least, all ancestor settings must be there, as they're not inserted on the fly. Therefore, add your new settings to the GAST database setup file. Existing DBs will of course be broken until one manually adds the new settings to them, as it is not de rigueur amongst GN developers to provide SQL scripts to fix that.

  • [geonetwork-root]/gast/setup/db/Settings.ddf

custom changes

The changes above allowed you to create new settings for GeoNetwork, and made their value manageable through the system config page. Now of course still nothing *happens* with your new settings; so now you'll need to implement your functionality that actually uses the settings. This may be anywhere, of course, depending on what you intend to use your settings for. Good luck!