Search in sources :

Example 31 with ResourceKey

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

the class RequireFunction method call.

@Override
public Object call(final Object thiz, final Object... args) {
    if (args.length != 1) {
        throw new IllegalArgumentException("require(..) must have one parameter");
    }
    final String name = args[0].toString();
    final ResourceKey key = resolve(name);
    return this.executor.executeRequire(key);
}
Also used : ResourceKey(com.enonic.xp.resource.ResourceKey)

Example 32 with ResourceKey

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

the class ScriptRuntimeTest method testResolve.

@Test
public void testResolve() {
    final ResourceKey script = ResourceKey.from("myapplication:/resolve/resolve-test.js");
    final ScriptExports exports = runTestScript(script);
    assertNotNull(exports);
    assertSame(script, exports.getScript());
}
Also used : ScriptExports(com.enonic.xp.script.ScriptExports) ResourceKey(com.enonic.xp.resource.ResourceKey) Test(org.junit.jupiter.api.Test)

Example 33 with ResourceKey

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

the class RequireResolverTest method resolve_no_ext_js.

@Test
public void resolve_no_ext_js() throws Exception {
    touchFile("dummy/index.js");
    final ResourceKey key2 = resolve("/a/b/c.js", "/dummy");
    assertEquals("/dummy/index.js", key2.getPath());
}
Also used : ResourceKey(com.enonic.xp.resource.ResourceKey) Test(org.junit.jupiter.api.Test)

Example 34 with ResourceKey

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

the class RequireResolverTest method resolve_js.

@Test
public void resolve_js() throws Exception {
    final ResourceKey key = resolve("/a/b/c.js", "/dummy.js");
    assertEquals("/dummy.js", key.getPath());
    final ResourceKey key2 = resolve("/c.js", "./dummy.js");
    assertEquals("/dummy.js", key2.getPath());
    final ResourceKey key3 = resolve("/dir1/c.js", "../dummy.js");
    assertEquals("/dummy.js", key3.getPath());
    final ResourceKey key4 = resolve("/dir1/dir2/c.txt", "dummy.txt");
    assertEquals("/dir1/dir2/dummy.txt", key4.getPath());
}
Also used : ResourceKey(com.enonic.xp.resource.ResourceKey) Test(org.junit.jupiter.api.Test)

Example 35 with ResourceKey

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

the class AdminToolHandlerWorker method execute.

@Override
public PortalResponse execute() throws Exception {
    // Retrieves the AdminToolDescriptor
    final AdminToolDescriptor adminToolDescriptor = adminToolDescriptorService.getByKey(descriptorKey);
    if (adminToolDescriptor == null) {
        throw WebException.notFound(String.format("Admin application [%s] not found", descriptorKey));
    }
    // Checks if the access to AdminToolDescriptor is allowed
    final PrincipalKeys principals = ContextAccessor.current().getAuthInfo().getPrincipals();
    if (!adminToolDescriptor.isAccessAllowed(principals)) {
        throw WebException.forbidden(String.format("You don't have permission to access [%s]", descriptorKey));
    }
    // Renders the Admin application
    final ResourceKey scriptDir = ResourceKey.from(descriptorKey.getApplicationKey(), "admin/tools/" + descriptorKey.getName());
    final ControllerScript controllerScript = this.controllerScriptFactory.fromDir(scriptDir);
    return controllerScript.execute(this.request);
}
Also used : PrincipalKeys(com.enonic.xp.security.PrincipalKeys) ControllerScript(com.enonic.xp.portal.controller.ControllerScript) AdminToolDescriptor(com.enonic.xp.admin.tool.AdminToolDescriptor) ResourceKey(com.enonic.xp.resource.ResourceKey)

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