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;
}
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;
}
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;
}
}
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;
}
});
}
};
}
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;
}
}
Aggregations