rewrite URLs in CSS files
- by Don
Hi,
I'm writing a Maven plugin that merges CSS files together. So all the CSS files that match /foo/bar/*.css might get merged to /foo/merged.css.
A concern is that in a file such as /foo/bar/baz.css there might be a property such as:
background: url("images/pic.jpg")
So when the file is merged into /foo/merged.css this will need to be changed to
background: url("bar/images/pic.jpg")
The recalculated URL obviously depends on 3 factors:
original URL
original CSS file location
merged CSS file location
Assuming that the original and merged CSS files are both on the same filesystem, is there a general formula (or Java library) that can be used to calculate the new url given these 3 inputs?
Thanks,
Don