String metatypeLocation = MetaTypeService.METATYPE_DOCUMENTS_LOCATION + "/metatype";
// check if all labels and descriptions are inlined
boolean allInlined = true;
for(final ComponentContainer cc : ccc.components) {
final MetatypeContainer mc = cc.getMetatypeContainer();
if ( mc.getName() == null ) {
if ( oldStyle ) {
mc.setName( "%" + cc.getComponentDescription().getName() + ".name");
} else {
mc.setName("Component " + cc.getComponentDescription().getName());
}
}
if ( mc.getName() != null && mc.getName().startsWith("%") ) {
allInlined = false;
}
if ( mc.getDescription() == null ) {
if ( oldStyle ) {
mc.setDescription("%" + cc.getComponentDescription().getName() + ".description");
} else {
mc.setDescription("Description for " + cc.getComponentDescription().getName());
}
}
if ( mc.getDescription() != null && mc.getDescription().startsWith("%") ) {
allInlined = false;
}
for(final MetatypeAttributeDefinition mad : mc.getProperties()) {
if ( mad.getName() == null ) {
if ( oldStyle ) {
mad.setName("%" + mad.getId() + ".name");
} else {
mad.setName("Property " + mad.getId());
}
}
if ( mad.getName() != null && mad.getName().startsWith("%") ) {
allInlined = false;
}
if ( mad.getDescription() == null ) {
if ( oldStyle ) {
mad.setDescription("%" + mad.getId() + ".description");
} else {
mad.setDescription("Description for " + mad.getId());
}
}
if ( mad.getDescription() != null && mad.getDescription().startsWith("%") ) {
allInlined = false;
}
}
}
if ( allInlined ) {
final Properties metatypeProps = new Properties();
// externalize all labels and descriptions
for(final ComponentContainer cc : ccc.components) {
final MetatypeContainer mc = cc.getMetatypeContainer();
final String baseKey = cc.getComponentDescription().getName().replace("$", ".");
if ( mc.getName() != null ) {
final String key = baseKey + ".name";
metatypeProps.put(key, mc.getName());
mc.setName("%" + key);
}
if ( mc.getDescription() != null ) {
final String key = baseKey + ".description";
metatypeProps.put(key, mc.getDescription());
mc.setDescription("%" + key);
}
for(final MetatypeAttributeDefinition mad : mc.getProperties()) {
if ( mad.getName() != null ) {
final String key = baseKey + "." + mad.getId() + ".name";
metatypeProps.put(key, mad.getName());
mad.setName("%" + key);
}