Skip to content

Commit b008a8a

Browse files
Use NGResourceManager to load component template files
1 parent 648684c commit b008a8a

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

ng-appserver/src/main/java/ng/appserver/NGComponentDefinition.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import org.slf4j.Logger;
1212
import org.slf4j.LoggerFactory;
1313

14-
import ng.appserver.privates.NGResourceLoader;
1514
import ng.appserver.templating.NGDeclarationFormatException;
1615
import ng.appserver.templating.NGElementUtils;
1716
import ng.appserver.templating.NGHTMLFormatException;
@@ -201,7 +200,7 @@ private NGElement _loadTemplate() {
201200

202201
// If that fails, let's go for the single file html template
203202
if( htmlTemplateStringOptional.isEmpty() ) {
204-
final Optional<byte[]> htmlTemplate = NGResourceLoader.bytesForComponentResource( name() + ".html" );
203+
final Optional<byte[]> htmlTemplate = NGApplication.application().resourceManager().bytesForComponentResourceNamed( name() + ".html" );
205204

206205
if( htmlTemplate.isPresent() ) {
207206
htmlTemplateStringOptional = Optional.of( new String( htmlTemplate.get(), StandardCharsets.UTF_8 ) );
@@ -261,7 +260,7 @@ private static Optional<String> loadStringFromTemplateFolder( final String templ
261260

262261
final String htmlTemplateFilename = templateName + ".wo/" + templateName + "." + extension;
263262

264-
final Optional<byte[]> templateBytes = NGResourceLoader.bytesForComponentResource( htmlTemplateFilename );
263+
final Optional<byte[]> templateBytes = NGApplication.application().resourceManager().bytesForComponentResourceNamed( htmlTemplateFilename );
265264

266265
if( templateBytes.isEmpty() ) {
267266
return Optional.empty();

ng-appserver/src/main/java/ng/appserver/NGResourceManager.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@ public class NGResourceManager {
2626
/**
2727
* FIXME: Experimental caches. Resource caches should be located centrally.
2828
*/
29+
private final Map<String, Optional<byte[]>> _appResourceCache = new ConcurrentHashMap<>();
2930
private final Map<String, Optional<byte[]>> _webserverResourceCache = new ConcurrentHashMap<>();
31+
private final Map<String, Optional<byte[]>> _componentResourceCache = new ConcurrentHashMap<>();
3032
private final Map<String, Optional<byte[]>> _publicResourceCache = new ConcurrentHashMap<>();
31-
private final Map<String, Optional<byte[]>> _appResourceCache = new ConcurrentHashMap<>();
3233

3334
/**
3435
* Specifies if we want to use the resources cache.
@@ -47,6 +48,11 @@ public Optional<byte[]> bytesForWebserverResourceNamed( final String resourceNam
4748
return bytesForAnyResource( resourceName, _webserverResourceCache, NGResourceLoader::bytesForWebserverResource );
4849
}
4950

51+
public Optional<byte[]> bytesForComponentResourceNamed( final String resourceName ) {
52+
Objects.requireNonNull( resourceName );
53+
return bytesForAnyResource( resourceName, _componentResourceCache, NGResourceLoader::bytesForComponentResource );
54+
}
55+
5056
public Optional<byte[]> bytesForPublicResourceNamed( final String resourceName ) {
5157
Objects.requireNonNull( resourceName );
5258
return bytesForAnyResource( resourceName, _publicResourceCache, NGResourceLoader::bytesForPublicResource );

0 commit comments

Comments
 (0)