Skip to content

Commit

Permalink
Added basic implementation ofn NGResourceURL
Browse files Browse the repository at this point in the history
  • Loading branch information
hugithordarson committed Oct 22, 2024
1 parent 81bb3e1 commit 5b79a35
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
2 changes: 2 additions & 0 deletions ng-appserver/src/main/java/ng/appserver/NGElementUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import ng.appserver.elements.NGJavaScript;
import ng.appserver.elements.NGPopUpButton;
import ng.appserver.elements.NGRepetition;
import ng.appserver.elements.NGResourceURL;
import ng.appserver.elements.NGString;
import ng.appserver.elements.NGStylesheet;
import ng.appserver.elements.NGSubmitButton;
Expand Down Expand Up @@ -74,6 +75,7 @@ public class NGElementUtils {
addClass( NGJavaScript.class, "script" );
addClass( NGPopUpButton.class, "popUpButton" ); // CHECKME: We might want to consider just naming this "popup"
addClass( NGRepetition.class, "repetition" );
addClass( NGResourceURL.class, "resourceURL" );
addClass( NGSubmitButton.class, "submit" );
addClass( NGStylesheet.class, "stylesheet" );
addClass( NGSwitchComponent.class, "switch" );
Expand Down
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() );
}
}

0 comments on commit 5b79a35

Please sign in to comment.