Mailing List webobjects-dev@wocommunity.org Message #530
From: Hugi Thordarson <hugi@karlmenn.is>
Subject: Re: [WO-DEV] Dynamic URL in CSS
Date: Wed, 1 Oct 2025 14:55:09 +0000
To: WebObjects & WOnder Development <webobjects-dev@wocommunity.org>
Hi Markus.

In the long term you might want to use templating for your resources. But if you need to get things up and running quickly, here's one method I sometimes use in situations like this:
If all resources are referenced in the way you show in your sample (URLs served from a known path relative to the site's root), you can copy the site's resources into a folder in your application's resources folder, then catch the "wrong URLs" in your application's dispatchRequest() and serve the resource yourself, something like shown in the code example below.
If it's a large amount of resources and/or you don't want them with your application's resources, you can also just keep them anywhere your computer can reach them and read them using Files.readAllBytes(). Heck, you could even just proxy the actual files from the remote server. But that's probably not so wise :).

@Override
public WOResponse dispatchRequest( WORequest request ) {
if( isDevelopmentModeSafe() ) {
final String uri = request.uri();

if( uri.startsWith( "/MyApp" ) ) {
// Just removing the slash here and assuming the resources are located in a folder in resources called "MyApp"
final String resourcePath = uri.substring( 1 );
final String contentType = resourceManager().contentTypeForResourceNamed( resourcePath );
byte[] resourceBytes = resourceManager().bytesForResourceNamed( resourcePath, "app", null );

final WOResponse response = new WOResponse();
response.setContent( resourceBytes );
response.setHeader( contentType, "content-type" );
return response;
}
}

return super.dispatchRequest( request );
}

Cheers,
- hugi


> On 1 Oct 2025, at 12:53, Markus Ruggiero (rucotec) <markus.ruggiero@rucotec.ch> wrote:
>
> I have a large customer application that has nicely structured CSS files. Unfortunately in one of them there are some absolute references to WebServerResources
>
> background-image: url(“/MyApp/images/logo.png");
>
> This fails when the file is in WebServerResources. Up to now my customer had all resources served statically from Apache. This works in production but is not portable and breaks in Eclipse on my dev machine.
>
> What would be the best way to convert such CSS URLs? I cannot just put a WOResourceURL in there or some such because the definition is in a separate .css file in WebServerResources, not in a WOComponent.
>
> How to best deal with such things?
>
> Thanks for any tip and help
> ---markus---
>
>
>

Subscribe (FEED) Subscribe (DIGEST) Subscribe (INDEX) Unsubscribe Mail to Listmaster