Search in sources :

Example 21 with Site

use of org.broadleafcommerce.common.site.domain.Site 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)

Example 22 with Site

use of org.broadleafcommerce.common.site.domain.Site in project BroadleafCommerce by BroadleafCommerce.

the class StructuredContentServiceImpl method buildNameKey.

protected String buildNameKey(SandBox sandBox, StructuredContent sc, Boolean secure) {
    BroadleafRequestContext context = BroadleafRequestContext.getBroadleafRequestContext();
    Site site = (context != null) ? context.getNonPersistentSite() : null;
    Long siteId = (site != null) ? site.getId() : null;
    Locale locale = findLanguageOnlyLocale(sc.getLocale());
    String contentType = sc.getStructuredContentType().getName();
    String contentName = sc.getContentName() + "-" + sc.getId();
    return buildNameKey(sandBox, siteId, locale, contentType, contentName, secure);
}
Also used : Site(org.broadleafcommerce.common.site.domain.Site) Locale(org.broadleafcommerce.common.locale.domain.Locale) BroadleafRequestContext(org.broadleafcommerce.common.web.BroadleafRequestContext)

Example 23 with Site

use of org.broadleafcommerce.common.site.domain.Site in project BroadleafCommerce by BroadleafCommerce.

the class StructuredContentServiceImpl method buildTypeKey.

protected String buildTypeKey(SandBox sandBox, StructuredContent sc) {
    BroadleafRequestContext context = BroadleafRequestContext.getBroadleafRequestContext();
    Site site = (context != null) ? context.getNonPersistentSite() : null;
    Long siteId = (site != null) ? site.getId() : null;
    Locale locale = findLanguageOnlyLocale(sc.getLocale());
    String contentType = sc.getStructuredContentType().getName();
    return buildTypeKey(sandBox, siteId, locale, contentType);
}
Also used : Site(org.broadleafcommerce.common.site.domain.Site) Locale(org.broadleafcommerce.common.locale.domain.Locale) BroadleafRequestContext(org.broadleafcommerce.common.web.BroadleafRequestContext)

Example 24 with Site

use of org.broadleafcommerce.common.site.domain.Site in project BroadleafCommerce by BroadleafCommerce.

the class AdminAssetController method viewEntityForm.

@Override
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
public String viewEntityForm(HttpServletRequest request, HttpServletResponse response, Model model, @PathVariable Map<String, String> pathVars, @PathVariable(value = "id") String id) throws Exception {
    Site currentSite = BroadleafRequestContext.getBroadleafRequestContext().getNonPersistentSite();
    model.addAttribute("cmsUrlPrefix", staticAssetService.getStaticAssetUrlPrefix());
    String returnPath = super.viewEntityForm(request, response, model, pathVars, id);
    staticAssetExtensionManager.getProxy().removeShareOptionsForMTStandardSite(model, currentSite);
    return returnPath;
}
Also used : Site(org.broadleafcommerce.common.site.domain.Site)

Example 25 with Site

use of org.broadleafcommerce.common.site.domain.Site in project BroadleafCommerce by BroadleafCommerce.

the class SiteServiceImpl method getNonPersistentSite.

protected Site getNonPersistentSite(Site persistentSite) {
    if (persistentSite == null) {
        return null;
    }
    NonPersistentSiteThreadLocalCache cache = NonPersistentSiteThreadLocalCache.getSitesCache();
    Site clone = cache.getSites().get(persistentSite.getId());
    if (clone == null) {
        clone = persistentSite.clone();
        extensionManager.getProxy().contributeNonPersitentSiteProperties(persistentSite, clone);
        cache.getSites().put(persistentSite.getId(), clone);
    }
    return clone;
}
Also used : Site(org.broadleafcommerce.common.site.domain.Site)

Aggregations

Site (org.broadleafcommerce.common.site.domain.Site)27 BroadleafRequestContext (org.broadleafcommerce.common.web.BroadleafRequestContext)16 ArrayList (java.util.ArrayList)5 Locale (org.broadleafcommerce.common.locale.domain.Locale)4 SandBox (org.broadleafcommerce.common.sandbox.domain.SandBox)4 SiteImpl (org.broadleafcommerce.common.site.domain.SiteImpl)4 ExtensionResultHolder (org.broadleafcommerce.common.extension.ExtensionResultHolder)3 Catalog (org.broadleafcommerce.common.site.domain.Catalog)3 AdminUser (org.broadleafcommerce.openadmin.server.security.domain.AdminUser)3 File (java.io.File)2 Set (java.util.Set)2 TimeZone (java.util.TimeZone)2 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)2 Element (net.sf.ehcache.Element)2 CloudSolrClient (org.apache.solr.client.solrj.impl.CloudSolrClient)2 RequestDTOImpl (org.broadleafcommerce.common.RequestDTOImpl)2 BroadleafRequestedCurrencyDto (org.broadleafcommerce.common.currency.domain.BroadleafRequestedCurrencyDto)2 IOException (java.io.IOException)1 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1