The Metadata add-on has two basic structure elements: Metadata sets and Metadata fields. A set contains one ore more fields. The basic set and field handling is available via the "com.communardo.confluence.metadata.service.MetadataManager".
Just inject it into your classes with constructor injection or setter injection. The injection itself only works, if you have defined a correct component-import in your atlassian-plugin.xml (please see Quick Setup of Metadata API (v 3.0)).
This should give you the space metadata sets as well as the global metadata sets.
Or just load the metadata sets of a specific space:
//load the metadata sets of a space with the spacekey "demo"
List<MetadataSet> sets = metadataManager.loadMetadataSets("demo");
Iterate through metadata fields of a set
for (MetadataField metadataField : metadataset.getMetadataFields()) {
}
Read a metadata field value on a page or blog post
Each metadata field stores data objects, but only the metadata field type knows how to handle them. Field types are Checkbox; Textfield; Userfield and so on. So, first we need to load the data object. We use the "loadContentMetadataValue" method for that purpose.