Search in sources :

Example 1 with IScopeAwareTextResourceProcessor

use of org.apache.wicket.resource.IScopeAwareTextResourceProcessor 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)

Example 2 with IScopeAwareTextResourceProcessor

use of org.apache.wicket.resource.IScopeAwareTextResourceProcessor in project wicket by apache.

the class JavaScriptPackageResource method processResponse.

@Override
protected byte[] processResponse(final Attributes attributes, byte[] bytes) {
    final byte[] processedResponse = super.processResponse(attributes, bytes);
    IJavaScriptCompressor 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 : IJavaScriptCompressor(org.apache.wicket.javascript.IJavaScriptCompressor) IScopeAwareTextResourceProcessor(org.apache.wicket.resource.IScopeAwareTextResourceProcessor)

Aggregations

IScopeAwareTextResourceProcessor (org.apache.wicket.resource.IScopeAwareTextResourceProcessor)2 ICssCompressor (org.apache.wicket.css.ICssCompressor)1 IJavaScriptCompressor (org.apache.wicket.javascript.IJavaScriptCompressor)1