Search in sources :

Example 1 with ReplacementResourceBundleReference

use of org.apache.wicket.resource.bundles.ReplacementResourceBundleReference in project wicket by apache.

the class ResourceAggregator method preserveJavaScriptDetails.

/**
 * Preserves the resource reference details for JavaScript resource replacements.
 *
 * For example if CSS resource with media <em>screen</em> is replaced with
 * {@link org.apache.wicket.protocol.http.WebApplication#addResourceReplacement(org.apache.wicket.request.resource.JavaScriptResourceReference, org.apache.wicket.request.resource.ResourceReference)} then the replacement will
 * will inherit the media attribute
 *
 * @param item   The replaced header item
 * @param bundle The bundle that represents the replacement
 * @return the bundle with the preserved details
 */
private HeaderItem preserveJavaScriptDetails(JavaScriptReferenceHeaderItem item, JavaScriptReferenceHeaderItem bundle) {
    HeaderItem resultBundle;
    ResourceReference bundleReference = bundle.getReference();
    if (bundleReference instanceof ReplacementResourceBundleReference) {
        resultBundle = JavaScriptHeaderItem.forReference(bundleReference, item.getPageParameters(), item.getId(), item.isDefer(), item.getCharset(), item.getCondition());
    } else {
        resultBundle = bundle;
    }
    return resultBundle;
}
Also used : ReplacementResourceBundleReference(org.apache.wicket.resource.bundles.ReplacementResourceBundleReference) ResourceReference(org.apache.wicket.request.resource.ResourceReference)

Example 2 with ReplacementResourceBundleReference

use of org.apache.wicket.resource.bundles.ReplacementResourceBundleReference in project wicket by apache.

the class WebApplication method addResourceReplacement.

/**
 * Registers a replacement resource for the given CSS resource. This replacement can be another
 * {@link CssResourceReference} for a packaged resource, but it can also be an
 * {@link org.apache.wicket.request.resource.UrlResourceReference} to replace the resource by a
 * resource hosted on a CDN. Registering a replacement will cause the resource to replaced by
 * the given resource throughout the application: if {@code base} is added, {@code replacement}
 * will be added instead.
 *
 * @param base
 *            The resource to replace
 * @param replacement
 *            The replacement
 */
public final void addResourceReplacement(CssResourceReference base, ResourceReference replacement) {
    ReplacementResourceBundleReference bundle = new ReplacementResourceBundleReference(replacement);
    bundle.addProvidedResources(CssHeaderItem.forReference(base));
    getResourceBundles().addBundle(CssHeaderItem.forReference(bundle));
}
Also used : ReplacementResourceBundleReference(org.apache.wicket.resource.bundles.ReplacementResourceBundleReference)

Example 3 with ReplacementResourceBundleReference

use of org.apache.wicket.resource.bundles.ReplacementResourceBundleReference in project wicket by apache.

the class ResourceAggregator method preserveCssDetails.

/**
 * Preserves the resource reference details for CSS resource replacements.
 *
 * For example if CSS resource with media <em>screen</em> is replaced with
 * {@link org.apache.wicket.protocol.http.WebApplication#addResourceReplacement(org.apache.wicket.request.resource.CssResourceReference, org.apache.wicket.request.resource.ResourceReference)} then the replacement will
 * will inherit the media attribute
 *
 * @param item   The replaced header item
 * @param bundle The bundle that represents the replacement
 * @return the bundle with the preserved details
 */
protected HeaderItem preserveCssDetails(CssReferenceHeaderItem item, CssReferenceHeaderItem bundle) {
    HeaderItem resultBundle;
    ResourceReference bundleReference = bundle.getReference();
    if (bundleReference instanceof ReplacementResourceBundleReference) {
        resultBundle = CssHeaderItem.forReference(bundleReference, item.getPageParameters(), item.getMedia(), item.getCondition());
    } else {
        resultBundle = bundle;
    }
    return resultBundle;
}
Also used : ReplacementResourceBundleReference(org.apache.wicket.resource.bundles.ReplacementResourceBundleReference) ResourceReference(org.apache.wicket.request.resource.ResourceReference)

Example 4 with ReplacementResourceBundleReference

use of org.apache.wicket.resource.bundles.ReplacementResourceBundleReference in project wicket by apache.

the class WebApplication method addResourceReplacement.

/**
 * Registers a replacement resource for the given javascript resource. This replacement can be
 * another {@link JavaScriptResourceReference} for a packaged resource, but it can also be an
 * {@link org.apache.wicket.request.resource.UrlResourceReference} to replace the resource by a
 * resource hosted on a CDN. Registering a replacement will cause the resource to replaced by
 * the given resource throughout the application: if {@code base} is added, {@code replacement}
 * will be added instead.
 *
 * @param base
 *            The resource to replace
 * @param replacement
 *            The replacement
 */
public final void addResourceReplacement(JavaScriptResourceReference base, ResourceReference replacement) {
    ReplacementResourceBundleReference bundle = new ReplacementResourceBundleReference(replacement);
    bundle.addProvidedResources(JavaScriptHeaderItem.forReference(base));
    getResourceBundles().addBundle(JavaScriptHeaderItem.forReference(bundle));
}
Also used : ReplacementResourceBundleReference(org.apache.wicket.resource.bundles.ReplacementResourceBundleReference)

Aggregations

ReplacementResourceBundleReference (org.apache.wicket.resource.bundles.ReplacementResourceBundleReference)4 ResourceReference (org.apache.wicket.request.resource.ResourceReference)2