use of org.broadleafcommerce.presentation.model.BroadleafTemplateModel in project BroadleafCommerce by BroadleafCommerce.
the class ResourceBundleProcessor method getReplacementModel.
@Override
public BroadleafTemplateModel getReplacementModel(String tagName, Map<String, String> tagAttributes, BroadleafTemplateContext context) {
String name = tagAttributes.get("name");
String mappingPrefix = tagAttributes.get("mapping-prefix");
boolean async = tagAttributes.containsKey("async");
boolean defer = tagAttributes.containsKey("defer");
boolean includeAsyncDeferUnbundled = tagAttributes.containsKey("includeAsyncDeferUnbundled") && Boolean.parseBoolean(tagAttributes.get("includeAsyncDeferUnbundled"));
String dependencyEvent = tagAttributes.get("bundle-dependency-event");
List<String> files = new ArrayList<>();
for (String file : tagAttributes.get("files").split(",")) {
files.add(file.trim());
}
List<String> additionalBundleFiles = bundlingService.getAdditionalBundleFiles(name);
if (additionalBundleFiles != null) {
files.addAll(additionalBundleFiles);
}
BroadleafTemplateModel model = context.createModel();
if (getBundleEnabled()) {
String bundleResourceName = bundlingService.resolveBundleResourceName(name, mappingPrefix, files);
String bundleUrl = getBundleUrl(bundleResourceName, context);
addElementToModel(bundleUrl, async, defer, dependencyEvent, context, model);
} else {
if (async) {
async = includeAsyncDeferUnbundled;
}
if (defer) {
defer = includeAsyncDeferUnbundled;
}
for (String fileName : files) {
fileName = fileName.trim();
String fullFileName = (String) context.parseExpression("@{'" + mappingPrefix + fileName + "'}");
addElementToModel(fullFileName, async, defer, context, model);
}
}
return model;
}
use of org.broadleafcommerce.presentation.model.BroadleafTemplateModel in project BroadleafCommerce by BroadleafCommerce.
the class LinkedDataProcessor method getReplacementModel.
@Override
public BroadleafTemplateModel getReplacementModel(final String s, final Map<String, String> map, final BroadleafTemplateContext context) {
String linkedDataText = "<script type=\"application/ld+json\">\n" + getData(context.getRequest()) + "\n</script>";
final BroadleafTemplateModel model = context.createModel();
final BroadleafTemplateElement linkedData = context.createTextElement(linkedDataText);
model.addElement(linkedData);
return model;
}
use of org.broadleafcommerce.presentation.model.BroadleafTemplateModel in project BroadleafCommerce by BroadleafCommerce.
the class TransparentRedirectCreditCardFormProcessor method getInjectedModelAndTagAttributes.
@Override
public BroadleafTemplateModelModifierDTO getInjectedModelAndTagAttributes(String rootTagName, Map<String, String> rootTagAttributes, BroadleafTemplateContext context) {
PaymentRequestDTO requestDTO = (PaymentRequestDTO) context.parseExpression(rootTagAttributes.get("paymentRequestDTO"));
Map<String, Map<String, String>> formParameters = new HashMap<>();
Map<String, String> configurationSettings = new HashMap<>();
// Create the configuration settings map to pass into the payment module
Map<String, String> keysToKeep = new HashMap<>();
for (String key : rootTagAttributes.keySet()) {
if (key.startsWith("config-")) {
final int trimLength = "config-".length();
String configParam = key.substring(trimLength);
configurationSettings.put(configParam, rootTagAttributes.get(key));
} else {
keysToKeep.put(key, rootTagAttributes.get(key));
}
}
keysToKeep.remove("paymentRequestDTO");
try {
extensionManager.getProxy().createTransparentRedirectForm(formParameters, requestDTO, configurationSettings);
} catch (PaymentException e) {
throw new RuntimeException("Unable to Create the Transparent Redirect Form", e);
}
StringBuilder formActionKey = new StringBuilder("formActionKey");
StringBuilder formHiddenParamsKey = new StringBuilder("formHiddenParamsKey");
extensionManager.getProxy().setFormActionKey(formActionKey);
extensionManager.getProxy().setFormHiddenParamsKey(formHiddenParamsKey);
// Change the action attribute on the form to the Payment Gateways Endpoint
String actionUrl = "";
Map<String, String> actionValue = formParameters.get(formActionKey.toString());
if (actionValue != null && actionValue.size() > 0) {
String key = (String) actionValue.keySet().toArray()[0];
actionUrl = actionValue.get(key);
}
keysToKeep.put("action", actionUrl);
BroadleafTemplateModel model = context.createModel();
// Append any hidden fields necessary for the Transparent Redirect
Map<String, String> hiddenFields = formParameters.get(formHiddenParamsKey.toString());
if (MapUtils.isNotEmpty(hiddenFields)) {
for (String key : hiddenFields.keySet()) {
Map<String, String> attributes = new HashMap<>();
attributes.put("type", "hidden");
attributes.put("name", key);
attributes.put("value", hiddenFields.get(key));
BroadleafTemplateElement input = context.createStandaloneElement("input", attributes, true);
model.addElement(input);
}
}
return new BroadleafTemplateModelModifierDTO(model, keysToKeep, "form");
}
use of org.broadleafcommerce.presentation.model.BroadleafTemplateModel in project BroadleafCommerce by BroadleafCommerce.
the class FormProcessor method getInjectedModelAndTagAttributes.
@Override
public BroadleafTemplateModelModifierDTO getInjectedModelAndTagAttributes(String rootTagName, Map<String, String> rootTagAttributes, BroadleafTemplateContext context) {
Map<String, String> formAttributes = new HashMap<>();
formAttributes.putAll(rootTagAttributes);
BroadleafTemplateModel model = context.createModel();
BroadleafTemplateModelModifierDTO dto = new BroadleafTemplateModelModifierDTO();
// We do this instead of checking for a POST because post is default if nothing is specified
if (!"GET".equalsIgnoreCase(formAttributes.get("method"))) {
try {
String csrfToken = eps.getCSRFToken();
String stateVersionToken = null;
if (spps.isEnabled()) {
stateVersionToken = spps.getStateVersionToken();
}
// detect multipart form
if ("multipart/form-data".equalsIgnoreCase(formAttributes.get("enctype"))) {
String csrfQueryParameter = "?" + eps.getCsrfTokenParameter() + "=" + csrfToken;
if (stateVersionToken != null) {
csrfQueryParameter += "&" + spps.getStateVersionTokenParameter() + "=" + stateVersionToken;
}
// Add this into the attribute map to be used for the new <form> tag. The expression has already
// been executed, don't need to treat the value as an expression
String actionValue = formAttributes.get("action");
actionValue += csrfQueryParameter;
formAttributes.put("action", actionValue);
} else {
Map<String, String> csrfAttributes = new HashMap<>();
csrfAttributes.put("type", "hidden");
csrfAttributes.put("name", eps.getCsrfTokenParameter());
csrfAttributes.put("value", csrfToken);
BroadleafTemplateElement csrfTag = context.createStandaloneElement("input", csrfAttributes, true);
model.addElement(csrfTag);
if (stateVersionToken != null) {
Map<String, String> stateVersionAttributes = new HashMap<>();
stateVersionAttributes.put("type", "hidden");
stateVersionAttributes.put("name", spps.getStateVersionTokenParameter());
stateVersionAttributes.put("value", stateVersionToken);
BroadleafTemplateElement stateVersionTag = context.createStandaloneElement("input", stateVersionAttributes, true);
model.addElement(stateVersionTag);
}
dto.setModel(model);
}
} catch (ServiceException e) {
throw new RuntimeException("Could not get a CSRF token for this session", e);
}
}
dto.setFormParameters(formAttributes);
dto.setReplacementTagName("form");
return dto;
}
use of org.broadleafcommerce.presentation.model.BroadleafTemplateModel in project BroadleafCommerce by BroadleafCommerce.
the class GoogleUniversalAnalyticsProcessor method getReplacementModel.
@Override
public BroadleafTemplateModel getReplacementModel(String tagName, Map<String, String> tagAttributes, BroadleafTemplateContext context) {
StringBuffer sb = new StringBuffer();
Map<String, String> trackers = getTrackers();
if (MapUtils.isNotEmpty(trackers)) {
sb.append("(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){");
sb.append("(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),");
sb.append("m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)");
sb.append("})(window,document,'script','//www.google-analytics.com/analytics.js','ga');");
String orderNumberExpression = tagAttributes.get("ordernumber");
String orderNumber = null;
if (orderNumberExpression != null) {
orderNumber = (String) context.parseExpression(orderNumberExpression);
}
Order order = null;
if (orderNumber != null) {
order = orderService.findOrderByOrderNumber(orderNumber);
}
for (Entry<String, String> tracker : trackers.entrySet()) {
String trackerName = tracker.getKey();
String trackerPrefix = "";
String id = tracker.getValue();
sb.append("ga('create', '" + id + "', 'auto', {");
if (!"webProperty".equals(trackerName)) {
trackerPrefix = trackerName + ".";
sb.append("'name': '" + trackerName + "'");
if (testLocal) {
sb.append(",");
}
}
if (testLocal) {
sb.append("'cookieDomain': 'none'");
}
sb.append("});");
if ("webProperty".equals(trackerName)) {
HttpServletRequest request = BroadleafRequestContext.getBroadleafRequestContext().getRequest();
if (request != null) {
Map<String, String> setValuesMap = (Map<String, String>) request.getAttribute("blGAValuesMap");
if (setValuesMap != null) {
for (Map.Entry<String, String> entry : setValuesMap.entrySet()) {
sb.append("ga('" + trackerPrefix + "set',").append(entry.getKey()).append(",").append(entry.getValue()).append(");");
}
}
}
}
sb.append("ga('" + trackerPrefix + "send', 'pageview');");
if (isIncludeLinkAttribution()) {
sb.append(getLinkAttributionJs(trackerPrefix));
}
if (isIncludeDisplayAdvertising()) {
sb.append(getDisplayAdvertisingJs(trackerPrefix));
}
if (order != null) {
sb.append(getTransactionJs(order, trackerPrefix));
}
}
// Add contentNode to the document
BroadleafTemplateModel model = context.createModel();
BroadleafTemplateNonVoidElement scriptTag = context.createNonVoidElement("script");
BroadleafTemplateElement script = context.createTextElement(sb.toString());
scriptTag.addChild(script);
model.addElement(scriptTag);
return model;
} else {
LOG.warn("No trackers were found, not outputting Google Analytics script. Set the googleAnalytics.webPropertyId" + " and/or the googleAnalytics.masterWebPropertyId system properties to output Google Analytics");
}
return null;
}
Aggregations