Search in sources :

Example 1 with NullURLHandler

use of org.broadleafcommerce.cms.url.domain.NullURLHandler in project BroadleafCommerce by BroadleafCommerce.

the class URLHandlerServiceImpl method findURLHandlerByURI.

/**
 * Checks the passed in URL to determine if there is a matching URLHandler.
 * Returns null if no handler was found.
 *
 * @param uri
 * @return
 */
@Override
public URLHandler findURLHandlerByURI(String uri) {
    // This allows clients or implementors to manipulate the URI, for example making it all lower case.
    // The default implementation simply does not manipulate the URI in any way, but simply returns
    // what is passed in.
    uri = manipulateUri(uri);
    URLHandler handler = null;
    Site site = null;
    if (BroadleafRequestContext.getBroadleafRequestContext() != null) {
        site = BroadleafRequestContext.getBroadleafRequestContext().getNonPersistentSite();
    }
    String key = buildURLHandlerCacheKey(site, uri);
    // See if this is in cache first, but only if we are in production
    if (BroadleafRequestContext.getBroadleafRequestContext().isProductionSandBox()) {
        handler = getUrlHandlerFromCache(key);
    }
    if (handler == null) {
        // Check for an exact match in the DB...
        handler = urlHandlerDao.findURLHandlerByURI(uri);
        if (handler == null) {
            // Check for a regex match
            handler = checkForMatches(uri);
        }
        if (handler == null) {
            // Use the NullURLHandler instance. This will be cached to indicate that
            // This URL does not have a match.
            handler = NULL_URL_HANDLER;
        } else if (!(URLHandlerDTO.class.isAssignableFrom(handler.getClass()))) {
            // Create a non-entity instance of the DTO to cache.
            handler = new URLHandlerDTO(handler.getNewURL(), handler.getUrlRedirectType());
        }
        if (BroadleafRequestContext.getBroadleafRequestContext().isProductionSandBox()) {
            getUrlHandlerCache().put(new Element(key, handler));
        }
    }
    if (handler instanceof NullURLHandler) {
        return null;
    }
    return handler;
}
Also used : NullURLHandler(org.broadleafcommerce.cms.url.domain.NullURLHandler) URLHandler(org.broadleafcommerce.cms.url.domain.URLHandler) Site(org.broadleafcommerce.common.site.domain.Site) URLHandlerDTO(org.broadleafcommerce.cms.url.domain.URLHandlerDTO) Element(net.sf.ehcache.Element) NullURLHandler(org.broadleafcommerce.cms.url.domain.NullURLHandler)

Aggregations

Element (net.sf.ehcache.Element)1 NullURLHandler (org.broadleafcommerce.cms.url.domain.NullURLHandler)1 URLHandler (org.broadleafcommerce.cms.url.domain.URLHandler)1 URLHandlerDTO (org.broadleafcommerce.cms.url.domain.URLHandlerDTO)1 Site (org.broadleafcommerce.common.site.domain.Site)1