RWS / dxa-web-application-java

SDL Digital Experience Accelerator Java Spring MVC web application
25 stars 37 forks source link

Static content other than FAVICON cannot be entered at ROOT level #38

Open Jasmeet0108 opened 8 years ago

Jasmeet0108 commented 8 years ago

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.

azarakovskiy commented 8 years ago

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.

jarnohenneman commented 8 years ago

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);
    }
}
rpannekoek commented 8 years ago

TSI-1940 (internal issue ID for tracking purposes)

jajimene commented 6 years ago

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