Search in sources :

Example 46 with ResourceKey

use of com.enonic.xp.resource.ResourceKey in project xp by enonic.

the class SchemaLoader method loadIcon.

private Icon loadIcon(final N name, final String mimeType, final String ext) {
    final ResourceKey resourceKey = toResourceKey(name, ext);
    final Resource resource = this.resourceService.getResource(resourceKey);
    return SchemaHelper.loadIcon(resource, mimeType);
}
Also used : Resource(com.enonic.xp.resource.Resource) ResourceKey(com.enonic.xp.resource.ResourceKey)

Example 47 with ResourceKey

use of com.enonic.xp.resource.ResourceKey in project xp by enonic.

the class TaskDescriptorLoaderTest method testLoad.

@Test
public void testLoad() {
    final DescriptorKey descriptorKey = DescriptorKey.from("myapp1:task1");
    final ResourceKey resourceKey = this.loader.toResource(descriptorKey);
    assertEquals("myapp1:/tasks/task1/task1.xml", resourceKey.toString());
    final Resource resource = this.resourceService.getResource(resourceKey);
    final TaskDescriptor descriptor = this.loader.load(descriptorKey, resource);
    assertEquals("MyTask", descriptor.getDescription());
    FormItem formItem = descriptor.getConfig().getFormItem("param1");
    assertEquals(" something ", formItem.toInput().getDefaultValue().getRootValue());
}
Also used : TaskDescriptor(com.enonic.xp.task.TaskDescriptor) FormItem(com.enonic.xp.form.FormItem) Resource(com.enonic.xp.resource.Resource) DescriptorKey(com.enonic.xp.page.DescriptorKey) ResourceKey(com.enonic.xp.resource.ResourceKey) Test(org.junit.jupiter.api.Test)

Example 48 with ResourceKey

use of com.enonic.xp.resource.ResourceKey in project xp by enonic.

the class NamedTaskScriptFactoryImpl method doCreate.

private NamedTaskScript doCreate(final TaskDescriptor descriptor, final PropertyTree data) {
    final ResourceKey scriptResourceKey = ResourceKey.from(descriptor.getApplicationKey(), TASKS_PATH_PREFIX + descriptor.getName() + "/" + descriptor.getName() + ".js");
    final ScriptExports exports;
    try {
        exports = this.scriptService.execute(scriptResourceKey);
    } catch (ResourceNotFoundException e) {
        throw new TaskNotFoundException(descriptor.getKey(), "Missing task script");
    }
    final boolean exists = exports.hasMethod(NamedTaskScript.SCRIPT_METHOD_NAME);
    if (!exists) {
        throw new TaskNotFoundException(descriptor.getKey(), "Missing exported function '" + NamedTaskScript.SCRIPT_METHOD_NAME + "' in task script");
    }
    return new NamedTaskScript(exports, descriptor, data);
}
Also used : TaskNotFoundException(com.enonic.xp.task.TaskNotFoundException) ScriptExports(com.enonic.xp.script.ScriptExports) ResourceNotFoundException(com.enonic.xp.resource.ResourceNotFoundException) ResourceKey(com.enonic.xp.resource.ResourceKey)

Example 49 with ResourceKey

use of com.enonic.xp.resource.ResourceKey in project xp by enonic.

the class WidgetDescriptorLoaderTest method testLoadMax.

@Test
public void testLoadMax() {
    final DescriptorKey descriptorKey = DescriptorKey.from("myapp1:widget1");
    final ResourceKey resourceKey = this.loader.toResource(descriptorKey);
    assertEquals("myapp1:/admin/widgets/widget1/widget1.xml", resourceKey.toString());
    final Resource resource = this.resourceService.getResource(resourceKey);
    final WidgetDescriptor descriptor = this.loader.load(descriptorKey, resource);
    assertEquals("MyWidget", descriptor.getDisplayName());
    assertEquals(1, descriptor.getInterfaces().size());
    assertTrue(descriptor.getInterfaces().contains("com.enonic.xp.my-interface"));
    assertEquals(1, descriptor.getAllowedPrincipals().getSize());
    assertTrue(descriptor.getAllowedPrincipals().contains(PrincipalKey.from("role:system.user.admin")));
}
Also used : Resource(com.enonic.xp.resource.Resource) DescriptorKey(com.enonic.xp.page.DescriptorKey) WidgetDescriptor(com.enonic.xp.admin.widget.WidgetDescriptor) ResourceKey(com.enonic.xp.resource.ResourceKey) Test(org.junit.jupiter.api.Test)

Example 50 with ResourceKey

use of com.enonic.xp.resource.ResourceKey in project xp by enonic.

the class StyleDescriptorTest method testToResourceKey.

@Test
public void testToResourceKey() {
    final ResourceKey resourceKey = StyleDescriptor.toResourceKey(ApplicationKey.from("myapp"));
    assertEquals("myapp:/site/styles.xml", resourceKey.toString());
}
Also used : ResourceKey(com.enonic.xp.resource.ResourceKey) Test(org.junit.jupiter.api.Test)

Aggregations

ResourceKey (com.enonic.xp.resource.ResourceKey)76 Test (org.junit.jupiter.api.Test)49 Resource (com.enonic.xp.resource.Resource)21 ApplicationKey (com.enonic.xp.app.ApplicationKey)12 ResourceService (com.enonic.xp.resource.ResourceService)12 ScriptExports (com.enonic.xp.script.ScriptExports)11 Application (com.enonic.xp.app.Application)9 UrlResource (com.enonic.xp.resource.UrlResource)9 URL (java.net.URL)9 BeforeEach (org.junit.jupiter.api.BeforeEach)9 PortalRequest (com.enonic.xp.portal.PortalRequest)8 HttpServletRequest (javax.servlet.http.HttpServletRequest)8 ApplicationService (com.enonic.xp.app.ApplicationService)7 AssetUrlParams (com.enonic.xp.portal.url.AssetUrlParams)7 ScriptAsyncService (com.enonic.xp.script.impl.async.ScriptAsyncService)7 ScriptRuntimeFactoryImpl (com.enonic.xp.script.impl.standard.ScriptRuntimeFactoryImpl)7 PortalResponse (com.enonic.xp.portal.PortalResponse)6 PortalScriptServiceImpl (com.enonic.xp.portal.impl.script.PortalScriptServiceImpl)6 Assertions.assertNotNull (org.junit.jupiter.api.Assertions.assertNotNull)6 PropertyTree (com.enonic.xp.data.PropertyTree)5