The InterMine webapp, and to a limited extent web services, supports the use of labels for classes and fields. Unlabelled classes and fields are formatted for enhanced legibility.
The current system for determining a label is as follows:
- Split from its camel case parts as specified in Apache Commons StringUtils
- Each part is given an initial upper-case
- The parts are then joined by spaces
Handling paths is similar, except that the dots (”.”) between class and field names are replaced by right angle-brackets (“>”).
|Organism.shortName||Organism > Short Name|
Well named fields and classes thus do not need explicit labelling.
Labels can be configured however in two ways, in order of precedence: #. Classes and fields can be configured individually. This configuration respects inheritance, and subclasses automatically inherit the field labels of their parents. #. Translation tables can be set up for classes and fields. These are for cases where ALL classes/fields with a certain name should be relabelled. Examples are url -> URL, which would otherwise be rendered as ‘’Url’‘. This is especially useful for acroynms.
To apply individual configuration, the file webconfig-model.xml needs to be edited, and a label attribute added to items you want to configure. eg:
<class className="org.intermine.model.bio.Allele" label="SOME CLASS LABEL"> <fields> <fieldconfig fieldExpr="primaryIdentifier" label="SOME FIELD LABEL"/> <fieldconfig fieldExpr="symbol"/> <fieldconfig fieldExpr="alleleClass"/> <fieldconfig fieldExpr="organism.name" label="Organism"/> </fields> </class>
This is most helpful in the case of compound field-expressions (“organism.name”), which can this be configured to display as just a single expression.
For this, the mine needs to be made aware of properties files that hold the appropriate translations. Biological mines automatically get three of these files:
Additional files can be specified. Add the the following properties to your web.properties:
All resources should be names relative to the WEB-INF directory where they will end up.
You can have as many additional files as you wish, but:
A new tag library is available to help with labelling. Add the following to the top of any jsp you write that you want to use labels in:
<%@ taglib uri="/WEB-INF/functions.tld" prefix="imf" %>
This library provides five functions, which expose static methods from the org.intermine.web.logic.WebUtil class:
The values INTERMINE_API and WEBCONFIG are automatically available within jsps at all times.
While it is possible to call the formatting methods of WebUtil directly from Java controllers, it is not advisable, from design principles, to do so. Labels are an aspect of presentation (the view) and thus not the responsibility of Java classes (the controllers). The only justifiable place to call presentation methods from is in action classes that directly return data to the user, eg. in webservices and ajax calls.
Pages in the InterMine webapp have a variable in the global scope named $MODEL_TRANSLATION_TABLE. This contains information on how all classes and their fields should be displayed.
To access its information, for classes:
var className = ??; var displayName = $MODEL_TRANSLATION_TABLE[className].displayName;
And for fields of this class:
var fieldName = ??; var fieldDisplayName = $MODEL_TRANSLATION_TABLE[className].fields[fieldName]