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);
}
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);
}
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()));
}
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;
}
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);
}
}
Aggregations