Search in sources :

Example 1 with ICssCompressor

use of org.apache.wicket.css.ICssCompressor in project wicket by apache.

the class CompositeCssCompressor method process.

/**
 * Compresses the given original content in the order of compressors. If no compressor has been
 * given the original content is going to be returned.
 */
@Override
public String process(String input, Class<?> scope, String name) {
    String compressed = input;
    for (ICssCompressor compressor : compressors) {
        if (compressor instanceof IScopeAwareTextResourceProcessor) {
            IScopeAwareTextResourceProcessor processor = (IScopeAwareTextResourceProcessor) compressor;
            compressed = processor.process(compressed, scope, name);
        } else {
            compressed = compressor.compress(compressed);
        }
    }
    return compressed;
}
Also used : ICssCompressor(org.apache.wicket.css.ICssCompressor)

Example 2 with ICssCompressor

use of org.apache.wicket.css.ICssCompressor in project wicket by apache.

the class ResourceSettings method setCssCompressor.

/**
 * Set the CSS compressor implemententation use e.g. by
 * {@link org.apache.wicket.request.resource.CssPackageResource CssPackageResource}. A typical
 * implementation will remove comments and whitespace. But a no-op implementation is available
 * as well.
 *
 * @param compressor
 *            The implementation to be used
 * @return The old value
 * @return {@code this} object for chaining
 */
public ICssCompressor setCssCompressor(ICssCompressor compressor) {
    ICssCompressor old = cssCompressor;
    cssCompressor = compressor;
    return old;
}
Also used : ICssCompressor(org.apache.wicket.css.ICssCompressor)

Example 3 with ICssCompressor

use of org.apache.wicket.css.ICssCompressor in project wicket by apache.

the class CssTemplate method getString.

@Override
public String getString() {
    String nonCompressed = super.getString();
    ICssCompressor compressor = null;
    if (Application.exists()) {
        compressor = Application.get().getResourceSettings().getCssCompressor();
    }
    if (compressor != null) {
        return compressor.compress(nonCompressed);
    } else {
        // don't strip the comments
        return nonCompressed;
    }
}
Also used : ICssCompressor(org.apache.wicket.css.ICssCompressor)

Example 4 with ICssCompressor

use of org.apache.wicket.css.ICssCompressor in project wicket by apache.

the class CssPackageResourceTest method newApplication.

@Override
protected WebApplication newApplication() {
    return new MockApplication() {

        @Override
        protected void init() {
            super.init();
            getResourceSettings().setCssCompressor(new ICssCompressor() {

                @Override
                public String compress(String original) {
                    return APP_COMPRESSED;
                }
            });
        }
    };
}
Also used : ICssCompressor(org.apache.wicket.css.ICssCompressor) MockApplication(org.apache.wicket.mock.MockApplication)

Example 5 with ICssCompressor

use of org.apache.wicket.css.ICssCompressor in project wicket by apache.

the class CssPackageResource method processResponse.

@Override
protected byte[] processResponse(final Attributes attributes, final byte[] bytes) {
    final byte[] processedResponse = super.processResponse(attributes, bytes);
    ICssCompressor compressor = getCompressor();
    if (compressor != null && getCompress()) {
        try {
            String charsetName = "UTF-8";
            String nonCompressed = new String(processedResponse, charsetName);
            String output;
            if (compressor instanceof IScopeAwareTextResourceProcessor) {
                IScopeAwareTextResourceProcessor scopeAwareProcessor = (IScopeAwareTextResourceProcessor) compressor;
                output = scopeAwareProcessor.process(nonCompressed, getScope(), name);
            } else {
                output = compressor.compress(nonCompressed);
            }
            return output.getBytes(charsetName);
        } catch (Exception e) {
            log.error("Error while filtering content", e);
            return processedResponse;
        }
    } else {
        // don't strip the comments
        return processedResponse;
    }
}
Also used : ICssCompressor(org.apache.wicket.css.ICssCompressor) IScopeAwareTextResourceProcessor(org.apache.wicket.resource.IScopeAwareTextResourceProcessor)

Aggregations

ICssCompressor (org.apache.wicket.css.ICssCompressor)6 ArrayList (java.util.ArrayList)1 CssReferenceHeaderItem (org.apache.wicket.markup.head.CssReferenceHeaderItem)1 MockApplication (org.apache.wicket.mock.MockApplication)1 CssResourceReference (org.apache.wicket.request.resource.CssResourceReference)1 IScopeAwareTextResourceProcessor (org.apache.wicket.resource.IScopeAwareTextResourceProcessor)1