The Implementation Class
The following listing shows the content of
example/CustomMetadataInjector.java
, which does
the actual injection. It is a very simple example but could easily
be extended to inject more fields, or even automatically look up the
fields in content items, and inject data into fields with names that
match metadata field names.
Note that the class extends
AbstractMetadataBase
. This saves some work
implementing the provider-specific details.
package example; import neo.xredsys.api.ArticleTransaction; import neo.xredsys.content.type.Field; class CustomMetadataInjector extends AbstractMetadataBase implements ContentMetadataInjector { static final String CAPTION_FIELD_NAME = "CAPTION"; CustomMetadataInjector(final DefaultMetadataInjectorSpi pProvider) { super(pProvider); } public void inject(ArticleTransaction pContent, Map<String, List<Object>> pMetadata) { Field defaultMetadataField = pContent.getArticleType().getField(CAPTION_FIELD_NAME); List<Object> captions = pMetadata.get("Caption/Abstract"); // Standard IPTC field if (defaultMetadataField != null && captions != null) { pContent.setFieldValue(METADATA_FIELD_NAME, toNLSV(captions)); } } private static String toNLSV(final List<Object> pValues) { StringBuilder buffer = new StringBuilder(); for (Object value : pValues) { if (buffer.length() > 0) { buffer.append("\n "); } buffer.append(value); } } return buffer.toString(); }