@Override public Resource getResource(final ResourceKey resourceKey) { URL resourceUrl = null; final Application application = getActiveApplication(resourceKey.getApplicationKey()); if (application != null) { String resourcePath = resourceKey.getPath(); resourceUrl = application.getBundle().getResource(resourcePath); } return new UrlResource(resourceKey, resourceUrl); }
private ControllerMappingDescriptor toMappingDescriptor(final DomElement mappingElement) { final ControllerMappingDescriptor.Builder builder = ControllerMappingDescriptor.create(); final String controllerPath = mappingElement.getAttribute(MAPPING_DESCRIPTOR_CONTROLLER_ATTRIBUTE); builder.controller(ResourceKey.from(this.currentApplication, controllerPath)); final String orderValue = mappingElement.getAttribute(MAPPING_DESCRIPTOR_ORDER_ATTRIBUTE); if (isNotEmpty(orderValue)) { builder.order(Integer.parseInt(orderValue)); } final DomElement matchElement = mappingElement.getChild(MAPPING_DESCRIPTOR_MATCH_TAG_NAME); if (matchElement != null) { final String match = matchElement.getValue(); if (isNotEmpty(match)) { builder.contentConstraint(match); } } final DomElement patternElement = mappingElement.getChild(MAPPING_DESCRIPTOR_PATTERN_TAG_NAME); if (patternElement != null) { final String pattern = patternElement.getValue(); if (isNotEmpty(pattern)) { final boolean invert = "true" .equals(patternElement.getAttribute(MAPPING_DESCRIPTOR_INVERT_ATTRIBUTE, "false")); builder.pattern(pattern); builder.invertPattern(invert); } } return builder.build(); }
@Override public ResourceKeys findFolders(final ApplicationKey applicationKey, final String path) { ResourceKeys resourceKeys = null; final Application application = getActiveApplication(applicationKey); if (application != null) { Bundle bundle = application.getBundle(); final Enumeration<String> entryPaths = bundle.getEntryPaths(path); if (entryPaths != null) { final List<ResourceKey> resourceKeyList = Collections.list(entryPaths) .stream() .filter(entryPath -> entryPath.endsWith("/")) .map(entryPath -> ResourceKey.from(applicationKey, entryPath)) .collect(Collectors.toList()); resourceKeys = ResourceKeys.from(resourceKeyList); } } if (resourceKeys == null) { resourceKeys = ResourceKeys.empty(); } return resourceKeys; }
@Override public ResourceKeys findResourceKeys( final ApplicationKey applicationKey, final String path, final String filePattern, boolean recurse) { ResourceKeys resourceKeys = null; final Application application = getActiveApplication(applicationKey); if (application != null) { Bundle bundle = application.getBundle(); final Enumeration<URL> entries = bundle.findEntries(path, filePattern, recurse); if (entries != null) { final List<ResourceKey> resourceKeyList = Collections.list(entries) .stream() .map(resourceUrl -> ResourceKey.from(applicationKey, resourceUrl.getPath())) .collect(Collectors.toList()); resourceKeys = ResourceKeys.from(resourceKeyList); } } if (resourceKeys == null) { resourceKeys = ResourceKeys.empty(); } return resourceKeys; }
@Override public ScriptExports execute(final ResourceKey script) { final ScriptExecutor executor = this.executorManager.getExecutor(script.getApplicationKey()); final Object exports = executor.executeMain(script); final ScriptValue value = executor.newScriptValue(exports); return new ScriptExportsImpl(script, value, exports); }
private Properties loadBundle(final ApplicationKey applicationKey, final String bundleExtension) { Properties properties = new Properties(); final ResourceKey resourceKey = ResourceKey.from(applicationKey, PHRASE_FOLDER + bundleExtension + ".properties"); final Resource resource = resourceService.getResource(resourceKey); if (resource.exists()) { try (InputStream in = resource.openStream()) { properties.load(in); } catch (final IOException e) { throw new LocalizationException( "Not able to load resource for: " + applicationKey.toString(), e); } } return properties; }
public static ResourceKey toResourceKey(final DescriptorKey key) { return ResourceKey.from( key.getApplicationKey(), "site/layouts/" + key.getName() + "/" + key.getName() + ".xml"); }
@Override public ResourceKey getComponentPath() { final DescriptorKey key = this.getKey(); return ResourceKey.from(key.getApplicationKey(), "site/layouts/" + key.getName()); }
@Override public boolean hasScript(final ResourceKey script) { final ResourceService service = this.executorManager.getExecutor(script.getApplicationKey()).getResourceService(); return service.getResource(script).exists(); }