use of com.enonic.xp.resource.ResourceKey in project xp by enonic.
the class NamedTaskFactoryImplTest method setupPortalScriptService.
private PortalScriptService setupPortalScriptService() {
final BundleContext bundleContext = mock(BundleContext.class);
final Bundle bundle = mock(Bundle.class);
when(bundle.getBundleContext()).thenReturn(bundleContext);
final Application application = mock(Application.class);
when(application.getBundle()).thenReturn(bundle);
when(application.getClassLoader()).thenReturn(getClass().getClassLoader());
when(application.isStarted()).thenReturn(true);
when(application.getConfig()).thenReturn(ConfigBuilder.create().build());
final ApplicationService applicationService = mock(ApplicationService.class);
when(applicationService.getInstalledApplication(ApplicationKey.from("myapplication"))).thenReturn(application);
ResourceService resourceService = mock(ResourceService.class);
final Answer<Object> getResource = invocation -> {
final ResourceKey resourceKey = (ResourceKey) invocation.getArguments()[0];
final URL resourceUrl = NamedTaskFactoryImplTest.class.getResource("/" + resourceKey.getApplicationKey() + resourceKey.getPath());
return new UrlResource(resourceKey, resourceUrl);
};
when(resourceService.getResource(any())).thenAnswer(getResource);
final ScriptAsyncService scriptAsyncService = mock(ScriptAsyncService.class);
final ScriptRuntimeFactoryImpl runtimeFactory = new ScriptRuntimeFactoryImpl(applicationService, resourceService, scriptAsyncService);
final PortalScriptServiceImpl scriptService = new PortalScriptServiceImpl(runtimeFactory);
scriptService.initialize();
return scriptService;
}
use of com.enonic.xp.resource.ResourceKey in project xp by enonic.
the class ProcessingCache method doProcess.
private ProcessingEntry doProcess(final ResourceProcessor<?, ?> processor) {
final ResourceKey resourceKey = processor.toResourceKey();
final Resource resource = this.loader.apply(resourceKey);
final Object value = processor.process(resource);
if (value == null) {
return null;
}
return new ProcessingEntry(resourceKey, value, resource.getTimestamp());
}
use of com.enonic.xp.resource.ResourceKey in project xp by enonic.
the class LocaleServiceImplTest method loadResource.
private Resource loadResource(final InvocationOnMock invocation) {
final ResourceKey resourceKey = (ResourceKey) invocation.getArguments()[0];
final String path = resourceKey.getName();
final URL url = getClass().getResource(path.substring(path.lastIndexOf('/') + 1));
return new UrlResource(resourceKey, url);
}
use of com.enonic.xp.resource.ResourceKey in project xp by enonic.
the class LocaleServiceImpl method getAppLocales.
private Set<Locale> getAppLocales(final ApplicationKey applicationKey, final String... bundleNames) {
LOG.debug("Create app locales for {}", applicationKey);
final Set<Locale> locales = new LinkedHashSet<>();
for (final String bundleName : bundleNames) {
final String bundlePattern = "^" + Pattern.quote(bundleName.startsWith("/") ? bundleName : "/" + bundleName) + ".*\\.properties$";
final ResourceKeys resourceKeys = resourceService.findFiles(applicationKey, bundlePattern);
for (ResourceKey resourceKey : resourceKeys) {
final Locale locale = localeFromResource(resourceKey.getName());
locales.add(locale);
if (locale.equals(LOCALE_NO)) {
locales.add(LOCALE_NB);
locales.add(LOCALE_NN);
}
if (locale.getLanguage().equals(LOCALE_NB.getLanguage()) || locale.getLanguage().equals(LOCALE_NN.getLanguage())) {
locales.add(LOCALE_NO);
}
}
}
return locales;
}
use of com.enonic.xp.resource.ResourceKey in project xp by enonic.
the class IconLoader method loadIcon.
private static Icon loadIcon(final MacroKey macroKey, final String mimeType, final String ext, final ResourceService resourceService, final String path) {
final ResourceKey resourceKey = toResourceKey(macroKey, ext, path);
final Resource resource = resourceService.getResource(resourceKey);
return doLoadIcon(resource, mimeType);
}
Aggregations