public int doEndTag() throws JspException { AssetRequestContext.get(pageContext.getRequest()).addBundles(includes).excludeBundles(excludes); return EVAL_PAGE; }
public int doEndTag() throws JspException { AssetRequestContext.get(pageContext.getRequest()).excludeJs(jsExcludes); AssetRequestContext.get(pageContext.getRequest()).excludeCss(cssExcludes); return EVAL_PAGE; }
/** * Updates the current {@link HttpServletRequest} with the passed * {@link DatatableBundles}. * * @param bundle * The {@link DatatableBundles} to add. */ public void addBundle(DatatableBundles bundle) { AssetRequestContext.get(table.getTableConfiguration().getRequest()).addBundles(bundle); }
String existingPlaceholder = AssetRequestContext.get(pageContext.getRequest()).getJsPlaceholder(); if (StringUtils.isNotBlank(existingPlaceholder)) { throw new JspException( AssetRequestContext.get(pageContext.getRequest()).setJsPlaceholder(placeholder); String existingPlaceholder = AssetRequestContext.get(pageContext.getRequest()).getCssPlaceholder(); if (StringUtils.isNotBlank(existingPlaceholder)) { throw new JspException( AssetRequestContext.get(pageContext.getRequest()).setCssPlaceholder(placeholder);
JQueryJsContentGenerator javascriptGenerator = (JQueryJsContentGenerator) AssetRequestContext.get(request) .getGenerator(DatatableComponent.COMPONENT_NAME); AssetRequestContext.get(request).addBundles(DatatableBundles.DDL_DT) .addGenerator(DatatableComponent.COMPONENT_NAME, javascriptGenerator);
/** * <p> * Returns the {@link AssetRequestContext} associated to the passed * {@link ServletRequest}. * </p> * <p> * If it doesn't exist, a new instance is created and stored as a request * attribute. * </p> * * @param servletRequest * The servlet request in which is stored the * {@link AssetRequestContext}. * @return the instance of {@link AssetRequestContext} associated with the * current servlet request. */ public static AssetRequestContext get(ServletRequest servletRequest) { Object attribute = servletRequest.getAttribute(AssetRequestContext.class.getCanonicalName()); Context context = (Context) servletRequest.getAttribute(WebConstants.DANDELION_CONTEXT_ATTRIBUTE); if (attribute == null || !(attribute instanceof AssetRequestContext)) { attribute = new AssetRequestContext(); ((AssetRequestContext) attribute).addBundles(context.getConfiguration().getBundleIncludes()); ((AssetRequestContext) attribute).excludeBundles(context.getConfiguration().getBundleExcludes()); ((AssetRequestContext) attribute).excludeJs(context.getConfiguration().getAssetJsExcludes()); ((AssetRequestContext) attribute).excludeCss(context.getConfiguration().getAssetCssExcludes()); servletRequest.setAttribute(AssetRequestContext.class.getCanonicalName(), attribute); } return AssetRequestContext.class.cast(attribute); }
public Set<Alert> alerts() { Set<Alert> errors = new HashSet<Alert>(); String currentUri = UrlUtils.getCurrentUri(request).toString(); LOG.debug("Checking for alerts for the request \"{}\"", currentUri); String[] bundleNames = AssetRequestContext.get(this.request).getBundles(true); errors.addAll(this.context.getBundleStorage().alertsFor(bundleNames)); LOG.debug("-> Errors found: {}", errors.size()); return errors; }
AssetRequestContext arc = AssetRequestContext.get(handlerContext.getRequest()); String cssPlaceholder = arc.getCssPlaceholder(); String jsPlaceholder = arc.getJsPlaceholder();
AssetRequestContext.get(request).excludeBundles(STANDALONE_BUNDLES_TO_EXCLUDE);
@Override protected String doGetContent(Asset asset, Map<String, Object> parameters, HttpServletRequest request) { AssetContentGenerator generator = AssetRequestContext.get(request).getGenerator(asset.getGeneratorUid()); if (generator == null) { throw new DandelionException("No asset generator has been found in the request with the uid \"" + asset.getGeneratorUid() + "\". Ensure to call AssetRequestContext.get(request).addGenerator(\"" + asset.getGeneratorUid() + "\", ...);"); } return generator.getAssetContent(request); } }
for (String bundleToExclude : AssetRequestContext.get(this.request).getExcludedBundles()) { Set<BundleStorageUnit> bsus = this.context.getBundleStorage().bundlesFor(bundleToExclude); for (BundleStorageUnit bsu : bsus) { for (String assetToExclude : AssetRequestContext.get(this.request).getExcludedJs()) { excludedJsNames.add(assetToExclude); for (String bundleToExclude : AssetRequestContext.get(this.request).getExcludedBundles()) { Set<BundleStorageUnit> bsus = this.context.getBundleStorage().bundlesFor(bundleToExclude); for (BundleStorageUnit bsu : bsus) { for (String assetToExclude : AssetRequestContext.get(this.request).getExcludedCss()) { excludedCssNames.add(assetToExclude);
public void addBundleParameter(String assetName, String paramName, Object paramValue) { AssetRequestContext.get(table.getTableConfiguration().getRequest()).addParameter(assetName, paramName, paramValue); }
/** * <p> * Returns the content of the given {@link Asset}, using its * {@link Asset#getFinalLocation()} value. * * <p> * Note that this method can be used to access the asset's content after the * {@link AssetProcessor}'s execution. * * @param asset * The asset from which the content should be extracted. * @param request * The current HTTP request. * @return the raw content (unprocessed) of the passed {@link Asset}. */ public String getContent(Asset asset, HttpServletRequest request) { Map<String, Object> parameters = AssetRequestContext.get(request).getParameters(asset.getName()); String content = doGetContent(asset, parameters, request); // Apply variable replacement if (!parameters.isEmpty()) { for (Map.Entry<String, Object> entry : parameters.entrySet()) { content = content.replace(entry.getKey(), entry.getValue().toString()); } } return content; }
/** * <p> * Adds the given comma-separated list of bundles to the current * {@link AssetRequestContext}. * </p> * * @param bundles * A comma-separated list of bundles. * @return the current {@link AssetRequestContext} updated with the active * bundle. */ public AssetRequestContext addBundles(String bundles) { if (bundles == null || bundles.isEmpty()) { return this; } return addBundles(bundles.split(",")); }
@Override protected ProcessorResult doProcessAttribute(Arguments arguments, Element element, String attributeName) { String strippedAttributeName = AttributesUtil.stripPrefix(attributeName, DandelionDialect.DIALECT_PREFIX); PlaceholderAttributeNames placeholderAttributeName = (PlaceholderAttributeNames) AttributesUtil .find(strippedAttributeName, PlaceholderAttributeNames.values()); HttpServletRequest request = ArgumentsUtil.getWebContext(arguments).getHttpServletRequest(); AssetRequestContext arc = AssetRequestContext.get(request); String attributeValue = element.getAttributeValue(attributeName); if (StringUtils.isBlank(attributeValue)) { throw new DandelionException("The \"type\" attribute cannot be blank. Possible values: \"" + PLACEHOLDER_TYPE_JS + "\" or \"" + PLACEHOLDER_TYPE_CSS + "\"."); } String placeholder = "dandelionPlaceholder" + attributeValue; handlePlaceholder(attributeValue, arc, placeholder); switch (placeholderAttributeName) { // Include a new Text node containing the placeholder within the existing // element case PLACEHOLDER_INCLUDE: Text text = new Text(placeholder); element.insertChild(element.getChildren().size(), text); break; // Replace the current element by the placeholder case PLACEHOLDER_REPLACE: text = new Text(placeholder); element.clearChildren(); element.addChild(text); break; } return ProcessorResult.ok(); }
/** * <p> * Adds the given collection of bundles to the current * {@link AssetRequestContext}. * </p> * * @param bundles * A collection of bundle names. * @return the current {@link AssetRequestContext}. */ public AssetRequestContext excludeBundles(Collection<String> bundles) { for (String bundle : bundles) { excludeBundles(bundle); } return this; }
public AssetRequestContext excludeCss(Collection<String> cssToExclude) { for (String css : cssToExclude) { excludeCss(css); } return this; }
public AssetRequestContext excludeJs(Collection<String> jsToExclude) { for (String js : jsToExclude) { excludeJs(js); } return this; }
String existingPlaceholder = AssetRequestContext.get(pageContext.getRequest()).getJsPlaceholder(); if (StringUtils.isNotBlank(existingPlaceholder)) { throw new JspException( AssetRequestContext.get(pageContext.getRequest()).setJsPlaceholder(placeholder); String existingPlaceholder = AssetRequestContext.get(pageContext.getRequest()).getCssPlaceholder(); if (StringUtils.isNotBlank(existingPlaceholder)) { throw new JspException( AssetRequestContext.get(pageContext.getRequest()).setCssPlaceholder(placeholder);
JQueryJsContentGenerator javascriptGenerator = (JQueryJsContentGenerator) AssetRequestContext.get(this.request) .getGenerator(DatatableComponent.COMPONENT_NAME); AssetRequestContext.get(this.request).addBundles(DatatableBundles.DDL_DT) .addGenerator(DatatableComponent.COMPONENT_NAME, javascriptGenerator);