use of com.enonic.xp.macro.MacroKey in project xp by enonic.
the class MacroInstruction method resolveMacroDescriptor.
private MacroDescriptor resolveMacroDescriptor(final SiteConfigs siteConfigs, final String macroName) {
// Searches for the macro in the applications associated to the site
MacroDescriptor macroDescriptor = siteConfigs.stream().map(siteConfig -> MacroKey.from(siteConfig.getApplicationKey(), macroName)).map(macroDescriptorService::getByKey).filter(Objects::nonNull).findFirst().orElse(null);
if (macroDescriptor == null) {
macroDescriptor = resolveMacroDescriptorCaseInsensitive(siteConfigs, macroName);
}
// If there is no corresponding macro
if (macroDescriptor == null) {
// Searches in the builtin macros
final MacroKey macroKey = MacroKey.from(ApplicationKey.SYSTEM, macroName);
macroDescriptor = macroDescriptorService.getByKey(macroKey);
}
return macroDescriptor;
}
use of com.enonic.xp.macro.MacroKey in project xp by enonic.
the class MacroDescriptorServiceTest method testGetBySystemKey.
@Test
public void testGetBySystemKey() throws Exception {
final MacroKey macroKey = MacroKey.from(ApplicationKey.SYSTEM, "disable");
final MacroDescriptor descriptor = this.service.getByKey(macroKey);
assertNotNull(descriptor);
assertTrue(descriptor.getKey().equals(macroKey));
assertEquals("Disable macros", descriptor.getDisplayName());
assertEquals("Contents of this macro will not be formatted", descriptor.getDescription());
assertNotNull(descriptor.getForm());
}
use of com.enonic.xp.macro.MacroKey in project xp by enonic.
the class MacroDescriptorServiceTest method testGetByKey.
@Test
public void testGetByKey() throws Exception {
final MacroKey macroKey = MacroKey.from(ApplicationKey.from("myapp1"), "macro1");
final MacroDescriptor descriptor = this.service.getByKey(macroKey);
assertNotNull(descriptor);
assertTrue(descriptor.getKey().equals(macroKey));
}
use of com.enonic.xp.macro.MacroKey in project xp by enonic.
the class MacroDescriptorServiceTest method testIconAdded.
@Test
public void testIconAdded() throws Exception {
final MacroKey macroKey = MacroKey.from(ApplicationKey.SYSTEM, "disable");
final MacroDescriptor descriptor = this.service.getByKey(macroKey);
assertNotNull(descriptor);
assertTrue(descriptor.getKey().equals(macroKey));
assertNotNull(descriptor.getIcon());
}
use of com.enonic.xp.macro.MacroKey in project xp by enonic.
the class MacroDescriptorServiceImpl method getByKey.
@Override
public MacroDescriptor getByKey(final MacroKey key) {
MacroDescriptor descriptor;
if (isSystem(key.getApplicationKey())) {
descriptor = builtinMacrosDescriptors.getByKey(key);
} else {
final ResourceProcessor<MacroKey, MacroDescriptor> descriptorProcessor = newDescriptorProcessor(key);
descriptor = this.resourceService.processResource(descriptorProcessor);
if (descriptor == null) {
final ResourceProcessor<MacroKey, MacroDescriptor> controllerProcessor = newControllerProcessor(key);
descriptor = this.resourceService.processResource(controllerProcessor);
}
}
return descriptor;
}
Aggregations