use of com.enonic.xp.schema.mixin.MixinName in project xp by enonic.
the class ApplicationRelativeResolverTest method toMixinName.
@Test
public void toMixinName() {
final ApplicationRelativeResolver resolver = new ApplicationRelativeResolver(ApplicationKey.from("aaa"));
MixinName mixinName = resolver.toMixinName("bbb");
assertEquals(mixinName.getLocalName(), "bbb");
mixinName = resolver.toMixinName("ccc:ddd");
assertEquals(mixinName.getLocalName(), "ddd");
}
use of com.enonic.xp.schema.mixin.MixinName in project xp by enonic.
the class MixinServiceImpl method transformFormItems.
private List<FormItem> transformFormItems(final Iterable<FormItem> iterable, final Set<MixinName> inlineMixinStack) {
final List<FormItem> formItems = new ArrayList<>();
for (final FormItem formItem : iterable) {
if (formItem instanceof InlineMixin) {
final InlineMixin inline = (InlineMixin) formItem;
final MixinName mixinName = inline.getMixinName();
final Mixin mixin = getByName(mixinName);
if (mixin != null) {
if (inlineMixinStack.contains(mixinName)) {
final String error = "Cycle detected in mixin [" + mixin.getName() + "]. It contains an inline mixin that references itself.";
LOG.error(error);
throw new IllegalArgumentException(error);
}
inlineMixinStack.add(mixinName);
final Form mixinForm = doInlineFormItems(mixin.getForm(), inlineMixinStack);
inlineMixinStack.remove(mixinName);
for (final FormItem mixinFormItem : mixinForm) {
formItems.add(mixinFormItem.copy());
}
} else {
throw new IllegalArgumentException("Inline mixin [" + mixinName + "] not found");
}
} else if (formItem instanceof FormItemSet) {
final FormItemSet.Builder formItemSetBuilder = FormItemSet.create((FormItemSet) formItem);
formItemSetBuilder.clearFormItems();
formItemSetBuilder.addFormItems(transformFormItems((FormItemSet) formItem, inlineMixinStack));
formItems.add(formItemSetBuilder.build());
} else if (formItem instanceof FieldSet) {
final FieldSet.Builder formItemSetBuilder = FieldSet.create((FieldSet) formItem);
formItemSetBuilder.clearFormItems();
formItemSetBuilder.addFormItems(transformFormItems((FieldSet) formItem, inlineMixinStack));
formItems.add(formItemSetBuilder.build());
} else if (formItem instanceof FormOptionSet) {
final FormOptionSet.Builder formOptionSetBuilder = FormOptionSet.create((FormOptionSet) formItem);
formOptionSetBuilder.clearOptions();
for (FormOptionSetOption option : (FormOptionSet) formItem) {
final FormOptionSetOption.Builder optionBuilder = FormOptionSetOption.create(option);
optionBuilder.clearFormItems();
optionBuilder.addFormItems(transformFormItems(option.getFormItems(), inlineMixinStack));
formOptionSetBuilder.addOptionSetOption(optionBuilder.build());
}
formItems.add(formOptionSetBuilder.build());
} else {
formItems.add(formItem.copy());
}
}
return formItems;
}
Aggregations