-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added basic implementation ofn NGResourceURL
- Loading branch information
1 parent
81bb3e1
commit 5b79a35
Showing
2 changed files
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
ng-appserver/src/main/java/ng/appserver/elements/NGResourceURL.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package ng.appserver.elements; | ||
|
||
import java.util.Map; | ||
import java.util.Optional; | ||
|
||
import ng.appserver.NGAssociation; | ||
import ng.appserver.NGContext; | ||
import ng.appserver.NGDynamicElement; | ||
import ng.appserver.NGElement; | ||
import ng.appserver.NGResourceRequestHandler; | ||
import ng.appserver.NGResponse; | ||
import ng.appserver.privates.NGHTMLUtilities; | ||
|
||
public class NGResourceURL extends NGDynamicElement { | ||
|
||
private final NGAssociation _namespaceAssociation; | ||
|
||
private final NGAssociation _filenameAssociation; | ||
|
||
public NGResourceURL( final String name, final Map<String, NGAssociation> associations, final NGElement template ) { | ||
super( null, null, null ); | ||
_namespaceAssociation = NGHTMLUtilities.namespaceAssociation( associations, true ); | ||
_filenameAssociation = associations.get( "filename" ); | ||
} | ||
|
||
@Override | ||
public void appendToResponse( NGResponse response, NGContext context ) { | ||
final String filename = (String)_filenameAssociation.valueInComponent( context.component() ); | ||
final String namespace = NGHTMLUtilities.namespaceInContext( context, _namespaceAssociation ); | ||
final Optional<String> url = NGResourceRequestHandler.urlForWebserverResourceNamed( namespace, filename ); | ||
|
||
// FIXME: We might want some more graceful error handling here in case of a non-existent resource // Hugi 2024-10-22 | ||
response.appendContentString( url.get() ); | ||
} | ||
} |