use of com.enonic.xp.resource.ResourceKey in project xp by enonic.
the class WidgetHandlerWorker method execute.
@Override
public PortalResponse execute() throws Exception {
if (this.request.getMode() != RenderMode.ADMIN) {
throw WebException.forbidden("Render mode must be ADMIN.");
}
// Retrieves the WidgetDescriptor
final WidgetDescriptor widgetDescriptor = widgetDescriptorService.getByKey(descriptorKey);
if (widgetDescriptor == null) {
throw WebException.notFound(String.format("Widget [%s] not found", descriptorKey));
}
// Checks if the access to WidgetDescriptor is allowed
final PrincipalKeys principals = ContextAccessor.current().getAuthInfo().getPrincipals();
if (!widgetDescriptor.isAccessAllowed(principals)) {
throw WebException.forbidden(String.format("You don't have permission to access [%s]", descriptorKey));
}
// Renders the widget
this.request.setApplicationKey(this.descriptorKey.getApplicationKey());
final ResourceKey scriptDir = ResourceKey.from(descriptorKey.getApplicationKey(), "admin/widgets/" + descriptorKey.getName());
final ControllerScript controllerScript = this.controllerScriptFactory.fromDir(scriptDir);
return controllerScript.execute(this.request);
}
use of com.enonic.xp.resource.ResourceKey in project xp by enonic.
the class WidgetDescriptorLoaderTest method testLoadMin.
@Test
public void testLoadMin() {
final DescriptorKey descriptorKey = DescriptorKey.from("myapp1:widget2");
final ResourceKey resourceKey = this.loader.toResource(descriptorKey);
final Resource resource = this.resourceService.getResource(resourceKey);
final WidgetDescriptor descriptor = this.loader.load(descriptorKey, resource);
assertEquals("MyWidget2", descriptor.getDisplayName());
assertEquals("MyWidget2 description", descriptor.getDescription());
assertEquals(1, descriptor.getInterfaces().size());
assertTrue(descriptor.getInterfaces().contains("com.enonic.xp.my-interface"));
assertNull(descriptor.getAllowedPrincipals());
}
use of com.enonic.xp.resource.ResourceKey in project xp by enonic.
the class ResourceKeyConverterTest method testSameType.
@Test
public void testSameType() {
final ResourceKey key = ResourceKey.from("myapplication:/some/path");
assertSame(key, Converters.convert(key, ResourceKey.class));
}
use of com.enonic.xp.resource.ResourceKey in project xp by enonic.
the class PartDescriptorLoader method loadIcon.
private Icon loadIcon(final DescriptorKey key, final String mimeType, final String ext) {
final ResourceKey resourceKey = PartDescriptor.toResourceKey(key, ext);
final Resource resource = this.resourceService.getResource(resourceKey);
if (!resource.exists()) {
return null;
}
final Instant modifiedTime = Instant.ofEpochMilli(resource.getTimestamp());
return Icon.from(resource.readBytes(), mimeType, modifiedTime);
}
use of com.enonic.xp.resource.ResourceKey in project xp by enonic.
the class LocaleServiceImpl method loadBundle.
private Properties loadBundle(final ApplicationKey applicationKey, final String bundleName) {
final ResourceKey resourceKey = ResourceKey.from(applicationKey, bundleName + ".properties");
final Resource resource = resourceService.getResource(resourceKey);
final Properties properties = new Properties();
if (resource.exists()) {
try (Reader in = resource.openReader()) {
properties.load(in);
} catch (final IOException e) {
throw new LocalizationException("Not able to load resource for: " + applicationKey.toString(), e);
}
}
return properties;
}
Aggregations