Search in sources :

Example 61 with BroadleafRequestContext

use of org.broadleafcommerce.common.web.BroadleafRequestContext in project BroadleafCommerce by BroadleafCommerce.

the class SystemPropertiesDaoImpl method getSite.

protected String getSite() {
    String site = "";
    BroadleafRequestContext brc = BroadleafRequestContext.getBroadleafRequestContext();
    if (brc != null) {
        if (brc.getSite() != null) {
            site = String.valueOf(brc.getSite().getId());
        }
    }
    return site;
}
Also used : BroadleafRequestContext(org.broadleafcommerce.common.web.BroadleafRequestContext)

Example 62 with BroadleafRequestContext

use of org.broadleafcommerce.common.web.BroadleafRequestContext in project BroadleafCommerce by BroadleafCommerce.

the class SystemPropertiesServiceImpl method buildKey.

/**
 * Properties can vary by site.   If a site is found on the request, use the site id as part of the
 * cache-key.
 *
 * @param propertyName
 * @return
 */
protected String buildKey(String propertyName) {
    Long siteId = null;
    BroadleafRequestContext brc = BroadleafRequestContext.getBroadleafRequestContext();
    if (brc != null) {
        if (brc.getSite() != null) {
            siteId = brc.getSite().getId();
        }
    }
    return buildKey(propertyName, siteId);
}
Also used : BroadleafRequestContext(org.broadleafcommerce.common.web.BroadleafRequestContext)

Example 63 with BroadleafRequestContext

use of org.broadleafcommerce.common.web.BroadleafRequestContext in project BroadleafCommerce by BroadleafCommerce.

the class BroadleafFileServiceImpl method getBaseDirectory.

/**
 * Returns the baseDirectory for writing and reading files as the property assetFileSystemPath if it
 * exists or java.tmp.io if that property has not been set.
 */
protected String getBaseDirectory(boolean skipSite) {
    String path = "";
    if (StringUtils.isBlank(tempFileSystemBaseDirectory)) {
        path = DEFAULT_STORAGE_DIRECTORY;
    } else {
        path = tempFileSystemBaseDirectory;
    }
    if (!skipSite) {
        // Create site specific directory if Multi-site (all site files will be located in the same directory)
        BroadleafRequestContext brc = BroadleafRequestContext.getBroadleafRequestContext();
        if (brc != null && brc.getSite() != null) {
            String siteDirectory = "site-" + brc.getSite().getId();
            String siteHash = DigestUtils.md5Hex(siteDirectory);
            path = FilenameUtils.concat(path, siteHash.substring(0, 2));
            path = FilenameUtils.concat(path, siteDirectory);
        }
    }
    return path;
}
Also used : BroadleafRequestContext(org.broadleafcommerce.common.web.BroadleafRequestContext)

Example 64 with BroadleafRequestContext

use of org.broadleafcommerce.common.web.BroadleafRequestContext in project BroadleafCommerce by BroadleafCommerce.

the class BLCVariableExpression method getPrice.

/**
 * Returns the price at the correct scale and rounding for the default currency
 * @see Money#defaultCurrency()
 * @param amount
 * @return
 */
public String getPrice(String amount) {
    Money price = Money.ZERO;
    String sanitizedAmount = StringUtil.removeNonNumerics(amount);
    if (StringUtils.isNotEmpty(sanitizedAmount)) {
        price = new Money(sanitizedAmount);
        BroadleafRequestContext brc = BroadleafRequestContext.getBroadleafRequestContext();
        if (brc.getJavaLocale() != null) {
            NumberFormat formatter = BroadleafCurrencyUtils.getNumberFormatFromCache(brc.getJavaLocale(), price.getCurrency());
            return formatter.format(price.getAmount());
        }
    }
    return "$ " + price.getAmount().toString();
}
Also used : Money(org.broadleafcommerce.common.money.Money) BroadleafRequestContext(org.broadleafcommerce.common.web.BroadleafRequestContext) NumberFormat(java.text.NumberFormat)

Example 65 with BroadleafRequestContext

use of org.broadleafcommerce.common.web.BroadleafRequestContext in project BroadleafCommerce by BroadleafCommerce.

the class BLCVariableExpression method getCurrentUrl.

protected String getCurrentUrl() {
    BroadleafRequestContext brc = BroadleafRequestContext.getBroadleafRequestContext();
    String currentUrl = "";
    if (brc != null && brc.getRequest() != null) {
        currentUrl = brc.getRequest().getRequestURI();
        if (!StringUtils.isEmpty(brc.getRequest().getQueryString())) {
            currentUrl = currentUrl + "?" + brc.getRequest().getQueryString();
        }
    }
    return currentUrl;
}
Also used : BroadleafRequestContext(org.broadleafcommerce.common.web.BroadleafRequestContext)

Aggregations

BroadleafRequestContext (org.broadleafcommerce.common.web.BroadleafRequestContext)78 Site (org.broadleafcommerce.common.site.domain.Site)16 HashMap (java.util.HashMap)12 HttpServletRequest (javax.servlet.http.HttpServletRequest)11 ArrayList (java.util.ArrayList)9 Map (java.util.Map)9 Locale (org.broadleafcommerce.common.locale.domain.Locale)8 SandBox (org.broadleafcommerce.common.sandbox.domain.SandBox)5 StructuredContentDTO (org.broadleafcommerce.common.structure.dto.StructuredContentDTO)5 MessageSource (org.springframework.context.MessageSource)5 List (java.util.List)4 StructuredContent (org.broadleafcommerce.cms.structure.domain.StructuredContent)4 Field (java.lang.reflect.Field)3 HashSet (java.util.HashSet)3 Locale (java.util.Locale)3 Catalog (org.broadleafcommerce.common.site.domain.Catalog)3 BroadleafAttributeModifier (org.broadleafcommerce.presentation.model.BroadleafAttributeModifier)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 File (java.io.File)2 PrintWriter (java.io.PrintWriter)2