*
<<<<<<< HEAD
/*
* Copyright (c) 2008. All rights reserved.
*/
package ro.isdc.wro.model.resource.processor.impl.css;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ro.isdc.wro.config.ReadOnlyContext;
import ro.isdc.wro.model.group.Inject;
import ro.isdc.wro.model.resource.processor.support.ImageUrlRewriter;
import ro.isdc.wro.model.resource.processor.support.ImageUrlRewriter.RewriterContext;
import ro.isdc.wro.model.resource.support.MutableResourceAuthorizationManager;
import ro.isdc.wro.model.resource.support.ResourceAuthorizationManager;
/**
* Note: When used together with {@link CssImportPreProcessor}, the {@link CssUrlRewritingProcessor} should come first,
* otherwise it will produce wrong results.
*
* Rewrites background images url of the provided css content. This implementation takes care of most common cases such
* as those described bellow:
*
*
*
*
* | Css resource URI |
* Image URL |
* Computed Image URL |
*
*
*
* | ANY |
* [URL]/1.jpg |
* [URL]/1.jpg |
*
*
* | /1.css |
* /a/1.jpg |
* /a/1.jpg |
*
*
* | /1.jpg |
* /1.jpg |
*
*
* | 1.jpg |
* ../1.jpg |
*
*
* | ../1.jpg |
* ../../1.jpg |
*
*
* | /WEB-INF/1.css |
* /a/1.jpg |
* /a/1.jpg |
*
*
* | /1.jpg |
* /1.jpg |
*
*
* | 1.jpg |
* [WRO-PREFIX]?id=/WEB-INF/1.jpg |
*
*
* | ../1.jpg |
* [WRO-PREFIX]?id=/WEB-INF/../1.jpg |
*
*
* [X]/1.css
*
* where [X] is URL or a classpath resource
* where [WRO-PREFIX] is a servletContext prefix
* which will map WRO filter to the result url. |
* /a/1.jpg |
* [WRO-PREFIX]?id=[X]/a/1.jpg |
*
*
* | /1.jpg |
* [WRO-PREFIX]?id=[X]/1.jpg |
*
*
* | 1.jpg |
* [WRO-PREFIX]?id=[X]/1.jpg |
*
*
* | ../1.jpg |
* [WRO-PREFIX]?id=[X]/../1.jpg |
*
*
*
*
* [X]/1.css
* The algorithm requires two types of {@link UriLocator} objects, one for resolving url resources & one for classpath
* resources. Both need to be injected using IoC when creating the instance of {@link CssUrlRewritingProcessor} class.
*
* @author Alex Objelean
* @created Nov 19, 2008
*/
public class CssUrlRewritingProcessor
extends AbstractCssUrlRewritingProcessor {
private static final Logger LOG = LoggerFactory.getLogger(CssUrlRewritingProcessor.class);
public static final String ALIAS = "cssUrlRewriting";
@Inject
private ResourceAuthorizationManager authorizationManager;
@Inject
private ReadOnlyContext context;
/**
* {@inheritDoc}
*/
@Override
protected void onUrlReplaced(final String replacedUrl) {
final String allowedUrl = StringUtils.removeStart(replacedUrl, getUrlPrefix());
LOG.debug("adding allowed url: {}", allowedUrl);
//add only if add is supported
if (authorizationManager instanceof MutableResourceAuthorizationManager) {
((MutableResourceAuthorizationManager) authorizationManager).add(allowedUrl);
}
}
/**
* Replace provided url with the new url if needed.
*
* @param cssUri
* Uri of the parsed css.
* @param imageUrl
* to replace.
* @return replaced url.
*/
@Override
protected String replaceImageUrl(final String cssUri, final String imageUrl) {
=======
/*
* Copyright (c) 2008. All rights reserved.
*/
package ro.isdc.wro.model.resource.processor.impl.css;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ro.isdc.wro.config.ReadOnlyContext;
import ro.isdc.wro.model.group.Inject;
import ro.isdc.wro.model.resource.locator.UriLocator;
import ro.isdc.wro.model.resource.processor.support.ImageUrlRewriter;
import ro.isdc.wro.model.resource.processor.support.ImageUrlRewriter.RewriterContext;
import ro.isdc.wro.model.resource.support.MutableResourceAuthorizationManager;
import ro.isdc.wro.model.resource.support.ResourceAuthorizationManager;
/**
* Note: When used together with {@link CssImportPreProcessor}, the {@link CssUrlRewritingProcessor} should come first,
* otherwise it will produce wrong results.
*
* Rewrites background images url of the provided css content. This implementation takes care of most common cases such
* as those described bellow:
*
*
*
*
* | Css resource URI |
* Image URL |
* Computed Image URL |
*
*
*
* | ANY |
* [URL]/1.jpg |
* [URL]/1.jpg |
*
*
* | /1.css |
* /a/1.jpg |
* /a/1.jpg |
*
*
* | /1.jpg |
* /1.jpg |
*
*
* | 1.jpg |
* /WEB-INF/1.css |
* /a/1.jpg |
* /a/1.jpg |
*
*
* | /1.jpg |
* /1.jpg |
*
*
* | 1.jpg |
* [WRO-PREFIX]?id=/WEB-INF/1.jpg |
*
*
* | ../1.jpg |
* [WRO-PREFIX]?id=/WEB-INF/../1.jpg |
*
*
* where [X] is URL or a classpath resource
* where [WRO-PREFIX] is a servletContext prefix
* which will map WRO filter to the result url.
* /a/1.jpg |
* [WRO-PREFIX]?id=[X]/a/1.jpg |
*
*
* | /1.jpg |
* [WRO-PREFIX]?id=[X]/1.jpg |
*
*
* | 1.jpg |
* [WRO-PREFIX]?id=[X]/1.jpg |
*
*
* | ../1.jpg |
* [WRO-PREFIX]?id=[X]/../1.jpg |
*
*
*
*
* The algorithm requires two types of {@link UriLocator} objects, one for resolving url resources & one for classpath
* resources. Both need to be injected using IoC when creating the instance of {@link CssUrlRewritingProcessor} class.
*
* @author Alex Objelean
* @created Nov 19, 2008
*/
public class CssUrlRewritingProcessor
extends AbstractCssUrlRewritingProcessor {
private static final Logger LOG = LoggerFactory.getLogger(CssUrlRewritingProcessor.class);
public static final String ALIAS = "cssUrlRewriting";
@Inject
private ResourceAuthorizationManager authorizationManager;
@Inject
private ReadOnlyContext context;
@Override
protected void onUrlReplaced(final String replacedUrl) {
final String allowedUrl = StringUtils.removeStart(replacedUrl, getUrlPrefix());
LOG.debug("adding allowed url: {}", allowedUrl);
//add only if add is supported
if (authorizationManager instanceof MutableResourceAuthorizationManager) {
((MutableResourceAuthorizationManager) authorizationManager).add(allowedUrl);
}
}
/**
* Replace provided url with the new url if needed.
*
* @param cssUri
* Uri of the parsed css.
* @param imageUrl
* to replace.
* @return replaced url.
*/
@Override
protected String replaceImageUrl(final String cssUri, final String imageUrl) {
>>>>>>> 2f3dc582f9006a6d78f01d6a0cf78d8f1d5e0616
//Can be null when using standalone context.
final String contextPath = context.getRequest() != null ? context.getRequest().getContextPath() : null;
final RewriterContext rewriterContext = new RewriterContext().setAggregatedFolderPath( |