dxa-web-application-java icon indicating copy to clipboard operation
dxa-web-application-java copied to clipboard

Static content other than FAVICON cannot be entered at ROOT level

Open Jasmeet0108 opened this issue 8 years ago • 4 comments

As per part of customer requirement. It was required to add some PNG, JSON and XML files at root path same as where favicon is created. This was not possible in current dxa code implementation even if we updated html-design to iclude images and other stuff at root level.

To achieve this we need to change in LocalizationImpl.java under dxa-common-impl Method isStaticContent --> add p.contains(".png") || p.contains(".svg") || p.contains(".json") || p.contains(".xml"), or any other format that you need to include

@Override
public boolean isStaticContent(String url) {
    if (!url.startsWith(path)) {
        return false;
    }
    if (url.startsWith(mediaRoot)) {
        return true;
    }
    final String p = path.equals("/") ? url : url.substring(path.length());
    return p.equals(FAVICON_PATH) || SYSTEM_ASSETS_PATTERN.matcher(p).matches() || p.contains(".png") || p.contains(".svg") || p.contains(".json") || p.contains(".xml")
}

This will allow us to configure different favicon based on device and OS.

Jasmeet0108 avatar Apr 15 '16 11:04 Jasmeet0108

This is indeed a point to improve. Your solutions works but this is not an ideal option without any doubts. Although, since we can't really predict whether we currently have a page URL or a static resource with a random name, this makes it a bit difficult to solve this issue straight.

Anyways, I see the acceptable compromise: make static resources paths configurable externally with default preset. We even have a ready mechanism for this.

azarakovskiy avatar May 02 '16 09:05 azarakovskiy

It's also possible to place your favicon in the assets folder in the webapplication like so;

public class CustomSpringConfiguration extends SpringConfiguration {
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {

        registry.addResourceHandler("/assets/**").addResourceLocations("/assets/");
        registry.setOrder(-1);

        super.addResourceHandlers(registry);
    }
}

jarnohenneman avatar Jun 15 '16 11:06 jarnohenneman

TSI-1940 (internal issue ID for tracking purposes)

rpannekoek avatar Sep 12 '16 14:09 rpannekoek

Hi. Did you add any feature to specify the assets path externally? Like in a properties file. So we don't need to extend LocalizationImpl

jajimene avatar Feb 07 '18 17:02 jajimene