Search in sources :

Example 1 with MacroKey

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;
}
Also used : MacroKey(com.enonic.xp.macro.MacroKey) MacroDescriptor(com.enonic.xp.macro.MacroDescriptor) Objects(java.util.Objects)

Example 2 with MacroKey

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());
}
Also used : MacroKey(com.enonic.xp.macro.MacroKey) MacroDescriptor(com.enonic.xp.macro.MacroDescriptor) Test(org.junit.jupiter.api.Test)

Example 3 with MacroKey

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));
}
Also used : MacroKey(com.enonic.xp.macro.MacroKey) MacroDescriptor(com.enonic.xp.macro.MacroDescriptor) Test(org.junit.jupiter.api.Test)

Example 4 with 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());
}
Also used : MacroKey(com.enonic.xp.macro.MacroKey) MacroDescriptor(com.enonic.xp.macro.MacroDescriptor) Test(org.junit.jupiter.api.Test)

Example 5 with MacroKey

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;
}
Also used : MacroKey(com.enonic.xp.macro.MacroKey) MacroDescriptor(com.enonic.xp.macro.MacroDescriptor)

Aggregations

MacroKey (com.enonic.xp.macro.MacroKey)14 MacroDescriptor (com.enonic.xp.macro.MacroDescriptor)12 Test (org.junit.jupiter.api.Test)9 Form (com.enonic.xp.form.Form)7 RenderException (com.enonic.xp.portal.impl.rendering.RenderException)5 ApplicationKey (com.enonic.xp.app.ApplicationKey)4 ContentId (com.enonic.xp.content.ContentId)4 ContentPath (com.enonic.xp.content.ContentPath)4 PropertyTree (com.enonic.xp.data.PropertyTree)4 Input (com.enonic.xp.form.Input)4 InputTypeName (com.enonic.xp.inputtype.InputTypeName)4 MacroDescriptorService (com.enonic.xp.macro.MacroDescriptorService)4 MacroDescriptors (com.enonic.xp.macro.MacroDescriptors)4 PortalRequest (com.enonic.xp.portal.PortalRequest)4 PortalResponse (com.enonic.xp.portal.PortalResponse)4 MacroProcessor (com.enonic.xp.portal.macro.MacroProcessor)4 MacroProcessorFactory (com.enonic.xp.portal.macro.MacroProcessorFactory)4 ContentTypeName (com.enonic.xp.schema.content.ContentTypeName)4 PrincipalKey (com.enonic.xp.security.PrincipalKey)4 Site (com.enonic.xp.site.Site)4