User's Manual

Chapter 11. Services Tutorials 149
public String getTag() {
return "Body Text";
}
public ContentType getType() {
return ContentType.RAW;
}
public byte[] getBytes() {
String body = m_note.getBody();
// Wrap the body HTML in a header and footer
return ("
html> head> title>" +
m_note.getTitle() +
"
/title> /head> body>" +
body +
" /body> /html>").getBytes();
}
}
...
Example 11-13. Raw content provider
Finally to the getContent method in the MetadataProvider interface is used to wire in the sup-
ported ContentProvider implementations. This method returns an array of ContentProvider
objects for each type, for example, allowing an object which ’0..n’ file attachments to return each file
as raw content.
...
public ContentProvider[] getContent(DomainObject dobj,
ContentType type) {
Note note = (Note)dobj;
if (type == ContentType.TEXT) {
return new ContentProvider[] {
new TextContentProvider(note)
};
} else if (type == ContentType.RAW) {
return new ContentProvider[] {
new HTMLContentProvider(note)
};
} else {
return null;
}
}
Example 11-14. Wiring up the content providers
11.6.1.4. Metadata provider registration
The search service maintains a registry of which metadata provider adapters to use for each object
type. To activate searching of the Note domain object, its adapter must be registered. The regis-
tration process is typically done upon startup from the init(DomainInitEvent e) method of
com.arsdigita.runtime.Initializer. When determining which adapter to use for extracting
metadata, the search service will travel up the object type inheritance tree until it finds a registered
adapter. Thus if an application has a number of object types all inheriting from a common parent, it
may be sufficient to register the metadata provider against the parent type.