/**
* {@inheritDoc}
*/
@Override
protected void doProcess(Reader reader, Writer writer, ProcessingContext processingContext) throws Exception {
Asset asset = processingContext.getAsset();
String contextPath = processingContext.getRequest().getContextPath();
LOG.debug("Processing {}", asset.toLog());
urlRewriter.setContextPath(contextPath);
StringBuilder assetContent = StringBuilderUtils.toStringBuilder(reader);
BufferedWriter bufferedWriter = null;
try {
LOG.debug(" Old location: {}", asset.getConfigLocation());
LOG.debug(" New location: {}", asset.getFinalLocation());
bufferedWriter = new BufferedWriter(writer);
bufferedWriter.write(urlRewriter.rewriteUrl("/" + contextPath + asset.getConfigLocation(),
asset.getFinalLocation(), assetContent.toString()).toString());
}
catch (IOException e) {
LOG.error("An error occurred when processing relative paths inside the asset " + asset.toLog());
throw DandelionException.wrap(e);
}
finally {
try {
if (reader != null)
reader.close();
}
catch (IOException e) {
// Should never happen
LOG.error("An error occurred when processing relative paths inside the asset " + asset.toLog());
throw DandelionException.wrap(e);
}
// Flush and closes the stream
bufferedWriter.close();