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