Search in sources :

Example 31 with ApplicationKey

use of com.enonic.xp.app.ApplicationKey in project xp by enonic.

the class SiteServiceImplTest method get_descriptor_for_unknown_application.

@Test
public void get_descriptor_for_unknown_application() {
    final ApplicationKey applicationKey = ApplicationKey.from("unknown");
    final SiteDescriptor siteDescriptor = this.service.getDescriptor(applicationKey);
    assertEquals(null, siteDescriptor);
}
Also used : SiteDescriptor(com.enonic.xp.site.SiteDescriptor) ApplicationKey(com.enonic.xp.app.ApplicationKey) Test(org.junit.jupiter.api.Test)

Example 32 with ApplicationKey

use of com.enonic.xp.app.ApplicationKey in project xp by enonic.

the class StyleDescriptorServiceImplTest method getByApplicationInvalidStyles.

@Test
public void getByApplicationInvalidStyles() {
    addApplication("myapp3", "/apps/myapp3");
    final ApplicationKey appKey = ApplicationKey.from("myapp3");
    final StyleDescriptor descriptor = this.service.getByApplication(appKey);
    assertNull(descriptor);
}
Also used : ApplicationKey(com.enonic.xp.app.ApplicationKey) StyleDescriptor(com.enonic.xp.style.StyleDescriptor) Test(org.junit.jupiter.api.Test)

Example 33 with ApplicationKey

use of com.enonic.xp.app.ApplicationKey in project xp by enonic.

the class StyleDescriptorServiceImplTest method getByApplication.

@Test
public void getByApplication() {
    final ApplicationKey appKey = ApplicationKey.from("myapp1");
    final StyleDescriptor descriptor = this.service.getByApplication(appKey);
    assertNotNull(descriptor);
    assertEquals(descriptor.getApplicationKey(), appKey);
    assertTrue(Instant.now().isAfter(descriptor.getModifiedTime()));
}
Also used : ApplicationKey(com.enonic.xp.app.ApplicationKey) StyleDescriptor(com.enonic.xp.style.StyleDescriptor) Test(org.junit.jupiter.api.Test)

Example 34 with ApplicationKey

use of com.enonic.xp.app.ApplicationKey in project xp by enonic.

the class BaseContentHandler method createSitePropertySet.

private PropertySet createSitePropertySet(final Map<String, Object> siteConfig, final ContentTypeName contentTypeName) {
    if (siteConfig == null) {
        return null;
    }
    final ApplicationKey applicationKey = ApplicationKey.from(siteConfig.get("applicationKey").toString());
    final Map<String, ?> appConfigData = (Map<String, ?>) siteConfig.get("config");
    if (appConfigData == null) {
        return null;
    }
    final PropertySet propertySet = new PropertySet();
    propertySet.addString("applicationKey", applicationKey.toString());
    propertySet.addSet("config", this.translateToPropertyTree(appConfigData, applicationKey, contentTypeName).getRoot());
    return propertySet;
}
Also used : ApplicationKey(com.enonic.xp.app.ApplicationKey) PropertySet(com.enonic.xp.data.PropertySet) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 35 with ApplicationKey

use of com.enonic.xp.app.ApplicationKey in project xp by enonic.

the class MacroInstruction method evaluate.

@Override
public PortalResponse evaluate(final PortalRequest portalRequest, final String instruction) {
    if (!Instruction.isInstruction(instruction, "MACRO")) {
        return null;
    }
    // parse instruction
    final Instruction macroInstruction;
    try {
        macroInstruction = new InstructionParser().parse(instruction);
    } catch (RenderException e) {
        return null;
    }
    final String macroName = macroInstruction.attribute(MACRO_NAME);
    if (macroName == null) {
        return null;
    }
    // resolve macro processor
    final Site site = portalRequest.getSite();
    if (site == null) {
        throw new RenderException("Macro controller script could not be resolved, context site could not be found.");
    }
    final MacroDescriptor macroDescriptor = resolveMacroDescriptor(site.getSiteConfigs(), macroName);
    if (macroDescriptor == null) {
        final String editModeMacro = toMacroInstruction(macroInstruction);
        return PortalResponse.create().body(editModeMacro).build();
    }
    final MacroProcessor macroProcessor = resolveMacroProcessor(macroDescriptor);
    if (macroProcessor == null) {
        throw new RenderException("Macro controller not found: " + macroName);
    }
    // execute macro
    final MacroContext context = createContext(macroInstruction, macroDescriptor, portalRequest);
    final ApplicationKey previousAppKey = portalRequest.getApplicationKey();
    try {
        portalRequest.setApplicationKey(macroDescriptor.getKey().getApplicationKey());
        return macroProcessor.process(context);
    } finally {
        portalRequest.setApplicationKey(previousAppKey);
    }
}
Also used : Site(com.enonic.xp.site.Site) ApplicationKey(com.enonic.xp.app.ApplicationKey) RenderException(com.enonic.xp.portal.impl.rendering.RenderException) MacroDescriptor(com.enonic.xp.macro.MacroDescriptor) MacroProcessor(com.enonic.xp.portal.macro.MacroProcessor) MacroContext(com.enonic.xp.portal.macro.MacroContext) PostProcessInstruction(com.enonic.xp.portal.postprocess.PostProcessInstruction)

Aggregations

ApplicationKey (com.enonic.xp.app.ApplicationKey)78 Test (org.junit.jupiter.api.Test)40 Application (com.enonic.xp.app.Application)16 SiteDescriptor (com.enonic.xp.site.SiteDescriptor)12 Bundle (org.osgi.framework.Bundle)10 ResourceKey (com.enonic.xp.resource.ResourceKey)6 PropertyTree (com.enonic.xp.data.PropertyTree)5 ExtraData (com.enonic.xp.content.ExtraData)4 Site (com.enonic.xp.site.Site)4 Node (com.enonic.xp.node.Node)3 DescriptorKey (com.enonic.xp.page.DescriptorKey)3 PortalRequest (com.enonic.xp.portal.PortalRequest)3 PortalResponse (com.enonic.xp.portal.PortalResponse)3 XDataName (com.enonic.xp.schema.xdata.XDataName)3 ByteSource (com.google.common.io.ByteSource)3 ApplicationInvalidator (com.enonic.xp.app.ApplicationInvalidator)2 ExtraDatas (com.enonic.xp.content.ExtraDatas)2 PropertySet (com.enonic.xp.data.PropertySet)2 ControllerScript (com.enonic.xp.portal.controller.ControllerScript)2 RenderException (com.enonic.xp.portal.impl.rendering.RenderException)2