Page 1 of 1

using blStaticAssetService to fetch url.prefix in service

Posted: Wed Sep 19, 2012 1:37 pm
by srini
Hi,

I am trying to fetch staticAssetEnvironmentUrlPrefix value in my service layer like below but the value is coming as null. Is there something I need to do besides the below code. Please advise.

@Resource(name="blStaticAssetService")
protected StaticAssetService staticAssetService;

cmsUrl = staticAssetService.getStaticAssetEnvironmentUrlPrefix();

Thanks,
Srini.

Re: using blStaticAssetService to fetch url.prefix in service

Posted: Wed Sep 19, 2012 4:12 pm
by phillipuniverse
Do you have the asset.server.url.prefix property set in a properties file?

Re: using blStaticAssetService to fetch url.prefix in service

Posted: Wed Sep 19, 2012 4:20 pm
by srini
Yes Phillip. I am able to get the property value using cms:url from jsp but not in the service.

Thanks,
Srini.

Re: using blStaticAssetService to fetch url.prefix in service

Posted: Thu Sep 20, 2012 9:34 am
by phillipuniverse
From StaticAssetServiceImpl:

Code: Select all


    
@Override
    
public void setStaticAssetUrlPrefix(String staticAssetUrlPrefix) {
        
this.staticAssetUrlPrefix staticAssetUrlPrefix;
    }

    @
Override
    
public String getStaticAssetEnvironmentUrlPrefix() {
        return 
fixEnvironmentUrlPrefix(staticAssetEnvironmentUrlPrefix);
    }
    ...
    ...
       
/**
     * Trims whitespace.   If the value is the same as the internal url prefix, then return
     * null.
     *
     * @param urlPrefix
     * @return
     */
    
private String fixEnvironmentUrlPrefix(String urlPrefix) {
        if (
urlPrefix != null) {
            
urlPrefix urlPrefix.trim();
            if (
"".equals(urlPrefix)) {
                
// The value was not set.
                
urlPrefix null;
            } else if (
urlPrefix.equals(staticAssetUrlPrefix)) {
                
// The value is the same as the default, so no processing needed.
                
urlPrefix null;
            }
        }

        if (
urlPrefix != null && !urlPrefix.endsWith("/")) {
            
urlPrefix urlPrefix "/";
        }
        return 
urlPrefix;
    }
 


That fixEnvironmentUrlPrefix method will return null if it is the same as getStaticAssetUrlPrefix(). Is this the case?